2d059fcc22
Implement support for text 'rotate' attribute: https://www.w3.org/TR/SVG11/text.html#TSpanElementRotateAttribute. Unlike other character-positioning attributes (x/y/dx/dy), rotate - is not cumulative - only applies to its respective node scope (does not affect other fragments in the current chunk) - has different padding semantics: if there are fewer rotate values than characters, the remaining characters use the last specified value from the closest ancestor To the last point, we now have to discriminate three states: - unspecified (default -> 0) - explicit value for the given character index - implicit value (last value in the closest ancestor) Local implicit values override implicit ancestor values -- but not explicit ancestor values. High level changes: - plumb 'rotate' attribute - expand per-character position info (ShapeBuffer) to include rotation - expand per-glyph position info (RunRec) to include rotation - expand PosAttrs to include rotation and add specific inheritance rules (see above) - pass computed rotation values to RSX blob buffers Bug: skia:10840 Change-Id: Ia19ec5e8bb6fea06d49a9bd72ace575c2ffd100e Reviewed-on: https://skia-review.googlesource.com/c/skia/+/348877 Commit-Queue: Florin Malita <fmalita@google.com> Reviewed-by: Tyler Denniston <tdenniston@google.com>
102 lines
2.8 KiB
C++
102 lines
2.8 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(Rotate, std::vector<SkSVGNumberType>, {})
|
|
|
|
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
|