Important: The information in this document is obsolete and should not be used for new development.
StyledLineBreak
TheStyledLineBreakfunction returns the proper location to break a line of text. It breaks the line on a word boundary if possible and allows for multiscript runs and style runs on a single line.
FUNCTION StyledLineBreak(textPtr: Ptr; textLen: LongInt; textStart, textEnd, flags: LongInt; VAR textWidth: Fixed; VAR textOffset: LongInt): StyledLineBreakCode;
textPtr- A pointer to the beginning of a script run on the current line to be broken.
textLen- The number of bytes in the script run on the current line to be broken.
textStart- A byte offset to the beginning of a style run within the script run.
textEnd- A byte offset to the end of the style run within the script run.
flags- Reserved for future expansion; must be 0.
textWidth- The maximum length of the displayed line in pixels.
StyledLineBreakdecrements this value for its own use. Your responsibility is to set it before your first call toStyledLineBreakfor a line.textOffset- Must be nonzero on your first call to
StyledLineBreakfor a line, and zero for subsequent calls toStyledLineBreakfor that line. This value allowsStyledLineBreakto differentiate between the first and subsequent calls, which is important when a long word is found (as described below).- On output,
textOffsetis the count of bytes fromtextPtrto the location in the text string where the line break is to occur.DESCRIPTION
Use theStyledLineBreakfunction when you are laying out lines in an environment that may include text from multiple scripts. To use this function, you need to understand how QuickDraw draws text, which is described in the chapter "QuickDraw Text" in this book.You can only use the
StyledLineBreakfunction when you have organized your text in script runs and style runs within each script run. This type of text organization is used by most text-processing applications that allow for multiscript text. Use this function when you are displaying text in a screen area to determine the best place to break each displayed line. For an overview of how to use this function, read the section "Finding Line Breaks" beginning on page 5-24.What you do is iterate through your text, a script run at a time starting from the first character past the end of the previous line. Use
StyledLineBreakto check each style run in the script run (in memory order) until the function determines that it has arrived at a line break. As you loop through each style run, before callingStyledLineBreak, you must set the text values in the graphics port record that are used by QuickDraw to measure the text. These include the font, font size, and font style of the style run. An example of a loop that uses this function is found in Listing 5-4 on page 5-27.When used with unformatted text,
textStartcan be 0, andtextEndis identical totextLen. With styled text, the interval betweentextStartandtextEndspecifies a style run. The interval betweentextPtrandtextLenspecifies a script run. Note that the style runs inStyledLineBreakmust be traversed in memory order, not in display order.If the current style run is included in a contiguous sequence of other style runs of the same script, then
textPtrshould point to the start of the first style run of the same script on the line, andtextLenshould include the last style run of the same script on the line. This is because word boundaries can extend across style runs, but not across script runs.
StyledLineBreakautomatically decrements thetextWidthvariable by the width of the style run for use on the next call. You need to set the value oftextWidthbefore calling it to process a line.The
textOffsetparameter must be nonzero for the first call on a line and zero for each call to the function on the line. This allowsStyledLineBreakto act differently when a long word is encountered: if the word is in the first style run on the line,StyledLineBreakbreaks the line on a character boundary within the word; if the word is in a subsequent style run on the line,StyledLineBreakbreaks the line before the start of the word.When
StyledLineBreakfinds a line break, it sets the value oftextOffsetto the count of bytes that can be displayed starting attextPtr.
Although the offsets are in long integer values and the widths are in fixed values for future extensions, in the current version the long integer values are restricted to the integer range, and only the integer portion of the widths is used.
- IMPORTANT
- When
StyledLineBreakis called for the second or subsequent style runs within a script run, thetextOffsetvalue at exit may be less than thetextStartparameter (that is, it may specify a line break before the current style run).![]()
StyledLineBreakalways chooses a line break for the last style run on the line in memory order as if all whitespace in that style run would be stripped. TheVisibleLengthfunction, which is a QuickDraw function used to eliminate trailing spaces from a style run before drawing it, can be called for the style run that is at the display end of a line. This leads to a potential conflict when both functions are used with mixed-directional text: if the end of a line in memory order actually occurs in the middle of the displayed line,StyledLineBreakassumes that the whitespace is stripped from that run, butVisibleLengthdoes not strip the characters. TheVisibleLengthfunction is described in the chapter "QuickDraw Text" in this book.The
StyledLineBreakresult (defined by theStyledLineBreakCodedata type) indicates whether the function broke on a word boundary or a character boundary, or if the width extended beyond the edge of the text.ASSEMBLY-LANGUAGE INFORMATION
The trap macro and routine selector for theStyledLineBreakfunction are
Trap macro Selector _ScriptUtil $821C FFFE RESULT CODES
BreakOverflow 2 No line break is yet necessary, since the current style run still fits on the line BreakChar 1 Line breaks on character boundary BreakWord 0 Line breaks on word boundary SEE ALSO
For details on theVisibleLength,TextWidth, andPortionTextfunctions, see the chapter "QuickDraw Text" in this book.