@@ -10,16 +10,17 @@ namespace KnowledgePicker.WordCloud.Drawing
10
10
public sealed class SkGraphicEngine : IGraphicEngine < SKBitmap >
11
11
{
12
12
private readonly SKCanvas canvas ;
13
+ private readonly SKColor defaultColor ;
13
14
private readonly SKPaint textPaint ;
14
15
private readonly WordCloudInput wordCloud ;
15
- private readonly bool ownsTextPaint ;
16
16
private bool bitmapExtracted ;
17
17
18
18
private SkGraphicEngine ( ISizer sizer , WordCloudInput wordCloud ,
19
19
SKPaint textPaint )
20
20
{
21
21
Sizer = sizer ;
22
22
this . wordCloud = wordCloud ;
23
+ defaultColor = textPaint . Color ;
23
24
this . textPaint = textPaint ;
24
25
Bitmap = new SKBitmap ( wordCloud . Width , wordCloud . Height ) ;
25
26
canvas = new SKCanvas ( Bitmap ) ;
@@ -31,13 +32,13 @@ public SkGraphicEngine(ISizer sizer, WordCloudInput wordCloud,
31
32
Sizer = sizer ;
32
33
Bitmap = new SKBitmap ( wordCloud . Width , wordCloud . Height ) ;
33
34
canvas = new SKCanvas ( Bitmap ) ;
35
+ defaultColor = SKColor . Parse ( wordCloud . TextColor ) ;
34
36
textPaint = new SKPaint
35
37
{
36
- Color = SKColor . Parse ( wordCloud . TextColor ) ,
38
+ Color = defaultColor ,
37
39
Typeface = font ,
38
40
IsAntialias = antialias
39
41
} ;
40
- ownsTextPaint = true ;
41
42
this . wordCloud = wordCloud ;
42
43
}
43
44
@@ -60,14 +61,22 @@ public void Draw(PointD location, RectangleD measured, string text, int count, s
60
61
// https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/graphics/skiasharp/basics/text.
61
62
textPaint . TextSize = ( float ) Sizer . GetFontSize ( count ) ;
62
63
if ( colorHex != null )
64
+ {
63
65
textPaint . Color = SKColor . Parse ( colorHex ) ;
66
+ }
67
+ else
68
+ {
69
+ textPaint . Color = defaultColor ;
70
+ }
64
71
canvas . DrawText ( text , ( float ) ( location . X - measured . Left ) ,
65
72
( float ) ( location . Y - measured . Top ) , textPaint ) ;
66
73
}
67
74
68
75
public IGraphicEngine < SKBitmap > Clone ( )
69
76
{
70
- return new SkGraphicEngine ( Sizer , wordCloud , textPaint ) ;
77
+ var clonedTextPaint = textPaint . Clone ( ) ;
78
+ clonedTextPaint . Color = defaultColor ;
79
+ return new SkGraphicEngine ( Sizer , wordCloud , clonedTextPaint ) ;
71
80
}
72
81
73
82
public SKBitmap ExtractBitmap ( )
@@ -78,10 +87,7 @@ public SKBitmap ExtractBitmap()
78
87
79
88
public void Dispose ( )
80
89
{
81
- if ( ownsTextPaint )
82
- {
83
- textPaint . Dispose ( ) ;
84
- }
90
+ textPaint . Dispose ( ) ;
85
91
canvas . Dispose ( ) ;
86
92
if ( ! bitmapExtracted )
87
93
{
0 commit comments