Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - Word spacing calulations in TJ
  FAQ FAQ  Forum Search   Register Register  Login Login

Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

Word spacing calulations in TJ

 Post Reply Post Reply
Author
Mei View Drop Down
New Member
New Member
Avatar

Joined: 28 Mar 2012
Points: 38
Post Options Post Options   Quote Mei Quote  Post ReplyReply Direct Link To This Post Topic: Word spacing calulations in TJ
    Posted: 17 May 2012 at 7:33am
Hi,

I have a scenario as below,

/TT5 1 Tf
.4611 0 TD
-.0006 Tc
1.0581 Tw
[( Adjust )1059.9(notifications)]TJ


Everything is fine except the numeric value in bold inside TJ operator. How to handle this,

I made some research and tried the below,

This is how my rendering begins and continues,


Text to be rendered=Adjust+singleSpace

left = -3.1317007839679718[initially]
...
..

left = -2.1880765652749687--->d  [d is rendered here considering Tc]

left = -1.6325242215534672--->j

left = -1.4109562528319657--->u

left = -0.85540390911046416-->s

left = -0.35600390913896263-->t

left = -0.0787718779174611--->' '//space


//Handling the numeric value inside Tj

We calculate a extra spacing unit as like below,

space= Numeric Value * (fontsize/1000)

left=left-space




This causes left values as,

left = -0.861439892090857(since the fontSize is 1 and NumericValue becomes 1.0599[ie 10599/1000])

This makes the next text(notification) to get collapse with previous char..

Do I miss something..

Thanks,
Mei

Back to Top
aandi View Drop Down
Senior Member
Senior Member


Joined: 07 Jul 2011
Points: 18358
Post Options Post Options   Quote aandi Quote  Post ReplyReply Direct Link To This Post Posted: 17 May 2012 at 8:03am
1. What is the effective Text Matrix at the time of this code fragment?
2. What is the effective CTM at the time of the code fragment?
3. What does Acrobat show?


Edited by aandi - 17 May 2012 at 8:10am
Back to Top
Mei View Drop Down
New Member
New Member
Avatar

Joined: 28 Mar 2012
Points: 38
Post Options Post Options   Quote Mei Quote  Post ReplyReply Direct Link To This Post Posted: 17 May 2012 at 8:13am
Hi Aandi,
Thanks for your reply,

here is my code,

/GS1 gs
BT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
/TT2 1 Tf
.2267 0 TD
.0004 Tc
(1.1)Tj
/TT1 1 Tf
1.2667 0 TD
0 Tc
<0003>Tj
/TT3 1 Tf
.2267 0 TD
<001f>Tj
/TT1 1 Tf
1 0 TD
<0003>Tj
/TT2 1 Tf
.2267 0 TD
.0011 Tc
[(xxxxx)5.3(x)-.1(xxx)]TJ
/TT1 1 Tf
4.4867 0 TD
0 Tc
<0003>Tj
/TT2 1 Tf
.2267 0 TD
-.0002 Tc
(24,)Tj
/TT1 1 Tf
1.26 0 TD
0 Tc
<0003>Tj
/TT2 1 Tf
.2267 0 TD
-.0002 Tc
(2010)Tj
/TT1 1 Tf
2.0267 0 TD
.0006 Tc
<00030003>Tj
ET
/Cs6 cs .50196 0 0 scn
60.54 736.02 6 9.96 re
f
BT
/TT5 1 Tf
10.02 0 0 10.02 72 726.78 Tm
0 g
0 Tc
( )Tj
0 -1.1497 TD
( )Tj
46.1497 -67.5629 TD
.0007 Tc
(3 )Tj
ET
/Cs6 cs .50196 0 0 scn
545.46 36 6 11.52 re
f
BT
/TT12 1 Tf
10.02 0 0 10.02 108 700.2 Tm
0 g
0 Tc
(o)Tj
/TT5 1 Tf
.5988 0 TD
-.0002 Tc
-.0022 Tw
[( )-922.2(The xx)5.1(xxxx x)8.8(x)-.9(xxxxxx)5.1(s)-3.2( xxxx xxx xxxxxxxxxxx)5.1(xx xx)]TJ
20.5569 0 TD
.0002 Tc
-.0026 Tw
[(x xxx)5.5(xxxxxx xxx xx)5.5(xx)6.8(xxxxx xx xxx x)5.5(x)-2.8(xx xx )6(xxxx)6.8(-xxx)6.9(x )]TJ
-19.3593 -1.497 TD
-.0001 Tc
-.0023 Tw
[(xxxxx)5.2(x xxxx)8.2(, xxx xx)5.2(xxx x)5.2(x)-.8( xxx xxxxxxx’)6.5(s)-3.1( xxxx)6.5(xxxxxx l)6.5(x).5(xx xxx xxxx)6.5(xxxxxx xxxxxxx xxxx, xxx xxx )]TJ
T*
-.0004 Tc
-.002 Tw
[(xxxxx)6.2(x)-1.1(xxx x)4.9(x)-3.4( xxxxxxx xx xx)4.9(x xxxxx)4.9(x )]TJ
-5.3892 -1.497 TD
0 Tc
0 Tw
( )Tj
/TT10 1 Tf
T*
<0078>Tj
/TT5 1 Tf
.4611 0 TD
-.0006 Tc
1.0581 Tw
[( Adjust )1059.9(notifications)]TJ
ET
Thanks,
Mei


Edited by Mei - 17 May 2012 at 8:26am
Back to Top
Mei View Drop Down
New Member
New Member
Avatar

Joined: 28 Mar 2012
Points: 38
Post Options Post Options   Quote Mei Quote  Post ReplyReply Direct Link To This Post Posted: 17 May 2012 at 8:27am
Hi aandi,

The adobe shows the document correctly.

Thanks,
Mei
Back to Top
aandi View Drop Down
Senior Member
Senior Member


Joined: 07 Jul 2011
Points: 18358
Post Options Post Options   Quote aandi Quote  Post ReplyReply Direct Link To This Post Posted: 17 May 2012 at 8:33am
I think the problem here is the oversimplified  left = left - space.
This only applies when the text matrix is 1 0 0 d x y.
Your reference to the font size being 1 is oversimplifying and misleading.

Rather than thinking "I have a character position" and "I have a font size" think only "I have a text matrix".

After showing each character, the text matrix is adjusted by the formula in 9.4.4.

The position of the next character in text space is now given by the Tx, Ty components in the updated matrix. (Text positioning is of course adjusted by the CTM as well, without changing the text matrix. Remember that a "cm" operator may appear anywhere between BT and ET.)


Edited by aandi - 17 May 2012 at 8:37am
Back to Top
Mei View Drop Down
New Member
New Member
Avatar

Joined: 28 Mar 2012
Points: 38
Post Options Post Options   Quote Mei Quote  Post ReplyReply Direct Link To This Post Posted: 17 May 2012 at 10:07am
Hi aandi,

Thanks,

Yes, I am updating the TM, TD and Td each time with the value of "left".

Could you please guide me whether I am handling the numeric value inside the TJ correctly. Would it should affect the rendering positions and my implementation works for more than 60% of Pdf documents.

What these values actually mean.

As you said "After showing each character, the text matrix is adjusted by the formula in 9.4.4." could you please send me any link for this. Am using the following document to implement my own pdfviewer,

PDF Reference
sixth edition
Adobe® Portable Document Format
Version 1.7
November 2006

Is there any better materials

Regards,
Mei
Back to Top
aandi View Drop Down
Senior Member
Senior Member


Joined: 07 Jul 2011
Points: 18358
Post Options Post Options   Quote aandi Quote  Post ReplyReply Direct Link To This Post Posted: 17 May 2012 at 10:36am
1. PDF standards

Adobe created the PDF standard and took it through many versions, finally PDF 1.7. 

At that point Adobe made it an "open" standard by giving it to ISO. This was finally adopted as ISO 32000-1. They didn't change the words much but all the section numbers changed.

I don't like ISO 32000-1 as much as the PDF Reference from Adobe; although the words are pretty much the same the layout is not so easy to use. 

However, it _is_ the standard, so I now give references to its section numbers (realistically, I'm not going to look up my replies in two books and give two numbers).

One interesting result of making PDF open is that the standard is no longer free. In fact, to buy it from ISO costs US$250. Happily, Adobe came to an agreement that they could provide the final version of the draft available free, and as far as I know this is identical.  (Who knows what will happen if the standard is ever revised?)

2. The text question.

The important section is the section called "Text space details". This gives everything you need. In particular, there is nothing separate for character position, and nothing separate for font size. There is the text matrix, which is updated according to text operators (Tm, of course, but also Tf and many others). All text showing operations update Tm after showing each character.

The text matrix Tm is used to derive the text rendering matrix Trm for each character. It is Trm which gives the actual position of each character (and also its size, rotation etc.).

Back to Top
Mei View Drop Down
New Member
New Member
Avatar

Joined: 28 Mar 2012
Points: 38
Post Options Post Options   Quote Mei Quote  Post ReplyReply Direct Link To This Post Posted: 17 May 2012 at 12:56pm
Hi aandi,

I will try to implement the Trm for rendering.

Thanks for your helpful guidance.

Regards,
Mei

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.10
Copyright ©2001-2017 Web Wiz Ltd.

This page was generated in 0.156 seconds.