735ac97eb4
Introduce support for relative position adjustments [1]: - plumb dx, dy attributes - extend ScopedPosResolver to also handle the new attributes - introduce ShapeBuffer to store both utf8 text and position adjustments for shaping (replaces prev 'filtered' array). - position adjustments are cumulative (relative adjustments affect all following characters) - utf8 encoding is variable length; for simplicity, ensure that the pos adjustment array and the utf8 array are always the same size by repeating the pos adjustment times number of utf8 bytes - introduce a temporary buffer for retrieving utf8 cluster information from SkShaper - post-shaping, use the utf8 cluster info to map back to character indices and apply the associated position adjutment [1] https://www.w3.org/TR/SVG11/text.html#TSpanElementDXAttribute Bug: skia:10840 Change-Id: Ia9f227f91723400711ff2b5d260976290da1e2e5 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/346636 Commit-Queue: Florin Malita <fmalita@google.com> Reviewed-by: Tyler Denniston <tdenniston@google.com>
101 lines
2.7 KiB
C++
101 lines
2.7 KiB
C++
/*
|
|
* Copyright 2019 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#ifndef SkSVGText_DEFINED
|
|
#define SkSVGText_DEFINED
|
|
|
|
#include <vector>
|
|
|
|
#include "modules/svg/include/SkSVGTransformableNode.h"
|
|
#include "modules/svg/include/SkSVGTypes.h"
|
|
|
|
class SkSVGTextContext;
|
|
|
|
// Base class for text-rendering nodes.
|
|
class SkSVGTextFragment : public SkSVGTransformableNode {
|
|
public:
|
|
void renderText(const SkSVGRenderContext&, SkSVGTextContext*, SkSVGXmlSpace) const;
|
|
|
|
protected:
|
|
explicit SkSVGTextFragment(SkSVGTag t) : INHERITED(t) {}
|
|
|
|
virtual void onRenderText(const SkSVGRenderContext&, SkSVGTextContext*,
|
|
SkSVGXmlSpace) const = 0;
|
|
|
|
private:
|
|
SkPath onAsPath(const SkSVGRenderContext&) const final;
|
|
|
|
using INHERITED = SkSVGTransformableNode;
|
|
};
|
|
|
|
// Base class for nestable text containers (<text>, <tspan>, etc).
|
|
class SkSVGTextContainer : public SkSVGTextFragment {
|
|
public:
|
|
SVG_ATTR(X, std::vector<SkSVGLength>, {})
|
|
SVG_ATTR(Y, std::vector<SkSVGLength>, {})
|
|
SVG_ATTR(Dx, std::vector<SkSVGLength>, {})
|
|
SVG_ATTR(Dy, std::vector<SkSVGLength>, {})
|
|
|
|
SVG_ATTR(XmlSpace, SkSVGXmlSpace, SkSVGXmlSpace::kDefault)
|
|
|
|
void appendChild(sk_sp<SkSVGNode>) final;
|
|
|
|
protected:
|
|
explicit SkSVGTextContainer(SkSVGTag t) : INHERITED(t) {}
|
|
|
|
private:
|
|
void onRender(const SkSVGRenderContext&) const final;
|
|
void onRenderText(const SkSVGRenderContext&, SkSVGTextContext*, SkSVGXmlSpace) const final;
|
|
|
|
bool parseAndSetAttribute(const char*, const char*) override;
|
|
|
|
std::vector<sk_sp<SkSVGTextFragment>> fChildren;
|
|
|
|
using INHERITED = SkSVGTextFragment;
|
|
};
|
|
|
|
class SkSVGText final : public SkSVGTextContainer {
|
|
public:
|
|
static sk_sp<SkSVGText> Make() { return sk_sp<SkSVGText>(new SkSVGText()); }
|
|
|
|
private:
|
|
SkSVGText() : INHERITED(SkSVGTag::kText) {}
|
|
|
|
using INHERITED = SkSVGTextContainer;
|
|
};
|
|
|
|
class SkSVGTSpan final : public SkSVGTextContainer {
|
|
public:
|
|
static sk_sp<SkSVGTSpan> Make() { return sk_sp<SkSVGTSpan>(new SkSVGTSpan()); }
|
|
|
|
private:
|
|
SkSVGTSpan() : INHERITED(SkSVGTag::kTSpan) {}
|
|
|
|
using INHERITED = SkSVGTextContainer;
|
|
};
|
|
|
|
class SkSVGTextLiteral final : public SkSVGTextFragment {
|
|
public:
|
|
static sk_sp<SkSVGTextLiteral> Make() {
|
|
return sk_sp<SkSVGTextLiteral>(new SkSVGTextLiteral());
|
|
}
|
|
|
|
SVG_ATTR(Text, SkSVGStringType, SkSVGStringType())
|
|
|
|
private:
|
|
SkSVGTextLiteral() : INHERITED(SkSVGTag::kTextLiteral) {}
|
|
|
|
void onRender(const SkSVGRenderContext&) const override {}
|
|
void onRenderText(const SkSVGRenderContext&, SkSVGTextContext*, SkSVGXmlSpace) const override;
|
|
|
|
void appendChild(sk_sp<SkSVGNode>) override {}
|
|
|
|
using INHERITED = SkSVGTextFragment;
|
|
};
|
|
|
|
#endif // SkSVGText_DEFINED
|