Skip to content

Commit f26b8c2

Browse files
committed
经过测试,能够拿到字体,但渲染内容是空的
1 parent e3b9a88 commit f26b8c2

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,20 @@ public CharacterSet CurrentCharacterSet
5555
public SKFont SKFont { get; } = new SKFont();
5656

5757

58-
public void UpdateSkiaTextStatus()
58+
public void UpdateSkiaTextStatus(string text)
5959
{
6060
var skFont = SKFont;
6161
skFont.Size = CurrentFontSize;
62-
skFont.Typeface = SKTypeface.FromFamilyName(CurrentFontName, (SKFontStyleWeight) FontWeight,
62+
63+
skFont.Typeface?.Dispose();
64+
65+
SKTypeface? typeface = SKTypeface.FromFamilyName(CurrentFontName, (SKFontStyleWeight) FontWeight,
6366
SKFontStyleWidth.Normal, IsItalic ? SKFontStyleSlant.Italic : SKFontStyleSlant.Upright);
6467

68+
Console.WriteLine($"CurrentFontName='{CurrentFontName}' get the SKTypeface {(typeface is null ? "is null" : "not null")}. Text={text}");
69+
70+
skFont.Typeface = typeface;
71+
6572
Paint.Style = SKPaintStyle.Fill;
6673
Paint.Color = CurrentTextColor;
6774
}
@@ -87,6 +94,7 @@ public void UpdateSkiaFillStatus()
8794
public void Dispose()
8895
{
8996
Paint.Dispose();
97+
SKFont.Typeface?.Dispose();
9098
SKFont.Dispose();
9199
}
92100
}

src/MediaConverters/SkiaWmfRenderer/src/SkiaWmfRenderer/Rendering/WmfRenderer.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Oxage.Wmf.Records;
33
using SkiaSharp;
44
using System;
5+
using System.Diagnostics;
56
using System.Diagnostics.CodeAnalysis;
67

78
namespace SkiaWmfRenderer.Rendering;
@@ -410,7 +411,7 @@ private static bool RenderRecord(SKCanvas canvas, WmfRenderStatus renderStatus,
410411

411412
var currentXOffset = renderStatus.CurrentX + extTextoutRecord.X + renderStatus.LastDxOffset;
412413

413-
renderStatus.UpdateSkiaTextStatus();
414+
renderStatus.UpdateSkiaTextStatus(text);
414415

415416
if (extTextoutRecord.Dx is null)
416417
{
@@ -449,6 +450,8 @@ private static bool RenderRecord(SKCanvas canvas, WmfRenderStatus renderStatus,
449450
{
450451
case RecordType.META_EXTTEXTOUT:
451452
{
453+
Debug.Fail("当前已经有 WmfExtTextoutRecord 类型了");
454+
452455
renderStatus.IsIncludeText = true;
453456

454457
// 关于字间距的规则:
@@ -487,7 +490,7 @@ private static bool RenderRecord(SKCanvas canvas, WmfRenderStatus renderStatus,
487490
//Debug.Assert(st == unknownRecord.RecordSize);
488491
var dxLength = unknownRecord.Data.Length - st;
489492

490-
renderStatus.UpdateSkiaTextStatus();
493+
renderStatus.UpdateSkiaTextStatus(text);
491494

492495
var currentXOffset = renderStatus.CurrentX + tx + renderStatus.LastDxOffset;
493496

0 commit comments

Comments
 (0)