0

在处理字体时,如果是“1 2”,有没有办法弄清楚两个字符之间的空格应该是多少?

如果它在 C++ 或 C# 中是已知的,我不介意。如果它在 C++ 中,我会将其编组,如果在 C# 中,我会将它保存到一个文件中并在 C++ 中加载它。我尝试查看 TextMetric 结构,但它不存在。

4

4 回答 4

2

Graphics.MeasureCharacterRanges\u200D通过在前后添加零宽度连接符来测量单个字形(甚至空格),获得了很好的结果。然而,由于我认为是零宽度连接器,它确实忽略了所有字距调整的东西。

你需要一堆额外的参数,但是 a new StringFormat(StringFormat.GenericTypographic)andRectangle.Empty对我来说很好。

它返回字符串中每个字符的漂亮浮点边界数组。

于 2011-05-07T02:33:18.670 回答
1

您可以使用Graphics.MeasureString()并传入" "带有空格的字体和字符串吗?

于 2011-05-06T20:23:54.950 回答
1

如果您想要文本如何呈现的指标,您需要提供文本。您需要提供 ascii 空格字符。现代系统使用 Kerning 来调整间距并使文本看起来更有吸引力。

于 2011-05-06T20:24:35.030 回答
0

下面是 C# 中使用表单的 Paint 事件处理程序的示例:

private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
    float widthWithSpace = e.Graphics.MeasureString("1 2", new Font("Arial", 12)).Width;
    float widthWithoutSpace = e.Graphics.MeasureString("12", new Font("Arial", 12)).Width;
    float spaceWidthInPixels = widthWithSpace - widthWithoutSpace ;
}
于 2011-05-07T02:18:10.833 回答