Adjusting the TextMatrix in iText

夙愿已清 提交于 2019-12-11 19:41:38

问题


I generated a PDF with a row of chars M. Every M had consistent width, but the distance between each was changing: first couple was 2px, the fifth one had 3px, then the next four had 2px, the tenth 3px, etc.

Since there is absolutly no difference in any of the M's or any spaces inbetween in my code, only conclusion is that some width value could not scale properly in coordinate system generating an extra pixel every so often.

This is how PDF calculates how much to move horizontally when a glyph is painted:

When calcualting for a standard 96DPI display, each pixel is represented by 0.75 unit (checked and tested thoroughly).

Having that in mind, I need to make sure that Tx value is divisible by 0.75.

This is what I know:

  1. w0 is an integer originating from widths array (widths[])
  2. Tfs is a nubmer divisible by 0.75 (set by me)
  3. Th is 100 (default)
  4. Tc and Tw are both 0 (default)

So Tj/1000 needs to be an integer, meaning Tj needs to be divisible by 1000.

One way is to get and adjust the Tj value. Another approach to this is to acces the Tx value once it's calcualted and just change it to closest value divisible by 0.75.

How do I do this in iText?

Or is my whole assumption wrong?

Source: link (page 252)


回答1:


I have seen this question asked before here on SO and I really do not understand what your are trying to achieve. If you drew the M letters at equal distances then they will be displayed at equal distances. What you are experiencing is a limitation of the display technology and it is caused by pixel fitting.
Creating a PDF file to be displayed pixel perfect at 96dpi is not something the PDF format was designed for. Even if you create such a PDF file that is displayed as you expect in one viewer, you have no guarantee that it will be displayed the same in another viewer.



来源:https://stackoverflow.com/questions/18860450/adjusting-the-textmatrix-in-itext

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