@@ -82,7 +82,9 @@ TextLine::TextLine(ParagraphImpl* master,
8282 , fSizes (sizes)
8383 , fHasBackground (false )
8484 , fHasShadows (false )
85- , fHasDecorations (false ) {
85+ , fHasDecorations (false )
86+ , fAscentStyle (LineMetricStyle::CSS)
87+ , fDescentStyle (LineMetricStyle::CSS) {
8688 // Reorder visual runs
8789 auto & start = master->cluster (fGhostClusterRange .start );
8890 auto & end = master->cluster (fGhostClusterRange .end - 1 );
@@ -317,9 +319,13 @@ SkScalar TextLine::metricsWithoutMultiplier(TextHeightBehavior correction) {
317319 });
318320 SkScalar delta = 0 ;
319321 if (correction == TextHeightBehavior::kDisableFirstAscent ) {
320- delta += (this ->fSizes .ascent () - result.ascent ());
322+ delta += (this ->fSizes .fAscent - result.fAscent );
323+ this ->fSizes .fAscent -= delta;
324+ this ->fAscentStyle = LineMetricStyle::Typographic;
321325 } else if (correction == TextHeightBehavior::kDisableLastDescent ) {
322- delta -= (this ->fSizes .descent () - result.descent ());
326+ delta -= (this ->fSizes .fDescent - result.fDescent );
327+ this ->fSizes .fDescent -= delta;
328+ this ->fDescentStyle = LineMetricStyle::Typographic;
323329 }
324330 fAdvance .fY += delta;
325331 return delta;
@@ -545,7 +551,7 @@ Run* TextLine::shapeEllipsis(const SkString& ellipsis, Run* run) {
545551 SkString fEllipsis ;
546552 };
547553
548- ShapeHandler handler (run->lineHeight (), ellipsis);
554+ ShapeHandler handler (run->heightMultiplier (), ellipsis);
549555 std::unique_ptr<SkShaper> shaper = SkShaper::MakeShapeDontWrapOrReorder ();
550556 SkASSERT_RELEASE (shaper != nullptr );
551557 shaper->shape (ellipsis.c_str (), ellipsis.size (), run->font (), true ,
@@ -568,22 +574,21 @@ TextLine::ClipContext TextLine::measureTextInsideOneRun(TextRange textRange,
568574 SkASSERT (textRange == run->textRange ());
569575 result.fTextShift = runOffsetInLine;
570576 result.clip = SkRect::MakeXYWH (runOffsetInLine,
571- sizes ().runTop (run),
577+ sizes ().runTop (run, this -> fAscentStyle ),
572578 run->advance ().fX ,
573- run->calculateHeight ());
579+ run->calculateHeight (this -> fAscentStyle , this -> fDescentStyle ));
574580 return result;
575581 } else if (run->isPlaceholder ()) {
576582 if (SkScalarIsFinite (run->fFontMetrics .fAscent )) {
577583 result.clip = SkRect::MakeXYWH (runOffsetInLine,
578- sizes ().runTop (run),
584+ sizes ().runTop (run, this -> fAscentStyle ),
579585 run->advance ().fX ,
580- run->calculateHeight ());
586+ run->calculateHeight (this -> fAscentStyle , this -> fDescentStyle ));
581587 } else {
582588 result.clip = SkRect::MakeXYWH (runOffsetInLine, run->fFontMetrics .fAscent , run->advance ().fX , 0 );
583589 }
584590 return result;
585591 }
586-
587592 // Find [start:end] clusters for the text
588593 bool found;
589594 ClusterIndex startIndex;
@@ -617,9 +622,9 @@ TextLine::ClipContext TextLine::measureTextInsideOneRun(TextRange textRange,
617622 // coming from letter spacing or word spacing or justification)
618623 result.clip =
619624 SkRect::MakeXYWH (0 ,
620- sizes ().runTop (run),
625+ sizes ().runTop (run, this -> fAscentStyle ),
621626 run->calculateWidth (result.pos , result.pos + result.size , false ),
622- run->calculateHeight ());
627+ run->calculateHeight (this -> fAscentStyle , this -> fDescentStyle ));
623628
624629 // Correct the width in case the text edges don't match clusters
625630 // TODO: This is where we get smart about selecting a part of a cluster
@@ -908,27 +913,27 @@ void TextLine::getRectsForRange(TextRange textRange0,
908913 clip.fBottom = this ->height ();
909914 clip.fTop = this ->sizes ().delta ();
910915 break ;
911- case RectHeightStyle::kIncludeLineSpacingTop :
912- if (!isFirstLine ()) {
913- clip.fTop -= this ->sizes ().runTop (context.run );
914- }
915- clip.fBottom -= this ->sizes ().runTop (context.run );
916- break ;
917- case RectHeightStyle::kIncludeLineSpacingMiddle :
918- if (!isFirstLine ()) {
919- clip.fTop -= this ->sizes ().runTop (context.run ) / 2 ;
916+ case RectHeightStyle::kIncludeLineSpacingTop : {
917+ if (isFirstLine ()) {
918+ auto verticalShift = this ->sizes ().runTop (context.run , LineMetricStyle::Typographic);
919+ clip.fTop += verticalShift;
920920 }
921+ break ;
922+ }
923+ case RectHeightStyle::kIncludeLineSpacingMiddle : {
924+ auto verticalShift = this ->sizes ().runTop (context.run , LineMetricStyle::Typographic);
925+ clip.fTop += isFirstLine () ? verticalShift : verticalShift / 2 ;
926+ clip.fBottom += isLastLine () ? 0 : verticalShift / 2 ;
927+ break ;
928+ }
929+ case RectHeightStyle::kIncludeLineSpacingBottom : {
930+ auto verticalShift = this ->sizes ().runTop (context.run , LineMetricStyle::Typographic);
931+ clip.offset (0 , verticalShift);
921932 if (isLastLine ()) {
922- clip.fBottom -= this ->sizes ().runTop (context.run );
923- } else {
924- clip.fBottom -= this ->sizes ().runTop (context.run ) / 2 ;
925- }
926- break ;
927- case RectHeightStyle::kIncludeLineSpacingBottom :
928- if (isLastLine ()) {
929- clip.fBottom -= this ->sizes ().runTop (context.run );
933+ clip.fBottom -= verticalShift;
930934 }
931- break ;
935+ break ;
936+ }
932937 case RectHeightStyle::kStrut : {
933938 auto strutStyle = paragraphStyle.getStrutStyle ();
934939 if (strutStyle.getStrutEnabled ()
@@ -940,11 +945,15 @@ void TextLine::getRectsForRange(TextRange textRange0,
940945 }
941946 }
942947 break ;
943- case RectHeightStyle::kTight :
948+ case RectHeightStyle::kTight : {
944949 if (run->fHeightMultiplier > 0 ) {
945950 // This is a special case when we do not need to take in account this height multiplier
946- clip.fBottom = clip.fTop + clip.height () / run->fHeightMultiplier ;
951+ auto correctedHeight = clip.height () / run->fHeightMultiplier ;
952+ auto verticalShift = this ->sizes ().runTop (context.run , LineMetricStyle::Typographic);
953+ clip.fTop += verticalShift;
954+ clip.fBottom = clip.fTop + correctedHeight;
947955 }
956+ }
948957 break ;
949958 default :
950959 SkASSERT (false );
@@ -1003,7 +1012,8 @@ void TextLine::getRectsForRange(TextRange textRange0,
10031012 lastRun != nullptr &&
10041013 lastRun->placeholderStyle () == nullptr &&
10051014 context.run ->placeholderStyle () == nullptr &&
1006- nearlyEqual (lastRun->lineHeight (), context.run ->lineHeight ()) &&
1015+ nearlyEqual (lastRun->heightMultiplier (),
1016+ context.run ->heightMultiplier ()) &&
10071017 lastRun->font () == context.run ->font ())
10081018 {
10091019 auto & lastBox = boxes.back ();
0 commit comments