PDF glyph spacing and TJ operator

旧城冷巷雨未停 提交于 2019-12-02 20:16:04

问题


I am new to PDF, and i want to manipulate the space between the characters in a file. I have read the PDFReference and understood some of it. Now, the problem I have is how to calculate the spaces for the text rendering.

I have for example:

1 0 0 1 0 188.28799438 cm
BT 
/F2 11.04 Tf
1 0 0 -1 0 9.38000011 Tm 
(Some)Tj ( )Tj 
21.24200058 0 Td 
(text)Tj ( )Tj 

Which I want to turn into this:

1 0 0 1 0 188.28799438 cm
BT 
/F2 11.04 Tf
1 0 0 -1 0 9.38000011 Tm 
[(S)10(o)10(m)10(e)( )]TJ 
21.24200058 0 Td 
[(t)10(e)10(x)10(t)( )]TJ 

To add the spaces and then be able to manipulate them. However I was wondering how to calculate the ctm and the line matrix with those added values.

I know that we concatenate cm with the previous one.

cm2 x cm1

The Tms are not concatenated Tm2 replaces Tm1.

I am stuck with the td operator and the new spaces I added. Any clue?


回答1:


As clarified in comments, the OP is not asking for effects of the TJ numbers on the current transformation matrix or text line matrix but instead on the text matrix Tm.

This is explained in the specification ISO 32000-1 (and equivalently in ISO 32000-2) in section 9.4.4 Text Space Details: After drawing a glyph (probably followed by a number in a TJ instruction array argument), the text matrix shall be updated as follows:

In horizontal mode tx is the displacement and ty is zero, in vertical mode tx is zero and ty is the displacement. The applicable value is calculated as

I.e. if you do this calculation while processing a TJ instruction and there is a number following the character code for the currently drawn glyph, that number is considered here as the parameterTj.

Thus, if you want to determine the displacement caused by a number element of a TJ array argument alone — e.g. if the first element in the TJ array argument is a number or if there are multiple consecutive number elements in the TJ array argument and you want to know the effect of each one — the above reduces to

tx = (−Tj / 1000) × Tfs × Th

ty = (−Tj / 1000) × Tfs




回答2:


If you're working with horizontal text and only want to control the spacing between glyphs with the TJ operator, you don't need to worry about adding those values to the current transformation matrix or line matrix.

  • The CTM is a master matrix that maps user space coordinates to output device coordinates; for each glyph, it is concatenated with other parameters to make a temporary text rendering matrix to position the glyph, but the CTM does not accumulate changes as glyphs are positioned (see 9.4.4 'Text Space Details' in the PDF 32000 reference)
  • The line matrix captures the value of the initial text matrix at the beginning of a line of a text; it's really only used for matching the vertical position of lines of text and isn't affected by the spacing between glyphs (see 9.4.2 'Text Positioning Operators')


来源:https://stackoverflow.com/questions/52078442/pdf-glyph-spacing-and-tj-operator

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!