summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXFont.c
diff options
context:
space:
mode:
authordas <das>2008-06-19 00:10:54 (GMT)
committerdas <das>2008-06-19 00:10:54 (GMT)
commit67c11f668fa08165fee1456c81361bb7adfe6d74 (patch)
treeade443eeeea6886f3834bb83452b3e0f90d72e36 /macosx/tkMacOSXFont.c
parent97adda8abbf04c68397fb636005a3a871f0b914c (diff)
downloadtk-67c11f668fa08165fee1456c81361bb7adfe6d74.zip
tk-67c11f668fa08165fee1456c81361bb7adfe6d74.tar.gz
tk-67c11f668fa08165fee1456c81361bb7adfe6d74.tar.bz2
* macosx/tkMacOSXFont.c (TkpGetFontFromAttributes, InitFont): fix
incorrect conversion to points of font sizes already in points; factor out retrieval of font family name from font family ID.
Diffstat (limited to 'macosx/tkMacOSXFont.c')
-rw-r--r--macosx/tkMacOSXFont.c99
1 files changed, 65 insertions, 34 deletions
diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c
index 00d1976..66d92f2 100644
--- a/macosx/tkMacOSXFont.c
+++ b/macosx/tkMacOSXFont.c
@@ -5,7 +5,7 @@
* 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>
+ * Copyright (c) 2006-2008 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:
@@ -35,7 +35,7 @@
* 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.37 2007/12/13 15:27:09 dgp Exp $
+ * RCS: @(#) $Id: tkMacOSXFont.c,v 1.37.2.1 2008/06/19 00:10:54 das Exp $
*/
#include "tkMacOSXPrivate.h"
@@ -213,8 +213,9 @@ static const Tcl_UniChar *UpdateLineBuffer(const MacFont *fontPtr,
* 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 const char *FamilyNameForFamilyID(FMFontFamily familyId);
+static void InitFont(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,
@@ -470,7 +471,7 @@ TkpGetNativeFont(
CopyPascalStringToC(fontName, (char*)fontName);
fontPtr = (MacFont *) ckalloc(sizeof(MacFont));
- InitFont(tkwin, fontFamily, (char*)fontName, fontSize, fontStyle, fontPtr);
+ InitFont(fontFamily, (char*)fontName, fontSize, fontStyle, fontPtr);
return (TkFont *) fontPtr;
}
@@ -549,7 +550,8 @@ TkpGetFontFromAttributes(
fontPtr = (MacFont *) tkFontPtr;
ReleaseFont(fontPtr);
}
- InitFont(tkwin, familyId, name, faPtr->size, qdStyle, fontPtr);
+ InitFont(familyId, name, TkFontGetPoints(tkwin, faPtr->size),
+ qdStyle, fontPtr);
return (TkFont *) fontPtr;
}
@@ -1372,6 +1374,48 @@ UpdateLineBuffer(
/*
*---------------------------------------------------------------------------
*
+ * FamilyNameForFamilyID --
+ *
+ * Helper for InitFont() and TkMacOSXFontDescriptionForFMFontInfo().
+ * Retrieves font family names for a given font family ID.
+ *
+ * Results:
+ * Font family name or NULL.
+ *
+ * Side effects:
+ * None.
+ *
+ *---------------------------------------------------------------------------
+ */
+
+static const char *
+FamilyNameForFamilyID(
+ FMFontFamily familyId)
+{
+ OSStatus err;
+ char name[256] = "";
+ const MacFontFamily * familyPtr = NULL;
+
+ 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);
+#ifdef TK_MAC_DEBUG_FONTS
+ if (!familyPtr) {
+ TkMacOSXDbgMsg("Font family '%s' not found", name);
+ }
+#endif
+ }
+ return familyPtr ? familyPtr->name : NULL;
+}
+
+/*
+ *---------------------------------------------------------------------------
+ *
* InitFont --
*
* Helper for TkpGetNativeFont() and TkpGetFontFromAttributes().
@@ -1393,7 +1437,6 @@ UpdateLineBuffer(
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. */
@@ -1402,45 +1445,24 @@ InitFont(
MacFont * fontPtr) /* Filled with information constructed from the
* above arguments. */
{
- OSStatus err;
FontInfo fi;
TkFontAttributes * faPtr;
TkFontMetrics * fmPtr;
- short points;
int periodWidth, wWidth;
if (size == 0) {
size = GetDefFontSize();
}
- points = (short) TkFontGetPoints(tkwin, size);
- ChkErr(FetchFontInfo, familyId, points, qdStyle, &fi);
- if (familyName == NULL) {
- 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
- TkMacOSXDbgMsg("Font family '%s' not found", name);
-#endif
- }
- }
+ ChkErr(FetchFontInfo, familyId, size, qdStyle, &fi);
+ if (!familyName) {
+ familyName = FamilyNameForFamilyID(familyId);
}
fontPtr->font.fid = (Font) fontPtr;
faPtr = &fontPtr->font.fa;
faPtr->family = familyName;
- faPtr->size = points;
+ faPtr->size = size;
faPtr->weight = (qdStyle & bold) ? TK_FW_BOLD : TK_FW_NORMAL;
faPtr->slant = (qdStyle & italic) ? TK_FS_ITALIC : TK_FS_ROMAN;
faPtr->underline = ((qdStyle & underline) != 0);
@@ -1461,10 +1483,10 @@ InitFont(
fmPtr->maxWidth = fi.widMax;
fontPtr->qdFont = familyId;
- fontPtr->qdSize = points;
+ fontPtr->qdSize = size;
fontPtr->qdStyle = (short) qdStyle;
- InitATSUObjects(familyId, points, qdStyle, &fontPtr->atsuFontId,
+ InitATSUObjects(familyId, size, qdStyle, &fontPtr->atsuFontId,
&fontPtr->atsuLayout, &fontPtr->atsuStyle);
Tk_MeasureChars((Tk_Font)fontPtr, ".", 1, -1, 0, &periodWidth);
@@ -2462,3 +2484,12 @@ TkMacOSXUseAntialiasedText(
antialiasedTextEnabled = enable;
return TCL_OK;
}
+
+/*
+ * Local Variables:
+ * mode: c
+ * c-basic-offset: 4
+ * fill-column: 79
+ * coding: utf-8
+ * End:
+ */