@@ -189,8 +189,7 @@ SkRect TextLine::calculateBoundaries() {
189189 boundaries.fBottom += shadowRect.fBottom ;
190190 }
191191
192- boundaries.offset (this ->fOffset ); // Line offset from the beginning of the para
193- boundaries.offset (this ->fShift , 0 ); // Shift produced by formatting
192+ boundaries.offset (this ->offset ()); // Line offset from the beginning of the para
194193 boundaries.offset (0 , this ->baseline ()); // Down by baseline
195194
196195 return boundaries;
@@ -201,9 +200,6 @@ void TextLine::paint(SkCanvas* textCanvas) {
201200 return ;
202201 }
203202
204- textCanvas->save ();
205- textCanvas->translate (this ->offset ().fX , this ->offset ().fY );
206-
207203 if (fHasBackground ) {
208204 this ->iterateThroughVisualRuns (false ,
209205 [textCanvas, this ]
@@ -257,8 +253,6 @@ void TextLine::paint(SkCanvas* textCanvas) {
257253 return true ;
258254 });
259255 }
260-
261- textCanvas->restore ();
262256}
263257
264258void TextLine::format (TextAlign align, SkScalar maxWidth) {
@@ -348,19 +342,21 @@ void TextLine::paintText(SkCanvas* canvas, TextRange textRange, const TextStyle&
348342 SkScalar correctedBaseline = SkScalarFloorToScalar (this ->baseline () + 0.5 );
349343 SkTextBlobBuilder builder;
350344 context.run ->copyTo (builder, SkToU32 (context.pos ), context.size , SkVector::Make (0 , correctedBaseline));
351- canvas->save ();
352345 if (context.clippingNeeded ) {
353- canvas->clipRect (extendHeight (context));
346+ canvas->save ();
347+ canvas->clipRect (extendHeight (context).makeOffset (this ->offset ()));
354348 }
355349
356- canvas->translate (context.fTextShift , 0 );
357- canvas->drawTextBlob (builder.make (), 0 , 0 , paint);
358- canvas->restore ();
350+ canvas->drawTextBlob (builder.make (), this ->offset ().fX + context.fTextShift , this ->offset ().fY , paint);
351+
352+ if (context.clippingNeeded ) {
353+ canvas->restore ();
354+ }
359355}
360356
361357void TextLine::paintBackground (SkCanvas* canvas, TextRange textRange, const TextStyle& style, const ClipContext& context) const {
362358 if (style.hasBackground ()) {
363- canvas->drawRect (context.clip , style.getBackground ());
359+ canvas->drawRect (context.clip . makeOffset ( this -> offset ()) , style.getBackground ());
364360 }
365361}
366362
@@ -379,24 +375,28 @@ void TextLine::paintShadow(SkCanvas* canvas, TextRange textRange, const TextStyl
379375
380376 SkTextBlobBuilder builder;
381377 context.run ->copyTo (builder, context.pos , context.size , SkVector::Make (0 , shiftDown));
382- canvas->save ();
383- SkRect clip = context.clip ;
384- clip.offset (shadow.fOffset );
378+
385379 if (context.clippingNeeded ) {
386- canvas->clipRect (extendHeight (context));
380+ canvas->save ();
381+ SkRect clip = extendHeight (context);
382+ clip.offset (this ->offset ());
383+ canvas->clipRect (clip);
384+ }
385+ canvas->drawTextBlob (builder.make (), this ->offset ().fX + context.fTextShift + shadow.fOffset .x (), this ->offset ().fY + shadow.fOffset .y (), paint);
386+
387+ if (context.clippingNeeded ) {
388+ canvas->restore ();
387389 }
388- canvas->translate (context.fTextShift , 0 );
389- canvas->drawTextBlob (builder.make (), shadow.fOffset .x (), shadow.fOffset .y (), paint);
390- canvas->restore ();
391390 }
392391}
393392
394393void TextLine::paintDecorations (SkCanvas* canvas, TextRange textRange, const TextStyle& style, const ClipContext& context) const {
395394
395+ SkAutoCanvasRestore acr (canvas, true );
396+ canvas->translate (this ->offset ().fX , this ->offset ().fY );
396397 Decorations decorations;
397398 SkScalar correctedBaseline = SkScalarFloorToScalar (this ->baseline () + 0.5 );
398- decorations.paint (canvas, style, context, correctedBaseline, this ->fShift );
399-
399+ decorations.paint (canvas, style, context, correctedBaseline, this ->offset ());
400400}
401401
402402void TextLine::justify (SkScalar maxWidth) {
0 commit comments