Skip to content

Commit d930568

Browse files
committed
完成字符的正确渲染
1 parent 6e09e3c commit d930568

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/MediaConverters/SkiaWmfRenderer/src/SkiaWmfRenderer/Rendering/RenderTextHelper.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ public static void DrawText(this SKCanvas canvas, string text, float x, float y,
2121

2222
font.Shape(buffer);
2323

24+
// 经过实验测试,发现这里的 GetGlyphInfoSpan 方法返回的 Codepoint 就是 GlyphIndex 的值
25+
// 如 edd88c25d3b92b231df2ed5c7fc0ce9297b98d96 的实验,只要在 HarfBuzzSharp.Font 的 Shape 方法之后,那么获取的 Codepoint 就是 GlyphIndex 的值
26+
// 如其控制台输出的如下内容:
27+
// Typeface=Standard Symbols PS GlyphCount=191
28+
// ContainsGlyph('p')=True 81
29+
// TryGetGlyph=True 81
30+
// (int) 'p' == 112
31+
// Before HarfBuzzSharp.Font.Shape Codepoint=112
32+
// After HarfBuzzSharp.Font.Shape Codepoint=81
33+
// 可见在 StandardSymbolsPS.ttf 字体下,在 Shape 之前,获取到的 Codepoint 就是字符的 Codepoint 值,而不是 GlyphIndex 的值。在 Shape 之后,获取到的 Codepoint 就是 GlyphIndex 的值
2434
ReadOnlySpan<GlyphInfo> glyphInfoSpan = buffer.GetGlyphInfoSpan();
2535
Span<ushort> glyphsSpan = glyphInfoSpan.Length < 1024 ?
2636
stackalloc ushort[glyphInfoSpan.Length]
@@ -29,15 +39,7 @@ stackalloc ushort[glyphInfoSpan.Length]
2939
for (int i = 0; i < glyphInfoSpan.Length; i++)
3040
{
3141
var codepoint = glyphInfoSpan[i].Codepoint;
32-
if (font.TryGetGlyph(codepoint, out uint glyphId))
33-
{
34-
glyphsSpan[i] = (ushort) glyphId;
35-
}
36-
else
37-
{
38-
// 暂时不知道怎么处理
39-
glyphsSpan[i] = 0;
40-
}
42+
glyphsSpan[i] = (ushort) codepoint;
4143
}
4244

4345
Span<byte> byteBuffer = MemoryMarshal.AsBytes(glyphsSpan);

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ public void UpdateSkiaTextStatus(string text)
116116
SKFontStyleWidth.Normal, IsItalic ? SKFontStyleSlant.Italic : SKFontStyleSlant.Upright);
117117
}
118118

119-
120-
121119
Console.WriteLine($"CurrentFontName='{CurrentFontName}' get the SKTypeface {(typeface is null ? "is null" : "not null")}. SKTypeface={typeface?.FamilyName} GlyphCount={typeface?.GlyphCount}. Text={text}");
122120

123121
skFont.Typeface = typeface;

0 commit comments

Comments
 (0)