@@ -84,32 +84,6 @@ SkScalerContextFlags GrTextContext::ComputeScalerContextFlags(
84
84
}
85
85
}
86
86
87
- bool glyph_too_big_for_atlas (const SkGlyph& glyph) {
88
- return glyph.fWidth >= 256 || glyph.fHeight >= 256 ;
89
- }
90
-
91
- static SkRect rect_to_draw (
92
- const SkGlyph& glyph, SkPoint origin, SkScalar textScale, GrGlyph::MaskStyle maskStyle) {
93
-
94
- SkScalar dx = SkIntToScalar (glyph.fLeft );
95
- SkScalar dy = SkIntToScalar (glyph.fTop );
96
- SkScalar width = SkIntToScalar (glyph.fWidth );
97
- SkScalar height = SkIntToScalar (glyph.fHeight );
98
-
99
- if (maskStyle == GrGlyph::kDistance_MaskStyle ) {
100
- dx += SK_DistanceFieldInset;
101
- dy += SK_DistanceFieldInset;
102
- width -= 2 * SK_DistanceFieldInset;
103
- height -= 2 * SK_DistanceFieldInset;
104
- }
105
-
106
- dx *= textScale;
107
- dy *= textScale;
108
- width *= textScale;
109
- height *= textScale;
110
-
111
- return SkRect::MakeXYWH (origin.x () + dx, origin.y () + dy, width, height);
112
- }
113
87
114
88
void GrTextContext::regenerateGlyphRunList (GrTextBlob* cacheBlob,
115
89
GrGlyphCache* glyphCache,
@@ -162,7 +136,6 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob,
162
136
SkPoint glyphPos = origin + *positionCursor++;
163
137
if (glyph.fWidth > 0 ) {
164
138
if (glyph.fMaskFormat == SkMask::kSDF_Format ) {
165
-
166
139
AppendGlyph (
167
140
cacheBlob, runIndex, glyphCache, &currStrike,
168
141
glyph, GrGlyph::kDistance_MaskStyle ,
@@ -226,10 +199,10 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob,
226
199
[cacheBlob, runIndex, glyphCache, &currStrike, runPaint, cache{cache.get ()}]
227
200
(const SkMask& mask, const SkGlyph& glyph, SkPoint position) {
228
201
AppendGlyph (cacheBlob, runIndex, glyphCache, &currStrike,
229
- glyph, GrGlyph::kCoverage_MaskStyle ,
230
- SkScalarFloorToScalar (position.fX ),
231
- SkScalarFloorToScalar (position.fY ),
232
- runPaint.filteredPremulColor (), cache, SK_Scalar1, false );
202
+ glyph, GrGlyph::kCoverage_MaskStyle ,
203
+ SkScalarFloorToScalar (position.fX ),
204
+ SkScalarFloorToScalar (position.fY ),
205
+ runPaint.filteredPremulColor (), cache, SK_Scalar1, false );
233
206
};
234
207
235
208
glyphDrawer->drawUsingMasks (cache.get (), glyphRun, origin, viewMatrix, drawOneGlyph);
@@ -238,48 +211,6 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob,
238
211
}
239
212
}
240
213
241
- void GrTextContext::AppendGlyph (GrTextBlob* blob, int runIndex,
242
- GrGlyphCache* grGlyphCache,
243
- sk_sp<GrTextStrike>* strike,
244
- const SkGlyph& skGlyph, GrGlyph::MaskStyle maskStyle,
245
- SkScalar sx, SkScalar sy,
246
- GrColor color, SkGlyphCache* skGlyphCache,
247
- SkScalar textRatio, bool needsTransform) {
248
- if (!*strike) {
249
- *strike = grGlyphCache->getStrike (skGlyphCache);
250
- }
251
-
252
- GrGlyph::PackedID id = GrGlyph::Pack (skGlyph.getGlyphID (),
253
- skGlyph.getSubXFixed (),
254
- skGlyph.getSubYFixed (),
255
- maskStyle);
256
- GrGlyph* glyph = (*strike)->getGlyph (skGlyph, id, skGlyphCache);
257
- if (!glyph) {
258
- return ;
259
- }
260
-
261
- SkASSERT (skGlyph.fWidth == glyph->width ());
262
- SkASSERT (skGlyph.fHeight == glyph->height ());
263
-
264
- SkRect glyphRect = rect_to_draw (skGlyph, {sx, sy}, textRatio, maskStyle);
265
-
266
- if (!glyphRect.isEmpty ()) {
267
- // If the glyph is too large we fall back to paths
268
- if (glyph_too_big_for_atlas (skGlyph)) {
269
- if (glyph->fPath != nullptr ) {
270
- const SkPath* glyphPath = skGlyphCache->findPath (skGlyph);
271
- if (glyphPath != nullptr ) {
272
- glyph->fPath = new SkPath (*glyphPath);
273
- }
274
- blob->appendPathGlyph (runIndex, *glyph->fPath , sx, sy, textRatio, !needsTransform);
275
- }
276
- } else {
277
- blob->appendGlyph (runIndex, glyphRect, color, *strike, glyph,
278
- skGlyphCache, skGlyph, sx, sy, textRatio, !needsTransform);
279
- }
280
- }
281
- }
282
-
283
214
void GrTextContext::drawGlyphRunList (
284
215
GrContext* context, GrTextUtils::Target* target, const GrClip& clip,
285
216
const SkMatrix& viewMatrix, const SkSurfaceProps& props, const SkGlyphRunList& glyphRunList,
@@ -522,6 +453,52 @@ void GrTextContext::DrawBmpPosTextAsPaths(GrTextBlob* blob, int runIndex,
522
453
fallbackTextHelper.drawText (blob, runIndex, glyphCache, props, origPaint, scalerContextFlags);
523
454
}
524
455
456
+ void GrTextContext::AppendGlyph (GrTextBlob* blob, int runIndex,
457
+ GrGlyphCache* grGlyphCache,
458
+ sk_sp<GrTextStrike>* strike,
459
+ const SkGlyph& skGlyph, GrGlyph::MaskStyle maskStyle,
460
+ SkScalar sx, SkScalar sy,
461
+ GrColor color, SkGlyphCache* skGlyphCache,
462
+ SkScalar textRatio, bool needsTransform) {
463
+ if (!*strike) {
464
+ *strike = grGlyphCache->getStrike (skGlyphCache);
465
+ }
466
+
467
+ GrGlyph::PackedID id = GrGlyph::Pack (skGlyph.getGlyphID (),
468
+ skGlyph.getSubXFixed (),
469
+ skGlyph.getSubYFixed (),
470
+ maskStyle);
471
+ GrGlyph* glyph = (*strike)->getGlyph (skGlyph, id, skGlyphCache);
472
+ if (!glyph) {
473
+ return ;
474
+ }
475
+
476
+ SkASSERT (skGlyph.fWidth == glyph->width ());
477
+ SkASSERT (skGlyph.fHeight == glyph->height ());
478
+
479
+ SkScalar dx = SkIntToScalar (glyph->fBounds .fLeft );
480
+ SkScalar dy = SkIntToScalar (glyph->fBounds .fTop );
481
+ SkScalar width = SkIntToScalar (glyph->fBounds .width ());
482
+ SkScalar height = SkIntToScalar (glyph->fBounds .height ());
483
+
484
+ if (maskStyle == GrGlyph::kDistance_MaskStyle ) {
485
+ dx += SK_DistanceFieldInset;
486
+ dy += SK_DistanceFieldInset;
487
+ width -= 2 * SK_DistanceFieldInset;
488
+ height -= 2 * SK_DistanceFieldInset;
489
+ }
490
+
491
+ dx *= textRatio;
492
+ dy *= textRatio;
493
+ width *= textRatio;
494
+ height *= textRatio;
495
+
496
+ SkRect glyphRect = SkRect::MakeXYWH (sx + dx, sy + dy, width, height);
497
+
498
+ blob->appendGlyph (runIndex, glyphRect, color, *strike, glyph, skGlyphCache, skGlyph, sx, sy,
499
+ textRatio, !needsTransform);
500
+ }
501
+
525
502
void GrTextContext::SanitizeOptions (Options* options) {
526
503
if (options->fMaxDistanceFieldFontSize < 0 .f ) {
527
504
options->fMaxDistanceFieldFontSize = kDefaultMaxDistanceFieldFontSize ;
0 commit comments