Skip to content

Commit e1b7107

Browse files
committed
加上默认的字体
1 parent 6f045b4 commit e1b7107

File tree

4 files changed

+46
-21
lines changed

4 files changed

+46
-21
lines changed

src/MediaConverters/MediaConverters.Lib/Imaging/Optimizations/EnhancedGraphicsMetafileOptimization.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,9 @@ private static ImageFileOptimizationResult ConvertWithSkiaWmfRenderer(ImageFileO
152152

153153
var skiaWmfRenderConfiguration = new SkiaWmfRenderConfiguration()
154154
{
155-
RequestWidth = requestWidth,
156-
RequestHeight = requestHeight
155+
RequestWidth = requestWidth,
156+
RequestHeight = requestHeight,
157+
FontFolder = new DirectoryInfo(Path.Join(AppContext.BaseDirectory, "Assets", "Fonts"))
157158
};
158159
if (SkiaWmfRenderHelper.TryConvertToPng(file, outputPngFile, skiaWmfRenderConfiguration) && File.Exists(outputPngFile.FullName))
159160
{
Binary file not shown.

src/MediaConverters/MediaConverters.Tool/MediaConverters.Tool.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<ItemGroup>
1717
<None Include="Assets\$(RuntimeIdentifier)\**" CopyToOutputDirectory="PreserveNewest" />
1818
<None Include="Assets\gsfonts\**" CopyToOutputDirectory="PreserveNewest" />
19+
<None Include="Assets\Fonts\**" CopyToOutputDirectory="PreserveNewest" />
1920
</ItemGroup>
2021

2122
<ItemGroup>

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

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -110,36 +110,59 @@ public void UpdateSkiaTextStatus(string text)
110110
_harfBuzzFont = null;
111111
_harfBuzzFace = null;
112112

113-
SKTypeface? typeface;
113+
SKTypeface? typeface = TryGetTypeface();
114+
115+
116+
RenderConfiguration.LogMessage($"CurrentFontName='{CurrentFontName}' get the SKTypeface {(typeface is null ? "is null" : "not null")}. SKTypeface={typeface?.FamilyName} GlyphCount={typeface?.GlyphCount}. Text={text}");
117+
118+
skFont.Typeface = typeface;
119+
120+
Paint.Style = SKPaintStyle.Fill;
121+
Paint.Color = CurrentTextColor;
122+
123+
//Paint.Typeface = typeface;
124+
125+
}
126+
private SKTypeface? TryGetTypeface()
127+
{
114128
if (CurrentFontName == "Symbol")
115129
{
116-
var symbolFontFile = Path.Join(AppContext.BaseDirectory, "StandardSymbolsPS.ttf");
117-
//symbolFontFile = Path.Join(AppContext.BaseDirectory, "symbol.ttf");
118-
typeface = SKTypeface.FromFile(symbolFontFile);
119-
}
120-
else
121-
{
122-
typeface = SKTypeface.FromFamilyName(CurrentFontName, (SKFontStyleWeight) FontWeight,
123-
SKFontStyleWidth.Normal, IsItalic ? SKFontStyleSlant.Italic : SKFontStyleSlant.Upright);
130+
if (RenderConfiguration.SymbolFontFile?.Exists is true)
131+
{
132+
return SKTypeface.FromFile(RenderConfiguration.SymbolFontFile.FullName);
133+
}
124134

125-
if (typeface is null || typeface.GlyphCount == 0)
135+
if (RenderConfiguration.FontFolder is { } fontFolder)
126136
{
127-
var fontFile = Path.Join(AppContext.BaseDirectory, $"{CurrentFontName}.ttf");
128-
if (File.Exists(fontFile))
137+
var symbolFontFile = Path.Join(fontFolder.FullName, "symbol.ttf");
138+
139+
if (File.Exists(symbolFontFile))
140+
{
141+
return SKTypeface.FromFile(symbolFontFile);
142+
}
143+
144+
symbolFontFile = Path.Join(fontFolder.FullName, "StandardSymbolsPS.ttf");
145+
146+
if (File.Exists(symbolFontFile))
129147
{
130-
typeface = SKTypeface.FromFile(fontFile);
148+
return SKTypeface.FromFile(symbolFontFile);
131149
}
132150
}
133151
}
134152

135-
RenderConfiguration.LogMessage($"CurrentFontName='{CurrentFontName}' get the SKTypeface {(typeface is null ? "is null" : "not null")}. SKTypeface={typeface?.FamilyName} GlyphCount={typeface?.GlyphCount}. Text={text}");
136-
137-
skFont.Typeface = typeface;
153+
var typeface = SKTypeface.FromFamilyName(CurrentFontName, (SKFontStyleWeight) FontWeight,
154+
SKFontStyleWidth.Normal, IsItalic ? SKFontStyleSlant.Italic : SKFontStyleSlant.Upright);
138155

139-
Paint.Style = SKPaintStyle.Fill;
140-
Paint.Color = CurrentTextColor;
156+
if ((typeface is null || typeface.GlyphCount == 0) && RenderConfiguration.FontFolder is not null)
157+
{
158+
var fontFile = Path.Join(RenderConfiguration.FontFolder.FullName, $"{CurrentFontName}.ttf");
159+
if (File.Exists(fontFile))
160+
{
161+
typeface = SKTypeface.FromFile(fontFile);
162+
}
163+
}
141164

142-
//Paint.Typeface = typeface;
165+
return typeface;
143166
}
144167

145168
public void UpdateSkiaStrokeStatus()

0 commit comments

Comments
 (0)