NPortionText
NPortionText Indicates the correct proportion of justification
#include <Script.h> Script Manager
Fixed NPortionText( textPtr, textLen, styleRunPostion, numer,
denom);
Ptr textPtr ; a pointer to the text to be justified
long textLen ; specifies the length of the text
JustStyleCode StyleRunPosition; position of a style run within the line
Point numer ; scaling factor
Point denom ; scaling factor
returns a fixed "magic number" that is based on the number
of spaces, number of characters, font, size, style,
styleRunPosition value, and the scaling parameters.
The NPortionText procedure supplies a new version of PortionText that
lets you indicate the position of a style run within a line for lines with
multiple style runs and accepts scaling parameters

Notes:The NPortionText function allows you to find out how to distribute the slop
value for a line among the style runs on the line. The textPtr parameter is a
pointer to the text while textLength is a long integer that indicates the
length of the text. The function returns a fixed "magic number" that is based
on the number of spaces, number of characters, font, size, style,
styleRunPosition value, and the scaling parameters.
You should call NPortionText for all of the style runs on a line, and the
slop value for the line should be allocated among the style runs in the same
ratio as their NPortionText return values. To allocate spacing among
multiple style runs, you can specify the position of a style run within the
line by using the styleRunPosition parameter of type JustStyleCode.
To handle the spacing between multiple style runs on a line correctly, the
new justification routines take a styleRunPosition parameter that specifies
the position of the style run on a line.
The values for styleRunPosition are as follows:
Constant Meaning
smOnlyStyleRun This style run is the only one on the line.
smLeftStyleRun Multiple style runs are on the line, and this is the
leftmost.
smRightStyleRun Multiple style runs are on the line, and this is the
rightmost.
smMiddleStyleRun Multiple style runs are on the line, and this is
neither the leftmost nor the rightmost.
If styleRunPosition has the value smOnlyStyleRun, the justification
routines behave exactly like their earlier versions. For other values of
styleRunPosition, the behavior may depend on the script. The behavior for
Roman is described in Justifying Text on the Roman Script System.
For example, suppose that there are three style runs on a line: A, B, and C.
The line needs to be widened by 11 pixels for justification. Calling
PortionText on these format runs yields the first row in the Table below.
Table Proportions of slop value to be distributed
A B C Total
PortionText 5.4 7.3 8.2 20.9
Normalized .258 .349 remainder 1.00
Pixels (p) 2.84 3.84 remainder 11.0
Rounded (r) 3 4 remainder 11
You can use these values to compute weighted spacing. The proportion of the
justification to be allotted to A is 25.8 percent, so it receives 3 pixels out
of 11. In general, to prevent rounding errors, rn = round(∑1..n p) -
1..n-1 r (which can be computed iteratively); for example, rB is
round(3.84+2.84) - 3, and rC is round(11.0) - 7.
The code example below provides a code sample that illustrates the action
of the NPortionText function. The CalcJustAmount routine in the code
example below expects an array of the following type of records.
The CalcJustAmount routine also takes as a parameter a count of the total
number of records that the array contains. Finally, the extra pixel width to
be distributed is passed in as the TotalPixelSlop parameter. The routine
calculates the amount of slop that should be allocated to each run, and
assigns that value to the field tJustAmount.
// Listing Distributing slop value among style runs
// Assuming inclusion of
#include <Script.h>
#include <FixMath.h>
#define MaxRuns 100
typedef struct {
Ptr tPtr;
long tLength;
Style tFace;
short tFont;
short tSize;
JustStyleCode tPlaceOnLine;
Point t numer, tdenom;
Fixed tJustAmount;
} RunRecord;
typedef RunRecord RunArray[MaxRuns];
void CalcJustAmount (RunArray rArray, short NRuns, short TotalPixelSlop);
void CalcJustAmount (RunArray rArray, short NRuns, short TotalPixelSlop)
{
short i;
Fixed TotalSlopProportion;
// First find the proportion for each run, temporarily remembering it
// in the tJustAmount field of the record, and summing the
// returned values in TotalSlopProportion.
TotalSlopProportion = 0;
for (i = 0; i < NRuns; i++) {
//set the grafPort's font settings to correspond to this run
TextFace(rArray[i].tFace);
TextFont(rArray[i].tFont);
TextSize(rArray[i].tSize);
rArray[i].tJustAmount = NPortionText(rArray[i].tPtr,
rArray[i].tLength, rArray[i].tPlaceOnLine, rArray[i].t numer,
Array[i].tdenom);
TotalSlopProportion = TotalSlopProportion + rArray[i].tJustAmount;
}
// Having found the portion of slop to be allocated to each run,
// normalize it ( runportion / totalportion), and then convert
// that value to
// UnRounded Pixels ( (runportion / totalportion) * TotalPixelSlop ).
for (i = 0; i < NRuns; i++)
// Note you can round the value calculated here by using
// the FixRound routine.
rArray[i].tJustAmount = FixMul(FixDiv(rArray[i].tJustAmount,
TotalSlopProportion),TotalPixelSlop);
}