summaryrefslogtreecommitdiffstats
path: root/win/tkWinFont.c
diff options
context:
space:
mode:
Diffstat (limited to 'win/tkWinFont.c')
-rw-r--r--win/tkWinFont.c617
1 files changed, 380 insertions, 237 deletions
diff --git a/win/tkWinFont.c b/win/tkWinFont.c
index f209716..86f63ac 100644
--- a/win/tkWinFont.c
+++ b/win/tkWinFont.c
@@ -50,7 +50,7 @@ typedef struct FontFamily {
int isSymbolFont; /* Non-zero if this is a symbol font. */
int isWideFont; /* 1 if this is a double-byte font, 0
* otherwise. */
- BOOL (WINAPI *textOutProc)(HDC, int, int, TCHAR *, int);
+ BOOL (WINAPI *textOutProc)(HDC hdc, int x, int y, TCHAR *str, int len);
/* The procedure to use to draw text after it
* has been converted from UTF-8 to the
* encoding of this font. */
@@ -94,10 +94,12 @@ typedef struct FontFamily {
typedef struct SubFont {
char **fontMap; /* Pointer to font map from the FontFamily,
* cached here to save a dereference. */
- HFONT hFont; /* The specific screen font that will be used
+ HFONT hFont0; /* The specific screen font that will be used
* when displaying/measuring chars belonging
* to the FontFamily. */
FontFamily *familyPtr; /* The FontFamily for this SubFont. */
+ HFONT hFontAngled;
+ double angle;
} SubFont;
/*
@@ -123,7 +125,6 @@ typedef struct WinFont {
* attributes. Usually points to
* staticSubFonts, but may point to malloced
* space if there are lots of SubFonts. */
-
HWND hwnd; /* Toplevel window of application that owns
* this font, used for getting HDC for
* offscreen measurements. */
@@ -172,7 +173,7 @@ typedef struct ThreadSpecificData {
* currently loaded. As screen fonts are
* loaded, this list grows to hold information
* about what characters exist in each font
- * family. */
+ * family. */
Tcl_HashTable uidTable;
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;
@@ -189,40 +190,45 @@ static Tcl_Encoding systemEncoding;
static FontFamily * AllocFontFamily(HDC hdc, HFONT hFont, int base);
static SubFont * CanUseFallback(HDC hdc, WinFont *fontPtr,
- char *fallbackName, int ch,
+ const char *fallbackName, int ch,
SubFont **subFontPtrPtr);
static SubFont * CanUseFallbackWithAliases(HDC hdc, WinFont *fontPtr,
- char *faceName, int ch, Tcl_DString *nameTriedPtr,
+ const char *faceName, int ch,
+ Tcl_DString *nameTriedPtr,
SubFont **subFontPtrPtr);
-static int FamilyExists(HDC hdc, CONST char *faceName);
-static char * FamilyOrAliasExists(HDC hdc, CONST char *faceName);
+static int FamilyExists(HDC hdc, const char *faceName);
+static const char * FamilyOrAliasExists(HDC hdc, const char *faceName);
static SubFont * FindSubFontForChar(WinFont *fontPtr, int ch,
SubFont **subFontPtrPtr);
static void FontMapInsert(SubFont *subFontPtr, int ch);
static void FontMapLoadPage(SubFont *subFontPtr, int row);
static int FontMapLookup(SubFont *subFontPtr, int ch);
static void FreeFontFamily(FontFamily *familyPtr);
-static HFONT GetScreenFont(CONST TkFontAttributes *faPtr,
- CONST char *faceName, int pixelSize);
+static HFONT GetScreenFont(const TkFontAttributes *faPtr,
+ const char *faceName, int pixelSize,
+ double angle);
static void InitFont(Tk_Window tkwin, HFONT hFont,
int overstrike, WinFont *tkFontPtr);
-static void InitSubFont(HDC hdc, HFONT hFont, int base,
+static inline void InitSubFont(HDC hdc, HFONT hFont, int base,
SubFont *subFontPtr);
static int CreateNamedSystemLogFont(Tcl_Interp *interp,
- Tk_Window tkwin, CONST char* name,
+ Tk_Window tkwin, const char* name,
LOGFONT* logFontPtr);
static int CreateNamedSystemFont(Tcl_Interp *interp,
- Tk_Window tkwin, CONST char* name, HFONT hFont);
+ Tk_Window tkwin, const char* name, HFONT hFont);
static int LoadFontRanges(HDC hdc, HFONT hFont,
USHORT **startCount, USHORT **endCount,
int *symbolPtr);
static void MultiFontTextOut(HDC hdc, WinFont *fontPtr,
- CONST char *source, int numBytes, int x, int y);
+ const char *source, int numBytes, int x, int y,
+ double angle);
static void ReleaseFont(WinFont *fontPtr);
-static void ReleaseSubFont(SubFont *subFontPtr);
-static int SeenName(CONST char *name, Tcl_DString *dsPtr);
-static void SwapLong(PULONG p);
-static void SwapShort(USHORT *p);
+static inline void ReleaseSubFont(SubFont *subFontPtr);
+static int SeenName(const char *name, Tcl_DString *dsPtr);
+static inline HFONT SelectFont(HDC hdc, WinFont *fontPtr,
+ SubFont *subFontPtr, double angle);
+static inline void SwapLong(PULONG p);
+static inline void SwapShort(USHORT *p);
static int CALLBACK WinFontCanUseProc(ENUMLOGFONT *lfPtr,
NEWTEXTMETRIC *tmPtr, int fontType,
LPARAM lParam);
@@ -298,7 +304,7 @@ TkpFontPkgInit(
TkFont *
TkpGetNativeFont(
Tk_Window tkwin, /* For display where font will be used. */
- CONST char *name) /* Platform-specific font name. */
+ const char *name) /* Platform-specific font name. */
{
int object;
WinFont *fontPtr;
@@ -309,7 +315,7 @@ TkpGetNativeFont(
}
tkwin = (Tk_Window) ((TkWindow *) tkwin)->mainPtr->winPtr;
- fontPtr = (WinFont *) ckalloc(sizeof(WinFont));
+ fontPtr = ckalloc(sizeof(WinFont));
InitFont(tkwin, GetStockObject(object), 0, fontPtr);
return (TkFont *) fontPtr;
@@ -317,13 +323,13 @@ TkpGetNativeFont(
/*
*---------------------------------------------------------------------------
+ *
* CreateNamedSystemFont --
*
* This function registers a Windows logical font description with the Tk
* named font mechanism.
*
- * Side effects
- *
+ * Side effects:
* A new named font is added to the Tk font registry.
*
*---------------------------------------------------------------------------
@@ -333,12 +339,12 @@ static int
CreateNamedSystemLogFont(
Tcl_Interp *interp,
Tk_Window tkwin,
- CONST char* name,
- LOGFONTA* logFontPtr)
+ const char* name,
+ LOGFONT* logFontPtr)
{
HFONT hFont;
int r;
-
+
hFont = CreateFontIndirect(logFontPtr);
r = CreateNamedSystemFont(interp, tkwin, name, hFont);
DeleteObject((HGDIOBJ)hFont);
@@ -347,13 +353,13 @@ CreateNamedSystemLogFont(
/*
*---------------------------------------------------------------------------
- * CreateNamedSystemFont --
*
- * This function registers a Windows font with the Tk
- * named font mechanism.
+ * CreateNamedSystemFont --
*
- * Side effects
+ * This function registers a Windows font with the Tk named font
+ * mechanism.
*
+ * Side effects:
* A new named font is added to the Tk font registry.
*
*---------------------------------------------------------------------------
@@ -363,12 +369,12 @@ static int
CreateNamedSystemFont(
Tcl_Interp *interp,
Tk_Window tkwin,
- CONST char* name,
+ const char* name,
HFONT hFont)
{
WinFont winfont;
int r;
-
+
TkDeleteNamedFont(NULL, tkwin, name);
InitFont(tkwin, hFont, 0, &winfont);
r = TkCreateNamedFont(interp, tkwin, name, &winfont.font.fa);
@@ -378,16 +384,19 @@ CreateNamedSystemFont(
/*
*---------------------------------------------------------------------------
+ *
* TkWinSystemFonts --
*
* Create some platform specific named fonts that to give access to the
- * system fonts. These are all defined for the Windows desktop parameters.
+ * system fonts. These are all defined for the Windows desktop
+ * parameters.
*
*---------------------------------------------------------------------------
*/
void
-TkWinSetupSystemFonts(TkMainInfo *mainPtr)
+TkWinSetupSystemFonts(
+ TkMainInfo *mainPtr)
{
Tcl_Interp *interp;
Tk_Window tkwin;
@@ -401,14 +410,14 @@ TkWinSetupSystemFonts(TkMainInfo *mainPtr)
/* force this for now */
if (((TkWindow *) tkwin)->mainPtr == NULL) {
- ((TkWindow *) tkwin)->mainPtr = mainPtr;
+ ((TkWindow *) tkwin)->mainPtr = mainPtr;
}
/*
- * If this API call fails then we will fallback to setting these
- * named fonts from script in ttk/fonts.tcl. So far I've only
- * seen it fail when WINVER has been defined for a higher platform than
- * we are running on. (ie: WINVER=0x0600 and running on XP).
+ * If this API call fails then we will fallback to setting these named
+ * fonts from script in ttk/fonts.tcl. So far I've only seen it fail when
+ * WINVER has been defined for a higher platform than we are running on.
+ * (i.e. WINVER=0x0600 and running on XP).
*/
ZeroMemory(&ncMetrics, sizeof(ncMetrics));
@@ -416,26 +425,26 @@ TkWinSetupSystemFonts(TkMainInfo *mainPtr)
if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(ncMetrics), &ncMetrics, 0)) {
CreateNamedSystemLogFont(interp, tkwin, "TkDefaultFont",
- &ncMetrics.lfMessageFont);
+ &ncMetrics.lfMessageFont);
CreateNamedSystemLogFont(interp, tkwin, "TkHeadingFont",
- &ncMetrics.lfMessageFont);
+ &ncMetrics.lfMessageFont);
CreateNamedSystemLogFont(interp, tkwin, "TkTextFont",
- &ncMetrics.lfMessageFont);
+ &ncMetrics.lfMessageFont);
CreateNamedSystemLogFont(interp, tkwin, "TkMenuFont",
- &ncMetrics.lfMenuFont);
+ &ncMetrics.lfMenuFont);
CreateNamedSystemLogFont(interp, tkwin, "TkTooltipFont",
- &ncMetrics.lfStatusFont);
+ &ncMetrics.lfStatusFont);
CreateNamedSystemLogFont(interp, tkwin, "TkCaptionFont",
- &ncMetrics.lfCaptionFont);
+ &ncMetrics.lfCaptionFont);
CreateNamedSystemLogFont(interp, tkwin, "TkSmallCaptionFont",
- &ncMetrics.lfSmCaptionFont);
+ &ncMetrics.lfSmCaptionFont);
}
iconMetrics.cbSize = sizeof(iconMetrics);
if (SystemParametersInfo(SPI_GETICONMETRICS, sizeof(iconMetrics),
&iconMetrics, 0)) {
CreateNamedSystemLogFont(interp, tkwin, "TkIconFont",
- &iconMetrics.lfFont);
+ &iconMetrics.lfFont);
}
/*
@@ -444,9 +453,9 @@ TkWinSetupSystemFonts(TkMainInfo *mainPtr)
*/
{
- LOGFONTA lfFixed = {
+ LOGFONT lfFixed = {
0, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
- 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, ""
+ 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, TEXT("")
};
long pointSize, dpi;
HDC hdc = GetDC(NULL);
@@ -457,13 +466,13 @@ TkWinSetupSystemFonts(TkMainInfo *mainPtr)
CreateNamedSystemLogFont(interp, tkwin, "TkFixedFont", &lfFixed);
}
- /*
+ /*
* Setup the remaining standard Tk font names as named fonts.
*/
for (mapPtr = systemMap; mapPtr->strKey != NULL; mapPtr++) {
- hFont = (HFONT)GetStockObject(mapPtr->numKey);
- CreateNamedSystemFont(interp, tkwin, mapPtr->strKey, hFont);
+ hFont = (HFONT) GetStockObject(mapPtr->numKey);
+ CreateNamedSystemFont(interp, tkwin, mapPtr->strKey, hFont);
}
}
@@ -505,7 +514,7 @@ TkpGetFontFromAttributes(
* will be released. If NULL, a new TkFont
* structure is allocated. */
Tk_Window tkwin, /* For display where font will be used. */
- CONST TkFontAttributes *faPtr)
+ const TkFontAttributes *faPtr)
/* Set of attributes to match. */
{
int i, j;
@@ -514,7 +523,7 @@ TkpGetFontFromAttributes(
HFONT hFont;
Window window;
WinFont *fontPtr;
- char ***fontFallbacks;
+ const char *const *const *fontFallbacks;
Tk_Uid faceName, fallback, actualName;
tkwin = (Tk_Window) ((TkWindow *) tkwin)->mainPtr->winPtr;
@@ -562,9 +571,9 @@ TkpGetFontFromAttributes(
ReleaseDC(hwnd, hdc);
hFont = GetScreenFont(faPtr, faceName,
- TkFontGetPixels(tkwin, faPtr->size));
+ TkFontGetPixels(tkwin, faPtr->size), 0.0);
if (tkFontPtr == NULL) {
- fontPtr = (WinFont *) ckalloc(sizeof(WinFont));
+ fontPtr = ckalloc(sizeof(WinFont));
} else {
fontPtr = (WinFont *) tkFontPtr;
ReleaseFont(fontPtr);
@@ -629,10 +638,12 @@ TkpGetFontFamilies(
HDC hdc;
HWND hwnd;
Window window;
+ Tcl_Obj *resultObj;
window = Tk_WindowId(tkwin);
hwnd = (window == None) ? NULL : TkWinGetHWND(window);
hdc = GetDC(hwnd);
+ resultObj = Tcl_NewObj();
/*
* On any version NT, there may fonts with international names. Use the
@@ -649,14 +660,10 @@ TkpGetFontFamilies(
* because it only exists under NT.
*/
- if (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT) {
- EnumFontFamiliesW(hdc, NULL, (FONTENUMPROCW) WinFontFamilyEnumProc,
- (LPARAM) interp);
- } else {
- EnumFontFamiliesA(hdc, NULL, (FONTENUMPROCA) WinFontFamilyEnumProc,
- (LPARAM) interp);
- }
+ EnumFontFamilies(hdc, NULL, (FONTENUMPROC) WinFontFamilyEnumProc,
+ (LPARAM) resultObj);
ReleaseDC(hwnd, hdc);
+ Tcl_SetObjResult(interp, resultObj);
}
static int CALLBACK
@@ -666,17 +673,13 @@ WinFontFamilyEnumProc(
int fontType, /* Type of font (not used). */
LPARAM lParam) /* Result object to hold result. */
{
- char *faceName;
+ char *faceName = (char *) lfPtr->elfLogFont.lfFaceName;
+ Tcl_Obj *resultObj = (Tcl_Obj *) lParam;
Tcl_DString faceString;
- Tcl_Obj *strPtr;
- Tcl_Interp *interp;
- interp = (Tcl_Interp *) lParam;
- faceName = lfPtr->elfLogFont.lfFaceName;
Tcl_ExternalToUtfDString(systemEncoding, faceName, -1, &faceString);
- strPtr = Tcl_NewStringObj(Tcl_DStringValue(&faceString),
- Tcl_DStringLength(&faceString));
- Tcl_ListObjAppendElement(NULL, Tcl_GetObjResult(interp), strPtr);
+ Tcl_ListObjAppendElement(NULL, resultObj, Tcl_NewStringObj(
+ Tcl_DStringValue(&faceString), Tcl_DStringLength(&faceString)));
Tcl_DStringFree(&faceString);
return 1;
}
@@ -709,13 +712,14 @@ TkpGetSubFonts(
FontFamily *familyPtr;
Tcl_Obj *resultPtr, *strPtr;
- resultPtr = Tcl_GetObjResult(interp);
+ resultPtr = Tcl_NewObj();
fontPtr = (WinFont *) tkfont;
for (i = 0; i < fontPtr->numSubFonts; i++) {
familyPtr = fontPtr->subFontArray[i].familyPtr;
strPtr = Tcl_NewStringObj(familyPtr->faceName, -1);
Tcl_ListObjAppendElement(NULL, resultPtr, strPtr);
}
+ Tcl_SetObjResult(interp, resultPtr);
}
/*
@@ -740,7 +744,7 @@ 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 */
+ TkFontAttributes *faPtr) /* Output: Font attributes */
{
WinFont *fontPtr = (WinFont *) tkfont;
/* Structure describing the logical font */
@@ -748,22 +752,22 @@ TkpGetFontAttrsForChar(
/* GDI device context */
SubFont *lastSubFontPtr = &fontPtr->subFontArray[0];
/* Pointer to subfont array in case
- * FindSubFontForChar needs to fix up
- * the memory allocation */
- SubFont *thisSubFontPtr = FindSubFontForChar(fontPtr, c,
- &lastSubFontPtr);
- /* Pointer to the subfont to use for
- * the given character */
+ * FindSubFontForChar needs to fix up the
+ * memory allocation */
+ SubFont *thisSubFontPtr =
+ FindSubFontForChar(fontPtr, c, &lastSubFontPtr);
+ /* Pointer to the subfont to use for the given
+ * character */
FontFamily *familyPtr = thisSubFontPtr->familyPtr;
HFONT oldfont; /* Saved font from the device context */
- TEXTMETRIC tm; /* Font metrics of the selected subfont */
+ TEXTMETRICA tm; /* Font metrics of the selected subfont */
/*
* Get the font attributes.
*/
- oldfont = SelectObject(hdc, thisSubFontPtr->hFont);
- GetTextMetrics(hdc, &tm);
+ oldfont = SelectObject(hdc, thisSubFontPtr->hFont0);
+ GetTextMetricsA(hdc, &tm);
SelectObject(hdc, oldfont);
ReleaseDC(fontPtr->hwnd, hdc);
faPtr->family = familyPtr->faceName;
@@ -778,7 +782,7 @@ TkpGetFontAttrsForChar(
/*
*---------------------------------------------------------------------------
*
- * Tk_MeasureChars --
+ * Tk_MeasureChars --
*
* Determine the number of bytes from the string that will fit in the
* given horizontal span. The measurement is done under the assumption
@@ -798,7 +802,7 @@ TkpGetFontAttrsForChar(
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
+ 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. */
@@ -829,7 +833,7 @@ Tk_MeasureChars(
FontFamily *familyPtr;
Tcl_DString runString;
SubFont *thisSubFontPtr, *lastSubFontPtr;
- CONST char *p, *end, *next = NULL, *start;
+ const char *p, *end, *next = NULL, *start;
if (numBytes == 0) {
*lengthPtr = 0;
@@ -840,7 +844,7 @@ Tk_MeasureChars(
hdc = GetDC(fontPtr->hwnd);
lastSubFontPtr = &fontPtr->subFontArray[0];
- oldFont = SelectObject(hdc, lastSubFontPtr->hFont);
+ oldFont = SelectObject(hdc, lastSubFontPtr->hFont0);
/*
* A three step process:
@@ -862,8 +866,8 @@ Tk_MeasureChars(
Tcl_UtfToExternalDString(familyPtr->encoding, start,
(int) (p - start), &runString);
size.cx = 0;
- (*familyPtr->getTextExtentPoint32Proc)(hdc,
- Tcl_DStringValue(&runString),
+ familyPtr->getTextExtentPoint32Proc(hdc,
+ (TCHAR *)Tcl_DStringValue(&runString),
Tcl_DStringLength(&runString) >> familyPtr->isWideFont,
&size);
Tcl_DStringFree(&runString);
@@ -875,7 +879,7 @@ Tk_MeasureChars(
lastSubFontPtr = thisSubFontPtr;
start = p;
- SelectObject(hdc, lastSubFontPtr->hFont);
+ SelectObject(hdc, lastSubFontPtr->hFont0);
}
p = next;
}
@@ -890,8 +894,7 @@ Tk_MeasureChars(
Tcl_UtfToExternalDString(familyPtr->encoding, start,
(int) (p - start), &runString);
size.cx = 0;
- (*familyPtr->getTextExtentPoint32Proc)(hdc,
- Tcl_DStringValue(&runString),
+ familyPtr->getTextExtentPoint32Proc(hdc, (TCHAR *) Tcl_DStringValue(&runString),
Tcl_DStringLength(&runString) >> familyPtr->isWideFont,
&size);
Tcl_DStringFree(&runString);
@@ -924,8 +927,8 @@ Tk_MeasureChars(
&dstWrote, NULL);
Tcl_DStringAppend(&runString,buf,dstWrote);
size.cx = 0;
- (*familyPtr->getTextExtentPoint32Proc)(hdc,
- Tcl_DStringValue(&runString),
+ familyPtr->getTextExtentPoint32Proc(hdc,
+ (TCHAR *) Tcl_DStringValue(&runString),
Tcl_DStringLength(&runString) >> familyPtr->isWideFont,
&size);
if ((curX+size.cx) > maxLength) {
@@ -966,7 +969,7 @@ Tk_MeasureChars(
* procedure without the maxLength limit or any flags.
*/
- CONST char *lastWordBreak = NULL;
+ const char *lastWordBreak = NULL;
Tcl_UniChar ch2;
end = p;
@@ -1000,7 +1003,7 @@ Tk_MeasureChars(
/*
*---------------------------------------------------------------------------
*
- * 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
@@ -1025,7 +1028,7 @@ Tk_MeasureChars(
int
TkpMeasureCharsInContext(
Tk_Font tkfont, /* Font in which characters will be drawn. */
- CONST char *source, /* UTF-8 string to be displayed. Need not be
+ 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. */
@@ -1077,7 +1080,7 @@ Tk_DrawChars(
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
+ 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
@@ -1104,18 +1107,18 @@ Tk_DrawChars(
SetROP2(dc, tkpWinRopModes[gc->function]);
if ((gc->clip_mask != None) &&
- ((TkpClipMask*)gc->clip_mask)->type == TKP_CLIP_REGION) {
- SelectClipRgn(dc, (HRGN)((TkpClipMask*)gc->clip_mask)->value.region);
+ ((TkpClipMask *) gc->clip_mask)->type == TKP_CLIP_REGION) {
+ SelectClipRgn(dc, (HRGN)((TkpClipMask *)gc->clip_mask)->value.region);
}
if ((gc->fill_style == FillStippled
|| gc->fill_style == FillOpaqueStippled)
&& gc->stipple != None) {
- TkWinDrawable *twdPtr = (TkWinDrawable *)gc->stipple;
+ TkWinDrawable *twdPtr = (TkWinDrawable *) gc->stipple;
HBRUSH oldBrush, stipple;
HBITMAP oldBitmap, bitmap;
HDC dcMem;
- TEXTMETRIC tm;
+ TEXTMETRICA tm;
SIZE size;
if (twdPtr->type != TWD_BITMAP) {
@@ -1141,8 +1144,8 @@ Tk_DrawChars(
* Compute the bounding box and create a compatible bitmap.
*/
- GetTextExtentPoint(dcMem, source, numBytes, &size);
- GetTextMetrics(dcMem, &tm);
+ GetTextExtentPointA(dcMem, source, numBytes, &size);
+ GetTextMetricsA(dcMem, &tm);
size.cx -= tm.tmOverhang;
bitmap = CreateCompatibleBitmap(dc, size.cx, size.cy);
oldBitmap = SelectObject(dcMem, bitmap);
@@ -1156,11 +1159,11 @@ Tk_DrawChars(
*/
PatBlt(dcMem, 0, 0, size.cx, size.cy, BLACKNESS);
- MultiFontTextOut(dc, fontPtr, source, numBytes, x, y);
+ MultiFontTextOut(dc, fontPtr, source, numBytes, x, y, 0.0);
BitBlt(dc, x, y - tm.tmAscent, size.cx, size.cy, dcMem,
0, 0, 0xEA02E9);
PatBlt(dcMem, 0, 0, size.cx, size.cy, WHITENESS);
- MultiFontTextOut(dc, fontPtr, source, numBytes, x, y);
+ MultiFontTextOut(dc, fontPtr, source, numBytes, x, y, 0.0);
BitBlt(dc, x, y - tm.tmAscent, size.cx, size.cy, dcMem,
0, 0, 0x8A0E06);
@@ -1177,11 +1180,11 @@ Tk_DrawChars(
SetTextAlign(dc, TA_LEFT | TA_BASELINE);
SetTextColor(dc, gc->foreground);
SetBkMode(dc, TRANSPARENT);
- MultiFontTextOut(dc, fontPtr, source, numBytes, x, y);
+ MultiFontTextOut(dc, fontPtr, source, numBytes, x, y, 0.0);
} else {
HBITMAP oldBitmap, bitmap;
HDC dcMem;
- TEXTMETRIC tm;
+ TEXTMETRICA tm;
SIZE size;
dcMem = CreateCompatibleDC(dc);
@@ -1195,13 +1198,14 @@ Tk_DrawChars(
* Compute the bounding box and create a compatible bitmap.
*/
- GetTextExtentPoint(dcMem, source, numBytes, &size);
- GetTextMetrics(dcMem, &tm);
+ GetTextExtentPointA(dcMem, source, numBytes, &size);
+ GetTextMetricsA(dcMem, &tm);
size.cx -= tm.tmOverhang;
bitmap = CreateCompatibleBitmap(dc, size.cx, size.cy);
oldBitmap = SelectObject(dcMem, bitmap);
- MultiFontTextOut(dcMem, fontPtr, source, numBytes, 0, tm.tmAscent);
+ MultiFontTextOut(dcMem, fontPtr, source, numBytes, 0, tm.tmAscent,
+ 0.0);
BitBlt(dc, x, y - tm.tmAscent, size.cx, size.cy, dcMem,
0, 0, (DWORD) tkpWinBltModes[gc->function]);
@@ -1216,6 +1220,154 @@ Tk_DrawChars(
TkWinReleaseDrawableDC(drawable, dc, &state);
}
+void
+TkDrawAngledChars(
+ 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. */
+ double x, double y, /* Coordinates at which to place origin of
+ * string when drawing. */
+ double angle)
+{
+ HDC dc;
+ WinFont *fontPtr;
+ TkWinDCState state;
+
+ fontPtr = (WinFont *) gc->font;
+ display->request++;
+
+ if (drawable == None) {
+ return;
+ }
+
+ dc = TkWinGetDrawableDC(display, drawable, &state);
+
+ SetROP2(dc, tkpWinRopModes[gc->function]);
+
+ if ((gc->clip_mask != None) &&
+ ((TkpClipMask *) gc->clip_mask)->type == TKP_CLIP_REGION) {
+ SelectClipRgn(dc, (HRGN)((TkpClipMask *)gc->clip_mask)->value.region);
+ }
+
+ if ((gc->fill_style == FillStippled
+ || gc->fill_style == FillOpaqueStippled)
+ && gc->stipple != None) {
+ TkWinDrawable *twdPtr = (TkWinDrawable *)gc->stipple;
+ HBRUSH oldBrush, stipple;
+ HBITMAP oldBitmap, bitmap;
+ HDC dcMem;
+ TEXTMETRICA tm;
+ SIZE size;
+
+ if (twdPtr->type != TWD_BITMAP) {
+ Tcl_Panic("unexpected drawable type in stipple");
+ }
+
+ /*
+ * Select stipple pattern into destination dc.
+ */
+
+ dcMem = CreateCompatibleDC(dc);
+
+ stipple = CreatePatternBrush(twdPtr->bitmap.handle);
+ SetBrushOrgEx(dc, gc->ts_x_origin, gc->ts_y_origin, NULL);
+ oldBrush = SelectObject(dc, stipple);
+
+ SetTextAlign(dcMem, TA_LEFT | TA_BASELINE);
+ SetTextColor(dcMem, gc->foreground);
+ SetBkMode(dcMem, TRANSPARENT);
+ SetBkColor(dcMem, RGB(0, 0, 0));
+
+ /*
+ * Compute the bounding box and create a compatible bitmap.
+ */
+
+ GetTextExtentPointA(dcMem, source, numBytes, &size);
+ GetTextMetricsA(dcMem, &tm);
+ size.cx -= tm.tmOverhang;
+ bitmap = CreateCompatibleBitmap(dc, size.cx, size.cy);
+ oldBitmap = SelectObject(dcMem, bitmap);
+
+ /*
+ * The following code is tricky because fonts are rendered in multiple
+ * colors. First we draw onto a black background and copy the white
+ * bits. Then we draw onto a white background and copy the black bits.
+ * Both the foreground and background bits of the font are ANDed with
+ * the stipple pattern as they are copied.
+ */
+
+ PatBlt(dcMem, 0, 0, size.cx, size.cy, BLACKNESS);
+ MultiFontTextOut(dc, fontPtr, source, numBytes, (int)x, (int)y, angle);
+ BitBlt(dc, (int)x, (int)y - tm.tmAscent, size.cx, size.cy, dcMem,
+ 0, 0, 0xEA02E9);
+ PatBlt(dcMem, 0, 0, size.cx, size.cy, WHITENESS);
+ MultiFontTextOut(dc, fontPtr, source, numBytes, (int)x, (int)y, angle);
+ BitBlt(dc, (int)x, (int)y - tm.tmAscent, size.cx, size.cy, dcMem,
+ 0, 0, 0x8A0E06);
+
+ /*
+ * Destroy the temporary bitmap and restore the device context.
+ */
+
+ SelectObject(dcMem, oldBitmap);
+ DeleteObject(bitmap);
+ DeleteDC(dcMem);
+ SelectObject(dc, oldBrush);
+ DeleteObject(stipple);
+ } else if (gc->function == GXcopy) {
+ SetTextAlign(dc, TA_LEFT | TA_BASELINE);
+ SetTextColor(dc, gc->foreground);
+ SetBkMode(dc, TRANSPARENT);
+ MultiFontTextOut(dc, fontPtr, source, numBytes, (int)x, (int)y, angle);
+ } else {
+ HBITMAP oldBitmap, bitmap;
+ HDC dcMem;
+ TEXTMETRICA tm;
+ SIZE size;
+
+ dcMem = CreateCompatibleDC(dc);
+
+ SetTextAlign(dcMem, TA_LEFT | TA_BASELINE);
+ SetTextColor(dcMem, gc->foreground);
+ SetBkMode(dcMem, TRANSPARENT);
+ SetBkColor(dcMem, RGB(0, 0, 0));
+
+ /*
+ * Compute the bounding box and create a compatible bitmap.
+ */
+
+ GetTextExtentPointA(dcMem, source, numBytes, &size);
+ GetTextMetricsA(dcMem, &tm);
+ size.cx -= tm.tmOverhang;
+ bitmap = CreateCompatibleBitmap(dc, size.cx, size.cy);
+ oldBitmap = SelectObject(dcMem, bitmap);
+
+ MultiFontTextOut(dcMem, fontPtr, source, numBytes, 0, tm.tmAscent,
+ angle);
+ BitBlt(dc, (int)x, (int)y - tm.tmAscent, size.cx, size.cy, dcMem,
+ 0, 0, (DWORD) tkpWinBltModes[gc->function]);
+
+ /*
+ * Destroy the temporary bitmap and restore the device context.
+ */
+
+ SelectObject(dcMem, oldBitmap);
+ DeleteObject(bitmap);
+ DeleteDC(dcMem);
+ }
+ TkWinReleaseDrawableDC(drawable, dc, &state);
+}
+
/*
*---------------------------------------------------------------------------
*
@@ -1241,7 +1393,7 @@ TkpDrawCharsInContext(
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
+ 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
@@ -1256,8 +1408,8 @@ TkpDrawCharsInContext(
* drawing. */
{
(void) numBytes; /*unused*/
- Tk_DrawChars(display, drawable, gc, tkfont,
- source + rangeStart, rangeLength, x, y);
+ Tk_DrawChars(display, drawable, gc, tkfont, source + rangeStart,
+ rangeLength, x, y);
}
/*
@@ -1285,23 +1437,24 @@ MultiFontTextOut(
HDC hdc, /* HDC to draw into. */
WinFont *fontPtr, /* Contains set of fonts to use when drawing
* following string. */
- CONST char *source, /* Potentially multilingual UTF-8 string. */
+ const char *source, /* Potentially multilingual UTF-8 string. */
int numBytes, /* Length of string in bytes. */
- int x, int y) /* Coordinates at which to place origin of
+ int x, int y, /* Coordinates at which to place origin of
* string when drawing. */
+ double angle)
{
Tcl_UniChar ch;
SIZE size;
HFONT oldFont;
FontFamily *familyPtr;
Tcl_DString runString;
- CONST char *p, *end, *next;
+ const char *p, *end, *next;
SubFont *lastSubFontPtr, *thisSubFontPtr;
- TEXTMETRIC tm;
+ TEXTMETRICA tm;
lastSubFontPtr = &fontPtr->subFontArray[0];
- oldFont = SelectObject(hdc, lastSubFontPtr->hFont);
- GetTextMetrics(hdc, &tm);
+ oldFont = SelectFont(hdc, fontPtr, lastSubFontPtr, angle);
+ GetTextMetricsA(hdc, &tm);
end = source + numBytes;
for (p = source; p < end; ) {
@@ -1312,11 +1465,11 @@ MultiFontTextOut(
familyPtr = lastSubFontPtr->familyPtr;
Tcl_UtfToExternalDString(familyPtr->encoding, source,
(int) (p - source), &runString);
- (*familyPtr->textOutProc)(hdc, x-(tm.tmOverhang/2), y,
- Tcl_DStringValue(&runString),
+ familyPtr->textOutProc(hdc, x-(tm.tmOverhang/2), y,
+ (TCHAR *)Tcl_DStringValue(&runString),
Tcl_DStringLength(&runString)>>familyPtr->isWideFont);
- (*familyPtr->getTextExtentPoint32Proc)(hdc,
- Tcl_DStringValue(&runString),
+ familyPtr->getTextExtentPoint32Proc(hdc,
+ (TCHAR *)Tcl_DStringValue(&runString),
Tcl_DStringLength(&runString) >> familyPtr->isWideFont,
&size);
x += size.cx;
@@ -1324,8 +1477,8 @@ MultiFontTextOut(
}
lastSubFontPtr = thisSubFontPtr;
source = p;
- SelectObject(hdc, lastSubFontPtr->hFont);
- GetTextMetrics(hdc, &tm);
+ SelectFont(hdc, fontPtr, lastSubFontPtr, angle);
+ GetTextMetricsA(hdc, &tm);
}
p = next;
}
@@ -1333,13 +1486,38 @@ MultiFontTextOut(
familyPtr = lastSubFontPtr->familyPtr;
Tcl_UtfToExternalDString(familyPtr->encoding, source,
(int) (p - source), &runString);
- (*familyPtr->textOutProc)(hdc, x-(tm.tmOverhang/2), y,
- Tcl_DStringValue(&runString),
+ familyPtr->textOutProc(hdc, x-(tm.tmOverhang/2), y,
+ (TCHAR *)Tcl_DStringValue(&runString),
Tcl_DStringLength(&runString) >> familyPtr->isWideFont);
Tcl_DStringFree(&runString);
}
SelectObject(hdc, oldFont);
}
+
+static inline HFONT
+SelectFont(
+ HDC hdc,
+ WinFont *fontPtr,
+ SubFont *subFontPtr,
+ double angle)
+{
+ if (angle == 0.0) {
+ return SelectObject(hdc, subFontPtr->hFont0);
+ } else if (angle == subFontPtr->angle) {
+ return SelectObject(hdc, subFontPtr->hFontAngled);
+ } else {
+ if (subFontPtr->hFontAngled) {
+ DeleteObject(subFontPtr->hFontAngled);
+ }
+ subFontPtr->hFontAngled = GetScreenFont(&fontPtr->font.fa,
+ subFontPtr->familyPtr->faceName, fontPtr->pixelSize, angle);
+ if (subFontPtr->hFontAngled == NULL) {
+ return SelectObject(hdc, subFontPtr->hFont0);
+ }
+ subFontPtr->angle = angle;
+ return SelectObject(hdc, subFontPtr->hFontAngled);
+ }
+}
/*
*---------------------------------------------------------------------------
@@ -1378,20 +1556,20 @@ InitFont(
HDC hdc;
HWND hwnd;
HFONT oldFont;
- TEXTMETRIC tm;
+ TEXTMETRICA tm;
Window window;
TkFontMetrics *fmPtr;
Tcl_Encoding encoding;
Tcl_DString faceString;
TkFontAttributes *faPtr;
- char buf[LF_FACESIZE * sizeof(WCHAR)];
+ TCHAR buf[LF_FACESIZE];
window = Tk_WindowId(tkwin);
hwnd = (window == None) ? NULL : TkWinGetHWND(window);
hdc = GetDC(hwnd);
oldFont = SelectObject(hdc, hFont);
- GetTextMetrics(hdc, &tm);
+ GetTextMetricsA(hdc, &tm);
/*
* On any version NT, there may fonts with international names. Use the
@@ -1408,12 +1586,8 @@ InitFont(
* GetTextFace because it only exists under NT.
*/
- if (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT) {
- GetTextFaceW(hdc, LF_FACESIZE, (WCHAR *) buf);
- } else {
- GetTextFaceA(hdc, LF_FACESIZE, (char *) buf);
- }
- Tcl_ExternalToUtfDString(systemEncoding, buf, -1, &faceString);
+ GetTextFace(hdc, LF_FACESIZE, buf);
+ Tcl_ExternalToUtfDString(systemEncoding, (char *) buf, -1, &faceString);
fontPtr->font.fid = (Font) fontPtr;
fontPtr->hwnd = hwnd;
@@ -1423,7 +1597,7 @@ InitFont(
faPtr->family = Tk_GetUid(Tcl_DStringValue(&faceString));
faPtr->size =
- TkFontGetPoints(tkwin, -(fontPtr->pixelSize));
+ TkFontGetPoints(tkwin, -(fontPtr->pixelSize));
faPtr->weight =
(tm.tmWeight > FW_MEDIUM) ? TK_FW_BOLD : TK_FW_NORMAL;
faPtr->slant = (tm.tmItalic != 0) ? TK_FS_ITALIC : TK_FS_ROMAN;
@@ -1442,7 +1616,7 @@ InitFont(
encoding = fontPtr->subFontArray[0].familyPtr->encoding;
if (encoding == TkWinGetUnicodeEncoding()) {
- GetCharWidthW(hdc, 0, BASE_CHARS - 1, fontPtr->widths);
+ GetCharWidth(hdc, 0, BASE_CHARS - 1, fontPtr->widths);
} else {
GetCharWidthA(hdc, 0, BASE_CHARS - 1, fontPtr->widths);
}
@@ -1479,7 +1653,7 @@ ReleaseFont(
ReleaseSubFont(&fontPtr->subFontArray[i]);
}
if (fontPtr->subFontArray != fontPtr->staticSubFonts) {
- ckfree((char *) fontPtr->subFontArray);
+ ckfree(fontPtr->subFontArray);
}
}
@@ -1501,7 +1675,7 @@ ReleaseFont(
*-------------------------------------------------------------------------
*/
-static void
+static inline void
InitSubFont(
HDC hdc, /* HDC in which font can be selected. */
HFONT hFont, /* The screen font. */
@@ -1510,9 +1684,11 @@ InitSubFont(
SubFont *subFontPtr) /* Filled with SubFont constructed from above
* attributes. */
{
- subFontPtr->hFont = hFont;
+ subFontPtr->hFont0 = hFont;
subFontPtr->familyPtr = AllocFontFamily(hdc, hFont, base);
subFontPtr->fontMap = subFontPtr->familyPtr->fontMap;
+ subFontPtr->hFontAngled = NULL;
+ subFontPtr->angle = 0.0;
}
/*
@@ -1532,11 +1708,14 @@ InitSubFont(
*---------------------------------------------------------------------------
*/
-static void
+static inline void
ReleaseSubFont(
SubFont *subFontPtr) /* The SubFont to delete. */
{
- DeleteObject(subFontPtr->hFont);
+ DeleteObject(subFontPtr->hFont0);
+ if (subFontPtr->hFontAngled) {
+ DeleteObject(subFontPtr->hFontAngled);
+ }
FreeFontFamily(subFontPtr->familyPtr);
}
@@ -1579,17 +1758,13 @@ AllocFontFamily(
FontFamily *familyPtr;
Tcl_DString faceString;
Tcl_Encoding encoding;
- char buf[LF_FACESIZE * sizeof(WCHAR)];
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
+ TCHAR buf[LF_FACESIZE];
+ ThreadSpecificData *tsdPtr =
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
hFont = SelectObject(hdc, hFont);
- if (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT) {
- GetTextFaceW(hdc, LF_FACESIZE, (WCHAR *) buf);
- } else {
- GetTextFaceA(hdc, LF_FACESIZE, (char *) buf);
- }
- Tcl_ExternalToUtfDString(systemEncoding, buf, -1, &faceString);
+ GetTextFace(hdc, LF_FACESIZE, buf);
+ Tcl_ExternalToUtfDString(systemEncoding, (char *) buf, -1, &faceString);
faceName = Tk_GetUid(Tcl_DStringValue(&faceString));
Tcl_DStringFree(&faceString);
hFont = SelectObject(hdc, hFont);
@@ -1602,7 +1777,7 @@ AllocFontFamily(
}
}
- familyPtr = (FontFamily *) ckalloc(sizeof(FontFamily));
+ familyPtr = ckalloc(sizeof(FontFamily));
memset(familyPtr, 0, sizeof(FontFamily));
familyPtr->nextPtr = tsdPtr->fontFamilyList;
tsdPtr->fontFamilyList = familyPtr;
@@ -1688,7 +1863,7 @@ FreeFontFamily(
{
int i;
FontFamily **familyPtrPtr;
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
+ ThreadSpecificData *tsdPtr =
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
if (familyPtr == NULL) {
@@ -1704,10 +1879,10 @@ FreeFontFamily(
}
}
if (familyPtr->startCount != NULL) {
- ckfree((char *) familyPtr->startCount);
+ ckfree(familyPtr->startCount);
}
if (familyPtr->endCount != NULL) {
- ckfree((char *) familyPtr->endCount);
+ ckfree(familyPtr->endCount);
}
if (familyPtr->encoding != TkWinGetUnicodeEncoding()) {
Tcl_FreeEncoding(familyPtr->encoding);
@@ -1719,13 +1894,13 @@ FreeFontFamily(
for (familyPtrPtr = &tsdPtr->fontFamilyList; ; ) {
if (*familyPtrPtr == familyPtr) {
- *familyPtrPtr = familyPtr->nextPtr;
+ *familyPtrPtr = familyPtr->nextPtr;
break;
}
familyPtrPtr = &(*familyPtrPtr)->nextPtr;
}
- ckfree((char *) familyPtr);
+ ckfree(familyPtr);
}
/*
@@ -1759,9 +1934,10 @@ FindSubFontForChar(
HDC hdc;
int i, j, k;
CanUse canUse;
- char **aliases, **anyFallbacks;
- char ***fontFallbacks;
- char *fallbackName;
+ const char *const *aliases;
+ const char *const *anyFallbacks;
+ const char *const *const *fontFallbacks;
+ const char *fallbackName;
SubFont *subFontPtr;
Tcl_DString ds;
@@ -1850,13 +2026,8 @@ FindSubFontForChar(
canUse.ch = ch;
canUse.subFontPtr = NULL;
canUse.subFontPtrPtr = subFontPtrPtr;
- if (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT) {
- EnumFontFamiliesW(hdc, NULL, (FONTENUMPROCW) WinFontCanUseProc,
- (LPARAM) &canUse);
- } else {
- EnumFontFamiliesA(hdc, NULL, (FONTENUMPROCA) WinFontCanUseProc,
- (LPARAM) &canUse);
- }
+ EnumFontFamilies(hdc, NULL, (FONTENUMPROC) WinFontCanUseProc,
+ (LPARAM) &canUse);
subFontPtr = canUse.subFontPtr;
end:
@@ -1864,7 +2035,7 @@ FindSubFontForChar(
if (subFontPtr == NULL) {
/*
- * No font can display this character. We will use the base font and
+ * No font can display this character. We will use the base font and
* have it display the "unknown" character.
*/
@@ -1897,7 +2068,7 @@ WinFontCanUseProc(
fontPtr = canUsePtr->fontPtr;
nameTriedPtr = canUsePtr->nameTriedPtr;
- fallbackName = lfPtr->elfLogFont.lfFaceName;
+ fallbackName = (char *) lfPtr->elfLogFont.lfFaceName;
Tcl_ExternalToUtfDString(systemEncoding, fallbackName, -1, &faceString);
fallbackName = Tcl_DStringValue(&faceString);
@@ -2022,7 +2193,7 @@ FontMapLoadPage(
USHORT *startCount, *endCount;
int i, j, bitOffset, end, segCount;
- subFontPtr->fontMap[row] = (char *) ckalloc(FONTMAP_BITSPERPAGE / 8);
+ subFontPtr->fontMap[row] = ckalloc(FONTMAP_BITSPERPAGE / 8);
memset(subFontPtr->fontMap[row], 0, FONTMAP_BITSPERPAGE / 8);
familyPtr = subFontPtr->familyPtr;
@@ -2046,7 +2217,8 @@ FontMapLoadPage(
if (endCount[j] >= i) {
if (startCount[j] <= i) {
bitOffset = i & (FONTMAP_BITSPERPAGE - 1);
- subFontPtr->fontMap[row][bitOffset >> 3] |= 1 << (bitOffset & 7);
+ subFontPtr->fontMap[row][bitOffset >> 3] |=
+ 1 << (bitOffset & 7);
}
break;
}
@@ -2104,7 +2276,7 @@ CanUseFallbackWithAliases(
HDC hdc, /* HDC in which font can be selected. */
WinFont *fontPtr, /* The font object that will own the new
* screen font. */
- char *faceName, /* Desired face name for new screen font. */
+ const char *faceName, /* Desired face name for new screen font. */
int ch, /* The Unicode character that the new screen
* font must be able to display. */
Tcl_DString *nameTriedPtr, /* Records face names that have already been
@@ -2115,7 +2287,7 @@ CanUseFallbackWithAliases(
* array of subfonts. */
{
int i;
- char **aliases;
+ const char *const *aliases;
SubFont *subFontPtr;
if (SeenName(faceName, nameTriedPtr) == 0) {
@@ -2160,11 +2332,11 @@ CanUseFallbackWithAliases(
static int
SeenName(
- CONST char *name, /* The name to check. */
+ const char *name, /* The name to check. */
Tcl_DString *dsPtr) /* Contains names that have already been
* seen. */
{
- CONST char *seen, *end;
+ const char *seen, *end;
seen = Tcl_DStringValue(dsPtr);
end = seen + Tcl_DStringLength(dsPtr);
@@ -2174,7 +2346,7 @@ SeenName(
}
seen += strlen(seen) + 1;
}
- Tcl_DStringAppend(dsPtr, (char *) name, (int) (strlen(name) + 1));
+ Tcl_DStringAppend(dsPtr, name, (int) (strlen(name) + 1));
return 0;
}
@@ -2207,7 +2379,7 @@ CanUseFallback(
HDC hdc, /* HDC in which font can be selected. */
WinFont *fontPtr, /* The font object that will own the new
* screen font. */
- char *faceName, /* Desired face name for new screen font. */
+ const char *faceName, /* Desired face name for new screen font. */
int ch, /* The Unicode character that the new screen
* font must be able to display. */
SubFont **subFontPtrPtr) /* Variable to fix-up if we realloc the array
@@ -2235,7 +2407,8 @@ CanUseFallback(
* Load this font and see if it has the desired character.
*/
- hFont = GetScreenFont(&fontPtr->font.fa, faceName, fontPtr->pixelSize);
+ hFont = GetScreenFont(&fontPtr->font.fa, faceName, fontPtr->pixelSize,
+ 0.0);
InitSubFont(hdc, hFont, 0, &subFont);
if (((ch < 256) && (subFont.familyPtr->isSymbolFont))
|| (FontMapLookup(&subFont, ch) == 0)) {
@@ -2251,12 +2424,11 @@ CanUseFallback(
if (fontPtr->numSubFonts >= SUBFONT_SPACE) {
SubFont *newPtr;
- newPtr = (SubFont *) ckalloc(sizeof(SubFont)
- * (fontPtr->numSubFonts + 1));
- memcpy((char *) newPtr, fontPtr->subFontArray,
+ newPtr = ckalloc(sizeof(SubFont) * (fontPtr->numSubFonts + 1));
+ memcpy(newPtr, fontPtr->subFontArray,
fontPtr->numSubFonts * sizeof(SubFont));
if (fontPtr->subFontArray != fontPtr->staticSubFonts) {
- ckfree((char *) fontPtr->subFontArray);
+ ckfree(fontPtr->subFontArray);
}
/*
@@ -2291,22 +2463,24 @@ CanUseFallback(
static HFONT
GetScreenFont(
- CONST TkFontAttributes *faPtr,
+ const TkFontAttributes *faPtr,
/* Desired font attributes for new HFONT. */
- CONST char *faceName, /* Overrides font family specified in font
+ const char *faceName, /* Overrides font family specified in font
* attributes. */
- int pixelSize) /* Overrides size specified in font
+ int pixelSize, /* Overrides size specified in font
* attributes. */
+ double angle) /* What is the desired orientation of the
+ * font. */
{
Tcl_DString ds;
HFONT hFont;
- LOGFONTW lf;
+ LOGFONT lf;
memset(&lf, 0, sizeof(lf));
lf.lfHeight = -pixelSize;
lf.lfWidth = 0;
- lf.lfEscapement = 0;
- lf.lfOrientation = 0;
+ lf.lfEscapement = ROUND16(angle * 10);
+ lf.lfOrientation = ROUND16(angle * 10);
lf.lfWeight = (faPtr->weight == TK_FW_NORMAL) ? FW_NORMAL : FW_BOLD;
lf.lfItalic = faPtr->slant;
lf.lfUnderline = faPtr->underline;
@@ -2318,36 +2492,10 @@ GetScreenFont(
lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
Tcl_UtfToExternalDString(systemEncoding, faceName, -1, &ds);
-
- if (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT) {
- Tcl_UniChar *src, *dst;
-
- /*
- * We can only store up to LF_FACESIZE wide characters
- */
-
- if ((size_t)Tcl_DStringLength(&ds) >= (LF_FACESIZE * sizeof(WCHAR))) {
- Tcl_DStringSetLength(&ds, LF_FACESIZE);
- }
- src = (Tcl_UniChar *) Tcl_DStringValue(&ds);
- dst = (Tcl_UniChar *) lf.lfFaceName;
- while (*src != '\0') {
- *dst++ = *src++;
- }
- *dst = '\0';
- hFont = CreateFontIndirectW(&lf);
- } else {
- /*
- * We can only store up to LF_FACESIZE characters
- */
-
- if (Tcl_DStringLength(&ds) >= LF_FACESIZE) {
- Tcl_DStringSetLength(&ds, LF_FACESIZE);
- }
- strcpy((char *) lf.lfFaceName, Tcl_DStringValue(&ds));
- hFont = CreateFontIndirectA((LOGFONTA *) &lf);
- }
+ _tcsncpy(lf.lfFaceName, (TCHAR *)Tcl_DStringValue(&ds), LF_FACESIZE-1);
Tcl_DStringFree(&ds);
+ lf.lfFaceName[LF_FACESIZE-1] = 0;
+ hFont = CreateFontIndirect(&lf);
return hFont;
}
@@ -2373,7 +2521,7 @@ GetScreenFont(
static int
FamilyExists(
HDC hdc, /* HDC in which font family will be used. */
- CONST char *faceName) /* Font family to query. */
+ const char *faceName) /* Font family to query. */
{
int result;
Tcl_DString faceString;
@@ -2403,27 +2551,22 @@ FamilyExists(
* non-zero value.
*/
- if (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT) {
- result = EnumFontFamiliesW(hdc, (WCHAR*) Tcl_DStringValue(&faceString),
- (FONTENUMPROCW) WinFontExistProc, 0);
- } else {
- result = EnumFontFamiliesA(hdc, (char *) Tcl_DStringValue(&faceString),
- (FONTENUMPROCA) WinFontExistProc, 0);
- }
+ result = EnumFontFamilies(hdc, (TCHAR*) Tcl_DStringValue(&faceString),
+ (FONTENUMPROC) WinFontExistProc, 0);
Tcl_DStringFree(&faceString);
return (result == 0);
}
-static char *
+static const char *
FamilyOrAliasExists(
HDC hdc,
- CONST char *faceName)
+ const char *faceName)
{
- char **aliases;
+ const char *const *aliases;
int i;
if (FamilyExists(hdc, faceName) != 0) {
- return (char *) faceName;
+ return faceName;
}
aliases = TkFontGetAliasList(faceName);
if (aliases != NULL) {
@@ -2453,7 +2596,7 @@ WinFontExistProc(
#pragma pack(1) /* Structures are byte aligned in file. */
-#define CMAPHEX 0x636d6170 /* Key for character map resource. */
+#define CMAPHEX 0x636d6170 /* Key for character map resource. */
typedef struct CMAPTABLE {
USHORT version; /* Table version number (0). */
@@ -2495,7 +2638,7 @@ typedef struct SUBHEADER {
} SUBHEADER;
typedef struct HIBYTETABLE {
- USHORT format; /* Format number is set to 2. */
+ USHORT format; /* Format number is set to 2. */
USHORT length; /* The actual length in bytes of this
* subtable. */
USHORT version; /* Version number (starts at 0). */
@@ -2613,7 +2756,7 @@ LoadFontRanges(
}
n = GetFontData(hdc, cmapKey, 0, &cmapTable, sizeof(cmapTable));
- if (n != (int)GDI_ERROR) {
+ if (n != (int) GDI_ERROR) {
if (swapped) {
SwapShort(&cmapTable.numTables);
}
@@ -2651,8 +2794,8 @@ LoadFontRanges(
segCount = subTable.segment.segCountX2 / 2;
cbData = segCount * sizeof(USHORT);
- startCount = (USHORT *) ckalloc((unsigned)cbData);
- endCount = (USHORT *) ckalloc((unsigned)cbData);
+ startCount = ckalloc(cbData);
+ endCount = ckalloc(cbData);
offset = encTable.offset + sizeof(subTable.segment);
GetFontData(hdc, cmapKey, (DWORD) offset, endCount, cbData);
@@ -2695,8 +2838,8 @@ LoadFontRanges(
segCount = 1;
cbData = segCount * sizeof(USHORT);
- startCount = (USHORT *) ckalloc((unsigned) cbData);
- endCount = (USHORT *) ckalloc((unsigned) cbData);
+ startCount = ckalloc(cbData);
+ endCount = ckalloc(cbData);
startCount[0] = 0x0000;
endCount[0] = 0x00ff;
}
@@ -2724,14 +2867,14 @@ LoadFontRanges(
*-------------------------------------------------------------------------
*/
-static void
+static inline void
SwapShort(
PUSHORT p)
{
*p = (SHORT)(HIBYTE(*p) + (LOBYTE(*p) << 8));
}
-static void
+static inline void
SwapLong(
PULONG p)
{