gpt4 book ai didi

c# - 如何以编程方式安装字体

转载 作者:行者123 更新时间:2023-11-30 17:21:53 26 4
gpt4 key购买 nike

我想在我的程序加载中安装一种特定的字体,并使用该字体来呈现程序的文本。如何以编程方式在 WinCE 6 上从 .NET CF 安装字体。

最佳答案

This blog entry显示如何使用 native 代码在 Windows CE 中枚举和添加字体。对于托管代码,这将起作用:

internal class FontHelper
{
private delegate int EnumFontFamProc(IntPtr lpelf, IntPtr lpntm, uint FontType, IntPtr lParam);
private List<string> m_fonts = new List<string>();

public FontHelper()
{
RefreshFontList();
}

public void RefreshFontList()
{
m_fonts.Clear();

var dc = GetDC(IntPtr.Zero);
var d = new EnumFontFamProc(EnumFontCallback);
var ptr = Marshal.GetFunctionPointerForDelegate(d);
EnumFontFamilies(dc, null, ptr, IntPtr.Zero);
}

public string[] SupportedFonts
{
get { return m_fonts.ToArray(); }
}

private const int SIZEOF_LOGFONT = 92;
private const int LOGFONT = 28;
private const int LF_FACESIZE = 32;
private const int LF_FULLFACESIZE = 64;

[DllImport("coredll", SetLastError = true)]
private static extern IntPtr GetDC(IntPtr hwnd);

[DllImport("coredll", SetLastError = true)]
private static extern int EnumFontFamilies(IntPtr hdc, string lpszFamily, IntPtr lpEnumFontFamProc, IntPtr lParam);

private int EnumFontCallback(IntPtr lpelf, IntPtr lpntm, uint FontType, IntPtr lParam)
{
var data = new byte[SIZEOF_LOGFONT + LF_FACESIZE + LF_FULLFACESIZE];

Marshal.Copy(lpelf, data, 0, data.Length);
var fontName = Encoding.Unicode.GetString(data, SIZEOF_LOGFONT, LF_FULLFACESIZE).TrimEnd('\0');
Debug.WriteLine(fontName);
m_fonts.Add(fontName);

return 1;
}
}

关于c# - 如何以编程方式安装字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3104949/

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