Retired Document
Important: This document may not represent best practices for current development. Links to downloads and other resources may no longer be valid.
QuickDraw Text Reference (Not Recommended)
| Framework | ApplicationServices/ApplicationServices.h |
| Declared in | Quickdraw.h QuickdrawText.h |
Overview
You can use the QuickDraw text routines to measure and draw text ranging in complexity from a single glyph to a line of justified text containing multiple languages and styles. In addition to measuring and drawing text, the QuickDraw text routines also help you to determine which characters to highlight and where to position the caret to mark the insertion point. These routines translate pixel locations into byte offsets and vice versa.
To understand the routines described in this document, it is helpful to be familiar with the other parts of QuickDraw. It is also helpful to be familiar with the Font Manager, because of the close relationship between QuickDraw and the Font Manager. To understand the tasks involved in text layout, you should also be acquainted with the Text Utilities and the Script Manager.
Carbon supports the majority of QuickDraw Text.
Functions by Task
Determining the Caret Position, and Selecting and Highlighting Text
-
CharToPixelAvailable in OS X v10.0 through OS X v10.6 -
HiliteTextAvailable in OS X v10.0 through OS X v10.6 -
PixelToCharAvailable in OS X v10.0 through OS X v10.6
Drawing Text
-
DrawCharAvailable in OS X v10.0 through OS X v10.6 -
DrawJustifiedAvailable in OS X v10.0 through OS X v10.6 -
DrawStringAvailable in OS X v10.0 through OS X v10.6 -
DrawTextAvailable in OS X v10.0 through OS X v10.6 -
StandardGlyphsAvailable in OS X v10.0 through OS X v10.6 -
StdTextAvailable in OS X v10.0 through OS X v10.6 -
stdtextAvailable in OS X v10.0 through OS X v10.6
Laying Out a Line of Text
-
GetFormatOrderAvailable in OS X v10.0 through OS X v10.6 -
PortionLineAvailable in OS X v10.0 through OS X v10.6 -
VisibleLengthAvailable in OS X v10.0 through OS X v10.6
Measuring Text
-
CharWidthAvailable in OS X v10.0 through OS X v10.6 -
MeasureJustifiedAvailable in OS X v10.0 through OS X v10.6 -
MeasureTextAvailable in OS X v10.0 through OS X v10.6 -
StdTxMeasAvailable in OS X v10.0 through OS X v10.6 -
StringWidthAvailable in OS X v10.0 through OS X v10.6 -
TextWidthAvailable in OS X v10.0 through OS X v10.6
Setting Text Characteristics
-
CharExtraAvailable in OS X v10.0 through OS X v10.6 -
GetFontInfoAvailable in OS X v10.0 through OS X v10.6 -
SpaceExtraAvailable in OS X v10.0 through OS X v10.6 -
TextFaceAvailable in OS X v10.0 through OS X v10.6 -
TextFontAvailable in OS X v10.0 through OS X v10.6 -
TextModeAvailable in OS X v10.0 through OS X v10.6 -
TextSizeAvailable in OS X v10.0 through OS X v10.6
Truncating Strings and Breaking Lines
-
StyledLineBreakAvailable in OS X v10.0 through OS X v10.6 -
TruncStringAvailable in OS X v10.0 through OS X v10.6 -
TruncTextAvailable in OS X v10.0 through OS X v10.6
Working With Universal Procedure Pointers
-
DisposeStyleRunDirectionUPPAvailable in OS X v10.0 through OS X v10.6 -
InvokeStyleRunDirectionUPPAvailable in OS X v10.0 through OS X v10.6 -
NewStyleRunDirectionUPPAvailable in OS X v10.0 through OS X v10.6
Callbacks
StyleRunDirectionProcPtr
Defines a pointer to a style run direction callback function that calculates, for a style run identified by number, the direction of that style run.
typedef Boolean (*StyleRunDirectionProcPtr) ( short styleRunIndex, void * dirParam );
If you name your function MyStyleRunDirectionProc, you would declare it like this:
Boolean StyleRunDirectionProcPtr ( short styleRunIndex, void * dirParam );
Parameters
- styleRunIndex
A value that identifies the style run whose direction is needed.
- dirParam
A pointer to an application-defined parameter block that contains the font and script information for each style run in the text. The contents of this parameter block are used to determine the direction of the style run. Because of the relationship between the font family ID and the script code, the font family ID can be used to determine the text direction.
Return Value
A Boolean value that is TRUE for right-to-left text direction, FALSE for left-to-right.
Discussion
To fill the ordering array (type FormatOrder) for style runs on a line, the GetFormatOrder function calls MyStyleRunDirectionCallback for each style run numbered from firstFormat to lastFormat. GetFormatOrder passes MyStyleRunDirectionCallback a number identifying the style run in storage order, and a pointer to the parameter information block, dirParam, that contains the font and style information for the style run. Given dirParam and a style run identifier, the application-defined MyStyleRunDirectionCallback function should be able to determine the style run direction.
You should store your style run information in a way that makes it convenient for MyStyleRunDirectionCallback. One obvious way to do this is to declare a structure type for style runs that allows you to save things like font style, font family ID, script number, and so forth. You then can store these structures in an array. When the time comes for GetFormatOrder to fill the ordering array, MyStyleRunDirectionCallback can consult the style run array for direction information for each of the numbered style runs in turn.
For more information, see GetFormatOrder.
When you provide the Component Manager with a pointer to your function, you should use a universal procedure pointer (UPP). The definition of the UPP data type for your file identification function is as follows:
typedef (StyleRunDirectionProcPtr) StyleRunDirectionUPP;
Before using your style run direction callback function, you must first create a new universal procedure pointer to it, using the NewStyleRunDirectionUPP function, as shown here:
StyleRunDirectionUPP MyStyleRunDirectionUPP;
MyStyleRunDirectionUPP = StyleRunDirectionUPP(&MyStyleRunDirectionCallback)
You then pass MyStyleRunDirectionUPP to the function GetFormatOrder. If you wish to call your own callback function, you can use the InvokeStyleRunDirectionUPP function:
direction = InvokeStyleRunDirectionUPP(styleRunIndex, ¶mInfo, MyStyleRunDirectionUPP)
When you are finished using your callback function, you should dispose of the universal procedure pointer associated with it, using the DisposeStyleRunDirectionUPP function.
DisposeStyleRunDirectionUPP(MyStyleRunDirectionUPP);
Availability
- Available in OS X v10.0 through OS X v10.6.
Declared In
QuickdrawText.hData Types
FontInfo
Contains font metric information.
struct FontInfo {
short ascent;
short descent;
short widMax;
short leading;
};
typedef struct FontInfo FontInfo;
Fields
ascentThe measurement, in pixels, from the baseline to the ascent line of the font.
descentThe measurement, in pixels, from the baseline to the descent line of the font.
widMaxThe width, in pixels, of the largest glyph in the font.
leadingThe measurement, in pixels, from the descent line to the ascent line below it.
Discussion
The FontInfo data type defines a font information structure. The GetFontInfo function uses the font information structure to return measurement information based on the font of the current graphics port. If the current font has an associated font, as do Arabic and Hebrew, GetFontInfo returns information based on both fonts. The font information structure contains the ascent, the descent, the width of the largest glyph, and the leading for a given font. The StdTxMeas function also uses a structure of type FontInfo to return information about the current font.
Availability
- Available in OS X v10.0 and later.
Declared In
Quickdraw.hFormatOrder
Contains and array of display orders for style runs.
typedef FormatOrder[1];
Discussion
The GetFormatOrder function fills the supplied format order array with the display order of each style run.
Availability
- Available in OS X v10.0 through OS X v10.6.
Declared In
QuickdrawText.hStyleRunDirectionUPP
Defines a universal procedure pointer to a style run direction callback.
typedef StyleRunDirectionProcPtr StyleRunDirectionUPP;
Discussion
For more information, see the description of the StyleRunDirectionProcPtr callback function.
Availability
- Available in OS X v10.0 through OS X v10.6.
Declared In
QuickdrawText.hConstants
Caret Direction Constants
Specify a caret position.
enum {
leftCaret = 0,
rightCaret = -1,
kHilite = 1
};
Constants
leftCaretPlace caret for left-to-right text direction.
Available in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.rightCaretPlace caret for right-to-left text direction.
Available in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.kHiliteSpecifies that the caret position should be determined according to the primary line direction, based on the value of
SysDirection.Available in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.
Discussion
You can use these constants to specify a value for direction, as used in the CharToPixel function.
Truncation Status Values
Returned as result codes for the functions TruncString and TruncText.
enum {
notTruncated = 0,
truncated = 1,
truncErr = -1,
smNotTruncated = 0,
smTruncated = 1,
smTruncErr = -1
};
Constants
notTruncatedSpecifies that truncation is not necessary.
Available in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.truncatedSpecifies that truncation was performed.
Available in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.truncErrSpecifies a general error occurred.
Available in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.smNotTruncatedSpecifies that truncation is not necessary. This is obsolete.
Available in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.smTruncatedSpecifies that truncation was performed. This is obsolete.
Available in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.smTruncErrSpecifies a general error occurred. This is obsolete.
Available in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.
Style Line Break Values
Specify a line break.
typedef SInt8 StyledLineBreakCode;
enum {
smBreakWord = 0,
smBreakChar = 1,
smBreakOverflow = 2
};
Constants
smBreakWordAvailable in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.smBreakCharAvailable in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.smBreakOverflowAvailable in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.
Obsolete Caret Placement Values
Specify where to place a caret.
enum {
smLeftCaret = 0,
smRightCaret = -1,
smHilite = 1
};
Constants
smLeftCaretSpecifies to place caret for left block. This is obsolete.
Available in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.smRightCaretSpecifies to place caret for right block. This is obsolete.
Available in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.smHiliteSpecifies the direction is
TESysJust. This is obsolete.Available in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.
Style Run Position Constants
Specify style run positions.
typedef short JustStyleCode;
enum {
onlyStyleRun = 0,
leftStyleRun = 1,
rightStyleRun = 2,
middleStyleRun = 3,
smOnlyStyleRun = 0,
smLeftStyleRun = 1,
smRightStyleRun = 2,
smMiddleStyleRun = 3
};
Constants
onlyStyleRunThis is the only style run on the line.
Available in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.leftStyleRunThis is the leftmost of multiple style runs on the line.
Available in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.rightStyleRunThis is the rightmost of multiple style runs on the line
Available in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.middleStyleRunThe line and this one is interior: neither leftmost nor rightmost.
Available in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.smOnlyStyleRunThis is obsolete.
Available in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.smLeftStyleRunThis is obsolete.
Available in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.smRightStyleRunThis is obsolete.
Available in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.smMiddleStyleRunThis is obsolete.
Available in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.
Discussion
Use one of the following constants (defined as type JustStyleCode) in the styleRunPosition parameter for PortionLine DrawJustified, MeasureJustified, CharToPixel, and PixelToChar.
txFlag Constants
Specify constants for txFlags.
enum {
tfAntiAlias = 1 << 0,
tfUnicode = 1 << 1
};
Constants
tfAntiAliasAvailable in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.tfUnicodeAvailable in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.
Discussion
These used to be the pad field after txFace.
Truncation Positions
Specify where to truncate a string.
typedef TruncCode;
enum {
truncEnd = 0,
truncMiddle = 0x4000,
smTruncEnd = 0,
smTruncMiddle = 0x4000
};
Constants
truncEndTruncate at end.
Available in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.truncMiddleTruncate in middle.
Available in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.smTruncEndTruncate at end. This is obsolete.
Available in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.smTruncMiddleTruncate in middle. This is obsolete.
Available in OS X v10.0 through OS X v10.6.
Declared in
QuickdrawText.h.
© 2003, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-13)