@@ -315,7 +315,7 @@ public override void DrawText(ScreenPoint p, string text, OxyColor fill, string
315315
316316 if ( maxSize . HasValue || halign != HorizontalAlignment . Left || valign != VerticalAlignment . Bottom )
317317 {
318- width = bounds . Width ;
318+ width = bounds . Left + bounds . Width ;
319319 height = lineHeight ;
320320 }
321321 else
@@ -338,6 +338,8 @@ public override void DrawText(ScreenPoint p, string text, OxyColor fill, string
338338
339339 var dx = halign == HorizontalAlignment . Left ? 0d : ( halign == HorizontalAlignment . Center ? - width * 0.5 : - width ) ;
340340 var dy = valign == VerticalAlignment . Bottom ? 0d : ( valign == VerticalAlignment . Middle ? height * 0.5 : height ) ;
341+ var x0 = - bounds . Left ;
342+ var y0 = delta ;
341343
342344 this . SetFill ( fill ) ;
343345 this . SetAlias ( false ) ;
@@ -349,12 +351,13 @@ public override void DrawText(ScreenPoint p, string text, OxyColor fill, string
349351 this . gctx . RotateCTM ( ( float ) ( rotate / 180 * Math . PI ) ) ;
350352 }
351353
352- this . gctx . TranslateCTM ( ( float ) dx - bounds . Left , ( float ) dy + delta ) ;
354+ this . gctx . TranslateCTM ( ( float ) dx + x0 , ( float ) dy + y0 ) ;
353355 this . gctx . ScaleCTM ( 1f , - 1f ) ;
354356
355357 if ( maxSize . HasValue )
356358 {
357- this . gctx . ClipToRect ( new RectangleF ( 0 , 0 , ( float ) Math . Ceiling ( width ) , ( float ) Math . Ceiling ( height ) ) ) ;
359+ var clipRect = new RectangleF ( - x0 , y0 , ( float ) Math . Ceiling ( width ) , ( float ) Math . Ceiling ( height ) ) ;
360+ this . gctx . ClipToRect ( clipRect ) ;
358361 }
359362
360363 textLine . Draw ( this . gctx ) ;
@@ -390,7 +393,7 @@ public override OxySize MeasureText(string text, string fontFamily, double fontS
390393 this . GetFontMetrics ( font , out lineHeight , out delta ) ;
391394 this . gctx . TextPosition = new PointF ( 0 , 0 ) ;
392395 var bounds = textLine . GetImageBounds ( this . gctx ) ;
393- return new OxySize ( bounds . Width , lineHeight ) ;
396+ return new OxySize ( bounds . Left + bounds . Width , lineHeight ) ;
394397 }
395398 }
396399 }
0 commit comments