summaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2011-10-13 12:36:52 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2011-10-13 12:36:52 (GMT)
commit70a8983986e67b157b1ba85d4984926147ef82e4 (patch)
treec8dfadccbd160c0a86debe052126c1ba055eb774 /win
parent0d77c740c517d0938a08711269b93a51b90e423e (diff)
downloadtk-70a8983986e67b157b1ba85d4984926147ef82e4.zip
tk-70a8983986e67b157b1ba85d4984926147ef82e4.tar.gz
tk-70a8983986e67b157b1ba85d4984926147ef82e4.tar.bz2
Internationalization of all Windows font handling
Diffstat (limited to 'win')
-rw-r--r--win/tkWinDialog.c30
-rw-r--r--win/tkWinFont.c78
2 files changed, 44 insertions, 64 deletions
diff --git a/win/tkWinDialog.c b/win/tkWinDialog.c
index 9d1b576..4dc8d9e 100644
--- a/win/tkWinDialog.c
+++ b/win/tkWinDialog.c
@@ -1981,14 +1981,17 @@ ConvertExternalFilename(
*/
static Tcl_Obj *
-GetFontObj(HDC hdc, LOGFONTA *plf)
+GetFontObj(HDC hdc, LOGFONT *plf)
{
+ Tcl_DString ds;
Tcl_Obj *resObj;
int pt = 0;
resObj = Tcl_NewListObj(0, NULL);
+ Tcl_ExternalToUtfDString(TkWinGetUnicodeEncoding(), (char *) plf->lfFaceName, -1, &ds);
Tcl_ListObjAppendElement(NULL, resObj,
- Tcl_NewStringObj(plf->lfFaceName, -1));
+ Tcl_NewStringObj(Tcl_DStringValue(&ds), -1));
+ Tcl_DStringFree(&ds);
pt = -MulDiv(plf->lfHeight, 72, GetDeviceCaps(hdc, LOGPIXELSY));
Tcl_ListObjAppendElement(NULL, resObj, Tcl_NewIntObj(pt));
if (plf->lfWeight >= 700) {
@@ -2010,7 +2013,7 @@ GetFontObj(HDC hdc, LOGFONTA *plf)
}
static void
-ApplyLogfont(Tcl_Interp *interp, Tcl_Obj *cmdObj, HDC hdc, LOGFONTA *logfontPtr)
+ApplyLogfont(Tcl_Interp *interp, Tcl_Obj *cmdObj, HDC hdc, LOGFONT *logfontPtr)
{
int objc;
Tcl_Obj **objv, **tmpv;
@@ -2098,10 +2101,10 @@ HookProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
*/
if (WM_COMMAND == msg && LOWORD(wParam) == 1026) {
- LOGFONTA lf = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0}};
+ LOGFONT lf = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0}};
HDC hdc = GetDC(hwndDlg);
- SendMessageA(hwndDlg, WM_CHOOSEFONT_GETLOGFONT, 0, (LPARAM) &lf);
+ SendMessage(hwndDlg, WM_CHOOSEFONT_GETLOGFONT, 0, (LPARAM) &lf);
if (phd && phd->cmdObj) {
ApplyLogfont(phd->interp, phd->cmdObj, hdc, &lf);
}
@@ -2331,9 +2334,10 @@ FontchooserShowCmd(
int objc,
Tcl_Obj *const objv[])
{
+ Tcl_DString ds;
Tk_Window tkwin = clientData, parent;
- CHOOSEFONTA cf;
- LOGFONTA lf;
+ CHOOSEFONT cf;
+ LOGFONT lf;
HDC hdc;
HookData *hdPtr;
int r = TCL_OK, oldMode = 0;
@@ -2351,10 +2355,10 @@ FontchooserShowCmd(
Tk_MakeWindowExist(parent);
- ZeroMemory(&cf, sizeof(CHOOSEFONTA));
- ZeroMemory(&lf, sizeof(LOGFONTA));
+ ZeroMemory(&cf, sizeof(CHOOSEFONT));
+ ZeroMemory(&lf, sizeof(LOGFONT));
lf.lfCharSet = DEFAULT_CHARSET;
- cf.lStructSize = sizeof(CHOOSEFONTA);
+ cf.lStructSize = sizeof(CHOOSEFONT);
cf.hwndOwner = Tk_GetHWND(Tk_WindowId(parent));
cf.lpLogFont = &lf;
cf.nFontType = SCREEN_FONTTYPE;
@@ -2375,7 +2379,9 @@ FontchooserShowCmd(
}
fontPtr = (TkFont *) f;
cf.Flags |= CF_INITTOLOGFONTSTRUCT;
- strncpy(lf.lfFaceName, Tk_GetUid(fontPtr->fa.family), LF_FACESIZE-1);
+ Tcl_UtfToExternalDString(TkWinGetUnicodeEncoding(), fontPtr->fa.family, -1, &ds);
+ _tcsncpy(lf.lfFaceName, (TCHAR *)Tcl_DStringValue(&ds), LF_FACESIZE-1);
+ Tcl_DStringFree(&ds);
lf.lfFaceName[LF_FACESIZE-1] = 0;
lf.lfHeight = -MulDiv(TkFontGetPoints(tkwin, fontPtr->fa.size),
GetDeviceCaps(hdc, LOGPIXELSY), 72);
@@ -2405,7 +2411,7 @@ FontchooserShowCmd(
if (TCL_OK == r) {
oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
- if (ChooseFontA(&cf)) {
+ if (ChooseFont(&cf)) {
if (hdPtr->cmdObj) {
ApplyLogfont(hdPtr->interp, hdPtr->cmdObj, hdc, &lf);
}
diff --git a/win/tkWinFont.c b/win/tkWinFont.c
index 17de016..86f63ac 100644
--- a/win/tkWinFont.c
+++ b/win/tkWinFont.c
@@ -213,7 +213,7 @@ static inline void InitSubFont(HDC hdc, HFONT hFont, int base,
SubFont *subFontPtr);
static int CreateNamedSystemLogFont(Tcl_Interp *interp,
Tk_Window tkwin, const char* name,
- LOGFONTA* logFontPtr);
+ LOGFONT* logFontPtr);
static int CreateNamedSystemFont(Tcl_Interp *interp,
Tk_Window tkwin, const char* name, HFONT hFont);
static int LoadFontRanges(HDC hdc, HFONT hFont,
@@ -229,14 +229,14 @@ 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(ENUMLOGFONTA *lfPtr,
- NEWTEXTMETRICA *tmPtr, int fontType,
+static int CALLBACK WinFontCanUseProc(ENUMLOGFONT *lfPtr,
+ NEWTEXTMETRIC *tmPtr, int fontType,
LPARAM lParam);
-static int CALLBACK WinFontExistProc(ENUMLOGFONTA *lfPtr,
- NEWTEXTMETRICA *tmPtr, int fontType,
+static int CALLBACK WinFontExistProc(ENUMLOGFONT *lfPtr,
+ NEWTEXTMETRIC *tmPtr, int fontType,
LPARAM lParam);
-static int CALLBACK WinFontFamilyEnumProc(ENUMLOGFONTA *lfPtr,
- NEWTEXTMETRICA *tmPtr, int fontType,
+static int CALLBACK WinFontFamilyEnumProc(ENUMLOGFONT *lfPtr,
+ NEWTEXTMETRIC *tmPtr, int fontType,
LPARAM lParam);
/*
@@ -340,12 +340,12 @@ CreateNamedSystemLogFont(
Tcl_Interp *interp,
Tk_Window tkwin,
const char* name,
- LOGFONTA* logFontPtr)
+ LOGFONT* logFontPtr)
{
HFONT hFont;
int r;
- hFont = CreateFontIndirectA(logFontPtr);
+ hFont = CreateFontIndirect(logFontPtr);
r = CreateNamedSystemFont(interp, tkwin, name, hFont);
DeleteObject((HGDIOBJ)hFont);
return r;
@@ -401,8 +401,8 @@ TkWinSetupSystemFonts(
Tcl_Interp *interp;
Tk_Window tkwin;
const TkStateMap *mapPtr;
- NONCLIENTMETRICSA ncMetrics;
- ICONMETRICSA iconMetrics;
+ NONCLIENTMETRICS ncMetrics;
+ ICONMETRICS iconMetrics;
HFONT hFont;
interp = (Tcl_Interp *) mainPtr->interp;
@@ -422,7 +422,7 @@ TkWinSetupSystemFonts(
ZeroMemory(&ncMetrics, sizeof(ncMetrics));
ncMetrics.cbSize = sizeof(ncMetrics);
- if (SystemParametersInfoA(SPI_GETNONCLIENTMETRICS,
+ if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(ncMetrics), &ncMetrics, 0)) {
CreateNamedSystemLogFont(interp, tkwin, "TkDefaultFont",
&ncMetrics.lfMessageFont);
@@ -441,7 +441,7 @@ TkWinSetupSystemFonts(
}
iconMetrics.cbSize = sizeof(iconMetrics);
- if (SystemParametersInfoA(SPI_GETICONMETRICS, sizeof(iconMetrics),
+ if (SystemParametersInfo(SPI_GETICONMETRICS, sizeof(iconMetrics),
&iconMetrics, 0)) {
CreateNamedSystemLogFont(interp, tkwin, "TkIconFont",
&iconMetrics.lfFont);
@@ -453,9 +453,9 @@ TkWinSetupSystemFonts(
*/
{
- 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);
@@ -668,12 +668,12 @@ TkpGetFontFamilies(
static int CALLBACK
WinFontFamilyEnumProc(
- ENUMLOGFONTA *lfPtr, /* Logical-font data. */
- NEWTEXTMETRICA *tmPtr, /* Physical-font data (not used). */
+ ENUMLOGFONT *lfPtr, /* Logical-font data. */
+ NEWTEXTMETRIC *tmPtr, /* Physical-font data (not used). */
int fontType, /* Type of font (not used). */
LPARAM lParam) /* Result object to hold result. */
{
- char *faceName = lfPtr->elfLogFont.lfFaceName;
+ char *faceName = (char *) lfPtr->elfLogFont.lfFaceName;
Tcl_Obj *resultObj = (Tcl_Obj *) lParam;
Tcl_DString faceString;
@@ -2048,8 +2048,8 @@ FindSubFontForChar(
static int CALLBACK
WinFontCanUseProc(
- ENUMLOGFONTA *lfPtr, /* Logical-font data. */
- NEWTEXTMETRICA *tmPtr, /* Physical-font data (not used). */
+ ENUMLOGFONT *lfPtr, /* Logical-font data. */
+ NEWTEXTMETRIC *tmPtr, /* Physical-font data (not used). */
int fontType, /* Type of font (not used). */
LPARAM lParam) /* Result object to hold result. */
{
@@ -2068,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);
@@ -2492,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 (Tcl_DStringLength(&ds) >= (int)(LF_FACESIZE * sizeof(TCHAR))) {
- Tcl_DStringSetLength(&ds, LF_FACESIZE);
- }
- src = (Tcl_UniChar *) Tcl_DStringValue(&ds);
- dst = (Tcl_UniChar *) lf.lfFaceName;
- while (*src != '\0') {
- *dst++ = *src++;
- }
- *dst = '\0';
- hFont = CreateFontIndirect(&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;
}
@@ -2607,8 +2581,8 @@ FamilyOrAliasExists(
static int CALLBACK
WinFontExistProc(
- ENUMLOGFONTA *lfPtr, /* Logical-font data. */
- NEWTEXTMETRICA *tmPtr, /* Physical-font data (not used). */
+ ENUMLOGFONT *lfPtr, /* Logical-font data. */
+ NEWTEXTMETRIC *tmPtr, /* Physical-font data (not used). */
int fontType, /* Type of font (not used). */
LPARAM lParam) /* EnumFontData to hold result. */
{