skia2/modules/svg/include/SkSVGText.h

123 lines
3.5 KiB
C
Raw Normal View History

/*
* 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 onShapeText(const SkSVGRenderContext&, SkSVGTextContext*, SkSVGXmlSpace) const = 0;
// Text nodes other than the root <text> element are not rendered directly.
void onRender(const SkSVGRenderContext&) const override {}
private:
SkPath onAsPath(const SkSVGRenderContext&) const override;
using INHERITED = SkSVGTransformableNode;
};
// Base class for nestable text containers (<text>, <tspan>, etc).
class SkSVGTextContainer : public SkSVGTextFragment {
public:
Reland "[svg] Absolute positioning support for text" This reverts commit e2f62453523e8eeb98968570b48b229f1cc1e712. Reason for revert: relanding with fixes Original change's description: > Revert "[svg] Absolute positioning support for text" > > This reverts commit febb1b87a5e73bdbe2cb598783082d3644d0e969. > > Reason for revert: breaking the android roll > > Original change's description: > > [svg] Absolute positioning support for text > > > > Implement per-character position attribute lookup based on [1]: > > > > - convert "x" and "y" attributes to arrays > > - introduce ScopedPosResolver to handle positioning attribute lookup > > and fallback > > - push a new resolver every time we enter a text positioning element > > scope (<text>, <tspan>, etc). > > - flush/reposition a new text chunk every time we encounter explicit > > absolute positions > > > > The position attribute fallback logic is complex enough to warrant a > > unit test. > > > > [1] https://www.w3.org/TR/SVG11/text.html#TSpanElementXAttribute > > > > Bug: skia:10840 > > Change-Id: I66c478fea4a179fdb8b1a6a9ff00c4dd9509f8d2 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/345161 > > Commit-Queue: Florin Malita <fmalita@chromium.org> > > Commit-Queue: Florin Malita <fmalita@google.com> > > Reviewed-by: Tyler Denniston <tdenniston@google.com> > > TBR=fmalita@chromium.org,fmalita@google.com,tdenniston@google.com > > Change-Id: I80e3396d555369fe835ee73102135061f63e8bf0 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10840 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/345417 > Reviewed-by: Derek Sollenberger <djsollen@google.com> > Commit-Queue: Derek Sollenberger <djsollen@google.com> TBR=djsollen@google.com,fmalita@chromium.org,fmalita@google.com,tdenniston@google.com # Not skipping CQ checks because this is a reland. Bug: skia:10840 Change-Id: I4c6f6a9f19c0f7598bdcf34e915f43c139b995a9 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/345420 Reviewed-by: Florin Malita <fmalita@google.com> Commit-Queue: Florin Malita <fmalita@google.com>
2020-12-17 21:36:54 +00:00
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)
Reland "[svg] Absolute positioning support for text" This reverts commit e2f62453523e8eeb98968570b48b229f1cc1e712. Reason for revert: relanding with fixes Original change's description: > Revert "[svg] Absolute positioning support for text" > > This reverts commit febb1b87a5e73bdbe2cb598783082d3644d0e969. > > Reason for revert: breaking the android roll > > Original change's description: > > [svg] Absolute positioning support for text > > > > Implement per-character position attribute lookup based on [1]: > > > > - convert "x" and "y" attributes to arrays > > - introduce ScopedPosResolver to handle positioning attribute lookup > > and fallback > > - push a new resolver every time we enter a text positioning element > > scope (<text>, <tspan>, etc). > > - flush/reposition a new text chunk every time we encounter explicit > > absolute positions > > > > The position attribute fallback logic is complex enough to warrant a > > unit test. > > > > [1] https://www.w3.org/TR/SVG11/text.html#TSpanElementXAttribute > > > > Bug: skia:10840 > > Change-Id: I66c478fea4a179fdb8b1a6a9ff00c4dd9509f8d2 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/345161 > > Commit-Queue: Florin Malita <fmalita@chromium.org> > > Commit-Queue: Florin Malita <fmalita@google.com> > > Reviewed-by: Tyler Denniston <tdenniston@google.com> > > TBR=fmalita@chromium.org,fmalita@google.com,tdenniston@google.com > > Change-Id: I80e3396d555369fe835ee73102135061f63e8bf0 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10840 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/345417 > Reviewed-by: Derek Sollenberger <djsollen@google.com> > Commit-Queue: Derek Sollenberger <djsollen@google.com> TBR=djsollen@google.com,fmalita@chromium.org,fmalita@google.com,tdenniston@google.com # Not skipping CQ checks because this is a reland. Bug: skia:10840 Change-Id: I4c6f6a9f19c0f7598bdcf34e915f43c139b995a9 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/345420 Reviewed-by: Florin Malita <fmalita@google.com> Commit-Queue: Florin Malita <fmalita@google.com>
2020-12-17 21:36:54 +00:00
void appendChild(sk_sp<SkSVGNode>) final;
protected:
explicit SkSVGTextContainer(SkSVGTag t) : INHERITED(t) {}
void onShapeText(const SkSVGRenderContext&, SkSVGTextContext*, SkSVGXmlSpace) const override;
bool parseAndSetAttribute(const char*, const char*) override;
private:
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) {}
void onRender(const SkSVGRenderContext&) const override;
SkRect onObjectBoundingBox(const SkSVGRenderContext&) const override;
SkPath onAsPath(const SkSVGRenderContext&) const override;
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 onShapeText(const SkSVGRenderContext&, SkSVGTextContext*, SkSVGXmlSpace) const override;
void appendChild(sk_sp<SkSVGNode>) override {}
using INHERITED = SkSVGTextFragment;
};
class SkSVGTextPath final : public SkSVGTextContainer {
public:
static sk_sp<SkSVGTextPath> Make() { return sk_sp<SkSVGTextPath>(new SkSVGTextPath()); }
SVG_ATTR(Href , SkSVGIRI , {} )
SVG_ATTR(StartOffset, SkSVGLength, SkSVGLength(0))
private:
SkSVGTextPath() : INHERITED(SkSVGTag::kTextPath) {}
void onShapeText(const SkSVGRenderContext&, SkSVGTextContext*, SkSVGXmlSpace) const override;
bool parseAndSetAttribute(const char*, const char*) override;
using INHERITED = SkSVGTextContainer;
};
#endif // SkSVGText_DEFINED