Skip to content

Commit 79328a8

Browse files
authored
Merge pull request #59 from dotnet-campus/t/lindexi/Wmf
如果 Inkscape 没有安装则重复转换时不要尝试启动进程
2 parents 693db92 + 983bbf5 commit 79328a8

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/MediaConverters/SkiaWmfRenderer/src/SkiaWmfRenderer/Optimizations/EnhancedGraphicsMetafileOptimization.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,12 @@ private static EnhancedGraphicsMetafileOptimizationResult ConvertWithLibWmf(in E
291291
return EnhancedGraphicsMetafileOptimizationResult.NotSupported();
292292
}
293293

294+
/// <summary>
295+
/// 是否 Inkscape 应用程序未安装
296+
/// </summary>
297+
/// 先不考虑后续 Inkscape 可能安装的问题。可在业务端设置为 false 继续尝试
298+
public static bool IsInkscapeNotBeInstalled { get; set; }
299+
294300
[SupportedOSPlatform("linux")]
295301
private static EnhancedGraphicsMetafileOptimizationResult ConvertWithInkscape(EnhancedGraphicsMetafileOptimizationContext context)
296302
{
@@ -301,6 +307,13 @@ private static EnhancedGraphicsMetafileOptimizationResult ConvertWithInkscape(En
301307

302308
context.LogMessage($"Start convert emf or wmf to png by Inkscape. File:'{file}'");
303309

310+
if (IsInkscapeNotBeInstalled)
311+
{
312+
// 转换失败,因为缓存的属性明确表示 Inkscape 应用程序不存在
313+
context.LogMessage($"Convert emf or wmf to svg by Inkscape failed. Because cache property indicate Inkscape application not be installed. {nameof(IsInkscapeNotBeInstalled)}=true. We will continue use libwmf to convert the image.");
314+
return EnhancedGraphicsMetafileOptimizationResult.NotSupported();
315+
}
316+
304317
var processStartInfo = new ProcessStartInfo("inkscape")
305318
{
306319
ArgumentList =
@@ -336,6 +349,9 @@ private static EnhancedGraphicsMetafileOptimizationResult ConvertWithInkscape(En
336349
// 明确不存在,那就不记录错误信息了
337350
// 大概耗时 17 毫秒
338351
context.LogMessage($"Convert emf or wmf to svg by Inkscape failed. Because not found Inkscape application. Please make sure Inkscape be installed. We will continue use libwmf to convert the image.");
352+
353+
// 设置为 true 缓存,避免下次继续尝试
354+
IsInkscapeNotBeInstalled = true;
339355
}
340356
else
341357
{

src/MediaConverters/SkiaWmfRenderer/src/SkiaWmfRenderer/SkiaWmfRenderer.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,12 @@
5353
<PrivateAssets>all</PrivateAssets>
5454
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
5555
</PackageReference>
56-
<PackageReference Include="SkiaSharp" Version="3.119.0" />
56+
<PackageReference Include="SkiaSharp" Version="3.116.1" />
5757

5858
<PackageReference Include="Svg.Skia" Version="3.0.4" />
5959
<PackageReference Include="System.Drawing.Common" Version="9.0.7" />
6060

6161
<PackageReference Include="HarfBuzzSharp" Version="8.3.1.1" />
62-
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="8.3.1.1" />
6362

6463
<!-- System.Text.Encoding.CodePages 库被用在 Encoding.RegisterProvider 处理大量特殊编码 -->
6564
<PackageReference Include="System.Text.Encoding.CodePages" Version="9.0.7" />

0 commit comments

Comments
 (0)