CTM矩阵乘法与先前状态与PDF位置解析中的单位矩阵? [英] CTM matrix multiplication with previous state vs with Identity matrix in PDF position parsing?

查看:51
本文介绍了CTM矩阵乘法与先前状态与PDF位置解析中的单位矩阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 CTM 矩阵计算上经历了不同的解决方案(其中一些是

如图 1 和图 2 所示,只是将新矩阵从 Td 替换为 Tm.从 2 到 3 又是最后一次 CTM 乘法.我怎么知道?(从视觉上我可以看出来)

情况 2:

在这种情况下,矩阵推送和计算将如何进行?

情况 3:

BTTT_1 20 Tf35.56 150.24533 Td _____________ 1(一些示例文本)Tj50.526 250.36 Td ________________ 2(二线新替换)Tj0 -16.2 Td _____________________ 3(线端.)TjET

这种情况1和2只是替换,2和3之前的矩阵乘法.我怎么知道?

案例 4:

请至少解析这些位置直到 10.这个

在上面一个需要计算l的位置.我用 1 到 4 个数字突出显示.我需要计算每个人的位置 l 如何做到这一点?及其评论中讨论了示例 4.

示例 5

q 0.1 0 0 0.1 0 0 厘米/R108 克0 克q...问0 0 1 rgq...问4.05 瓦0 克722.023 4082.13 米722.023 4490.28 升秒723.961 4488.25 米2872.98 4488.25 升秒404.1 瓦0 0 0.199951 0 K723.961 4284.18 米2872.98 4284.18 升秒4.05 瓦0 克720 4080.2 米2876.94 4080.2 升秒2874.91 4082.13 米2874.91 4490.28 升秒0 克q

为什么您对这些说明的看法显示的数字不准确?以上是从流内容中复制粘贴的,不需要像这样更改数字...

<块引用>

q0.1 0 0 0.1 0 0 厘米

将 CTM 设置为

 0.1 0 0CTM = 0 0.1 00 0 1

<块引用>

/R108 gs...0 克

CTM 没有任何反应

<块引用>

722.023 4082.13 m722.023 4490.28 升秒

我们必须将 CTM 应用于这些坐标

 0.1 0 0[722.023 4082.13] * 0 0.1 0 = [72.2023 408.213]0 0 10.1 0 0[722.023 4490.28] * 0 0.1 0 = [72.2023 449.028]0 0 1

因此,一条线从 72.2023,408.213 到 72.2023,449.028.

<块引用>

723.961 4488.25 m2872.98 4488.25 升秒

和上面一样,从 72.3961,448.825 到 287.298,448.825 画了一条线.

<块引用>

404.1 w0 0 0.199951 0 K723.961 4284.18 米2872.98 4284.18 升秒

再次从 72.3961,428.418 到 287.298,428.418 画一条线.这里唯一值得注意的是这条线很宽,大约.40个单位,所以这个线"实际上看起来更像是一个填充的矩形,代表了具有洛伦兹力特征的文本框的背景.

<块引用>

4.05 w0 克720 4080.2 米2876.94 4080.2 升秒

绘制另一条线,再次变窄,因此看起来像一条线,这次是从 72,408.02 到 287.694 408.02.

<块引用>

2874.91 4082.13 m2874.91 4490.28 升秒

最后一行,这次是从 287.491,408.213 到 287.491,449.028.

I gone through different solutions on CTM matrix calculations(someof them are this and this).

What I know about content stream is when "q " encounters we need to push identity matrix in a graphics_stack and keep multiply with next position operator(cm , Tm, Td, TD) CTM. When "Q" encounters we need to pop the last matrix.

For text positioning parsing when "BT" encounters push in identity matrix in position_stack and keep multiply with next position operator(cm , Tm, Td, TD) CTM. When "ET" encounters we need to pop the last matrix.

Here the some times we need to multiply with last CTM matrix and some times just multiply with identity matrix. When these cases are occurs?

Case 1:

From as shown in image 1 and 2 case merely replacement of new matrix from Td to Tm. And from 2 to 3 it's again last CTM multiplication. How I know?(By visually I can tell by looks)

Case 2:

In this case which how the matrix pushing and calculation will be there ?

Case 3:

BT
TT_1 20 Tf
35.56 150.24533 Td _______________ 1
(some sample text) Tj
50.526 250.36 Td  ________________ 2
(second line new replace) Tj
0 -16.2 Td   _____________________ 3
(Line end.) Tj
ET

This case 1 and 2 are merely replacement, 2 and 3 previous matrix multiplication. How do I know?

Case 4:

Please parse these positions at least till 10. The source file of this pdf

Case 5:

In above one need to calculate the l position. I highlighted with 1 to 4 numbers. I need to calculate the positions of each and every l How can do that? pdf

case6:

What is the change in calculation when the page(pdf) is rotated to 90 or 180 or 270 and 315 degrees?

These are some cases what I saw. What else might cases I can encounter and What is the generic approach to solve this ?

解决方案

Operators of interest

First of all, I get the impression you mix up two different aspects. You have the current transformation matrix (CTM) and you have the text and text line matrices. The CTM is subject to cm, q, and Q. The text and text line matrices are subject to BT, Tm, Td, ... And to determine the exact position and direction of drawn text you need the product of text matrix and CTM at the time that text is drawn.

How those operators change the matrices, is described in the PDF specification, ISO 32000 part 1 or 2.

From ISO 32000-1 Table 57 – Graphics State Operators –

  • cm: Modify the current transformation matrix (CTM) by concatenating the specified matrix
  • q: Save the current graphics state including the CTM on the graphics state stack
  • Q: Restore the graphics state including the CTM by removing the most recently saved state from the stack and making it the current state

From ISO 32000-1 Table 107 – Text object operators –

  • BT: Begin a text object, initializing the text matrix, Tm, and the text line matrix, Tlm, to the identity matrix.

From ISO 32000-1 Table 108 – Text-positioning operators –

  • tx ty Td: Move to the start of the next line, offset from the start of the current line by (tx, ty). More precisely, this operator shall perform these assignments:

  • a b c d e f Tm: Set the text matrix, Tm, and the text line matrix, Tlm:

Furthermore, TD, T*, ', and " operate on Tm and Tlm in a way specified using the Td operator.

From ISO 32000-1 section 9.4.4 – Text Space Details –

Whenever a glyph is drawn, its entire transformation from text space may be represented by a text rendering matrix, Trm:

where Tfs is the current font size, Th is the current horizontal scaling factor, and Trise is the current text rise value.

After drawing that glyph, Tm is updated according to the glyph displacement

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

Example 1

In the following paragraphs I use rounded values to concentrate on the essentials.

The CTM starts as the Identity matrix, and as there is no cm operation here, it remains so all the time. Tm and Tlm on the other hand do change:

BT

Tm and Tlm are both set to the identity matrix

/GS0 gs
/T1_0 10 Tf

No change to Tm or Tlm.

317 65 Td

This multiplies a translation matrix as described above from the left to the former value of the Tlm and sets Tm and Tlm to the result:

             1  0  0     1 0 0       1  0  0
T  = T   =   0  1  0  *  0 1 0  =    0  1  0
 m    lm   317 65  1     0 0 1     317 65  1

As that former value was the identity, this may look like a replacement by the Td translation matrix but it actually is a multiplication.

(F)Tj

This draws a glyph transformed by the text rendering matrix

       10 × 1   0  0       1  0  0     1 0 0      10  0  0
T   =       0  10  0  *    0  1  0  *  0 1 0  =    0 10  0
 rm         0   0  1     317 65  1     0 0 1     317 65  1

Thereafter Tm is updated as described above. Unfortunately we don't have the widths of the font T1_0, so we cannot calculate the updated value.

1 0 0 1 370 87 Tm

This sets the text matrix, Tm, and the text line matrix, Tlm, to the given matrix:

              1  0  0
T  = T   =    0  1  0
 m    lm    370 87  1

So now we know the current Tm value again.

-47 -22 Td

This multiplies a translation matrix as described above from the left to the former value of the Tlm and sets Tm and Tlm to the result:

              1   0  0       1  0  0       1  0  0
T  = T   =    0   1  0  *    0  1  0  =    0  1  0
 m    lm    -47 -22  1     370 87  1     323 65  1

[(igure)-251(2.3:)-621(P)16...] TJ

This draws the strings in the argument array with a starting text rendering matrix of

       10 × 1   0  0       1  0  0     1 0 0      10  0  0
T   =       0  10  0  *    0  1  0  *  0 1 0  =    0 10  0
 rm         0   0  1     323 65  1     0 0 1     323 65  1

updating Tm again and again as described above.

Example 2

In the following paragraphs I use rounded values to concentrate on the essentials.

The CTM starts as the Identity matrix.

q

This saves the current graphics state, including the current CTM. As there is no Q operation in the example, though, we can ignore that for now.

.24 0 0 .24 91 740 cm

This updates the CTM by the given matrix:

        0.24   0     0     1 0 0      0.24   0     0
CTM =   0      0.24  0  *  0 1 0  =   0      0.24  0
       91    740     1     0 0 1     91    740     1

BT

Tm and Tlm are both set to the identity matrix

133 0 0 133 0 0 Tm

This sets the text matrix, Tm, and the text line matrix, Tlm, to the given matrix:

            133   0  0
T  = T   =    0 133  0
 m    lm      0   0  1

/TT1.0 1 Tf
.002 Tc

No change to CTM, Tm, or Tlm.

[(The)1( )1(Long )1(Tai)1(l)]TJ

This draws the strings in the argument array with a starting text rendering matrix of

       1 × 1  0  0     133   0  0      0.24   0    0     32   0  0
T   =      0  1  0  *    0 133  0  *   0      0.24 0  =   0  32  0
 rm        0  0  1       0   0  1     91    740    1     91 740  1

updating Tm again and again as described above.

Example 3

BT
TT_1 20 Tf
35.56 150.24533 Td _______________ 1
(some sample text) Tj
50.526 250.36 Td  ________________ 2
(second line new replace) Tj
0 -16.2 Td   _____________________ 3
(Line end.) Tj
ET

In the following paragraphs I use rounded values to concentrate on the essentials.

The CTM starts as the Identity matrix, and as there is no cm operation here, it remains so all the time. Tm and Tlm on the other hand do change:

BT

Tm and Tlm are both set to the identity matrix

TT_1 20 Tf

No change to Tm or Tlm.

36 150 Td

This multiplies a translation matrix as described above from the left to the former value of the Tlm and sets Tm and Tlm to the result:

            1   0  0     1 0 0      1   0  0
T  = T   =  0   1  0  *  0 1 0  =   0   1  0
 m    lm   36 150  1     0 0 1     36 150  1

As that former value was the identity, this may look like a replacement by the Td translation matrix but it actually is a multiplication.

(some sample text) Tj

This draws glyphs transformed by the text rendering matrix

       20 × 1   0  0      1   0  0     1 0 0     20   0  0
T   =       0  20  0  *   0   1  0  *  0 1 0  =   0  20  0
 rm         0   0  1     36 150  1     0 0 1     36 150  1

Thereafter Tm is updated as described above. Unfortunately we don't have the widths of the font TT_1, so we cannot calculate the updated value.

51 250 Td

This multiplies a translation matrix as described above from the left to the former value of the Tlm and sets Tm and Tlm to the result:

            1   0  0      1   0  0      1   0  0
T  = T   =  0   1  0  *   0   1  0  =   0   1  0
 m    lm   51 250  1     36 150  1     87 400  1

So now we know the current Tm value again.

(second line new replace) Tj

This draws glyphs transformed by the text rendering matrix

       20 × 1   0  0      1   0  0     1 0 0     20   0  0
T   =       0  20  0  *   0   1  0  *  0 1 0  =   0  20  0
 rm         0   0  1     87 400  1     0 0 1     87 400  1

Thereafter Tm is updated as described above. Unfortunately we don't have the widths of the font TT_1, so we cannot calculate the updated value.

0 -16 Td

This multiplies a translation matrix as described above from the left to the former value of the Tlm and sets Tm and Tlm to the result:

            1   0  0      1   0  0      1   0  0
T  = T   =  0   1  0  *   0   1  0  =   0   1  0
 m    lm    0 -16  1     87 400  1     87 384  1

So now we know the current Tm value again.

(Line end.) Tj

This draws glyphs transformed by the text rendering matrix

       20 × 1   0  0      1   0  0     1 0 0     20   0  0
T   =       0  20  0  *   0   1  0  *  0 1 0  =   0  20  0
 rm         0   0  1     87 384  1     0 0 1     87 384  1

Thereafter Tm is updated as described above. Unfortunately we don't have the widths of the font TT_1, so we cannot calculate the updated value.

Example 4

We discussed example 4 in your answer and the comments to it.

Example 5

q 0.1 0 0 0.1 0 0 cm
/R108 gs
0 g
q
...
Q
0 0 1 rg
q
...
Q
4.05 w
0 G
722.023 4082.13 m
722.023 4490.28 l
S
723.961 4488.25 m
2872.98 4488.25 l
S
404.1 w
0 0 0.199951 0 K
723.961 4284.18 m
2872.98 4284.18 l
S
4.05 w
0 G
720 4080.2 m
2876.94 4080.2 l
S
2874.91 4082.13 m
2874.91 4490.28 l
S
0 g
q 

Why does your view of those instructions show the numbers inaccurately? The above is copy&pasted from the stream contents, there is no need to change the numbers like that...

q
0.1 0 0 0.1 0 0 cm

Sets the CTM to

       0.1 0   0
CTM =  0   0.1 0
       0   0   1

/R108 gs
...
0 G

Nothing happens to the CTM

722.023 4082.13 m
722.023 4490.28 l
S

We have to apply the CTM to these coordinates

                      0.1 0   0
[722.023 4082.13]  *  0   0.1 0  = [72.2023 408.213]
                      0   0   1

                      0.1 0   0
[722.023 4490.28]  *  0   0.1 0  = [72.2023 449.028]
                      0   0   1

Thus, a line is stroked from 72.2023,408.213 to 72.2023,449.028.

723.961 4488.25 m
2872.98 4488.25 l
S

Just like above, a line is drawn from 72.3961,448.825 to 287.298,448.825.

404.1 w
0 0 0.199951 0 K
723.961 4284.18 m
2872.98 4284.18 l
S

And again, a line is drawn from 72.3961,428.418 to 287.298,428.418. The only notable thing here is that the line is quite wide, ca. 40 units, so this "line" actually looks more like a filled rectangle and represents the background of the text box with the Lorentz force characterization.

4.05 w
0 G
720 4080.2 m
2876.94 4080.2 l
S

Another line is drawn, narrow again and, therefore, looking like a line, this time from 72,408.02 to 287.694 408.02.

2874.91 4082.13 m
2874.91 4490.28 l
S

And finally the last line, this time from 287.491,408.213 to 287.491,449.028.

这篇关于CTM矩阵乘法与先前状态与PDF位置解析中的单位矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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