1 /*
2 * Copyright 2006 The Android Open Source Project
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SkGlyph_DEFINED
9 #define SkGlyph_DEFINED
10
11 #include "include/core/SkDrawable.h"
12 #include "include/core/SkPath.h"
13 #include "include/core/SkPoint.h"
14 #include "include/core/SkRect.h"
15 #include "include/core/SkRefCnt.h"
16 #include "include/core/SkScalar.h"
17 #include "include/core/SkString.h"
18 #include "include/core/SkTypes.h"
19 #include "include/private/SkChecksum.h"
20 #include "include/private/base/SkFixed.h"
21 #include "include/private/base/SkDebug.h"
22 #include "include/private/base/SkTo.h"
23 #include "src/base/SkVx.h"
24 #include "src/core/SkMask.h"
25
26 #include <algorithm>
27 #include <cmath>
28 #include <cstddef>
29 #include <cstdint>
30 #include <limits>
31
32 class SkArenaAlloc;
33 class SkGlyph;
34 class SkScalerContext;
35 namespace sktext {
36 class StrikeForGPU;
37 } // namespace sktext
38
39 // -- SkPackedGlyphID ------------------------------------------------------------------------------
40 // A combination of SkGlyphID and sub-pixel position information.
41 struct SkPackedGlyphID {
42 inline static constexpr uint32_t kImpossibleID = ~0u;
43 enum {
44 // Lengths
45 kGlyphIDLen = 16u,
46 kSubPixelPosLen = 2u,
47
48 // Bit positions
49 kSubPixelX = 0u,
50 kGlyphID = kSubPixelPosLen,
51 kSubPixelY = kGlyphIDLen + kSubPixelPosLen,
52 kEndData = kGlyphIDLen + 2 * kSubPixelPosLen,
53
54 // Masks
55 kGlyphIDMask = (1u << kGlyphIDLen) - 1,
56 kSubPixelPosMask = (1u << kSubPixelPosLen) - 1,
57 kMaskAll = (1u << kEndData) - 1,
58
59 // Location of sub pixel info in a fixed pointer number.
60 kFixedPointBinaryPointPos = 16u,
61 kFixedPointSubPixelPosBits = kFixedPointBinaryPointPos - kSubPixelPosLen,
62 };
63
64 inline static const constexpr SkScalar kSubpixelRound =
65 1.f / (1u << (SkPackedGlyphID::kSubPixelPosLen + 1));
66
67 inline static const constexpr SkIPoint kXYFieldMask{kSubPixelPosMask << kSubPixelX,
68 kSubPixelPosMask << kSubPixelY};
69
70 struct Hash {
operatorSkPackedGlyphID::Hash71 uint32_t operator() (SkPackedGlyphID packedID) const {
72 return packedID.hash();
73 }
74 };
75
SkPackedGlyphIDSkPackedGlyphID76 constexpr explicit SkPackedGlyphID(SkGlyphID glyphID)
77 : fID{(uint32_t)glyphID << kGlyphID} { }
78
SkPackedGlyphIDSkPackedGlyphID79 constexpr SkPackedGlyphID(SkGlyphID glyphID, SkFixed x, SkFixed y)
80 : fID {PackIDXY(glyphID, x, y)} { }
81
SkPackedGlyphIDSkPackedGlyphID82 constexpr SkPackedGlyphID(SkGlyphID glyphID, uint32_t x, uint32_t y)
83 : fID {PackIDSubXSubY(glyphID, x, y)} { }
84
SkPackedGlyphIDSkPackedGlyphID85 SkPackedGlyphID(SkGlyphID glyphID, SkPoint pt, SkIPoint mask)
86 : fID{PackIDSkPoint(glyphID, pt, mask)} { }
87
SkPackedGlyphIDSkPackedGlyphID88 constexpr explicit SkPackedGlyphID(uint32_t v) : fID{v & kMaskAll} { }
SkPackedGlyphIDSkPackedGlyphID89 constexpr SkPackedGlyphID() : fID{kImpossibleID} {}
90
91 bool operator==(const SkPackedGlyphID& that) const {
92 return fID == that.fID;
93 }
94 bool operator!=(const SkPackedGlyphID& that) const {
95 return !(*this == that);
96 }
97 bool operator<(SkPackedGlyphID that) const {
98 return this->fID < that.fID;
99 }
100
glyphIDSkPackedGlyphID101 SkGlyphID glyphID() const {
102 return (fID >> kGlyphID) & kGlyphIDMask;
103 }
104
valueSkPackedGlyphID105 uint32_t value() const {
106 return fID;
107 }
108
getSubXFixedSkPackedGlyphID109 SkFixed getSubXFixed() const {
110 return this->subToFixed(kSubPixelX);
111 }
112
getSubYFixedSkPackedGlyphID113 SkFixed getSubYFixed() const {
114 return this->subToFixed(kSubPixelY);
115 }
116
hashSkPackedGlyphID117 uint32_t hash() const {
118 return SkChecksum::CheapMix(fID);
119 }
120
dumpSkPackedGlyphID121 SkString dump() const {
122 SkString str;
123 str.appendf("glyphID: %d, x: %d, y:%d", glyphID(), getSubXFixed(), getSubYFixed());
124 return str;
125 }
126
shortDumpSkPackedGlyphID127 SkString shortDump() const {
128 SkString str;
129 str.appendf("0x%x|%1d|%1d", this->glyphID(),
130 this->subPixelField(kSubPixelX),
131 this->subPixelField(kSubPixelY));
132 return str;
133 }
134
135 private:
PackIDSubXSubYSkPackedGlyphID136 static constexpr uint32_t PackIDSubXSubY(SkGlyphID glyphID, uint32_t x, uint32_t y) {
137 SkASSERT(x < (1u << kSubPixelPosLen));
138 SkASSERT(y < (1u << kSubPixelPosLen));
139
140 return (x << kSubPixelX) | (y << kSubPixelY) | (glyphID << kGlyphID);
141 }
142
143 // Assumptions: pt is properly rounded. mask is set for the x or y fields.
144 //
145 // A sub-pixel field is a number on the interval [2^kSubPixel, 2^(kSubPixel + kSubPixelPosLen)).
146 // Where kSubPixel is either kSubPixelX or kSubPixelY. Given a number x on [0, 1) we can
147 // generate a sub-pixel field using:
148 // sub-pixel-field = x * 2^(kSubPixel + kSubPixelPosLen)
149 //
150 // We can generate the integer sub-pixel field by &-ing the integer part of sub-filed with the
151 // sub-pixel field mask.
152 // int-sub-pixel-field = int(sub-pixel-field) & (kSubPixelPosMask << kSubPixel)
153 //
154 // The last trick is to extend the range from [0, 1) to [0, 2). The extend range is
155 // necessary because the modulo 1 calculation (pt - floor(pt)) generates numbers on [-1, 1).
156 // This does not round (floor) properly when converting to integer. Adding one to the range
157 // causes truncation and floor to be the same. Coincidentally, masking to produce the field also
158 // removes the +1.
PackIDSkPointSkPackedGlyphID159 static uint32_t PackIDSkPoint(SkGlyphID glyphID, SkPoint pt, SkIPoint mask) {
160 #if 0
161 // TODO: why does this code not work on GCC 8.3 x86 Debug builds?
162 using namespace skvx;
163 using XY = Vec<2, float>;
164 using SubXY = Vec<2, int>;
165
166 const XY magic = {1.f * (1u << (kSubPixelPosLen + kSubPixelX)),
167 1.f * (1u << (kSubPixelPosLen + kSubPixelY))};
168 XY pos{pt.x(), pt.y()};
169 XY subPos = (pos - floor(pos)) + 1.0f;
170 SubXY sub = cast<int>(subPos * magic) & SubXY{mask.x(), mask.y()};
171 #else
172 const float magicX = 1.f * (1u << (kSubPixelPosLen + kSubPixelX)),
173 magicY = 1.f * (1u << (kSubPixelPosLen + kSubPixelY));
174
175 float x = pt.x(),
176 y = pt.y();
177 x = (x - floorf(x)) + 1.0f;
178 y = (y - floorf(y)) + 1.0f;
179 int sub[] = {
180 (int)(x * magicX) & mask.x(),
181 (int)(y * magicY) & mask.y(),
182 };
183 #endif
184
185 SkASSERT(sub[0] / (1u << kSubPixelX) < (1u << kSubPixelPosLen));
186 SkASSERT(sub[1] / (1u << kSubPixelY) < (1u << kSubPixelPosLen));
187 return (glyphID << kGlyphID) | sub[0] | sub[1];
188 }
189
PackIDXYSkPackedGlyphID190 static constexpr uint32_t PackIDXY(SkGlyphID glyphID, SkFixed x, SkFixed y) {
191 return PackIDSubXSubY(glyphID, FixedToSub(x), FixedToSub(y));
192 }
193
FixedToSubSkPackedGlyphID194 static constexpr uint32_t FixedToSub(SkFixed n) {
195 return ((uint32_t)n >> kFixedPointSubPixelPosBits) & kSubPixelPosMask;
196 }
197
subPixelFieldSkPackedGlyphID198 constexpr uint32_t subPixelField(uint32_t subPixelPosBit) const {
199 return (fID >> subPixelPosBit) & kSubPixelPosMask;
200 }
201
subToFixedSkPackedGlyphID202 constexpr SkFixed subToFixed(uint32_t subPixelPosBit) const {
203 uint32_t subPixelPosition = this->subPixelField(subPixelPosBit);
204 return subPixelPosition << kFixedPointSubPixelPosBits;
205 }
206
207 uint32_t fID;
208 };
209
210 // -- SkAxisAlignment ------------------------------------------------------------------------------
211 // SkAxisAlignment specifies the x component of a glyph's position is rounded when kX, and the y
212 // component is rounded when kY. If kNone then neither are rounded.
213 enum class SkAxisAlignment : uint32_t {
214 kNone,
215 kX,
216 kY,
217 };
218
219 // round and ignorePositionMask are used to calculate the subpixel position of a glyph.
220 // The per component (x or y) calculation is:
221 //
222 // subpixelOffset = (floor((viewportPosition + rounding) & mask) >> 14) & 3
223 //
224 // where mask is either 0 or ~0, and rounding is either
225 // 1/2 for non-subpixel or 1/8 for subpixel.
226 struct SkGlyphPositionRoundingSpec {
227 SkGlyphPositionRoundingSpec(bool isSubpixel, SkAxisAlignment axisAlignment);
228 const SkVector halfAxisSampleFreq;
229 const SkIPoint ignorePositionMask;
230 const SkIPoint ignorePositionFieldMask;
231
232 private:
233 static SkVector HalfAxisSampleFreq(bool isSubpixel, SkAxisAlignment axisAlignment);
234 static SkIPoint IgnorePositionMask(bool isSubpixel, SkAxisAlignment axisAlignment);
235 static SkIPoint IgnorePositionFieldMask(bool isSubpixel, SkAxisAlignment axisAlignment);
236 };
237
238 class SkGlyphRect;
239 namespace skglyph {
240 SkGlyphRect rect_union(SkGlyphRect, SkGlyphRect);
241 SkGlyphRect rect_intersection(SkGlyphRect, SkGlyphRect);
242 } // namespace skglyph
243
244 // SkGlyphRect encodes rectangles with coordinates using SkScalar. It is specialized for
245 // rectangle union and intersection operations.
246 class SkGlyphRect {
247 public:
248 SkGlyphRect() = default;
SkGlyphRect(SkScalar left,SkScalar top,SkScalar right,SkScalar bottom)249 SkGlyphRect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
250 : fRect{-left, -top, right, bottom} { }
empty()251 bool empty() const {
252 return -fRect[0] >= fRect[2] || -fRect[1] >= fRect[3];
253 }
rect()254 SkRect rect() const {
255 return SkRect::MakeLTRB(-fRect[0], -fRect[1], fRect[2], fRect[3]);
256 }
offset(SkScalar x,SkScalar y)257 SkGlyphRect offset(SkScalar x, SkScalar y) const {
258 return SkGlyphRect{fRect + Storage{-x, -y, x, y}};
259 }
offset(SkPoint pt)260 SkGlyphRect offset(SkPoint pt) const {
261 return this->offset(pt.x(), pt.y());
262 }
scaleAndOffset(SkScalar scale,SkPoint offset)263 SkGlyphRect scaleAndOffset(SkScalar scale, SkPoint offset) const {
264 auto [x, y] = offset;
265 return fRect * scale + Storage{-x, -y, x, y};
266 }
inset(SkScalar dx,SkScalar dy)267 SkGlyphRect inset(SkScalar dx, SkScalar dy) const {
268 return fRect - Storage{dx, dy, dx, dy};
269 }
leftTop()270 SkPoint leftTop() const { return -this->negLeftTop(); }
rightBottom()271 SkPoint rightBottom() const { return {fRect[2], fRect[3]}; }
widthHeight()272 SkPoint widthHeight() const { return this->rightBottom() + negLeftTop(); }
273 friend SkGlyphRect skglyph::rect_union(SkGlyphRect, SkGlyphRect);
274 friend SkGlyphRect skglyph::rect_intersection(SkGlyphRect, SkGlyphRect);
275
276 private:
negLeftTop()277 SkPoint negLeftTop() const { return {fRect[0], fRect[1]}; }
278 using Storage = skvx::Vec<4, SkScalar>;
SkGlyphRect(Storage rect)279 SkGlyphRect(Storage rect) : fRect{rect} { }
280 Storage fRect;
281 };
282
283 namespace skglyph {
empty_rect()284 inline SkGlyphRect empty_rect() {
285 constexpr SkScalar max = std::numeric_limits<SkScalar>::max();
286 return {max, max, -max, -max};
287 }
full_rect()288 inline SkGlyphRect full_rect() {
289 constexpr SkScalar max = std::numeric_limits<SkScalar>::max();
290 return {-max, -max, max, max};
291 }
rect_union(SkGlyphRect a,SkGlyphRect b)292 inline SkGlyphRect rect_union(SkGlyphRect a, SkGlyphRect b) {
293 return skvx::max(a.fRect, b.fRect);
294 }
rect_intersection(SkGlyphRect a,SkGlyphRect b)295 inline SkGlyphRect rect_intersection(SkGlyphRect a, SkGlyphRect b) {
296 return skvx::min(a.fRect, b.fRect);
297 }
298
299 enum class GlyphAction {
300 kUnset,
301 kAccept,
302 kReject,
303 kDrop,
304 kSize,
305 };
306
307 enum ActionType {
308 kDirectMask = 0,
309 kDirectMaskCPU = 2,
310 kMask = 4,
311 kSDFT = 6,
312 kPath = 8,
313 kDrawable = 10,
314 };
315
316 enum ActionTypeSize {
317 kTotalBits = 12
318 };
319 } // namespace skglyph
320
321 // SkGlyphDigest contains a digest of information for making GPU drawing decisions. It can be
322 // referenced instead of the glyph itself in many situations. In the remote glyphs cache the
323 // SkGlyphDigest is the only information that needs to be stored in the cache.
324 class SkGlyphDigest {
325 public:
326 // An atlas consists of plots, and plots hold glyphs. The minimum a plot can be is 256x256.
327 // This means that the maximum size a glyph can be is 256x256.
328 static constexpr uint16_t kSkSideTooBigForAtlas = 256;
329
330 // Default ctor is only needed for the hash table.
331 SkGlyphDigest() = default;
332 SkGlyphDigest(size_t index, const SkGlyph& glyph);
index()333 int index() const { return fIndex; }
isEmpty()334 bool isEmpty() const { return fIsEmpty; }
isColor()335 bool isColor() const { return fFormat == SkMask::kARGB32_Format; }
maskFormat()336 SkMask::Format maskFormat() const { return static_cast<SkMask::Format>(fFormat); }
337
actionFor(skglyph::ActionType actionType)338 skglyph::GlyphAction actionFor(skglyph::ActionType actionType) const {
339 return static_cast<skglyph::GlyphAction>((fActions >> actionType) & 0b11);
340 }
341
342 void setActionFor(skglyph::ActionType, SkGlyph*, sktext::StrikeForGPU*);
343
maxDimension()344 uint16_t maxDimension() const {
345 return std::max(fWidth, fHeight);
346 }
347
fitsInAtlasDirect()348 bool fitsInAtlasDirect() const {
349 return this->maxDimension() <= kSkSideTooBigForAtlas;
350 }
351
fitsInAtlasInterpolated()352 bool fitsInAtlasInterpolated() const {
353 // Include the padding needed for interpolating the glyph when drawing.
354 return this->maxDimension() <= kSkSideTooBigForAtlas - 2;
355 }
356
bounds()357 SkGlyphRect bounds() const {
358 return SkGlyphRect(fLeft, fTop, (SkScalar)fLeft + fWidth, (SkScalar)fTop + fHeight);
359 }
360
361 static bool FitsInAtlas(const SkGlyph& glyph);
362
363 private:
setAction(skglyph::ActionType actionType,skglyph::GlyphAction action)364 void setAction(skglyph::ActionType actionType, skglyph::GlyphAction action) {
365 using namespace skglyph;
366 SkASSERT(action != GlyphAction::kUnset);
367 SkASSERT(this->actionFor(actionType) == GlyphAction::kUnset);
368 const uint32_t mask = 0b11 << actionType;
369 fActions &= ~mask;
370 fActions |= SkTo<uint32_t>(action) << actionType;
371 }
372
373 static_assert(SkPackedGlyphID::kEndData == 20);
374 static_assert(SkMask::kCountMaskFormats <= 8);
375 static_assert(SkTo<int>(skglyph::GlyphAction::kSize) <= 4);
376 struct {
377 uint32_t fIndex : SkPackedGlyphID::kEndData;
378 uint16_t fIsEmpty : 1;
379 uint32_t fFormat : 3;
380 uint32_t fActions : skglyph::ActionTypeSize::kTotalBits;
381 };
382 int16_t fLeft, fTop;
383 uint16_t fWidth, fHeight;
384 };
385
386 class SkGlyph {
387 public:
388 // SkGlyph() is used for testing.
SkGlyph()389 constexpr SkGlyph() : SkGlyph{SkPackedGlyphID()} { }
390 SkGlyph(const SkGlyph&);
391 SkGlyph& operator=(const SkGlyph&);
392 SkGlyph(SkGlyph&&);
393 SkGlyph& operator=(SkGlyph&&);
394 ~SkGlyph();
SkGlyph(SkPackedGlyphID id)395 constexpr explicit SkGlyph(SkPackedGlyphID id) : fID{id} { }
396
advanceVector()397 SkVector advanceVector() const { return SkVector{fAdvanceX, fAdvanceY}; }
advanceX()398 SkScalar advanceX() const { return fAdvanceX; }
advanceY()399 SkScalar advanceY() const { return fAdvanceY; }
400
getGlyphID()401 SkGlyphID getGlyphID() const { return fID.glyphID(); }
getPackedID()402 SkPackedGlyphID getPackedID() const { return fID; }
getSubXFixed()403 SkFixed getSubXFixed() const { return fID.getSubXFixed(); }
getSubYFixed()404 SkFixed getSubYFixed() const { return fID.getSubYFixed(); }
405
406 size_t rowBytes() const;
407 size_t rowBytesUsingFormat(SkMask::Format format) const;
408
409 // Call this to set all the metrics fields to 0 (e.g. if the scaler
410 // encounters an error measuring a glyph). Note: this does not alter the
411 // fImage, fPath, fID, fMaskFormat fields.
412 void zeroMetrics();
413
414 SkMask mask() const;
415
416 SkMask mask(SkPoint position) const;
417
418 // Image
419 // If we haven't already tried to associate an image with this glyph
420 // (i.e. setImageHasBeenCalled() returns false), then use the
421 // SkScalerContext or const void* argument to set the image.
422 bool setImage(SkArenaAlloc* alloc, SkScalerContext* scalerContext);
423 bool setImage(SkArenaAlloc* alloc, const void* image);
424
425 // Merge the 'from' glyph into this glyph using alloc to allocate image data. Return the number
426 // of bytes allocated. Copy the width, height, top, left, format, and image into this glyph
427 // making a copy of the image using the alloc.
428 size_t setMetricsAndImage(SkArenaAlloc* alloc, const SkGlyph& from);
429
430 // Returns true if the image has been set.
setImageHasBeenCalled()431 bool setImageHasBeenCalled() const {
432 return fImage != nullptr || this->isEmpty() || this->imageTooLarge();
433 }
434
435 // Return a pointer to the path if the image exists, otherwise return nullptr.
image()436 const void* image() const { SkASSERT(this->setImageHasBeenCalled()); return fImage; }
437
438 // Return the size of the image.
439 size_t imageSize() const;
440
441 // Path
442 // If we haven't already tried to associate a path to this glyph
443 // (i.e. setPathHasBeenCalled() returns false), then use the
444 // SkScalerContext or SkPath argument to try to do so. N.B. this
445 // may still result in no path being associated with this glyph,
446 // e.g. if you pass a null SkPath or the typeface is bitmap-only.
447 //
448 // This setPath() call is sticky... once you call it, the glyph
449 // stays in its state permanently, ignoring any future calls.
450 //
451 // Returns true if this is the first time you called setPath()
452 // and there actually is a path; call path() to get it.
453 bool setPath(SkArenaAlloc* alloc, SkScalerContext* scalerContext);
454 bool setPath(SkArenaAlloc* alloc, const SkPath* path, bool hairline);
455
456 // Returns true if that path has been set.
setPathHasBeenCalled()457 bool setPathHasBeenCalled() const { return fPathData != nullptr; }
458
459 // Return a pointer to the path if it exists, otherwise return nullptr. Only works if the
460 // path was previously set.
461 const SkPath* path() const;
462 bool pathIsHairline() const;
463
464 bool setDrawable(SkArenaAlloc* alloc, SkScalerContext* scalerContext);
465 bool setDrawable(SkArenaAlloc* alloc, sk_sp<SkDrawable> drawable);
setDrawableHasBeenCalled()466 bool setDrawableHasBeenCalled() const { return fDrawableData != nullptr; }
467 SkDrawable* drawable() const;
468
469 // Format
isColor()470 bool isColor() const { return fMaskFormat == SkMask::kARGB32_Format; }
maskFormat()471 SkMask::Format maskFormat() const { return fMaskFormat; }
472 size_t formatAlignment() const;
473
474 // Bounds
maxDimension()475 int maxDimension() const { return std::max(fWidth, fHeight); }
iRect()476 SkIRect iRect() const { return SkIRect::MakeXYWH(fLeft, fTop, fWidth, fHeight); }
rect()477 SkRect rect() const { return SkRect::MakeXYWH(fLeft, fTop, fWidth, fHeight); }
glyphRect()478 SkGlyphRect glyphRect() const {
479 return SkGlyphRect(fLeft, fTop, fLeft + fWidth, fTop + fHeight);
480 }
left()481 int left() const { return fLeft; }
top()482 int top() const { return fTop; }
width()483 int width() const { return fWidth; }
height()484 int height() const { return fHeight; }
isEmpty()485 bool isEmpty() const {
486 // fHeight == 0 -> fWidth == 0;
487 SkASSERT(fHeight != 0 || fWidth == 0);
488 return fWidth == 0;
489 }
imageTooLarge()490 bool imageTooLarge() const { return fWidth >= kMaxGlyphWidth; }
491
492 // Make sure that the intercept information is on the glyph and return it, or return it if it
493 // already exists.
494 // * bounds - either end of the gap for the character.
495 // * scale, xPos - information about how wide the gap is.
496 // * array - accumulated gaps for many characters if not null.
497 // * count - the number of gaps.
498 void ensureIntercepts(const SkScalar bounds[2], SkScalar scale, SkScalar xPos,
499 SkScalar* array, int* count, SkArenaAlloc* alloc);
500
setImage(void * image)501 void setImage(void* image) { fImage = image; }
502
503 private:
504 // There are two sides to an SkGlyph, the scaler side (things that create glyph data) have
505 // access to all the fields. Scalers are assumed to maintain all the SkGlyph invariants. The
506 // consumer side has a tighter interface.
507 friend class RandomScalerContext;
508 friend class SkScalerContext;
509 friend class SkScalerContextProxy;
510 friend class SkScalerContext_Empty;
511 friend class SkScalerContext_FreeType;
512 friend class SkScalerContext_FreeType_Base;
513 friend class SkScalerContext_DW;
514 friend class SkScalerContext_GDI;
515 friend class SkScalerContext_Mac;
516 friend class SkStrikeClientImpl;
517 friend class SkTestScalerContext;
518 friend class SkTestSVGScalerContext;
519 friend class SkUserScalerContext;
520 friend class TestSVGTypeface;
521 friend class TestTypeface;
522
523 inline static constexpr uint16_t kMaxGlyphWidth = 1u << 13u;
524
525 // Support horizontal and vertical skipping strike-through / underlines.
526 // The caller walks the linked list looking for a match. For a horizontal underline,
527 // the fBounds contains the top and bottom of the underline. The fInterval pair contains the
528 // beginning and end of the intersection of the bounds and the glyph's path.
529 // If interval[0] >= interval[1], no intersection was found.
530 struct Intercept {
531 Intercept* fNext;
532 SkScalar fBounds[2]; // for horz underlines, the boundaries in Y
533 SkScalar fInterval[2]; // the outside intersections of the axis and the glyph
534 };
535
536 struct PathData {
537 Intercept* fIntercept{nullptr};
538 SkPath fPath;
539 bool fHasPath{false};
540 // A normal user-path will have patheffects applied to it and eventually become a dev-path.
541 // A dev-path is always a fill-path, except when it is hairline.
542 // The fPath is a dev-path, so sidecar the paths hairline status.
543 // This allows the user to avoid filling paths which should not be filled.
544 bool fHairline{false};
545 };
546
547 struct DrawableData {
548 Intercept* fIntercept{nullptr};
549 sk_sp<SkDrawable> fDrawable;
550 bool fHasDrawable{false};
551 };
552
553 size_t allocImage(SkArenaAlloc* alloc);
554
555 // path == nullptr indicates that there is no path.
556 void installPath(SkArenaAlloc* alloc, const SkPath* path, bool hairline);
557
558 // drawable == nullptr indicates that there is no path.
559 void installDrawable(SkArenaAlloc* alloc, sk_sp<SkDrawable> drawable);
560
561 // The width and height of the glyph mask.
562 uint16_t fWidth = 0,
563 fHeight = 0;
564
565 // The offset from the glyphs origin on the baseline to the top left of the glyph mask.
566 int16_t fTop = 0,
567 fLeft = 0;
568
569 // fImage must remain null if the glyph is empty or if width > kMaxGlyphWidth.
570 void* fImage = nullptr;
571
572 // Path data has tricky state. If the glyph isEmpty, then fPathData should always be nullptr,
573 // else if fPathData is not null, then a path has been requested. The fPath field of fPathData
574 // may still be null after the request meaning that there is no path for this glyph.
575 PathData* fPathData = nullptr;
576 DrawableData* fDrawableData = nullptr;
577
578 // The advance for this glyph.
579 float fAdvanceX = 0,
580 fAdvanceY = 0;
581
582 SkMask::Format fMaskFormat{SkMask::kBW_Format};
583
584 // Used by the SkScalerContext to pass state from generateMetrics to generateImage.
585 // Usually specifies which glyph representation was used to generate the metrics.
586 uint16_t fScalerContextBits = 0;
587
588 // An SkGlyph can be created with just a packedID, but generally speaking some glyph factory
589 // needs to actually fill out the glyph before it can be used as part of that system.
590 SkDEBUGCODE(bool fAdvancesBoundsFormatAndInitialPathDone{false};)
591
592 SkPackedGlyphID fID;
593 };
594
595 #endif
596