diff options
Diffstat (limited to 'generic/tkFont.c')
-rw-r--r-- | generic/tkFont.c | 2347 |
1 files changed, 1239 insertions, 1108 deletions
diff --git a/generic/tkFont.c b/generic/tkFont.c index 95feec3..1a6474f 100644 --- a/generic/tkFont.c +++ b/generic/tkFont.c @@ -1,44 +1,42 @@ -/* +/* * tkFont.c -- * - * This file maintains a database of fonts for the Tk toolkit. - * It also provides several utility procedures for measuring and - * displaying text. + * This file maintains a database of fonts for the Tk toolkit. It also + * provides several utility functions for measuring and displaying text. * * Copyright (c) 1990-1994 The Regents of the University of California. * Copyright (c) 1994-1998 Sun Microsystems, Inc. * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ -#include "tkPort.h" #include "tkInt.h" #include "tkFont.h" /* - * The following structure is used to keep track of all the fonts that - * exist in the current application. It must be stored in the - * TkMainInfo for the application. + * The following structure is used to keep track of all the fonts that exist + * in the current application. It must be stored in the TkMainInfo for the + * application. */ - + typedef struct TkFontInfo { - Tcl_HashTable fontCache; /* Map a string to an existing Tk_Font. - * Keys are string font names, values are - * TkFont pointers. */ + Tcl_HashTable fontCache; /* Map a string to an existing Tk_Font. Keys + * are string font names, values are TkFont + * pointers. */ Tcl_HashTable namedTable; /* Map a name to a set of attributes for a * font, used when constructing a Tk_Font from - * a named font description. Keys are - * strings, values are NamedFont pointers. */ + * a named font description. Keys are strings, + * values are NamedFont pointers. */ TkMainInfo *mainPtr; /* Application that owns this structure. */ int updatePending; /* Non-zero when a World Changed event has - * already been queued to handle a change to - * a named font. */ + * already been queued to handle a change to a + * named font. */ } TkFontInfo; /* * The following data structure is used to keep track of the font attributes - * for each named font that has been defined. The named font is only deleted + * for each named font that has been defined. The named font is only deleted * when the last reference to it goes away. */ @@ -48,84 +46,83 @@ typedef struct NamedFont { * last reference goes away. */ TkFontAttributes fa; /* Desired attributes for named font. */ } NamedFont; - + /* - * The following two structures are used to keep track of string - * measurement information when using the text layout facilities. + * The following two structures are used to keep track of string measurement + * information when using the text layout facilities. * * A LayoutChunk represents a contiguous range of text that can be measured - * and displayed by low-level text calls. In general, chunks will be - * delimited by newlines and tabs. Low-level, platform-specific things - * like kerning and non-integer character widths may occur between the - * characters in a single chunk, but not between characters in different - * chunks. - * - * A TextLayout is a collection of LayoutChunks. It can be displayed with - * respect to any origin. It is the implementation of the Tk_TextLayout - * opaque token. + * and displayed by low-level text calls. In general, chunks will be delimited + * by newlines and tabs. Low-level, platform-specific things like kerning and + * non-integer character widths may occur between the characters in a single + * chunk, but not between characters in different chunks. + * + * A TextLayout is a collection of LayoutChunks. It can be displayed with + * respect to any origin. It is the implementation of the Tk_TextLayout opaque + * token. */ typedef struct LayoutChunk { - CONST char *start; /* Pointer to simple string to be displayed. + const char *start; /* Pointer to simple string to be displayed. * This is a pointer into the TkTextLayout's * string. */ int numBytes; /* The number of bytes in this chunk. */ int numChars; /* The number of characters in this chunk. */ int numDisplayChars; /* The number of characters to display when - * this chunk is displayed. Can be less than + * this chunk is displayed. Can be less than * numChars if extra space characters were - * absorbed by the end of the chunk. This - * will be < 0 if this is a chunk that is - * holding a tab or newline. */ + * absorbed by the end of the chunk. This will + * be < 0 if this is a chunk that is holding a + * tab or newline. */ int x, y; /* The origin of the first character in this * chunk with respect to the upper-left hand * corner of the TextLayout. */ - int totalWidth; /* Width in pixels of this chunk. Used - * when hit testing the invisible spaces at - * the end of a chunk. */ + int totalWidth; /* Width in pixels of this chunk. Used when + * hit testing the invisible spaces at the end + * of a chunk. */ int displayWidth; /* Width in pixels of the displayable - * characters in this chunk. Can be less than + * characters in this chunk. Can be less than * width if extra space characters were * absorbed by the end of the chunk. */ } LayoutChunk; typedef struct TextLayout { Tk_Font tkfont; /* The font used when laying out the text. */ - CONST char *string; /* The string that was layed out. */ - int width; /* The maximum width of all lines in the - * text layout. */ - int numChunks; /* Number of chunks actually used in - * following array. */ - LayoutChunk chunks[1]; /* Array of chunks. The actual size will - * be maxChunks. THIS FIELD MUST BE THE LAST - * IN THE STRUCTURE. */ + const char *string; /* The string that was layed out. */ + int width; /* The maximum width of all lines in the text + * layout. */ + int numChunks; /* Number of chunks actually used in following + * array. */ + LayoutChunk chunks[1]; /* Array of chunks. The actual size will be + * maxChunks. THIS FIELD MUST BE THE LAST IN + * THE STRUCTURE. */ } TextLayout; /* * The following structures are used as two-way maps between the values for - * the fields in the TkFontAttributes structure and the strings used in - * Tcl, when parsing both option-value format and style-list format font - * name strings. + * the fields in the TkFontAttributes structure and the strings used in Tcl, + * when parsing both option-value format and style-list format font name + * strings. */ -static TkStateMap weightMap[] = { +static const TkStateMap weightMap[] = { {TK_FW_NORMAL, "normal"}, {TK_FW_BOLD, "bold"}, {TK_FW_UNKNOWN, NULL} }; -static TkStateMap slantMap[] = { +static const TkStateMap slantMap[] = { {TK_FS_ROMAN, "roman"}, {TK_FS_ITALIC, "italic"}, {TK_FS_UNKNOWN, NULL} }; -static TkStateMap underlineMap[] = { +static const TkStateMap underlineMap[] = { {1, "underline"}, {0, NULL} }; -static TkStateMap overstrikeMap[] = { +static const TkStateMap overstrikeMap[] = { {1, "overstrike"}, {0, NULL} }; @@ -135,7 +132,7 @@ static TkStateMap overstrikeMap[] = { * TkFontAttributes. */ -static TkStateMap xlfdWeightMap[] = { +static const TkStateMap xlfdWeightMap[] = { {TK_FW_NORMAL, "normal"}, {TK_FW_NORMAL, "medium"}, {TK_FW_NORMAL, "book"}, @@ -144,16 +141,16 @@ static TkStateMap xlfdWeightMap[] = { {TK_FW_BOLD, "demi"}, {TK_FW_BOLD, "demibold"}, {TK_FW_NORMAL, NULL} /* Assume anything else is "normal". */ -}; +}; -static TkStateMap xlfdSlantMap[] = { +static const TkStateMap xlfdSlantMap[] = { {TK_FS_ROMAN, "r"}, {TK_FS_ITALIC, "i"}, {TK_FS_OBLIQUE, "o"}, {TK_FS_ROMAN, NULL} /* Assume anything else is "roman". */ }; -static TkStateMap xlfdSetwidthMap[] = { +static const TkStateMap xlfdSetwidthMap[] = { {TK_SW_NORMAL, "normal"}, {TK_SW_CONDENSE, "narrow"}, {TK_SW_CONDENSE, "semicondensed"}, @@ -162,11 +159,11 @@ static TkStateMap xlfdSetwidthMap[] = { }; /* - * The following structure and defines specify the valid builtin options - * when configuring a set of font attributes. + * The following structure and defines specify the valid builtin options when + * configuring a set of font attributes. */ -static CONST char *fontOpt[] = { +static const char *fontOpt[] = { "-family", "-size", "-weight", @@ -185,10 +182,10 @@ static CONST char *fontOpt[] = { #define FONT_NUMFIELDS 6 /* - * Hardcoded font aliases. These are used to describe (mostly) identical - * fonts whose names differ from platform to platform. If the - * user-supplied font name matches any of the names in one of the alias - * lists, the other names in the alias list are also automatically tried. + * Hardcoded font aliases. These are used to describe (mostly) identical fonts + * whose names differ from platform to platform. If the user-supplied font + * name matches any of the names in one of the alias lists, the other names in + * the alias list are also automatically tried. */ static char *timesAliases[] = { @@ -226,7 +223,7 @@ static char *gothicAliases[] = { /* Windows (MS goshikku). */ "\344\270\270\343\202\264\343\202\267\343\203\203\343\202\257\342\210\222\357\274\255", /* Mac (goshikku-M). */ - NULL + NULL }; static char *dingbatsAliases[] = { @@ -245,43 +242,46 @@ static char **fontAliases[] = { gothicAliases, dingbatsAliases, NULL -}; +}; /* - * Hardcoded font classes. If the character cannot be found in the base - * font, the classes are examined in order to see if some other similar - * font should be examined also. + * Hardcoded font classes. If the character cannot be found in the base font, + * the classes are examined in order to see if some other similar font should + * be examined also. */ static char *systemClass[] = { - "fixed", /* Unix. */ - /* Windows. */ - "chicago", "osaka", "sistemny", /* Mac. */ + "fixed", /* Unix. */ + /* Windows. */ + "chicago", "osaka", "sistemny", + /* Mac. */ NULL }; static char *serifClass[] = { - "times", "palatino", "mincho", /* All platforms. */ - "song ti", /* Unix. */ - "ms serif", "simplified arabic", /* Windows. */ - "latinski", /* Mac. */ + "times", "palatino", "mincho", + /* All platforms. */ + "song ti", /* Unix. */ + "ms serif", "simplified arabic", + /* Windows. */ + "latinski", /* Mac. */ NULL }; static char *sansClass[] = { - "helvetica", "gothic", /* All platforms. */ - /* Unix. */ + "helvetica", "gothic", /* All platforms. */ + /* Unix. */ "ms sans serif", "traditional arabic", - /* Windows. */ - "bastion", /* Mac. */ + /* Windows. */ + "bastion", /* Mac. */ NULL }; static char *monoClass[] = { - "courier", "gothic", /* All platforms. */ - "fangsong ti", /* Unix. */ - "simplified arabic fixed", /* Windows. */ - "monaco", "pryamoy", /* Mac. */ + "courier", "gothic", /* All platforms. */ + "fangsong ti", /* Unix. */ + "simplified arabic fixed", /* Windows. */ + "monaco", "pryamoy", /* Mac. */ NULL }; @@ -299,9 +299,9 @@ static char **fontFallbacks[] = { }; /* - * Global fallbacks. If the character could not be found in the preferred - * fallback list, this list is examined. If the character still cannot be - * found, all font families in the system are examined. + * Global fallbacks. If the character could not be found in the preferred + * fallback list, this list is examined. If the character still cannot be + * found, all font families in the system are examined. */ static char *globalFontClass[] = { @@ -314,43 +314,35 @@ static char *globalFontClass[] = { }; #define GetFontAttributes(tkfont) \ - ((CONST TkFontAttributes *) &((TkFont *) (tkfont))->fa) + ((const TkFontAttributes *) &((TkFont *) (tkfont))->fa) #define GetFontMetrics(tkfont) \ - ((CONST TkFontMetrics *) &((TkFont *) (tkfont))->fm) - - -static int ConfigAttributesObj _ANSI_ARGS_((Tcl_Interp *interp, - Tk_Window tkwin, int objc, Tcl_Obj *CONST objv[], - TkFontAttributes *faPtr)); -static int CreateNamedFont _ANSI_ARGS_((Tcl_Interp *interp, - Tk_Window tkwin, CONST char *name, - TkFontAttributes *faPtr)); -static void DupFontObjProc _ANSI_ARGS_((Tcl_Obj *srcObjPtr, - Tcl_Obj *dupObjPtr)); -static int FieldSpecified _ANSI_ARGS_((CONST char *field)); -static void FreeFontObjProc _ANSI_ARGS_((Tcl_Obj *objPtr)); -static int GetAttributeInfoObj _ANSI_ARGS_((Tcl_Interp *interp, - CONST TkFontAttributes *faPtr, Tcl_Obj *objPtr)); -static LayoutChunk * NewChunk _ANSI_ARGS_((TextLayout **layoutPtrPtr, - int *maxPtr, CONST char *start, int numChars, - int curX, int newX, int y)); -static int ParseFontNameObj _ANSI_ARGS_((Tcl_Interp *interp, - Tk_Window tkwin, Tcl_Obj *objPtr, - TkFontAttributes *faPtr)); -static void RecomputeWidgets _ANSI_ARGS_((TkWindow *winPtr)); -static int SetFontFromAny _ANSI_ARGS_((Tcl_Interp *interp, - Tcl_Obj *objPtr)); -static void TheWorldHasChanged _ANSI_ARGS_(( - ClientData clientData)); -static void UpdateDependentFonts _ANSI_ARGS_((TkFontInfo *fiPtr, - Tk_Window tkwin, Tcl_HashEntry *namedHashPtr)); + ((const TkFontMetrics *) &((TkFont *) (tkfont))->fm) + + +static int ConfigAttributesObj(Tcl_Interp *interp, + Tk_Window tkwin, int objc, Tcl_Obj *const objv[], + TkFontAttributes *faPtr); +static void DupFontObjProc(Tcl_Obj *srcObjPtr, Tcl_Obj *dupObjPtr); +static int FieldSpecified(const char *field); +static void FreeFontObjProc(Tcl_Obj *objPtr); +static int GetAttributeInfoObj(Tcl_Interp *interp, + const TkFontAttributes *faPtr, Tcl_Obj *objPtr); +static LayoutChunk * NewChunk(TextLayout **layoutPtrPtr, int *maxPtr, + const char *start, int numChars, int curX, + int newX, int y); +static int ParseFontNameObj(Tcl_Interp *interp, Tk_Window tkwin, + Tcl_Obj *objPtr, TkFontAttributes *faPtr); +static void RecomputeWidgets(TkWindow *winPtr); +static int SetFontFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr); +static void TheWorldHasChanged(ClientData clientData); +static void UpdateDependentFonts(TkFontInfo *fiPtr, + Tk_Window tkwin, Tcl_HashEntry *namedHashPtr); /* * The following structure defines the implementation of the "font" Tcl - * object, used for drawing. The internalRep.twoPtrValue.ptr1 field of - * each font object points to the TkFont structure for the font, or - * NULL. + * object, used for drawing. The internalRep.twoPtrValue.ptr1 field of each + * font object points to the TkFont structure for the font, or NULL. */ Tcl_ObjType tkFontObjType = { @@ -360,29 +352,29 @@ Tcl_ObjType tkFontObjType = { NULL, /* updateStringProc */ SetFontFromAny /* setFromAnyProc */ }; - /* *--------------------------------------------------------------------------- * * TkFontPkgInit -- * - * This procedure is called when an application is created. It - * initializes all the structures that are used by the font - * package on a per application basis. + * This function is called when an application is created. It initializes + * all the structures that are used by the font package on a per + * application basis. * * Results: - * Stores a token in the mainPtr to hold information needed by this - * package on a per application basis. + * Stores a token in the mainPtr to hold information needed by this + * package on a per application basis. * * Side effects: * Memory allocated. * *--------------------------------------------------------------------------- */ + void -TkFontPkgInit(mainPtr) - TkMainInfo *mainPtr; /* The application being created. */ +TkFontPkgInit( + TkMainInfo *mainPtr) /* The application being created. */ { TkFontInfo *fiPtr; @@ -401,9 +393,9 @@ TkFontPkgInit(mainPtr) * * TkFontPkgFree -- * - * This procedure is called when an application is deleted. It - * deletes all the structures that were used by the font package - * for this application. + * This function is called when an application is deleted. It deletes all + * the structures that were used by the font package for this + * application. * * Results: * None. @@ -415,8 +407,8 @@ TkFontPkgInit(mainPtr) */ void -TkFontPkgFree(mainPtr) - TkMainInfo *mainPtr; /* The application being deleted. */ +TkFontPkgFree( + TkMainInfo *mainPtr) /* The application being deleted. */ { TkFontInfo *fiPtr; Tcl_HashEntry *hPtr, *searchPtr; @@ -431,15 +423,17 @@ TkFontPkgFree(mainPtr) searchPtr = Tcl_NextHashEntry(&search)) { fontsLeft++; #ifdef DEBUG_FONTS - fprintf(stderr, "Font %s still in cache.\n", + fprintf(stderr, "Font %s still in cache.\n", Tcl_GetHashKey(&fiPtr->fontCache, searchPtr)); #endif } + #ifdef PURIFY if (fontsLeft) { - panic("TkFontPkgFree: all fonts should have been freed already"); + Tcl_Panic("TkFontPkgFree: all fonts should have been freed already"); } #endif + Tcl_DeleteHashTable(&fiPtr->fontCache); hPtr = Tcl_FirstHashEntry(&fiPtr->namedTable, &search); @@ -457,10 +451,10 @@ TkFontPkgFree(mainPtr) /* *--------------------------------------------------------------------------- * - * Tk_FontObjCmd -- + * Tk_FontObjCmd -- * - * This procedure is implemented to process the "font" Tcl command. - * See the user documentation for details on what it does. + * This function is implemented to process the "font" Tcl command. See + * the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -472,16 +466,16 @@ TkFontPkgFree(mainPtr) */ int -Tk_FontObjCmd(clientData, interp, objc, objv) - ClientData clientData; /* Main window associated with interpreter. */ - Tcl_Interp *interp; /* Current interpreter. */ - int objc; /* Number of arguments. */ - Tcl_Obj *CONST objv[]; /* Argument objects. */ +Tk_FontObjCmd( + ClientData clientData, /* Main window associated with interpreter. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *const objv[]) /* Argument objects. */ { int index; Tk_Window tkwin; TkFontInfo *fiPtr; - static CONST char *optionStrings[] = { + static const char *optionStrings[] = { "actual", "configure", "create", "delete", "families", "measure", "metrics", "names", NULL @@ -504,259 +498,320 @@ Tk_FontObjCmd(clientData, interp, objc, objv) } switch ((enum options) index) { - case FONT_ACTUAL: { - int skip, result; - Tk_Font tkfont; - Tcl_Obj *objPtr; - CONST TkFontAttributes *faPtr; + case FONT_ACTUAL: { + int skip, result, n; + const char *s; + Tk_Font tkfont; + Tcl_Obj *optPtr, *charPtr, *resultPtr; + Tcl_UniChar uniChar = 0; + const TkFontAttributes *faPtr; + TkFontAttributes fa; - skip = TkGetDisplayOf(interp, objc - 3, objv + 3, &tkwin); - if (skip < 0) { - return TCL_ERROR; - } - if ((objc < 3) || (objc - skip > 4)) { - Tcl_WrongNumArgs(interp, 2, objv, - "font ?-displayof window? ?option?"); - return TCL_ERROR; - } - tkfont = Tk_AllocFontFromObj(interp, tkwin, objv[2]); - if (tkfont == NULL) { - return TCL_ERROR; - } - objc -= skip; - objv += skip; - faPtr = GetFontAttributes(tkfont); - objPtr = NULL; - if (objc > 3) { - objPtr = objv[3]; - } - result = GetAttributeInfoObj(interp, faPtr, objPtr); - Tk_FreeFont(tkfont); - return result; + /* + * Params 0 and 1 are 'font actual'. Param 2 is the font name. 3-4 may + * be '-displayof $window' + */ + + skip = TkGetDisplayOf(interp, objc - 3, objv + 3, &tkwin); + if (skip < 0) { + return TCL_ERROR; } - case FONT_CONFIGURE: { - int result; - char *string; - Tcl_Obj *objPtr; - NamedFont *nfPtr; - Tcl_HashEntry *namedHashPtr; - if (objc < 3) { - Tcl_WrongNumArgs(interp, 2, objv, "fontname ?options?"); - return TCL_ERROR; - } - string = Tcl_GetString(objv[2]); - namedHashPtr = Tcl_FindHashEntry(&fiPtr->namedTable, string); - nfPtr = NULL; /* lint. */ - if (namedHashPtr != NULL) { - nfPtr = (NamedFont *) Tcl_GetHashValue(namedHashPtr); - } - if ((namedHashPtr == NULL) || (nfPtr->deletePending != 0)) { - Tcl_AppendResult(interp, "named font \"", string, - "\" doesn't exist", NULL); - return TCL_ERROR; - } - if (objc == 3) { - objPtr = NULL; - } else if (objc == 4) { - objPtr = objv[3]; + /* + * Next parameter may be an option. + */ + + n = skip + 3; + optPtr = NULL; + charPtr = NULL; + if (n < objc) { + s = Tcl_GetString(objv[n]); + if (s[0] == '-' && s[1] != '-') { + optPtr = objv[n]; + ++n; } else { - result = ConfigAttributesObj(interp, tkwin, objc - 3, - objv + 3, &nfPtr->fa); - UpdateDependentFonts(fiPtr, tkwin, namedHashPtr); - return result; + optPtr = NULL; } - return GetAttributeInfoObj(interp, &nfPtr->fa, objPtr); } - case FONT_CREATE: { - int skip, i; - char *name; - char buf[16 + TCL_INTEGER_SPACE]; - TkFontAttributes fa; - Tcl_HashEntry *namedHashPtr; - skip = 3; - if (objc < 3) { - name = NULL; - } else { - name = Tcl_GetString(objv[2]); - if (name[0] == '-') { - name = NULL; - } - } - if (name == NULL) { - /* - * No font name specified. Generate one of the form "fontX". - */ + /* + * Next parameter may be '--' to mark end of options. + */ - for (i = 1; ; i++) { - sprintf(buf, "font%d", i); - namedHashPtr = Tcl_FindHashEntry(&fiPtr->namedTable, buf); - if (namedHashPtr == NULL) { - break; - } - } - name = buf; - skip = 2; + if (n < objc) { + if (!strcmp(Tcl_GetString(objv[n]), "--")) { + ++n; } - TkInitFontAttributes(&fa); - if (ConfigAttributesObj(interp, tkwin, objc - skip, objv + skip, - &fa) != TCL_OK) { - return TCL_ERROR; - } - if (CreateNamedFont(interp, tkwin, name, &fa) != TCL_OK) { + } + + /* + * Next parameter is the character to get font information for. + */ + + if (n < objc) { + charPtr = objv[n]; + ++n; + } + + /* + * If there were fewer than 3 args, or args remain, that's an error. + */ + + if (objc < 3 || n < objc) { + Tcl_WrongNumArgs(interp, 2, objv, + "font ?-displayof window? ?option? ?--? ?char?"); + return TCL_ERROR; + } + + /* + * The 'charPtr' arg must be a single Unicode. + */ + + if (charPtr != NULL) { + if (Tcl_GetCharLength(charPtr) != 1) { + resultPtr = Tcl_NewStringObj( + "expected a single character but got \"", -1); + Tcl_AppendLimitedToObj(resultPtr, Tcl_GetString(charPtr), + -1, 40, "..."); + Tcl_AppendToObj(resultPtr, "\"", -1); + Tcl_SetObjResult(interp, resultPtr); return TCL_ERROR; } - Tcl_AppendResult(interp, name, NULL); - break; + uniChar = Tcl_GetUniChar(charPtr, 0); + } + + /* + * Find the font. + */ + + tkfont = Tk_AllocFontFromObj(interp, tkwin, objv[2]); + if (tkfont == NULL) { + return TCL_ERROR; } - case FONT_DELETE: { - int i; - char *string; - NamedFont *nfPtr; - Tcl_HashEntry *namedHashPtr; + /* + * Determine the font attributes. + */ + + if (charPtr == NULL) { + faPtr = GetFontAttributes(tkfont); + } else { + TkpGetFontAttrsForChar(tkwin, tkfont, uniChar, &fa); + faPtr = &fa; + } + result = GetAttributeInfoObj(interp, faPtr, optPtr); + + Tk_FreeFont(tkfont); + return result; + } + case FONT_CONFIGURE: { + int result; + char *string; + Tcl_Obj *objPtr; + NamedFont *nfPtr; + Tcl_HashEntry *namedHashPtr; + + if (objc < 3) { + Tcl_WrongNumArgs(interp, 2, objv, "fontname ?options?"); + return TCL_ERROR; + } + string = Tcl_GetString(objv[2]); + namedHashPtr = Tcl_FindHashEntry(&fiPtr->namedTable, string); + nfPtr = NULL; /* lint. */ + if (namedHashPtr != NULL) { + nfPtr = (NamedFont *) Tcl_GetHashValue(namedHashPtr); + } + if ((namedHashPtr == NULL) || (nfPtr->deletePending != 0)) { + Tcl_AppendResult(interp, "named font \"", string, + "\" doesn't exist", NULL); + return TCL_ERROR; + } + if (objc == 3) { + objPtr = NULL; + } else if (objc == 4) { + objPtr = objv[3]; + } else { + result = ConfigAttributesObj(interp, tkwin, objc - 3, objv + 3, + &nfPtr->fa); + UpdateDependentFonts(fiPtr, tkwin, namedHashPtr); + return result; + } + return GetAttributeInfoObj(interp, &nfPtr->fa, objPtr); + } + case FONT_CREATE: { + int skip, i; + char *name; + char buf[16 + TCL_INTEGER_SPACE]; + TkFontAttributes fa; + Tcl_HashEntry *namedHashPtr; + + skip = 3; + if (objc < 3) { + name = NULL; + } else { + name = Tcl_GetString(objv[2]); + if (name[0] == '-') { + name = NULL; + } + } + if (name == NULL) { /* - * Delete the named font. If there are still widgets using this - * font, then it isn't deleted right away. + * No font name specified. Generate one of the form "fontX". */ - if (objc < 3) { - Tcl_WrongNumArgs(interp, 2, objv, "fontname ?fontname ...?"); - return TCL_ERROR; - } - for (i = 2; i < objc; i++) { - string = Tcl_GetString(objv[i]); - namedHashPtr = Tcl_FindHashEntry(&fiPtr->namedTable, string); + for (i = 1; ; i++) { + sprintf(buf, "font%d", i); + namedHashPtr = Tcl_FindHashEntry(&fiPtr->namedTable, buf); if (namedHashPtr == NULL) { - Tcl_AppendResult(interp, "named font \"", string, - "\" doesn't exist", (char *) NULL); - return TCL_ERROR; - } - nfPtr = (NamedFont *) Tcl_GetHashValue(namedHashPtr); - if (nfPtr->refCount != 0) { - nfPtr->deletePending = 1; - } else { - Tcl_DeleteHashEntry(namedHashPtr); - ckfree((char *) nfPtr); + break; } } - break; + name = buf; + skip = 2; + } + TkInitFontAttributes(&fa); + if (ConfigAttributesObj(interp, tkwin, objc - skip, objv + skip, + &fa) != TCL_OK) { + return TCL_ERROR; + } + if (TkCreateNamedFont(interp, tkwin, name, &fa) != TCL_OK) { + return TCL_ERROR; } - case FONT_FAMILIES: { - int skip; + Tcl_AppendResult(interp, name, NULL); + break; + } + case FONT_DELETE: { + int i, result = TCL_OK; + char *string; - skip = TkGetDisplayOf(interp, objc - 2, objv + 2, &tkwin); - if (skip < 0) { - return TCL_ERROR; - } - if (objc - skip != 2) { - Tcl_WrongNumArgs(interp, 2, objv, "?-displayof window?"); - return TCL_ERROR; - } - TkpGetFontFamilies(interp, tkwin); - break; + /* + * Delete the named font. If there are still widgets using this font, + * then it isn't deleted right away. + */ + + if (objc < 3) { + Tcl_WrongNumArgs(interp, 2, objv, "fontname ?fontname ...?"); + return TCL_ERROR; } - case FONT_MEASURE: { - char *string; - Tk_Font tkfont; - int length, skip; - Tcl_Obj *resultPtr; - - skip = TkGetDisplayOf(interp, objc - 3, objv + 3, &tkwin); - if (skip < 0) { - return TCL_ERROR; - } - if (objc - skip != 4) { - Tcl_WrongNumArgs(interp, 2, objv, - "font ?-displayof window? text"); - return TCL_ERROR; - } - tkfont = Tk_AllocFontFromObj(interp, tkwin, objv[2]); - if (tkfont == NULL) { - return TCL_ERROR; - } - string = Tcl_GetStringFromObj(objv[3 + skip], &length); - resultPtr = Tcl_GetObjResult(interp); - Tcl_SetIntObj(resultPtr, Tk_TextWidth(tkfont, string, length)); - Tk_FreeFont(tkfont); - break; + for (i = 2; i < objc && result == TCL_OK; i++) { + string = Tcl_GetString(objv[i]); + result = TkDeleteNamedFont(interp, tkwin, string); + } + return result; + } + case FONT_FAMILIES: { + int skip; + + skip = TkGetDisplayOf(interp, objc - 2, objv + 2, &tkwin); + if (skip < 0) { + return TCL_ERROR; } - case FONT_METRICS: { - Tk_Font tkfont; - int skip, index, i; - CONST TkFontMetrics *fmPtr; - static CONST char *switches[] = { - "-ascent", "-descent", "-linespace", "-fixed", NULL - }; + if (objc - skip != 2) { + Tcl_WrongNumArgs(interp, 2, objv, "?-displayof window?"); + return TCL_ERROR; + } + TkpGetFontFamilies(interp, tkwin); + break; + } + case FONT_MEASURE: { + char *string; + Tk_Font tkfont; + int length = 0, skip = 0; + Tcl_Obj *resultPtr; + if (objc > 4) { skip = TkGetDisplayOf(interp, objc - 3, objv + 3, &tkwin); if (skip < 0) { return TCL_ERROR; } - if ((objc < 3) || ((objc - skip) > 4)) { - Tcl_WrongNumArgs(interp, 2, objv, - "font ?-displayof window? ?option?"); - return TCL_ERROR; - } - tkfont = Tk_AllocFontFromObj(interp, tkwin, objv[2]); - if (tkfont == NULL) { + } + if (objc - skip != 4) { + Tcl_WrongNumArgs(interp, 2, objv, "font ?-displayof window? text"); + return TCL_ERROR; + } + tkfont = Tk_AllocFontFromObj(interp, tkwin, objv[2]); + if (tkfont == NULL) { + return TCL_ERROR; + } + string = Tcl_GetStringFromObj(objv[3 + skip], &length); + resultPtr = Tcl_GetObjResult(interp); + Tcl_SetIntObj(resultPtr, Tk_TextWidth(tkfont, string, length)); + Tk_FreeFont(tkfont); + break; + } + case FONT_METRICS: { + Tk_Font tkfont; + int skip, index, i; + const TkFontMetrics *fmPtr; + static const char *switches[] = { + "-ascent", "-descent", "-linespace", "-fixed", NULL + }; + + skip = TkGetDisplayOf(interp, objc - 3, objv + 3, &tkwin); + if (skip < 0) { + return TCL_ERROR; + } + if ((objc < 3) || ((objc - skip) > 4)) { + Tcl_WrongNumArgs(interp, 2, objv, + "font ?-displayof window? ?option?"); + return TCL_ERROR; + } + tkfont = Tk_AllocFontFromObj(interp, tkwin, objv[2]); + if (tkfont == NULL) { + return TCL_ERROR; + } + objc -= skip; + objv += skip; + fmPtr = GetFontMetrics(tkfont); + if (objc == 3) { + char buf[64 + TCL_INTEGER_SPACE * 4]; + + sprintf(buf, "-ascent %d -descent %d -linespace %d -fixed %d", + fmPtr->ascent, fmPtr->descent, + fmPtr->ascent + fmPtr->descent, fmPtr->fixed); + Tcl_AppendResult(interp, buf, NULL); + } else { + if (Tcl_GetIndexFromObj(interp, objv[3], switches, "metric", 0, + &index) != TCL_OK) { + Tk_FreeFont(tkfont); return TCL_ERROR; } - objc -= skip; - objv += skip; - fmPtr = GetFontMetrics(tkfont); - if (objc == 3) { - char buf[64 + TCL_INTEGER_SPACE * 4]; - - sprintf(buf, "-ascent %d -descent %d -linespace %d -fixed %d", - fmPtr->ascent, fmPtr->descent, - fmPtr->ascent + fmPtr->descent, - fmPtr->fixed); - Tcl_AppendResult(interp, buf, NULL); - } else { - if (Tcl_GetIndexFromObj(interp, objv[3], switches, - "metric", 0, &index) != TCL_OK) { - Tk_FreeFont(tkfont); - return TCL_ERROR; - } - i = 0; /* Needed only to prevent compiler - * warning. */ - switch (index) { - case 0: i = fmPtr->ascent; break; - case 1: i = fmPtr->descent; break; - case 2: i = fmPtr->ascent + fmPtr->descent; break; - case 3: i = fmPtr->fixed; break; - } - Tcl_SetIntObj(Tcl_GetObjResult(interp), i); + i = 0; /* Needed only to prevent compiler warning. */ + switch (index) { + case 0: i = fmPtr->ascent; break; + case 1: i = fmPtr->descent; break; + case 2: i = fmPtr->ascent + fmPtr->descent; break; + case 3: i = fmPtr->fixed; break; } - Tk_FreeFont(tkfont); - break; + Tcl_SetIntObj(Tcl_GetObjResult(interp), i); } - case FONT_NAMES: { - char *string; - NamedFont *nfPtr; - Tcl_HashSearch search; - Tcl_HashEntry *namedHashPtr; - Tcl_Obj *strPtr, *resultPtr; - - if (objc != 2) { - Tcl_WrongNumArgs(interp, 1, objv, "names"); - return TCL_ERROR; - } - resultPtr = Tcl_GetObjResult(interp); - namedHashPtr = Tcl_FirstHashEntry(&fiPtr->namedTable, &search); - while (namedHashPtr != NULL) { - nfPtr = (NamedFont *) Tcl_GetHashValue(namedHashPtr); - if (nfPtr->deletePending == 0) { - string = Tcl_GetHashKey(&fiPtr->namedTable, namedHashPtr); - strPtr = Tcl_NewStringObj(string, -1); - Tcl_ListObjAppendElement(NULL, resultPtr, strPtr); - } - namedHashPtr = Tcl_NextHashEntry(&search); + Tk_FreeFont(tkfont); + break; + } + case FONT_NAMES: { + char *string; + NamedFont *nfPtr; + Tcl_HashSearch search; + Tcl_HashEntry *namedHashPtr; + Tcl_Obj *strPtr, *resultPtr; + + if (objc != 2) { + Tcl_WrongNumArgs(interp, 1, objv, "names"); + return TCL_ERROR; + } + resultPtr = Tcl_GetObjResult(interp); + namedHashPtr = Tcl_FirstHashEntry(&fiPtr->namedTable, &search); + while (namedHashPtr != NULL) { + nfPtr = (NamedFont *) Tcl_GetHashValue(namedHashPtr); + if (nfPtr->deletePending == 0) { + string = Tcl_GetHashKey(&fiPtr->namedTable, namedHashPtr); + strPtr = Tcl_NewStringObj(string, -1); + Tcl_ListObjAppendElement(NULL, resultPtr, strPtr); } - break; + namedHashPtr = Tcl_NextHashEntry(&search); } + break; + } } return TCL_OK; } @@ -766,10 +821,10 @@ Tk_FontObjCmd(clientData, interp, objc, objv) * * UpdateDependentFonts, TheWorldHasChanged, RecomputeWidgets -- * - * Called when the attributes of a named font changes. Updates all - * the instantiated fonts that depend on that named font and then - * uses the brute force approach and prepares every widget to - * recompute its geometry. + * Called when the attributes of a named font changes. Updates all the + * instantiated fonts that depend on that named font and then uses the + * brute force approach and prepares every widget to recompute its + * geometry. * * Results: * None. @@ -781,10 +836,10 @@ Tk_FontObjCmd(clientData, interp, objc, objv) */ static void -UpdateDependentFonts(fiPtr, tkwin, namedHashPtr) - TkFontInfo *fiPtr; /* Info about application's fonts. */ - Tk_Window tkwin; /* A window in the application. */ - Tcl_HashEntry *namedHashPtr;/* The named font that is changing. */ +UpdateDependentFonts( + TkFontInfo *fiPtr, /* Info about application's fonts. */ + Tk_Window tkwin, /* A window in the application. */ + Tcl_HashEntry *namedHashPtr)/* The named font that is changing. */ { Tcl_HashEntry *cacheHashPtr; Tcl_HashSearch search; @@ -794,8 +849,8 @@ UpdateDependentFonts(fiPtr, tkwin, namedHashPtr) nfPtr = (NamedFont *) Tcl_GetHashValue(namedHashPtr); if (nfPtr->refCount == 0) { /* - * Well nobody's using this named font, so don't have to tell - * any widgets to recompute themselves. + * Well nobody's using this named font, so don't have to tell any + * widgets to recompute themselves. */ return; @@ -818,8 +873,8 @@ UpdateDependentFonts(fiPtr, tkwin, namedHashPtr) } static void -TheWorldHasChanged(clientData) - ClientData clientData; /* Info about application's fonts. */ +TheWorldHasChanged( + ClientData clientData) /* Info about application's fonts. */ { TkFontInfo *fiPtr; @@ -830,8 +885,8 @@ TheWorldHasChanged(clientData) } static void -RecomputeWidgets(winPtr) - TkWindow *winPtr; /* Window to which command is sent. */ +RecomputeWidgets( + TkWindow *winPtr) /* Window to which command is sent. */ { Tk_ClassWorldChangedProc *proc; proc = Tk_GetClassProc(winPtr->classProcsPtr, worldChangedProc); @@ -842,22 +897,23 @@ RecomputeWidgets(winPtr) /* * Notify all the descendants of this window that the world has changed. * - * This could be done recursively or iteratively. The recursive version - * is easier to implement and understand, and typically, windows with a - * -font option will be leaf nodes in the widget heirarchy (buttons, - * labels, etc.), so the recursion depth will be shallow. + * This could be done recursively or iteratively. The recursive version is + * easier to implement and understand, and typically, windows with a -font + * option will be leaf nodes in the widget heirarchy (buttons, labels, + * etc.), so the recursion depth will be shallow. * - * However, the additional overhead of the recursive calls may become - * a performance problem if typical usage alters such that -font'ed widgets - * appear high in the heirarchy, causing deep recursion. This could happen + * However, the additional overhead of the recursive calls may become a + * performance problem if typical usage alters such that -font'ed widgets + * appear high in the heirarchy, causing deep recursion. This could happen * with text widgets, or more likely with the (not yet existant) labeled - * frame widget. With these widgets it is possible, even likely, that a + * frame widget. With these widgets it is possible, even likely, that a * -font'ed widget (text or labeled frame) will not be a leaf node, but - * will instead have many descendants. If this is ever found to cause - * a performance problem, it may be worth investigating an iterative - * version of the code below. + * will instead have many descendants. If this is ever found to cause a + * performance problem, it may be worth investigating an iterative version + * of the code below. */ - for (winPtr = winPtr->childList; winPtr != NULL; winPtr = winPtr->nextPtr) { + + for (winPtr=winPtr->childList ; winPtr!=NULL ; winPtr=winPtr->nextPtr) { RecomputeWidgets(winPtr); } } @@ -865,56 +921,57 @@ RecomputeWidgets(winPtr) /* *--------------------------------------------------------------------------- * - * CreateNamedFont -- + * TkCreateNamedFont -- * - * Create the specified named font with the given attributes in the - * named font table associated with the interp. + * Create the specified named font with the given attributes in the named + * font table associated with the interp. * * Results: - * Returns TCL_OK if the font was successfully created, or TCL_ERROR - * if the named font already existed. If TCL_ERROR is returned, an - * error message is left in the interp's result. + * Returns TCL_OK if the font was successfully created, or TCL_ERROR if + * the named font already existed. If TCL_ERROR is returned, an error + * message is left in the interp's result. * * Side effects: * Assume there used to exist a named font by the specified name, and * that the named font had been deleted, but there were still some - * widgets using the named font at the time it was deleted. If a - * new named font is created with the same name, all those widgets - * that were using the old named font will be redisplayed using - * the new named font's attributes. + * widgets using the named font at the time it was deleted. If a new + * named font is created with the same name, all those widgets that were + * using the old named font will be redisplayed using the new named + * font's attributes. * *--------------------------------------------------------------------------- */ -static int -CreateNamedFont(interp, tkwin, name, faPtr) - Tcl_Interp *interp; /* Interp for error return. */ - Tk_Window tkwin; /* A window associated with interp. */ - CONST char *name; /* Name for the new named font. */ - TkFontAttributes *faPtr; /* Attributes for the new named font. */ +int +TkCreateNamedFont( + Tcl_Interp *interp, /* Interp for error return (can be NULL). */ + Tk_Window tkwin, /* A window associated with interp. */ + const char *name, /* Name for the new named font. */ + TkFontAttributes *faPtr) /* Attributes for the new named font. */ { TkFontInfo *fiPtr; Tcl_HashEntry *namedHashPtr; - int new; - NamedFont *nfPtr; + int isNew; + NamedFont *nfPtr; fiPtr = ((TkWindow *) tkwin)->mainPtr->fontInfoPtr; - namedHashPtr = Tcl_CreateHashEntry(&fiPtr->namedTable, name, &new); - - if (new == 0) { + namedHashPtr = Tcl_CreateHashEntry(&fiPtr->namedTable, name, &isNew); + + if (!isNew) { nfPtr = (NamedFont *) Tcl_GetHashValue(namedHashPtr); if (nfPtr->deletePending == 0) { - Tcl_ResetResult(interp); - Tcl_AppendResult(interp, "named font \"", name, - "\" already exists", (char *) NULL); + if (interp) { + Tcl_AppendResult(interp, "named font \"", name, + "\" already exists", NULL); + } return TCL_ERROR; } /* - * Recreating a named font with the same name as a previous - * named font. Some widgets were still using that named - * font, so they need to get redisplayed. + * Recreating a named font with the same name as a previous named + * font. Some widgets were still using that named font, so they need + * to get redisplayed. */ nfPtr->fa = *faPtr; @@ -927,7 +984,7 @@ CreateNamedFont(interp, tkwin, name, faPtr) nfPtr->deletePending = 0; Tcl_SetHashValue(namedHashPtr, nfPtr); nfPtr->fa = *faPtr; - nfPtr->refCount = 0; + nfPtr->refCount = 0; nfPtr->deletePending = 0; return TCL_OK; } @@ -935,76 +992,116 @@ CreateNamedFont(interp, tkwin, name, faPtr) /* *--------------------------------------------------------------------------- * - * Tk_GetFont -- + * TkDeleteNamedFont -- + * + * Delete the named font. If there are still widgets using this font, + * then it isn't deleted right away. + * + *--------------------------------------------------------------------------- + */ + +int +TkDeleteNamedFont( + Tcl_Interp *interp, /* Interp for error return (can be NULL). */ + Tk_Window tkwin, /* A window associated with interp. */ + CONST char *name) /* Name for the new named font. */ +{ + TkFontInfo *fiPtr; + NamedFont *nfPtr; + Tcl_HashEntry *namedHashPtr; + + fiPtr = ((TkWindow *) tkwin)->mainPtr->fontInfoPtr; + + namedHashPtr = Tcl_FindHashEntry(&fiPtr->namedTable, name); + if (namedHashPtr == NULL) { + if (interp) { + Tcl_AppendResult(interp, "named font \"", name, + "\" doesn't exist", NULL); + } + return TCL_ERROR; + } + nfPtr = (NamedFont *) Tcl_GetHashValue(namedHashPtr); + if (nfPtr->refCount != 0) { + nfPtr->deletePending = 1; + } else { + Tcl_DeleteHashEntry(namedHashPtr); + ckfree((char *) nfPtr); + } + return TCL_OK; +} + +/* + *--------------------------------------------------------------------------- + * + * Tk_GetFont -- * * Given a string description of a font, map the description to a * corresponding Tk_Font that represents the font. * * Results: - * The return value is token for the font, or NULL if an error - * prevented the font from being created. If NULL is returned, an - * error message will be left in the interp's result. + * The return value is token for the font, or NULL if an error prevented + * the font from being created. If NULL is returned, an error message + * will be left in the interp's result. * * Side effects: - * The font is added to an internal database with a reference - * count. For each call to this procedure, there should eventually - * be a call to Tk_FreeFont() or Tk_FreeFontFromObj() so that the - * database is cleaned up when fonts aren't in use anymore. + * The font is added to an internal database with a reference count. For + * each call to this function, there should eventually be a call to + * Tk_FreeFont() or Tk_FreeFontFromObj() so that the database is cleaned + * up when fonts aren't in use anymore. * *--------------------------------------------------------------------------- */ Tk_Font -Tk_GetFont(interp, tkwin, string) - Tcl_Interp *interp; /* Interp for database and error return, or - * NULL for no error messages. */ - Tk_Window tkwin; /* For display on which font will be used. */ - CONST char *string; /* String describing font, as: named font, +Tk_GetFont( + Tcl_Interp *interp, /* Interp for database and error return. */ + Tk_Window tkwin, /* For display on which font will be used. */ + const char *string) /* String describing font, as: named font, * native format, or parseable string. */ { - Tk_Font tkfont; + Tk_Font tkfont; Tcl_Obj *strPtr; strPtr = Tcl_NewStringObj((char *) string, -1); Tcl_IncrRefCount(strPtr); tkfont = Tk_AllocFontFromObj(interp, tkwin, strPtr); - Tcl_DecrRefCount(strPtr); + Tcl_DecrRefCount(strPtr); return tkfont; } /* *--------------------------------------------------------------------------- * - * Tk_AllocFontFromObj -- + * Tk_AllocFontFromObj -- * * Given a string description of a font, map the description to a * corresponding Tk_Font that represents the font. * * Results: - * The return value is token for the font, or NULL if an error - * prevented the font from being created. If NULL is returned, an - * error message will be left in interp's result object (if non-NULL). + * The return value is token for the font, or NULL if an error prevented + * the font from being created. If NULL is returned, an error message + * will be left in interp's result object. * * Side effects: - * The font is added to an internal database with a reference - * count. For each call to this procedure, there should eventually - * be a call to Tk_FreeFont() or Tk_FreeFontFromObj() so that the - * database is cleaned up when fonts aren't in use anymore. + * The font is added to an internal database with a reference count. For + * each call to this function, there should eventually be a call to + * Tk_FreeFont() or Tk_FreeFontFromObj() so that the database is cleaned + * up when fonts aren't in use anymore. * *--------------------------------------------------------------------------- */ Tk_Font -Tk_AllocFontFromObj(interp, tkwin, objPtr) - Tcl_Interp *interp; /* Interp for database and error return. */ - Tk_Window tkwin; /* For screen on which font will be used. */ - Tcl_Obj *objPtr; /* Object describing font, as: named font, +Tk_AllocFontFromObj( + Tcl_Interp *interp, /* Interp for database and error return. */ + Tk_Window tkwin, /* For screen on which font will be used. */ + Tcl_Obj *objPtr) /* Object describing font, as: named font, * native format, or parseable string. */ { TkFontInfo *fiPtr; Tcl_HashEntry *cacheHashPtr, *namedHashPtr; TkFont *fontPtr, *firstFontPtr, *oldFontPtr; - int new, descent; + int isNew, descent; NamedFont *nfPtr; fiPtr = ((TkWindow *) tkwin)->mainPtr->fontInfoPtr; @@ -1017,8 +1114,8 @@ Tk_AllocFontFromObj(interp, tkwin, objPtr) if (oldFontPtr != NULL) { if (oldFontPtr->resourceRefCount == 0) { /* - * This is a stale reference: it refers to a TkFont that's - * no longer in use. Clear the reference. + * This is a stale reference: it refers to a TkFont that's no + * longer in use. Clear the reference. */ FreeFontObjProc(objPtr); @@ -1030,17 +1127,17 @@ Tk_AllocFontFromObj(interp, tkwin, objPtr) } /* - * Next, search the list of fonts that have the name we want, to see - * if one of them is for the right screen. + * Next, search the list of fonts that have the name we want, to see if + * one of them is for the right screen. */ - new = 0; + isNew = 0; if (oldFontPtr != NULL) { cacheHashPtr = oldFontPtr->cacheHashPtr; FreeFontObjProc(objPtr); } else { cacheHashPtr = Tcl_CreateHashEntry(&fiPtr->fontCache, - Tcl_GetString(objPtr), &new); + Tcl_GetString(objPtr), &isNew); } firstFontPtr = (TkFont *) Tcl_GetHashValue(cacheHashPtr); for (fontPtr = firstFontPtr; (fontPtr != NULL); @@ -1048,13 +1145,13 @@ Tk_AllocFontFromObj(interp, tkwin, objPtr) if (Tk_Screen(tkwin) == fontPtr->screen) { fontPtr->resourceRefCount++; fontPtr->objRefCount++; - objPtr->internalRep.twoPtrValue.ptr1 = (VOID *) fontPtr; + objPtr->internalRep.twoPtrValue.ptr1 = (void *) fontPtr; return (Tk_Font) fontPtr; } } /* - * The desired font isn't in the table. Make a new one. + * The desired font isn't in the table. Make a new one. */ namedHashPtr = Tcl_FindHashEntry(&fiPtr->namedTable, @@ -1079,7 +1176,7 @@ Tk_AllocFontFromObj(interp, tkwin, objPtr) Tcl_Obj *dupObjPtr = Tcl_DuplicateObj(objPtr); if (ParseFontNameObj(interp, tkwin, dupObjPtr, &fa) != TCL_OK) { - if (new) { + if (isNew) { Tcl_DeleteHashEntry(cacheHashPtr); } Tcl_DecrRefCount(dupObjPtr); @@ -1095,6 +1192,19 @@ Tk_AllocFontFromObj(interp, tkwin, objPtr) } } + /* + * Detect the system font engine going wrong and fail more gracefully. + */ + + if (fontPtr == NULL) { + if (isNew) { + Tcl_DeleteHashEntry(cacheHashPtr); + } + Tcl_AppendResult(interp, "failed to allocate font due to ", + "internal system font engine problem", NULL); + return NULL; + } + fontPtr->resourceRefCount = 1; fontPtr->objRefCount = 1; fontPtr->cacheHashPtr = cacheHashPtr; @@ -1122,7 +1232,7 @@ Tk_AllocFontFromObj(interp, tkwin, objPtr) * Get information used for drawing underlines in generic code on a * non-underlined font. */ - + descent = fontPtr->fm.descent; fontPtr->underlinePos = descent / 2; fontPtr->underlineHeight = TkFontGetPixels(tkwin, fontPtr->fa.size) / 10; @@ -1131,9 +1241,9 @@ Tk_AllocFontFromObj(interp, tkwin, objPtr) } if (fontPtr->underlinePos + fontPtr->underlineHeight > descent) { /* - * If this set of values would cause the bottom of the underline - * bar to stick below the descent of the font, jack the underline - * up a bit higher. + * If this set of values would cause the bottom of the underline bar + * to stick below the descent of the font, jack the underline up a bit + * higher. */ fontPtr->underlineHeight = descent - fontPtr->underlinePos; @@ -1142,8 +1252,8 @@ Tk_AllocFontFromObj(interp, tkwin, objPtr) fontPtr->underlineHeight = 1; } } - - objPtr->internalRep.twoPtrValue.ptr1 = (VOID *) fontPtr; + + objPtr->internalRep.twoPtrValue.ptr1 = (void *) fontPtr; return (Tk_Font) fontPtr; } @@ -1152,31 +1262,31 @@ Tk_AllocFontFromObj(interp, tkwin, objPtr) * * Tk_GetFontFromObj -- * - * Find the font that corresponds to a given object. The font must - * have already been created by Tk_GetFont or Tk_AllocFontFromObj. + * Find the font that corresponds to a given object. The font must have + * already been created by Tk_GetFont or Tk_AllocFontFromObj. * * Results: - * The return value is a token for the font that matches objPtr - * and is suitable for use in tkwin. + * The return value is a token for the font that matches objPtr and is + * suitable for use in tkwin. * * Side effects: - * If the object is not already a font ref, the conversion will free - * any old internal representation. + * If the object is not already a font ref, the conversion will free any + * old internal representation. * *---------------------------------------------------------------------- */ Tk_Font -Tk_GetFontFromObj(tkwin, objPtr) - Tk_Window tkwin; /* The window that the font will be used in. */ - Tcl_Obj *objPtr; /* The object from which to get the font. */ +Tk_GetFontFromObj( + Tk_Window tkwin, /* The window that the font will be used in. */ + Tcl_Obj *objPtr) /* The object from which to get the font. */ { TkFontInfo *fiPtr = ((TkWindow *) tkwin)->mainPtr->fontInfoPtr; TkFont *fontPtr; Tcl_HashEntry *hashPtr; - + if (objPtr->typePtr != &tkFontObjType) { - SetFontFromAny((Tcl_Interp *) NULL, objPtr); + SetFontFromAny(NULL, objPtr); } fontPtr = (TkFont *) objPtr->internalRep.twoPtrValue.ptr1; @@ -1184,8 +1294,8 @@ Tk_GetFontFromObj(tkwin, objPtr) if (fontPtr != NULL) { if (fontPtr->resourceRefCount == 0) { /* - * This is a stale reference: it refers to a TkFont that's - * no longer in use. Clear the reference. + * This is a stale reference: it refers to a TkFont that's no + * longer in use. Clear the reference. */ FreeFontObjProc(objPtr); @@ -1196,8 +1306,8 @@ Tk_GetFontFromObj(tkwin, objPtr) } /* - * Next, search the list of fonts that have the name we want, to see - * if one of them is for the right screen. + * Next, search the list of fonts that have the name we want, to see if + * one of them is for the right screen. */ if (fontPtr != NULL) { @@ -1211,13 +1321,13 @@ Tk_GetFontFromObj(tkwin, objPtr) fontPtr = fontPtr->nextPtr) { if (Tk_Screen(tkwin) == fontPtr->screen) { fontPtr->objRefCount++; - objPtr->internalRep.twoPtrValue.ptr1 = (VOID *) fontPtr; + objPtr->internalRep.twoPtrValue.ptr1 = (void *) fontPtr; return (Tk_Font) fontPtr; } } } - panic("Tk_GetFontFromObj called with non-existent font!"); + Tcl_Panic("Tk_GetFontFromObj called with non-existent font!"); return NULL; } @@ -1226,28 +1336,28 @@ Tk_GetFontFromObj(tkwin, objPtr) * * SetFontFromAny -- * - * Convert the internal representation of a Tcl object to the - * font internal form. + * Convert the internal representation of a Tcl object to the font + * internal form. * * Results: * Always returns TCL_OK. * * Side effects: - * The object is left with its typePtr pointing to tkFontObjType. - * The TkFont pointer is NULL. + * The object is left with its typePtr pointing to tkFontObjType. The + * TkFont pointer is NULL. * *---------------------------------------------------------------------- */ static int -SetFontFromAny(interp, objPtr) - Tcl_Interp *interp; /* Used for error reporting if not NULL. */ - Tcl_Obj *objPtr; /* The object to convert. */ +SetFontFromAny( + Tcl_Interp *interp, /* Used for error reporting if not NULL. */ + Tcl_Obj *objPtr) /* The object to convert. */ { - Tcl_ObjType *typePtr; + const Tcl_ObjType *typePtr; /* - * Free the old internalRep before setting the new one. + * Free the old internalRep before setting the new one. */ Tcl_GetString(objPtr); @@ -1269,10 +1379,10 @@ SetFontFromAny(interp, objPtr) * Given a font, return a textual string identifying it. * * Results: - * The return value is the description that was passed to - * Tk_GetFont() to create the font. The storage for the returned - * string is only guaranteed to persist until the font is deleted. - * The caller should not modify this string. + * The return value is the description that was passed to Tk_GetFont() to + * create the font. The storage for the returned string is only + * guaranteed to persist until the font is deleted. The caller should not + * modify this string. * * Side effects: * None. @@ -1280,9 +1390,9 @@ SetFontFromAny(interp, objPtr) *--------------------------------------------------------------------------- */ -CONST char * -Tk_NameOfFont(tkfont) - Tk_Font tkfont; /* Font whose name is desired. */ +const char * +Tk_NameOfFont( + Tk_Font tkfont) /* Font whose name is desired. */ { TkFont *fontPtr; @@ -1293,7 +1403,7 @@ Tk_NameOfFont(tkfont) /* *--------------------------------------------------------------------------- * - * Tk_FreeFont -- + * Tk_FreeFont -- * * Called to release a font allocated by Tk_GetFont(). * @@ -1301,15 +1411,15 @@ Tk_NameOfFont(tkfont) * None. * * Side effects: - * The reference count associated with font is decremented, and - * only deallocated when no one is using it. + * The reference count associated with font is decremented, and only + * deallocated when no one is using it. * *--------------------------------------------------------------------------- */ void -Tk_FreeFont(tkfont) - Tk_Font tkfont; /* Font to be released. */ +Tk_FreeFont( + Tk_Font tkfont) /* Font to be released. */ { TkFont *fontPtr, *prevPtr; NamedFont *nfPtr; @@ -1324,9 +1434,8 @@ Tk_FreeFont(tkfont) } if (fontPtr->namedHashPtr != NULL) { /* - * This font derived from a named font. Reduce the reference - * count on the named font and free it if no-one else is - * using it. + * This font derived from a named font. Reduce the reference count on + * the named font and free it if no-one else is using it. */ nfPtr = (NamedFont *) Tcl_GetHashValue(fontPtr->namedHashPtr); @@ -1341,7 +1450,7 @@ Tk_FreeFont(tkfont) if (prevPtr == fontPtr) { if (fontPtr->nextPtr == NULL) { Tcl_DeleteHashEntry(fontPtr->cacheHashPtr); - } else { + } else { Tcl_SetHashValue(fontPtr->cacheHashPtr, fontPtr->nextPtr); } } else { @@ -1360,7 +1469,7 @@ Tk_FreeFont(tkfont) /* *--------------------------------------------------------------------------- * - * Tk_FreeFontFromObj -- + * Tk_FreeFontFromObj -- * * Called to release a font inside a Tcl_Obj *. Decrements the refCount * of the font and removes it from the hash tables if necessary. @@ -1369,17 +1478,17 @@ Tk_FreeFont(tkfont) * None. * * Side effects: - * The reference count associated with font is decremented, and - * only deallocated when no one is using it. + * The reference count associated with font is decremented, and only + * deallocated when no one is using it. * *--------------------------------------------------------------------------- */ void -Tk_FreeFontFromObj(tkwin, objPtr) - Tk_Window tkwin; /* The window this font lives in. Needed - * for the screen value. */ - Tcl_Obj *objPtr; /* The Tcl_Obj * to be freed. */ +Tk_FreeFontFromObj( + Tk_Window tkwin, /* The window this font lives in. Needed for + * the screen value. */ + Tcl_Obj *objPtr) /* The Tcl_Obj * to be freed. */ { Tk_FreeFont(Tk_GetFontFromObj(tkwin, objPtr)); } @@ -1387,26 +1496,25 @@ Tk_FreeFontFromObj(tkwin, objPtr) /* *--------------------------------------------------------------------------- * - * FreeFontObjProc -- + * FreeFontObjProc -- * - * This proc is called to release an object reference to a font. - * Called when the object's internal rep is released or when - * the cached fontPtr needs to be changed. + * This proc is called to release an object reference to a font. Called + * when the object's internal rep is released or when the cached fontPtr + * needs to be changed. * * Results: * None. * * Side effects: - * The object reference count is decremented. When both it - * and the hash ref count go to zero, the font's resources - * are released. + * The object reference count is decremented. When both it and the hash + * ref count go to zero, the font's resources are released. * *--------------------------------------------------------------------------- */ static void -FreeFontObjProc(objPtr) - Tcl_Obj *objPtr; /* The object we are releasing. */ +FreeFontObjProc( + Tcl_Obj *objPtr) /* The object we are releasing. */ { TkFont *fontPtr = (TkFont *) objPtr->internalRep.twoPtrValue.ptr1; @@ -1422,30 +1530,30 @@ FreeFontObjProc(objPtr) /* *--------------------------------------------------------------------------- * - * DupFontObjProc -- + * DupFontObjProc -- * - * When a cached font object is duplicated, this is called to - * update the internal reps. + * When a cached font object is duplicated, this is called to update the + * internal reps. * * Results: * None. * * Side effects: - * The font's objRefCount is incremented and the internal rep - * of the copy is set to point to it. + * The font's objRefCount is incremented and the internal rep of the copy + * is set to point to it. * *--------------------------------------------------------------------------- */ static void -DupFontObjProc(srcObjPtr, dupObjPtr) - Tcl_Obj *srcObjPtr; /* The object we are copying from. */ - Tcl_Obj *dupObjPtr; /* The object we are copying to. */ +DupFontObjProc( + Tcl_Obj *srcObjPtr, /* The object we are copying from. */ + Tcl_Obj *dupObjPtr) /* The object we are copying to. */ { TkFont *fontPtr = (TkFont *) srcObjPtr->internalRep.twoPtrValue.ptr1; - + dupObjPtr->typePtr = srcObjPtr->typePtr; - dupObjPtr->internalRep.twoPtrValue.ptr1 = (VOID *) fontPtr; + dupObjPtr->internalRep.twoPtrValue.ptr1 = (void *) fontPtr; if (fontPtr != NULL) { fontPtr->objRefCount++; @@ -1457,10 +1565,10 @@ DupFontObjProc(srcObjPtr, dupObjPtr) * * Tk_FontId -- * - * Given a font, return an opaque handle that should be selected - * into the XGCValues structure in order to get the constructed - * gc to use this font. This procedure would go away if the - * XGCValues structure were replaced with a TkGCValues structure. + * Given a font, return an opaque handle that should be selected into the + * XGCValues structure in order to get the constructed gc to use this + * font. This function would go away if the XGCValues structure were + * replaced with a TkGCValues structure. * * Results: * As above. @@ -1472,8 +1580,9 @@ DupFontObjProc(srcObjPtr, dupObjPtr) */ Font -Tk_FontId(tkfont) - Tk_Font tkfont; /* Font that is going to be selected into GC. */ +Tk_FontId( + Tk_Font tkfont) /* Font that is going to be selected into + * GC. */ { TkFont *fontPtr; @@ -1486,26 +1595,27 @@ Tk_FontId(tkfont) * * Tk_GetFontMetrics -- * - * Returns overall ascent and descent metrics for the given font. - * These values can be used to space multiple lines of text and - * to align the baselines of text in different fonts. + * Returns overall ascent and descent metrics for the given font. These + * values can be used to space multiple lines of text and to align the + * baselines of text in different fonts. * * Results: - * If *heightPtr is non-NULL, it is filled with the overall height - * of the font, which is the sum of the ascent and descent. - * If *ascentPtr or *descentPtr is non-NULL, they are filled with - * the ascent and/or descent information for the font. + * If *heightPtr is non-NULL, it is filled with the overall height of the + * font, which is the sum of the ascent and descent. If *ascentPtr or + * *descentPtr is non-NULL, they are filled with the ascent and/or + * descent information for the font. * * Side effects: * None. * *--------------------------------------------------------------------------- */ + void -Tk_GetFontMetrics(tkfont, fmPtr) - Tk_Font tkfont; /* Font in which metrics are calculated. */ - Tk_FontMetrics *fmPtr; /* Pointer to structure in which font - * metrics for tkfont will be stored. */ +Tk_GetFontMetrics( + Tk_Font tkfont, /* Font in which metrics are calculated. */ + Tk_FontMetrics *fmPtr) /* Pointer to structure in which font metrics + * for tkfont will be stored. */ { TkFont *fontPtr; @@ -1520,33 +1630,32 @@ Tk_GetFontMetrics(tkfont, fmPtr) * * Tk_PostscriptFontName -- * - * Given a Tk_Font, return the name of the corresponding Postscript - * font. + * Given a Tk_Font, return the name of the corresponding Postscript font. * * Results: - * The return value is the pointsize of the given Tk_Font. - * The name of the Postscript font is appended to dsPtr. + * The return value is the pointsize of the given Tk_Font. The name of + * the Postscript font is appended to dsPtr. * * Side effects: - * If the font does not exist on the printer, the print job will - * fail at print time. Given a "reasonable" Postscript printer, - * the following Tk_Font font families should print correctly: + * If the font does not exist on the printer, the print job will fail at + * print time. Given a "reasonable" Postscript printer, the following + * Tk_Font font families should print correctly: * * Avant Garde, Arial, Bookman, Courier, Courier New, Geneva, * Helvetica, Monaco, New Century Schoolbook, New York, * Palatino, Symbol, Times, Times New Roman, Zapf Chancery, * and Zapf Dingbats. * - * Any other Tk_Font font families may not print correctly - * because the computed Postscript font name may be incorrect. + * Any other Tk_Font font families may not print correctly because the + * computed Postscript font name may be incorrect. * *--------------------------------------------------------------------------- */ int -Tk_PostscriptFontName(tkfont, dsPtr) - Tk_Font tkfont; /* Font in which text will be printed. */ - Tcl_DString *dsPtr; /* Pointer to an initialized Tcl_DString to +Tk_PostscriptFontName( + Tk_Font tkfont, /* Font in which text will be printed. */ + Tcl_DString *dsPtr) /* Pointer to an initialized Tcl_DString to * which the name of the Postscript font that * corresponds to tkfont will be appended. */ { @@ -1559,9 +1668,9 @@ Tk_PostscriptFontName(tkfont, dsPtr) fontPtr = (TkFont *) tkfont; /* - * Convert the case-insensitive Tk_Font family name to the - * case-sensitive Postscript family name. Take out any spaces and - * capitalize the first letter of each word. + * Convert the case-insensitive Tk_Font family name to the case-sensitive + * Postscript family name. Take out any spaces and capitalize the first + * letter of each word. */ family = fontPtr->fa.family; @@ -1589,8 +1698,8 @@ Tk_PostscriptFontName(tkfont, dsPtr) /* * Inline, capitalize the first letter of each word, lowercase the * rest of the letters in each word, and then take out the spaces - * between the words. This may make the DString shorter, which is - * safe to do. + * between the words. This may make the DString shorter, which is safe + * to do. */ Tcl_DStringAppend(dsPtr, family, -1); @@ -1607,7 +1716,7 @@ Tk_PostscriptFontName(tkfont, dsPtr) ch = Tcl_UniCharToUpper(ch); upper = 0; } else { - ch = Tcl_UniCharToLower(ch); + ch = Tcl_UniCharToLower(ch); } dest += Tcl_UniCharToUtf(ch, dest); } @@ -1655,14 +1764,12 @@ Tk_PostscriptFontName(tkfont, dsPtr) slantString = NULL; if (fontPtr->fa.slant == TK_FS_ROMAN) { ; + } else if ((strcmp(family, "Helvetica") == 0) + || (strcmp(family, "Courier") == 0) + || (strcmp(family, "AvantGarde") == 0)) { + slantString = "Oblique"; } else { - if ((strcmp(family, "Helvetica") == 0) - || (strcmp(family, "Courier") == 0) - || (strcmp(family, "AvantGarde") == 0)) { - slantString = "Oblique"; - } else { - slantString = "Italic"; - } + slantString = "Italic"; } /* @@ -1671,7 +1778,7 @@ Tk_PostscriptFontName(tkfont, dsPtr) */ if ((slantString == NULL) && (weightString == NULL)) { - if ((strcmp(family, "Times") == 0) + if ((strcmp(family, "Times") == 0) || (strcmp(family, "NewCenturySchlbk") == 0) || (strcmp(family, "Palatino") == 0)) { Tcl_DStringAppend(dsPtr, "-Roman", -1); @@ -1695,8 +1802,8 @@ Tk_PostscriptFontName(tkfont, dsPtr) * Tk_TextWidth -- * * A wrapper function for the more complicated interface of - * Tk_MeasureChars. Computes how much space the given - * simple string needs. + * Tk_MeasureChars. Computes how much space the given simple string + * needs. * * Results: * The return value is the width (in pixels) of the given string. @@ -1708,11 +1815,11 @@ Tk_PostscriptFontName(tkfont, dsPtr) */ int -Tk_TextWidth(tkfont, string, numBytes) - Tk_Font tkfont; /* Font in which text will be measured. */ - CONST char *string; /* String whose width will be computed. */ - int numBytes; /* Number of bytes to consider from - * string, or < 0 for strlen(). */ +Tk_TextWidth( + Tk_Font tkfont, /* Font in which text will be measured. */ + const char *string, /* String whose width will be computed. */ + int numBytes) /* Number of bytes to consider from string, or + * < 0 for strlen(). */ { int width; @@ -1726,15 +1833,15 @@ Tk_TextWidth(tkfont, string, numBytes) /* *--------------------------------------------------------------------------- * - * Tk_UnderlineChars -- + * Tk_UnderlineChars, TkUnderlineCharsInContext -- * - * This procedure draws an underline for a given range of characters - * in a given string. It doesn't draw the characters (which are - * assumed to have been displayed previously); it just draws the - * underline. This procedure would mainly be used to quickly - * underline a few characters without having to construct an - * underlined font. To produce properly underlined text, the - * appropriate underlined font should be constructed and used. + * These procedures draw an underline for a given range of characters in + * a given string. They don't draw the characters (which are assumed to + * have been displayed previously); they just draw the underline. These + * procedures would mainly be used to quickly underline a few characters + * without having to construct an underlined font. To produce properly + * underlined text, the appropriate underlined font should be constructed + * and used. * * Results: * None. @@ -1746,30 +1853,53 @@ Tk_TextWidth(tkfont, string, numBytes) */ void -Tk_UnderlineChars(display, drawable, gc, tkfont, string, x, y, firstByte, - lastByte) - Display *display; /* Display on which to draw. */ - Drawable drawable; /* Window or pixmap in which to draw. */ - GC gc; /* Graphics context for actually drawing +Tk_UnderlineChars( + Display *display, /* Display on which to draw. */ + Drawable drawable, /* Window or pixmap in which to draw. */ + GC gc, /* Graphics context for actually drawing * line. */ - Tk_Font tkfont; /* Font used in GC; must have been allocated - * by Tk_GetFont(). Used for character + Tk_Font tkfont, /* Font used in GC; must have been allocated + * by Tk_GetFont(). Used for character * dimensions, etc. */ - CONST char *string; /* String containing characters to be + const char *string, /* String containing characters to be * underlined or overstruck. */ - int x, y; /* Coordinates at which first character of + int x, int y, /* Coordinates at which first character of * string is drawn. */ - int firstByte; /* Index of first byte of first character. */ - int lastByte; /* Index of first byte after the last + int firstByte, /* Index of first byte of first character. */ + int lastByte) /* Index of first byte after the last + * character. */ +{ + TkUnderlineCharsInContext(display, drawable, gc, tkfont, string, + lastByte, x, y, firstByte, lastByte); +} + +void +TkUnderlineCharsInContext( + Display *display, /* Display on which to draw. */ + Drawable drawable, /* Window or pixmap in which to draw. */ + GC gc, /* Graphics context for actually drawing + * line. */ + Tk_Font tkfont, /* Font used in GC; must have been allocated + * by Tk_GetFont(). Used for character + * dimensions, etc. */ + const char *string, /* String containing characters to be + * underlined or overstruck. */ + int numBytes, /* Number of bytes in string. */ + int x, int y, /* Coordinates at which the first character of + * the whole string would be drawn. */ + int firstByte, /* Index of first byte of first character. */ + int lastByte) /* Index of first byte after the last * character. */ { TkFont *fontPtr; int startX, endX; fontPtr = (TkFont *) tkfont; - - Tk_MeasureChars(tkfont, string, firstByte, -1, 0, &startX); - Tk_MeasureChars(tkfont, string, lastByte, -1, 0, &endX); + + TkpMeasureCharsInContext(tkfont, string, numBytes, 0, firstByte, -1, 0, + &startX); + TkpMeasureCharsInContext(tkfont, string, numBytes, 0, lastByte, -1, 0, + &endX); XFillRectangle(display, drawable, gc, x + startX, y + fontPtr->underlinePos, (unsigned int) (endX - startX), @@ -1781,66 +1911,60 @@ Tk_UnderlineChars(display, drawable, gc, tkfont, string, x, y, firstByte, * * Tk_ComputeTextLayout -- * - * Computes the amount of screen space needed to display a - * multi-line, justified string of text. Records all the - * measurements that were done to determine to size and - * positioning of the individual lines of text; this information - * can be used by the Tk_DrawTextLayout() procedure to + * Computes the amount of screen space needed to display a multi-line, + * justified string of text. Records all the measurements that were done + * to determine to size and positioning of the individual lines of text; + * this information can be used by the Tk_DrawTextLayout() function to * display the text quickly (without remeasuring it). * - * This procedure is useful for simple widgets that want to - * display single-font, multi-line text and want Tk to handle the - * details. + * This function is useful for simple widgets that want to display + * single-font, multi-line text and want Tk to handle the details. * * Results: - * The return value is a Tk_TextLayout token that holds the - * measurement information for the given string. The token is - * only valid for the given string. If the string is freed, - * the token is no longer valid and must also be freed. To free - * the token, call Tk_FreeTextLayout(). + * The return value is a Tk_TextLayout token that holds the measurement + * information for the given string. The token is only valid for the + * given string. If the string is freed, the token is no longer valid and + * must also be freed. To free the token, call Tk_FreeTextLayout(). * - * The dimensions of the screen area needed to display the text - * are stored in *widthPtr and *heightPtr. + * The dimensions of the screen area needed to display the text are + * stored in *widthPtr and *heightPtr. * * Side effects: - * Memory is allocated to hold the measurement information. + * Memory is allocated to hold the measurement information. * *--------------------------------------------------------------------------- */ Tk_TextLayout -Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags, - widthPtr, heightPtr) - Tk_Font tkfont; /* Font that will be used to display text. */ - CONST char *string; /* String whose dimensions are to be +Tk_ComputeTextLayout( + Tk_Font tkfont, /* Font that will be used to display text. */ + const char *string, /* String whose dimensions are to be * computed. */ - int numChars; /* Number of characters to consider from + int numChars, /* Number of characters to consider from * string, or < 0 for strlen(). */ - int wrapLength; /* Longest permissible line length, in - * pixels. <= 0 means no automatic wrapping: - * just let lines get as long as needed. */ - Tk_Justify justify; /* How to justify lines. */ - int flags; /* Flag bits OR-ed together. - * TK_IGNORE_TABS means that tab characters - * should not be expanded. TK_IGNORE_NEWLINES - * means that newline characters should not - * cause a line break. */ - int *widthPtr; /* Filled with width of string. */ - int *heightPtr; /* Filled with height of string. */ + int wrapLength, /* Longest permissible line length, in pixels. + * <= 0 means no automatic wrapping: just let + * lines get as long as needed. */ + Tk_Justify justify, /* How to justify lines. */ + int flags, /* Flag bits OR-ed together. TK_IGNORE_TABS + * means that tab characters should not be + * expanded. TK_IGNORE_NEWLINES means that + * newline characters should not cause a line + * break. */ + int *widthPtr, /* Filled with width of string. */ + int *heightPtr) /* Filled with height of string. */ { TkFont *fontPtr; - CONST char *start, *end, *special; - int n, y, bytesThisChunk, maxChunks; - int baseline, height, curX, newX, maxWidth; + const char *start, *end, *special; + int n, y, bytesThisChunk, maxChunks, curLine, layoutHeight; + int baseline, height, curX, newX, maxWidth, *lineLengths; TextLayout *layoutPtr; LayoutChunk *chunkPtr; - CONST TkFontMetrics *fmPtr; + const TkFontMetrics *fmPtr; Tcl_DString lineBuffer; - int *lineLengths; - int curLine, layoutHeight; Tcl_DStringInit(&lineBuffer); - + fontPtr = (TkFont *) tkfont; if ((fontPtr == NULL) || (string == NULL)) { if (widthPtr != NULL) { @@ -1865,11 +1989,11 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags, maxChunks = 1; - layoutPtr = (TextLayout *) ckalloc(sizeof(TextLayout) - + (maxChunks - 1) * sizeof(LayoutChunk)); - layoutPtr->tkfont = tkfont; - layoutPtr->string = string; - layoutPtr->numChunks = 0; + layoutPtr = (TextLayout *) + ckalloc(sizeof(TextLayout) + (maxChunks-1) * sizeof(LayoutChunk)); + layoutPtr->tkfont = tkfont; + layoutPtr->string = string; + layoutPtr->numChunks = 0; baseline = fmPtr->ascent; maxWidth = 0; @@ -1884,7 +2008,7 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags, special = string; flags &= TK_IGNORE_TABS | TK_IGNORE_NEWLINES; - flags |= TK_WHOLE_WORDS | TK_AT_LEAST_ONE; + flags |= TK_WHOLE_WORDS | TK_AT_LEAST_ONE; for (start = string; start < end; ) { if (start >= special) { /* @@ -1892,7 +2016,7 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags, * * INTL: Note that it is safe to increment by byte, because we are * looking for 7-bit characters that will appear unchanged in - * UTF-8. At some point we may need to support the full Unicode + * UTF-8. At some point we may need to support the full Unicode * whitespace set. */ @@ -1912,7 +2036,7 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags, /* * Special points at the next special character (or the end of the - * string). Process characters between start and special. + * string). Process characters between start and special. */ chunkPtr = NULL; @@ -1924,7 +2048,7 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags, if (bytesThisChunk > 0) { chunkPtr = NewChunk(&layoutPtr, &maxChunks, start, bytesThisChunk, curX, newX, baseline); - + start += bytesThisChunk; curX = newX; } @@ -1934,8 +2058,8 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags, /* * Handle the special character. * - * INTL: Special will be pointing at a 7-bit character so we - * can safely treat it as a single byte. + * INTL: Special will be pointing at a 7-bit character so we can + * safely treat it as a single byte. */ chunkPtr = NULL; @@ -1955,7 +2079,7 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags, flags &= ~TK_AT_LEAST_ONE; continue; } - } else { + } else { NewChunk(&layoutPtr, &maxChunks, start, 1, curX, curX, baseline)->numDisplayChars = -1; start++; @@ -1964,9 +2088,9 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags, } /* - * No more characters are going to go on this line, either because - * no more characters can fit or there are no more characters left. - * Consume all extra spaces at end of line. + * No more characters are going to go on this line, either because no + * more characters can fit or there are no more characters left. + * Consume all extra spaces at end of line. */ while ((start < end) && isspace(UCHAR(*start))) { /* INTL: ISO space */ @@ -1983,12 +2107,12 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags, start++; } if (chunkPtr != NULL) { - CONST char *end; + const char *end; /* - * Append all the extra spaces on this line to the end of the - * last text chunk. This is a little tricky because we are - * switching back and forth between characters and bytes. + * Append all the extra spaces on this line to the end of the last + * text chunk. This is a little tricky because we are switching + * back and forth between characters and bytes. */ end = chunkPtr->start + chunkPtr->numBytes; @@ -2002,7 +2126,7 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags, } } - wrapLine: + wrapLine: flags |= TK_AT_LEAST_ONE; /* @@ -2015,8 +2139,8 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags, } /* - * Remember width of this line, so that all chunks on this line - * can be centered or right justified, if necessary. + * Remember width of this line, so that all chunks on this line can be + * centered or right justified, if necessary. */ Tcl_DStringAppend(&lineBuffer, (char *) &curX, sizeof(curX)); @@ -2026,9 +2150,8 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags, } /* - * If last line ends with a newline, then we need to make a 0 width - * chunk on the next line. Otherwise "Hello" and "Hello\n" are the - * same height. + * If last line ends with a newline, then we need to make a 0 width chunk + * on the next line. Otherwise "Hello" and "Hello\n" are the same height. */ if ((layoutPtr->numChunks > 0) && ((flags & TK_IGNORE_NEWLINES) == 0)) { @@ -2039,7 +2162,7 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags, Tcl_DStringAppend(&lineBuffer, (char *) &curX, sizeof(curX)); baseline += height; } - } + } layoutPtr->width = maxWidth; layoutHeight = baseline - fmPtr->ascent; @@ -2047,9 +2170,9 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags, layoutHeight = height; /* - * This fake chunk is used by the other procedures so that they can - * pretend that there is a chunk with no chars in it, which makes - * the coding simpler. + * This fake chunk is used by the other functions so that they can + * pretend that there is a chunk with no chars in it, which makes the + * coding simpler. */ layoutPtr->numChunks = 1; @@ -2066,7 +2189,7 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags, * Using maximum line length, shift all the chunks so that the lines * are all justified correctly. */ - + curLine = 0; chunkPtr = layoutPtr->chunks; y = chunkPtr->y; @@ -2104,8 +2227,8 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags, * * Tk_FreeTextLayout -- * - * This procedure is called to release the storage associated with - * a Tk_TextLayout when it is no longer needed. + * This function is called to release the storage associated with a + * Tk_TextLayout when it is no longer needed. * * Results: * None. @@ -2117,8 +2240,8 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags, */ void -Tk_FreeTextLayout(textLayout) - Tk_TextLayout textLayout; /* The text layout to be released. */ +Tk_FreeTextLayout( + Tk_TextLayout textLayout) /* The text layout to be released. */ { TextLayout *layoutPtr; @@ -2136,9 +2259,8 @@ Tk_FreeTextLayout(textLayout) * Use the information in the Tk_TextLayout token to display a * multi-line, justified string of text. * - * This procedure is useful for simple widgets that need to - * display single-font, multi-line text and want Tk to handle - * the details. + * This function is useful for simple widgets that need to display + * single-font, multi-line text and want Tk to handle the details. * * Results: * None. @@ -2150,25 +2272,25 @@ Tk_FreeTextLayout(textLayout) */ void -Tk_DrawTextLayout(display, drawable, gc, layout, x, y, firstChar, lastChar) - Display *display; /* Display on which to draw. */ - Drawable drawable; /* Window or pixmap in which to draw. */ - GC gc; /* Graphics context to use for drawing text. */ - Tk_TextLayout layout; /* Layout information, from a previous call - * to Tk_ComputeTextLayout(). */ - int x, y; /* Upper-left hand corner of rectangle in +Tk_DrawTextLayout( + Display *display, /* Display on which to draw. */ + Drawable drawable, /* Window or pixmap in which to draw. */ + GC gc, /* Graphics context to use for drawing text. */ + Tk_TextLayout layout, /* Layout information, from a previous call to + * Tk_ComputeTextLayout(). */ + int x, int y, /* Upper-left hand corner of rectangle in * which to draw (pixels). */ - int firstChar; /* The index of the first character to draw - * from the given text item. 0 specfies the + int firstChar, /* The index of the first character to draw + * from the given text item. 0 specfies the * beginning. */ - int lastChar; /* The index just after the last character - * to draw from the given text item. A number - * < 0 means to draw all characters. */ + int lastChar) /* The index just after the last character to + * draw from the given text item. A number < 0 + * means to draw all characters. */ { TextLayout *layoutPtr; int i, numDisplayChars, drawX; - CONST char *firstByte; - CONST char *lastByte; + const char *firstByte; + const char *lastByte; LayoutChunk *chunkPtr; layoutPtr = (TextLayout *) layout; @@ -2214,15 +2336,14 @@ Tk_DrawTextLayout(display, drawable, gc, layout, x, y, firstChar, lastChar) * * Tk_UnderlineTextLayout -- * - * Use the information in the Tk_TextLayout token to display an - * underline below an individual character. This procedure does - * not draw the text, just the underline. + * Use the information in the Tk_TextLayout token to display an underline + * below an individual character. This function does not draw the text, + * just the underline. * - * This procedure is useful for simple widgets that need to - * display single-font, multi-line text with an individual - * character underlined and want Tk to handle the details. - * To display larger amounts of underlined text, construct - * and use an underlined font. + * This function is useful for simple widgets that need to display + * single-font, multi-line text with an individual character underlined + * and want Tk to handle the details. To display larger amounts of + * underlined text, construct and use an underlined font. * * Results: * None. @@ -2234,16 +2355,16 @@ Tk_DrawTextLayout(display, drawable, gc, layout, x, y, firstChar, lastChar) */ void -Tk_UnderlineTextLayout(display, drawable, gc, layout, x, y, underline) - Display *display; /* Display on which to draw. */ - Drawable drawable; /* Window or pixmap in which to draw. */ - GC gc; /* Graphics context to use for drawing text. */ - Tk_TextLayout layout; /* Layout information, from a previous call - * to Tk_ComputeTextLayout(). */ - int x, y; /* Upper-left hand corner of rectangle in +Tk_UnderlineTextLayout( + Display *display, /* Display on which to draw. */ + Drawable drawable, /* Window or pixmap in which to draw. */ + GC gc, /* Graphics context to use for drawing text. */ + Tk_TextLayout layout, /* Layout information, from a previous call to + * Tk_ComputeTextLayout(). */ + int x, int y, /* Upper-left hand corner of rectangle in * which to draw (pixels). */ - int underline; /* Index of the single character to - * underline, or -1 for no underline. */ + int underline) /* Index of the single character to underline, + * or -1 for no underline. */ { TextLayout *layoutPtr; TkFont *fontPtr; @@ -2254,7 +2375,7 @@ Tk_UnderlineTextLayout(display, drawable, gc, layout, x, y, underline) layoutPtr = (TextLayout *) layout; fontPtr = (TkFont *) layoutPtr->tkfont; - XFillRectangle(display, drawable, gc, x + xx, + XFillRectangle(display, drawable, gc, x + xx, y + yy + fontPtr->fm.ascent + fontPtr->underlinePos, (unsigned int) width, (unsigned int) fontPtr->underlineHeight); } @@ -2266,25 +2387,25 @@ Tk_UnderlineTextLayout(display, drawable, gc, layout, x, y, underline) * Tk_PointToChar -- * * Use the information in the Tk_TextLayout token to determine the - * character closest to the given point. The point must be - * specified with respect to the upper-left hand corner of the - * text layout, which is considered to be located at (0, 0). + * character closest to the given point. The point must be specified with + * respect to the upper-left hand corner of the text layout, which is + * considered to be located at (0, 0). * - * Any point whose y-value is less that 0 will be considered closest - * to the first character in the text layout; any point whose y-value - * is greater than the height of the text layout will be considered - * closest to the last character in the text layout. + * Any point whose y-value is less that 0 will be considered closest to + * the first character in the text layout; any point whose y-value is + * greater than the height of the text layout will be considered closest + * to the last character in the text layout. * - * Any point whose x-value is less than 0 will be considered closest - * to the first character on that line; any point whose x-value is - * greater than the width of the text layout will be considered - * closest to the last character on that line. + * Any point whose x-value is less than 0 will be considered closest to + * the first character on that line; any point whose x-value is greater + * than the width of the text layout will be considered closest to the + * last character on that line. * * Results: - * The return value is the index of the character that was - * closest to the point. Given a text layout with no characters, - * the value 0 will always be returned, referring to a hypothetical - * zero-width placeholder character. + * The return value is the index of the character that was closest to the + * point. Given a text layout with no characters, the value 0 will always + * be returned, referring to a hypothetical zero-width placeholder + * character. * * Side effects: * None. @@ -2293,12 +2414,12 @@ Tk_UnderlineTextLayout(display, drawable, gc, layout, x, y, underline) */ int -Tk_PointToChar(layout, x, y) - Tk_TextLayout layout; /* Layout information, from a previous call - * to Tk_ComputeTextLayout(). */ - int x, y; /* Coordinates of point to check, with - * respect to the upper-left corner of the - * text layout. */ +Tk_PointToChar( + Tk_TextLayout layout, /* Layout information, from a previous call to + * Tk_ComputeTextLayout(). */ + int x, int y) /* Coordinates of point to check, with respect + * to the upper-left corner of the text + * layout. */ { TextLayout *layoutPtr; LayoutChunk *chunkPtr, *lastPtr; @@ -2307,8 +2428,8 @@ Tk_PointToChar(layout, x, y) if (y < 0) { /* - * Point lies above any line in this layout. Return the index of - * the first char. + * Point lies above any line in this layout. Return the index of the + * first char. */ return 0; @@ -2327,30 +2448,30 @@ Tk_PointToChar(layout, x, y) if (y < baseline + fontPtr->fm.descent) { if (x < chunkPtr->x) { /* - * Point is to the left of all chunks on this line. Return - * the index of the first character on this line. + * Point is to the left of all chunks on this line. Return the + * index of the first character on this line. */ return numChars; } if (x >= layoutPtr->width) { /* - * If point lies off right side of the text layout, return - * the last char in the last chunk on this line. Without - * this, it might return the index of the first char that - * was located outside of the text layout. + * If point lies off right side of the text layout, return the + * last char in the last chunk on this line. Without this, it + * might return the index of the first char that was located + * outside of the text layout. */ x = INT_MAX; } /* - * Examine all chunks on this line to see which one contains - * the specified point. + * Examine all chunks on this line to see which one contains the + * specified point. */ lastPtr = chunkPtr; - while ((i < layoutPtr->numChunks) && (chunkPtr->y == baseline)) { + while ((i < layoutPtr->numChunks) && (chunkPtr->y == baseline)) { if (x < chunkPtr->x + chunkPtr->totalWidth) { /* * Point falls on one of the characters in this chunk. @@ -2377,7 +2498,7 @@ Tk_PointToChar(layout, x, y) /* * Point is to the right of all chars in all the chunks on this - * line. Return the index just past the last char in the last + * line. Return the index just past the last char in the last * chunk on this line. */ @@ -2393,8 +2514,8 @@ Tk_PointToChar(layout, x, y) } /* - * Point lies below any line in this text layout. Return the index - * just past the last char. + * Point lies below any line in this text layout. Return the index just + * past the last char. */ return (lastPtr->start + lastPtr->numChars) - layoutPtr->string; @@ -2405,29 +2526,28 @@ Tk_PointToChar(layout, x, y) * * Tk_CharBbox -- * - * Use the information in the Tk_TextLayout token to return the - * bounding box for the character specified by index. + * Use the information in the Tk_TextLayout token to return the bounding + * box for the character specified by index. * - * The width of the bounding box is the advance width of the - * character, and does not include and left- or right-bearing. - * Any character that extends partially outside of the - * text layout is considered to be truncated at the edge. Any - * character which is located completely outside of the text - * layout is considered to be zero-width and pegged against - * the edge. + * The width of the bounding box is the advance width of the character, + * and does not include and left- or right-bearing. Any character that + * extends partially outside of the text layout is considered to be + * truncated at the edge. Any character which is located completely + * outside of the text layout is considered to be zero-width and pegged + * against the edge. * * The height of the bounding box is the line height for this font, - * extending from the top of the ascent to the bottom of the - * descent. Information about the actual height of the individual - * letter is not available. + * extending from the top of the ascent to the bottom of the descent. + * Information about the actual height of the individual letter is not + * available. + * + * A text layout that contains no characters is considered to contain a + * single zero-width placeholder character. * - * A text layout that contains no characters is considered to - * contain a single zero-width placeholder character. - * * Results: - * The return value is 0 if the index did not specify a character - * in the text layout, or non-zero otherwise. In that case, - * *bbox is filled with the bounding box of the character. + * The return value is 0 if the index did not specify a character in the + * text layout, or non-zero otherwise. In that case, *bbox is filled with + * the bounding box of the character. * * Side effects: * None. @@ -2436,25 +2556,26 @@ Tk_PointToChar(layout, x, y) */ int -Tk_CharBbox(layout, index, xPtr, yPtr, widthPtr, heightPtr) - Tk_TextLayout layout; /* Layout information, from a previous call to - * Tk_ComputeTextLayout(). */ - int index; /* The index of the character whose bbox is - * desired. */ - int *xPtr, *yPtr; /* Filled with the upper-left hand corner, in - * pixels, of the bounding box for the character - * specified by index, if non-NULL. */ - int *widthPtr, *heightPtr; - /* Filled with the width and height of the - * bounding box for the character specified by - * index, if non-NULL. */ +Tk_CharBbox( + Tk_TextLayout layout, /* Layout information, from a previous call to + * Tk_ComputeTextLayout(). */ + int index, /* The index of the character whose bbox is + * desired. */ + int *xPtr, int *yPtr, /* Filled with the upper-left hand corner, in + * pixels, of the bounding box for the + * character specified by index, if + * non-NULL. */ + int *widthPtr, int *heightPtr) + /* Filled with the width and height of the + * bounding box for the character specified by + * index, if non-NULL. */ { TextLayout *layoutPtr; LayoutChunk *chunkPtr; - int i, x, w; + int i, x = 0, w; Tk_Font tkfont; TkFont *fontPtr; - CONST char *end; + const char *end; if (index < 0) { return 0; @@ -2476,7 +2597,7 @@ Tk_CharBbox(layout, index, xPtr, yPtr, widthPtr, heightPtr) end = Tcl_UtfAtIndex(chunkPtr->start, index); if (xPtr != NULL) { Tk_MeasureChars(tkfont, chunkPtr->start, - end - chunkPtr->start, -1, 0, &x); + end - chunkPtr->start, -1, 0, &x); x += chunkPtr->x; } if (widthPtr != NULL) { @@ -2488,25 +2609,26 @@ Tk_CharBbox(layout, index, xPtr, yPtr, widthPtr, heightPtr) index -= chunkPtr->numChars; chunkPtr++; } - if (index == 0) { - /* - * Special case to get location just past last char in layout. - */ - - chunkPtr--; - x = chunkPtr->x + chunkPtr->totalWidth; - w = 0; - } else { + if (index != 0) { return 0; } /* - * Ensure that the bbox lies within the text layout. This forces all - * chars that extend off the right edge of the text layout to have - * truncated widths, and all chars that are completely off the right - * edge of the text layout to peg to the edge and have 0 width. + * Special case to get location just past last char in layout. + */ + + chunkPtr--; + x = chunkPtr->x + chunkPtr->totalWidth; + w = 0; + + /* + * Ensure that the bbox lies within the text layout. This forces all chars + * that extend off the right edge of the text layout to have truncated + * widths, and all chars that are completely off the right edge of the + * text layout to peg to the edge and have 0 width. */ - check: + + check: if (yPtr != NULL) { *yPtr = chunkPtr->y - fontPtr->fm.ascent; } @@ -2535,16 +2657,15 @@ Tk_CharBbox(layout, index, xPtr, yPtr, widthPtr, heightPtr) * * Tk_DistanceToTextLayout -- * - * Computes the distance in pixels from the given point to the - * given text layout. Non-displaying space characters that occur - * at the end of individual lines in the text layout are ignored - * for hit detection purposes. + * Computes the distance in pixels from the given point to the given text + * layout. Non-displaying space characters that occur at the end of + * individual lines in the text layout are ignored for hit detection + * purposes. * * Results: - * The return value is 0 if the point (x, y) is inside the text - * layout. If the point isn't inside the text layout then the - * return value is the distance in pixels from the point to the - * text item. + * The return value is 0 if the point (x, y) is inside the text layout. + * If the point isn't inside the text layout then the return value is the + * distance in pixels from the point to the text item. * * Side effects: * None. @@ -2553,12 +2674,12 @@ Tk_CharBbox(layout, index, xPtr, yPtr, widthPtr, heightPtr) */ int -Tk_DistanceToTextLayout(layout, x, y) - Tk_TextLayout layout; /* Layout information, from a previous call +Tk_DistanceToTextLayout( + Tk_TextLayout layout, /* Layout information, from a previous call * to Tk_ComputeTextLayout(). */ - int x, y; /* Coordinates of point to check, with - * respect to the upper-left corner of the - * text layout (in pixels). */ + int x, int y) /* Coordinates of point to check, with respect + * to the upper-left corner of the text layout + * (in pixels). */ { int i, x1, x2, y1, y2, xDiff, yDiff, dist, minDist, ascent, descent; LayoutChunk *chunkPtr; @@ -2569,14 +2690,14 @@ Tk_DistanceToTextLayout(layout, x, y) fontPtr = (TkFont *) layoutPtr->tkfont; ascent = fontPtr->fm.ascent; descent = fontPtr->fm.descent; - + minDist = 0; chunkPtr = layoutPtr->chunks; for (i = 0; i < layoutPtr->numChunks; i++) { if (chunkPtr->start[0] == '\n') { /* - * Newline characters are not counted when computing distance - * (but tab characters would still be considered). + * Newline characters are not counted when computing distance (but + * tab characters would still be considered). */ chunkPtr++; @@ -2620,15 +2741,15 @@ Tk_DistanceToTextLayout(layout, x, y) * * Tk_IntersectTextLayout -- * - * Determines whether a text layout lies entirely inside, - * entirely outside, or overlaps a given rectangle. Non-displaying - * space characters that occur at the end of individual lines in - * the text layout are ignored for intersection calculations. + * Determines whether a text layout lies entirely inside, entirely + * outside, or overlaps a given rectangle. Non-displaying space + * characters that occur at the end of individual lines in the text + * layout are ignored for intersection calculations. * * Results: - * The return value is -1 if the text layout is entirely outside of - * the rectangle, 0 if it overlaps, and 1 if it is entirely inside - * of the rectangle. + * The return value is -1 if the text layout is entirely outside of the + * rectangle, 0 if it overlaps, and 1 if it is entirely inside of the + * rectangle. * * Side effects: * None. @@ -2637,15 +2758,15 @@ Tk_DistanceToTextLayout(layout, x, y) */ int -Tk_IntersectTextLayout(layout, x, y, width, height) - Tk_TextLayout layout; /* Layout information, from a previous call - * to Tk_ComputeTextLayout(). */ - int x, y; /* Upper-left hand corner, in pixels, of +Tk_IntersectTextLayout( + Tk_TextLayout layout, /* Layout information, from a previous call to + * Tk_ComputeTextLayout(). */ + int x, int y, /* Upper-left hand corner, in pixels, of * rectangular area to compare with text - * layout. Coordinates are with respect to - * the upper-left hand corner of the text - * layout itself. */ - int width, height; /* The width and height of the above + * layout. Coordinates are with respect to the + * upper-left hand corner of the text layout + * itself. */ + int width, int height) /* The width and height of the above * rectangular area, in pixels. */ { int result, i, x1, y1, x2, y2; @@ -2656,19 +2777,19 @@ Tk_IntersectTextLayout(layout, x, y, width, height) /* * Scan the chunks one at a time, seeing whether each is entirely in, - * entirely out, or overlapping the rectangle. If an overlap is - * detected, return immediately; otherwise wait until all chunks have - * been processed and see if they were all inside or all outside. + * entirely out, or overlapping the rectangle. If an overlap is detected, + * return immediately; otherwise wait until all chunks have been processed + * and see if they were all inside or all outside. */ - + layoutPtr = (TextLayout *) layout; chunkPtr = layoutPtr->chunks; fontPtr = (TkFont *) layoutPtr->tkfont; - left = x; - top = y; - right = x + width; - bottom = y + height; + left = x; + top = y; + right = x + width; + bottom = y + height; result = 0; for (i = 0; i < layoutPtr->numChunks; i++) { @@ -2711,34 +2832,32 @@ Tk_IntersectTextLayout(layout, x, y, width, height) * * Tk_TextLayoutToPostscript -- * - * Outputs the contents of a text layout in Postscript format. - * The set of lines in the text layout will be rendered by the user - * supplied Postscript function. The function should be of the form: + * Outputs the contents of a text layout in Postscript format. The set of + * lines in the text layout will be rendered by the user supplied + * Postscript function. The function should be of the form: * - * justify x y string function -- + * justify x y string function -- * * Justify is -1, 0, or 1, depending on whether the following string - * should be left, center, or right justified, x and y is the - * location for the origin of the string, string is the sequence - * of characters to be printed, and function is the name of the - * caller-provided function; the function should leave nothing - * on the stack. - * - * The meaning of the origin of the string (x and y) depends on - * the justification. For left justification, x is where the - * left edge of the string should appear. For center justification, - * x is where the center of the string should appear. And for right - * justification, x is where the right edge of the string should - * appear. This behavior is necessary because, for example, right - * justified text on the screen is justified with screen metrics. - * The same string needs to be justified with printer metrics on - * the printer to appear in the correct place with respect to other - * similarly justified strings. In all circumstances, y is the - * location of the baseline for the string. + * should be left, center, or right justified, x and y is the location + * for the origin of the string, string is the sequence of characters to + * be printed, and function is the name of the caller-provided function; + * the function should leave nothing on the stack. + * + * The meaning of the origin of the string (x and y) depends on the + * justification. For left justification, x is where the left edge of the + * string should appear. For center justification, x is where the center + * of the string should appear. And for right justification, x is where + * the right edge of the string should appear. This behavior is necessary + * because, for example, right justified text on the screen is justified + * with screen metrics. The same string needs to be justified with + * printer metrics on the printer to appear in the correct place with + * respect to other similarly justified strings. In all circumstances, y + * is the location of the baseline for the string. * * Results: - * The interp's result is modified to hold the Postscript code that - * will render the text layout. + * The interp's result is modified to hold the Postscript code that will + * render the text layout. * * Side effects: * None. @@ -2747,20 +2866,17 @@ Tk_IntersectTextLayout(layout, x, y, width, height) */ void -Tk_TextLayoutToPostscript(interp, layout) - Tcl_Interp *interp; /* Filled with Postscript code. */ - Tk_TextLayout layout; /* The layout to be rendered. */ +Tk_TextLayoutToPostscript( + Tcl_Interp *interp, /* Filled with Postscript code. */ + Tk_TextLayout layout) /* The layout to be rendered. */ { #define MAXUSE 128 - char buf[MAXUSE+30]; + char buf[MAXUSE+30], uindex[5] = "\0\0\0\0", one_char[5]; LayoutChunk *chunkPtr; - int i, j, used, c, baseline; + int i, j, used, c, baseline, charsize; Tcl_UniChar ch; - CONST char *p, *last_p,*glyphname; + const char *p, *last_p, *glyphname; TextLayout *layoutPtr; - char uindex[5]="\0\0\0\0"; - char one_char[5]; - int charsize; int bytecount=0; layoutPtr = (TextLayout *) layout; @@ -2787,23 +2903,24 @@ Tk_TextLayoutToPostscript(interp, layout) p = chunkPtr->start; for (j = 0; j < chunkPtr->numDisplayChars; j++) { /* - * INTL: For now we just treat the characters as binary - * data and display the lower byte. Eventually this should - * be revised to handle international postscript fonts. + * INTL: For now we just treat the characters as binary data + * and display the lower byte. Eventually this should be + * revised to handle international postscript fonts. */ - last_p=p; - p +=(charsize= Tcl_UtfToUniChar(p,&ch)); - Tcl_UtfToExternal(interp,NULL,last_p,charsize,0,NULL,one_char,4, - NULL,&bytecount,NULL); - if (bytecount == 1) { + + last_p = p; + p += (charsize = Tcl_UtfToUniChar(p,&ch)); + Tcl_UtfToExternal(interp, NULL, last_p, charsize, 0, NULL, + one_char, 4, NULL, &bytecount, NULL); + if (bytecount == 1) { c = UCHAR(one_char[0]); /* c = UCHAR( ch & 0xFF) */; if ((c == '(') || (c == ')') || (c == '\\') || (c < 0x20) || (c >= UCHAR(0x7f))) { /* - * Tricky point: the "03" is necessary in the sprintf + * Tricky point: the "03" is necessary in the sprintf * below, so that a full three digits of octal are - * always generated. Without the "03", a number + * always generated. Without the "03", a number * following this sequence could be interpreted by * Postscript as part of this sequence. */ @@ -2814,36 +2931,42 @@ Tk_TextLayoutToPostscript(interp, layout) buf[used++] = c; } } else { - /* This character doesn't belong to system character set. - * So, we must use full glyph name */ - sprintf(uindex,"%04X",ch); /* endianness? */ - if ((glyphname = Tcl_GetVar2( interp , "::tk::psglyphs",uindex,0))) { - if (used > 0 && buf [used-1] == '(') + /* + * This character doesn't belong to system character set. + * So, we must use full glyph name. + */ + + sprintf(uindex, "%04X", ch); /* endianness? */ + glyphname = Tcl_GetVar2(interp,"::tk::psglyphs",uindex,0); + if (glyphname) { + if (used > 0 && buf [used-1] == '(') { --used; - else + } else { buf[used++] = ')'; + } buf[used++] = '/'; - while( (*glyphname) && (used < (MAXUSE+27))) + while ((*glyphname) && (used < (MAXUSE+27))) { buf[used++] = *glyphname++ ; + } buf[used++] = '('; } - + } if (used >= MAXUSE) { buf[used] = '\0'; - Tcl_AppendResult(interp, buf, (char *) NULL); + Tcl_AppendResult(interp, buf, NULL); used = 0; } } } if (used >= MAXUSE) { /* - * If there are a whole bunch of returns or tabs in a row, - * then buf[] could get filled up. + * If there are a whole bunch of returns or tabs in a row, then + * buf[] could get filled up. */ - + buf[used] = '\0'; - Tcl_AppendResult(interp, buf, (char *) NULL); + Tcl_AppendResult(interp, buf, NULL); used = 0; } chunkPtr++; @@ -2852,7 +2975,7 @@ Tk_TextLayoutToPostscript(interp, layout) buf[used++] = ']'; buf[used++] = '\n'; buf[used] = '\0'; - Tcl_AppendResult(interp, buf, (char *) NULL); + Tcl_AppendResult(interp, buf, NULL); } /* @@ -2864,33 +2987,32 @@ Tk_TextLayoutToPostscript(interp, layout) * initialized font attributes structure. * * Results: - * A standard Tcl return value. If TCL_ERROR is returned, an - * error message will be left in interp's result object (if non-NULL). + * A standard Tcl return value. If TCL_ERROR is returned, an error + * message will be left in interp's result object. * * Side effects: * The fields of the font attributes structure get filled in with - * information from argc/argv. If an error occurs while parsing, - * the font attributes structure will contain all modifications - * specified in the command line options up to the point of the - * error. + * information from argc/argv. If an error occurs while parsing, the font + * attributes structure will contain all modifications specified in the + * command line options up to the point of the error. * *--------------------------------------------------------------------------- */ static int -ConfigAttributesObj(interp, tkwin, objc, objv, faPtr) - Tcl_Interp *interp; /* Interp for error return, or NULL. */ - Tk_Window tkwin; /* For display on which font will be used. */ - int objc; /* Number of elements in argv. */ - Tcl_Obj *CONST objv[]; /* Command line options. */ - TkFontAttributes *faPtr; /* Font attributes structure whose fields - * are to be modified. Structure must already - * be properly initialized. */ +ConfigAttributesObj( + Tcl_Interp *interp, /* Interp for error return. */ + Tk_Window tkwin, /* For display on which font will be used. */ + int objc, /* Number of elements in argv. */ + Tcl_Obj *const objv[], /* Command line options. */ + TkFontAttributes *faPtr) /* Font attributes structure whose fields are + * to be modified. Structure must already be + * properly initialized. */ { int i, n, index; Tcl_Obj *optionPtr, *valuePtr; char *value; - + for (i = 0; i < objc; i += 2) { optionPtr = objv[i]; valuePtr = objv[i + 1]; @@ -2901,63 +3023,55 @@ ConfigAttributesObj(interp, tkwin, objc, objv, faPtr) } if ((i+2 >= objc) && (objc & 1)) { /* - * This test occurs after Tcl_GetIndexFromObj() so that - * "font create xyz -xyz" will return the error message - * that "-xyz" is a bad option, rather than that the value - * for "-xyz" is missing. + * This test occurs after Tcl_GetIndexFromObj() so that "font + * create xyz -xyz" will return the error message that "-xyz" is a + * bad option, rather than that the value for "-xyz" is missing. */ if (interp != NULL) { Tcl_AppendResult(interp, "value for \"", - Tcl_GetString(optionPtr), "\" option missing", - (char *) NULL); + Tcl_GetString(optionPtr), "\" option missing", NULL); } return TCL_ERROR; } switch (index) { - case FONT_FAMILY: { - value = Tcl_GetString(valuePtr); - faPtr->family = Tk_GetUid(value); - break; - } - case FONT_SIZE: { - if (Tcl_GetIntFromObj(interp, valuePtr, &n) != TCL_OK) { - return TCL_ERROR; - } - faPtr->size = n; - break; + case FONT_FAMILY: + value = Tcl_GetString(valuePtr); + faPtr->family = Tk_GetUid(value); + break; + case FONT_SIZE: + if (Tcl_GetIntFromObj(interp, valuePtr, &n) != TCL_OK) { + return TCL_ERROR; } - case FONT_WEIGHT: { - n = TkFindStateNumObj(interp, optionPtr, weightMap, valuePtr); - if (n == TK_FW_UNKNOWN) { - return TCL_ERROR; - } - faPtr->weight = n; - break; + faPtr->size = n; + break; + case FONT_WEIGHT: + n = TkFindStateNumObj(interp, optionPtr, weightMap, valuePtr); + if (n == TK_FW_UNKNOWN) { + return TCL_ERROR; } - case FONT_SLANT: { - n = TkFindStateNumObj(interp, optionPtr, slantMap, valuePtr); - if (n == TK_FS_UNKNOWN) { - return TCL_ERROR; - } - faPtr->slant = n; - break; + faPtr->weight = n; + break; + case FONT_SLANT: + n = TkFindStateNumObj(interp, optionPtr, slantMap, valuePtr); + if (n == TK_FS_UNKNOWN) { + return TCL_ERROR; } - case FONT_UNDERLINE: { - if (Tcl_GetBooleanFromObj(interp, valuePtr, &n) != TCL_OK) { - return TCL_ERROR; - } - faPtr->underline = n; - break; + faPtr->slant = n; + break; + case FONT_UNDERLINE: + if (Tcl_GetBooleanFromObj(interp, valuePtr, &n) != TCL_OK) { + return TCL_ERROR; } - case FONT_OVERSTRIKE: { - if (Tcl_GetBooleanFromObj(interp, valuePtr, &n) != TCL_OK) { - return TCL_ERROR; - } - faPtr->overstrike = n; - break; + faPtr->underline = n; + break; + case FONT_OVERSTRIKE: + if (Tcl_GetBooleanFromObj(interp, valuePtr, &n) != TCL_OK) { + return TCL_ERROR; } + faPtr->overstrike = n; + break; } } return TCL_OK; @@ -2971,14 +3085,13 @@ ConfigAttributesObj(interp, tkwin, objc, objv, faPtr) * Return information about the font attributes as a Tcl list. * * Results: - * The return value is TCL_OK if the objPtr was non-NULL and - * specified a valid font attribute, TCL_ERROR otherwise. If TCL_OK - * is returned, the interp's result object is modified to hold a - * description of either the current value of a single option, or a - * list of all options and their current values for the given font - * attributes. If TCL_ERROR is returned, the interp's result is - * set to an error message describing that the objPtr did not refer - * to a valid option. + * The return value is TCL_OK if the objPtr was non-NULL and specified a + * valid font attribute, TCL_ERROR otherwise. If TCL_OK is returned, the + * interp's result object is modified to hold a description of either the + * current value of a single option, or a list of all options and their + * current values for the given font attributes. If TCL_ERROR is + * returned, the interp's result is set to an error message describing + * that the objPtr did not refer to a valid option. * * Side effects: * None. @@ -2987,16 +3100,16 @@ ConfigAttributesObj(interp, tkwin, objc, objv, faPtr) */ static int -GetAttributeInfoObj(interp, faPtr, objPtr) - Tcl_Interp *interp; /* Interp to hold result. */ - CONST TkFontAttributes *faPtr; /* The font attributes to inspect. */ - Tcl_Obj *objPtr; /* If non-NULL, indicates the single - * option whose value is to be - * returned. Otherwise information is - * returned for all options. */ +GetAttributeInfoObj( + Tcl_Interp *interp, /* Interp to hold result. */ + const TkFontAttributes *faPtr, + /* The font attributes to inspect. */ + Tcl_Obj *objPtr) /* If non-NULL, indicates the single option + * whose value is to be returned. Otherwise + * information is returned for all options. */ { int i, index, start, end; - CONST char *str; + const char *str; Tcl_Obj *optionPtr, *valuePtr, *resultPtr; resultPtr = Tcl_GetObjResult(interp); @@ -3015,32 +3128,32 @@ GetAttributeInfoObj(interp, faPtr, objPtr) valuePtr = NULL; for (i = start; i < end; i++) { switch (i) { - case FONT_FAMILY: - str = faPtr->family; - valuePtr = Tcl_NewStringObj(str, ((str == NULL) ? 0 : -1)); - break; + case FONT_FAMILY: + str = faPtr->family; + valuePtr = Tcl_NewStringObj(str, ((str == NULL) ? 0 : -1)); + break; - case FONT_SIZE: - valuePtr = Tcl_NewIntObj(faPtr->size); - break; + case FONT_SIZE: + valuePtr = Tcl_NewIntObj(faPtr->size); + break; - case FONT_WEIGHT: - str = TkFindStateString(weightMap, faPtr->weight); - valuePtr = Tcl_NewStringObj(str, -1); - break; - - case FONT_SLANT: - str = TkFindStateString(slantMap, faPtr->slant); - valuePtr = Tcl_NewStringObj(str, -1); - break; + case FONT_WEIGHT: + str = TkFindStateString(weightMap, faPtr->weight); + valuePtr = Tcl_NewStringObj(str, -1); + break; - case FONT_UNDERLINE: - valuePtr = Tcl_NewBooleanObj(faPtr->underline); - break; + case FONT_SLANT: + str = TkFindStateString(slantMap, faPtr->slant); + valuePtr = Tcl_NewStringObj(str, -1); + break; - case FONT_OVERSTRIKE: - valuePtr = Tcl_NewBooleanObj(faPtr->overstrike); - break; + case FONT_UNDERLINE: + valuePtr = Tcl_NewBooleanObj(faPtr->underline); + break; + + case FONT_OVERSTRIKE: + valuePtr = Tcl_NewBooleanObj(faPtr->overstrike); + break; } if (objPtr != NULL) { Tcl_SetObjResult(interp, valuePtr); @@ -3058,8 +3171,8 @@ GetAttributeInfoObj(interp, faPtr, objPtr) * * ParseFontNameObj -- * - * Converts a object into a set of font attributes that can be used - * to construct a font. + * Converts a object into a set of font attributes that can be used to + * construct a font. * * The string rep of the object can be one of the following forms: * XLFD (see X documentation) @@ -3067,10 +3180,10 @@ GetAttributeInfoObj(interp, faPtr, objPtr) * "-option value [-option value ...]" * * Results: - * The return value is TCL_ERROR if the object was syntactically - * invalid. In that case an error message is left in interp's - * result object. Otherwise, fills the font attribute buffer with - * the values parsed from the string and returns TCL_OK; + * The return value is TCL_ERROR if the object was syntactically invalid. + * In that case an error message is left in interp's result object. + * Otherwise, fills the font attribute buffer with the values parsed from + * the string and returns TCL_OK; * * Side effects: * None. @@ -3079,13 +3192,12 @@ GetAttributeInfoObj(interp, faPtr, objPtr) */ static int -ParseFontNameObj(interp, tkwin, objPtr, faPtr) - Tcl_Interp *interp; /* Interp for error return, or NULL if no - * error messages are to be generated. */ - Tk_Window tkwin; /* For display on which font is used. */ - Tcl_Obj *objPtr; /* Parseable font description object. */ - TkFontAttributes *faPtr; /* Filled with attributes parsed from font - * name. Any attributes that were not +ParseFontNameObj( + Tcl_Interp *interp, /* Interp for error return. */ + Tk_Window tkwin, /* For display on which font is used. */ + Tcl_Obj *objPtr, /* Parseable font description object. */ + TkFontAttributes *faPtr) /* Filled with attributes parsed from font + * name. Any attributes that were not * specified in font name are filled with * default values. */ { @@ -3093,7 +3205,7 @@ ParseFontNameObj(interp, tkwin, objPtr, faPtr) int objc, result, i, n; Tcl_Obj **objv; char *string; - + TkInitFontAttributes(faPtr); string = Tcl_GetString(objPtr); @@ -3102,7 +3214,7 @@ ParseFontNameObj(interp, tkwin, objPtr, faPtr) * This may be an XLFD or an "-option value" string. * * If the string begins with "-*" or a "-foundry-family-*" pattern, - * then consider it an XLFD. + * then consider it an XLFD. */ if (string[1] == '*') { @@ -3120,13 +3232,13 @@ ParseFontNameObj(interp, tkwin, objPtr, faPtr) return ConfigAttributesObj(interp, tkwin, objc, objv, faPtr); } - + if (*string == '*') { /* - * This is appears to be an XLFD. Under Unix, all valid XLFDs were - * already handled by TkpGetNativeFont. If we are here, either we - * have something that initially looks like an XLFD but isn't or we - * have encountered an XLFD on Windows or Mac. + * This is appears to be an XLFD. Under Unix, all valid XLFDs were + * already handled by TkpGetNativeFont. If we are here, either we have + * something that initially looks like an XLFD but isn't or we have + * encountered an XLFD on Windows or Mac. */ xlfd: @@ -3134,18 +3246,32 @@ ParseFontNameObj(interp, tkwin, objPtr, faPtr) if (result == TCL_OK) { return TCL_OK; } + + /* + * If the string failed to parse but was considered to be a XLFD + * then it may be a "-option value" string with a hyphenated family + * name as per bug 2791352 + */ + + if (Tcl_ListObjGetElements(interp, objPtr, &objc, &objv) != TCL_OK) { + return TCL_ERROR; + } + + if (ConfigAttributesObj(interp, tkwin, objc, objv, faPtr) == TCL_OK) { + return TCL_OK; + } } /* - * Wasn't an XLFD or "-option value" string. Try it as a - * "font size style" list. + * Wasn't an XLFD or "-option value" string. Try it as a "font size style" + * list. */ if ((Tcl_ListObjGetElements(NULL, objPtr, &objc, &objv) != TCL_OK) || (objc < 1)) { if (interp != NULL) { Tcl_AppendResult(interp, "font \"", string, "\" doesn't exist", - (char *) NULL); + NULL); } return TCL_ERROR; } @@ -3193,7 +3319,7 @@ ParseFontNameObj(interp, tkwin, objPtr, faPtr) if (interp != NULL) { Tcl_AppendResult(interp, "unknown font style \"", - Tcl_GetString(objv[i]), "\"", (char *) NULL); + Tcl_GetString(objv[i]), "\"", NULL); } return TCL_ERROR; } @@ -3205,9 +3331,8 @@ ParseFontNameObj(interp, tkwin, objPtr, faPtr) * * NewChunk -- * - * Helper function for Tk_ComputeTextLayout(). Encapsulates a - * measured set of characters in a chunk that can be quickly - * drawn. + * Helper function for Tk_ComputeTextLayout(). Encapsulates a measured + * set of characters in a chunk that can be quickly drawn. * * Results: * A pointer to the new chunk in the text layout. @@ -3215,28 +3340,28 @@ ParseFontNameObj(interp, tkwin, objPtr, faPtr) * Side effects: * The text layout is reallocated to hold more chunks as necessary. * - * Currently, Tk_ComputeTextLayout() stores contiguous ranges of - * "normal" characters in a chunk, along with individual tab - * and newline chars in their own chunks. All characters in the - * text layout are accounted for. + * Currently, Tk_ComputeTextLayout() stores contiguous ranges of "normal" + * characters in a chunk, along with individual tab and newline chars in + * their own chunks. All characters in the text layout are accounted for. * *--------------------------------------------------------------------------- */ + static LayoutChunk * -NewChunk(layoutPtrPtr, maxPtr, start, numBytes, curX, newX, y) - TextLayout **layoutPtrPtr; - int *maxPtr; - CONST char *start; - int numBytes; - int curX; - int newX; - int y; +NewChunk( + TextLayout **layoutPtrPtr, + int *maxPtr, + const char *start, + int numBytes, + int curX, + int newX, + int y) { TextLayout *layoutPtr; LayoutChunk *chunkPtr; int maxChunks, numChars; size_t s; - + layoutPtr = *layoutPtrPtr; maxChunks = *maxPtr; if (layoutPtr->numChunks == maxChunks) { @@ -3271,8 +3396,8 @@ NewChunk(layoutPtrPtr, maxPtr, start, numBytes, curX, newX, y) * * Results: * Return value is TCL_ERROR if string was not a fully specified XLFD. - * Otherwise, fills font attribute buffer with the values parsed - * from the XLFD and returns TCL_OK. + * Otherwise, fills font attribute buffer with the values parsed from the + * XLFD and returns TCL_OK. * * Side effects: * None. @@ -3281,25 +3406,25 @@ NewChunk(layoutPtrPtr, maxPtr, start, numBytes, curX, newX, y) */ int -TkFontParseXLFD(string, faPtr, xaPtr) - CONST char *string; /* Parseable font description string. */ - TkFontAttributes *faPtr; /* Filled with attributes parsed from font - * name. Any attributes that were not +TkFontParseXLFD( + const char *string, /* Parseable font description string. */ + TkFontAttributes *faPtr, /* Filled with attributes parsed from font + * name. Any attributes that were not * specified in font name are filled with * default values. */ - TkXLFDAttributes *xaPtr; /* Filled with X-specific attributes parsed - * from font name. Any attributes that were + TkXLFDAttributes *xaPtr) /* Filled with X-specific attributes parsed + * from font name. Any attributes that were * not specified in font name are filled with - * default values. May be NULL if such + * default values. May be NULL if such * information is not desired. */ { char *src; - CONST char *str; + const char *str; int i, j; char *field[XLFD_NUMFIELDS + 2]; Tcl_DString ds; TkXLFDAttributes xa; - + if (xaPtr == NULL) { xaPtr = &xa; } @@ -3338,13 +3463,13 @@ TkFontParseXLFD(string, faPtr, xaPtr) /* * An XLFD of the form -adobe-times-medium-r-*-12-*-* is pretty common, - * but it is (strictly) malformed, because the first * is eliding both - * the Setwidth and the Addstyle fields. If the Addstyle field is a - * number, then assume the above incorrect form was used and shift all - * the rest of the fields right by one, so the number gets interpreted - * as a pixelsize. This fix is so that we don't get a million reports - * that "it works under X (as a native font name), but gives a syntax - * error under Windows (as a parsed set of attributes)". + * but it is (strictly) malformed, because the first * is eliding both the + * Setwidth and the Addstyle fields. If the Addstyle field is a number, + * then assume the above incorrect form was used and shift all the rest of + * the fields right by one, so the number gets interpreted as a pixelsize. + * This fix is so that we don't get a million reports that "it works under + * X (as a native font name), but gives a syntax error under Windows (as a + * parsed set of attributes)". */ if ((i > XLFD_ADD_STYLE) && (FieldSpecified(field[XLFD_ADD_STYLE]))) { @@ -3394,8 +3519,8 @@ TkFontParseXLFD(string, faPtr, xaPtr) /* XLFD_ADD_STYLE ignored. */ /* - * Pointsize in tenths of a point, but treat it as tenths of a pixel - * for historical compatibility. + * Pointsize in tenths of a point, but treat it as tenths of a pixel for + * historical compatibility. */ faPtr->size = 12; @@ -3422,7 +3547,7 @@ TkFontParseXLFD(string, faPtr, xaPtr) } /* - * Pixel height of font. If specified, overrides pointsize. + * Pixel height of font. If specified, overrides pointsize. */ if (FieldSpecified(field[XLFD_PIXEL_SIZE])) { @@ -3432,9 +3557,9 @@ TkFontParseXLFD(string, faPtr, xaPtr) * * [ N1 N2 N3 N4 ] * - * where N1 is the pixel size, and where N2, N3, and N4 - * are some additional numbers that I don't know - * the purpose of, so I ignore them. + * where N1 is the pixel size, and where N2, N3, and N4 are some + * additional numbers that I don't know the purpose of, so I + * ignore them. */ faPtr->size = atoi(field[XLFD_PIXEL_SIZE] + 1); @@ -3468,12 +3593,12 @@ TkFontParseXLFD(string, faPtr, xaPtr) * * FieldSpecified -- * - * Helper function for TkParseXLFD(). Determines if a field in the - * XLFD was set to a non-null, non-don't-care value. + * Helper function for TkParseXLFD(). Determines if a field in the XLFD + * was set to a non-null, non-don't-care value. * * Results: - * The return value is 0 if the field in the XLFD was not set and - * should be ignored, non-zero otherwise. + * The return value is 0 if the field in the XLFD was not set and should + * be ignored, non-zero otherwise. * * Side effects: * None. @@ -3482,11 +3607,12 @@ TkFontParseXLFD(string, faPtr, xaPtr) */ static int -FieldSpecified(field) - CONST char *field; /* The field of the XLFD to check. Strictly - * speaking, only when the string is "*" does it mean - * don't-care. However, an unspecified or question - * mark is also interpreted as don't-care. */ +FieldSpecified( + const char *field) /* The field of the XLFD to check. Strictly + * speaking, only when the string is "*" does + * it mean don't-care. However, an unspecified + * or question mark is also interpreted as + * don't-care. */ { char ch; @@ -3513,11 +3639,11 @@ FieldSpecified(field) * *--------------------------------------------------------------------------- */ - + int -TkFontGetPixels(tkwin, size) - Tk_Window tkwin; /* For point->pixel conversion factor. */ - int size; /* Font size. */ +TkFontGetPixels( + Tk_Window tkwin, /* For point->pixel conversion factor. */ + int size) /* Font size. */ { double d; @@ -3547,11 +3673,11 @@ TkFontGetPixels(tkwin, size) * *--------------------------------------------------------------------------- */ - + int -TkFontGetPoints(tkwin, size) - Tk_Window tkwin; /* For pixel->point conversion factor. */ - int size; /* Font size. */ +TkFontGetPoints( + Tk_Window tkwin, /* For pixel->point conversion factor. */ + int size) /* Font size. */ { double d; @@ -3570,24 +3696,24 @@ TkFontGetPoints(tkwin, size) * * TkFontGetAliasList -- * - * Given a font name, find the list of all aliases for that font - * name. One of the names in this list will probably be the name - * that this platform expects when asking for the font. + * Given a font name, find the list of all aliases for that font name. + * One of the names in this list will probably be the name that this + * platform expects when asking for the font. * * Results: - * As above. The return value is NULL if the font name has no - * aliases. + + * As above. The return value is NULL if the font name has no aliases. * * Side effects: * None. * *------------------------------------------------------------------------- */ - + char ** -TkFontGetAliasList(faceName) - CONST char *faceName; /* Font name to test for aliases. */ -{ +TkFontGetAliasList( + const char *faceName) /* Font name to test for aliases. */ +{ int i, j; for (i = 0; fontAliases[i] != NULL; i++) { @@ -3605,9 +3731,8 @@ TkFontGetAliasList(faceName) * * TkFontGetFallbacks -- * - * Get the list of font fallbacks that the platform-specific code - * can use to try to find the closest matching font the name - * requested. + * Get the list of font fallbacks that the platform-specific code can use + * to try to find the closest matching font the name requested. * * Results: * As above. @@ -3617,9 +3742,9 @@ TkFontGetAliasList(faceName) * *------------------------------------------------------------------------- */ - + char *** -TkFontGetFallbacks() +TkFontGetFallbacks(void) { return fontFallbacks; } @@ -3642,9 +3767,9 @@ TkFontGetFallbacks() * *------------------------------------------------------------------------- */ - + char ** -TkFontGetGlobalClass() +TkFontGetGlobalClass(void) { return globalFontClass; } @@ -3654,8 +3779,8 @@ TkFontGetGlobalClass() * * TkFontGetSymbolClass -- * - * Get the list of fonts that are symbolic; used if the operating - * system cannot apriori identify symbolic fonts on its own. + * Get the list of fonts that are symbolic; used if the operating system + * cannot apriori identify symbolic fonts on its own. * * Results: * As above. @@ -3665,9 +3790,9 @@ TkFontGetGlobalClass() * *------------------------------------------------------------------------- */ - + char ** -TkFontGetSymbolClass() +TkFontGetSymbolClass(void) { return symbolClass; } @@ -3677,13 +3802,12 @@ TkFontGetSymbolClass() * * TkDebugFont -- * - * This procedure returns debugging information about a font. + * This function returns debugging information about a font. * * Results: * The return value is a list with one sublist for each TkFont - * corresponding to "name". Each sublist has two elements that - * contain the resourceRefCount and objRefCount fields from the - * TkFont structure. + * corresponding to "name". Each sublist has two elements that contain + * the resourceRefCount and objRefCount fields from the TkFont structure. * * Side effects: * None. @@ -3692,10 +3816,10 @@ TkFontGetSymbolClass() */ Tcl_Obj * -TkDebugFont(tkwin, name) - Tk_Window tkwin; /* The window in which the font will be - * used (not currently used). */ - char *name; /* Name of the desired color. */ +TkDebugFont( + Tk_Window tkwin, /* The window in which the font will be used + * (not currently used). */ + char *name) /* Name of the desired color. */ { TkFont *fontPtr; Tcl_HashEntry *hashPtr; @@ -3707,14 +3831,14 @@ TkDebugFont(tkwin, name) if (hashPtr != NULL) { fontPtr = (TkFont *) Tcl_GetHashValue(hashPtr); if (fontPtr == NULL) { - panic("TkDebugFont found empty hash table entry"); + Tcl_Panic("TkDebugFont found empty hash table entry"); } for ( ; (fontPtr != NULL); fontPtr = fontPtr->nextPtr) { objPtr = Tcl_NewObj(); Tcl_ListObjAppendElement(NULL, objPtr, Tcl_NewIntObj(fontPtr->resourceRefCount)); Tcl_ListObjAppendElement(NULL, objPtr, - Tcl_NewIntObj(fontPtr->objRefCount)); + Tcl_NewIntObj(fontPtr->objRefCount)); Tcl_ListObjAppendElement(NULL, resultPtr, objPtr); } } @@ -3726,13 +3850,13 @@ TkDebugFont(tkwin, name) * * TkFontGetFirstTextLayout -- * - * This procedure returns the first chunk of a Tk_TextLayout, - * i.e. until the first font change on the first line (or the - * whole first line if there is no such font change). + * This function returns the first chunk of a Tk_TextLayout, i.e. until + * the first font change on the first line (or the whole first line if + * there is no such font change). * * Results: - * The return value is the byte length of the chunk, the chunk - * itself is copied into dst and its Tk_Font into font. + * The return value is the byte length of the chunk, the chunk itself is + * copied into dst and its Tk_Font into font. * * Side effects: * None. @@ -3742,21 +3866,20 @@ TkDebugFont(tkwin, name) int TkFontGetFirstTextLayout( - Tk_TextLayout layout, /* Layout information, from a previous call - * to Tk_ComputeTextLayout(). */ - Tk_Font * font, - char * dst) + Tk_TextLayout layout, /* Layout information, from a previous call to + * Tk_ComputeTextLayout(). */ + Tk_Font *font, + char *dst) { - TextLayout *layoutPtr; + TextLayout *layoutPtr; LayoutChunk *chunkPtr; int numBytesInChunk; layoutPtr = (TextLayout *)layout; - if ((layoutPtr==NULL) - || (layoutPtr->numChunks==0) - || (layoutPtr->chunks->numDisplayChars <= 0)) { - dst[0] = '\0'; - return 0; + if ((layoutPtr==NULL) || (layoutPtr->numChunks==0) + || (layoutPtr->chunks->numDisplayChars <= 0)) { + dst[0] = '\0'; + return 0; } chunkPtr = layoutPtr->chunks; numBytesInChunk = chunkPtr->numBytes; @@ -3764,3 +3887,11 @@ TkFontGetFirstTextLayout( *font = layoutPtr->tkfont; return numBytesInChunk; } + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ |