gpt4 book ai didi

c# - 在 SharpDX/DirectWrite 中获取 ABC 字符宽度

转载 作者:太空宇宙 更新时间:2023-11-03 21:02:01 25 4
gpt4 key购买 nike

在 GDI 中获取字符的 ABC 宽度(左方位、右方位等)我会调用 GetCharABCWidths .

我如何使用 SharpDX 或 DirectWrite 实现相同的测量,对于相同的字符,我是否应该期望值在这与 GDI 之间匹配?

到目前为止我做了什么?由于缺少 Direct* 和 SharpDX 文档而迷失方向。

最佳答案

/// <summary>
/// Takes a string, text format, and associated constraints, and produces an object that represents the fully analyzed and formatted result.
/// </summary>
/// <param name="factory">an instance of <see cref="T:SharpDX.DirectWrite.Factory" /></param>
/// <param name="text">An array of characters that contains the string to create a new <see cref="T:SharpDX.DirectWrite.TextLayout" /> object from. This array must be of length stringLength and can contain embedded NULL characters.</param>
/// <param name="textFormat">A pointer to an object that indicates the format to apply to the string.</param>
/// <param name="maxWidth">The width of the layout box.</param>
/// <param name="maxHeight">The height of the layout box.</param>
/// <unmanaged>HRESULT CreateTextLayout([In, Buffer] const wchar* string,[None] UINT32 stringLength,[None] IDWriteTextFormat* textFormat,[None] FLOAT maxWidth,[None] FLOAT maxHeight,[Out] IDWriteTextLayout** textLayout)</unmanaged>
public TextLayout(Factory factory, string text, TextFormat textFormat, float maxWidth, float maxHeight)

示例代码:

using (var dwFactory = new SharpDX.DirectWrite.Factory())
{
var textLayout = new TextLayout(dwFactory, "ABC", textFormat, float.PositiveInfinity, float.PositiveInfinity);
var width = textLayout.Metrics.Width
...
}

关于c# - 在 SharpDX/DirectWrite 中获取 ABC 字符宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44594167/

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