在iText中调整TextMatrix [英] Adjusting the TextMatrix in iText

查看:1267
本文介绍了在iText中调整TextMatrix的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我生成了一个带有一行字符M的PDF。每个M都有一致的宽度,但每个M之间的距离都在变化:第一对是2px,第五对有3px,然后接下来的四个有2px,第十个3px,等等。

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.

由于我的代码中任何M或任何空格中绝对没有差别,只有结论是某些宽度值无法在坐标系中正确缩放每隔一段时间生成一个额外的像素。

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.

这是PDF计算绘制字形时水平移动的程度:

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

何时计算标准的96DPI显示器,每个像素用0.75单位表示(经过检查和测试)。

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

考虑到这一点,我需要确保Tx值是可以被0.75整除。

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

这就是我所知道的:


  1. w0是一个源自widths数组的整数(widths [])

  2. Tfs是可以被0.75整除的nubmer(由我设置)

  3. Th是100(默认)

  4. Tc和Tw都是0(默认)

  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)

所以Tj / 1000需要是一个整数,意味着Tj需要被1000整除。

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

一种方法是获取并调整Tj值。另一种方法是在计算后获取Tx值,然后将其更改为可被0.75整除的最接近值。

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.

如何在iText中执行此操作?

How do I do this in iText?

或者我的整个假设是错误的?

Or is my whole assumption wrong?

资料来源: link(第252页)

推荐答案

我在此之前已经看过这个问题了,我真的不明白你想要实现的目标。如果您以相等的距离绘制M个字母,那么它们将以相等的距离显示。你所经历的是显示技术的局限性,它是由像素拟合引起的。

创建一个PDF格式,以96dpi显示像素,这不是PDF格式的设计目标。即使您创建了一个在一个查看器中按预期显示的PDF文件,也​​无法保证它将在另一个查看器中显示相同的内容。

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.

这篇关于在iText中调整TextMatrix的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆