1- using Oxage . Wmf ;
2- using SkiaSharp ;
3- using System . Diagnostics . CodeAnalysis ;
1+ using System . Diagnostics . CodeAnalysis ;
42using System . Drawing ;
5- using System . Text ;
6- using System . Xml ;
3+ using Oxage . Wmf ;
74using Oxage . Wmf . Records ;
8- using static System . Net . Mime . MediaTypeNames ;
5+ using SkiaSharp ;
96
107namespace SkiaWmfRenderer . Rendering ;
118
12- class WmfRenderStatus : IDisposable
13- {
14- public required float CurrentX { get ; set ; }
15- public required float CurrentY { get ; set ; }
16-
17- public required int Width { get ; set ; }
18- public required int Height { get ; set ; }
19-
20- public int CurrentRecordsIndex { get ; set ; }
21-
22- public SKColor CurrentPenColor { get ; set ; } = SKColors . Empty ;
23- public float CurrentPenThickness { get ; set ; } = 0 ;
24-
25- public float CurrentFontSize { get ; set ; }
26-
27- public string ? CurrentFontName { get ; set ; } = null ;
28-
29- public bool IsItalic { get ; set ; } = false ;
30- public int FontWeight { get ; set ; } = 400 ;
31-
32- public CharacterSet CurrentCharacterSet
33- {
34- get => _currentCharacterSet ;
35- set
36- {
37- _currentCharacterSet = value ;
38- CurrentEncoding = _currentCharacterSet . CharacterSetToEncoding ( ) ;
39- }
40- }
41-
42- private CharacterSet _currentCharacterSet = CharacterSet . DEFAULT_CHARSET ;
43-
44- public Encoding CurrentEncoding { get ; private set ; } = CharacterSet . DEFAULT_CHARSET . CharacterSetToEncoding ( ) ;
45-
46- public float LastDxOffset { get ; set ; } = 0 ;
47-
48- public SKColor CurrentTextColor { get ; set ; } =
49- SKColors . Black ;
50-
51- public SKPaint Paint { get ; } = new SKPaint ( )
52- {
53- IsAntialias = true
54- } ;
55-
56- public SKFont SKFont { get ; } = new SKFont ( ) ;
57-
58-
59- public void UpdateSkiaTextStatus ( )
60- {
61- var skFont = SKFont ;
62- skFont . Size = CurrentFontSize ;
63- skFont . Typeface = SKTypeface . FromFamilyName ( CurrentFontName , ( SKFontStyleWeight ) FontWeight ,
64- SKFontStyleWidth . Normal , IsItalic ? SKFontStyleSlant . Italic : SKFontStyleSlant . Upright ) ;
65-
66- Paint . Style = SKPaintStyle . Fill ;
67- Paint . Color = CurrentTextColor ;
68- }
69-
70- public void UpdateSkiaStrokeStatus ( )
71- {
72- Paint . IsStroke = true ;
73- Paint . Color = CurrentPenColor ;
74- Paint . StrokeWidth = CurrentPenThickness ;
75- Paint . Style = SKPaintStyle . Stroke ;
76- }
77-
78- public void Dispose ( )
79- {
80- Paint . Dispose ( ) ;
81- SKFont . Dispose ( ) ;
82- }
83- }
84-
859class WmfRenderer
8610{
8711 public required WmfDocument WmfDocument { get ; init ; }
@@ -161,7 +85,8 @@ private bool TryRenderInner(SKCanvas canvas, WmfRenderStatus renderStatus)
16185 {
16286 Color color = createPenIndirectRecord . Color ;
16387 renderStatus . CurrentPenColor = new SKColor ( color . R , color . G , color . B , color . A ) ;
164- renderStatus . CurrentPenThickness = Math . Max ( createPenIndirectRecord . Width . X , createPenIndirectRecord . Width . Y ) ;
88+ renderStatus . CurrentPenThickness =
89+ Math . Max ( createPenIndirectRecord . Width . X , createPenIndirectRecord . Width . Y ) ;
16590 break ;
16691 }
16792 // - [11] {== WmfMoveToRecord ==
@@ -188,7 +113,8 @@ private bool TryRenderInner(SKCanvas canvas, WmfRenderStatus renderStatus)
188113 //paint.Color = currentPenColor;
189114 //paint.StrokeWidth = currentPenThickness;
190115
191- canvas . DrawLine ( renderStatus . CurrentX , renderStatus . CurrentY , lineToRecord . X , lineToRecord . Y , renderStatus . Paint ) ;
116+ canvas . DrawLine ( renderStatus . CurrentX , renderStatus . CurrentY , lineToRecord . X , lineToRecord . Y ,
117+ renderStatus . Paint ) ;
192118
193119 break ;
194120 }
@@ -226,8 +152,8 @@ private bool TryRenderInner(SKCanvas canvas, WmfRenderStatus renderStatus)
226152 case WmfCreateFontIndirectRecord createFontIndirectRecord :
227153 {
228154 // "Times New Roman\0è±ñwñ±ñw @ów³\u0011fÁ"
229- renderStatus . CurrentFontName = createFontIndirectRecord . FaceName . ToString ( ) ;
230- renderStatus . CurrentCharacterSet = createFontIndirectRecord . CharSet ;
155+ renderStatus . CurrentFontName = createFontIndirectRecord . FaceName . ToString ( ) ;
156+ renderStatus . CurrentCharacterSet = createFontIndirectRecord . CharSet ;
231157
232158 // Width (2 bytes): A 16-bit signed integer that defines the average width, in logical units, of characters in the font. If Width is 0x0000, the aspect ratio of the device SHOULD be matched against the digitization aspect ratio of the available fonts to find the closest match, determined by the absolute value of the difference.
233159 var fontWidth = createFontIndirectRecord . Width ;
@@ -297,7 +223,8 @@ private bool TryRenderInner(SKCanvas canvas, WmfRenderStatus renderStatus)
297223
298224 if ( dxLength == 0 )
299225 {
300- canvas . DrawText ( text , currentXOffset , renderStatus . CurrentY + ty , renderStatus . SKFont , renderStatus . Paint ) ;
226+ canvas . DrawText ( text , currentXOffset , renderStatus . CurrentY + ty , renderStatus . SKFont ,
227+ renderStatus . Paint ) ;
301228 }
302229 else
303230 {
@@ -323,7 +250,8 @@ private bool TryRenderInner(SKCanvas canvas, WmfRenderStatus renderStatus)
323250
324251 for ( var textIndex = 0 ; textIndex < text . Length ; textIndex ++ )
325252 {
326- canvas . DrawText ( text [ textIndex ] . ToString ( ) , currentXOffset , renderStatus . CurrentY + ty , renderStatus . SKFont ,
253+ canvas . DrawText ( text [ textIndex ] . ToString ( ) , currentXOffset ,
254+ renderStatus . CurrentY + ty , renderStatus . SKFont ,
327255 renderStatus . Paint ) ;
328256
329257 currentXOffset += dxArray [ textIndex ] ;
@@ -344,7 +272,7 @@ private bool TryRenderInner(SKCanvas canvas, WmfRenderStatus renderStatus)
344272 return true ;
345273 }
346274
347- private static SKColor ToSKColor ( Color color )
275+ private static SKColor ToSKColor ( Color color )
348276 {
349277 return new SKColor ( color . R , color . G , color . B , color . A ) ;
350278 }
0 commit comments