Skip to content

Commit c1b3aa6

Browse files
committed
测试符号字体渲染是方框
1 parent 519863f commit c1b3aa6

2 files changed

Lines changed: 53 additions & 9 deletions

File tree

src/MediaConverters/SkiaWmfRenderer/samples/sample/Program.cs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System.Text;
77

88
using DocSharp.Markdown;
9-
9+
using SkiaSharp;
1010
using SkiaWmfRenderer;
1111

1212
var markdownText = new StringBuilder();
@@ -31,15 +31,45 @@
3131
Console.WriteLine($"Can not recognition '{args[0]}' as File or Folder");
3232
}
3333
}
34-
else
34+
else
3535
{
36-
// Debug mode
37-
var folder = @"C:\lindexi\wmf公式\";
36+
using var skBitmap = new SKBitmap(300,300,SKColorType.Bgra8888,SKAlphaType.Premul);
37+
skBitmap.Erase(SKColors.White);
38+
using var skCanvas = new SKCanvas(skBitmap);
39+
var text = "p";
40+
using var skPaint = new SKPaint();
41+
skPaint.TextSize = 50;
42+
var symbolFontFile = Path.Join(AppContext.BaseDirectory, "symbol.ttf");
43+
var skTypeface = SKTypeface.FromFile(symbolFontFile);
44+
Console.WriteLine($"Font='{symbolFontFile}' SKTypeface={skTypeface.FamilyName} GlyphCount={skTypeface.GlyphCount}");
45+
Console.WriteLine($"ContainsGlyph={skTypeface.ContainsGlyph('p')}");
46+
skPaint.Typeface = skTypeface;
47+
skPaint.Color = SKColors.Black;
48+
skPaint.IsAntialias = true;
49+
skCanvas.DrawText(text, 50, 100, skPaint);
50+
var outputFile = Path.Join(outputFolder, $"{DateTime.Now:HHmmss}.png");
51+
using var outputStream = File.OpenWrite(outputFile);
52+
skBitmap.Encode(outputStream, SKEncodedImageFormat.Png, 100);
53+
if (File.Exists(outputFile))
54+
{
55+
return;
56+
}
57+
58+
if (OperatingSystem.IsWindows())
59+
{
60+
// Debug mode
61+
var folder = @"C:\lindexi\wmf公式\";
3862

39-
ConvertImageFolder(folder);
63+
ConvertImageFolder(folder);
64+
}
65+
else
66+
{
67+
var file = Path.Join(AppContext.BaseDirectory, "image.wmf");
68+
ConvertImageFile(file);
69+
}
4070
}
4171

42-
var markdownFile = Path.Join(outputFolder, "README.md");
72+
var markdownFile = Path.Join(outputFolder, "README.md");
4373
var markdown = markdownText.ToString();
4474
File.WriteAllText(markdownFile, markdown);
4575

src/MediaConverters/SkiaWmfRenderer/src/SkiaWmfRenderer/Rendering/WmfRenderStatus.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,29 @@ public void UpdateSkiaTextStatus(string text)
6262

6363
skFont.Typeface?.Dispose();
6464

65-
SKTypeface? typeface = SKTypeface.FromFamilyName(CurrentFontName, (SKFontStyleWeight) FontWeight,
66-
SKFontStyleWidth.Normal, IsItalic ? SKFontStyleSlant.Italic : SKFontStyleSlant.Upright);
65+
SKTypeface? typeface;
66+
if (CurrentFontName == "Symbol")
67+
{
68+
var symbolFontFile = Path.Join(AppContext.BaseDirectory, "StandardSymbolsPS.ttf");
69+
symbolFontFile = Path.Join(AppContext.BaseDirectory, "symbol.ttf");
70+
typeface = SKTypeface.FromFile(symbolFontFile);
71+
}
72+
else
73+
{
74+
typeface = SKTypeface.FromFamilyName(CurrentFontName, (SKFontStyleWeight) FontWeight,
75+
SKFontStyleWidth.Normal, IsItalic ? SKFontStyleSlant.Italic : SKFontStyleSlant.Upright);
76+
}
6777

68-
Console.WriteLine($"CurrentFontName='{CurrentFontName}' get the SKTypeface {(typeface is null ? "is null" : "not null")}. Text={text}");
78+
79+
80+
Console.WriteLine($"CurrentFontName='{CurrentFontName}' get the SKTypeface {(typeface is null ? "is null" : "not null")}. SKTypeface={typeface?.FamilyName} GlyphCount={typeface?.GlyphCount}. Text={text}");
6981

7082
skFont.Typeface = typeface;
7183

7284
Paint.Style = SKPaintStyle.Fill;
7385
Paint.Color = CurrentTextColor;
86+
87+
Paint.Typeface = typeface;
7488
}
7589

7690
public void UpdateSkiaStrokeStatus()

0 commit comments

Comments
 (0)