NPixel2Char
NPixel2Char Find the nearest character offset
#include <Script.h> Script Manager
short NPixel2Char(textBuf, textLen, slop, pixelWidth, leadingEdge,
widthRemaining, styleRunPosition, numer, denom );
Ptr textBuf ; address of a text buffer
long textLen ; value for text length
Fixed slop ; value indicating extra pixels
Fixed pixelWidth ; indicates the width of a character
Boolean *leadingEdge ; indicates the beginning of the character
Fixed * widthRemaining ; amount of excess width
JustStyleCode styleRunPosition ; the position of a style run within the line
Point numer ; scaling factor
Point denom ; scaling factor
The NPixel2Char function helps you find the nearest character offset
within a text buffer corresponding to a given pixel width. It returns an integer
that is the offset of the character closest to pixelWidth. It is the inverse of the
NChar2Pixel function.
textBuf is a text buffer indicated by a pointer.
textLen is the length of the buffer.
slop is the number of pixels to add to a string's width after it has been
scaled.
pixelWidth indicates the width of a character.
leadingEdge TRUE if the offset is on the leading edge of the character.
widthRemaining :ÍE
amount of excess width. If the pixelWidth parameter that is passed
into NPixel2Char is greater than the width of the text specified by
the textBuf and textLen parameters, the amount of excess width is
returned in the widthRemaining parameter; otherwise,
widthRemaining is set to -1.
styleRunPosition For correct spacing between multiple style runs, you can specify
the position of a style run within the line by using the
styleRunPosition parameter of type JustStyleCode. See below for a
list of the values and meanings for these constants.
numer is a scaling factor
denom is a scaling factor
Returns: a short, indicating the offset of the character PixelWidth is closest
to.

Notes: The most common application of NPixel2Char is identifying the
character where a mouse-down event occurs in text and whether it is on the
leading or trailing edge of the character. For correct spacing between
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 in Justifying Text on the Roman Script System.
Note: In the NMeasureJust, NChar2Pixel, and NPixel2Char
routines, the text length should equal the entire visible part of the
style run on a line and should include trailing spaces if and only if
they are displayed. (They may not be displayed for the last style run
in the line, for example.) Otherwise, the results for the last
character on the line may be in valid.