Now, when we already have a mechanism to maintain the data needed for margin kerning, we can move to incorporation of character protruding into text composition. Character protruding can be applied to text composition at two levels.
The straightforward consideration is to implement it into the justification part, LEVEL 1CHARACTER PROTRUDING
i.e. when a paragraph has been already broken into lines and the lines are being jus- tified into the desired width. In this phase, before line justification is done, we check whether the beginning object of each line is a character with nonzero left protruding factor. If so, a kern of corresponding width (which can be either positive or negative) is put before the character. To be exact, a kern of width −Kl as explained above is inserted. By doing so, after justification the character will be shifted to the left by the desired amount. If the beginning object of a line is not a character or a character with zero protruding factor, thenKl is treated as zero. The right protruding factor is applied to the rightmost character in a similar manner. Kr is set to zero if the rightmost object is not a character or a character with zero right protruding factor. Otherwise, a kern of −Kr will be appended after the rightmost character. We call the above procedure level 1 character protruding.
Level 1 character protruding has no effect on line breaking, because it is appliedaf- terthe breakpoints have been found. Therefore, the result of line breaking remains the same as in the case without use of character protruding. This property can be desirable in cases when it is necessary to keep the line breaks (and thus the page breaks) in a document unchanged for backward compatibility.
Level 1 character protruding can influence interword spacing. In most cases, inter- EFFECT ON INTERWORD SPACING
word spacing is a little bit looser than expected, because some lines have to be justified to a wider width than the desired width. This is caused by the fact that when choosing between sequences of breakpoints, the line-breaking algorithm did not take into consid- eration the amount needed to protrude the characters at the margins. After shifting the characters at the margins, the interword spaces can be stretched more than expected. On the other hand, character protruding does not always impair interword spacing. For a line longer than the desired width (shrinking needed for justification), character pro- truding has a desirable effect on interword spacing because the line can be shrunk by a smaller amount. The effect of character protruding can be treated as adding an amount of Kl + Kr to the desired width before adjustment ratio is calculated for glue setting. Depending on the sign of the excess width, this addition can either increase or decrease
the absolute value of the adjustment ratio. The adjustment ratio as stated in Eq. (1) now becomes: r = (l+Kl+Kr −L)/Y, if(l+Kl +Kr −L >0)∧(Y >0); (l+Kl+Kr −L)/Z, if(l+Kl +Kr −L <0)∧(Z >0); 3, undefined otherwise. (4)
In plain words, the adjustment ratio formula with character protruding is obtained by substitutingl withl +Kl+Kr, i.e. the original desired width is replaced by a new value according to the amount needed to protrude the character at the line endings. Adding the protruding amountKl+Kr to the desired widthlcan even change the sign of the final excess width and thus the adjustment ratio. Thus, stretching can become shrinking and vice versa.
In general, level 1 character protruding has some side effects (either desirable or undesirable) on interword spacing of individual lines. Usually these side effects are quite small and the difference between interword spacing with and without character protruding is not very significant. However, it is much better if these side effects are also considered while choosing the breakpoints.
To incorporate character protruding into line breaking, the line-breaking algorithm LEVEL2 CHARACTER
PROTRUDING should be able to take into account the space amount needed to protrude the characters
at the margins of potential lines. This way, after the justification phase, the interword spacing will be set as the algorithm expected, i.e. in an optimal manner for the whole paragraph. We denote the use of character protruding in this case aslevel 2 character protruding.
Let us recall that the basic concept of TEX line breaking is to examine all feasible sequences of breakpoints and choose the one with fewest total demerits, where the total demerits depend on badness and penalty over all potential lines. With character protruding being applied, the badness calculation for a potential line must be adjusted according to the protruding amount of the line that would be applied in the justifica- tion phase.
The badness, as given in Eq. (2), depends on the adjustment ratio, which is again calculated according to the excess width. We already mentioned in level 1 character protrudingthat shifting the margin characters causes an effect similar to increasing the desired width by the protruding amount, and the influence on the adjustment ratio is given in Eq. (4). Thus, what we need now is to increase the desired width of individual lines by the protruding amount Kl + Kr associated with each line. By doing so, the badness calculation of a line will change accordingly. In the justification phase, the same amount will be added to the desired width again before the adjustment ratio will be calculated, so the interword spaces will be stretched or shrunk by the amount that the line-breaking algorithm calculated.
In level 2 character protruding, the badness calculation changes for individual lines, thus the demerits calculation can vary as well. The sequence of breakpoints with fewest
total demerits in level 2 character protruding can differ from the case without applying character protruding. It can even produce a different number of eventual lines. The value of final total demerits can either increase or decrease. However, the variance of total demerits should not be very large in terms of percentage, because the variance of badness for potential lines is often small. Level 2 character protruding has a similar effect to line breaking like the case when the average desired width over all lines is increased a bit.