@@ -10,16 +10,17 @@ namespace KnowledgePicker.WordCloud.Drawing
1010 public sealed class SkGraphicEngine : IGraphicEngine < SKBitmap >
1111 {
1212 private readonly SKCanvas canvas ;
13+ private readonly SKColor defaultColor ;
1314 private readonly SKPaint textPaint ;
1415 private readonly WordCloudInput wordCloud ;
15- private readonly bool ownsTextPaint ;
1616 private bool bitmapExtracted ;
1717
1818 private SkGraphicEngine ( ISizer sizer , WordCloudInput wordCloud ,
1919 SKPaint textPaint )
2020 {
2121 Sizer = sizer ;
2222 this . wordCloud = wordCloud ;
23+ defaultColor = textPaint . Color ;
2324 this . textPaint = textPaint ;
2425 Bitmap = new SKBitmap ( wordCloud . Width , wordCloud . Height ) ;
2526 canvas = new SKCanvas ( Bitmap ) ;
@@ -31,13 +32,13 @@ public SkGraphicEngine(ISizer sizer, WordCloudInput wordCloud,
3132 Sizer = sizer ;
3233 Bitmap = new SKBitmap ( wordCloud . Width , wordCloud . Height ) ;
3334 canvas = new SKCanvas ( Bitmap ) ;
35+ defaultColor = SKColor . Parse ( wordCloud . TextColor ) ;
3436 textPaint = new SKPaint
3537 {
36- Color = SKColor . Parse ( wordCloud . TextColor ) ,
38+ Color = defaultColor ,
3739 Typeface = font ,
3840 IsAntialias = antialias
3941 } ;
40- ownsTextPaint = true ;
4142 this . wordCloud = wordCloud ;
4243 }
4344
@@ -60,14 +61,22 @@ public void Draw(PointD location, RectangleD measured, string text, int count, s
6061 // https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/graphics/skiasharp/basics/text.
6162 textPaint . TextSize = ( float ) Sizer . GetFontSize ( count ) ;
6263 if ( colorHex != null )
64+ {
6365 textPaint . Color = SKColor . Parse ( colorHex ) ;
66+ }
67+ else
68+ {
69+ textPaint . Color = defaultColor ;
70+ }
6471 canvas . DrawText ( text , ( float ) ( location . X - measured . Left ) ,
6572 ( float ) ( location . Y - measured . Top ) , textPaint ) ;
6673 }
6774
6875 public IGraphicEngine < SKBitmap > Clone ( )
6976 {
70- return new SkGraphicEngine ( Sizer , wordCloud , textPaint ) ;
77+ var clonedTextPaint = textPaint . Clone ( ) ;
78+ clonedTextPaint . Color = defaultColor ;
79+ return new SkGraphicEngine ( Sizer , wordCloud , clonedTextPaint ) ;
7180 }
7281
7382 public SKBitmap ExtractBitmap ( )
@@ -78,10 +87,7 @@ public SKBitmap ExtractBitmap()
7887
7988 public void Dispose ( )
8089 {
81- if ( ownsTextPaint )
82- {
83- textPaint . Dispose ( ) ;
84- }
90+ textPaint . Dispose ( ) ;
8591 canvas . Dispose ( ) ;
8692 if ( ! bitmapExtracted )
8793 {
0 commit comments