gpt4 book ai didi

windows - 在 server core 2019ltsc 容器镜像中添加字体

转载 作者:可可西里 更新时间:2023-11-01 14:21:59 24 4
gpt4 key购买 nike

我们有一个应用程序 (GrapeCity ActiveReports) 生成 pdf 报告,该报告在基于下图构建的容器内运行:microsoft/dotnet-framework:4.7.2-sdk

此图像基于 2019ltsc 版本,这就是问题所在。生成 pdf 的应用程序正在(尝试)为这些报告使用 Arial 字体,但在 Windows 字体目录中找不到。

根据此 Microsoft 博客(在“容器改进”部分下),2019ltsc 版本删除了除 Arial 外的所有字体,并且它显然阻止了安装其他字体。 https://blogs.windows.com/windowsexperience/2018/05/29/announcing-windows-server-2019-insider-preview-build-17677/

以交互方式启动未修改的 SDK 图像并浏览到 C:\Windows\Fonts 仅显示存在 lucon.ttf 字体,没有其他内容。我们还尝试了 Microsoft 的此文档中概述的安装字体方法,但没有进行任何更改。字体本身安装正常,但生成程序无法使用它。 https://learn.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-windows-containers-custom-fonts

运行时返回以下异常:

System.InvalidOperationException: Cannot read the file for font: Arial

更新:收到 MS 支持的回复,看起来目前可能没有解决方案。

After a few days research, I haven’t got much progress about why the only font in mcr.microsoft.com.windows/servercore:ltsc2019 based image is lucon.ttf, and seems there’s no published method to add additional fonts to windows server core 2019 image. Based on the situation, I have sent emails to windows server 2019 product team to consult this issue. However, please understand, due to permission limit, I couldn’t guarantee I can get feedback from Product Team. I will keep researching and monitor on the product team, if I get any progress, I will get back to you as soon as possible.

最佳答案

我能够按照之前的建议安装它,让它在 ltsc2019 中工作:

COPY calibri.ttf c:/windows/fonts/calibri.TTF
RUN powershell.exe -NoProfile -Command New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts' -Name 'Calibri (TrueType)' -PropertyType String -Value calibri.ttf

然后调用

[DllImport("gdi32.dll")]static extern int AddFontResource(string lpFilename);

在使用字体之前。在构建图像时调用 AddFontResource 没有帮助。

当我们从 powershell 启动我们的应用程序时,我们从 C:\Users\ContainerAdministrator\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 调用 LoadFonts.ps1

RUN echo "C:\tools\LoadFonts.ps1" | Out-File -FilePath $profile

加载字体.ps1:

$fontCSharpCode = @'
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
namespace FontResource
{
public class AddRemoveFonts
{
[DllImport("gdi32.dll")]
static extern int AddFontResource(string lpFilename);
public static int AddFont(string fontFilePath) {
try
{
return AddFontResource(fontFilePath);
}
catch
{
return 0;
}
}
}
}
'@

Add-Type $fontCSharpCode

foreach($font in $(gci C:\Windows\Fonts))
{
if(!$font.FullName.EndsWith("lucon.ttf"))
{
Write-Output "Loading $($font.FullName)"
[FontResource.AddRemoveFonts]::AddFont($font.FullName) | Out-Null
}
}

关于windows - 在 server core 2019ltsc 容器镜像中添加字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54366537/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com