سؤال

I'm adding text to my visible signature. My text is that:

BT
1 0 0 1 0 1 Tm
 /F1 5
Tf
(Hello World)Tj
ET

5 is the font size. but how is that calculated?

I've just check width of text but it's not same:

AffineTransform affinetransform = new AffineTransform();
FontRenderContext frc = new FontRenderContext(affinetransform,true,true);     
Font font = new Font("myFont", Font.PLAIN, 5);
int textwidth = (int)(font.getStringBounds(text, frc).getWidth());

In my PDrectangle, size 5 is too big. Any ideas? How is 5 calculated?

هل كانت مفيدة؟

المحلول

@stanlyF already quoted how the font size is meant to be interpreted. Especially observe that it is about the nominal height of lines

You seem to have the misconception that it is the widths. As already mentioned in my answer to your former question, the widths of a string depends on

  • the font metrics, especially the character widths of the characters involved,
  • the font size,
  • the current character spacing value,
  • the current word spacing value,
  • the horizontal scaling,
  • the current text matrix, and
  • the current transformation matrix.

For details read the specification.

نصائح أخرى

you should also apply Tm text matrix transformations for this value.

"A font defines the glyphs for one standard size. This standard is arranged so that the nominal height of tightly spaced lines of text is 1 unit. In the default user coordinate system, this means the standard glyph size is 1 unit in user space, or 1 ⁄ 72 inch. The standard-size font must then be scaled to be usable. The scale factor is specified as the second operand of the Tf operator, thereby setting the text font size parameter in the graphics state."

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top