Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SkSVGTextContext::ScopedPosResolver Class Reference

#include <SkSVGTextPriv.h>

Public Member Functions

 ScopedPosResolver (const SkSVGTextContainer &, const SkSVGLengthContext &, SkSVGTextContext *, size_t)
 
 ScopedPosResolver (const SkSVGTextContainer &, const SkSVGLengthContext &, SkSVGTextContext *)
 
 ~ScopedPosResolver ()
 
PosAttrs resolve (size_t charIndex) const
 

Detailed Description

Definition at line 83 of file SkSVGTextPriv.h.

Constructor & Destructor Documentation

◆ ScopedPosResolver() [1/2]

SkSVGTextContext::ScopedPosResolver::ScopedPosResolver ( const SkSVGTextContainer txt,
const SkSVGLengthContext lctx,
SkSVGTextContext tctx,
size_t  charIndexOffset 
)

Definition at line 121 of file SkSVGText.cpp.

125 : fTextContext(tctx)
126 , fParent(tctx->fPosResolver)
127 , fCharIndexOffset(charIndexOffset)
128 , fX(ResolveLengths(lctx, txt.getX(), SkSVGLengthContext::LengthType::kHorizontal))
129 , fY(ResolveLengths(lctx, txt.getY(), SkSVGLengthContext::LengthType::kVertical))
130 , fDx(ResolveLengths(lctx, txt.getDx(), SkSVGLengthContext::LengthType::kHorizontal))
131 , fDy(ResolveLengths(lctx, txt.getDy(), SkSVGLengthContext::LengthType::kVertical))
132 , fRotate(txt.getRotate())
133{
134 fTextContext->fPosResolver = this;
135}

◆ ScopedPosResolver() [2/2]

SkSVGTextContext::ScopedPosResolver::ScopedPosResolver ( const SkSVGTextContainer txt,
const SkSVGLengthContext lctx,
SkSVGTextContext tctx 
)

Definition at line 137 of file SkSVGText.cpp.

140 : ScopedPosResolver(txt, lctx, tctx, tctx->fCurrentCharIndex) {}
ScopedPosResolver(const SkSVGTextContainer &, const SkSVGLengthContext &, SkSVGTextContext *, size_t)

◆ ~ScopedPosResolver()

SkSVGTextContext::ScopedPosResolver::~ScopedPosResolver ( )

Definition at line 142 of file SkSVGText.cpp.

142 {
143 fTextContext->fPosResolver = fParent;
144}

Member Function Documentation

◆ resolve()

SkSVGTextContext::PosAttrs SkSVGTextContext::ScopedPosResolver::resolve ( size_t  charIndex) const

Definition at line 146 of file SkSVGText.cpp.

146 {
147 PosAttrs attrs;
148
149 if (charIndex < fLastPosIndex) {
150 SkASSERT(charIndex >= fCharIndexOffset);
151 const auto localCharIndex = charIndex - fCharIndexOffset;
152
153 const auto hasAllLocal = localCharIndex < fX.size() &&
154 localCharIndex < fY.size() &&
155 localCharIndex < fDx.size() &&
156 localCharIndex < fDy.size() &&
157 localCharIndex < fRotate.size();
158 if (!hasAllLocal && fParent) {
159 attrs = fParent->resolve(charIndex);
160 }
161
162 if (localCharIndex < fX.size()) {
163 attrs[PosAttrs::kX] = fX[localCharIndex];
164 }
165 if (localCharIndex < fY.size()) {
166 attrs[PosAttrs::kY] = fY[localCharIndex];
167 }
168 if (localCharIndex < fDx.size()) {
169 attrs[PosAttrs::kDx] = fDx[localCharIndex];
170 }
171 if (localCharIndex < fDy.size()) {
172 attrs[PosAttrs::kDy] = fDy[localCharIndex];
173 }
174
175 // Rotation semantics are interestingly different [1]:
176 //
177 // - values are not cumulative
178 // - if explicit values are present at any level in the ancestor chain, those take
179 // precedence (closest ancestor)
180 // - last specified value applies to all remaining chars (closest ancestor)
181 // - these rules apply at node scope (not chunk scope)
182 //
183 // This means we need to discriminate between explicit rotation (rotate value provided for
184 // current char) and implicit rotation (ancestor has some values - but not for the requested
185 // char - we use the last specified value).
186 //
187 // [1] https://www.w3.org/TR/SVG11/text.html#TSpanElementRotateAttribute
188 if (!fRotate.empty()) {
189 if (localCharIndex < fRotate.size()) {
190 // Explicit rotation value overrides anything in the ancestor chain.
191 attrs[PosAttrs::kRotate] = fRotate[localCharIndex];
192 attrs.setImplicitRotate(false);
193 } else if (!attrs.has(PosAttrs::kRotate) || attrs.isImplicitRotate()){
194 // Local implicit rotation (last specified value) overrides ancestor implicit
195 // rotation.
196 attrs[PosAttrs::kRotate] = fRotate.back();
197 attrs.setImplicitRotate(true);
198 }
199 }
200
201 if (!attrs.hasAny()) {
202 // Once we stop producing explicit position data, there is no reason to
203 // continue trying for higher indices. We can suppress future lookups.
204 fLastPosIndex = charIndex;
205 }
206 }
207
208 return attrs;
209}
#define SkASSERT(cond)
Definition SkAssert.h:116
PosAttrs resolve(size_t charIndex) const

The documentation for this class was generated from the following files: