doxdici
doxdici

Reputation: 47

find pdf text position

I'm struggling with the calculation of pdf text position. I've read through internet, but without success.
I've read the pdf reference, but it's uhmmmm.
Now, I write a piece of pdf and I'll tell you my thinking about it...

/TT3 1 Tf
11.9951 0 0 12 71.94 420.9803 Tm     //scale x=11.9951  scaley=12   x position=71.94 y position=420.9803
<0003>Tj
/TT2 1 Tf
1.6657 -1.22 TD   //x position=71.94+1.6657 y position=420.9803-1.22
-.0016 Tc
(2\))Tj   //x position=71.94+1.6657-0.0016 y position=420.9803-1.22
/TT6 1 Tf
.8203 0 TD   //x position=71.94+1.6657-0.0016+0.8203
0 Tc
( )Tj
/TT3 1 Tf
10.016 0 0 10.02 71.94 237.6803 Tm  //x position=71.94 y position=237.6803
<0003>Tj
/TT2 1 Tf

I'm sure that something is wrong, because with this method the sequence is not rebuilt correctly.
Thank you a lot.

Upvotes: 1

Views: 337

Answers (1)

mkl
mkl

Reputation: 96039

First of all you shouldn't try to keep track of multiple scalars separately but instead of the whole current text matrix and text line matrix.

Then you ripped those instructions from the context. So we have to assume no relevant instructions preceded them.

Thus, we start with text matrix and text line matrix equal to the identity matrix.

/TT3 1 Tf
11.9951 0 0 12 71.94 420.9803 Tm

This sets both the text matrix and the text line matrix to

11.9951  0       0
 0      12       0
71.94  420.9803  1

Then

<0003>Tj

advances the text matrix by the width of this string. As I don't know the metrics of TT3, I cannot tell the resulting text matrix.

/TT2 1 Tf
1.6657 -1.22 TD

This multiplies

1       0    0
0       1    0
1.6657 -1.22 1

to the text line matrix from the left, resulting in the new text line matrix (slightly rounded)

11.9951    0       0
 0        12       0
91.92    406.3403  1

Then the text matrix is set to this value, too.

(2\))Tj

This advances the text matrix by the width of this string. As I don't know the metrics of TT2, I cannot tell the resulting text matrix. I don't even know whether this string in TT2 represents one or two glyphs. Thus, I cannot tell how often the character spacing is applied.

/TT6 1 Tf
.8203 0 TD

This multiplies

1       0    0
0       1    0
0.8203  0    1

to the text line matrix from the left, resulting in the new text line matrix (slightly rounded)

 11.9951    0       0
  0        12       0
101.76    406.3403  1

Now

0 Tc
( )Tj

This advances the text matrix by the width of this string. As I don't know the metrics of TT6, I cannot tell the resulting text matrix.

/TT3 1 Tf
10.016 0 0 10.02 71.94 237.6803 Tm

This sets both the text matrix and the text line matrix to

10.016    0        0
0        10.02     0
71.94   237.6803   1

Upvotes: 2

Related Questions