查找文本“空格”以像素为单位的值
在处理字体时,有没有办法计算出如果是“1 2”,两个字符之间的间距应该是多少?
如果它在 C++ 或 C# 中是已知的,我不介意。如果是 C++ 语言,我会将其封送过来,如果是 C# 语言,我会将其保存到文件中并在 C++ 中加载。我尝试查看 TextMetric 结构,但不存在。
With dealing with fonts, is there a way to figure out what the space between two characters should be if it was "1 2"?
If it is known in C++ or C#, I don't mind. If it is in C++, I will marshal it over, it if is in C#, I will save it to a file and load it in C++. I tried taking a look at the TextMetric structure but it was not there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Graphics.MeasureCharacterRanges 在测量单个值时获得非常好的结果通过在前后添加零宽度连接符
\u200D
来形成字形(甚至空格)。然而,由于我认为是零宽度连接器,它确实忽略了所有字偶距调整的内容。您需要一堆附加参数,但是
new StringFormat(StringFormat.GenericTypgraphic)
和Rectangle.Empty
对我来说效果很好。它返回字符串中每个字符的漂亮浮点边界数组。
Graphics.MeasureCharacterRanges gets pretty good results measuring single glyphs (even spaces) by adding a zero-width-joiner character
\u200D
before and after. It does however ignore all Kerning stuff, due to the zero-width-joiners I think.You need a bunch of additional parameters, but a
new StringFormat(StringFormat.GenericTypographic)
andRectangle.Empty
did just fine for me.It returns an array of nice floating point bounds of each character in the string.
如果您想要衡量文本呈现方式的指标,则需要提供文本。您需要提供 ascii 空格字符。现代系统使用字距调整来调整间距并使文本看起来更有吸引力。
If you want metrics of how text will be rendered you need to provide the text. You would need to provide the ascii space character. Modern systems using Kerning to adjust spacing and make text look more attractive.
您可以使用 Graphics.MeasureString() 并传入字体和 < code>" " 带空格的字符串?
Can you use Graphics.MeasureString() and pass in a font and
" "
string with space ?下面是使用表单的 Paint 事件处理程序的 C# 示例:
Here is an example in C# using a form's Paint event handler: