Skip to content

Commit a22d9b6

Browse files
committed
拆分文件
1 parent 03313a0 commit a22d9b6

3 files changed

Lines changed: 93 additions & 86 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using System.Text;
2+
using Oxage.Wmf;
3+
using SkiaSharp;
4+
5+
namespace SkiaWmfRenderer.Rendering;
6+
7+
class WmfRenderStatus : IDisposable
8+
{
9+
public required float CurrentX { get; set; }
10+
public required float CurrentY { get; set; }
11+
12+
public required int Width { get; set; }
13+
public required int Height { get; set; }
14+
15+
public int CurrentRecordsIndex { get; set; }
16+
17+
public SKColor CurrentPenColor { get; set; } = SKColors.Empty;
18+
public float CurrentPenThickness { get; set; } = 0;
19+
20+
public float CurrentFontSize { get; set; }
21+
22+
public string? CurrentFontName { get; set; } = null;
23+
24+
public bool IsItalic { get; set; } = false;
25+
public int FontWeight { get; set; } = 400;
26+
27+
public CharacterSet CurrentCharacterSet
28+
{
29+
get => _currentCharacterSet;
30+
set
31+
{
32+
_currentCharacterSet = value;
33+
CurrentEncoding = _currentCharacterSet.CharacterSetToEncoding();
34+
}
35+
}
36+
37+
private CharacterSet _currentCharacterSet = CharacterSet.DEFAULT_CHARSET;
38+
39+
public Encoding CurrentEncoding { get; private set; } = CharacterSet.DEFAULT_CHARSET.CharacterSetToEncoding();
40+
41+
public float LastDxOffset { get; set; } = 0;
42+
43+
public SKColor CurrentTextColor { get; set; } =
44+
SKColors.Black;
45+
46+
public SKPaint Paint { get; } = new SKPaint()
47+
{
48+
IsAntialias = true
49+
};
50+
51+
public SKFont SKFont { get; } = new SKFont();
52+
53+
54+
public void UpdateSkiaTextStatus()
55+
{
56+
var skFont = SKFont;
57+
skFont.Size = CurrentFontSize;
58+
skFont.Typeface = SKTypeface.FromFamilyName(CurrentFontName, (SKFontStyleWeight) FontWeight,
59+
SKFontStyleWidth.Normal, IsItalic ? SKFontStyleSlant.Italic : SKFontStyleSlant.Upright);
60+
61+
Paint.Style = SKPaintStyle.Fill;
62+
Paint.Color = CurrentTextColor;
63+
}
64+
65+
public void UpdateSkiaStrokeStatus()
66+
{
67+
Paint.IsStroke = true;
68+
Paint.Color = CurrentPenColor;
69+
Paint.StrokeWidth = CurrentPenThickness;
70+
Paint.Style = SKPaintStyle.Stroke;
71+
}
72+
73+
public void Dispose()
74+
{
75+
Paint.Dispose();
76+
SKFont.Dispose();
77+
}
78+
}

Workbench/Wmf/SkiaWmfRenderer/src/SkiaWmfRenderer/Rendering/WmfRenderer.cs

Lines changed: 14 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,11 @@
1-
using Oxage.Wmf;
2-
using SkiaSharp;
3-
using System.Diagnostics.CodeAnalysis;
1+
using System.Diagnostics.CodeAnalysis;
42
using System.Drawing;
5-
using System.Text;
6-
using System.Xml;
3+
using Oxage.Wmf;
74
using Oxage.Wmf.Records;
8-
using static System.Net.Mime.MediaTypeNames;
5+
using SkiaSharp;
96

107
namespace 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-
859
class 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
}

Workbench/Wmf/SkiaWmfRenderer/src/SkiaWmfRenderer/SkiaWmfRenderHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public static bool TryRender(FileInfo wmfFile, int requestWidth, int requestHeig
3030

3131
using var fileStream = wmfFile.OpenRead();
3232
var wmfDocument = new WmfDocument();
33+
3334
try
3435
{
3536
wmfDocument.Load(fileStream);

0 commit comments

Comments
 (0)