summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXFont.c
diff options
context:
space:
mode:
authordas <das>2007-04-29 02:26:47 (GMT)
committerdas <das>2007-04-29 02:26:47 (GMT)
commit9ba316b391173927a31b4ab7207dd5775e525448 (patch)
treed8296fa62af852c5f2e743159973d854366b69fa /macosx/tkMacOSXFont.c
parenta509e51da0d9070869060f9af35e97c86d48dabd (diff)
downloadtk-9ba316b391173927a31b4ab7207dd5775e525448.zip
tk-9ba316b391173927a31b4ab7207dd5775e525448.tar.gz
tk-9ba316b391173927a31b4ab7207dd5775e525448.tar.bz2
* macosx/tkMacOSXCarbonEvents.c: add window event target carbon event
* macosx/tkMacOSXEvent.c: handler for all kEventClassWindow and * macosx/tkMacOSXEvent.h: kEventClassMouse events; move all * macosx/tkMacOSXNotify.c: remaining events except for * macosx/tkMacOSXWindowEvent.c: kEventClassKeyboard from dispatcher to application event handler; pass event handler callRef downstream; fix debug event tracing; process all tcl event types in carbon event timer; delay carbon event timer first fire; add TkMacOSXTrackingLoop() to mark enter/exit of event tracking loop during which all tcl events but only carbon update events should be processed by the timer (replaces various calls to Tcl_SetServiceMode()); rename TkMacOSXReceiveAndProcessEvent() to TkMacOSXReceiveAndDispatchEvent(), move it from tkMacOSXEvent.c to tkMacOSXCarbonEvents.c and modify it to dequeue only update events during a tracking loop; add TkMacOSXRunTclEventLoop() to standardize the various ways in use to run the tcl event loop; add handling of kEventClassAppearance events (for ScrollBarVariantChanged event). * macosx/tkMacOSXDialog.c: use new TkMacOSXTrackingLoop() around * macosx/tkMacOSXEvent.c: blocking API that puts up modal dialogs * macosx/tkMacOSXMenu.c: or when entering/exiting menu/control * macosx/tkMacOSXMouseEvent.c: tracking, window dragging and other * macosx/tkMacOSXScale.c: mouse tracking loops. * macosx/tkMacOSXScrlbr.c: * macosx/tkMacOSXWindowEvent.c: * macosx/tkMacOSXWm.c: * macosx/tkMacOSXDialog.c: use new TkMacOSXRunTclEventLoop() * macosx/tkMacOSXScale.c: instead of Tcl_DoOneEvent(), * macosx/tkMacOSXScrlbr.c: Tcl_ServiceAll(), TclServiceIdle() * macosx/tkMacOSXWindowEvent.c: and Tcl_GlobalEval("update idletasks"). * macosx/tkMacOSXColor.c: make available as Tk system colors all * macosx/tkMacOSXPort.h: appearance manager brushes, text colors and backgrounds with new and legacy names, as well as the fully transparent color "systemTransparent"; add TkMacOSXSetColorIn{Port,Context}() to directly set an X pixel color value in the current QD port resp. the given CG context without requiring passage through rgb representation (lossy for most system colors); modernize/remove Classic-era code; replace crufty strcmp() elseifs by Tcl_GetIndexFromObjStruct(). * macosx/tkMacOSXButton.c: use new TkMacOSXSetColorInPort() * macosx/tkMacOSXDraw.c: instead of setting rgb color directly * macosx/tkMacOSXMenubutton.c: to allow for non-rgb system colors. * macosx/tkMacOSXCursor.c: implement "none" cursor as on other platforms [Patch 1615427]; add all missing appearance manager cursors. * macosx/tkMacOSXDefault.h: set SELECT_FG_COLORs to None to match aqua L&F; use standard system color names; use new 'menu' system font; correct default scrollbar width. * macosx/tkMacOSXDraw.c: standardize initialization, use and * macosx/tkMacOSXInt.h: emptying of various static temp rgns * macosx/tkMacOSXRegion.c: onto two global RgnHandles; in debug * macosx/tkMacOSXSubwindows.c: builds, verify emptiness of these temp * macosx/tkMacOSXWindowEvent.c: rgns before use. * macosx/tkMacOSXDraw.c: add TkMacOSX{Setup,Restore}DrawingContext() to * macosx/tkMacOSXInt.h: abstract common setup & teardown of drawing environment (for both CG and QD); save/restore QD theme drawing state; handle GC clip region; add TkpClipDrawableToRect() to allow clipped drawing into drawable regardless of GC used; use new system color "systemWindowHeaderBackground" to setup background in themed toplevels; correct implementation of TkMacOSXMakeStippleMap(). * macosx/tkMacOSXEntry.c: use new TkMacOSXSetupDrawingContext() and * macosx/tkMacOSXFont.c: TkMacOSXRestoreDrawingContext() instead of various setup/teardown procs like TkMacOSX{SetUp,Release}CGContext(), TkMacOSXQuarz{Start,End}Draw(), TkMacOSXSetUpGraphicsPort() etc. * macosx/tkMacOSXEmbed.c: add CG context and drawable clip rgn fields * macosx/tkMacOSXInt.h: to MacDrawable struct. * macosx/tkMacOSXSubwindows.c: * macosx/tkMacOSXDialog.c: make -parent option of tk_getOpenFile et al. use the sheet version of NavServices dialogs; ensure native parent win exists before using StandardSheet API for tk_messageBox [Bug 1677611]; force sheets to behave like app-modal dialogs via WindowModality() API; use more modern ColorPicker API. * macosx/tkAboutDlg.r: use themed movable modal dialog, fix (c) year. * macosx/tkMacOSXEntry.c: take xOff/yOff of MacDrawable into account when computing locations/bounds to ensure correct posititioning when not drawing into intermediate pixmap. * macosx/tkMacOSXFont.c: use appearance manager API to map system font * macosx/tkMacOSXFont.h: names to TkFonts; add "menu" system font for menu item text drawing from MDEF; disable broken QD stippling. * macosx/tkMacOSXMenu.c: large-scale rewrite of custom * macosx/tkMacOSXMenu.r (removed): MDEF and related code that * unix/Makefile.in: restores many longtime-MIA features to working order (e.g. images, custom colors & fonts in menus etc); implement compound menu items; use Appearance Mgr and ThemeText APIs to mimic native MDEF as closely as possible when default "menu" system font is used; remove now obsolete SICN drawing code and resources. * macosx/tkMacOSXCarbonEvents.c: handle additional menu carbon events * macosx/tkMacOSXEvent.c: in order to support <<MenuSelect>> in * macosx/tkMacOSXMenu.c: the menubar and in menus that are not * macosx/tkMacOSXMenus.c: using the custom MDEF [Bug 1620826]; fix early and missing clearing of current Tk active menu entry; fix extraneous sending of <<MenuSelect>> during active menu entry clearing. * macosx/tkMacOSXMouseEvent.c: add support for async window dragging by the window server; set the corresponding window attribute by default. * macosx/tkMacOSXMouseEvent.c: rationalized handling order of non-mousedown events; add TkMacOSXModifierState() to retrieve the current key modifiers in carbon format. * macosx/tkMacOSXScrlbr.c: use appearance manager API to retrieve scrollbar component metrics; add awareness of multiple possibilites for scrollbar arrow position in aqua and handle user changes to arrow position pref; handle difference in metrics of small & large scrollbar variants; handle aqua "jump to here" scrollbar behaviour; correct computation of scroll view size and position; enforce min scrollbar height to avoid scrollbar component overlap; erase scrollbar area outside of standard width; remove broken auto-adjust code; account for window class when leaving space for grow box; remove code to manually draw grow box; use modern API for thumb scroll proc; replace HiliteControl() by modern API; replace control mgr constants with appearance mgr equivalents. * macosx/tkMacOSXSubwindows.c: use SetWindowBounds() API instead of SizeWindow(); invalidate clip regions after X{Map,Unmap}Window as fix for [Bug 940117] made them dependent on mapping state; remove unneeded calls to TkMacOSXInvalClipRgns() and unnecessary setting of QD port; use native-endian pixmap on intel; remove obsolete pixmap pix locking. * macosx/tkMacOSXWindowEvent.c: handle only the first of a batch of kEventAppAvailableWindowBoundsChanged events sent per transaction; handle kEventWindowBoundsChanged event to support live window resizing and centralized sending of location/size changed ConfigureNotify events; ensure HIGrowBox is redrawn after bounds change; constrain window after dragging to ensure titlebar is not inacessible offscreen or under dock/menubar; handle kEventWindowGetRegion and kEventWindowDrawContent for transparent windows to mark resp. paint content region as transparent; handle kEventWindowConstrain for fullscreen windows to ensure bounds match new screen size; enter/exit fullscreen UIMode upon activation/deactivation of fullscreen window. * macosx/tkMacOSXWm.c: use live-resize and async-drag carbon window * macosx/tkMacOSXWm.h: attributes for toplevels by default; implement new [wm attributes] -topmost, -transparent and -fullscreen; refactor WmAttributesCmd() parallelling the tkUnixWm.c implementation, use thus factored proc to set proxy icon from [wm iconbitmap]; dynamically determine default values for toplevel min and max sizes (similar to tkWinWm.c impl): min sizes depend on window class & attributes to ensure visibility of all titlebar widgets and grow box, max sizes depend on maximal window bounds for all active displays; factor out code that puts into effect changes to master or override_redirect; use RepositionWindow() API to determine staggered initial window bounds; correct resize limit calculations, handle gridding and use modern resize API in TkMacOSXGrowToplevel(); remove sending of ConfigureNotify after resize or zoom (now handled by BoundsChanged handler); correct composite carbon window attribute handling, remove currently unusable attributes and add new attributes in [tk::unsupported::MacWindowStyle]; ensure validity of window class and attributes before use; apply changes to window class when handling carbon window attribute changes (if HIWindowChangeClass() API available); add debug build warning message when deprecated window style is used instead of window class; use transparent HIGrowBox for resizable windows; avoid unnecessary calls to window structure width API; use tcl time API in TkpGetMS(); add TkMacOSXEnterExitFullscreen() to enter/exit UIMode with dock and menubar hidden; restrict wmTracing output to debug builds; remove unneeded calls to TkMacOSXInvalClipRgns() and unnecessary setting of QD port; workaround GetWindowStructureWidths() Carbon bug (bogus results for never-mapped floating windows). * macosx/tkMacOSXXStubs.c (TkMacOSXDisplayChanged): add maximal window bounds field to Screen record (in ext_data), computed as the union of available window positioning bounds of all graphics devices (displays). * macosx/tkMacOSXBitmap.c: fix macRoman encoding leak. * macosx/tkMacOSXCursor.c: * macosx/tkMacOSXDebug.c (TkMacOSXCarbonEventToAscii): use static * macosx/tkMacOSXDebug.h: buffer to simplify callers; const fixes. * macosx/tkMacOSXBitmap.c: use more efficient QDSwapPort() instead of * macosx/tkMacOSXButton.c: GetPort()/SetPort()/GetGWorld()/SetGWorld(). * macosx/tkMacOSXDraw.c: * macosx/tkMacOSXFont.c: * macosx/tkMacOSXMenubutton.c: * macosx/tkMacOSXScale.c: * macosx/tkMacOSXScrlbr.c: * macosx/tkMacOSXXStubs.c: * macosx/tkMacOSXColor.c: use kHIToolboxVersionNumber for runtime OS * macosx/tkMacOSXEntry.c: version check rather than Gestalt() etc. * macosx/tkMacOSXInt.h: * macosx/tkMacOSXWm.c: * macosx/tkMacOSXDraw.c: remove obsolete and now incorrect * macosx/tkMacOSXInt.h: tkMenuCascadeRgn clipping code. * macosx/tkMacOSXMenu.c: * macosx/tkMacOSXHLEvents.c: replace Tcl_GlobalEval() resp. Tcl_Eval() * macosx/tkMacOSXScrlbr.c: by Tcl_EvalEx(). * macosx/tkMacOSXInit.c: * macosx/tkMacOSXInit.c (TkpInit): reorder initialization steps. * macosx/tkMacOSXKeyEvent.c: remove pre-10.2 support. * macosx/tkMacOSXMenus.c: remove now useless call to TkMacOSXHandleTearoffMenu(); use \x.. quoting for non-latin1 macroman literar chars to allow file to be edited as utf-8. * macosx/tkMacOSXScale.c: replace TrackControl() by modern * macosx/tkMacOSXScrlbr.c: HandleControlClick() API (using new TkMacOSXModifierState()). * macosx/tkMacOSXInt.h: move all constant #defines needed to * macosx/tkMacOSXColor.c: support building on older OS X releases * macosx/tkMacOSXEvent.h: to a central location in tkMacOSXInt.h. * macosx/tkMacOSXFont.c: * macosx/tkMacOSXMenu.c: * macosx/tkMacOSXMenubutton.c: * macosx/tkMacOSXMenus.c: * macosx/tkMacOSXMouseEvent.c: * macosx/tkMacOSXWm.c: * macosx/tkMacOSXInt.h: add ChkErr() macro to factor out * macosx/tkMacOSXButton.c: Carbon OSStatus return value checking * macosx/tkMacOSXCarbonEvents.c: and TkMacOSXDbgMsg() macro to factour * macosx/tkMacOSXClipboard.c: out debug message output; use these * macosx/tkMacOSXColor.c: macros to replace #ifdef TK_MAC_DEBUG * macosx/tkMacOSXCursor.c: blocks & direct printing to stderr, * macosx/tkMacOSXDebug.c: and to do additional OSStatus return * macosx/tkMacOSXDialog.c: checking, and to standardize OSStatus * macosx/tkMacOSXDraw.c: usage. * macosx/tkMacOSXEntry.c: * macosx/tkMacOSXEvent.c: * macosx/tkMacOSXFont.c: * macosx/tkMacOSXHLEvents.c: * macosx/tkMacOSXInit.c: * macosx/tkMacOSXKeyEvent.c: * macosx/tkMacOSXMenu.c: * macosx/tkMacOSXMenubutton.c: * macosx/tkMacOSXMenus.c: * macosx/tkMacOSXMouseEvent.c: * macosx/tkMacOSXScrlbr.c: * macosx/tkMacOSXSubwindows.c: * macosx/tkMacOSXWindowEvent.c: * macosx/tkMacOSXWm.c: * macosx/tkMacOSXXStubs.c: * macosx/tkMacOSXSend.c: remove duplicate/unused declarations. * macosx/tkMacOSXXStubs.c: * macosx/tkMacOSXDebug.c: const fixes. * macosx/tkMacOSXInit.c: * macosx/tkMacOSXTest.c: * macosx/tkMacOSXWm.c: * macosx/tkMacOSXXStubs.c: * macosx/Wish-Info.plist.in: add tcl document extensions/mime types and LSMinimumSystemVersion, LSRequiresCarbon & NSAppleScriptEnabled keys. * macosx/tkMacOSXAETE.r: fix whitespace. * macosx/tkMacOSXConfig.c: * macosx/tkMacOSXCursors.r: * macosx/tkMacOSXKeyboard.c: * macosx/tkMacOSXSend.c: * macosx/tkMacOSXXCursors.r: * macosx/README: * macosx/Makefile: fix/add copyright and license refs. * macosx/Tk-Info.plist.in: * macosx/Wish-Info.plist.in: * macosx/tkMacOSX.h:
Diffstat (limited to 'macosx/tkMacOSXFont.c')
-rw-r--r--macosx/tkMacOSXFont.c2453
1 files changed, 1200 insertions, 1253 deletions
diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c
index 45da327..2cd3dda 100644
--- a/macosx/tkMacOSXFont.c
+++ b/macosx/tkMacOSXFont.c
@@ -1,17 +1,18 @@
/*
* tkMacOSXFont.c --
*
- * Contains the Macintosh implementation of the platform-independant
- * font package interface.
+ * Contains the Macintosh implementation of the platform-independant
+ * font package interface.
*
* Copyright (c) 1990-1994 The Regents of the University of California.
* Copyright (c) 1994-1997 Sun Microsystems, Inc.
* Copyright 2001, Apple Computer, Inc.
+ * Copyright (c) 2006-2007 Daniel A. Steffen <das@users.sourceforge.net>
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXFont.c,v 1.3.2.8 2006/03/28 02:44:13 das Exp $
+ * RCS: @(#) $Id: tkMacOSXFont.c,v 1.3.2.9 2007/04/29 02:26:49 das Exp $
*/
#include "tkMacOSXInt.h"
@@ -20,8 +21,7 @@
#include "tclInt.h" /* for Tcl_CreateNamespace() */
/*
- * For doing things with Mac strings and Fixed numbers. This probably should move
- * the mac header file.
+ * Dealing with pascal strings.
*/
#ifndef StrLength
@@ -33,76 +33,71 @@
#define pstrcmp(s1, s2) RelString((s1), (s2), 1, 1)
#define pstrcasecmp(s1, s2) RelString((s1), (s2), 0, 1)
-#ifndef Fixed2Int
-#define Fixed2Int(f) ((f) >> 16)
-#define Int2Fixed(i) ((i) << 16)
-#endif
-
/*
* The preferred font encodings.
*/
-static CONST char *encodingList[] = {
+static const char *encodingList[] = {
"macRoman", "macJapan", NULL
};
/*
- * The following structures are used to map the script/language codes of a
+ * The following structures are used to map the script/language codes of a
* font to the name that should be passed to Tcl_GetTextEncoding() to obtain
- * the encoding for that font. The set of numeric constants is fixed and
+ * the encoding for that font. The set of numeric constants is fixed and
* defined by Apple.
*/
-
+
static TkStateMap scriptMap[] = {
- {smRoman, "macRoman"},
- {smJapanese, "macJapan"},
- {smTradChinese, "macChinese"},
- {smKorean, "macKorean"},
- {smArabic, "macArabic"},
- {smHebrew, "macHebrew"},
- {smGreek, "macGreek"},
- {smCyrillic, "macCyrillic"},
- {smRSymbol, "macRSymbol"},
- {smDevanagari, "macDevanagari"},
- {smGurmukhi, "macGurmukhi"},
- {smGujarati, "macGujarati"},
- {smOriya, "macOriya"},
- {smBengali, "macBengali"},
- {smTamil, "macTamil"},
- {smTelugu, "macTelugu"},
- {smKannada, "macKannada"},
- {smMalayalam, "macMalayalam"},
- {smSinhalese, "macSinhalese"},
- {smBurmese, "macBurmese"},
- {smKhmer, "macKhmer"},
- {smThai, "macThailand"},
- {smLaotian, "macLaos"},
- {smGeorgian, "macGeorgia"},
- {smArmenian, "macArmenia"},
- {smSimpChinese, "macSimpChinese"},
- {smTibetan, "macTIbet"},
- {smMongolian, "macMongolia"},
- {smGeez, "macEthiopia"},
- {smEastEurRoman, "macCentEuro"},
- {smVietnamese, "macVietnam"},
- {smExtArabic, "macSindhi"},
- {0, NULL}
-};
+ {smRoman, "macRoman"},
+ {smJapanese, "macJapan"},
+ {smTradChinese, "macChinese"},
+ {smKorean, "macKorean"},
+ {smArabic, "macArabic"},
+ {smHebrew, "macHebrew"},
+ {smGreek, "macGreek"},
+ {smCyrillic, "macCyrillic"},
+ {smRSymbol, "macRSymbol"},
+ {smDevanagari, "macDevanagari"},
+ {smGurmukhi, "macGurmukhi"},
+ {smGujarati, "macGujarati"},
+ {smOriya, "macOriya"},
+ {smBengali, "macBengali"},
+ {smTamil, "macTamil"},
+ {smTelugu, "macTelugu"},
+ {smKannada, "macKannada"},
+ {smMalayalam, "macMalayalam"},
+ {smSinhalese, "macSinhalese"},
+ {smBurmese, "macBurmese"},
+ {smKhmer, "macKhmer"},
+ {smThai, "macThailand"},
+ {smLaotian, "macLaos"},
+ {smGeorgian, "macGeorgia"},
+ {smArmenian, "macArmenia"},
+ {smSimpChinese, "macSimpChinese"},
+ {smTibetan, "macTIbet"},
+ {smMongolian, "macMongolia"},
+ {smGeez, "macEthiopia"},
+ {smEastEurRoman, "macCentEuro"},
+ {smVietnamese, "macVietnam"},
+ {smExtArabic, "macSindhi"},
+ {0, NULL}
+};
static TkStateMap romanMap[] = {
- {langCroatian, "macCroatian"},
- {langSlovenian, "macCroatian"},
- {langIcelandic, "macIceland"},
- {langRomanian, "macRomania"},
- {langTurkish, "macTurkish"},
- {langGreek, "macGreek"},
- {0, NULL}
+ {langCroatian, "macCroatian"},
+ {langSlovenian, "macCroatian"},
+ {langIcelandic, "macIceland"},
+ {langRomanian, "macRomania"},
+ {langTurkish, "macTurkish"},
+ {langGreek, "macGreek"},
+ {0, NULL}
};
static TkStateMap cyrillicMap[] = {
- {langUkrainian, "macUkraine"},
- {langBulgarian, "macBulgaria"},
- {0, NULL}
+ {langUkrainian, "macUkraine"},
+ {langBulgarian, "macBulgaria"},
+ {0, NULL}
};
/*
@@ -117,47 +112,47 @@ static TkStateMap cyrillicMap[] = {
*/
-#define FONTMAP_SHIFT 10
+#define FONTMAP_SHIFT 10
-#define FONTMAP_PAGES (1 << (sizeof(Tcl_UniChar) * 8 - FONTMAP_SHIFT))
-#define FONTMAP_BITSPERPAGE (1 << FONTMAP_SHIFT)
+#define FONTMAP_PAGES (1 << (sizeof(Tcl_UniChar) * 8 - FONTMAP_SHIFT))
+#define FONTMAP_BITSPERPAGE (1 << FONTMAP_SHIFT)
typedef struct FontFamily {
- struct FontFamily *nextPtr; /* Next in list of all known font families. */
- int refCount; /* How many SubFonts are referring to this
- * FontFamily. When the refCount drops to
- * zero, this FontFamily may be freed. */
+ struct FontFamily *nextPtr; /* Next in list of all known font families. */
+ int refCount; /* How many SubFonts are referring to this
+ * FontFamily. When the refCount drops to
+ * zero, this FontFamily may be freed. */
/*
* Key.
*/
- FMFontFamily faceNum; /* Unique face number key for this FontFamily. */
-
+ FMFontFamily faceNum; /* Unique face number key for this FontFamily. */
+
/*
* Derived properties.
*/
-
- Tcl_Encoding encoding; /* Encoding for this font family. */
- int isSymbolFont; /* Non-zero if this is a symbol family. */
- int isMultiByteFont; /* Non-zero if this is a multi-byte family. */
- char typeTable[256]; /* Table that identfies all lead bytes for a
- * multi-byte family, used when measuring chars.
- * If a byte is a lead byte, the value at the
- * corresponding position in the typeTable is 1,
- * otherwise 0. If this is a single-byte font,
- * all entries are 0. */
+
+ Tcl_Encoding encoding; /* Encoding for this font family. */
+ int isSymbolFont; /* Non-zero if this is a symbol family. */
+ int isMultiByteFont; /* Non-zero if this is a multi-byte family. */
+ char typeTable[256]; /* Table that identfies all lead bytes for a
+ * multi-byte family, used when measuring chars.
+ * If a byte is a lead byte, the value at the
+ * corresponding position in the typeTable is 1,
+ * otherwise 0. If this is a single-byte font,
+ * all entries are 0. */
char *fontMap[FONTMAP_PAGES];
- /* Two-level sparse table used to determine
- * quickly if the specified character exists.
- * As characters are encountered, more pages
- * in this table are dynamically added. The
- * contents of each page is a bitmask
- * consisting of FONTMAP_BITSPERPAGE bits,
- * representing whether this font can be used
- * to display the given character at the
- * corresponding bit position. The high bits
- * of the character are used to pick which
- * page of the table is used. */
+ /* Two-level sparse table used to determine
+ * quickly if the specified character exists.
+ * As characters are encountered, more pages
+ * in this table are dynamically added. The
+ * contents of each page is a bitmask
+ * consisting of FONTMAP_BITSPERPAGE bits,
+ * representing whether this font can be used
+ * to display the given character at the
+ * corresponding bit position. The high bits
+ * of the character are used to pick which
+ * page of the table is used. */
} FontFamily;
/*
@@ -167,9 +162,9 @@ typedef struct FontFamily {
*/
typedef struct SubFont {
- char **fontMap; /* Pointer to font map from the FontFamily,
- * cached here to save a dereference. */
- FontFamily *familyPtr; /* The FontFamily for this SubFont. */
+ char **fontMap; /* Pointer to font map from the FontFamily,
+ * cached here to save a dereference. */
+ FontFamily *familyPtr; /* The FontFamily for this SubFont. */
} SubFont;
/*
@@ -177,45 +172,45 @@ typedef struct SubFont {
* object.
*/
-#define SUBFONT_SPACE 3
+#define SUBFONT_SPACE 3
typedef struct MacFont {
- TkFont font; /* Stuff used by generic font package. Must
- * be first in structure. */
+ TkFont font; /* Stuff used by generic font package. Must
+ * be first in structure. */
SubFont staticSubFonts[SUBFONT_SPACE];
- /* Builtin space for a limited number of
- * SubFonts. */
- int numSubFonts; /* Length of following array. */
- SubFont *subFontArray; /* Array of SubFonts that have been loaded
- * in order to draw/measure all the characters
- * encountered by this font so far. All fonts
- * start off with one SubFont initialized by
- * AllocFont() from the original set of font
- * attributes. Usually points to
- * staticSubFonts, but may point to malloced
- * space if there are lots of SubFonts. */
-
- short size; /* Font size in pixels, constructed from
- * font attributes. */
- short style; /* Style bits, constructed from font
- * attributes. */
+ /* Builtin space for a limited number of
+ * SubFonts. */
+ int numSubFonts; /* Length of following array. */
+ SubFont *subFontArray; /* Array of SubFonts that have been loaded
+ * in order to draw/measure all the characters
+ * encountered by this font so far. All fonts
+ * start off with one SubFont initialized by
+ * AllocFont() from the original set of font
+ * attributes. Usually points to
+ * staticSubFonts, but may point to malloced
+ * space if there are lots of SubFonts. */
+
+ short size; /* Font size in pixels, constructed from
+ * font attributes. */
+ short style; /* Style bits, constructed from font
+ * attributes. */
} MacFont;
/*
* The following structure is used to map between the UTF-8 name for a font and
* the name that the Macintosh uses to refer to the font, in order to determine
- * if a font exists. The Macintosh names for fonts are stored in the encoding
+ * if a font exists. The Macintosh names for fonts are stored in the encoding
* of the font itself.
*/
-
+
typedef struct FontNameMap {
- Tk_Uid utfName; /* The name of the font in UTF-8. */
- StringPtr nativeName; /* The name of the font in the font's encoding. */
- FMFontFamily faceNum; /* Unique face number for this font. */
+ Tk_Uid utfName; /* The name of the font in UTF-8. */
+ StringPtr nativeName; /* The name of the font in the font's encoding. */
+ FMFontFamily faceNum; /* Unique face number for this font. */
} FontNameMap;
/*
- * The list of font families that are currently loaded. As screen fonts
+ * The list of font families that are currently loaded. As screen fonts
* are loaded, this list grows to hold information about what characters
* exist in each font family.
*/
@@ -225,299 +220,357 @@ static FontFamily *fontFamilyList = NULL;
/*
* Information cached about the system at startup time.
*/
-
+
static FontNameMap *gFontNameMap = NULL;
static GWorldPtr gWorld = NULL;
/*
+ * The names for our "native" fonts.
+ */
+
+#define SYSTEMFONT_NAME "system"
+#define APPLFONT_NAME "application"
+#define MENUITEMFONT_NAME "menu"
+
+/*
* Procedures used only in this file.
*/
-static FontFamily * AllocFontFamily(CONST MacFont *fontPtr, int family);
-static SubFont * CanUseFallback(MacFont *fontPtr, CONST char *fallbackName, int ch, SubFont **fixSubFontPtrPtr);
-static SubFont * CanUseFallbackWithAliases(MacFont *fontPtr, CONST char *faceName, int ch, Tcl_DString *nameTriedPtr, SubFont **fixSubFontPtrPtr);
+static FontFamily * AllocFontFamily(const MacFont *fontPtr, int family);
+static SubFont * CanUseFallback(MacFont *fontPtr, const char *fallbackName, int ch, SubFont **fixSubFontPtrPtr);
+static SubFont * CanUseFallbackWithAliases(MacFont *fontPtr, const char *faceName, int ch, Tcl_DString *nameTriedPtr, SubFont **fixSubFontPtrPtr);
static SubFont * FindSubFontForChar(MacFont *fontPtr, int ch, SubFont **fixSubFontPtrPtr);
static void FontMapInsert(SubFont *subFontPtr, int ch);
static void FontMapLoadPage(SubFont *subFontPtr, int row);
static int FontMapLookup(SubFont *subFontPtr, int ch);
static void FreeFontFamily(FontFamily *familyPtr);
-static void InitFont(Tk_Window tkwin, int family, int size, int style, MacFont *fontPtr);
-static void InitSubFont(CONST MacFont *fontPtr, int family, SubFont *subFontPtr);
-static void MultiFontDrawText(MacFont *fontPtr, CONST char *source, int numBytes, int x, int y);
+static void InitFont(Tk_Window tkwin, int family, unsigned char *familyName, int size, int style, MacFont *fontPtr);
+static void InitSubFont(const MacFont *fontPtr, int family, SubFont *subFontPtr);
+static void MultiFontDrawText(MacFont *fontPtr, const char *source, int numBytes, int x, int y);
static void ReleaseFont(MacFont *fontPtr);
static void ReleaseSubFont(SubFont *subFontPtr);
-static int SeenName(CONST char *name, Tcl_DString *dsPtr);
+static int SeenName(const char *name, Tcl_DString *dsPtr);
-static CONST char * BreakLine(FontFamily *familyPtr, int flags, CONST char *source, int numBytes, int *widthPtr);
-static int GetFamilyNum(CONST char *faceName, short *familyPtr);
-static int GetFamilyOrAliasNum(CONST char *faceName, short *familyPtr);
+static const char * BreakLine(FontFamily *familyPtr, int flags, const char *source, int numBytes, int *widthPtr);
+static int GetFamilyNum(const char *faceName, short *familyPtr);
+static int GetFamilyOrAliasNum(const char *faceName, short *familyPtr);
static Tcl_Encoding GetFontEncoding(int faceNum, int allowSymbol, int *isSymbolPtr);
static Tk_Uid GetUtfFaceName(StringPtr faceNameStr);
+static OSStatus GetThemeFontAndFamily(const ThemeFontID themeFontId,
+ FMFontFamily* fontFamily, unsigned char *fontName, SInt16 *fontSize,
+ Style *fontStyle);
+
/*
*-------------------------------------------------------------------------
- *
+ *
* TkpFontPkgInit --
*
- * This procedure is called when an application is created. It
- * initializes all the structures that are used by the
- * platform-dependant code on a per application basis.
+ * This procedure is called when an application is created. It
+ * initializes all the structures that are used by the
+ * platform-dependant code on a per application basis.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * See comments below.
+ * See comments below.
*
*-------------------------------------------------------------------------
*/
void
-TkpFontPkgInit(mainPtr)
- TkMainInfo *mainPtr; /* The application being created. */
+TkpFontPkgInit(
+ TkMainInfo *mainPtr) /* The application being created. */
{
FMFontFamilyIterator fontFamilyIterator;
- FMFontFamily fontFamily;
+ FMFontFamily fontFamily;
FontNameMap *tmpFontNameMap, *newFontNameMap, *mapPtr;
int i, j, numFonts, fontMapOffset, isSymbol;
Str255 nativeName;
Tcl_DString ds;
Tcl_Encoding encoding;
Tcl_Encoding *encodings;
-
+
if (gWorld == NULL) {
- Rect rect = {0, 0, 1, 1};
- SetFractEnable(0);
- /*
- * Used for saving and restoring state while drawing and measuring.
- */
- if (NewGWorld(&gWorld, 0, &rect, NULL, NULL, 0) != noErr) {
- Tcl_Panic("TkpFontPkgInit: NewGWorld failed");
- }
- /*
- * The name of each font is stored in the encoding of that font.
- * How would we translate a name from UTF-8 into the native encoding
- * of the font unless we knew the encoding of that font? We can't.
- * So, precompute the UTF-8 and native names of all fonts on the
- * system. The when the user asks for font by its UTF-8 name, we
- * lookup the name in that table and really ask for the font by its
- * native name. Any unknown UTF-8 names will be mapped to the system
- * font.
- */
- FMCreateFontFamilyIterator (NULL, NULL, kFMDefaultOptions, &fontFamilyIterator);
- numFonts = 0;
- while (FMGetNextFontFamily(&fontFamilyIterator, &fontFamily) != kFMIterationCompleted) {
- numFonts++;
- }
- tmpFontNameMap = (FontNameMap *) ckalloc(sizeof(FontNameMap) * numFonts);
- encodings = (Tcl_Encoding *) ckalloc(sizeof(Tcl_Encoding) * numFonts);
- mapPtr = tmpFontNameMap;
- FMResetFontFamilyIterator(NULL, NULL, kFMDefaultOptions, &fontFamilyIterator);
- i = 0;
- while (FMGetNextFontFamily(&fontFamilyIterator, &fontFamily) != kFMIterationCompleted) {
- mapPtr->faceNum = fontFamily;
- encodings[i] = GetFontEncoding(mapPtr->faceNum, 0, &isSymbol);
- FMGetFontFamilyName(fontFamily, nativeName );
- Tcl_ExternalToUtfDString(encodings[i], StrBody(nativeName), StrLength(nativeName), &ds);
- mapPtr->utfName = Tk_GetUid(Tcl_DStringValue(&ds));
- mapPtr->nativeName = (StringPtr) ckalloc(StrLength(nativeName) + 1);
- memcpy(mapPtr->nativeName, nativeName, StrLength(nativeName) + 1);
- Tcl_DStringFree(&ds);
- mapPtr++;
- i++;
- }
- FMDisposeFontFamilyIterator (&fontFamilyIterator);
-
- /*
- * Reorder FontNameMap so fonts with the preferred encodings are at
- * the front of the list. The relative order of fonts that all have
- * the same encoding is preserved. Fonts with unknown encodings get
- * stuck at the end.
- */
- newFontNameMap = (FontNameMap *) ckalloc(sizeof(FontNameMap) * (numFonts + 1));
- fontMapOffset = 0;
- for (i = 0; encodingList[i] != NULL; i++) {
- encoding = Tcl_GetEncoding(NULL, encodingList[i]);
- if (encoding == NULL) {
- continue;
- }
- for (j = 0; j < numFonts; j++) {
- if (encodings[j] == encoding) {
- newFontNameMap[fontMapOffset] = tmpFontNameMap[j];
- fontMapOffset++;
- Tcl_FreeEncoding(encodings[j]);
- tmpFontNameMap[j].utfName = NULL;
- }
- }
- Tcl_FreeEncoding(encoding);
- }
- for (i = 0; i < numFonts; i++) {
- if (tmpFontNameMap[i].utfName != NULL) {
- newFontNameMap[fontMapOffset] = tmpFontNameMap[i];
- fontMapOffset++;
- Tcl_FreeEncoding(encodings[i]);
- }
- }
- if (fontMapOffset != numFonts) {
- Tcl_Panic("TkpFontPkgInit: unexpected number of fonts");
- }
-
- mapPtr = &newFontNameMap[numFonts];
- mapPtr->utfName = NULL;
- mapPtr->nativeName = NULL;
- mapPtr->faceNum = 0;
-
- ckfree((char *) tmpFontNameMap);
- ckfree((char *) encodings);
-
- gFontNameMap = newFontNameMap;
+ Rect rect = {0, 0, 1, 1};
+
+ SetFractEnable(0);
+ /*
+ * Used for saving and restoring state while drawing and measuring.
+ */
+ if (ChkErr(NewGWorld, &gWorld, 32, &rect, NULL, NULL, 0
+#ifdef __LITTLE_ENDIAN__
+ | kNativeEndianPixMap
+#endif
+ ) != noErr) {
+ Tcl_Panic("TkpFontPkgInit: NewGWorld failed");
+ }
+ /*
+ * The name of each font is stored in the encoding of that font.
+ * How would we translate a name from UTF-8 into the native encoding
+ * of the font unless we knew the encoding of that font? We can't.
+ * So, precompute the UTF-8 and native names of all fonts on the
+ * system. The when the user asks for font by its UTF-8 name, we
+ * lookup the name in that table and really ask for the font by its
+ * native name. Any unknown UTF-8 names will be mapped to the system
+ * font.
+ */
+ FMCreateFontFamilyIterator(NULL, NULL, kFMDefaultOptions, &fontFamilyIterator);
+ numFonts = 0;
+ while (FMGetNextFontFamily(&fontFamilyIterator, &fontFamily) != kFMIterationCompleted) {
+ numFonts++;
+ }
+ tmpFontNameMap = (FontNameMap *) ckalloc(sizeof(FontNameMap) * numFonts);
+ encodings = (Tcl_Encoding *) ckalloc(sizeof(Tcl_Encoding) * numFonts);
+ mapPtr = tmpFontNameMap;
+ FMResetFontFamilyIterator(NULL, NULL, kFMDefaultOptions, &fontFamilyIterator);
+ i = 0;
+ while (FMGetNextFontFamily(&fontFamilyIterator, &fontFamily) != kFMIterationCompleted) {
+ mapPtr->faceNum = fontFamily;
+ encodings[i] = GetFontEncoding(mapPtr->faceNum, 0, &isSymbol);
+ FMGetFontFamilyName(fontFamily, nativeName );
+ Tcl_ExternalToUtfDString(encodings[i], StrBody(nativeName), StrLength(nativeName), &ds);
+ mapPtr->utfName = Tk_GetUid(Tcl_DStringValue(&ds));
+ mapPtr->nativeName = (StringPtr) ckalloc(StrLength(nativeName) + 1);
+ memcpy(mapPtr->nativeName, nativeName, StrLength(nativeName) + 1);
+ Tcl_DStringFree(&ds);
+ mapPtr++;
+ i++;
+ }
+ FMDisposeFontFamilyIterator(&fontFamilyIterator);
+
+ /*
+ * Reorder FontNameMap so fonts with the preferred encodings are at
+ * the front of the list. The relative order of fonts that all have
+ * the same encoding is preserved. Fonts with unknown encodings get
+ * stuck at the end.
+ */
+ newFontNameMap = (FontNameMap *) ckalloc(sizeof(FontNameMap) * (numFonts + 1));
+ fontMapOffset = 0;
+ for (i = 0; encodingList[i] != NULL; i++) {
+ encoding = Tcl_GetEncoding(NULL, encodingList[i]);
+ if (encoding == NULL) {
+ continue;
+ }
+ for (j = 0; j < numFonts; j++) {
+ if (encodings[j] == encoding) {
+ newFontNameMap[fontMapOffset] = tmpFontNameMap[j];
+ fontMapOffset++;
+ Tcl_FreeEncoding(encodings[j]);
+ tmpFontNameMap[j].utfName = NULL;
+ }
+ }
+ Tcl_FreeEncoding(encoding);
+ }
+ for (i = 0; i < numFonts; i++) {
+ if (tmpFontNameMap[i].utfName != NULL) {
+ newFontNameMap[fontMapOffset] = tmpFontNameMap[i];
+ fontMapOffset++;
+ Tcl_FreeEncoding(encodings[i]);
+ }
+ }
+ if (fontMapOffset != numFonts) {
+ Tcl_Panic("TkpFontPkgInit: unexpected number of fonts");
+ }
+
+ mapPtr = &newFontNameMap[numFonts];
+ mapPtr->utfName = NULL;
+ mapPtr->nativeName = NULL;
+ mapPtr->faceNum = 0;
+
+ ckfree((char *) tmpFontNameMap);
+ ckfree((char *) encodings);
+
+ gFontNameMap = newFontNameMap;
}
}
/*
*---------------------------------------------------------------------------
*
+ * GetThemeFontAndFamily --
+ *
+ * Wrapper around the GetThemeFont and FMGetFontFamilyFromName APIs.
+ *
+ *---------------------------------------------------------------------------
+ */
+
+OSStatus
+GetThemeFontAndFamily(
+ const ThemeFontID themeFontId,
+ FMFontFamily* fontFamily,
+ unsigned char *fontName,
+ SInt16 *fontSize,
+ Style *fontStyle)
+{
+ OSStatus err = ChkErr(GetThemeFont, themeFontId, smSystemScript, fontName,
+ fontSize, fontStyle);
+
+ if (err == noErr) {
+ *fontFamily = FMGetFontFamilyFromName(fontName);
+ if (*fontFamily == kInvalidFontFamily) {
+ err = kFMInvalidFontFamilyErr;
+ TkMacOSXDbgMsg("FMGetFontFamilyFromName failed.");
+ }
+ }
+ return err;
+}
+
+/*
+ *---------------------------------------------------------------------------
+ *
* TkpGetNativeFont --
*
- * Map a platform-specific native font name to a TkFont.
+ * Map a platform-specific native font name to a TkFont.
*
* Results:
- * The return value is a pointer to a TkFont that represents the
- * native font. If a native font by the given name could not be
- * found, the return value is NULL.
+ * The return value is a pointer to a TkFont that represents the
+ * native font. If a native font by the given name could not be
+ * found, the return value is NULL.
*
- * Every call to this procedure returns a new TkFont structure,
- * even if the name has already been seen before. The caller should
- * call TkpDeleteFont() when the font is no longer needed.
+ * Every call to this procedure returns a new TkFont structure,
+ * even if the name has already been seen before. The caller should
+ * call TkpDeleteFont() when the font is no longer needed.
*
- * The caller is responsible for initializing the memory associated
- * with the generic TkFont when this function returns and releasing
- * the contents of the generics TkFont before calling TkpDeleteFont().
+ * The caller is responsible for initializing the memory associated
+ * with the generic TkFont when this function returns and releasing
+ * the contents of the generics TkFont before calling TkpDeleteFont().
*
* Side effects:
- * None.
+ * None.
*
*---------------------------------------------------------------------------
*/
TkFont *
TkpGetNativeFont(
- Tk_Window tkwin, /* For display where font will be used. */
- CONST char *name) /* Platform-specific font name. */
+ Tk_Window tkwin, /* For display where font will be used. */
+ CONST char *name) /* Platform-specific font name. */
{
- SInt16 family;
- MacFont *fontPtr;
-
- if (strcmp(name, "system") == 0) {
- family = GetSysFont();
- } else if (strcmp(name, "application") == 0) {
- family = GetAppFont();
+ ThemeFontID themeFontId;
+ FMFontFamily fontFamily;
+ Str255 fontName;
+ SInt16 fontSize;
+ Style fontStyle;
+ MacFont * fontPtr;
+
+ if (strcmp(name, SYSTEMFONT_NAME) == 0) {
+ themeFontId = kThemeSystemFont;
+ } else if (strcmp(name, APPLFONT_NAME) == 0) {
+ themeFontId = kThemeApplicationFont;
+ } else if (strcmp(name, MENUITEMFONT_NAME) == 0) {
+ themeFontId = kThemeMenuItemFont;
} else {
- return NULL;
+ return NULL;
+ }
+ if (GetThemeFontAndFamily(themeFontId, &fontFamily, fontName, &fontSize,
+ &fontStyle) != noErr) {
+ return NULL;
}
-
+
fontPtr = (MacFont *) ckalloc(sizeof(MacFont));
- InitFont(tkwin, family, 0, 0, fontPtr);
-
+ InitFont(tkwin, fontFamily, fontName, fontSize, fontStyle, fontPtr);
+
return (TkFont *) fontPtr;
}
/*
*---------------------------------------------------------------------------
*
- * TkpGetFontFromAttributes --
+ * TkpGetFontFromAttributes --
*
- * Given a desired set of attributes for a font, find a font with
- * the closest matching attributes.
+ * Given a desired set of attributes for a font, find a font with
+ * the closest matching attributes.
*
* Results:
- * The return value is a pointer to a TkFont that represents the
- * font with the desired attributes. If a font with the desired
- * attributes could not be constructed, some other font will be
- * substituted automatically.
+ * The return value is a pointer to a TkFont that represents the
+ * font with the desired attributes. If a font with the desired
+ * attributes could not be constructed, some other font will be
+ * substituted automatically.
*
- * Every call to this procedure returns a new TkFont structure,
- * even if the specified attributes have already been seen before.
- * The caller should call TkpDeleteFont() to free the platform-
- * specific data when the font is no longer needed.
+ * Every call to this procedure returns a new TkFont structure,
+ * even if the specified attributes have already been seen before.
+ * The caller should call TkpDeleteFont() to free the platform-
+ * specific data when the font is no longer needed.
*
- * The caller is responsible for initializing the memory associated
- * with the generic TkFont when this function returns and releasing
- * the contents of the generic TkFont before calling TkpDeleteFont().
+ * The caller is responsible for initializing the memory associated
+ * with the generic TkFont when this function returns and releasing
+ * the contents of the generic TkFont before calling TkpDeleteFont().
*
* Side effects:
- * None.
+ * None.
*
*---------------------------------------------------------------------------
*/
TkFont *
TkpGetFontFromAttributes(
- TkFont *tkFontPtr, /* If non-NULL, store the information in
- * this existing TkFont structure, rather than
- * allocating a new structure to hold the
- * font; the existing contents of the font
- * will be released. If NULL, a new TkFont
- * structure is allocated. */
- Tk_Window tkwin, /* For display where font will be used. */
+ TkFont *tkFontPtr, /* If non-NULL, store the information in
+ * this existing TkFont structure, rather than
+ * allocating a new structure to hold the
+ * font; the existing contents of the font
+ * will be released. If NULL, a new TkFont
+ * structure is allocated. */
+ Tk_Window tkwin, /* For display where font will be used. */
CONST TkFontAttributes *faPtr)
- /* Set of attributes to match. */
+ /* Set of attributes to match. */
{
short faceNum, style;
int i, j;
- CONST char *faceName, *fallback;
+ const char *faceName, *fallback;
char ***fallbacks;
MacFont *fontPtr;
-
+
/*
* Algorithm to get the closest font to the one requested.
*
* try fontname
* try all aliases for fontname
* foreach fallback for fontname
- * try the fallback
- * try all aliases for the fallback
+ * try the fallback
+ * try all aliases for the fallback
*/
-
+
faceNum = 0;
faceName = faPtr->family;
if (faceName != NULL) {
- if (GetFamilyOrAliasNum(faceName, &faceNum) != 0) {
- goto found;
- }
- fallbacks = TkFontGetFallbacks();
- for (i = 0; fallbacks[i] != NULL; i++) {
- for (j = 0; (fallback = fallbacks[i][j]) != NULL; j++) {
- if (strcasecmp(faceName, fallback) == 0) {
- for (j = 0; (fallback = fallbacks[i][j]) != NULL; j++) {
- if (GetFamilyOrAliasNum(fallback, &faceNum)) {
- goto found;
- }
- }
- }
- break;
- }
- }
+ if (GetFamilyOrAliasNum(faceName, &faceNum) != 0) {
+ goto found;
+ }
+ fallbacks = TkFontGetFallbacks();
+ for (i = 0; fallbacks[i] != NULL; i++) {
+ for (j = 0; (fallback = fallbacks[i][j]) != NULL; j++) {
+ if (strcasecmp(faceName, fallback) == 0) {
+ for (j = 0; (fallback = fallbacks[i][j]) != NULL; j++) {
+ if (GetFamilyOrAliasNum(fallback, &faceNum)) {
+ goto found;
+ }
+ }
+ }
+ break;
+ }
+ }
}
-
- found:
+
+found:
style = 0;
if (faPtr->weight != TK_FW_NORMAL) {
- style |= bold;
+ style |= bold;
}
if (faPtr->slant != TK_FS_ROMAN) {
- style |= italic;
+ style |= italic;
}
if (faPtr->underline) {
- style |= underline;
+ style |= underline;
}
if (tkFontPtr == NULL) {
- fontPtr = (MacFont *) ckalloc(sizeof(MacFont));
+ fontPtr = (MacFont *) ckalloc(sizeof(MacFont));
} else {
- fontPtr = (MacFont *) tkFontPtr;
- ReleaseFont(fontPtr);
+ fontPtr = (MacFont *) tkFontPtr;
+ ReleaseFont(fontPtr);
}
- InitFont(tkwin, faceNum, faPtr->size, style, fontPtr);
-
+ InitFont(tkwin, faceNum, NULL, faPtr->size, style, fontPtr);
+
return (TkFont *) fontPtr;
}
@@ -526,26 +579,26 @@ TkpGetFontFromAttributes(
*
* TkpDeleteFont --
*
- * Called to release a font allocated by TkpGetNativeFont() or
- * TkpGetFontFromAttributes(). The caller should have already
- * released the fields of the TkFont that are used exclusively by
- * the generic TkFont code.
+ * Called to release a font allocated by TkpGetNativeFont() or
+ * TkpGetFontFromAttributes(). The caller should have already
+ * released the fields of the TkFont that are used exclusively by
+ * the generic TkFont code.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * TkFont is deallocated.
+ * TkFont is deallocated.
*
*---------------------------------------------------------------------------
*/
void
TkpDeleteFont(
- TkFont *tkFontPtr) /* Token of font to be deleted. */
+ TkFont *tkFontPtr) /* Token of font to be deleted. */
{
MacFont *fontPtr;
-
+
fontPtr = (MacFont *) tkFontPtr;
ReleaseFont(fontPtr);
}
@@ -555,31 +608,31 @@ TkpDeleteFont(
*
* TkpGetFontFamilies --
*
- * Return information about the font families that are available
- * on the display of the given window.
+ * Return information about the font families that are available
+ * on the display of the given window.
*
* Results:
- * Modifies interp's result object to hold a list of all the available
- * font families.
+ * Modifies interp's result object to hold a list of all the available
+ * font families.
*
* Side effects:
- * None.
+ * None.
*
*---------------------------------------------------------------------------
*/
-
+
void
TkpGetFontFamilies(
- Tcl_Interp *interp, /* Interp to hold result. */
- Tk_Window tkwin) /* For display to query. */
-{
+ Tcl_Interp *interp, /* Interp to hold result. */
+ Tk_Window tkwin) /* For display to query. */
+{
FontNameMap *mapPtr;
Tcl_Obj *resultPtr, *strPtr;
-
+
resultPtr = Tcl_GetObjResult(interp);
for (mapPtr = gFontNameMap; mapPtr->utfName != NULL; mapPtr++) {
- strPtr = Tcl_NewStringObj(mapPtr->utfName, -1);
- Tcl_ListObjAppendElement(NULL, resultPtr, strPtr);
+ strPtr = Tcl_NewStringObj(mapPtr->utfName, -1);
+ Tcl_ListObjAppendElement(NULL, resultPtr, strPtr);
}
}
@@ -588,23 +641,23 @@ TkpGetFontFamilies(
*
* TkpGetSubFonts --
*
- * A function used by the testing package for querying the actual
- * screen fonts that make up a font object.
+ * A function used by the testing package for querying the actual
+ * screen fonts that make up a font object.
*
* Results:
- * Modifies interp's result object to hold a list containing the
- * names of the screen fonts that make up the given font object.
+ * Modifies interp's result object to hold a list containing the
+ * names of the screen fonts that make up the given font object.
*
* Side effects:
- * None.
+ * None.
*
*-------------------------------------------------------------------------
*/
-
+
void
-TkpGetSubFonts(interp, tkfont)
- Tcl_Interp *interp; /* Interp to hold result. */
- Tk_Font tkfont; /* Font object to query. */
+TkpGetSubFonts(
+ Tcl_Interp *interp, /* Interp to hold result. */
+ Tk_Font tkfont) /* Font object to query. */
{
int i;
Tcl_Obj *resultPtr, *strPtr;
@@ -612,13 +665,13 @@ TkpGetSubFonts(interp, tkfont)
FontFamily *familyPtr;
Str255 nativeName;
- resultPtr = Tcl_GetObjResult(interp);
+ resultPtr = Tcl_GetObjResult(interp);
fontPtr = (MacFont *) tkfont;
for (i = 0; i < fontPtr->numSubFonts; i++) {
- familyPtr = fontPtr->subFontArray[i].familyPtr;
- GetFontName(familyPtr->faceNum, nativeName);
- strPtr = Tcl_NewStringObj(GetUtfFaceName(nativeName), -1);
- Tcl_ListObjAppendElement(NULL, resultPtr, strPtr);
+ familyPtr = fontPtr->subFontArray[i].familyPtr;
+ GetFontName(familyPtr->faceNum, nativeName);
+ strPtr = Tcl_NewStringObj(GetUtfFaceName(nativeName), -1);
+ Tcl_ListObjAppendElement(NULL, resultPtr, strPtr);
}
}
@@ -627,50 +680,50 @@ TkpGetSubFonts(interp, tkfont)
*
* Tk_MeasureChars --
*
- * Determine the number of characters from the string that will fit
- * in the given horizontal span. The measurement is done under the
- * assumption that Tk_DrawChars() will be used to actually display
- * the characters.
+ * Determine the number of characters from the string that will fit
+ * in the given horizontal span. The measurement is done under the
+ * assumption that Tk_DrawChars() will be used to actually display
+ * the characters.
*
* Results:
- * The return value is the number of bytes from source that
- * fit into the span that extends from 0 to maxLength. *lengthPtr is
- * filled with the x-coordinate of the right edge of the last
- * character that did fit.
+ * The return value is the number of bytes from source that
+ * fit into the span that extends from 0 to maxLength. *lengthPtr is
+ * filled with the x-coordinate of the right edge of the last
+ * character that did fit.
*
* Side effects:
- * None.
+ * None.
*
*---------------------------------------------------------------------------
*/
int
Tk_MeasureChars(
- Tk_Font tkfont, /* Font in which characters will be drawn. */
- CONST char *source, /* UTF-8 string to be displayed. Need not be
- * '\0' terminated. */
- int numBytes, /* Maximum number of bytes to consider
- * from source string. */
- int maxLength, /* If >= 0, maxLength specifies the longest
- * permissible line length; don't consider any
- * character that would cross this
- * x-position. If < 0, then line length is
- * unbounded and the flags argument is
- * ignored. */
- int flags, /* Various flag bits OR-ed together:
- * TK_PARTIAL_OK means include the last char
- * which only partially fit on this line.
- * TK_WHOLE_WORDS means stop on a word
- * boundary, if possible.
- * TK_AT_LEAST_ONE means return at least one
- * character even if no characters fit. */
- int *lengthPtr) /* Filled with x-location just after the
- * terminating character. */
+ Tk_Font tkfont, /* Font in which characters will be drawn. */
+ CONST char *source, /* UTF-8 string to be displayed. Need not be
+ * '\0' terminated. */
+ int numBytes, /* Maximum number of bytes to consider
+ * from source string. */
+ int maxLength, /* If >= 0, maxLength specifies the longest
+ * permissible line length; don't consider any
+ * character that would cross this
+ * x-position. If < 0, then line length is
+ * unbounded and the flags argument is
+ * ignored. */
+ int flags, /* Various flag bits OR-ed together:
+ * TK_PARTIAL_OK means include the last char
+ * which only partially fit on this line.
+ * TK_WHOLE_WORDS means stop on a word
+ * boundary, if possible.
+ * TK_AT_LEAST_ONE means return at least one
+ * character even if no characters fit. */
+ int *lengthPtr) /* Filled with x-location just after the
+ * terminating character. */
{
MacFont *fontPtr;
SubFont *thisSubFontPtr, *lastSubFontPtr;
- CGrafPtr saveWorld;
- GDHandle saveDevice;
+ CGrafPtr savePort;
+ Boolean portChanged;
int curX, curByte;
/*
@@ -684,109 +737,110 @@ Tk_MeasureChars(
* where a word or line break would occur, then can we map that
* number back to UTF-8?
*/
-
+
fontPtr = (MacFont *) tkfont;
- GetGWorld(&saveWorld, &saveDevice);
- SetGWorld(gWorld, NULL);
-
+ portChanged = QDSwapPort(gWorld, &savePort);
+
TextSize(fontPtr->size);
TextFace(fontPtr->style);
lastSubFontPtr = &fontPtr->subFontArray[0];
-
+
if (numBytes == 0) {
- curX = 0;
- curByte = 0;
+ curX = 0;
+ curByte = 0;
} else if (maxLength < 0) {
- CONST char *p, *end, *next;
- Tcl_UniChar ch;
- FontFamily *familyPtr;
- Tcl_DString runString;
-
- /*
- * A three step process:
- * 1. Find a contiguous range of characters that can all be
- * represented by a single screen font.
- * 2. Convert those chars to the encoding of that font.
- * 3. Measure converted chars.
- */
-
- curX = 0;
- end = source + numBytes;
- for (p = source; p < end; ) {
- next = p + Tcl_UtfToUniChar(p, &ch);
- thisSubFontPtr = FindSubFontForChar(fontPtr, ch, &lastSubFontPtr);
- if (thisSubFontPtr != lastSubFontPtr) {
- familyPtr = lastSubFontPtr->familyPtr;
- TextFont(familyPtr->faceNum);
- Tcl_UtfToExternalDString(familyPtr->encoding, source,
- p - source, &runString);
- curX += TextWidth(Tcl_DStringValue(&runString), 0,
- Tcl_DStringLength(&runString));
- Tcl_DStringFree(&runString);
+ const char *p, *end, *next;
+ Tcl_UniChar ch;
+ FontFamily *familyPtr;
+ Tcl_DString runString;
+
+ /*
+ * A three step process:
+ * 1. Find a contiguous range of characters that can all be
+ * represented by a single screen font.
+ * 2. Convert those chars to the encoding of that font.
+ * 3. Measure converted chars.
+ */
+
+ curX = 0;
+ end = source + numBytes;
+ for (p = source; p < end; ) {
+ next = p + Tcl_UtfToUniChar(p, &ch);
+ thisSubFontPtr = FindSubFontForChar(fontPtr, ch, &lastSubFontPtr);
+ if (thisSubFontPtr != lastSubFontPtr) {
+ familyPtr = lastSubFontPtr->familyPtr;
+ TextFont(familyPtr->faceNum);
+ Tcl_UtfToExternalDString(familyPtr->encoding, source,
+ p - source, &runString);
+ curX += TextWidth(Tcl_DStringValue(&runString), 0,
+ Tcl_DStringLength(&runString));
+ Tcl_DStringFree(&runString);
lastSubFontPtr = thisSubFontPtr;
- source = p;
- }
- p = next;
- }
- familyPtr = lastSubFontPtr->familyPtr;
- TextFont(familyPtr->faceNum);
- Tcl_UtfToExternalDString(familyPtr->encoding, source, p - source,
- &runString);
- curX += TextWidth(Tcl_DStringValue(&runString), 0,
- Tcl_DStringLength(&runString));
- Tcl_DStringFree(&runString);
- curByte = numBytes;
+ source = p;
+ }
+ p = next;
+ }
+ familyPtr = lastSubFontPtr->familyPtr;
+ TextFont(familyPtr->faceNum);
+ Tcl_UtfToExternalDString(familyPtr->encoding, source, p - source,
+ &runString);
+ curX += TextWidth(Tcl_DStringValue(&runString), 0,
+ Tcl_DStringLength(&runString));
+ Tcl_DStringFree(&runString);
+ curByte = numBytes;
} else {
- CONST char *p, *end, *next, *sourceOrig;
- int widthLeft;
- Tcl_UniChar ch;
- CONST char *rest = NULL;
-
- /*
- * How many chars will fit in the space allotted?
- */
-
- if (maxLength > 32767) {
- maxLength = 32767;
- }
-
- widthLeft = maxLength;
- sourceOrig = source;
- end = source + numBytes;
- for (p = source; p < end; p = next) {
- next = p + Tcl_UtfToUniChar(p, &ch);
- thisSubFontPtr = FindSubFontForChar(fontPtr, ch, &lastSubFontPtr);
- if (thisSubFontPtr != lastSubFontPtr) {
- if (p > source) {
- rest = BreakLine(lastSubFontPtr->familyPtr, flags, source,
- p - source, &widthLeft);
- flags &= ~TK_AT_LEAST_ONE;
- if (rest != NULL) {
- p = source;
- break;
- }
- }
+ const char *p, *end, *next, *sourceOrig;
+ int widthLeft;
+ Tcl_UniChar ch;
+ const char *rest = NULL;
+
+ /*
+ * How many chars will fit in the space allotted?
+ */
+
+ if (maxLength > 32767) {
+ maxLength = 32767;
+ }
+
+ widthLeft = maxLength;
+ sourceOrig = source;
+ end = source + numBytes;
+ for (p = source; p < end; p = next) {
+ next = p + Tcl_UtfToUniChar(p, &ch);
+ thisSubFontPtr = FindSubFontForChar(fontPtr, ch, &lastSubFontPtr);
+ if (thisSubFontPtr != lastSubFontPtr) {
+ if (p > source) {
+ rest = BreakLine(lastSubFontPtr->familyPtr, flags, source,
+ p - source, &widthLeft);
+ flags &= ~TK_AT_LEAST_ONE;
+ if (rest != NULL) {
+ p = source;
+ break;
+ }
+ }
lastSubFontPtr = thisSubFontPtr;
- source = p;
- }
- }
-
- if (p > source) {
- rest = BreakLine(lastSubFontPtr->familyPtr, flags, source, p - source,
- &widthLeft);
- }
-
- if (rest == NULL) {
- curByte = numBytes;
- } else {
- curByte = rest - sourceOrig;
- }
- curX = maxLength - widthLeft;
+ source = p;
+ }
+ }
+
+ if (p > source) {
+ rest = BreakLine(lastSubFontPtr->familyPtr, flags, source, p - source,
+ &widthLeft);
+ }
+
+ if (rest == NULL) {
+ curByte = numBytes;
+ } else {
+ curByte = rest - sourceOrig;
+ }
+ curX = maxLength - widthLeft;
}
- SetGWorld(saveWorld, saveDevice);
+ if (portChanged) {
+ QDSwapPort(savePort, NULL);
+ }
*lengthPtr = curX;
return curByte;
@@ -797,48 +851,48 @@ Tk_MeasureChars(
*
* BreakLine --
*
- * Determine where the given line of text should be broken so that it
- * fits in the specified range. Before calling this function, the
- * font values and graphics port must be set.
+ * Determine where the given line of text should be broken so that it
+ * fits in the specified range. Before calling this function, the
+ * font values and graphics port must be set.
*
* Results:
- * The return value is NULL if the specified range is larger that the
- * space the text needs, and *widthLeftPtr is filled with how much
- * space is left in the range after measuring the whole text buffer.
- * Otherwise, the return value is a pointer into the text buffer that
- * indicates where the line should be broken (up to, but not including
- * that character), and *widthLeftPtr is filled with how much space is
- * left in the range after measuring up to that character.
+ * The return value is NULL if the specified range is larger that the
+ * space the text needs, and *widthLeftPtr is filled with how much
+ * space is left in the range after measuring the whole text buffer.
+ * Otherwise, the return value is a pointer into the text buffer that
+ * indicates where the line should be broken (up to, but not including
+ * that character), and *widthLeftPtr is filled with how much space is
+ * left in the range after measuring up to that character.
*
* Side effects:
- * None.
+ * None.
*
*---------------------------------------------------------------------------
*/
-
-static CONST char *
+
+static const char *
BreakLine(
- FontFamily *familyPtr, /* FontFamily that describes the font values
- * that are already selected into the graphics
- * port. */
- int flags, /* Various flag bits OR-ed together:
- * TK_PARTIAL_OK means include the last char
- * which only partially fit on this line.
- * TK_WHOLE_WORDS means stop on a word
- * boundary, if possible.
- * TK_AT_LEAST_ONE means return at least one
- * character even if no characters fit. */
- CONST char *source, /* UTF-8 string to be displayed. Need not be
- * '\0' terminated. */
- int numBytes, /* Maximum number of bytes to consider
- * from source string. */
- int *widthLeftPtr) /* On input, specifies size of range into
- * which characters from source buffer should
- * be fit. On output, filled with how much
- * space is left after fitting as many
- * characters as possible into the range.
- * Result may be negative if TK_AT_LEAST_ONE
- * was specified in the flags argument. */
+ FontFamily *familyPtr, /* FontFamily that describes the font values
+ * that are already selected into the graphics
+ * port. */
+ int flags, /* Various flag bits OR-ed together:
+ * TK_PARTIAL_OK means include the last char
+ * which only partially fit on this line.
+ * TK_WHOLE_WORDS means stop on a word
+ * boundary, if possible.
+ * TK_AT_LEAST_ONE means return at least one
+ * character even if no characters fit. */
+ const char *source, /* UTF-8 string to be displayed. Need not be
+ * '\0' terminated. */
+ int numBytes, /* Maximum number of bytes to consider
+ * from source string. */
+ int *widthLeftPtr) /* On input, specifies size of range into
+ * which characters from source buffer should
+ * be fit. On output, filled with how much
+ * space is left after fitting as many
+ * characters as possible into the range.
+ * Result may be negative if TK_AT_LEAST_ONE
+ * was specified in the flags argument. */
{
Fixed pixelWidth, widthLeft;
StyledLineBreakCode breakCode;
@@ -848,37 +902,37 @@ BreakLine(
Point point;
int charOffset, thisCharWasDoubleByte;
char *p, *end, *typeTable;
-
+
TextFont(familyPtr->faceNum);
Tcl_UtfToExternalDString(familyPtr->encoding, source, numBytes,
- &runString);
- pixelWidth = Int2Fixed(*widthLeftPtr) + 1;
+ &runString);
+ pixelWidth = IntToFixed(*widthLeftPtr) + 1;
if (flags & TK_WHOLE_WORDS) {
- textOffset = (flags & TK_AT_LEAST_ONE);
- widthLeft = pixelWidth;
- breakCode = StyledLineBreak(Tcl_DStringValue(&runString),
- Tcl_DStringLength(&runString), 0, Tcl_DStringLength(&runString),
- 0, &widthLeft, &textOffset);
- if (breakCode != smBreakOverflow) {
- /*
- * StyledLineBreak includes all the space characters at the end of
- * line that we want to suppress.
- */
-
- textOffset = VisibleLength(Tcl_DStringValue(&runString), textOffset);
- goto getoffset;
- }
+ textOffset = (flags & TK_AT_LEAST_ONE);
+ widthLeft = pixelWidth;
+ breakCode = StyledLineBreak(Tcl_DStringValue(&runString),
+ Tcl_DStringLength(&runString), 0, Tcl_DStringLength(&runString),
+ 0, &widthLeft, &textOffset);
+ if (breakCode != smBreakOverflow) {
+ /*
+ * StyledLineBreak includes all the space characters at the end of
+ * line that we want to suppress.
+ */
+
+ textOffset = VisibleLength(Tcl_DStringValue(&runString), textOffset);
+ goto getoffset;
+ }
} else {
- point.v = 1;
- point.h = 1;
- textOffset = PixelToChar(Tcl_DStringValue(&runString),
- Tcl_DStringLength(&runString), 0, pixelWidth, &leadingEdge,
- &widthLeft, smOnlyStyleRun, point, point);
- if (Fixed2Int(widthLeft) < 0) {
- goto getoffset;
- }
+ point.v = 1;
+ point.h = 1;
+ textOffset = PixelToChar(Tcl_DStringValue(&runString),
+ Tcl_DStringLength(&runString), 0, pixelWidth, &leadingEdge,
+ &widthLeft, smOnlyStyleRun, point, point);
+ if (FixedToInt(widthLeft) < 0) {
+ goto getoffset;
+ }
}
- *widthLeftPtr = Fixed2Int(widthLeft);
+ *widthLeftPtr = FixedToInt(widthLeft);
Tcl_DStringFree(&runString);
return NULL;
@@ -886,50 +940,50 @@ BreakLine(
* The conversion routine that converts UTF-8 to the target encoding
* must map one UTF-8 character to exactly one encoding-specific
* character, so that the following algorithm works:
- *
+ *
* 1. Get byte offset of where line should be broken.
* 2. Get char offset corresponding to that byte offset.
* 3. Map that char offset to byte offset in UTF-8 string.
- */
+ */
getoffset:
thisCharWasDoubleByte = 0;
if (familyPtr->isMultiByteFont == 0) {
- charOffset = textOffset;
+ charOffset = textOffset;
} else {
- charOffset = 0;
- typeTable = familyPtr->typeTable;
-
- p = Tcl_DStringValue(&runString);
- end = p + textOffset;
- thisCharWasDoubleByte = typeTable[*((unsigned char *) p)];
- for ( ; p < end; p++) {
- thisCharWasDoubleByte = typeTable[*((unsigned char *) p)];
- p += thisCharWasDoubleByte;
- charOffset++;
- }
+ charOffset = 0;
+ typeTable = familyPtr->typeTable;
+
+ p = Tcl_DStringValue(&runString);
+ end = p + textOffset;
+ thisCharWasDoubleByte = typeTable[*((unsigned char *) p)];
+ for ( ; p < end; p++) {
+ thisCharWasDoubleByte = typeTable[*((unsigned char *) p)];
+ p += thisCharWasDoubleByte;
+ charOffset++;
+ }
}
-
+
if ((flags & TK_WHOLE_WORDS) == 0) {
- if ((flags & TK_PARTIAL_OK) && (leadingEdge != 0)) {
- textOffset += thisCharWasDoubleByte;
- textOffset++;
- charOffset++;
- } else if (((flags & TK_PARTIAL_OK) == 0) && (leadingEdge == 0)) {
- textOffset -= thisCharWasDoubleByte;
- textOffset--;
- charOffset--;
- }
+ if ((flags & TK_PARTIAL_OK) && (leadingEdge != 0)) {
+ textOffset += thisCharWasDoubleByte;
+ textOffset++;
+ charOffset++;
+ } else if (((flags & TK_PARTIAL_OK) == 0) && (leadingEdge == 0)) {
+ textOffset -= thisCharWasDoubleByte;
+ textOffset--;
+ charOffset--;
+ }
}
- if ((textOffset == 0) && (Tcl_DStringLength(&runString) > 0)
- && (flags & TK_AT_LEAST_ONE)) {
- p = Tcl_DStringValue(&runString);
- textOffset += familyPtr->typeTable[*((unsigned char *) p)];
- textOffset++;
- charOffset++;
+ if ((textOffset == 0) && (Tcl_DStringLength(&runString) > 0)
+ && (flags & TK_AT_LEAST_ONE)) {
+ p = Tcl_DStringValue(&runString);
+ textOffset += familyPtr->typeTable[*((unsigned char *) p)];
+ textOffset++;
+ charOffset++;
}
- *widthLeftPtr = Fixed2Int(pixelWidth)
- - TextWidth(Tcl_DStringValue(&runString), 0, textOffset);
+ *widthLeftPtr = FixedToInt(pixelWidth)
+ - TextWidth(Tcl_DStringValue(&runString), 0, textOffset);
Tcl_DStringFree(&runString);
return Tcl_UtfAtIndex(source, charOffset);
}
@@ -939,113 +993,82 @@ BreakLine(
*
* Tk_DrawChars --
*
- * Draw a string of characters on the screen.
+ * Draw a string of characters on the screen.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Information gets drawn on the screen.
+ * Information gets drawn on the screen.
*
*---------------------------------------------------------------------------
*/
void
Tk_DrawChars(
- Display *display, /* Display on which to draw. */
- Drawable drawable, /* Window or pixmap in which to draw. */
- GC gc, /* Graphics context for drawing characters. */
- Tk_Font tkfont, /* Font in which characters will be drawn;
- * must be the same as font used in GC. */
- CONST char *source, /* UTF-8 string to be displayed. Need not be
- * '\0' terminated. All Tk meta-characters
- * (tabs, control characters, and newlines)
- * should be stripped out of the string that
- * is passed to this function. If they are
- * not stripped out, they will be displayed as
- * regular printing characters. */
- int numBytes, /* Number of bytes in string. */
- int x, int y) /* Coordinates at which to place origin of
- * string when drawing. */
+ Display *display, /* Display on which to draw. */
+ Drawable drawable, /* Window or pixmap in which to draw. */
+ GC gc, /* Graphics context for drawing characters. */
+ Tk_Font tkfont, /* Font in which characters will be drawn;
+ * must be the same as font used in GC. */
+ CONST char *source, /* UTF-8 string to be displayed. Need not be
+ * '\0' terminated. All Tk meta-characters
+ * (tabs, control characters, and newlines)
+ * should be stripped out of the string that
+ * is passed to this function. If they are
+ * not stripped out, they will be displayed as
+ * regular printing characters. */
+ int numBytes, /* Number of bytes in string. */
+ int x, int y) /* Coordinates at which to place origin of
+ * string when drawing. */
{
- MacFont *fontPtr;
- MacDrawable *macWin;
- RGBColor macColor, origColor;
- GWorldPtr destPort;
- CGrafPtr saveWorld;
- GDHandle saveDevice;
- short txFont, txFace, txSize;
- BitMapPtr stippleMap;
- Rect portRect;
+ MacDrawable *macWin = (MacDrawable *) drawable;
+ MacFont *fontPtr = (MacFont *) tkfont;
+ TkMacOSXDrawingContext drawingContext;
- fontPtr = (MacFont *) tkfont;
- macWin = (MacDrawable *) drawable;
-
- destPort = TkMacOSXGetDrawablePort(drawable);
- GetPortBounds(destPort, &portRect);
- GetGWorld(&saveWorld, &saveDevice);
- SetGWorld(destPort, NULL);
-
- TkMacOSXSetUpClippingRgn(drawable);
- TkMacOSXSetUpGraphicsPort(gc, destPort);
-
- txFont = GetPortTextFont(destPort);
- txFace = GetPortTextFace(destPort);
- txSize = GetPortTextSize(destPort);
- GetForeColor(&origColor);
-
+ TkMacOSXSetupDrawingContext(drawable, gc, 0, &drawingContext);
+#if 0
+ /*
+ * Stippled QD text drawing only kind of works and is ugly, so disable it
+ * for now:
+ */
if ((gc->fill_style == FillStippled
- || gc->fill_style == FillOpaqueStippled)
- && gc->stipple != None) {
- Pixmap pixmap;
- GWorldPtr bufferPort;
- Pattern white;
-
- stippleMap = TkMacOSXMakeStippleMap(drawable, gc->stipple);
-
- pixmap = Tk_GetPixmap(display, drawable,
- stippleMap->bounds.right, stippleMap->bounds.bottom, 0);
-
- bufferPort = TkMacOSXGetDrawablePort(pixmap);
- SetGWorld(bufferPort, NULL);
-
- if (TkSetMacColor(gc->foreground, &macColor) == true) {
- RGBForeColor(&macColor);
- }
- GetQDGlobalsWhite(&white);
- ShowPen();
- FillRect(&stippleMap->bounds, &white);
- MultiFontDrawText(fontPtr, source, numBytes, 0, 0);
- HidePen();
-
- SetGWorld(destPort, NULL);
- CopyDeepMask(GetPortBitMapForCopyBits(bufferPort), stippleMap,
- GetPortBitMapForCopyBits(destPort), &stippleMap->bounds,
- &stippleMap->bounds, &portRect,
- srcOr, NULL);
-
- /* TODO: this doesn't work quite right - it does a blend. you can't
- * draw white text when you have a stipple.
- */
-
- Tk_FreePixmap(display, pixmap);
- ckfree(stippleMap->baseAddr);
- ckfree((char *)stippleMap);
- } else {
- if (TkSetMacColor(gc->foreground, &macColor) == true) {
- RGBForeColor(&macColor);
- }
- ShowPen();
- MultiFontDrawText(fontPtr, source, numBytes, macWin->xOff + x,
- macWin->yOff + y);
- HidePen();
+ || gc->fill_style == FillOpaqueStippled)
+ && gc->stipple != None) {
+ TkMacOSXDrawingContext pixmapDrawingContext;
+ BitMapPtr stippleMap;
+ Pixmap pixmap;
+ Pattern white;
+ Rect bounds = drawingContext.portBounds;
+
+ OffsetRect(&bounds, macWin->xOff + x, 0);
+ stippleMap = TkMacOSXMakeStippleMap(drawable, gc->stipple);
+ pixmap = Tk_GetPixmap(display, drawable,
+ stippleMap->bounds.right, stippleMap->bounds.bottom, 0);
+ TkMacOSXSetupDrawingContext(pixmap, gc, 0, &pixmapDrawingContext);
+ GetQDGlobalsWhite(&white);
+ FillRect(&stippleMap->bounds, &white);
+ MultiFontDrawText(fontPtr, source, numBytes, 0, macWin->yOff + y);
+ TkMacOSXRestoreDrawingContext(&pixmapDrawingContext);
+ CopyDeepMask(GetPortBitMapForCopyBits(TkMacOSXGetDrawablePort(pixmap)),
+ stippleMap, GetPortBitMapForCopyBits(
+ TkMacOSXGetDrawablePort(drawable)), &stippleMap->bounds,
+ &stippleMap->bounds, &bounds, srcOr, NULL);
+
+ /* TODO: this doesn't work quite right - it does a blend. You can't
+ * draw white text when you have a stipple.
+ */
+
+ Tk_FreePixmap(display, pixmap);
+ ckfree(stippleMap->baseAddr);
+ ckfree((char *)stippleMap);
+ } else
+#endif
+ {
+ MultiFontDrawText(fontPtr, source, numBytes, macWin->xOff + x,
+ macWin->yOff + y);
}
-
- TextFont(txFont);
- TextSize(txSize);
- TextFace(txFace);
- RGBForeColor(&origColor);
- SetGWorld(saveWorld, saveDevice);
+ TkMacOSXRestoreDrawingContext(&drawingContext);
}
/*
@@ -1053,37 +1076,37 @@ Tk_DrawChars(
*
* MultiFontDrawText --
*
- * Helper function for Tk_DrawChars. Draws characters, using the
- * various screen fonts in fontPtr to draw multilingual characters.
- * Note: No bidirectional support.
+ * Helper function for Tk_DrawChars. Draws characters, using the
+ * various screen fonts in fontPtr to draw multilingual characters.
+ * Note: No bidirectional support.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Information gets drawn on the screen.
- * Contents of fontPtr may be modified if more subfonts were loaded
- * in order to draw all the multilingual characters in the given
- * string.
+ * Information gets drawn on the screen.
+ * Contents of fontPtr may be modified if more subfonts were loaded
+ * in order to draw all the multilingual characters in the given
+ * string.
*
*-------------------------------------------------------------------------
*/
static void
MultiFontDrawText(
- MacFont *fontPtr, /* Contains set of fonts to use when drawing
- * following string. */
- CONST char *source, /* Potentially multilingual UTF-8 string. */
- int numBytes, /* Length of string in bytes. */
- int x, int y) /* Coordinates at which to place origin *
- * of string when drawing. */
+ MacFont *fontPtr, /* Contains set of fonts to use when drawing
+ * following string. */
+ const char *source, /* Potentially multilingual UTF-8 string. */
+ int numBytes, /* Length of string in bytes. */
+ int x, int y) /* Coordinates at which to place origin *
+ * of string when drawing. */
{
SubFont *thisSubFontPtr, *lastSubFontPtr;
FontFamily *familyPtr;
Tcl_DString runString;
- CONST char *p, *end, *next;
+ const char *p, *end, *next;
Tcl_UniChar ch;
-
+
TextSize(fontPtr->size);
TextFace(fontPtr->style);
@@ -1091,35 +1114,35 @@ MultiFontDrawText(
end = source + numBytes;
for (p = source; p < end; ) {
- next = p + Tcl_UtfToUniChar(p, &ch);
- thisSubFontPtr = FindSubFontForChar(fontPtr, ch, &lastSubFontPtr);
- if (thisSubFontPtr != lastSubFontPtr) {
- if (p > source) {
- familyPtr = lastSubFontPtr->familyPtr;
- TextFont(familyPtr->faceNum);
- Tcl_UtfToExternalDString(familyPtr->encoding, source,
- p - source, &runString);
- MoveTo((short) x, (short) y);
- DrawText(Tcl_DStringValue(&runString), 0,
- Tcl_DStringLength(&runString));
- x += TextWidth(Tcl_DStringValue(&runString), 0,
- Tcl_DStringLength(&runString));
- Tcl_DStringFree(&runString);
- source = p;
- }
- lastSubFontPtr = thisSubFontPtr;
- }
- p = next;
+ next = p + Tcl_UtfToUniChar(p, &ch);
+ thisSubFontPtr = FindSubFontForChar(fontPtr, ch, &lastSubFontPtr);
+ if (thisSubFontPtr != lastSubFontPtr) {
+ if (p > source) {
+ familyPtr = lastSubFontPtr->familyPtr;
+ TextFont(familyPtr->faceNum);
+ Tcl_UtfToExternalDString(familyPtr->encoding, source,
+ p - source, &runString);
+ MoveTo((short) x, (short) y);
+ DrawText(Tcl_DStringValue(&runString), 0,
+ Tcl_DStringLength(&runString));
+ x += TextWidth(Tcl_DStringValue(&runString), 0,
+ Tcl_DStringLength(&runString));
+ Tcl_DStringFree(&runString);
+ source = p;
+ }
+ lastSubFontPtr = thisSubFontPtr;
+ }
+ p = next;
}
if (p > source) {
- familyPtr = lastSubFontPtr->familyPtr;
- TextFont(familyPtr->faceNum);
- Tcl_UtfToExternalDString(familyPtr->encoding, source,
- p - source, &runString);
- MoveTo((short) x, (short) y);
- DrawText(Tcl_DStringValue(&runString), 0,
- Tcl_DStringLength(&runString));
- Tcl_DStringFree(&runString);
+ familyPtr = lastSubFontPtr->familyPtr;
+ TextFont(familyPtr->faceNum);
+ Tcl_UtfToExternalDString(familyPtr->encoding, source,
+ p - source, &runString);
+ MoveTo((short) x, (short) y);
+ DrawText(Tcl_DStringValue(&runString), 0,
+ Tcl_DStringLength(&runString));
+ Tcl_DStringFree(&runString);
}
}
@@ -1128,58 +1151,32 @@ MultiFontDrawText(
*
* TkMacOSXIsCharacterMissing --
*
- * Given a tkFont and a character determines whether the character has
- * a glyph defined in the font or not. Note that this is potentially
- * not compatible with Mac OS 8 as it looks at the font handle
- * structure directly. Looks into the character array of the font
- * handle to determine whether the glyph is defined or not.
+ * Given a tkFont and a character determines whether the character has
+ * a glyph defined in the font or not. Note that this is potentially
+ * not compatible with Mac OS 8 as it looks at the font handle
+ * structure directly. Looks into the character array of the font
+ * handle to determine whether the glyph is defined or not.
*
* Results:
- * Returns a 1 if the character is missing, a 0 if it is not.
+ * Returns a 1 if the character is missing, a 0 if it is not.
*
* Side effects:
- * None.
+ * None.
*
*---------------------------------------------------------------------------
*/
int
TkMacOSXIsCharacterMissing(
- Tk_Font tkfont, /* The font we are looking in. */
- unsigned int searchChar) /* The character we are looking for. */
+ Tk_Font tkfont, /* The font we are looking in. */
+ unsigned int searchChar) /* The character we are looking for. */
{
-/*
- * For some reason, FMSwapFont always returns a NULL font handle under OS X
- * Until we figure this one out, return 0;
- */
-#ifdef MAC_OSX_TK
+ /*
+ * For some reason, FMSwapFont always returns a NULL font handle under OS X
+ * Until we figure this one out, return 0;
+ */
+
return 0;
-#else
- MacFont *fontPtr = (MacFont *) tkfont;
- FMInput fm;
- FontRec **fontRecHandle;
- FMOutPtr fmOutPtr;
-
-
- fm.family = fontPtr->subFontArray[0].familyPtr->faceNum;
- fm.size = fontPtr->size;
- fm.face = fontPtr->style;
- fm.needBits = 0;
- fm.device = 0;
- fm.numer.h = fm.numer.v = fm.denom.h = fm.denom.v = 1;
-
- fmOutPtr = FMSwapFont(&fm);
- fprintf(stderr,"fmOut %08x, handle %08x\n", (int)fmOutPtr, fmOutPtr->fontHandle);
-
-#if !defined(UNIVERSAL_INTERFACES_VERSION) || (UNIVERSAL_INTERFACES_VERSION < 0x0300)
- fontRecHandle = (FontRec **) FMSwapFont(&fm)->fontResult;
-#else
- fontRecHandle = (FontRec **) FMSwapFont(&fm)->fontHandle;
-#endif
- return *(short *) ((long) &(*fontRecHandle)->owTLoc
- + ((long)((*fontRecHandle)->owTLoc + searchChar
- - (*fontRecHandle)->firstChar) * sizeof(short))) == -1;
-#endif
}
/*
@@ -1187,110 +1184,113 @@ TkMacOSXIsCharacterMissing(
*
* InitFont --
*
- * Helper for TkpGetNativeFont() and TkpGetFontFromAttributes().
- * Initializes the memory for a MacFont that wraps the platform-specific
- * data.
+ * Helper for TkpGetNativeFont() and TkpGetFontFromAttributes().
+ * Initializes the memory for a MacFont that wraps the platform-specific
+ * data.
*
- * The caller is responsible for initializing the fields of the
- * TkFont that are used exclusively by the generic TkFont code, and
- * for releasing those fields before calling TkpDeleteFont().
+ * The caller is responsible for initializing the fields of the
+ * TkFont that are used exclusively by the generic TkFont code, and
+ * for releasing those fields before calling TkpDeleteFont().
*
* Results:
- * Fills the MacFont structure.
+ * Fills the MacFont structure.
*
* Side effects:
- * Memory allocated.
+ * Memory allocated.
*
*---------------------------------------------------------------------------
- */
+ */
static void
InitFont(
- Tk_Window tkwin, /* For display where font will be used. */
- int faceNum, /* Macintosh font number. */
- int size, /* Point size for Macintosh font. */
- int style, /* Macintosh style bits. */
- MacFont *fontPtr) /* Filled with information constructed from
- * the above arguments. */
+ Tk_Window tkwin, /* For display where font will be used. */
+ int faceNum, /* Macintosh font number. */
+ unsigned char *familyName, /* The font family name or NULL. */
+ int size, /* Point size for Macintosh font. */
+ int style, /* Macintosh style bits. */
+ MacFont *fontPtr) /* Filled with information constructed from
+ * the above arguments. */
{
Str255 nativeName;
FontInfo fi;
TkFontAttributes *faPtr;
TkFontMetrics *fmPtr;
- CGrafPtr saveWorld;
- GDHandle saveDevice;
+ CGrafPtr savePort;
+ Boolean portChanged;
short pixels;
if (size == 0) {
- size = -GetDefFontSize();
+ size = -GetDefFontSize();
}
pixels = (short) TkFontGetPixels(tkwin, size);
-
- GetGWorld(&saveWorld, &saveDevice);
- SetGWorld(gWorld, NULL);
+
+ portChanged = QDSwapPort(gWorld, &savePort);
TextFont(faceNum);
-
-
TextSize(pixels);
TextFace(style);
GetFontInfo(&fi);
- GetFontName(faceNum, nativeName);
- fontPtr->font.fid = (Font) fontPtr;
-
+ if (!familyName) {
+ GetFontName(faceNum, nativeName);
+ familyName = nativeName;
+ }
+ fontPtr->font.fid = (Font) fontPtr;
+
faPtr = &fontPtr->font.fa;
- faPtr->family = GetUtfFaceName(nativeName);
+ faPtr->family = GetUtfFaceName(familyName);
faPtr->size = TkFontGetPoints(tkwin, size);
faPtr->weight = (style & bold) ? TK_FW_BOLD : TK_FW_NORMAL;
faPtr->slant = (style & italic) ? TK_FS_ITALIC : TK_FS_ROMAN;
faPtr->underline = ((style & underline) != 0);
faPtr->overstrike = 0;
-
+
fmPtr = &fontPtr->font.fm;
- fmPtr->ascent = fi.ascent;
- fmPtr->descent = fi.descent;
+ fmPtr->ascent = fi.ascent;
+ fmPtr->descent = fi.descent;
fmPtr->maxWidth = fi.widMax;
fmPtr->fixed = (CharWidth('i') == CharWidth('w'));
-
+
fontPtr->size = pixels;
fontPtr->style = (short) style;
-
+
fontPtr->numSubFonts = 1;
fontPtr->subFontArray = fontPtr->staticSubFonts;
InitSubFont(fontPtr, faceNum, &fontPtr->subFontArray[0]);
- SetGWorld(saveWorld, saveDevice);
+ if (portChanged) {
+ QDSwapPort(savePort, NULL);
+ }
}
/*
*-------------------------------------------------------------------------
*
* ReleaseFont --
- *
- * Called to release the Macintosh-specific contents of a TkFont.
- * The caller is responsible for freeing the memory used by the
- * font itself.
+ *
+ * Called to release the Macintosh-specific contents of a TkFont.
+ * The caller is responsible for freeing the memory used by the
+ * font itself.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Memory is freed.
+ * Memory is freed.
*
*---------------------------------------------------------------------------
*/
-
+
static void
ReleaseFont(
- MacFont *fontPtr) /* The font to delete. */
+ MacFont *fontPtr) /* The font to delete. */
{
int i;
for (i = 0; i < fontPtr->numSubFonts; i++) {
- ReleaseSubFont(&fontPtr->subFontArray[i]);
+ ReleaseSubFont(&fontPtr->subFontArray[i]);
}
if (fontPtr->subFontArray != fontPtr->staticSubFonts) {
- ckfree((char *) fontPtr->subFontArray);
+ ckfree((char *) fontPtr->subFontArray);
}
}
@@ -1299,26 +1299,26 @@ ReleaseFont(
*
* InitSubFont --
*
- * Wrap a screen font and load the FontFamily that represents
- * it. Used to prepare a SubFont so that characters can be mapped
- * from UTF-8 to the charset of the font.
+ * Wrap a screen font and load the FontFamily that represents
+ * it. Used to prepare a SubFont so that characters can be mapped
+ * from UTF-8 to the charset of the font.
*
* Results:
- * The subFontPtr is filled with information about the font.
+ * The subFontPtr is filled with information about the font.
*
* Side effects:
- * None.
+ * None.
*
*-------------------------------------------------------------------------
*/
static void
InitSubFont(
- CONST MacFont *fontPtr, /* Font object in which the SubFont will be
- * used. */
- int faceNum, /* The font number. */
- SubFont *subFontPtr) /* Filled with SubFont constructed from
- * above attributes. */
+ const MacFont *fontPtr, /* Font object in which the SubFont will be
+ * used. */
+ int faceNum, /* The font number. */
+ SubFont *subFontPtr) /* Filled with SubFont constructed from
+ * above attributes. */
{
subFontPtr->familyPtr = AllocFontFamily(fontPtr, faceNum);
subFontPtr->fontMap = subFontPtr->familyPtr->fontMap;
@@ -1329,21 +1329,21 @@ InitSubFont(
*
* ReleaseSubFont --
*
- * Called to release the contents of a SubFont. The caller is
- * responsible for freeing the memory used by the SubFont itself.
+ * Called to release the contents of a SubFont. The caller is
+ * responsible for freeing the memory used by the SubFont itself.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Memory and resources are freed.
+ * Memory and resources are freed.
*
*---------------------------------------------------------------------------
*/
static void
ReleaseSubFont(
- SubFont *subFontPtr) /* The SubFont to delete. */
+ SubFont *subFontPtr) /* The SubFont to delete. */
{
FreeFontFamily(subFontPtr->familyPtr);
}
@@ -1353,39 +1353,39 @@ ReleaseSubFont(
*
* AllocFontFamily --
*
- * Find the FontFamily structure associated with the given font
- * family. The information should be stored by the caller in a
- * SubFont and used when determining if that SubFont supports a
- * character.
+ * Find the FontFamily structure associated with the given font
+ * family. The information should be stored by the caller in a
+ * SubFont and used when determining if that SubFont supports a
+ * character.
*
* Results:
- * A pointer to a FontFamily. The reference count in the FontFamily
- * is automatically incremented. When the SubFont is released, the
- * reference count is decremented. When no SubFont is using this
- * FontFamily, it may be deleted.
+ * A pointer to a FontFamily. The reference count in the FontFamily
+ * is automatically incremented. When the SubFont is released, the
+ * reference count is decremented. When no SubFont is using this
+ * FontFamily, it may be deleted.
*
* Side effects:
- * A new FontFamily structure will be allocated if this font family
- * has not been seen.
+ * A new FontFamily structure will be allocated if this font family
+ * has not been seen.
*
*-------------------------------------------------------------------------
*/
static FontFamily *
AllocFontFamily(
- CONST MacFont *fontPtr, /* Font object in which the FontFamily will
- * be used. */
- int faceNum) /* The font number. */
+ const MacFont *fontPtr, /* Font object in which the FontFamily will
+ * be used. */
+ int faceNum) /* The font number. */
{
FontFamily *familyPtr;
int i;
-
+
familyPtr = fontFamilyList;
for (; familyPtr != NULL; familyPtr = familyPtr->nextPtr) {
- if (familyPtr->faceNum == faceNum) {
- familyPtr->refCount++;
- return familyPtr;
- }
+ if (familyPtr->faceNum == faceNum) {
+ familyPtr->refCount++;
+ return familyPtr;
+ }
}
familyPtr = (FontFamily *) ckalloc(sizeof(FontFamily));
@@ -1393,27 +1393,27 @@ AllocFontFamily(
familyPtr->nextPtr = fontFamilyList;
fontFamilyList = familyPtr;
- /*
- * Set key for this FontFamily.
+ /*
+ * Set key for this FontFamily.
*/
-
+
familyPtr->faceNum = faceNum;
- /*
+ /*
* An initial refCount of 2 means that FontFamily information will
* persist even when the SubFont that loaded the FontFamily is released.
* Change it to 1 to cause FontFamilies to be unloaded when not in use.
*/
-
+
familyPtr->refCount = 2;
familyPtr->encoding = GetFontEncoding(faceNum, 1, &familyPtr->isSymbolFont);
familyPtr->isMultiByteFont = 0;
FillParseTable(familyPtr->typeTable, FontToScript(faceNum));
for (i = 0; i < 256; i++) {
- if (familyPtr->typeTable[i] != 0) {
- familyPtr->isMultiByteFont = 1;
- break;
- }
+ if (familyPtr->typeTable[i] != 0) {
+ familyPtr->isMultiByteFont = 1;
+ break;
+ }
}
return familyPtr;
}
@@ -1423,52 +1423,52 @@ AllocFontFamily(
*
* FreeFontFamily --
*
- * Called to free a FontFamily when the SubFont is finished using it.
- * Frees the contents of the FontFamily and the memory used by the
- * FontFamily itself.
+ * Called to free a FontFamily when the SubFont is finished using it.
+ * Frees the contents of the FontFamily and the memory used by the
+ * FontFamily itself.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * None.
+ * None.
*
*-------------------------------------------------------------------------
*/
-
+
static void
FreeFontFamily(
- FontFamily *familyPtr) /* The FontFamily to delete. */
+ FontFamily *familyPtr) /* The FontFamily to delete. */
{
FontFamily **familyPtrPtr;
int i;
if (familyPtr == NULL) {
- return;
+ return;
}
familyPtr->refCount--;
if (familyPtr->refCount > 0) {
- return;
+ return;
}
Tcl_FreeEncoding(familyPtr->encoding);
for (i = 0; i < FONTMAP_PAGES; i++) {
- if (familyPtr->fontMap[i] != NULL) {
- ckfree((char *) familyPtr->fontMap[i]);
- }
+ if (familyPtr->fontMap[i] != NULL) {
+ ckfree((char *) familyPtr->fontMap[i]);
+ }
}
-
- /*
- * Delete from list.
+
+ /*
+ * Delete from list.
*/
-
+
for (familyPtrPtr = &fontFamilyList; ; ) {
- if (*familyPtrPtr == familyPtr) {
- *familyPtrPtr = familyPtr->nextPtr;
- break;
- }
- familyPtrPtr = &(*familyPtrPtr)->nextPtr;
+ if (*familyPtrPtr == familyPtr) {
+ *familyPtrPtr = familyPtr->nextPtr;
+ break;
+ }
+ familyPtrPtr = &(*familyPtrPtr)->nextPtr;
}
-
+
ckfree((char *) familyPtr);
}
@@ -1477,115 +1477,115 @@ FreeFontFamily(
*
* FindSubFontForChar --
*
- * Determine which physical screen font is necessary to use to
- * display the given character. If the font object does not have
- * a screen font that can display the character, another screen font
- * may be loaded into the font object, following a set of preferred
- * fallback rules.
+ * Determine which physical screen font is necessary to use to
+ * display the given character. If the font object does not have
+ * a screen font that can display the character, another screen font
+ * may be loaded into the font object, following a set of preferred
+ * fallback rules.
*
* Results:
- * The return value is the SubFont to use to display the given
- * character.
+ * The return value is the SubFont to use to display the given
+ * character.
*
* Side effects:
- * The contents of fontPtr are modified to cache the results
- * of the lookup and remember any SubFonts that were dynamically
- * loaded. The table of SubFonts might be extended, and if a non-NULL
- * reference to a subfont pointer is available, it is updated if it
- * previously pointed into the old subfont table.
+ * The contents of fontPtr are modified to cache the results
+ * of the lookup and remember any SubFonts that were dynamically
+ * loaded. The table of SubFonts might be extended, and if a non-NULL
+ * reference to a subfont pointer is available, it is updated if it
+ * previously pointed into the old subfont table.
*
*-------------------------------------------------------------------------
*/
static SubFont *
FindSubFontForChar(
- MacFont *fontPtr, /* The font object with which the character
- * will be displayed. */
- int ch, /* The Unicode character to be displayed. */
- SubFont **fixSubFontPtrPtr) /* Subfont reference to fix up if we
+ MacFont *fontPtr, /* The font object with which the character
+ * will be displayed. */
+ int ch, /* The Unicode character to be displayed. */
+ SubFont **fixSubFontPtrPtr) /* Subfont reference to fix up if we
* reallocate our subfont table. */
{
int i, j, k;
- CONST char *fallbackName;
+ const char *fallbackName;
char **aliases;
SubFont *subFontPtr;
FontNameMap *mapPtr;
Tcl_DString faceNames;
char ***fontFallbacks;
char **anyFallbacks;
-
+
if (FontMapLookup(&fontPtr->subFontArray[0], ch)) {
- return &fontPtr->subFontArray[0];
+ return &fontPtr->subFontArray[0];
}
for (i = 1; i < fontPtr->numSubFonts; i++) {
- if (FontMapLookup(&fontPtr->subFontArray[i], ch)) {
- return &fontPtr->subFontArray[i];
- }
+ if (FontMapLookup(&fontPtr->subFontArray[i], ch)) {
+ return &fontPtr->subFontArray[i];
+ }
}
/*
* Keep track of all face names that we check, so we don't check some
* name multiple times if it can be reached by multiple paths.
*/
-
+
Tcl_DStringInit(&faceNames);
-
+
aliases = TkFontGetAliasList(fontPtr->font.fa.family);
subFontPtr = NULL;
fontFallbacks = TkFontGetFallbacks();
for (i = 0; fontFallbacks[i] != NULL; i++) {
- for (j = 0; fontFallbacks[i][j] != NULL; j++) {
- fallbackName = fontFallbacks[i][j];
- if (strcasecmp(fallbackName, fontPtr->font.fa.family) == 0) {
- /*
- * If the base font has a fallback...
- */
-
- goto tryfallbacks;
- } else if (aliases != NULL) {
- /*
- * Or if an alias for the base font has a fallback...
- */
-
- for (k = 0; aliases[k] != NULL; k++) {
- if (strcasecmp(aliases[k], fallbackName) == 0) {
- goto tryfallbacks;
- }
- }
- }
- }
- continue;
-
- /*
- * ...then see if we can use one of the fallbacks, or an
- * alias for one of the fallbacks.
- */
-
- tryfallbacks:
- for (j = 0; fontFallbacks[i][j] != NULL; j++) {
- fallbackName = fontFallbacks[i][j];
- subFontPtr = CanUseFallbackWithAliases(fontPtr, fallbackName,
- ch, &faceNames, fixSubFontPtrPtr);
- if (subFontPtr != NULL) {
- goto end;
- }
- }
+ for (j = 0; fontFallbacks[i][j] != NULL; j++) {
+ fallbackName = fontFallbacks[i][j];
+ if (strcasecmp(fallbackName, fontPtr->font.fa.family) == 0) {
+ /*
+ * If the base font has a fallback...
+ */
+
+ goto tryfallbacks;
+ } else if (aliases != NULL) {
+ /*
+ * Or if an alias for the base font has a fallback...
+ */
+
+ for (k = 0; aliases[k] != NULL; k++) {
+ if (strcasecmp(aliases[k], fallbackName) == 0) {
+ goto tryfallbacks;
+ }
+ }
+ }
+ }
+ continue;
+
+ /*
+ * ...then see if we can use one of the fallbacks, or an
+ * alias for one of the fallbacks.
+ */
+
+ tryfallbacks:
+ for (j = 0; fontFallbacks[i][j] != NULL; j++) {
+ fallbackName = fontFallbacks[i][j];
+ subFontPtr = CanUseFallbackWithAliases(fontPtr, fallbackName,
+ ch, &faceNames, fixSubFontPtrPtr);
+ if (subFontPtr != NULL) {
+ goto end;
+ }
+ }
}
-
+
/*
- * See if we can use something from the global fallback list.
+ * See if we can use something from the global fallback list.
*/
anyFallbacks = TkFontGetGlobalClass();
for (i = 0; anyFallbacks[i] != NULL; i++) {
- fallbackName = anyFallbacks[i];
- subFontPtr = CanUseFallbackWithAliases(fontPtr, fallbackName, ch,
- &faceNames, fixSubFontPtrPtr);
- if (subFontPtr != NULL) {
- goto end;
- }
+ fallbackName = anyFallbacks[i];
+ subFontPtr = CanUseFallbackWithAliases(fontPtr, fallbackName, ch,
+ &faceNames, fixSubFontPtrPtr);
+ if (subFontPtr != NULL) {
+ goto end;
+ }
}
/*
@@ -1594,27 +1594,27 @@ FindSubFontForChar(
*/
for (mapPtr = gFontNameMap; mapPtr->utfName != NULL; mapPtr++) {
- fallbackName = mapPtr->utfName;
- if (SeenName(fallbackName, &faceNames) == 0) {
+ fallbackName = mapPtr->utfName;
+ if (SeenName(fallbackName, &faceNames) == 0) {
subFontPtr = CanUseFallback(fontPtr, fallbackName, ch,
fixSubFontPtrPtr);
- if (subFontPtr != NULL) {
- goto end;
- }
- }
+ if (subFontPtr != NULL) {
+ goto end;
+ }
+ }
}
-
+
end:
Tcl_DStringFree(&faceNames);
-
+
if (subFontPtr == NULL) {
- /*
- * No font can display this character. We will use the base font
- * and have it display the "unknown" character.
- */
+ /*
+ * No font can display this character. We will use the base font
+ * and have it display the "unknown" character.
+ */
- subFontPtr = &fontPtr->subFontArray[0];
- FontMapInsert(subFontPtr, ch);
+ subFontPtr = &fontPtr->subFontArray[0];
+ FontMapInsert(subFontPtr, ch);
}
return subFontPtr;
}
@@ -1624,33 +1624,33 @@ FindSubFontForChar(
*
* FontMapLookup --
*
- * See if the screen font can display the given character.
+ * See if the screen font can display the given character.
*
* Results:
- * The return value is 0 if the screen font cannot display the
- * character, non-zero otherwise.
+ * The return value is 0 if the screen font cannot display the
+ * character, non-zero otherwise.
*
* Side effects:
- * New pages are added to the font mapping cache whenever the
- * character belongs to a page that hasn't been seen before.
- * When a page is loaded, information about all the characters on
- * that page is stored, not just for the single character in
- * question.
+ * New pages are added to the font mapping cache whenever the
+ * character belongs to a page that hasn't been seen before.
+ * When a page is loaded, information about all the characters on
+ * that page is stored, not just for the single character in
+ * question.
*
*-------------------------------------------------------------------------
*/
static int
FontMapLookup(
- SubFont *subFontPtr, /* Contains font mapping cache to be queried
- * and possibly updated. */
- int ch) /* Character to be tested. */
+ SubFont *subFontPtr, /* Contains font mapping cache to be queried
+ * and possibly updated. */
+ int ch) /* Character to be tested. */
{
int row, bitOffset;
row = ch >> FONTMAP_SHIFT;
if (subFontPtr->fontMap[row] == NULL) {
- FontMapLoadPage(subFontPtr, row);
+ FontMapLoadPage(subFontPtr, row);
}
bitOffset = ch & (FONTMAP_BITSPERPAGE - 1);
return (subFontPtr->fontMap[row][bitOffset >> 3] >> (bitOffset & 7)) & 1;
@@ -1661,37 +1661,37 @@ FontMapLookup(
*
* FontMapInsert --
*
- * Tell the font mapping cache that the given screen font should be
- * used to display the specified character. This is called when no
- * font on the system can be be found that can display that
- * character; we lie to the font and tell it that it can display
- * the character, otherwise we would end up re-searching the entire
- * fallback hierarchy every time that character was seen.
+ * Tell the font mapping cache that the given screen font should be
+ * used to display the specified character. This is called when no
+ * font on the system can be be found that can display that
+ * character; we lie to the font and tell it that it can display
+ * the character, otherwise we would end up re-searching the entire
+ * fallback hierarchy every time that character was seen.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * New pages are added to the font mapping cache whenever the
- * character belongs to a page that hasn't been seen before.
- * When a page is loaded, information about all the characters on
- * that page is stored, not just for the single character in
- * question.
+ * New pages are added to the font mapping cache whenever the
+ * character belongs to a page that hasn't been seen before.
+ * When a page is loaded, information about all the characters on
+ * that page is stored, not just for the single character in
+ * question.
*
*-------------------------------------------------------------------------
*/
static void
FontMapInsert(
- SubFont *subFontPtr, /* Contains font mapping cache to be
- * updated. */
- int ch) /* Character to be added to cache. */
+ SubFont *subFontPtr, /* Contains font mapping cache to be
+ * updated. */
+ int ch) /* Character to be added to cache. */
{
int row, bitOffset;
row = ch >> FONTMAP_SHIFT;
if (subFontPtr->fontMap[row] == NULL) {
- FontMapLoadPage(subFontPtr, row);
+ FontMapLoadPage(subFontPtr, row);
}
bitOffset = ch & (FONTMAP_BITSPERPAGE - 1);
subFontPtr->fontMap[row][bitOffset >> 3] |= 1 << (bitOffset & 7);
@@ -1702,25 +1702,25 @@ FontMapInsert(
*
* FontMapLoadPage --
*
- * Load information about all the characters on a given page.
- * This information consists of one bit per character that indicates
- * whether the associated HFONT can (1) or cannot (0) display the
- * characters on the page.
+ * Load information about all the characters on a given page.
+ * This information consists of one bit per character that indicates
+ * whether the associated HFONT can (1) or cannot (0) display the
+ * characters on the page.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Mempry allocated.
+ * Mempry allocated.
*
*-------------------------------------------------------------------------
*/
-static void
+static void
FontMapLoadPage(
- SubFont *subFontPtr, /* Contains font mapping cache to be
- * updated. */
- int row) /* Index of the page to be loaded into
- * the cache. */
+ SubFont *subFontPtr, /* Contains font mapping cache to be
+ * updated. */
+ int row) /* Index of the page to be loaded into
+ * the cache. */
{
FMInput fm;
FMOutPtr fmOut;
@@ -1733,9 +1733,9 @@ FontMapLoadPage(
subFontPtr->fontMap[row] = (char *) ckalloc(FONTMAP_BITSPERPAGE / 8);
memset(subFontPtr->fontMap[row], 0, FONTMAP_BITSPERPAGE / 8);
-
+
encoding = subFontPtr->familyPtr->encoding;
-
+
fm.family = subFontPtr->familyPtr->faceNum;
fm.size = 12;
fm.face = 0;
@@ -1745,82 +1745,33 @@ FontMapLoadPage(
fm.numer.v = 1;
fm.denom.h = 1;
fm.denom.v = 1;
- /*
-#if !defined(UNIVERSAL_INTERFACES_VERSION) || (UNIVERSAL_INTERFACES_VERSION < 0x0300)
- fHandle = FMSwapFont(&fm)->fontHandle;
-#else
- fHandle = FMSwapFont(&fm)->fontHandle;
-#endif
-*/
+
/*
* For some reason, FMSwapFont alywas returns a structure where the returned font handle
* is NULL. Until we figure this one out, assume all characters are allowed
*/
+
fmOut = FMSwapFont(&fm);
fHandle = fmOut->fontHandle;
isMultiByteFont = subFontPtr->familyPtr->isMultiByteFont;
-#ifndef MAC_OSX_TK
- GetResInfo(fHandle, &theID, &theType, theName);
- fprintf ( stderr, "ResError() %d, %x\n", ResError (), fHandle );
- if (theType == 'sfnt') {
-#endif
- /*
- * Found an outline font which has very complex font record.
- * Let's just assume *ALL* the characters are allowed.
- */
-
- end = (row + 1) << FONTMAP_SHIFT;
- for (i = row << FONTMAP_SHIFT; i < end; i++) {
- if (Tcl_UtfToExternal(NULL, encoding, src, Tcl_UniCharToUtf(i,
- src),
- TCL_ENCODING_STOPONERROR, NULL, (char *) buf,
- sizeof(buf),
- &srcRead, &dstWrote, NULL) == TCL_OK) {
- bitOffset = i & (FONTMAP_BITSPERPAGE - 1);
- subFontPtr->fontMap[row][bitOffset >> 3] |= 1
- << (bitOffset & 7);
- }
- }
-#ifndef MAC_OSX_TK
- } else {
- /*
- * Found an old bitmap font which has a well-defined record.
- * We can check the width table to see which characters exist.
- */
-
- fontRecPtr = *((FontRec **) fHandle );
- widths = (short *) ((long) &fontRecPtr->owTLoc
- + ((long) (fontRecPtr->owTLoc - fontRecPtr->firstChar)
- * sizeof(short)));
-
- end = (row + 1) << FONTMAP_SHIFT;
- for (i = row << FONTMAP_SHIFT; i < end; i++) {
- if (Tcl_UtfToExternal(NULL, encoding, src,
- Tcl_UniCharToUtf(i, src),
- TCL_ENCODING_STOPONERROR, NULL, (char *) buf, sizeof(buf),
- &srcRead, &dstWrote, NULL) == TCL_OK) {
-
- if (((isMultiByteFont != 0) && (buf[0] > 31))
- || (widths[buf[0]] != -1)) {
- if ((buf[0] == 0x11) && (widths[0x12] == -1)) {
- continue;
- }
-
- /*
- * Mac's char existence metrics are only for one-byte
- * characters. If we have a double-byte char, just
- * assume that the font supports that char if the font's
- * encoding supports that char.
- */
-
- bitOffset = i & (FONTMAP_BITSPERPAGE - 1);
- subFontPtr->fontMap[row][bitOffset >> 3] |= 1
- << (bitOffset & 7);
- }
- }
- }
- }
-#endif
+
+ /*
+ * Found an outline font which has very complex font record.
+ * Let's just assume *ALL* the characters are allowed.
+ */
+
+ end = (row + 1) << FONTMAP_SHIFT;
+ for (i = row << FONTMAP_SHIFT; i < end; i++) {
+ if (Tcl_UtfToExternal(NULL, encoding, src, Tcl_UniCharToUtf(i,
+ src),
+ TCL_ENCODING_STOPONERROR, NULL, (char *) buf,
+ sizeof(buf),
+ &srcRead, &dstWrote, NULL) == TCL_OK) {
+ bitOffset = i & (FONTMAP_BITSPERPAGE - 1);
+ subFontPtr->fontMap[row][bitOffset >> 3] |= 1
+ << (bitOffset & 7);
+ }
+ }
}
/*
@@ -1828,59 +1779,59 @@ FontMapLoadPage(
*
* CanUseFallbackWithAliases --
*
- * Helper function for FindSubFontForChar. Determine if the
- * specified face name (or an alias of the specified face name)
- * can be used to construct a screen font that can display the
- * given character.
+ * Helper function for FindSubFontForChar. Determine if the
+ * specified face name (or an alias of the specified face name)
+ * can be used to construct a screen font that can display the
+ * given character.
*
* Results:
- * See CanUseFallback().
+ * See CanUseFallback().
*
* Side effects:
- * If the name and/or one of its aliases was rejected, the
- * rejected string is recorded in nameTriedPtr so that it won't
- * be tried again. The table of SubFonts might be extended, and if
- * a non-NULL reference to a subfont pointer is available, it is
- * updated if it previously pointed into the old subfont table.
+ * If the name and/or one of its aliases was rejected, the
+ * rejected string is recorded in nameTriedPtr so that it won't
+ * be tried again. The table of SubFonts might be extended, and if
+ * a non-NULL reference to a subfont pointer is available, it is
+ * updated if it previously pointed into the old subfont table.
*
*---------------------------------------------------------------------------
*/
static SubFont *
CanUseFallbackWithAliases(
- MacFont *fontPtr, /* The font object that will own the new
- * screen font. */
- CONST char *faceName, /* Desired face name for new screen font. */
- int ch, /* The Unicode character that the new
- * screen font must be able to display. */
- Tcl_DString *nameTriedPtr, /* Records face names that have already
- * been tried. It is possible for the same
- * face name to be queried multiple times when
- * trying to find a suitable screen font. */
- SubFont **fixSubFontPtrPtr) /* Subfont reference to fix up if we
+ MacFont *fontPtr, /* The font object that will own the new
+ * screen font. */
+ const char *faceName, /* Desired face name for new screen font. */
+ int ch, /* The Unicode character that the new
+ * screen font must be able to display. */
+ Tcl_DString *nameTriedPtr, /* Records face names that have already
+ * been tried. It is possible for the same
+ * face name to be queried multiple times when
+ * trying to find a suitable screen font. */
+ SubFont **fixSubFontPtrPtr) /* Subfont reference to fix up if we
* reallocate our subfont table. */
{
SubFont *subFontPtr;
char **aliases;
int i;
-
+
if (SeenName(faceName, nameTriedPtr) == 0) {
subFontPtr = CanUseFallback(fontPtr, faceName, ch, fixSubFontPtrPtr);
- if (subFontPtr != NULL) {
- return subFontPtr;
- }
+ if (subFontPtr != NULL) {
+ return subFontPtr;
+ }
}
aliases = TkFontGetAliasList(faceName);
if (aliases != NULL) {
- for (i = 0; aliases[i] != NULL; i++) {
- if (SeenName(aliases[i], nameTriedPtr) == 0) {
+ for (i = 0; aliases[i] != NULL; i++) {
+ if (SeenName(aliases[i], nameTriedPtr) == 0) {
subFontPtr = CanUseFallback(fontPtr, aliases[i], ch,
fixSubFontPtrPtr);
- if (subFontPtr != NULL) {
- return subFontPtr;
- }
- }
- }
+ if (subFontPtr != NULL) {
+ return subFontPtr;
+ }
+ }
+ }
}
return NULL;
}
@@ -1890,35 +1841,35 @@ CanUseFallbackWithAliases(
*
* SeenName --
*
- * Used to determine we have already tried and rejected the given
- * face name when looking for a screen font that can support some
- * Unicode character.
+ * Used to determine we have already tried and rejected the given
+ * face name when looking for a screen font that can support some
+ * Unicode character.
*
* Results:
- * The return value is 0 if this face name has not already been seen,
- * non-zero otherwise.
+ * The return value is 0 if this face name has not already been seen,
+ * non-zero otherwise.
*
* Side effects:
- * None.
+ * None.
*
*---------------------------------------------------------------------------
*/
static int
SeenName(
- CONST char *name, /* The name to check. */
- Tcl_DString *dsPtr) /* Contains names that have already been
- * seen. */
+ const char *name, /* The name to check. */
+ Tcl_DString *dsPtr) /* Contains names that have already been
+ * seen. */
{
- CONST char *seen, *end;
+ const char *seen, *end;
seen = Tcl_DStringValue(dsPtr);
end = seen + Tcl_DStringLength(dsPtr);
while (seen < end) {
- if (strcasecmp(seen, name) == 0) {
- return 1;
- }
- seen += strlen(seen) + 1;
+ if (strcasecmp(seen, name) == 0) {
+ return 1;
+ }
+ seen += strlen(seen) + 1;
}
Tcl_DStringAppend(dsPtr, (char *) name, (int) (strlen(name) + 1));
return 0;
@@ -1929,37 +1880,37 @@ SeenName(
*
* CanUseFallback --
*
- * If the specified physical screen font has not already been loaded
- * into the font object, determine if the specified physical screen
- * font can display the given character.
+ * If the specified physical screen font has not already been loaded
+ * into the font object, determine if the specified physical screen
+ * font can display the given character.
*
* Results:
- * The return value is a pointer to a newly allocated SubFont, owned
- * by the font object. This SubFont can be used to display the given
- * character. The SubFont represents the screen font with the base set
- * of font attributes from the font object, but using the specified
- * font name. NULL is returned if the font object already holds
- * a reference to the specified physical font or if the specified
- * physical font cannot display the given character.
- *
- * Side effects:
- * The font object's subFontArray is updated to contain a reference
- * to the newly allocated SubFont. The table of SubFonts might be
- * extended, and if a non-NULL reference to a subfont pointer is
- * available, it is updated if it previously pointed into the old
- * subfont table.
+ * The return value is a pointer to a newly allocated SubFont, owned
+ * by the font object. This SubFont can be used to display the given
+ * character. The SubFont represents the screen font with the base set
+ * of font attributes from the font object, but using the specified
+ * font name. NULL is returned if the font object already holds
+ * a reference to the specified physical font or if the specified
+ * physical font cannot display the given character.
+ *
+ * Side effects:
+ * The font object's subFontArray is updated to contain a reference
+ * to the newly allocated SubFont. The table of SubFonts might be
+ * extended, and if a non-NULL reference to a subfont pointer is
+ * available, it is updated if it previously pointed into the old
+ * subfont table.
*
*-------------------------------------------------------------------------
*/
static SubFont *
CanUseFallback(
- MacFont *fontPtr, /* The font object that will own the new
- * screen font. */
- CONST char *faceName, /* Desired face name for new screen font. */
- int ch, /* The Unicode character that the new
- * screen font must be able to display. */
- SubFont **fixSubFontPtrPtr) /* Subfont reference to fix up if we
+ MacFont *fontPtr, /* The font object that will own the new
+ * screen font. */
+ const char *faceName, /* Desired face name for new screen font. */
+ int ch, /* The Unicode character that the new
+ * screen font must be able to display. */
+ SubFont **fixSubFontPtrPtr) /* Subfont reference to fix up if we
* reallocate our subfont table. */
{
int i;
@@ -1967,48 +1918,48 @@ CanUseFallback(
short faceNum;
if (GetFamilyNum(faceName, &faceNum) == 0) {
- return NULL;
+ return NULL;
}
-
- /*
+
+ /*
* Skip all fonts we've already used.
*/
-
+
for (i = 0; i < fontPtr->numSubFonts; i++) {
- if (faceNum == fontPtr->subFontArray[i].familyPtr->faceNum) {
- return NULL;
- }
+ if (faceNum == fontPtr->subFontArray[i].familyPtr->faceNum) {
+ return NULL;
+ }
}
-
+
/*
* Load this font and see if it has the desired character.
*/
-
+
InitSubFont(fontPtr, faceNum, &subFont);
- if (((ch < 256) && (subFont.familyPtr->isSymbolFont))
- || (FontMapLookup(&subFont, ch) == 0)) {
- ReleaseSubFont(&subFont);
- return NULL;
+ if (((ch < 256) && (subFont.familyPtr->isSymbolFont))
+ || (FontMapLookup(&subFont, ch) == 0)) {
+ ReleaseSubFont(&subFont);
+ return NULL;
}
-
+
if (fontPtr->numSubFonts >= SUBFONT_SPACE) {
- SubFont *newPtr;
- newPtr = (SubFont *) ckalloc(sizeof(SubFont)
- * (fontPtr->numSubFonts + 1));
- memcpy((char *) newPtr, fontPtr->subFontArray,
- fontPtr->numSubFonts * sizeof(SubFont));
+ SubFont *newPtr = (SubFont *) ckalloc(sizeof(SubFont)
+ * (fontPtr->numSubFonts + 1));
+ memcpy((char *) newPtr, fontPtr->subFontArray,
+ fontPtr->numSubFonts * sizeof(SubFont));
if (fixSubFontPtrPtr != NULL) {
- /*
- * Fix up the variable pointed to by fixSubFontPtrPtr so it
- * still points into the live array. [Bug 618872]
- */
- *fixSubFontPtrPtr =
- newPtr + (*fixSubFontPtrPtr - fontPtr->subFontArray);
+ /*
+ * Fix up the variable pointed to by fixSubFontPtrPtr so it
+ * still points into the live array. [Bug 618872]
+ */
+
+ *fixSubFontPtrPtr =
+ newPtr + (*fixSubFontPtrPtr - fontPtr->subFontArray);
}
- if (fontPtr->subFontArray != fontPtr->staticSubFonts) {
- ckfree((char *) fontPtr->subFontArray);
- }
- fontPtr->subFontArray = newPtr;
+ if (fontPtr->subFontArray != fontPtr->staticSubFonts) {
+ ckfree((char *) fontPtr->subFontArray);
+ }
+ fontPtr->subFontArray = newPtr;
}
fontPtr->subFontArray[fontPtr->numSubFonts] = subFont;
fontPtr->numSubFonts++;
@@ -2020,60 +1971,60 @@ CanUseFallback(
*
* GetFamilyNum --
*
- * Determines if any physical screen font exists on the system with
- * the given family name. If the family exists, then it should be
- * possible to construct some physical screen font with that family
- * name.
+ * Determines if any physical screen font exists on the system with
+ * the given family name. If the family exists, then it should be
+ * possible to construct some physical screen font with that family
+ * name.
*
* Results:
- * The return value is 0 if the specified font family does not exist,
- * non-zero otherwise. *faceNumPtr is filled with the unique face
- * number that identifies the screen font, or 0 if the font family
- * did not exist.
+ * The return value is 0 if the specified font family does not exist,
+ * non-zero otherwise. *faceNumPtr is filled with the unique face
+ * number that identifies the screen font, or 0 if the font family
+ * did not exist.
*
* Side effects:
- * None.
+ * None.
*
*-------------------------------------------------------------------------
*/
static int
GetFamilyNum(
- CONST char *faceName, /* UTF-8 name of font family to query. */
- short *faceNumPtr) /* Filled with font number for above family. */
+ const char *faceName, /* UTF-8 name of font family to query. */
+ short *faceNumPtr) /* Filled with font number for above family. */
{
FontNameMap *mapPtr;
-
+
if (faceName != NULL) {
- for (mapPtr = gFontNameMap; mapPtr->utfName != NULL; mapPtr++) {
- if (strcasecmp(faceName, mapPtr->utfName) == 0) {
- *faceNumPtr = mapPtr->faceNum;
- return 1;
- }
- }
+ for (mapPtr = gFontNameMap; mapPtr->utfName != NULL; mapPtr++) {
+ if (strcasecmp(faceName, mapPtr->utfName) == 0) {
+ *faceNumPtr = mapPtr->faceNum;
+ return 1;
+ }
+ }
}
- *faceNumPtr = 0;
+ *faceNumPtr = 0;
return 0;
}
static int
GetFamilyOrAliasNum(
- CONST char *faceName, /* UTF-8 name of font family to query. */
- short *faceNumPtr) /* Filled with font number for above family. */
+ const char *faceName, /* UTF-8 name of font family to query. */
+ short *faceNumPtr) /* Filled with font number for above family. */
{
char **aliases;
int i;
-
+
if (GetFamilyNum(faceName, faceNumPtr) != 0) {
- return 1;
+ return 1;
}
aliases = TkFontGetAliasList(faceName);
if (aliases != NULL) {
- for (i = 0; aliases[i] != NULL; i++) {
- if (GetFamilyNum(aliases[i], faceNumPtr) != 0) {
- return 1;
- }
- }
+ for (i = 0; aliases[i] != NULL; i++) {
+ if (GetFamilyNum(aliases[i], faceNumPtr) != 0) {
+ return 1;
+ }
+ }
}
return 0;
}
@@ -2083,33 +2034,33 @@ GetFamilyOrAliasNum(
*
* GetUtfFaceName --
*
- * Given the native name for a Macintosh font (in which the name of
- * the font is in the encoding of the font itself), return the UTF-8
- * name that corresponds to that font. The specified font name must
- * refer to a font that actually exists on the machine.
+ * Given the native name for a Macintosh font (in which the name of
+ * the font is in the encoding of the font itself), return the UTF-8
+ * name that corresponds to that font. The specified font name must
+ * refer to a font that actually exists on the machine.
*
- * This function is used to obtain the UTF-8 name when querying the
- * properties of a Macintosh font object.
+ * This function is used to obtain the UTF-8 name when querying the
+ * properties of a Macintosh font object.
*
* Results:
- * The return value is a pointer to the UTF-8 of the specified font.
+ * The return value is a pointer to the UTF-8 of the specified font.
*
* Side effects:
- * None.
+ * None.
*
*------------------------------------------------------------------------
*/
-
+
static Tk_Uid
GetUtfFaceName(
- StringPtr nativeName) /* Pascal name for font in native encoding. */
+ StringPtr nativeName) /* Pascal name for font in native encoding. */
{
FontNameMap *mapPtr;
-
+
for (mapPtr = gFontNameMap; mapPtr->utfName != NULL; mapPtr++) {
- if (pstrcmp(nativeName, mapPtr->nativeName) == 0) {
- return mapPtr->utfName;
- }
+ if (pstrcmp(nativeName, mapPtr->nativeName) == 0) {
+ return mapPtr->utfName;
+ }
}
Tcl_Panic("GetUtfFaceName: unexpected nativeName");
return NULL;
@@ -2120,64 +2071,64 @@ GetUtfFaceName(
*
* GetFontEncoding --
*
- * Return a string that can be passed to Tcl_GetTextEncoding() and
- * used to convert bytes from UTF-8 into the encoding of the
- * specified font.
+ * Return a string that can be passed to Tcl_GetTextEncoding() and
+ * used to convert bytes from UTF-8 into the encoding of the
+ * specified font.
*
- * The desired encoding to use to convert the name of a symbolic
- * font into UTF-8 is macRoman, while the desired encoding to use
- * to convert bytes in a symbolic font to UTF-8 is the corresponding
- * symbolic encoding. Due to this dual interpretatation of symbolic
- * fonts, the caller can specify what type of encoding to return
- * should the specified font be symbolic.
+ * The desired encoding to use to convert the name of a symbolic
+ * font into UTF-8 is macRoman, while the desired encoding to use
+ * to convert bytes in a symbolic font to UTF-8 is the corresponding
+ * symbolic encoding. Due to this dual interpretatation of symbolic
+ * fonts, the caller can specify what type of encoding to return
+ * should the specified font be symbolic.
*
* Results:
- * The return value is a string that specifies the font's encoding.
- * If the font's encoding could not be identified, NULL is returned.
+ * The return value is a string that specifies the font's encoding.
+ * If the font's encoding could not be identified, NULL is returned.
*
* Side effects:
- * None.
+ * None.
*
*------------------------------------------------------------------------
*/
-
+
static Tcl_Encoding
GetFontEncoding(
- int faceNum, /* Macintosh font number. */
- int allowSymbol, /* If non-zero, then the encoding string
- * for symbol fonts will be the corresponding
- * symbol encoding. Otherwise, the encoding
- * string for symbol fonts will be
- * "macRoman". */
- int *isSymbolPtr) /* Filled with non-zero if this font is a
- * symbol font, 0 otherwise. */
+ int faceNum, /* Macintosh font number. */
+ int allowSymbol, /* If non-zero, then the encoding string
+ * for symbol fonts will be the corresponding
+ * symbol encoding. Otherwise, the encoding
+ * string for symbol fonts will be
+ * "macRoman". */
+ int *isSymbolPtr) /* Filled with non-zero if this font is a
+ * symbol font, 0 otherwise. */
{
Str255 faceName;
int script, lang;
- char *name;
-
+ char *name;
+
if (allowSymbol != 0) {
- GetFontName(faceNum, faceName);
- if (pstrcasecmp(faceName, "\psymbol") == 0) {
- *isSymbolPtr = 1;
- return Tcl_GetEncoding(NULL, "symbol");
- }
- if (pstrcasecmp(faceName, "\pzapf dingbats") == 0) {
- *isSymbolPtr = 1;
- return Tcl_GetEncoding(NULL, "macDingbats");
- }
+ GetFontName(faceNum, faceName);
+ if (pstrcasecmp(faceName, "\psymbol") == 0) {
+ *isSymbolPtr = 1;
+ return Tcl_GetEncoding(NULL, "symbol");
+ }
+ if (pstrcasecmp(faceName, "\pzapf dingbats") == 0) {
+ *isSymbolPtr = 1;
+ return Tcl_GetEncoding(NULL, "macDingbats");
+ }
}
*isSymbolPtr = 0;
script = FontToScript(faceNum);
lang = GetScriptVariable(script, smScriptLang);
name = NULL;
if (script == smRoman) {
- name = TkFindStateString(romanMap, lang);
+ name = TkFindStateString(romanMap, lang);
} else if (script == smCyrillic) {
- name = TkFindStateString(cyrillicMap, lang);
+ name = TkFindStateString(cyrillicMap, lang);
}
if (name == NULL) {
- name = TkFindStateString(scriptMap, script);
+ name = TkFindStateString(scriptMap, script);
}
return Tcl_GetEncoding(NULL, name);
}
@@ -2200,17 +2151,18 @@ GetFontEncoding(
*/
void
-TkMacOSXInitControlFontStyle(Tk_Font tkfont, ControlFontStylePtr fsPtr)
+TkMacOSXInitControlFontStyle(
+ Tk_Font tkfont,
+ ControlFontStylePtr fsPtr)
{
- MacFont *fontPtr;
- FontFamily *lastFamilyPtr;
- fontPtr = (MacFont *) tkfont;
- lastFamilyPtr = fontPtr->subFontArray[0].familyPtr;
+ MacFont *fontPtr = (MacFont *) tkfont;
+ FontFamily *lastFamilyPtr = fontPtr->subFontArray[0].familyPtr;
+
fsPtr->flags =
- kControlUseFontMask|
- kControlUseSizeMask|
- kControlUseFaceMask|
- kControlUseJustMask;
+ kControlUseFontMask|
+ kControlUseSizeMask|
+ kControlUseFaceMask|
+ kControlUseJustMask;
fsPtr->font = lastFamilyPtr->faceNum;
fsPtr->size = fontPtr->size;
fsPtr->style = fontPtr->style;
@@ -2222,77 +2174,72 @@ TkMacOSXInitControlFontStyle(Tk_Font tkfont, ControlFontStylePtr fsPtr)
*
* TkMacOSXUseAntialiasedText --
*
- * Enables or disables application-wide use of quickdraw
- * antialiased text (where available).
- * Sets up a linked tcl global boolean variable with write trace
- * to allow disabling of antialiased text from tcl.
+ * Enables or disables application-wide use of quickdraw
+ * antialiased text (where available).
+ * Sets up a linked tcl global boolean variable with write trace
+ * to allow disabling of antialiased text from tcl.
*
* Results:
- * TCL_OK if facility was sucessfully enabled/disabled.
- * TCL_ERROR if an error occurred or if facility is not available.
+ * TCL_OK if facility was sucessfully enabled/disabled.
+ * TCL_ERROR if an error occurred or if facility is not available.
*
* Side effects:
- * None.
+ * None.
*
*----------------------------------------------------------------------
*/
-/* define constants from 10.2 Quickdraw.h to enable compilation in 10.1 */
-#define kQDUseTrueTypeScalerGlyphs (1 << 0)
-#define kQDUseCGTextRendering (1 << 1)
-#define kQDUseCGTextMetrics (1 << 2)
-
static int TkMacOSXAntialiasedTextEnabled = FALSE;
static char *
-TkMacOSXAntialiasedTextVariableProc(clientData, interp, name1, name2, flags)
- ClientData clientData;
- Tcl_Interp *interp;
- CONST char *name1;
- CONST char *name2;
- int flags;
+TkMacOSXAntialiasedTextVariableProc(
+ ClientData clientData,
+ Tcl_Interp *interp,
+ const char *name1,
+ const char *name2,
+ int flags)
{
TkMacOSXUseAntialiasedText(interp, TkMacOSXAntialiasedTextEnabled);
return (char *) NULL;
}
int
-TkMacOSXUseAntialiasedText(interp, enable)
- Tcl_Interp *interp;
- int enable;
+TkMacOSXUseAntialiasedText(
+ Tcl_Interp *interp,
+ int enable)
{
static Boolean initialized = FALSE;
static UInt32 (*swaptextflags)(UInt32) = NULL;
-
+
if(!initialized) {
- swaptextflags = TkMacOSXGetNamedSymbol("QD", "_QDSwapTextFlags");
- if (!swaptextflags) {
- swaptextflags = TkMacOSXGetNamedSymbol("QD", "_SwapQDTextFlags");
- }
- initialized = TRUE;
-
- TkMacOSXAntialiasedTextEnabled = (swaptextflags ? enable : FALSE);
- if (Tcl_CreateNamespace(interp, "::tk::mac", NULL, NULL) == NULL) {
- Tcl_ResetResult(interp);
- }
- if (Tcl_TraceVar(interp, "::tk::mac::antialiasedtext",
- TCL_GLOBAL_ONLY | TCL_TRACE_WRITES,
- TkMacOSXAntialiasedTextVariableProc, NULL) != TCL_OK) {
- Tcl_ResetResult(interp);
- }
- if (Tcl_LinkVar(interp, "::tk::mac::antialiasedtext",
- (char *) &TkMacOSXAntialiasedTextEnabled,
- TCL_LINK_BOOLEAN) != TCL_OK) {
- Tcl_ResetResult(interp);
- }
+ swaptextflags = TkMacOSXGetNamedSymbol("QD", "_QDSwapTextFlags");
+ if (!swaptextflags) {
+ swaptextflags = TkMacOSXGetNamedSymbol("QD", "_SwapQDTextFlags");
+ }
+ initialized = TRUE;
+
+ TkMacOSXAntialiasedTextEnabled = (swaptextflags ? enable : FALSE);
+ if (Tcl_CreateNamespace(interp, "::tk::mac", NULL, NULL) == NULL) {
+ Tcl_ResetResult(interp);
+ }
+ if (Tcl_TraceVar(interp, "::tk::mac::antialiasedtext",
+ TCL_GLOBAL_ONLY | TCL_TRACE_WRITES,
+ TkMacOSXAntialiasedTextVariableProc, NULL) != TCL_OK) {
+ Tcl_ResetResult(interp);
+ }
+ if (Tcl_LinkVar(interp, "::tk::mac::antialiasedtext",
+ (char *) &TkMacOSXAntialiasedTextEnabled,
+ TCL_LINK_BOOLEAN) != TCL_OK) {
+ Tcl_ResetResult(interp);
+ }
}
if (swaptextflags) {
- swaptextflags(enable ? kQDUseCGTextRendering | kQDUseCGTextMetrics
- : kQDUseTrueTypeScalerGlyphs);
- TkMacOSXAntialiasedTextEnabled = enable;
- return TCL_OK;
+ swaptextflags(enable ? kQDUseCGTextRendering | kQDUseCGTextMetrics
+ : kQDUseTrueTypeScalerGlyphs);
+ TkMacOSXAntialiasedTextEnabled = enable;
+ return TCL_OK;
} else {
- TkMacOSXAntialiasedTextEnabled = FALSE;
- return TCL_ERROR;
+ TkMacOSXAntialiasedTextEnabled = FALSE;
+ return TCL_ERROR;
}
}