TextWidthHook
TextEdit Width Hooks
TextEdit's width hooks are called each the time the width of various
components of a line is calculated. This section describes two new hooks,
nWIDTHHook and TextWidthHook, and their relationships with the
original WIDTHHook hook. The new hook nWIDTHHook allows you access to
TextEdit's measuring routine for non-Roman script systems and provides a
way for you to replace this routine with your own script- compatible
measuring routine. TextWidthHook provides a way for you to replace the new
calls to the TextWidth function in TextEdit with your own measuring
routine.
Note: To test for the availability of the new width-measuring hooks, you
can call the Gestalt function with the gestaltTextEditVersion selector. A
result of gestaltTE2 or greater returned in the response parameter
indicates that the new width measurement hook nWIDTHHook is available.
A result of gestaltTE5 or greater returned in the response parameter
indicates that the new text width measurement hook TextWidthHook is
available. (For details, see
Determining the Version of TextEdit.)
TextWidthHook is available for version 6.0.7 (or higher) systems with
non-Roman script systems installed. However, there is no Gestalt constant
that indicates this availability.
The original WIDTHHook hook is available to provide backward
compatibility for your applications. TextEdit still uses WIDTHHook;
however, it now performs additional checks to determine whether to use
WIDTHHook or nWIDTHHook. TextEdit first determines whether a
non-Roman script system is installed. If it is, TextEdit uses the new
nWIDTHHook routine even if an application has overridden WIDTHHook
with a different measuring routine. If TextEdit finds that only the Roman
Script System is installed, it checks to see if WIDTHHook contains the
address of TextEdit's default routine for measuring. If it does, TextEdit uses
the nWIDTHHook routine. Otherwise, an application has provided a different
measuring routine to be used for system software with only the Roman Script
System installed, so TextEdit uses this routine instead of its own default
routine.
It is possible for you to provide alternate routines for both of these hooks to
guarantee that your routine is always used. However, unless the routine
measures correctly for non-Roman scripts, you should only replace
WIDTHHook and TextWidthHook.
The appropriate font, face, and size characteristics have already been set into
the current port by the time any of these routines is called.
The default action for WIDTHHook is to call the QuickDraw function
TextWidth and return.
The default action for nWIDTHHook is to call the Script Manager's
Char2Pixel function or TextWidth to measure accurately for non-Roman
scripts. For more information on Char2Pixel, see
Worldwide Software Overview. For comprehensive details, refer to
Macintosh Worldwide Development: Guide to System Software.
For a discussion of the slop value, see Worldwide Software Overview
description.
TextEdit also includes the new TextWidthHook routine that provides a way
for you to replace the new TextWidth calls in TextEdit with your own
measuring routine. You must use TextWidthHook in addition to WIDTHHook
and nWIDTHHook to replace TextEdit's measuring routines completely.
Note: There is a TextWidth call in the TextBox procedure that does not
use this hook because no edit record is allocated.
The default action for TextWidthHook is to always call the QuickDraw
TextWidth function (the same default action as for the original
WIDTHHook routine).