How the value of the tj operator is generated in a pdf document (justified text)

1.2k views Asked by At

I can't understand and find how the value of the tj operator is generated??

Here I paste result before and after changes in the display of the text (on the second block I changed the position Left-Justice and then again comeback to Centered)

I think pdf use some of prng, but what kind of, I can't find

HElp please

[(\003\024\027\005\003\030\036\b)-114.267(\003\006\007\024\036\b)-113.297(\026\002\024\003\032\020\b)-113.337(\b)-111.574(#\024\002\f\005\002\021\003\007\004\f\005\b)-117.089(\003\006\002\003\b)-114.08


[(\003\024\027\005\003\030\036\b)-114.366(\003\006\007\024\036\b)-113.297(\026\002\024\003\032\020\b)-113.327(\b)-111.693(#\024\002\f\005\002\021\003\007\004\f\005\b)-116.98(\003\006\002\003\b)-114.188

1

There are 1 answers

0
mkl On

First of all, the PDF format does not explicitly support text justification. PDF does not even know text column definitions to justify text in!

All the PDF format supports is

  • setting or changing the text matrix (and text line matrix), scaling, character and word spacing explicitly and
  • drawing text pieces which implicitly changes the text matrix.

Thus, if a PDF processor changes the justification of a line of text, it actually first has to have determined

  • which text pieces belong together and form that line of text;

    text pieces can be given as arguments of the Tj or TJ instructions (or more seldom the " or ' instructions); in simple cases the whole line is drawn using a single instruction but you cannot count on that in general; and

  • what the left and right borders of the text column are to justify between;

    e.g. these borders might be standard values assumed by the processor for certain page formats or derived from the current clip path.

Having determined these data, the procedure differs for different kinds of justification:

  • left justification - position the text matrix at the left text column border at the height of the line and simple let the text drawing instructions follow;
  • right justification - calculate the width of the drawn line using the current font, position the text matrix at the right text column border minus that width at the height of the line, and let the text drawing instructions follow;
  • center justification - calculate the width of the drawn line using the current font, position the text matrix at the middle of the text column minus half that width at the height of the line, and let the text drawing instructions follow;
  • full justification - calculate the width of the drawn line using the current font, set the character spacing and word spacing (using the Tc and Tw instructions, probably with a tweak of the Tz horizontal scaling) to use up the difference between that width and the text column width, position the text matrix at the left text column border at the height of the line, and let the text drawing instructions follow;

    or calculate the width of the drawn line using the current font, change the text drawing instructions to use up the difference between that width and the text column width (e.g. using the numeric TJ array argument values), position the text matrix at the left text column border at the height of the line, and let the changed text drawing instructions follow;

    or even apply a combination of these methods.

(The changes applied when doing a full justification - character spacing, word spacing, changes of text drawing instructions - obviously additionally are undone when later again changing to another type of justification...)

Positioning the text matrix can happen using the Tm, Td, TD, and T* instructions.

By the way, the positioning and scaling of the text also is influenced by the current transformation matrix. Thus, cm instructions can also be used for justification. But this is less likely than the use of the instructions mentioned above...


Unfortunately you merely supplied an excerpt from the array argument of a TJ instruction before and after such a justification job. One sees that the numeric elements of that array change very slightly. Whether this actually is the justification itself (as per the second option of the full justification above) or merely some computational inaccuracy cannot be told without the context.