查找各种Arial字体大小的字符宽度(以像素为单位) [英] Find char width in pixels for various Arial fontsizes

查看:3748
本文介绍了查找各种Arial字体大小的字符宽度(以像素为单位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,在C#中使用PDFsharp手动生成PDF。虽然这是相当冗长乏味,我必须使用它,并接近完成任务。只有一个问题仍然存在。

I have a program that is manually generating a PDF using PDFsharp in C#. Although it is rather tedious I have to use it and am nearing completion of the task. Only one issue remains.

问题:我想知道如何找出一个给定的字符的宽度是给定的字体大小在Arial。

Problem: I am wondering how I can find out what the width of a given char is for a given font size in Arial.

我遇到了麻烦,提出一个更精确的文本包装方法。现在,以像素为单位定义框的宽度,然后继续在该框中写出一个字符串。我只是猜测在字符串的最大长度可以适合在框中,有一些视觉奇怪,不时出现。

I am having trouble coming up with a more precise text wrapping method. Right now one defines a width of box in pixels and then proceeds to write out a string in that box. I kinda just guess at the max length of the string that can fit in the box and there are some visual oddities that crop up from time to time.

任何帮助?

感谢

推荐答案

在True Type字体和字距调整的时代,没有一个字符宽度。
字符串VA的宽度可能小于字符串V和A的宽度之和。

In the days of True Type fonts with kerning etc. there is not a single character width. The width of the string "VA" is probably less then the sum of the widths of the strings "V" and "A". Summing up the widths if individual characters is a starting point - but finally you have to measure the complete string.

PDFsharp包括类XTextFormatter(带有完整的字符串)。
如果单个字符是起始点,代码)。它可以适应具体要求。
它使用 gfx.MeasureString(token,this.font).Width 来测量字符串的宽度。

PDFsharp includes the class XTextFormatter (with full source code) that does this line wrapping. It can be adapted for specific requirements. It uses gfx.MeasureString(token, this.font).Width to measure the width of a string.

这篇关于查找各种Arial字体大小的字符宽度(以像素为单位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆