我正在开发一个标签设计程序,遇到了一个非常奇怪的问题,我在互联网上的任何地方都找不到答案.
基本解释是,当DrawString()
的layoutRectangle
属性设置为略高于文本长度大小的任何值时,字距调整似乎就会关闭.字符"TE"的组合最明显.
Correct Kerning with 'layoutRectangle' just enough to fit the text:
Wrong kerning with 'layoutRectangle' larger than required to fit the text:
您可能可以发现第二张图像中的"e"比第一张图像中的"e"画得更远.我在一个新项目中try 过,也发生了同样的事情.即使根本没有指定layoutRectangle
,您也可以观察到相同的行为.
以下是绘制字符串的代码行:
canvasGraphics.Graphics.DrawString(
_displayText.FormattedTextValue,
new Font(FontName, (float)((drawFontSizeToUse / 72d) * Canvas.RenderDPI), fontStyle, GraphicsUnit.Pixel),
Brushes.Black,
(Rectangle)new RectangleD(ScreenBounds.X, ScreenBounds.Y, ScreenBounds.Width, ScreenBounds.Height),
stringFormat
);
stringFormat
只是根据设置更改对齐方式.
有人知道如何解决这个问题吗?谢谢!
我try 过操纵不同的StringFormat
、TextRenderingHint
和任何Font
选项等(尽管可能有一些我不知道的.)
我无法使用"TextRenderer",因为它无法用于打印.