66
77namespace ManagedCode . FileContext ;
88
9- // Skia 3 retains these text overloads; keep their compatibility use in one adapter.
10- #pragma warning disable CS0618
119internal static class ReportCanvas
1210{
1311 private const float BoldStrokeWidth = .35f ;
@@ -19,15 +17,14 @@ internal static class ReportCanvas
1917 return SKTypeface . FromStream ( stream ) ?? throw new InvalidOperationException ( "The bundled report font cannot be loaded." ) ;
2018 } ) ;
2119
22- public static SKPaint Paint ( SKColor color , float size = 0 , float stroke = 0 , bool bold = false ) => new ( )
23- {
24- Color = color ,
25- IsAntialias = true ,
26- Typeface = Typeface . Value ,
27- TextSize = size ,
28- Style = StyleFor ( bold , stroke ) ,
29- StrokeWidth = bold ? BoldStrokeWidth : stroke
30- } ;
20+ public static ReportPaint Paint ( SKColor color , float size = 0 , float stroke = 0 , bool bold = false ) =>
21+ new ( new SKPaint
22+ {
23+ Color = color ,
24+ IsAntialias = true ,
25+ Style = StyleFor ( bold , stroke ) ,
26+ StrokeWidth = bold ? BoldStrokeWidth : stroke
27+ } , new SKFont { Typeface = Typeface . Value , Size = size } ) ;
3128
3229 private static SKPaintStyle StyleFor ( bool bold , float stroke )
3330 {
@@ -41,18 +38,18 @@ public static SKColor Parse(string value)
4138 return color ;
4239 }
4340
44- public static void RequireFits ( string value , SKPaint paint , float width , string field )
41+ public static void RequireFits ( string value , ReportPaint paint , float width , string field )
4542 {
4643 if ( MeasureText ( value , paint ) > width )
4744 { throw new ArgumentException ( $ "{ field } does not fit the available chart space; use a shorter label or a wider page.") ; }
4845 }
4946
50- public static void Text ( SKCanvas canvas , string value , float x , float y , SKPaint paint ) =>
51- canvas . DrawText ( value , x , y , paint ) ;
47+ public static void Text ( SKCanvas canvas , string value , float x , float y , ReportPaint paint ) =>
48+ canvas . DrawText ( value , x , y , SKTextAlign . Left , paint . Font , paint . ColorPaint ) ;
5249
53- public static float MeasureText ( string value , SKPaint paint ) => paint . MeasureText ( value ) ;
50+ public static float MeasureText ( string value , ReportPaint paint ) => paint . Font . MeasureText ( value , paint . ColorPaint ) ;
5451
55- public static IReadOnlyList < string > Wrap ( string value , SKPaint paint , float width )
52+ public static IReadOnlyList < string > Wrap ( string value , ReportPaint paint , float width )
5653 {
5754 var lines = new List < string > ( ) ;
5855 foreach ( var paragraph in value . Replace ( "\r \n " , "\n " , StringComparison . Ordinal ) . Replace ( '\r ' , '\n ' ) . Split ( '\n ' ) )
@@ -61,7 +58,7 @@ public static IReadOnlyList<string> Wrap(string value, SKPaint paint, float widt
6158 foreach ( var rune in paragraph . EnumerateRunes ( ) )
6259 {
6360 var candidate = current + rune ;
64- if ( paint . MeasureText ( candidate ) > width && current . Length > 0 )
61+ if ( MeasureText ( candidate , paint ) > width && current . Length > 0 )
6562 {
6663 lines . Add ( current ) ;
6764 current = rune . ToString ( ) ;
@@ -74,5 +71,3 @@ public static IReadOnlyList<string> Wrap(string value, SKPaint paint, float widt
7471 }
7572
7673}
77-
78- #pragma warning restore CS0618
0 commit comments