Justifying Text on the Roman Script System
Justifying Text on the Roman Script System
This section describes several important points about the way text is justified
in the Roman Script System:
The weight for allocating extra space to each nonspace character is in
the form of a percentage. This percentage is given by the
Script Manager's smgrCharPortion global variable as a 4.12
fixed-point number, which can be read with GetEnvirons and set
with SetEnvirons by using the smCharPortion verb. There is no
threshold for initiating intercharacter spacing, so this is not a highly
sophisticated model.
Every space in a style run is allocated the same amount of extra width
and thus is the same size, whether or not it is at the beginning or end of
the line or the style run.
For characters that are neither at the beginning nor at the end of the
line, half of the charExtra width is allocated on each side of the
character. Characters that are at the beginning or end of the line are
only allocated half of the charExtra width, which appears on the side of
the character toward the center of the line.
The Script Manager text justification routines do not automatically
strip trailing spaces. To strip trailing spaces in the last style run on
the line, call the VisibleLength function for the last style run and
pass its return value to these routines as the length of the last run.
The Figure below illustrates this model for the justification of text.
Justification in Roman text
Here's how the Script Manager computes the spacing factors for Roman
text.
At the beginning of the line layout process, the Script Manager bases its
values on information obtained by examining the text and a global variable that
contains the ratio used to allocate space among intercharacter spacing and
interword spacing.
Note: The elements in the equations used subsequently in this
discussion are defined here.
Value Meaning
NumChars The number of nonspace characters in the style run.
NumSpaces The number of space characters in the style run.
CharPortion The weight for allocating slop to intercharacter spacing
versus interword spacing.
SpacePortion 1.0 - CharPortion; the weight for allocating slop to
interword spacing.
The number of intercharacter spaces in a given style run is not necessarily
the same as NumChars because characters at the beginning or end of the line
are only allocated half an intercharacter space. The styleRunPosition
parameter for the style run must be used to determine NumInterCharSpaces
for the style run.
NumInterCharSpaces equals
NumChars - 1.0, if styleRunPosition = smOnlyStyleRun
NumChars - 0.5, if styleRunPosition = smLeftStyleRun
NumChars - 0.5, if styleRunPosition = smRightStyleRun
NumChars, if styleRunPosition = smMiddleStyleRun
A total weighted spacing for the style run can then be computed, as follows:
TotWeightedSpace = (NumInterCharSpaces * CharPortion) + (NumSpaces *
SpacePortion)
For Roman text, the NPortionText function returns a value based on
TotWeightedSpace, the font size, and the scaling factors. It is also adjusted by a
factor of 32 for backward compatibility with PortionText results.
NPortionText = TotWeightedSpace * fontSize * ( numer.h/denom.h) / 32.0
By calling NPortionText for each style run on a line, the slop value for the
line can be allocated among each of the style runs on the line to obtain
StyleRunSlop for each style run.
StyleRunSlop equals the amount of slop value allocated to this style run-that
is, the number of pixels by which the style run should be increased or
decreased in width after numerator-denominator scaling has been applied.
Finally, using TotWeightedSpace and StyleRunSlop, the values
MoreSpaceExtra and MoreCharExtra for the style run can be determined-that
is, the extra width for each space character and nonspace character after
numerator-denominator scaling has been applied.
MoreSpaceExtra = (SpacePortion * StyleRunSlop / TotWeightedSpace)
MoreCharExtra = (CharPortion * StyleRunSlop / TotWeightedSpace)
The Figure below demonstrates the capabilities of the Roman justification
routines, DrawJust and NDrawJust, compared to the QuickDraw routines,
The effects of the Roman justification routines