@@ -392,16 +392,12 @@ void SkPaint::getPosTextPath(const void* text, size_t length,
392392}
393393
394394template <SkTextInterceptsIter::TextType TextType, typename Func>
395- int GetTextIntercepts (const SkPaint& paint, const void * text, size_t length,
396- const SkScalar bounds[2 ], SkScalar* array, Func posMaker) {
397- SkASSERT (length == 0 || text != nullptr );
398- if (!length) {
399- return 0 ;
400- }
395+ int GetTextIntercepts (const SkFont& font, const SkPaint& paint, const SkGlyphID glyphs[],
396+ int glyphCount, const SkScalar bounds[2 ], SkScalar* array, Func posMaker) {
397+ SkASSERT (glyphCount == 0 || glyphs != nullptr );
401398
402399 const SkPoint pos0 = posMaker (0 );
403- SkTextInterceptsIter iter (static_cast <const char *>(text), length, paint, bounds,
404- pos0.x (), pos0.y (), TextType);
400+ SkTextInterceptsIter iter (glyphs, glyphCount, font, paint, bounds, pos0.x (), pos0.y (), TextType);
405401
406402 int i = 0 ;
407403 int count = 0 ;
@@ -415,59 +411,56 @@ int GetTextIntercepts(const SkPaint& paint, const void* text, size_t length,
415411 return count;
416412}
417413
418- int SkPaint::getTextIntercepts (const void * textData, size_t length ,
414+ int SkPaint::getTextIntercepts (const SkFont& font, const SkGlyphID glyphs[], int count ,
419415 SkScalar x, SkScalar y, const SkScalar bounds[2 ],
420416 SkScalar* array) const {
421417
422418 return GetTextIntercepts<SkTextInterceptsIter::TextType::kText >(
423- *this , textData, length , bounds, array, [&x, &y] (int ) -> SkPoint {
419+ font, *this , glyphs, count , bounds, array, [&x, &y] (int ) -> SkPoint {
424420 return SkPoint::Make (x, y);
425421 });
426422}
427423
428- int SkPaint::getPosTextIntercepts (const void * textData, size_t length, const SkPoint pos[],
429- const SkScalar bounds[2 ], SkScalar* array) const {
424+ int SkPaint::getPosTextIntercepts (const SkFont& font, const SkGlyphID glyphs[], int count,
425+ const SkPoint pos[], const SkScalar bounds[2 ],
426+ SkScalar* array) const {
430427
431428 return GetTextIntercepts<SkTextInterceptsIter::TextType::kPosText >(
432- *this , textData, length , bounds, array, [&pos] (int i) -> SkPoint {
429+ font, *this , glyphs, count , bounds, array, [&pos] (int i) -> SkPoint {
433430 return pos[i];
434431 });
435432}
436433
437- int SkPaint::getPosTextHIntercepts (const void * textData, size_t length, const SkScalar xpos[] ,
438- SkScalar constY, const SkScalar bounds[2 ],
434+ int SkPaint::getPosTextHIntercepts (const SkFont& font, const SkGlyphID glyphs[], int count ,
435+ const SkScalar xpos[], SkScalar constY, const SkScalar bounds[2 ],
439436 SkScalar* array) const {
440437
441438 return GetTextIntercepts<SkTextInterceptsIter::TextType::kPosText >(
442- *this , textData, length , bounds, array, [&xpos, &constY] (int i) -> SkPoint {
439+ font, *this , glyphs, count , bounds, array, [&xpos, &constY] (int i) -> SkPoint {
443440 return SkPoint::Make (xpos[i], constY);
444441 });
445442}
446443
447444int SkPaint::getTextBlobIntercepts (const SkTextBlob* blob, const SkScalar bounds[2 ],
448445 SkScalar* intervals) const {
449446 int count = 0 ;
450- SkPaint runPaint (*this );
451-
452447 SkTextBlobRunIterator it (blob);
448+
453449 while (!it.done ()) {
454- it.applyFontToPaint (&runPaint);
455- const size_t runByteCount = it.glyphCount () * sizeof (SkGlyphID);
456450 SkScalar* runIntervals = intervals ? intervals + count : nullptr ;
457451
458452 switch (it.positioning ()) {
459453 case SkTextBlobRunIterator::kDefault_Positioning :
460- count += runPaint. getTextIntercepts (it.glyphs (), runByteCount , it.offset ().x (),
461- it.offset ().y (), bounds, runIntervals);
454+ count += this -> getTextIntercepts (it.font (), it. glyphs (), it. glyphCount () , it.offset ().x (),
455+ it.offset ().y (), bounds, runIntervals);
462456 break ;
463457 case SkTextBlobRunIterator::kHorizontal_Positioning :
464- count += runPaint. getPosTextHIntercepts (it.glyphs (), runByteCount , it.pos (),
465- it.offset ().y (), bounds, runIntervals);
458+ count += this -> getPosTextHIntercepts (it.font (), it. glyphs (), it. glyphCount () , it.pos (),
459+ it.offset ().y (), bounds, runIntervals);
466460 break ;
467461 case SkTextBlobRunIterator::kFull_Positioning :
468- count += runPaint.getPosTextIntercepts (it.glyphs (), runByteCount,
469- reinterpret_cast <const SkPoint*>(it.pos ()),
470- bounds, runIntervals);
462+ count += this ->getPosTextIntercepts (it.font (), it.glyphs (), it.glyphCount (),
463+ reinterpret_cast <const SkPoint*>(it.pos ()), bounds, runIntervals);
471464 break ;
472465 }
473466
@@ -510,23 +503,19 @@ static bool has_thick_frame(const SkPaint& paint) {
510503 paint.getStyle () != SkPaint::kFill_Style ;
511504}
512505
513- SkTextBaseIter::SkTextBaseIter (const char text [], size_t length ,
514- const SkPaint& paint,
515- bool applyStrokeAndPathEffects )
516- : fPaint(paint) {
517- fGlyphCacheProc = SkFontPriv::GetGlyphCacheProc (paint. getTextEncoding (), true );
506+ SkTextBaseIter::SkTextBaseIter (const SkGlyphID glyphs [], int count, const SkFont& font ,
507+ const SkPaint& paint)
508+ : fFont(font), fPaint(paint )
509+ {
510+ SkAssertResult (count >= 0 );
518511
519- fPaint . setLinearText (true );
512+ fFont . setLinearMetrics (true );
520513 fPaint .setMaskFilter (nullptr ); // don't want this affecting our path-cache lookup
521514
522- if (fPaint .getPathEffect () == nullptr && !has_thick_frame (fPaint )) {
523- applyStrokeAndPathEffects = false ;
524- }
525-
526515 // can't use our canonical size if we need to apply patheffects
527516 if (fPaint .getPathEffect () == nullptr ) {
528- fPaint . setTextSize ( SkIntToScalar ( SkPaint::kCanonicalTextSizeForPaths )) ;
529- fScale = paint. getTextSize () / SkPaint::kCanonicalTextSizeForPaths ;
517+ fScale = fFont . getSize () / SkPaint::kCanonicalTextSizeForPaths ;
518+ fFont . setSize ( SkIntToScalar ( SkPaint::kCanonicalTextSizeForPaths )) ;
530519 // Note: fScale can be zero here (even if it wasn't before the divide). It can also
531520 // be very very small. We call sk_ieee_float_divide below to ensure IEEE divide behavior,
532521 // since downstream we will check for the resulting coordinates being non-finite anyway.
@@ -538,24 +527,13 @@ SkTextBaseIter::SkTextBaseIter(const char text[], size_t length,
538527 fScale = SK_Scalar1;
539528 }
540529
541- if (!applyStrokeAndPathEffects) {
542- fPaint .setStyle (SkPaint::kFill_Style );
543- fPaint .setPathEffect (nullptr );
544- }
545-
546- // SRGBTODO: Is this correct?
547- const SkFont font = SkFont::LEGACY_ExtractFromPaint (fPaint );
548- fCache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive (font, fPaint );
530+ fPaint .setStyle (SkPaint::kFill_Style );
531+ fPaint .setPathEffect (nullptr );
549532
550- SkPaint::Style style = SkPaint::kFill_Style ;
551- sk_sp<SkPathEffect> pe;
533+ fCache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive (fFont , fPaint );
552534
553- if (!applyStrokeAndPathEffects) {
554- style = paint.getStyle (); // restore
555- pe = paint.refPathEffect (); // restore
556- }
557- fPaint .setStyle (style);
558- fPaint .setPathEffect (pe);
535+ fPaint .setStyle (paint.getStyle ());
536+ fPaint .setPathEffect (paint.refPathEffect ());
559537 fPaint .setMaskFilter (paint.refMaskFilter ()); // restore
560538
561539 // now compute fXOffset if needed
@@ -564,41 +542,18 @@ SkTextBaseIter::SkTextBaseIter(const char text[], size_t length,
564542 fXPos = xOffset;
565543 fPrevAdvance = 0 ;
566544
567- fText = text;
568- fStop = text + length;
569- }
570-
571- bool SkTextToPathIter::next (const SkPath** path, SkScalar* xpos) {
572- if (fText < fStop ) {
573- const SkGlyph& glyph = fGlyphCacheProc (fCache .get (), &fText , fStop );
574-
575- fXPos += fPrevAdvance * fScale ;
576- fPrevAdvance = advance (glyph); // + fPaint.getTextTracking();
577-
578- if (glyph.fWidth ) {
579- if (path) {
580- *path = fCache ->findPath (glyph);
581- }
582- } else {
583- if (path) {
584- *path = nullptr ;
585- }
586- }
587- if (xpos) {
588- *xpos = fXPos ;
589- }
590- return true ;
591- }
592- return false ;
545+ fGlyphs = glyphs;
546+ fStop = glyphs + count;
593547}
594548
595549bool SkTextInterceptsIter::next (SkScalar* array, int * count) {
596- const SkGlyph& glyph = fGlyphCacheProc (fCache .get (), &fText , fStop );
550+ SkASSERT (fGlyphs < fStop );
551+ const SkGlyph& glyph = fCache ->getGlyphIDMetrics (*fGlyphs ++);
597552 fXPos += fPrevAdvance * fScale ;
598553 fPrevAdvance = advance (glyph); // + fPaint.getTextTracking();
599554 if (fCache ->findPath (glyph)) {
600555 fCache ->findIntercepts (fBounds , fScale , fXPos , false ,
601556 const_cast <SkGlyph*>(&glyph), array, count);
602557 }
603- return fText < fStop ;
558+ return fGlyphs < fStop ;
604559}
0 commit comments