天道酬勤,学无止境

text-width

Strange behavior while computing string width in pixels for simulation of word wrap

Trying to get string width in C# to simulate wordwrap and position of text (now written in richTextBox). Size of richTextBox is 555x454 px and I use monospaced font Courier New 12pt. I tried TextRenderer.MeasureText() and also Graphics.MeasureString() methods. TextRenderer was returning bigger values than Graphics so text which normally fits into one line, my code determined should be wrapped to other line. But with using Graphics, on the other hand, my code determined that particular string is shorter than it is printed in original richTextBox so it was wrapped to next line in wrong place

2021-05-12 08:37:36    分类:问答    c#   fonts   word-wrap   eye-tracking   text-width

如何计算iText中的字符串宽度?(How to calculate the string width in iText?)

问题 我正在使用iText编写PDF。 在某些情况下,我需要使用SetVisibleSignature函数对PDF进行SetVisibleSignature 。 使用此功能,我们需要指定将内容写入其中的矩形。 但是我很难计算出字符串的宽度,因此我可以在设置PDF签名之前先设置矩形。 如何在iText中计算字符串宽度? 回答1 您可以使用BaseFont.getWidthPoint(String text, float fontSize)来获取pt中字符串的宽度。 或者将字符串放在Chunk中,然后执行chunk.getWidthPoint() 回答2 可接受的答案BaseFont.getWidthPoint在itext 5.5.4中将不起作用,因为该方法不再是静态的。 即使它仍然存在,也不会考虑所使用的真实字体(其字体或粗体/斜体),因为它是静态的并且接收的参数有限。 chunk.getWidthPoint()确实可以使用真正的字体,如稍后所述,但是对于某些用途,仅针对宽度不断地创建块是浪费的,特别是如果以后不打算使用该块的话。 这是chunk.getWidthPoint()的基础代码,用作您的独立替代品,假设您未进行任何水平缩放: font.getCalculatedBaseFont(true).getWidthPoint(text, font.getCalculatedSize

2021-04-26 12:20:18    分类:技术分享    pdf   pdf-generation   itext   text-width

How to calculate the string width in iText?

I am using iText to write a PDF. In some cases, I need to sign the PDF with the SetVisibleSignature function. With this function, we need to designate the rectangle that we will write the content into. But it's hard for me to calculate how wide the string will be, so that I can set the rectangle before setting a signature on the PDF. How can I calculate the string width in iText?

2021-04-06 18:30:14    分类:问答    pdf   pdf-generation   itext   text-width