Important: The information in this document is obsolete and should not be used for new development.
CharToPixel
TheCharToPixelfunction returns the screen pixel width from the left edge of a text segment to the glyph of the character whose byte offset you specify.
FUNCTION CharToPixel (textBuf: Ptr; textLen: LongInt; slop: Fixed; offset: LongInt; direction: Integer; styleRunPosition: JustStyleCode; numer: Point; denom: Point): Integer;
textBuf- A pointer to the beginning of the text segment.
textLen- The length in bytes of the entire text segment pointed to by
textBuf. TheCharToPixelfunction requires the context of the complete text in order to determine the correct value.slop- The amount of slop for the text to be drawn. A positive value extends the text segment; a negative value condenses the text segment.
offset- The offset from
textBufto the character within the text segment whose display pixel location is to be measured. For 2-byte script systems, if the character whose position is to be measured is 2 bytes long, this is the offset of the first byte.direction- This parameter specifies whether
CharToPixelis to return the caret position for a character with a direction of left-to-right or right-to-left. A direction value ofhiliteindicates thatCharToPixelis to use the caret position for the character direction that matches the primary line direction as specified by theSysDirectionglobal variable.styleRunPosition- The position on the line of this style run. The style run can be the only one on the line, the leftmost on the line, the rightmost on the line, or one between two other style runs.
numer- A point giving the numerator for the horizontal and vertical
scaling factors.denom- A point giving the denominator for the horizontal and vertical
scaling factors.DESCRIPTION
You useCharToPixelto find the onscreen pixel location at which to draw a caret and to identify the selection points for highlighting. TheCharToPixelfunction returns the horizontal distance in pixels from the start of the range of text beginning with the byte offset attextBufto the glyph corresponding to the character whose byte offset is specified by theoffsetparameter. The pixel location is relative to the beginning of the text segment, not the left margin of the display line. To get the actual display line pixel location of the glyph relative to the left margin, you add the pixel value thatCharToPixelreturns to the pixel location at the end of the previous style run (on the left) in display order. In other words, you need to know the length of the text in pixels on the display line up to the beginning of the range of text that you callCharToPixelfor, and then you add in the screen pixel width thatCharToPixelreturns.You specify a value for
textLenthat is equal to the entire visible part of the style run on a line and includes trailing spaces if and only if they are displayed. They may not be displayed, for example, for the last style run in memory order, which is part of the line. Do not confuse thetextLenparameter with theoffset, which is the byte offset of the character within the text segment whose pixel locationCharToPixelis to return.If you use
CharToPixelto get a caret position to mark the insertion point, you specify a value ofleftCaretorrightCaretfor thedirectionparameter. You can use the value of thePixelToCharleadingEdgeflag to determine thedirectionparameter value.If the
leadingEdgeflag isFALSE, you base the value of thedirectionparameter on the direction of the character at the byte offset in memory that precedes the one thatPixelToCharreturns; ifleadingEdgeisTRUE, you base the value of the direction parameter on the direction of the character at the byte offset thatPixelToCharreturns. If there isn't a character at the byte offset, you base the value of thedirectionparameter on the primary line direction as determined by theSysDirection
global variable.You can use the following constants to specify a value for
direction.For more information about the scaling factors, see "The numer and denom Parameters" on page 3-64. See "The styleRunPosition Parameter" on page 3-63 for a description of the
styleRunPositionparameter and the values it takes. See "The slop Parameter" on page 3-63 for more information about theslopparameter.
For more information about
- Note
- Be sure to pass the same values for
styleRunPositionand the scaling factors (numeranddenom) toCharToPixelthat you pass to any of the other justification routines for this style run.![]()
CharToPixelsee "Drawing Carets and Highlighting" on page 3-46.SPECIAL CONSIDERATIONS
TheCharToPixelfunction works with text in all script systems. For 1-byte contextual script systems,CharToPixelcalculates the widths of any ligatures, reversals, and compound characters that need to be drawn.Note that
textLenis the number of bytes to be drawn, not the number of characters. Because 2-byte script systems also include characters consisting of only one byte, do not simply multiply the number of characters by 2 to determine this value; you must determine and specify the correct number of bytes.The
CharToPixelfunction may move memory; do not call this procedure at
interrupt time.