diff options
author | das <das> | 2007-04-23 21:24:32 (GMT) |
---|---|---|
committer | das <das> | 2007-04-23 21:24:32 (GMT) |
commit | 11dbb8af58fd851913e5c781e3164e8211e93745 (patch) | |
tree | 1a0bc7c114e940c5e46d3704ac14fb34f4cc029e /macosx/tkMacOSXFont.c | |
parent | 24b160e09ae3ca4b52502fe59ddcd5fc80e00713 (diff) | |
download | tk-11dbb8af58fd851913e5c781e3164e8211e93745.zip tk-11dbb8af58fd851913e5c781e3164e8211e93745.tar.gz tk-11dbb8af58fd851913e5c781e3164e8211e93745.tar.bz2 |
* macosx/tkMacOSXCarbonEvents.c: add window event target carbon event
* macosx/tkMacOSXEvent.c: handler for all kEventClassWindow and
* macosx/tkMacOSXEvent.h: kEventClassMouse events;
* macosx/tkMacOSXNotify.c: move all 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
* macosx/ttkMacOSXTheme.c: 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
* macosx/ttkMacOSXTheme.c: 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; always draw with CG; remove QD
dependent stippling algorithm; move most header declarations into the
source file (as they were not used anywhere else).
* macosx/tkMacOSXMenu.c: large-scale rewrite of custom
* macosx/tkMacOSXMenu.r (removed): MDEF and related code that
* macosx/Wish.xcode/project.pbxproj: restores many longtime-MIA
* macosx/Wish.xcodeproj/project.pbxproj: features to working order
* unix/Makefile.in: (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/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/ttkMacOSXTheme.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/Wish-Common.xcconfig: add Wish's Info.plist as __info_plist
section to tktest; enable more warnings.
* macosx/Wish.xcodeproj/project.pbxproj: add 'DebugMemCompile' build
configuration that calls configure with --enable-symbols=all; disable
configure check for __attribute__((__visibility__("hidden"))) in Debug
configuration to restore availability of ZeroLink.
* macosx/Wish-Common.xcconfig: fix whitespace.
* macosx/Wish-Debug.xcconfig:
* macosx/Wish-Release.xcconfig:
* macosx/tkMacOSXAETE.r:
* macosx/tkMacOSXConfig.c:
* macosx/tkMacOSXCursors.r:
* macosx/tkMacOSXKeyboard.c:
* macosx/tkMacOSXSend.c:
* macosx/ttkMacOSXTheme.c:
* macosx/tkMacOSXXCursors.r:
* macosx/README:
* macosx/GNUmakefile: fix/add copyright and license refs.
* macosx/Tk-Info.plist.in:
* macosx/Wish-Info.plist.in:
* macosx/Wish.xcode/project.pbxproj:
* macosx/Wish.xcodeproj/project.pbxproj:
* macosx/tkMacOSX.h:
Diffstat (limited to 'macosx/tkMacOSXFont.c')
-rw-r--r-- | macosx/tkMacOSXFont.c | 2520 |
1 files changed, 1056 insertions, 1464 deletions
diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c index 2f81ae5..1a4a399 100644 --- a/macosx/tkMacOSXFont.c +++ b/macosx/tkMacOSXFont.c @@ -1,10 +1,11 @@ /* * tkMacOSXFont.c -- * - * Contains the Macintosh implementation of the platform-independant - * font package interface. This version uses ATSU instead of Quickdraw. + * Contains the Macintosh implementation of the platform-independant + * font package interface. This version uses ATSU instead of Quickdraw. * * Copyright 2002-2004 Benjamin Riefenstahl, Benjamin.Riefenstahl@epost.de + * Copyright (c) 2006-2007 Daniel A. Steffen <das@users.sourceforge.net> * * Some functions were originally copied verbatim from the QuickDraw version * of tkMacOSXFont.c, which had these copyright notices: @@ -16,7 +17,6 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * * Todos: * * - Get away from Font Manager and Quickdraw functions as much as possible, @@ -26,39 +26,31 @@ * instead of just assuming that they are the same. * * - Get a second font register going for fonts that are not assigned to a - * font family by the OS. On my system I have 27 fonts of that type, + * font family by the OS. On my system I have 27 fonts of that type, * Hebrew, Arabic and Hindi fonts that actually come with the system. * FMGetFontFamilyInstanceFromFont() returns -981 (kFMInvalidFontFamilyErr) * for these and they are not listed when enumerating families, but they - * are when enumerating fonts directly. The problem that the OS sees may - * be that at least some of them do not contain any Latin characters. Note + * are when enumerating fonts directly. The problem that the OS sees may + * be that at least some of them do not contain any Latin characters. Note * that such fonts can not be used for controls, because controls * definitely require a family id (this assertion needs testing). * - * RCS: @(#) $Id: tkMacOSXFont.c,v 1.23 2007/04/21 19:06:38 hobbs Exp $ + * RCS: @(#) $Id: tkMacOSXFont.c,v 1.24 2007/04/23 21:24:33 das Exp $ */ #include "tkMacOSXInt.h" #include "tkMacOSXFont.h" /* -#ifdef TK_MAC_DEBUG +#ifdef TK_MAC_DEBUG #define TK_MAC_DEBUG_FONTS #endif */ -/* Define macros only available on Mac OS X 10.3 or later */ -#ifndef FixedToInt -#define FixedToInt(a) ((short)(((Fixed)(a) + fixed1/2) >> 16)) -#endif -#ifndef IntToFixed -#define IntToFixed(a) ((Fixed)(a) << 16) -#endif - /* - * Problem: The sum of two parts is not the same as the whole. In particular + * Problem: The sum of two parts is not the same as the whole. In particular * the width of two separately measured strings will usually be larger than - * the width of them pasted together. Tk has a design bug here, because it + * the width of them pasted together. Tk has a design bug here, because it * generally assumes that this kind of arithmetic works. * To workaround this, #define TK_MAC_COALESCE_LINE to 1 below, we then avoid * lines that tremble and shiver while the cursor passes through them by @@ -68,17 +60,45 @@ */ #define TK_MAC_COALESCE_LINE 0 -typedef TkMacOSXFont MacFont; -typedef TkMacOSXFontDrawingContext DrawingContext; +/* + * The following structure represents our Macintosh-specific implementation + * of a font object. + */ + +typedef struct { + TkFont font; /* Stuff used by generic font package. Must + * be first in structure. */ + + /* + * The ATSU view of the font and other text properties. Used for drawing + * and measuring. + */ + + ATSUFontID atsuFontId; /* == FMFont. */ + ATSUTextLayout atsuLayout; /* ATSU layout object, representing the whole + * text that ATSU sees with some option + * bits. */ + ATSUStyle atsuStyle; /* ATSU style object, representing a run of + * text with the same properties. */ + + /* + * The QuickDraw view of the font. Used to configure controls. + */ + + FMFontFamily qdFont; /* == FMFontFamilyId, Carbon replacement for + * QD face numbers. */ + short qdSize; /* Font size in points. */ + short qdStyle; /* QuickDraw style bits. */ +} MacFont; /* - * Information about font families, initialized at startup time. Font + * Information about font families, initialized at startup time. Font * families are described by a mapping from UTF-8 names to MacOS font family - * IDs. The whole list is kept as the sorted array "familyList", allocated + * IDs. The whole list is kept as the sorted array "familyList", allocated * with ckrealloc(). * * Note: This would have been easier, if we could just have used Tcl hash - * arrays. Unfortunately there seems to be no pre-packaged + * arrays. Unfortunately there seems to be no pre-packaged * non-case-sensitive version of that available. */ @@ -89,137 +109,121 @@ typedef struct { static MacFontFamily * familyList = NULL; static int - familyListNextFree = 0, /* The next free slot in familyList. */ - familyListMaxValid = 0, /* The top of the sorted area. */ - familyListSize = 0; /* The size of the whole array. */ + familyListNextFree = 0, /* The next free slot in familyList. */ + familyListMaxValid = 0, /* The top of the sorted area. */ + familyListSize = 0; /* The size of the whole array. */ /* * A simple one-shot sub-allocator for fast and efficient allocation of - * strings. Used by the familyList array for the names. These strings are - * only allocated once at startup and never freed. If you ever need to + * strings. Used by the familyList array for the names. These strings are + * only allocated once at startup and never freed. If you ever need to * re-initialize this, you can just ckfree() all the StringBlocks in the list * and start over. */ -#define STRING_BLOCK_MAX (1024-8) /* Make sizeof(StringBlock) == - * 1024. */ +#define STRING_BLOCK_MAX (1024-8) /* Make sizeof(StringBlock) == + * 1024. */ typedef struct StringBlock { - struct StringBlock * next; /* Starting from "stringMemory" these - * blocks form a linked list. */ - int nextFree; /* Top of the used area in the - * "strings" member. */ - char strings[STRING_BLOCK_MAX]; /* The actual memory managed here. */ + struct StringBlock *next; /* Starting from "stringMemory" these + * blocks form a linked list. */ + int nextFree; /* Top of the used area in the + * "strings" member. */ + char strings[STRING_BLOCK_MAX]; /* The actual memory managed here. */ } StringBlock; -static StringBlock * stringMemory = NULL; - +static StringBlock *stringMemory = NULL; #if TK_MAC_COALESCE_LINE -static Tcl_DString currentLine; /* The current line as seen so far. This - * contains a Tcl_UniChar DString. */ +static Tcl_DString currentLine; /* The current line as seen so far. This + * contains a Tcl_UniChar DString. */ static int - currentY = -1, /* The Y position (row in pixels) of the - * current line. */ - currentLeft = -1, /* The left edge (pixels) of the current - * line. */ - currentRight = -1; /* The right edge (pixels) of the current - * line. */ -static const MacFont * currentFontPtr = NULL; - /* The font of the current line. */ + currentY = -1, /* The Y position (row in pixels) of the + * current line. */ + currentLeft = -1, /* The left edge (pixels) of the current + * line. */ + currentRight = -1; /* The right edge (pixels) of the current + * line. */ +static const MacFont *currentFontPtr = NULL; + /* The font of the current line. */ #endif /* TK_MAC_COALESCE_LINE */ static int antialiasedTextEnabled; /* - * The names for our two "native" fonts. + * The names for our "native" fonts. */ -#define SYSTEMFONT_NAME "system" -#define APPLFONT_NAME "application" +#define SYSTEMFONT_NAME "system" +#define APPLFONT_NAME "application" +#define MENUITEMFONT_NAME "menu" /* * Procedures used only in this file. */ +static void LayoutSetString(const MacFont *fontPtr, + const TkMacOSXDrawingContext *drawingContextPtr, + const UniChar * uchars, int ulen); + /* * The actual workers. */ -static void MacFontDrawText( - const MacFont * fontPtr, - const char * source, int numBytes, - int rangeStart, int rangeLength, - int x, int y); -static int MeasureStringWidth( - const MacFont * fontPtr, - int start, int end); +static int MeasureStringWidth(const MacFont *fontPtr, int start, int end); #if TK_MAC_COALESCE_LINE -static const Tcl_UniChar * UpdateLineBuffer( - const MacFont * fontPtr, - const DrawingContext * drawingContextPtr, - const char * source, int numBytes, - int x, int y, - int * offset); +static const Tcl_UniChar *UpdateLineBuffer(const MacFont *fontPtr, + const TkMacOSXDrawingContext *drawingContextPtr, const char *source, + int numBytes, int x, int y, int * offset); #endif /* TK_MAC_COALESCE_LINE */ /* * Initialization and setup of a font data structure. */ -static void InitFont( - Tk_Window tkwin, - FMFontFamily familyId, const char * familyName, - int size, int qdStyle, MacFont * fontPtr); -static void InitATSUObjects( - FMFontFamily familyId, - short qdsize, short qdStyle, - ATSUFontID * fontIdPtr, - ATSUTextLayout * layoutPtr, ATSUStyle * stylePtr); -static void InitATSUStyle( - ATSUFontID fontId, short ptSize, short qdStyle, - ATSUStyle style); -static void SetFontFeatures( - ATSUFontID fontId, int fixed, - ATSUStyle style); -static void AdjustFontHeight( - MacFont * fontPtr); -static void InitATSULayout( - const DrawingContext * drawingContextPtr, - ATSUTextLayout layout, int fixed); -static void ReleaseFont( - MacFont * fontPtr); +static void InitFont(Tk_Window tkwin, FMFontFamily familyId, + const char *familyName, int size, int qdStyle, MacFont *fontPtr); +static void InitATSUObjects(FMFontFamily familyId, short qdsize, short qdStyle, + ATSUFontID *fontIdPtr, ATSUTextLayout *layoutPtr, ATSUStyle *stylePtr); +static void InitATSUStyle(ATSUFontID fontId, short ptSize, short qdStyle, + ATSUStyle style); +static void SetFontFeatures(ATSUFontID fontId, int fixed, ATSUStyle style); +static void AdjustFontHeight(MacFont *fontPtr); +static void InitATSULayout(const TkMacOSXDrawingContext *drawingContextPtr, + ATSUTextLayout layout, int fixed); +static void ReleaseFont(MacFont *fontPtr); /* * Finding fonts by name. */ -static const MacFontFamily * FindFontFamilyOrAlias( - const char * name); -static const MacFontFamily * FindFontFamilyOrAliasOrFallback( - const char * name); +static const MacFontFamily *FindFontFamilyOrAlias(const char *name); +static const MacFontFamily *FindFontFamilyOrAliasOrFallback(const char *name); /* * Doing interesting things with font families and fonts. */ static void InitFontFamilies(void); -static OSStatus GetFontFamilyName( - FMFontFamily fontFamily, char * name, int numBytes); +static OSStatus GetFontFamilyName(FMFontFamily fontFamily, char *name, + int numBytes); /* * Accessor functions and internal utilities for the font family list. */ -static const MacFontFamily * AddFontFamily( - const char * name, FMFontFamily familyId); -static const MacFontFamily * FindFontFamily(const char * name); -static Tcl_Obj * EnumFontFamilies(void); +static const MacFontFamily *AddFontFamily(const char *name, + FMFontFamily familyId); +static const MacFontFamily *FindFontFamily(const char *name); +static Tcl_Obj *EnumFontFamilies(void); static OSStatus FontFamilyEnumCallback(ATSFontFamilyRef family, void *refCon); static void SortFontFamilies(void); -static int CompareFontFamilies(const void * vp1, const void * vp2); -static const char * AddString(const char * in); +static int CompareFontFamilies(const void *vp1, const void *vp2); +static const char *AddString(const char *in); +static OSStatus GetThemeFontAndFamily(const ThemeFontID themeFontId, + FMFontFamily *fontFamily, unsigned char *fontName, SInt16 *fontSize, + Style *fontStyle); /* @@ -227,33 +231,60 @@ static const char * AddString(const char * in); * * 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: - * Initialization of variables local to this file. + * Initialization of variables local to this file. * *------------------------------------------------------------------------- */ void TkpFontPkgInit( - TkMainInfo * mainPtr) /* The application being created. */ + TkMainInfo *mainPtr) /* The application being created. */ { InitFontFamilies(); #if TK_MAC_COALESCE_LINE Tcl_DStringInit(¤tLine); #endif +} + +/* + *--------------------------------------------------------------------------- + * + * GetThemeFontAndFamily -- + * + * Wrapper around the GetThemeFont and FMGetFontFamilyFromName APIs. + * + *--------------------------------------------------------------------------- + */ -#ifdef TK_MAC_DEBUG_FONTS - fprintf(stderr, "tkMacOSXFont.c (ATSU version) intialized " - "(" __TIME__ ")\n"); -#endif +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; } /* @@ -261,45 +292,56 @@ TkpFontPkgInit( * * 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. */ { - FMFontFamily familyId; + ThemeFontID themeFontId; + FMFontFamily fontFamily; + Str255 fontName; + SInt16 fontSize; + Style fontStyle; MacFont * fontPtr; if (strcmp(name, SYSTEMFONT_NAME) == 0) { - familyId = GetSysFont(); + themeFontId = kThemeSystemFont; } else if (strcmp(name, APPLFONT_NAME) == 0) { - familyId = GetAppFont(); + 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; + } + CopyPascalStringToC(fontName, (char*)fontName); fontPtr = (MacFont *) ckalloc(sizeof(MacFont)); - InitFont(tkwin, familyId, NULL, 0, 0, fontPtr); + InitFont(tkwin, fontFamily, (char*)fontName, fontSize, fontStyle, fontPtr); return (TkFont *) fontPtr; } @@ -309,74 +351,74 @@ TkpGetNativeFont( * * 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. */ - const TkFontAttributes * faPtr) - /* Set of attributes to match. */ + 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. */ { short qdStyle; FMFontFamily familyId; - const char * name; - const MacFontFamily * familyPtr; - MacFont * fontPtr; + const char *name; + const MacFontFamily *familyPtr; + MacFont *fontPtr; familyId = GetAppFont(); name = NULL; qdStyle = 0; if (faPtr->family != NULL) { - familyPtr = FindFontFamilyOrAliasOrFallback(faPtr->family); - if (familyPtr != NULL) { - name = familyPtr->name; - familyId = familyPtr->familyId; - } + familyPtr = FindFontFamilyOrAliasOrFallback(faPtr->family); + if (familyPtr != NULL) { + name = familyPtr->name; + familyId = familyPtr->familyId; + } } if (faPtr->weight != TK_FW_NORMAL) { - qdStyle |= bold; + qdStyle |= bold; } if (faPtr->slant != TK_FS_ROMAN) { - qdStyle |= italic; + qdStyle |= italic; } if (faPtr->underline) { - qdStyle |= underline; + qdStyle |= 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, familyId, name, faPtr->size, qdStyle, fontPtr); @@ -388,23 +430,23 @@ 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: - * TkFont is deallocated. + * TkFont is deallocated. * * Side effects: - * None. + * None. * *--------------------------------------------------------------------------- */ void TkpDeleteFont( - TkFont * tkFontPtr) /* Token of font to be deleted. */ + TkFont *tkFontPtr) /* Token of font to be deleted. */ { ReleaseFont((MacFont *) tkFontPtr); } @@ -414,25 +456,25 @@ 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. */ { - Tcl_SetObjResult(interp,EnumFontFamilies()); + Tcl_SetObjResult(interp, EnumFontFamilies()); } /* @@ -440,26 +482,26 @@ 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( - Tcl_Interp * interp, /* Interp to hold result. */ - Tk_Font tkfont) /* Font object to query. */ + Tcl_Interp *interp, /* Interp to hold result. */ + Tk_Font tkfont) /* Font object to query. */ { /* We don't know much about our fallback fonts, ATSU does all that for - * us. We could use ATSUMatchFont to implement this function. But as + * us. We could use ATSUMatchFont to implement this function. But as * the information is only used for testing, such an effort seems not * very useful. */ } @@ -469,35 +511,35 @@ TkpGetSubFonts( * * TkpGetFontAttrsForChar -- * - * Retrieve the font attributes of the actual font used to render a - * given character. + * Retrieve the font attributes of the actual font used to render a + * given character. * * Results: - * None. + * None. * * Side effects: - * The font attributes are stored in *faPtr. + * The font attributes are stored in *faPtr. * *---------------------------------------------------------------------- */ void TkpGetFontAttrsForChar( - Tk_Window tkwin, /* Window on the font's display */ - Tk_Font tkfont, /* Font to query */ - Tcl_UniChar c, /* Character of interest */ - TkFontAttributes* faPtr) /* Output: Font attributes */ + Tk_Window tkwin, /* Window on the font's display */ + Tk_Font tkfont, /* Font to query */ + Tcl_UniChar c, /* Character of interest */ + TkFontAttributes* faPtr) /* Output: Font attributes */ { - TkMacOSXFont* fontPtr = (TkMacOSXFont*) tkfont; + const MacFont * fontPtr = (const MacFont *) tkfont; UniChar uchar = c; - DrawingContext drawingContext; + TkMacOSXDrawingContext drawingContext; OSStatus err; ATSUFontID fontId; UniCharArrayOffset changedOffset; UniCharCount changedLength; /* - * Most of the attributes are just copied from the base font. This + * Most of the attributes are just copied from the base font. This * assumes that all fonts can have all attributes. */ @@ -507,202 +549,172 @@ TkpGetFontAttrsForChar( * But the name of the actual font may still differ, so we activate the * string as an ATSU layout and ask ATSU about the fallback. */ + TkMacOSXSetupDrawingContext(Tk_WindowId(tkwin), NULL, 1, &drawingContext); -#if TK_MAC_USE_QUARZ - TkMacOSXQuarzStartDraw(&drawingContext); -#endif - - TkMacOSXLayoutSetString(fontPtr, &drawingContext, &uchar, 1); + LayoutSetString(fontPtr, &drawingContext, &uchar, 1); fontId = fontPtr->atsuFontId; err = ATSUMatchFontsToText( - fontPtr->atsuLayout, 0, 1, - &fontId, &changedOffset, &changedLength); -#ifdef TK_MAC_DEBUG_FONTS + fontPtr->atsuLayout, 0, 1, + &fontId, &changedOffset, &changedLength); if (err != kATSUFontsMatched && err != noErr) { - fprintf(stderr, "TkpGetFontAttrsForChar: " - "Can't match \\u%04X\n", - (unsigned) c); + TkMacOSXDbgMsg("Can't match \\u%04X", (unsigned) c); } -#endif if (err == kATSUFontsMatched) { - - /* - * A fallback was used and the actual font is in fontId. Determine - * the name. - */ - - FMFontFamily fontFamilyId; - FMFontStyle fontStyle; - int i; - - err = FMGetFontFamilyInstanceFromFont( - fontId, &fontFamilyId, &fontStyle); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "FMGetFontFamilyInstanceFromFont: Error %d\n", - (int) err); - } -#endif - - if (err == noErr) { - - /* - * Find the canonical name in our global list. - */ - - for (i=0; i<familyListMaxValid; ++i) { - if (fontFamilyId == familyList[i].familyId) { - faPtr->family = familyList[i].name; - break; - } - } -#ifdef TK_MAC_DEBUG_FONTS - if (i >= familyListMaxValid) { - fprintf(stderr, "TkpGetFontAttrsForChar: " - "Can't find font %d for \\u%04X\n", - (int) fontFamilyId, (unsigned) c); - } -#endif - } + /* + * A fallback was used and the actual font is in fontId. Determine + * the name. + */ + + FMFontFamily fontFamilyId; + FMFontStyle fontStyle; + int i; + + err = ChkErr(FMGetFontFamilyInstanceFromFont, fontId, &fontFamilyId, + &fontStyle); + if (err == noErr) { + /* + * Find the canonical name in our global list. + */ + + for (i=0; i<familyListMaxValid; ++i) { + if (fontFamilyId == familyList[i].familyId) { + faPtr->family = familyList[i].name; + break; + } + } + if (i >= familyListMaxValid) { + TkMacOSXDbgMsg("Can't find font %d for \\u%04X", fontFamilyId, + (unsigned) c); + } + } } -#if TK_MAC_USE_QUARZ - TkMacOSXQuarzEndDraw(&drawingContext); -#endif + TkMacOSXRestoreDrawingContext(&drawingContext); } /* *--------------------------------------------------------------------------- * - * Tk_MeasureChars -- + * 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. * - * With ATSUI we need the line context to do this right, so we have the - * actual implementation in TkpMeasureCharsInContext(). + * With ATSUI we need the line context to do this right, so we have the + * actual implementation in TkpMeasureCharsInContext(). * * 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. * * Todo: - * - * Effects of the "flags" parameter are untested. + * Effects of the "flags" parameter are untested. * *--------------------------------------------------------------------------- */ 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. */ { - return TkpMeasureCharsInContext( - tkfont, source, numBytes, 0, numBytes, maxLength, flags, lengthPtr); + return TkpMeasureCharsInContext(tkfont, source, numBytes, 0, numBytes, + maxLength, flags, lengthPtr); } /* *--------------------------------------------------------------------------- * - * TkpMeasureCharsInContext -- + * TkpMeasureCharsInContext -- * - * Determine the number of bytes from the string that will fit in the - * given horizontal span. The measurement is done under the assumption - * that TkpDrawCharsInContext() will be used to actually display the - * characters. + * Determine the number of bytes from the string that will fit in the + * given horizontal span. The measurement is done under the assumption + * that TkpDrawCharsInContext() will be used to actually display the + * characters. * - * This one is almost the same as Tk_MeasureChars(), but with access to - * all the characters on the line for context. + * This one is almost the same as Tk_MeasureChars(), but with access to + * all the characters on the line for context. * * 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 TkpMeasureCharsInContext( - 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 in all. */ - int rangeStart, /* Index of first byte to measure. */ - int rangeLength, /* Length of range to measure in bytes. */ - 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 fits on this line. - * TK_WHOLE_WORDS means stop on a word boundary, - * if possible. - * TK_AT_LEAST_ONE means return at least one - * character (or at least the first partial word - * in case TK_WHOLE_WORDS is also set) even if no - * characters (words) fit. - * TK_ISOLATE_END means that the last character - * should not be considered in context with the - * rest of the string (used for breaking - * lines). */ - 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 in all. */ + int rangeStart, /* Index of first byte to measure. */ + int rangeLength, /* Length of range to measure in bytes. */ + 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 fits on this line. + * TK_WHOLE_WORDS means stop on a word + * boundary, if possible. TK_AT_LEAST_ONE + * means return at least one character (or at + * least the first partial word in case + * TK_WHOLE_WORDS is also set) even if no + * characters (words) fit. TK_ISOLATE_END + * means that the last character should not be + * considered in context with the rest of the + * string (used for breaking lines). */ + int *lengthPtr) /* Filled with x-location just after the + * terminating character. */ { - const MacFont * fontPtr = (const MacFont *) tkfont; - int curX = -1; - int curByte = 0; - UniChar * uchars; + const MacFont *fontPtr = (const MacFont *) tkfont; + int curX = -1, curByte = 0; + UniChar *uchars; int ulen, urstart, urlen, urend; Tcl_DString ucharBuffer; - DrawingContext drawingContext; - /* * Sanity checks. */ - if ((rangeStart < 0) || ((rangeStart+rangeLength) > numBytes)) { -#ifdef TK_MAC_DEBUG_FONTS - fprintf(stderr, "MeasureChars: bad parameters\n"); -#endif - *lengthPtr = 0; - return 0; + if (rangeStart < 0 || (rangeStart+rangeLength) > numBytes) { + TkMacOSXDbgMsg("Bad parameters"); + *lengthPtr = 0; + return 0; } /* @@ -710,284 +722,243 @@ TkpMeasureCharsInContext( */ if (rangeLength == 0 || (maxLength == 0 && !(flags & TK_AT_LEAST_ONE))) { -#ifdef TK_MAC_DEBUG_FONTS - fflush(stdout); - fprintf(stderr, "measure: '%.*s', empty\n", - rangeLength, source+rangeStart); - fflush(stderr); -#endif - *lengthPtr = 0; - return 0; + *lengthPtr = 0; + return 0; } -#if TK_MAC_USE_QUARZ - TkMacOSXQuarzStartDraw(&drawingContext); -#endif - Tcl_DStringInit(&ucharBuffer); uchars = Tcl_UtfToUniCharDString(source, numBytes, &ucharBuffer); ulen = Tcl_DStringLength(&ucharBuffer) / sizeof(Tcl_UniChar); - TkMacOSXLayoutSetString(fontPtr, &drawingContext, uchars, ulen); + LayoutSetString(fontPtr, NULL, uchars, ulen); urstart = Tcl_NumUtfChars(source, rangeStart); urlen = Tcl_NumUtfChars(source+rangeStart,rangeLength); urend = urstart + urlen; if (maxLength < 0) { - - curX = MeasureStringWidth(fontPtr, urstart, urend); - curByte = rangeLength; - + curX = MeasureStringWidth(fontPtr, urstart, urend); + curByte = rangeLength; } else { - - UniCharArrayOffset offset = 0; - OSStatus err; - - /* - * Have some upper limit on the size actually used. - */ - - if (maxLength > 32767) { - maxLength = 32767; - } - - offset = urstart; - err = noErr; - - if (maxLength > 1) { - - /* - * Let the system do some work by calculating a line break. - * - * Somehow ATSUBreakLine seems to assume that it needs at least - * one pixel padding. So we add one to the limit. Note also - * that ATSUBreakLine sometimes runs into an endless loop when - * the third parameter is equal or less than IntToFixed(2), so we - * need at least IntToFixed(3) (at least that's the current state - * of my knowledge). - */ - - err = ATSUBreakLine( - fontPtr->atsuLayout, - urstart, - IntToFixed(maxLength+1), - false, /* !iUseAsSoftLineBreak */ - &offset); - - /* - * There is no way to signal an error from this routine, so we - * use predefined offset=urstart and otherwise ignore the - * possibility. - */ + UniCharArrayOffset offset = 0; + OSStatus err; + + /* + * Have some upper limit on the size actually used. + */ + + if (maxLength > 32767) { + maxLength = 32767; + } + + offset = urstart; + err = noErr; + + if (maxLength > 1) { + /* + * Let the system do some work by calculating a line break. + * + * Somehow ATSUBreakLine seems to assume that it needs at least + * one pixel padding. So we add one to the limit. Note also + * that ATSUBreakLine sometimes runs into an endless loop when + * the third parameter is equal or less than IntToFixed(2), so we + * need at least IntToFixed(3) (at least that's the current state + * of my knowledge). + */ + + err = ATSUBreakLine(fontPtr->atsuLayout, urstart, + IntToFixed(maxLength+1), false, /* !iUseAsSoftLineBreak */ + &offset); + + /* + * There is no way to signal an error from this routine, so we + * use predefined offset=urstart and otherwise ignore the + * possibility. + */ + + if ((err != noErr) && (err != kATSULineBreakInWord)) { + TkMacOSXDbgMsg("ATSUBreakLine failed: %ld for '%.*s'", err, + rangeLength, source+rangeStart); + } #ifdef TK_MAC_DEBUG_FONTS - if ((err != noErr) && (err != kATSULineBreakInWord)) { - fprintf(stderr, "ATSUBreakLine(): Error %d for '%.*s'\n", - (int) err, rangeLength, source+rangeStart); - } + TkMacOSXDbgMsg("measure: '%.*s', break offset=%ld, errcode=%ld", + rangeLength, source+rangeStart, offset, err); #endif -#ifdef TK_MAC_DEBUG_FONTS - fprintf(stderr, "measure: '%.*s', break offset=%d, errcode=%d\n", - rangeLength, source+rangeStart, (int) offset, (int) err); -#endif - - /* - * ATSUBreakLine includes the whitespace that separates words, - * but we don't want that. Besides, ATSUBreakLine thinks that - * spaces don't occupy pixels at the end of the break, which is - * also something we like to decide for ourself. - */ - - while ((offset > (UniCharArrayOffset)urstart) && (uchars[offset-1] == ' ')) { - offset--; - } - - /* - * Fix up left-overs for the TK_WHOLE_WORDS case. - */ - - if (flags & TK_WHOLE_WORDS) { - if(flags & TK_AT_LEAST_ONE) { - - /* - * If we are the the start of the range, we need to look - * forward. If we are not at the end of a word, we must - * be in the middle of the first word, so we also look - * forward. - */ - - if ((offset == (UniCharArrayOffset)urstart) || (uchars[offset] != ' ')) { - while ((offset < (UniCharArrayOffset)urend) - && (uchars[offset] != ' ')) { - offset++; - } - } - } else { - - /* - * If we are not at the end of a word, we need to look - * backward. - */ - - if ((offset != (UniCharArrayOffset)urend) && (uchars[offset] != ' ')) { - while ((offset > (UniCharArrayOffset)urstart) - && (uchars[offset-1] != ' ')) { - offset--; - } - while ((offset > (UniCharArrayOffset)urstart) - && (uchars[offset-1] == ' ')) { - offset--; - } - } - } - } - } - - if (offset > (UniCharArrayOffset)urend) { - offset = urend; - } - - /* - * If "flags" says that we don't actually want a word break, we need - * to find the next character break ourself, as ATSUBreakLine() will - * only give us word breaks. Do a simple linear search. - */ - - if ((err != kATSULineBreakInWord) - && !(flags & TK_WHOLE_WORDS) - && (offset <= (UniCharArrayOffset)urend)) { - - UniCharArrayOffset lastOffset = offset; - UniCharArrayOffset nextoffset; - int lastX = -1; - int wantonemorechar = -1; /* undecided */ - - while (offset <= (UniCharArrayOffset)urend) { - - if (flags & TK_ISOLATE_END) { - TkMacOSXLayoutSetString(fontPtr, &drawingContext, - uchars, offset); - } - curX = MeasureStringWidth(fontPtr, urstart, offset); + /* + * ATSUBreakLine includes the whitespace that separates words, + * but we don't want that. Besides, ATSUBreakLine thinks that + * spaces don't occupy pixels at the end of the break, which is + * also something we like to decide for ourself. + */ + + while ((offset > (UniCharArrayOffset)urstart) && + (uchars[offset-1] == ' ')) { + offset--; + } + + /* + * Fix up left-overs for the TK_WHOLE_WORDS case. + */ + + if (flags & TK_WHOLE_WORDS) { + if (flags & TK_AT_LEAST_ONE) { + /* + * If we are the the start of the range, we need to look + * forward. If we are not at the end of a word, we must + * be in the middle of the first word, so we also look + * forward. + */ + + if ((offset == (UniCharArrayOffset)urstart) || + (uchars[offset] != ' ')) { + while ((offset < (UniCharArrayOffset)urend) + && (uchars[offset] != ' ')) { + offset++; + } + } + } else { + /* + * If we are not at the end of a word, we need to look + * backward. + */ + + if ((offset != (UniCharArrayOffset)urend) && + (uchars[offset] != ' ')) { + while ((offset > (UniCharArrayOffset)urstart) + && (uchars[offset-1] != ' ')) { + offset--; + } + while ((offset > (UniCharArrayOffset)urstart) + && (uchars[offset-1] == ' ')) { + offset--; + } + } + } + } + } + + if (offset > (UniCharArrayOffset)urend) { + offset = urend; + } + + /* + * If "flags" says that we don't actually want a word break, we need + * to find the next character break ourself, as ATSUBreakLine() will + * only give us word breaks. Do a simple linear search. + */ + + if ((err != kATSULineBreakInWord) + && !(flags & TK_WHOLE_WORDS) + && (offset <= (UniCharArrayOffset)urend)) { + UniCharArrayOffset lastOffset = offset; + UniCharArrayOffset nextoffset; + int lastX = -1; + int wantonemorechar = -1; /* undecided */ + + while (offset <= (UniCharArrayOffset)urend) { + if (flags & TK_ISOLATE_END) { + LayoutSetString(fontPtr, NULL, uchars, offset); + } + curX = MeasureStringWidth(fontPtr, urstart, offset); #ifdef TK_MAC_DEBUG_FONTS - fprintf(stderr, "measure: '%.*s', try until=%d, width=%d\n", - rangeLength, source+rangeStart, (int) offset, curX); + TkMacOSXDbgMsg("measure: '%.*s', try until=%ld, width=%d", + rangeLength, source+rangeStart, offset, curX); #endif - if (curX > maxLength) { - - /* - * Even if we are over the limit, we may want another - * character in some situations. Than we keep looking - * for one more character. - */ - - if (wantonemorechar == -1) { - wantonemorechar = - ((flags & TK_AT_LEAST_ONE) - && (lastOffset == (UniCharArrayOffset)urstart)) - || - ((flags & TK_PARTIAL_OK) - && (lastX != maxLength)) - ; - if (!wantonemorechar) { - break; - } - lastX = curX; - } - - /* - * There may belong combining marks to this character. - * Wait for a new curX to collect them all. - */ - - if (lastX != curX) { - break; - } - } - - /* - * Save this position, so we can come back to it. - */ - - lastX = curX; - lastOffset = offset; - - /* - * Increment offset by one character, taking combining marks - * into account. - */ - - if (offset >= (UniCharArrayOffset)urend) { - break; - } - nextoffset = 0; - if (flags & TK_ISOLATE_END) { - TkMacOSXLayoutSetString(fontPtr, &drawingContext, - uchars, ulen); - } - err = ATSUNextCursorPosition( - fontPtr->atsuLayout, - offset, - kATSUByCluster, - &nextoffset); - if (err != noErr) { -#ifdef TK_MAC_DEBUG_FONTS - fprintf(stderr, "ATSUNextCursorPosition(): " - "Error %d\n", (int) err); -#endif - break; - } - if (nextoffset <= offset) { + if (curX > maxLength) { + /* + * Even if we are over the limit, we may want another + * character in some situations. Than we keep looking + * for one more character. + */ + + if (wantonemorechar == -1) { + wantonemorechar = ((flags & TK_AT_LEAST_ONE) && + (lastOffset == (UniCharArrayOffset)urstart)) || + ((flags & TK_PARTIAL_OK) && + (lastX != maxLength)); + if (!wantonemorechar) { + break; + } + lastX = curX; + } + + /* + * There may belong combining marks to this character. + * Wait for a new curX to collect them all. + */ + + if (lastX != curX) { + break; + } + } + + /* + * Save this position, so we can come back to it. + */ + + lastX = curX; + lastOffset = offset; + + /* + * Increment offset by one character, taking combining marks + * into account. + */ + + if (offset >= (UniCharArrayOffset)urend) { + break; + } + nextoffset = 0; + if (flags & TK_ISOLATE_END) { + LayoutSetString(fontPtr, NULL, uchars, ulen); + } + err = ChkErr(ATSUNextCursorPosition, fontPtr->atsuLayout, + offset, kATSUByCluster, &nextoffset); + if (err != noErr) { + break; + } + if (nextoffset <= offset) { #ifdef TK_MAC_DEBUG_FONTS - fprintf(stderr, "ATSUNextCursorPosition(): " - "Can't move further " - "(shouldn't happen, bad data?)\n"); + TkMacOSXDbgMsg("ATSUNextCursorPosition: Can't move further" + " (shouldn't happen, bad data?)"); #endif - break; - } - - offset = nextoffset; - } - - /* - * We have overshot one character, so backup one position. - */ - - curX = lastX; - offset = lastOffset; - } - - if (curX < 0) { - if (flags & TK_ISOLATE_END) { - TkMacOSXLayoutSetString(fontPtr, &drawingContext, - uchars, offset); - } - curX = MeasureStringWidth(fontPtr, urstart, offset); - } - - curByte = Tcl_UtfAtIndex(source, offset) - source; - curByte -= rangeStart; + break; + } + + offset = nextoffset; + } + + /* + * We have overshot one character, so backup one position. + */ + + curX = lastX; + offset = lastOffset; + } + + if (curX < 0) { + if (flags & TK_ISOLATE_END) { + LayoutSetString(fontPtr, NULL, uchars, offset); + } + curX = MeasureStringWidth(fontPtr, urstart, offset); + } + + curByte = Tcl_UtfAtIndex(source, offset) - source; + curByte -= rangeStart; } Tcl_DStringFree(&ucharBuffer); -#if TK_MAC_USE_QUARZ - TkMacOSXQuarzEndDraw(&drawingContext); -#endif - #ifdef TK_MAC_DEBUG_FONTS - fflush(stdout); - fprintf(stderr, "measure: '%.*s', maxpix=%d, -> width=%d, bytes=%d, " - "flags=%s%s%s%s\n", - rangeLength, source+rangeStart, maxLength, curX, curByte, - flags & TK_PARTIAL_OK ? "partialOk " : "", - flags & TK_WHOLE_WORDS ? "wholeWords " : "", - flags & TK_AT_LEAST_ONE ? "atLeastOne " : "", - flags & TK_ISOLATE_END ? "isolateEnd " : ""); - fflush(stderr); + TkMacOSXDbgMsg("measure: '%.*s', maxpix=%d, -> width=%d, bytes=%d, " + "flags=%s%s%s%s", rangeLength, source+rangeStart, maxLength, curX, + curByte, + flags & TK_PARTIAL_OK ? "partialOk " : "", + flags & TK_WHOLE_WORDS ? "wholeWords " : "", + flags & TK_AT_LEAST_ONE ? "atLeastOne " : "", + flags & TK_ISOLATE_END ? "isolateEnd " : ""); #endif *lengthPtr = curX; @@ -999,360 +970,120 @@ TkpMeasureCharsInContext( * * Tk_DrawChars -- * - * Draw a string of characters on the screen. + * Draw a string of characters on the screen. * - * With ATSUI we need the line context to do this right, so we have the - * actual implementation in TkpDrawCharsInContext(). + * With ATSUI we need the line context to do this right, so we have the + * actual implementation in TkpDrawCharsInContext(). * * 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 the - * 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 the + * string when drawing. */ { TkpDrawCharsInContext(display, drawable, gc, tkfont, source, numBytes, - 0, numBytes, x, y); + 0, numBytes, x, y); } - /* *--------------------------------------------------------------------------- * * TkpDrawCharsInContext -- * - * Draw a string of characters on the screen like Tk_DrawChars(), with - * access to all the characters on the line for context. + * Draw a string of characters on the screen like Tk_DrawChars(), with + * access to all the characters on the line for context. * * Results: - * None. + * None. * * Side effects: - * Information gets drawn on the screen. + * Information gets drawn on the screen. * * Todo: - * - * We could try to implement a correct stipple algorithm. - * - * The fiddling with QD GraphPorts can be replaced with just working - * with the Quarz CGContext (see TkMacOSXQuarzStartDraw()), once we - * decide to stick to Quarz and really forget about QD drawing in here. + * Stippled text drawing. * *--------------------------------------------------------------------------- */ void TkpDrawCharsInContext( - 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 rangeStart, /* Index of first byte to draw. */ - int rangeLength, /* Length of range to draw in bytes. */ - int x, int y) /* Coordinates at which to place origin of the - * whole (not just the range) string when - * drawing. */ -{ - const MacFont * fontPtr; - MacDrawable * macWin; - RGBColor macColor, origColor; - GWorldPtr destPort; - CGrafPtr saveWorld; - GDHandle saveDevice; - BitMapPtr stippleMap; - Rect portRect; - - fontPtr = (const MacFont *) tkfont; - macWin = (MacDrawable *) drawable; - - destPort = TkMacOSXGetDrawablePort(drawable); - GetPortBounds(destPort, &portRect); - GetGWorld(&saveWorld, &saveDevice); - SetGWorld(destPort, NULL); - - TkMacOSXSetUpClippingRgn(drawable); - TkMacOSXSetUpGraphicsPort(gc, destPort); - - GetForeColor(&origColor); - - 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)) { - RGBForeColor(&macColor); - } - GetQDGlobalsWhite(&white); - ShowPen(); - FillRect(&stippleMap->bounds, &white); - MacFontDrawText(fontPtr, source, numBytes, rangeStart, rangeLength, - 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)) { - RGBForeColor(&macColor); - } - ShowPen(); - MacFontDrawText(fontPtr, source, numBytes, rangeStart, rangeLength, - macWin->xOff + x, macWin->yOff + y); - HidePen(); - } - - RGBForeColor(&origColor); - - SetGWorld(saveWorld, saveDevice); -} - -#if TK_MAC_USE_QUARZ -#define RGBFLOATRED(c) (float)((float)(c.red) / 65535.0f) -#define RGBFLOATGREEN(c) (float)((float)(c.green) / 65535.0f) -#define RGBFLOATBLUE(c) (float)((float)(c.blue) / 65535.0f) -/* - *------------------------------------------------------------------------- - * - * TkMacOSXQuarzStartDraw -- - * - * Setup a Quarz CGContext from the current QD GraphPort for use in - * drawing or measuring. - * - * Results: - * - * A CGContext is allocated, configured and returned in - * drawingContextPtr. Also drawingContextPtr->portRect is filled in. - * - * Side effects: - * - * None. - * - * Assumptions: - * - * The current QD GraphPort contains all the data necessary. This is - * clearly the case for the actual drawing, but not so clear for - * measuring. OTOH for measuring the specific parameters are not really - * interesting and the GraphPort is not changed either. The - * availability of a CGContext may be important for the measuring - * process though. - * - *------------------------------------------------------------------------- - */ - -void -TkMacOSXQuarzStartDraw( - DrawingContext * drawingContextPtr) /* Quarz context data filled in - * by this function. */ -{ - GDHandle currentDevice; - CGrafPtr destPort; - RGBColor macColor; - CGContextRef outContext; - OSStatus err; - Rect boundsRect; - static RgnHandle clipRgn = NULL; - - GetGWorld(&destPort, ¤tDevice); - - err = QDBeginCGContext(destPort, &outContext); - - if (err == noErr && outContext) { - /* - * Now clip the CG Context to the port. We also have to intersect our clip - * region with the port visible region so we don't overwrite the window - * decoration. - */ - - if (!clipRgn) { - clipRgn = NewRgn(); - } - - GetPortBounds(destPort, &boundsRect); - - RectRgn(clipRgn, &boundsRect); - SectRegionWithPortClipRegion(destPort, clipRgn); - SectRegionWithPortVisibleRegion(destPort, clipRgn); - ClipCGContextToRegion(outContext, &boundsRect, clipRgn); - SetEmptyRgn(clipRgn); - - /* - * Note: You have to call SyncCGContextOriginWithPort - * AFTER all the clip region manipulations. - */ - - SyncCGContextOriginWithPort(outContext, destPort); - - /* - * Scale the color values, as QD uses UInt16 with the range [0..2^16-1] - * while Quarz uses float with [0..1]. NB: Only - * CGContextSetRGBFillColor() seems to be actually used by ATSU. - */ - - GetForeColor(&macColor); - CGContextSetRGBFillColor(outContext, - RGBFLOATRED(macColor), - RGBFLOATGREEN(macColor), - RGBFLOATBLUE(macColor), - 1.0f); - #ifdef TK_MAC_DEBUG_FONTS - } else { - fprintf(stderr, "QDBeginCGContext(): Error %d\n", (int) err); - #endif - } - - drawingContextPtr->graphPort = destPort; - drawingContextPtr->cgContext = outContext; - drawingContextPtr->portRect = boundsRect; - -} - -/* - *------------------------------------------------------------------------- - * - * TkMacOSXQuarzEndDraw -- - * - * Free the Quarz CGContext in drawingContextPtr. - * - * Results: - * - * The CGContext is de-allocated. drawingContextPtr->cgContext will be - * invalid after this. - * - * Side effects: - * - * None. - * - *------------------------------------------------------------------------- - */ - -void -TkMacOSXQuarzEndDraw( - DrawingContext * drawingContextPtr) -{ - if (drawingContextPtr->cgContext) { - QDEndCGContext( - drawingContextPtr->graphPort, - &drawingContextPtr->cgContext); - } -} -#endif /* TK_MAC_USE_QUARZ */ - -/* - *------------------------------------------------------------------------- - * - * MacFontDrawText -- - * - * Helper function for Tk_DrawChars. Draws characters, using the - * screen font in fontPtr to draw multilingual characters. - * - * Results: - * None. - * - * Side effects: - * Information gets drawn on the screen. - * - *------------------------------------------------------------------------- - */ - -static void -MacFontDrawText( - const MacFont * fontPtr, /* Contains font to use when drawing - * following string. */ - const char * source, /* Potentially multilingual UTF-8 string. */ - int numBytes, /* Length of string in bytes. */ - int rangeStart, /* Index of first byte to draw. */ - int rangeLength, /* Length of range to draw in bytes. */ - 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 rangeStart, /* Index of first byte to draw. */ + int rangeLength, /* Length of range to draw in bytes. */ + int x, int y) /* Coordinates at which to place origin of the + * whole (not just the range) string when + * drawing. */ { + const MacFont * fontPtr = (const MacFont *) tkfont; + MacDrawable *macWin = (MacDrawable *) drawable; Fixed fx, fy; int ulen, urstart, urlen; const UniChar * uchars; int lineOffset; - DrawingContext drawingContext; - OSStatus err; - + TkMacOSXDrawingContext drawingContext; #if !TK_MAC_COALESCE_LINE Tcl_DString runString; #endif + TkMacOSXSetupDrawingContext(drawable, gc, 1, &drawingContext); -#if TK_MAC_USE_QUARZ - TkMacOSXQuarzStartDraw(&drawingContext); - - /* - * Turn the y coordinate upside-down for Quarz drawing. We would have - * liked to just use a CTM transform in the CGContext, but than we get - * upside-down text, so doing it that way gets more painfull than to just - * hack around the problem right here. - */ - - y = drawingContext.portRect.bottom - drawingContext.portRect.top - y; - fy = IntToFixed(y); -#else - fy = IntToFixed(y); +#if 0 + /* TODO: implement stippled text drawing */ + if ((gc->fill_style == FillStippled + || gc->fill_style == FillOpaqueStippled) + && gc->stipple != None) { + #error Stippling not implemented + } #endif + x += macWin->xOff; + y += macWin->yOff; + /* Turn the y coordinate upside-down for Quarz drawing. */ + if (drawingContext.context) { + CGContextConcatCTM(drawingContext.context, CGAffineTransformMake(1.0, + 0.0, 0.0, -1.0, 0.0, drawingContext.portBounds.bottom - + drawingContext.portBounds.top)); + y = drawingContext.portBounds.bottom - + drawingContext.portBounds.top - y; + } + fy = IntToFixed(y); #if TK_MAC_COALESCE_LINE UpdateLineBuffer( - fontPtr, &drawingContext, source, numBytes, x, y, &lineOffset); + fontPtr, &drawingContext, source, numBytes, x, y, &lineOffset); fx = IntToFixed(currentLeft); @@ -1366,67 +1097,54 @@ MacFontDrawText( uchars = Tcl_UtfToUniCharDString(source, numBytes, &runString); ulen = Tcl_DStringLength(&runString) / sizeof(uchars[0]); - TkMacOSXLayoutSetString(fontPtr, &drawingContext, uchars, ulen); + LayoutSetString(fontPtr, &drawingContext, uchars, ulen); #endif urstart = Tcl_NumUtfChars(source, rangeStart); urlen = Tcl_NumUtfChars(source+rangeStart,rangeLength); - err = ATSUDrawText( - fontPtr->atsuLayout, - lineOffset+urstart, urlen, - fx, fy); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "ATSUDrawText(): Error %d\n", (int) err); - } -#endif + ChkErr(ATSUDrawText, fontPtr->atsuLayout, lineOffset+urstart, urlen, fx, + fy); #if !TK_MAC_COALESCE_LINE Tcl_DStringFree(&runString); #endif -#if TK_MAC_USE_QUARZ - TkMacOSXQuarzEndDraw(&drawingContext); -#endif + TkMacOSXRestoreDrawingContext(&drawingContext); } - /* *--------------------------------------------------------------------------- * * MeasureStringWidth -- * - * Low-level measuring of strings. + * Low-level measuring of strings. * * Results: - * - * The width of the string in pixels. + * The width of the string in pixels. * * Side effects: - * - * None. + * None. * * Assumptions: - * - * fontPtr->atsuLayout is setup with the actual string data to measure. + * fontPtr->atsuLayout is setup with the actual string data to measure. * *--------------------------------------------------------------------------- */ static int MeasureStringWidth( - const MacFont * fontPtr, /* Contains font, ATSU layout and string data - * to measure. */ - int start, int end) /* Start and end positions to measure in that - * string. */ + const MacFont *fontPtr, /* Contains font, ATSU layout and string data + * to measure. */ + int start, int end) /* Start and end positions to measure in that + * string. */ { /* * This implementation of measuring via ATSUGetGlyphBounds() does not * quite conform with the specification given for [font measure]: * - * The return value is the total width in pixels of text, not - * including the extra pixels used by highly exagerrated characters - * such as cursive "f". + * The return value is the total width in pixels of text, not + * including the extra pixels used by highly exagerrated characters + * such as cursive "f". * * Instead the result of ATSUGetGlyphBounds() *does* include these * "extra pixels". @@ -1434,26 +1152,18 @@ MeasureStringWidth( ATSTrapezoid bounds; ItemCount numBounds; - OSStatus err; if (end <= start) { - return 0; + return 0; } bounds.upperRight.x = bounds.upperLeft.x = 0; - err = ATSUGetGlyphBounds( - fontPtr->atsuLayout, - 0, 0, - start, end-start, - kATSUseFractionalOrigins, - 1, &bounds, &numBounds); + ChkErr(ATSUGetGlyphBounds, fontPtr->atsuLayout, 0, 0, start, end-start, + kATSUseFractionalOrigins, 1, &bounds, &numBounds); #ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "ATSUGetGlyphBounds(): Error %d\n", (int) err); - } else if (numBounds < 1) { - fprintf(stderr, "ATSUGetGlyphBounds(): No output\n"); - } else if (numBounds > 1) { - fprintf(stderr, "ATSUGetGlyphBounds(): More output\n"); + if (numBounds < 1 || numBounds > 1) { + TkMacOSXDbgMsg("ATSUGetGlyphBounds: %s output", + numBounds < 1 ? "No " : "More"); } #endif @@ -1466,58 +1176,57 @@ MeasureStringWidth( * * UpdateLineBuffer -- * - * See the general dicussion of TK_MAC_COALESCE_LINE on the header - * pages. This function maintains the data for this feature. + * See the general dicussion of TK_MAC_COALESCE_LINE on the header + * pages. This function maintains the data for this feature. * * Results: * - * The Tcl_UniChar string of the whole line as seen so far. + * The Tcl_UniChar string of the whole line as seen so far. * * Side effects: + * "*offset" is filled with the index of the first new character in + * "currentLine". The globals currentLine, currentY, currentLeft, + * currentRight and currentFontPtr are updated as necessary. * - * "*offset" is filled with the index of the first new character in - * "currentLine". The globals currentLine, currentY, currentLeft, - * currentRight and currentFontPtr are updated as necessary. - * - * The currentLine string is set as the current text in - * fontPtr->atsuLayout (see TkMacOSXLayoutSetString()). + * The currentLine string is set as the current text in + * fontPtr->atsuLayout (see LayoutSetString()). * *------------------------------------------------------------------------- */ static const Tcl_UniChar * UpdateLineBuffer( - const MacFont * fontPtr,/* The font to be used for the new piece of - * text. */ - const DrawingContext * drawingContextPtr, - /* The Quarz drawing parameters. Needed for - * measuring the new piece. */ - const char * source, /* A new piece of line to be added. */ - int numBytes, /* Length of the new piece. */ - int x, int y, /* Position of the new piece in the window. */ - int * offset) /* Filled with the offset of the new piece in - * currentLine. */ + const MacFont *fontPtr, /* The font to be used for the new piece of + * text. */ + const TkMacOSXDrawingContext *drawingContextPtr, + /* The Quarz drawing parameters. Needed for + * measuring the new piece. */ + const char *source, /* A new piece of line to be added. */ + int numBytes, /* Length of the new piece. */ + int x, int y, /* Position of the new piece in the window. */ + int *offset) /* Filled with the offset of the new piece in + * currentLine. */ { const Tcl_UniChar * uchars; int ulen; if (y != currentY - || x < currentRight-1 || x > currentRight+2 - || currentFontPtr != fontPtr) { - Tcl_DStringFree(¤tLine); - Tcl_DStringInit(¤tLine); - currentY = y; - currentLeft = x; - currentFontPtr = fontPtr; - *offset = 0; + || x < currentRight-1 || x > currentRight+2 + || currentFontPtr != fontPtr) { + Tcl_DStringFree(¤tLine); + Tcl_DStringInit(¤tLine); + currentY = y; + currentLeft = x; + currentFontPtr = fontPtr; + *offset = 0; } else { - *offset = Tcl_DStringLength(¤tLine) / 2; + *offset = Tcl_DStringLength(¤tLine) / 2; } Tcl_UtfToUniCharDString(source, numBytes, ¤tLine); uchars = (const Tcl_UniChar*) Tcl_DStringValue(¤tLine); ulen = Tcl_DStringLength(¤tLine) / sizeof(*uchars); - TkMacOSXLayoutSetString(fontPtr, drawingContextPtr, uchars, ulen); + LayoutSetString(fontPtr, drawingContextPtr, uchars, ulen); currentRight = x + MeasureStringWidth(fontPtr, *offset, ulen); return uchars; @@ -1529,33 +1238,33 @@ UpdateLineBuffer( * * 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. */ - FMFontFamily familyId, /* The font family to initialize for. */ - const char * familyName,/* The font family name, if known. Otherwise - * this can be NULL. */ - int size, /* Point size for the font. */ - int qdStyle, /* QuickDraw style bits. */ - MacFont * fontPtr) /* Filled with information constructed from the - * above arguments. */ + Tk_Window tkwin, /* For display where font will be used. */ + FMFontFamily familyId, /* The font family to initialize for. */ + const char * familyName, /* The font family name, if known. Otherwise + * this can be NULL. */ + int size, /* Point size for the font. */ + int qdStyle, /* QuickDraw style bits. */ + MacFont * fontPtr) /* Filled with information constructed from the + * above arguments. */ { OSStatus err; FontInfo fi; @@ -1565,38 +1274,30 @@ InitFont( int periodWidth, wWidth; if (size == 0) { - size = GetDefFontSize(); + size = GetDefFontSize(); } points = (short) TkFontGetPoints(tkwin, size); - - err = FetchFontInfo(familyId, points, qdStyle, &fi); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "FetchFontInfo(): Error %d\n", (int) err); - } -#endif - + ChkErr(FetchFontInfo, familyId, points, qdStyle, &fi); if (familyName == NULL) { - char name[256] = ""; - const MacFontFamily * familyPtr; - - err = GetFontFamilyName(familyId, name, sizeof(name)); - if (err == noErr) { - - /* - * We find the canonical font name, so we can avoid unnecessary - * memory management. - */ - - familyPtr = FindFontFamily(name); - if (familyPtr != NULL) { - familyName = familyPtr->name; - } else { + char name[256] = ""; + const MacFontFamily * familyPtr; + + err = ChkErr(GetFontFamilyName, familyId, name, sizeof(name)); + if (err == noErr) { + /* + * We find the canonical font name, so we can avoid unnecessary + * memory management. + */ + + familyPtr = FindFontFamily(name); + if (familyPtr != NULL) { + familyName = familyPtr->name; + } else { #ifdef TK_MAC_DEBUG_FONTS - fprintf(stderr, "Font family '%s': Not found\n", name); + TkMacOSXDbgMsg("Font family '%s' not found", name); #endif - } - } + } + } } fontPtr->font.fid = (Font) fontPtr; @@ -1613,8 +1314,8 @@ InitFont( /* * Note: Macs measure the line height as ascent + descent + - * leading. Leading as a separate entity does not exist in X11 - * and Tk. We add it to the ascent at the moment, because adding + * leading. Leading as a separate entity does not exist in X11 + * and Tk. We add it to the ascent at the moment, because adding * it to the descent, as the Mac docs would indicate, would change * the position of self-drawn underlines. */ @@ -1627,9 +1328,8 @@ InitFont( fontPtr->qdSize = points; fontPtr->qdStyle = (short) qdStyle; - InitATSUObjects( - familyId, points, qdStyle, - &fontPtr->atsuFontId, &fontPtr->atsuLayout, &fontPtr->atsuStyle); + InitATSUObjects(familyId, points, qdStyle, &fontPtr->atsuFontId, + &fontPtr->atsuLayout, &fontPtr->atsuStyle); Tk_MeasureChars((Tk_Font)fontPtr, ".", 1, -1, 0, &periodWidth); Tk_MeasureChars((Tk_Font)fontPtr, "W", 1, -1, 0, &wWidth); @@ -1645,31 +1345,29 @@ InitFont( * * InitATSUObjects -- * - * Helper for InitFont(). Initializes the ATSU data handles for a - * MacFont. + * Helper for InitFont(). Initializes the ATSU data handles for a + * MacFont. * * Results: - * - * Sets up all we know and can do at this point in time in fontIdPtr, - * layoutPtr and stylePtr. + * Sets up all we know and can do at this point in time in fontIdPtr, + * layoutPtr and stylePtr. * * Side effects: - * - * Allocates data structures inside of ATSU. + * Allocates data structures inside of ATSU. * *--------------------------------------------------------------------------- */ static void InitATSUObjects( - FMFontFamily familyId, /* The font family to use. */ - short ptSize, short qdStyles, /* The additional font parameters. */ - ATSUFontID * fontIdPtr, /* Filled with the font id. */ - ATSUTextLayout * layoutPtr, /* Filled with the ATSU layout handle. */ - ATSUStyle * stylePtr) /* Filled with the ATSU style handle, - * configured with all parameters. */ + FMFontFamily familyId, /* The font family to use. */ + short ptSize, short qdStyles, + /* The additional font parameters. */ + ATSUFontID *fontIdPtr, /* Filled with the font id. */ + ATSUTextLayout *layoutPtr, /* Filled with the ATSU layout handle. */ + ATSUStyle *stylePtr) /* Filled with the ATSU style handle, + * configured with all parameters. */ { - OSStatus err; FMFontStyle stylesDone, stylesLeft; /* @@ -1684,14 +1382,8 @@ InitATSUObjects( * Generate a font id from family id and QD style bits. */ - err = FMGetFontFromFontFamilyInstance( - familyId, qdStyles, fontIdPtr, &stylesDone); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "FMGetFontFromFontFamilyInstance(): Error %d\n", - (int) err); - } -#endif + ChkErr(FMGetFontFromFontFamilyInstance, familyId, qdStyles, fontIdPtr, + &stylesDone); /* * We see what style bits are left and tell ATSU to synthesize what's @@ -1704,25 +1396,15 @@ InitATSUObjects( * Create the style and set its attributes. */ - err = ATSUCreateStyle(stylePtr); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "ATSUCreateStyle(): Error %d\n", (int) err); - } -#endif + ChkErr(ATSUCreateStyle, stylePtr); InitATSUStyle(*fontIdPtr, ptSize, stylesLeft, *stylePtr); /* - * Create the layout. Note: We can't set the layout attributes here, + * Create the layout. Note: We can't set the layout attributes here, * because the text and the style must be set first. */ - err = ATSUCreateTextLayout(layoutPtr); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "ATSUCreateTextLayout(): Error %d\n", (int) err); - } -#endif + ChkErr(ATSUCreateTextLayout, layoutPtr); /*InitATSULayout(*layoutPtr);*/ } @@ -1731,25 +1413,24 @@ InitATSUObjects( * * InitATSUStyle -- * - * Helper for InitATSUObjects(). Initializes the ATSU style for a - * MacFont. + * Helper for InitATSUObjects(). Initializes the ATSU style for a + * MacFont. * * Results: - * - * Sets up all parameters needed for an ATSU style. + * Sets up all parameters needed for an ATSU style. * * Side effects: - * - * Allocates data structures for the style inside of ATSU. + * Allocates data structures for the style inside of ATSU. * *--------------------------------------------------------------------------- */ static void InitATSUStyle( - ATSUFontID fontId, /* The font id to use. */ - short ptSize, short qdStyles, /* Additional font parameters. */ - ATSUStyle style) /* The style handle to configure. */ + ATSUFontID fontId, /* The font id to use. */ + short ptSize, short qdStyles, + /* Additional font parameters. */ + ATSUStyle style) /* The style handle to configure. */ { /* * Attributes for the style. @@ -1757,69 +1438,57 @@ InitATSUStyle( Fixed fsize = IntToFixed(ptSize); Boolean - isBold = (qdStyles&bold) != 0, - isUnderline = (qdStyles&underline) != 0, - isItalic = (qdStyles&italic) != 0; + isBold = (qdStyles&bold) != 0, + isUnderline = (qdStyles&underline) != 0, + isItalic = (qdStyles&italic) != 0; ATSStyleRenderingOptions options = - antialiasedTextEnabled == -1 ? kATSStyleNoOptions : - antialiasedTextEnabled == 0 ? kATSStyleNoAntiAliasing : - kATSStyleApplyAntiAliasing; + antialiasedTextEnabled == -1 ? kATSStyleNoOptions : + antialiasedTextEnabled == 0 ? kATSStyleNoAntiAliasing : + kATSStyleApplyAntiAliasing; static const ATSUAttributeTag styleTags[] = { - kATSUFontTag, kATSUSizeTag, - kATSUQDBoldfaceTag, kATSUQDItalicTag, kATSUQDUnderlineTag, - kATSUStyleRenderingOptionsTag, + kATSUFontTag, kATSUSizeTag, + kATSUQDBoldfaceTag, kATSUQDItalicTag, kATSUQDUnderlineTag, + kATSUStyleRenderingOptionsTag, }; static const ByteCount styleSizes[] = { - sizeof(ATSUFontID), sizeof(Fixed), - sizeof(Boolean), sizeof(Boolean), sizeof(Boolean), - sizeof(ATSStyleRenderingOptions), + sizeof(ATSUFontID), sizeof(Fixed), + sizeof(Boolean), sizeof(Boolean), sizeof(Boolean), + sizeof(ATSStyleRenderingOptions), }; const ATSUAttributeValuePtr styleValues[] = { - &fontId, &fsize, - &isBold, &isItalic, &isUnderline, - &options, + &fontId, &fsize, + &isBold, &isItalic, &isUnderline, + &options, }; - OSStatus err; - - err = ATSUSetAttributes( - style, - sizeof(styleTags)/sizeof(styleTags[0]), - styleTags, styleSizes, styleValues); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "ATSUSetAttributes(): Error %d\n", (int) err); - } -#endif + ChkErr(ATSUSetAttributes, style, sizeof(styleTags)/sizeof(styleTags[0]), + styleTags, styleSizes, styleValues); } - /* *--------------------------------------------------------------------------- * * SetFontFeatures -- * - * Helper for InitFont(). Request specific font features of the ATSU - * style object for a MacFont. + * Helper for InitFont(). Request specific font features of the ATSU + * style object for a MacFont. * * Results: - * - * None. + * None. * * Side effects: - * - * Specific font features are enabled on the ATSU style object. + * Specific font features are enabled on the ATSU style object. * *--------------------------------------------------------------------------- */ static void SetFontFeatures( - ATSUFontID fontId, /* The font id to use. */ - int fixed, /* Is this a fixed font? */ - ATSUStyle style) /* The style handle to configure. */ + ATSUFontID fontId, /* The font id to use. */ + int fixed, /* Is this a fixed font? */ + ATSUStyle style) /* The style handle to configure. */ { /* * Don't use the standard latin ligatures, if this is determined to be a @@ -1827,24 +1496,16 @@ SetFontFeatures( */ static const ATSUFontFeatureType fixed_featureTypes[] = { - kLigaturesType, kLigaturesType + kLigaturesType, kLigaturesType }; static const ATSUFontFeatureSelector fixed_featureSelectors[] = { - kCommonLigaturesOffSelector, kRareLigaturesOffSelector + kCommonLigaturesOffSelector, kRareLigaturesOffSelector }; - OSStatus err; - if (fixed) { - err = ATSUSetFontFeatures( - style, - sizeof(fixed_featureTypes)/sizeof(fixed_featureTypes[0]), - fixed_featureTypes, fixed_featureSelectors); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "ATSUSetFontFeatures(): Error %d\n", (int) err); - } -#endif + ChkErr(ATSUSetFontFeatures, style, sizeof(fixed_featureTypes) / + sizeof(fixed_featureTypes[0]), fixed_featureTypes, + fixed_featureSelectors); } } @@ -1853,17 +1514,15 @@ SetFontFeatures( * * AdjustFontHeight -- * - * Helper for InitFont(). Check font height against some real world - * examples. + * Helper for InitFont(). Check font height against some real world + * examples. * * Results: - * - * None. + * None. * * Side effects: - * - * The metrics in fontPtr->font.fm are adjusted so that typical combined - * characters fit into ascent+descent. + * The metrics in fontPtr->font.fm are adjusted so that typical combined + * characters fit into ascent+descent. * *--------------------------------------------------------------------------- */ @@ -1875,7 +1534,7 @@ AdjustFontHeight( /* * The standard values for ascent, descent and leading as determined in * InitFont do not take composition into account, they are designed for - * plain ASCII characters. This code measures the actual size of some + * plain ASCII characters. This code measures the actual size of some * typical composed characters from the Latin-1 range and corrects these * factors, especially the ascent. * @@ -1883,237 +1542,174 @@ AdjustFontHeight( * than requested. * * An alternative would be to instruct ATSU to shrink oversized combined - * characters. I think I have seen that feature somewhere, but I can't + * characters. I think I have seen that feature somewhere, but I can't * find it now [BR]. */ static const UniChar chars[] - /* Auml, Aacute, Acirc, Atilde, Ccedilla */ - = {0x00C4, 0x00C1, 0x00C2, 0x00C3, 0x00C7}; + /* Auml, Aacute, Acirc, Atilde, Ccedilla */ + = {0x00C4, 0x00C1, 0x00C2, 0x00C3, 0x00C7}; static const int charslen = sizeof(chars) / sizeof(chars[0]); - - DrawingContext drawingContext; Rect size; OSStatus err; - -#if TK_MAC_USE_QUARZ - TkMacOSXQuarzStartDraw(&drawingContext); -#endif - - TkMacOSXLayoutSetString(fontPtr, &drawingContext, chars, charslen); + LayoutSetString(fontPtr, NULL, chars, charslen); size.top = size.bottom = 0; - err = ATSUMeasureTextImage( - fontPtr->atsuLayout, - 0, charslen, - 0, 0, - &size); - -#if TK_MAC_USE_QUARZ - TkMacOSXQuarzEndDraw(&drawingContext); -#endif + err = ChkErr(ATSUMeasureTextImage, fontPtr->atsuLayout, 0, charslen, 0, 0, + &size); - if (err != noErr) { -#ifdef TK_MAC_DEBUG_FONTS - fprintf(stderr, "ATSUMeasureTextImage(): Error %d\n", (int) err); -#endif - } else { - TkFontMetrics * fmPtr = &fontPtr->font.fm; - int ascent = -size.top; - int descent = size.bottom; - - if (ascent > fmPtr->ascent) { - fmPtr->ascent = ascent; - } - if (descent > fmPtr->descent) { - fmPtr->descent = descent; - } + if (err == noErr) { + TkFontMetrics * fmPtr = &fontPtr->font.fm; + int ascent = -size.top; + int descent = size.bottom; + + if (ascent > fmPtr->ascent) { + fmPtr->ascent = ascent; + } + if (descent > fmPtr->descent) { + fmPtr->descent = descent; + } } } - /* *--------------------------------------------------------------------------- * * InitATSULayout -- * - * Helper for TkMacOSXLayoutSetString(). Initializes the ATSU layout - * object for a MacFont and a specific string. + * Helper for LayoutSetString(). Initializes the ATSU layout + * object for a MacFont and a specific string. * * Results: - * - * Sets up all parameters needed for an ATSU layout object. + * Sets up all parameters needed for an ATSU layout object. * * Side effects: - * - * Allocates data structures for the layout object inside of ATSU. + * Allocates data structures for the layout object inside of ATSU. * * Assumptions: - * - * The actual string data and style information is already set by - * ATSUSetTextPointerLocation() and ATSUSetRunStyle() (see - * TkMacOSXLayoutSetString()). + * The actual string data and style information is already set by + * ATSUSetTextPointerLocation() and ATSUSetRunStyle() (see + * LayoutSetString()). * *--------------------------------------------------------------------------- */ static void InitATSULayout( - const DrawingContext * drawingContextPtr, - /* Specifies the CGContext to use. */ - ATSUTextLayout layout, /* The layout object to configure. */ - int fixed) /* Is this a fixed font? */ + const TkMacOSXDrawingContext *drawingContextPtr, + /* Specifies the CGContext to use. */ + ATSUTextLayout layout, /* The layout object to configure. */ + int fixed) /* Is this a fixed font? */ { /* * Attributes for the layout. */ - ATSLineLayoutOptions layoutOptions = - 0 + ATSLineLayoutOptions layoutOptions = 0 #if TK_MAC_COALESCE_LINE - /* - * Options to use unconditionally, when we try to do coalescing in here. - */ - | kATSLineDisableAllLayoutOperations - | kATSLineFractDisable - | kATSLineUseDeviceMetrics + /* + * Options to use unconditionally when we try to do coalescing. + */ + | kATSLineDisableAllLayoutOperations + | kATSLineFractDisable + | kATSLineUseDeviceMetrics #endif - ; + ; + CGContextRef context = drawingContextPtr ? + drawingContextPtr->context : NULL; static const ATSUAttributeTag layoutTags[] = { -#if TK_MAC_USE_QUARZ - kATSUCGContextTag, -#endif - kATSULineLayoutOptionsTag, + kATSUCGContextTag, + kATSULineLayoutOptionsTag, }; static const ByteCount layoutSizes[] = { -#if TK_MAC_USE_QUARZ - sizeof(CGContextRef), -#endif - sizeof(ATSLineLayoutOptions), + sizeof(CGContextRef), + sizeof(ATSLineLayoutOptions), }; const ATSUAttributeValuePtr layoutValues[] = { -#if TK_MAC_USE_QUARZ - (void*)&drawingContextPtr->cgContext, -#endif - &layoutOptions, + &context, + &layoutOptions, }; - OSStatus err; - /* * Ensure W(abcdefg) == W(a)*7 for fixed fonts (Latin scripts only). */ if (fixed) { - layoutOptions |= - kATSLineFractDisable - | kATSLineUseDeviceMetrics - ; - } - - err = ATSUSetLayoutControls( - layout, - sizeof(layoutTags)/sizeof(layoutTags[0]), - layoutTags, layoutSizes, layoutValues); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "ATSUSetLayoutControls(): Error %d\n", (int) err); + layoutOptions |= kATSLineFractDisable | kATSLineUseDeviceMetrics; } -#endif - err = ATSUSetTransientFontMatching(layout, true); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "ATSUSetTransientFontMatching(): Error %d\n", - (int) err); - } -#endif + ChkErr(ATSUSetLayoutControls, layout, sizeof(layoutTags) / + sizeof(layoutTags[0]), layoutTags, layoutSizes, layoutValues); + ChkErr(ATSUSetTransientFontMatching, layout, true); } /* *--------------------------------------------------------------------------- * - * TkMacOSXLayoutSetString -- + * LayoutSetString -- * - * Setup the MacFont for a specific string. + * Setup the MacFont for a specific string. * * Results: - * - * Sets up all parameters so that ATSU can work with the objects in - * MacFont. + * Sets up all parameters so that ATSU can work with the objects in + * MacFont. * * Side effects: - * - * Sets parameters on the layout object fontPtr->atsuLayout. + * Sets parameters on the layout object fontPtr->atsuLayout. * *--------------------------------------------------------------------------- */ void -TkMacOSXLayoutSetString( - const MacFont * fontPtr, /* The fontPtr to configure. */ - const DrawingContext * drawingContextPtr, - /* For the CGContext to be used.*/ - const UniChar * uchars, int ulen) /* The UniChar string to set into - * fontPtr->atsuLayout. */ +LayoutSetString( + const MacFont *fontPtr, /* The fontPtr to configure. */ + const TkMacOSXDrawingContext *drawingContextPtr, + /* For the CGContext to be used.*/ + const UniChar *uchars, int ulen) + /* The UniChar string to set into + * fontPtr->atsuLayout. */ { - OSStatus err; - err = ATSUSetTextPointerLocation( - fontPtr->atsuLayout, - uchars, kATSUFromTextBeginning, ulen, - ulen); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "ATSUSetTextPointerLocation(): Error %d\n", (int) err); - } -#endif + ChkErr(ATSUSetTextPointerLocation, fontPtr->atsuLayout, uchars, + kATSUFromTextBeginning, ulen, ulen); /* * Styles can only be set after the text is set. */ - err = ATSUSetRunStyle( - fontPtr->atsuLayout, fontPtr->atsuStyle, - kATSUFromTextBeginning, kATSUToTextEnd); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "ATSUSetRunStyle(): Error %d\n", (int) err); - } -#endif + ChkErr(ATSUSetRunStyle, fontPtr->atsuLayout, fontPtr->atsuStyle, + kATSUFromTextBeginning, kATSUToTextEnd); /* * Layout attributes can only be set after the styles are set. */ - InitATSULayout( - drawingContextPtr, fontPtr->atsuLayout, - fontPtr->font.fm.fixed); + InitATSULayout(drawingContextPtr, fontPtr->atsuLayout, + fontPtr->font.fm.fixed); } - /* *------------------------------------------------------------------------- * * 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. */ { ATSUDisposeTextLayout(fontPtr->atsuLayout); ATSUDisposeStyle(fontPtr->atsuStyle); @@ -2124,40 +1720,40 @@ ReleaseFont( * * FindFontFamilyOrAlias, FindFontFamilyOrAliasOrFallback -- * - * Determine 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. + * Determine 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. * - * FindFontFamilyOrAlias also considers font aliases as determined by - * TkFontGetAliasList(). + * FindFontFamilyOrAlias also considers font aliases as determined by + * TkFontGetAliasList(). * - * FindFontFamilyOrAliasOrFallback also considers font aliases as - * determined by TkFontGetFallbacks(). + * FindFontFamilyOrAliasOrFallback also considers font aliases as + * determined by TkFontGetFallbacks(). * - * The overall algorithm to get the closest font to the one requested is - * this: + * The overall algorithm to get the closest font to the one requested is + * this: * - * try fontname - * try all aliases for fontname - * foreach fallback for fontname - * try the fallback - * try all aliases for the fallback + * try fontname + * try all aliases for fontname + * foreach fallback for fontname + * try the fallback + * try all aliases for the fallback * * Results: * - * The return value is NULL if the specified font family does not exist, - * a valid MacFontFamily* otherwise. + * The return value is NULL if the specified font family does not exist, + * a valid MacFontFamily* otherwise. * * Side effects: * - * None. + * None. * *------------------------------------------------------------------------- */ static const MacFontFamily * FindFontFamilyOrAlias( - const char * name) /* Name or alias name of the font to find. */ + const char *name) /* Name or alias name of the font to find. */ { const MacFontFamily * familyPtr; char ** aliases; @@ -2165,24 +1761,24 @@ FindFontFamilyOrAlias( familyPtr = FindFontFamily(name); if (familyPtr != NULL) { - return familyPtr; + return familyPtr; } aliases = TkFontGetAliasList(name); if (aliases != NULL) { - for (i = 0; aliases[i] != NULL; i++) { - familyPtr = FindFontFamily(aliases[i]); - if (familyPtr != NULL) { - return familyPtr; - } - } + for (i = 0; aliases[i] != NULL; i++) { + familyPtr = FindFontFamily(aliases[i]); + if (familyPtr != NULL) { + return familyPtr; + } + } } return NULL; } - + static const MacFontFamily * FindFontFamilyOrAliasOrFallback( - const char * name) /* Name or alias name of the font to find. */ + const char *name) /* Name or alias name of the font to find. */ { const MacFontFamily * familyPtr; const char * fallback; @@ -2191,36 +1787,36 @@ FindFontFamilyOrAliasOrFallback( familyPtr = FindFontFamilyOrAlias(name); if (familyPtr != NULL) { - return familyPtr; + return familyPtr; } fallbacks = TkFontGetFallbacks(); for (i = 0; fallbacks[i] != NULL; i++) { - for (j = 0; (fallback = fallbacks[i][j]) != NULL; j++) { - if (strcasecmp(name, fallback) == 0) { - for (j = 0; (fallback = fallbacks[i][j]) != NULL; j++) { - familyPtr = FindFontFamilyOrAlias(fallback); - if (familyPtr != NULL) { - return familyPtr; - } - } - } - break; /* benny: This "break" is a carry-over from - * tkMacOSXFont.c, but what is actually its purpose - * ???? */ - } + for (j = 0; (fallback = fallbacks[i][j]) != NULL; j++) { + if (strcasecmp(name, fallback) == 0) { + for (j = 0; (fallback = fallbacks[i][j]) != NULL; j++) { + familyPtr = FindFontFamilyOrAlias(fallback); + if (familyPtr != NULL) { + return familyPtr; + } + } + } + break; /* benny: This "break" is a carry-over from + * tkMacOSXFont.c, but what is actually its purpose + * ???? */ + } } /* - * FIXME: We would have liked to recover by re-enumerating fonts. But + * FIXME: We would have liked to recover by re-enumerating fonts. But * that doesn't work, because Carbon seems to cache the inital list of - * fonts. Fonts newly installed don't show up with + * fonts. Fonts newly installed don't show up with * FMCreateFontFamilyIterator()/FMGetNextFontFamily() without a restart - * of the app. Similar problem with fonts removed. + * of the app. Similar problem with fonts removed. */ #ifdef TK_MAC_DEBUG_FONTS - fprintf(stderr, "Font family '%s': Not found\n", name); + TkMacOSXDbgMsg("Font family '%s' not found", name); #endif return NULL; @@ -2231,16 +1827,16 @@ FindFontFamilyOrAliasOrFallback( * * InitFontFamilies -- * - * Helper to TkpFontPkgInit. Use the Font Manager to fill in the - * familyList global array. + * Helper to TkpFontPkgInit. Use the Font Manager to fill in the + * familyList global array. * * Results: * - * None. + * None. * * Side effects: * - * Allocates memory. + * Allocates memory. * *------------------------------------------------------------------------- */ @@ -2248,32 +1844,58 @@ FindFontFamilyOrAliasOrFallback( static void InitFontFamilies(void) { - OSStatus err; + FMFontFamily fontFamily; + Str255 fontName; + SInt16 fontSize; + Style fontStyle; /* * Has this been called before? */ if (familyListNextFree > 0) { - return; + return; } - err = ATSFontFamilyApplyFunction(FontFamilyEnumCallback,NULL); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "ATSFontFamilyApplyFunction(): Error %d\n", (int) err); - } -#endif + ChkErr(ATSFontFamilyApplyFunction, FontFamilyEnumCallback,NULL); - AddFontFamily(APPLFONT_NAME, GetAppFont()); - AddFontFamily(SYSTEMFONT_NAME, GetSysFont()); + if (GetThemeFontAndFamily(kThemeSystemFont, &fontFamily, fontName, + &fontSize, &fontStyle) == noErr) { + AddFontFamily(SYSTEMFONT_NAME, fontFamily); + } + if (GetThemeFontAndFamily(kThemeApplicationFont, &fontFamily, fontName, + &fontSize, &fontStyle) == noErr) { + AddFontFamily(APPLFONT_NAME, fontFamily); + } + if (GetThemeFontAndFamily(kThemeMenuItemFont, &fontFamily, fontName, + &fontSize, &fontStyle) == noErr) { + AddFontFamily(MENUITEMFONT_NAME, fontFamily); + } SortFontFamilies(); } + +/* + *------------------------------------------------------------------------- + * + * FontFamilyEnumCallback -- + * + * Callback for ATSFontFamilyApplyFunction(). + * + * Results: + * + * noErr. + * + * Side effects: + * + * None. + * + *------------------------------------------------------------------------- + */ static OSStatus FontFamilyEnumCallback( - ATSFontFamilyRef family, + ATSFontFamilyRef family, void *refCon) { OSStatus err; @@ -2281,42 +1903,41 @@ FontFamilyEnumCallback( (void) refCon; - err = GetFontFamilyName(family, name, sizeof(name)); + err = ChkErr(GetFontFamilyName, family, name, sizeof(name)); if (err == noErr) { - AddFontFamily(name, family); + AddFontFamily(name, family); } return noErr; } - /* *------------------------------------------------------------------------- * * GetFontFamilyName -- * - * Use the Font Manager to get the name of a given FMFontfamily. This - * currently gets the standard, non-localized QuickDraw name. Other - * names would be possible, see docs for ATSUFindFontName for a - * selection. The MacOSX font selector seems to use the localized - * family name given by ATSUFindFontName(kFontFamilyName), but that API - * doesn't give us a name at all for some fonts. + * Use the Font Manager to get the name of a given FMFontfamily. This + * currently gets the standard, non-localized QuickDraw name. Other + * names would be possible, see docs for ATSUFindFontName for a + * selection. The MacOSX font selector seems to use the localized + * family name given by ATSUFindFontName(kFontFamilyName), but that API + * doesn't give us a name at all for some fonts. * * Results: - * An OS error code, noErr on success. name is filled with the - * resulting name. + * An OS error code, noErr on success. name is filled with the + * resulting name. * * Side effects: - * None. + * None. * *------------------------------------------------------------------------- */ static OSStatus GetFontFamilyName( - FMFontFamily fontFamily, /* The font family for which to find the - * name. */ - char * name, int numBytes) /* Filled with the result. */ + FMFontFamily fontFamily, /* The font family for which to find the + * name. */ + char * name, int numBytes) /* Filled with the result. */ { OSStatus err; Str255 nativeName; @@ -2326,13 +1947,9 @@ GetFontFamilyName( nativeName[0] = 0; name[0] = 0; - - err = FMGetFontFamilyName(fontFamily, nativeName); + err = ChkErr(FMGetFontFamilyName, fontFamily, nativeName); if (err != noErr) { -#ifdef TK_MAC_DEBUG_FONTS - fprintf(stderr, "FMGetFontFamilyName(): Error %d\n", (int) err); -#endif - return err; + return err; } /* @@ -2341,36 +1958,25 @@ GetFontFamilyName( */ encoding = kTextEncodingMacRoman; - err = FMGetFontFamilyTextEncoding(fontFamily, &encoding); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "FMGetFontFamilyTextEncoding(): Error %d\n", (int) err); - } -#endif - + ChkErr(FMGetFontFamilyTextEncoding, fontFamily, &encoding); nameencoding = encoding; - err = RevertTextEncodingToScriptInfo(encoding, &nameencoding, NULL, NULL); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "RevertTextEncodingToScriptInfo(): Error %d\n", - (int) err); - } -#endif + ChkErr(RevertTextEncodingToScriptInfo, encoding, &nameencoding, NULL, + NULL); /* - * Note: We could use Tcl facilities to do the re-encoding here. We'd + * Note: We could use Tcl facilities to do the re-encoding here. We'd * have to maintain tables to map OS encoding codes to Tcl encoding names - * like tkMacOSXFont.c did. Using native re-encoding directly instead is - * a lot easier and future-proof than that. There is one snag, though: I - * have seen CFStringGetCString() crash with invalid encoding ids. But + * like tkMacOSXFont.c did. Using native re-encoding directly instead is + * a lot easier and future-proof than that. There is one snag, though: I + * have seen CFStringGetCString() crash with invalid encoding ids. But * than if that happens it would be a bug in * FMGetFontFamilyTextEncoding() or RevertTextEncodingToScriptInfo(). */ cfString = CFStringCreateWithPascalStringNoCopy( - NULL, nativeName, nameencoding, kCFAllocatorNull); + NULL, nativeName, nameencoding, kCFAllocatorNull); CFStringGetCString( - cfString, name, numBytes, kCFStringEncodingUTF8); + cfString, name, numBytes, kCFStringEncodingUTF8); CFRelease(cfString); return noErr; @@ -2381,41 +1987,39 @@ GetFontFamilyName( * * FindFontFamily -- * - * Find the font family with the given name in the global familyList. - * Uses bsearch() for convenient access. Comparision is done - * non-case-sensitively with CompareFontFamilies() which see. + * Find the font family with the given name in the global familyList. + * Uses bsearch() for convenient access. Comparision is done + * non-case-sensitively with CompareFontFamilies() which see. * * Results: * - * MacFontFamily: A pair of family id and the actual name registered for - * the font. + * MacFontFamily: A pair of family id and the actual name registered for + * the font. * * Side effects: * - * None. + * None. * * Assumption: * - * Requires the familyList array to be sorted. + * Requires the familyList array to be sorted. * *------------------------------------------------------------------------- */ static const MacFontFamily * FindFontFamily( - const char * name) /* The family name. Note: Names are compared - * non-case-sensitive. */ + const char *name) /* The family name. Note: Names are compared + * non-case-sensitive. */ { const MacFontFamily key = {name,-1}; if(familyListMaxValid <= 0) { - return NULL; + return NULL; } - return bsearch( - &key, - familyList, familyListMaxValid, sizeof(*familyList), - CompareFontFamilies); + return bsearch(&key, familyList, familyListMaxValid, sizeof(*familyList), + CompareFontFamilies); } /* @@ -2423,15 +2027,13 @@ FindFontFamily( * * EnumFontFamilies -- * - * Create a Tcl list with the registered names in the global familyList. + * Create a Tcl list with the registered names in the global familyList. * * Results: - * - * A Tcl list of names. + * A Tcl list of names. * * Side effects: - * - * None. + * None. * *------------------------------------------------------------------------- */ @@ -2444,8 +2046,8 @@ EnumFontFamilies(void) tclList = Tcl_NewListObj(0, NULL); for (i=0; i<familyListMaxValid; ++i) { - Tcl_ListObjAppendElement( - NULL, tclList, Tcl_NewStringObj(familyList[i].name, -1)); + Tcl_ListObjAppendElement(NULL, tclList, + Tcl_NewStringObj(familyList[i].name, -1)); } return tclList; @@ -2456,33 +2058,32 @@ EnumFontFamilies(void) * * AddFontFamily -- * - * Register a font family in familyList. Until SortFontFamilies() is - * called, this is not actually available for FindFontFamily(). + * Register a font family in familyList. Until SortFontFamilies() is + * called, this is not actually available for FindFontFamily(). * * Results: * - * MacFontFamily: The new pair of family id and the actual name - * registered for the font. + * MacFontFamily: The new pair of family id and the actual name + * registered for the font. * * Side effects: * - * New entry in familyList and familyListNextFree updated. + * New entry in familyList and familyListNextFree updated. * *------------------------------------------------------------------------- */ static const MacFontFamily * AddFontFamily( - const char * name, /* Font family name to register. */ - FMFontFamily familyId) /* Font family id to register. */ + const char *name, /* Font family name to register. */ + FMFontFamily familyId) /* Font family id to register. */ { MacFontFamily * familyPtr; if (familyListNextFree >= familyListSize) { - familyListSize += 100; - familyList = (MacFontFamily *) ckrealloc( - (void*) familyList, - familyListSize * sizeof(*familyList)); + familyListSize += 100; + familyList = (MacFontFamily *) ckrealloc((void*) familyList, + familyListSize * sizeof(*familyList)); } familyPtr = familyList + familyListNextFree; @@ -2499,18 +2100,18 @@ AddFontFamily( * * SortFontFamilies -- * - * Sort the entries in familyList. Only after calling - * SortFontFamilies(), the new families registered with AddFontFamily() - * are actually available for FindFontFamily(), because FindFontFamily() - * requires the array to be sorted. + * Sort the entries in familyList. Only after calling + * SortFontFamilies(), the new families registered with AddFontFamily() + * are actually available for FindFontFamily(), because FindFontFamily() + * requires the array to be sorted. * * Results: * - * None. + * None. * * Side effects: * - * familyList is sorted and familyListMaxValid is updated. + * familyList is sorted and familyListMaxValid is updated. * *------------------------------------------------------------------------- */ @@ -2519,8 +2120,8 @@ static void SortFontFamilies(void) { if (familyListNextFree > 0) { - qsort( familyList, familyListNextFree, sizeof(*familyList), - CompareFontFamilies); + qsort(familyList, familyListNextFree, sizeof(*familyList), + CompareFontFamilies); } familyListMaxValid = familyListNextFree; } @@ -2530,21 +2131,19 @@ SortFontFamilies(void) * * CompareFontFamilies -- * - * Comparison function used by SortFontFamilies() and FindFontFamily(). + * Comparison function used by SortFontFamilies() and FindFontFamily(). * * Results: + * Result as required to generate a stable sort order for bsearch() and + * qsort(). The ordering is not case-sensitive as far as + * Tcl_UtfNcasecmp() (which see) can provide that. * - * Result as required to generate a stable sort order for bsearch() and - * qsort(). The ordering is not case-sensitive as far as - * Tcl_UtfNcasecmp() (which see) can provide that. - * - * Note: It would be faster to compare first the length and the actual - * strings only as a tie-breaker, but than the ordering wouldn't look so - * pretty in [font families] ;-). + * Note: It would be faster to compare first the length and the actual + * strings only as a tie-breaker, but than the ordering wouldn't look so + * pretty in [font families] ;-). * * Side effects: - * - * None. + * None. * *------------------------------------------------------------------------- */ @@ -2556,9 +2155,7 @@ CompareFontFamilies( { const char * name1; const char * name2; - int len1; - int len2; - int diff; + int len1, len2, diff; name1 = ((const MacFontFamily *) vp1)->name; name2 = ((const MacFontFamily *) vp2)->name; @@ -2576,36 +2173,34 @@ CompareFontFamilies( * * AddString -- * - * Helper for AddFontFamily(). Allocates a string in the one-shot - * allocator. + * Helper for AddFontFamily(). Allocates a string in the one-shot + * allocator. * * Results: - * - * A duplicated string in the one-shot allocator. + * A duplicated string in the one-shot allocator. * * Side effects: - * - * May allocate a new memory block. + * May allocate a new memory block. * *------------------------------------------------------------------------- */ static const char * AddString( - const char * in) /* String to add, zero-terminated. */ + const char *in) /* String to add, zero-terminated. */ { int len; - char * result; - + char *result; + len = strlen(in) +1; if (stringMemory == NULL - || (stringMemory->nextFree+len) > STRING_BLOCK_MAX ) { - StringBlock * newblock = - (StringBlock *) ckalloc(sizeof(StringBlock)); - newblock->next = stringMemory; - newblock->nextFree = 0; - stringMemory = newblock; + || (stringMemory->nextFree+len) > STRING_BLOCK_MAX) { + StringBlock * newblock = (StringBlock *) ckalloc(sizeof(StringBlock)); + + newblock->next = stringMemory; + newblock->nextFree = 0; + stringMemory = newblock; } result = stringMemory->strings + stringMemory->nextFree; @@ -2621,27 +2216,27 @@ AddString( * * TkMacOSXIsCharacterMissing -- * - * Given a tkFont and a character determine whether the character has - * a glyph defined in the font or not. + * Given a tkFont and a character determine whether the character has + * a glyph defined in the font 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. */ { /* Background: This function is private and only used in * tkMacOSXMenu.c:FindMarkCharacter(). * - * We could use ATSUMatchFont() to implement. We'd have to change the + * We could use ATSUMatchFont() to implement. We'd have to change the * definition of the encoding of the parameter searchChar from MacRoman * to UniChar for that. * @@ -2656,30 +2251,27 @@ TkMacOSXIsCharacterMissing( * * TkMacOSXInitControlFontStyle -- * - * This procedure sets up the appropriate ControlFontStyleRec - * for a Mac control. + * This procedure sets up the appropriate ControlFontStyleRec + * for a Mac control. * * Results: - * None. + * None. * * Side effects: - * None. + * None. * *---------------------------------------------------------------------- */ void TkMacOSXInitControlFontStyle( - Tk_Font tkfont, /* Tk font object to use for the control. */ - ControlFontStylePtr fsPtr) /* The style object to configure. */ + Tk_Font tkfont, /* Tk font object to use for the control. */ + ControlFontStylePtr fsPtr) /* The style object to configure. */ { - const MacFont * fontPtr; - fontPtr = (MacFont *) tkfont; - fsPtr->flags = - kControlUseFontMask| - kControlUseSizeMask| - kControlUseFaceMask| - kControlUseJustMask; + const MacFont * fontPtr = (MacFont *) tkfont; + + fsPtr->flags = kControlUseFontMask | kControlUseSizeMask | + kControlUseFaceMask | kControlUseJustMask; fsPtr->font = fontPtr->qdFont; fsPtr->size = fontPtr->qdSize; fsPtr->style = fontPtr->qdStyle; @@ -2691,46 +2283,46 @@ TkMacOSXInitControlFontStyle( * * TkMacOSXUseAntialiasedText -- * - * Enables or disables application-wide use of antialiased text (where - * available). Sets up a linked Tcl global variable to allow - * disabling of antialiased text from tcl. - * The possible values for this variable are: + * Enables or disables application-wide use of antialiased text (where + * available). Sets up a linked Tcl global variable to allow + * disabling of antialiased text from tcl. + * The possible values for this variable are: * - * -1 - Use system default as configurable in "System Preferences" -> - * "General". - * 0 - Unconditionally disable antialiasing. - * 1 - Unconditionally enable antialiasing. + * -1 - Use system default as configurable in "System Preferences" -> + * "General". + * 0 - Unconditionally disable antialiasing. + * 1 - Unconditionally enable antialiasing. * * Results: * - * TCL_OK. + * TCL_OK. * * Side effects: * - * None. + * None. * *---------------------------------------------------------------------- */ MODULE_SCOPE int TkMacOSXUseAntialiasedText( - Tcl_Interp * interp, /* The Tcl interpreter to receive the - * variable .*/ - int enable) /* Initial value. */ + Tcl_Interp * interp, /* The Tcl interpreter to receive the + * variable.*/ + int enable) /* Initial value. */ { static Boolean initialized = FALSE; - if(!initialized) { - initialized = TRUE; - - if (Tcl_CreateNamespace(interp, "::tk::mac", NULL, NULL) == NULL) { - Tcl_ResetResult(interp); - } - if (Tcl_LinkVar(interp, "::tk::mac::antialiasedtext", - (char *) &antialiasedTextEnabled, - TCL_LINK_INT) != TCL_OK) { - Tcl_ResetResult(interp); - } + if (!initialized) { + initialized = TRUE; + + if (Tcl_CreateNamespace(interp, "::tk::mac", NULL, NULL) == NULL) { + Tcl_ResetResult(interp); + } + if (Tcl_LinkVar(interp, "::tk::mac::antialiasedtext", + (char *) &antialiasedTextEnabled, + TCL_LINK_INT) != TCL_OK) { + Tcl_ResetResult(interp); + } } antialiasedTextEnabled = enable; return TCL_OK; |