diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-03-24 07:56:41 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-03-24 07:56:41 (GMT) |
commit | bc56730d2abae5198c3667a55729e01684f3cb29 (patch) | |
tree | a67f18bf70f2081877ab48b4aecd142c54848262 /win/tkWinFont.c | |
parent | abbe37191732849b4d22072a8572f29205025457 (diff) | |
download | tk-bc56730d2abae5198c3667a55729e01684f3cb29.zip tk-bc56730d2abae5198c3667a55729e01684f3cb29.tar.gz tk-bc56730d2abae5198c3667a55729e01684f3cb29.tar.bz2 |
Replace all instances of Tcl_WinTCharToUtf()/Tcl_WinUtfToTChar() with Tcl_UniCharToUtfDString()/Tcl_UtfToUniCharDString(), if possible (only for -DTCL_UTF_MAX=3, which is the default and only supported option)
Backported, as far as possible, from 8.7. This helps moving away from Tcl_WinTCharToUtf()/Tcl_WinUtfToTChar(), even though it only becomes deprecated in 8.7.
Diffstat (limited to 'win/tkWinFont.c')
-rw-r--r-- | win/tkWinFont.c | 83 |
1 files changed, 44 insertions, 39 deletions
diff --git a/win/tkWinFont.c b/win/tkWinFont.c index aae34a7..c430d48 100644 --- a/win/tkWinFont.c +++ b/win/tkWinFont.c @@ -300,8 +300,8 @@ TkpGetNativeFont( } tkwin = (Tk_Window) ((TkWindow *) tkwin)->mainPtr->winPtr; - fontPtr = ckalloc(sizeof(WinFont)); - InitFont(tkwin, GetStockObject(object), 0, fontPtr); + fontPtr = (WinFont *)ckalloc(sizeof(WinFont)); + InitFont(tkwin, (HFONT)GetStockObject(object), 0, fontPtr); return (TkFont *) fontPtr; } @@ -558,7 +558,7 @@ TkpGetFontFromAttributes( hFont = GetScreenFont(faPtr, faceName, (int)(TkFontGetPixels(tkwin, faPtr->size) + 0.5), 0.0); if (tkFontPtr == NULL) { - fontPtr = ckalloc(sizeof(WinFont)); + fontPtr = (WinFont *)ckalloc(sizeof(WinFont)); } else { fontPtr = (WinFont *) tkFontPtr; ReleaseFont(fontPtr); @@ -658,10 +658,12 @@ WinFontFamilyEnumProc( int fontType, /* Type of font (not used). */ LPARAM lParam) /* Result object to hold result. */ { + WCHAR *faceName = lfPtr->elfLogFont.lfFaceName; Tcl_Obj *resultObj = (Tcl_Obj *) lParam; Tcl_DString faceString; - Tcl_WinTCharToUtf((LPCTSTR)lfPtr->elfLogFont.lfFaceName, -1, &faceString); + Tcl_DStringInit(&faceString); + Tcl_WCharToUtfDString(faceName, wcslen(faceName), &faceString); Tcl_ListObjAppendElement(NULL, resultObj, Tcl_NewStringObj( Tcl_DStringValue(&faceString), Tcl_DStringLength(&faceString))); Tcl_DStringFree(&faceString); @@ -750,7 +752,7 @@ TkpGetFontAttrsForChar( * Get the font attributes. */ - oldfont = SelectObject(hdc, thisSubFontPtr->hFont0); + oldfont = (HFONT)SelectObject(hdc, thisSubFontPtr->hFont0); GetTextMetricsW(hdc, &tm); SelectObject(hdc, oldfont); ReleaseDC(fontPtr->hwnd, hdc); @@ -828,7 +830,7 @@ Tk_MeasureChars( hdc = GetDC(fontPtr->hwnd); lastSubFontPtr = &fontPtr->subFontArray[0]; - oldFont = SelectObject(hdc, lastSubFontPtr->hFont0); + oldFont = (HFONT)SelectObject(hdc, lastSubFontPtr->hFont0); /* * A three step process: @@ -1037,6 +1039,7 @@ TkpMeasureCharsInContext( * terminating character. */ { (void) numBytes; /*unused*/ + return Tk_MeasureChars(tkfont, source + rangeStart, rangeLength, maxLength, flags, lengthPtr); } @@ -1117,7 +1120,7 @@ Tk_DrawChars( stipple = CreatePatternBrush(twdPtr->bitmap.handle); SetBrushOrgEx(dc, gc->ts_x_origin, gc->ts_y_origin, NULL); - oldBrush = SelectObject(dc, stipple); + oldBrush = (HBRUSH)SelectObject(dc, stipple); SetTextAlign(dcMem, TA_LEFT | TA_BASELINE); SetTextColor(dcMem, gc->foreground); @@ -1132,7 +1135,7 @@ Tk_DrawChars( GetTextMetricsW(dcMem, &tm); size.cx -= tm.tmOverhang; bitmap = CreateCompatibleBitmap(dc, size.cx, size.cy); - oldBitmap = SelectObject(dcMem, bitmap); + oldBitmap = (HBITMAP)SelectObject(dcMem, bitmap); /* * The following code is tricky because fonts are rendered in multiple @@ -1186,7 +1189,7 @@ Tk_DrawChars( GetTextMetricsW(dcMem, &tm); size.cx -= tm.tmOverhang; bitmap = CreateCompatibleBitmap(dc, size.cx, size.cy); - oldBitmap = SelectObject(dcMem, bitmap); + oldBitmap = (HBITMAP)SelectObject(dcMem, bitmap); MultiFontTextOut(dcMem, fontPtr, source, numBytes, 0, tm.tmAscent, 0.0); @@ -1265,7 +1268,7 @@ TkDrawAngledChars( stipple = CreatePatternBrush(twdPtr->bitmap.handle); SetBrushOrgEx(dc, gc->ts_x_origin, gc->ts_y_origin, NULL); - oldBrush = SelectObject(dc, stipple); + oldBrush = (HBRUSH)SelectObject(dc, stipple); SetTextAlign(dcMem, TA_LEFT | TA_BASELINE); SetTextColor(dcMem, gc->foreground); @@ -1280,7 +1283,7 @@ TkDrawAngledChars( GetTextMetricsW(dcMem, &tm); size.cx -= tm.tmOverhang; bitmap = CreateCompatibleBitmap(dc, size.cx, size.cy); - oldBitmap = SelectObject(dcMem, bitmap); + oldBitmap = (HBITMAP)SelectObject(dcMem, bitmap); /* * The following code is tricky because fonts are rendered in multiple @@ -1334,7 +1337,7 @@ TkDrawAngledChars( GetTextMetricsW(dcMem, &tm); size.cx -= tm.tmOverhang; bitmap = CreateCompatibleBitmap(dc, size.cx, size.cy); - oldBitmap = SelectObject(dcMem, bitmap); + oldBitmap = (HBITMAP)SelectObject(dcMem, bitmap); MultiFontTextOut(dcMem, fontPtr, source, numBytes, 0, tm.tmAscent, angle); @@ -1392,7 +1395,6 @@ TkpDrawCharsInContext( * drawing. */ { int widthUntilStart; - (void) numBytes; /*unused*/ Tk_MeasureChars(tkfont, source, rangeStart, -1, 0, &widthUntilStart); @@ -1498,9 +1500,9 @@ SelectFont( double angle) { if (angle == 0.0) { - return SelectObject(hdc, subFontPtr->hFont0); + return (HFONT)SelectObject(hdc, subFontPtr->hFont0); } else if (angle == subFontPtr->angle) { - return SelectObject(hdc, subFontPtr->hFontAngled); + return (HFONT)SelectObject(hdc, subFontPtr->hFontAngled); } else { if (subFontPtr->hFontAngled) { DeleteObject(subFontPtr->hFontAngled); @@ -1508,10 +1510,10 @@ SelectFont( subFontPtr->hFontAngled = GetScreenFont(&fontPtr->font.fa, subFontPtr->familyPtr->faceName, fontPtr->pixelSize, angle); if (subFontPtr->hFontAngled == NULL) { - return SelectObject(hdc, subFontPtr->hFont0); + return (HFONT)SelectObject(hdc, subFontPtr->hFont0); } subFontPtr->angle = angle; - return SelectObject(hdc, subFontPtr->hFontAngled); + return (HFONT)SelectObject(hdc, subFontPtr->hFontAngled); } } @@ -1563,12 +1565,13 @@ InitFont( window = Tk_WindowId(tkwin); hwnd = (window == None) ? NULL : TkWinGetHWND(window); hdc = GetDC(hwnd); - oldFont = SelectObject(hdc, hFont); + oldFont = (HFONT)SelectObject(hdc, hFont); GetTextMetricsW(hdc, &tm); GetTextFaceW(hdc, LF_FACESIZE, buf); - Tcl_WinTCharToUtf((LPCTSTR)buf, -1, &faceString); + Tcl_DStringInit(&faceString); + Tcl_WCharToUtfDString(buf, wcslen(buf), &faceString); fontPtr->font.fid = (Font) fontPtr; fontPtr->hwnd = hwnd; @@ -1740,15 +1743,16 @@ AllocFontFamily( Tcl_DString faceString; Tcl_Encoding encoding; WCHAR buf[LF_FACESIZE]; - ThreadSpecificData *tsdPtr = + ThreadSpecificData *tsdPtr = (ThreadSpecificData *) Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); - hFont = SelectObject(hdc, hFont); + hFont = (HFONT)SelectObject(hdc, hFont); GetTextFaceW(hdc, LF_FACESIZE, buf); - Tcl_WinTCharToUtf((LPCTSTR)buf, -1, &faceString); + Tcl_DStringInit(&faceString); + Tcl_WCharToUtfDString(buf, wcslen(buf), &faceString); faceName = Tk_GetUid(Tcl_DStringValue(&faceString)); Tcl_DStringFree(&faceString); - hFont = SelectObject(hdc, hFont); + hFont = (HFONT)SelectObject(hdc, hFont); familyPtr = tsdPtr->fontFamilyList; for ( ; familyPtr != NULL; familyPtr = familyPtr->nextPtr) { @@ -1758,7 +1762,7 @@ AllocFontFamily( } } - familyPtr = ckalloc(sizeof(FontFamily)); + familyPtr = (FontFamily *)ckalloc(sizeof(FontFamily)); memset(familyPtr, 0, sizeof(FontFamily)); familyPtr->nextPtr = tsdPtr->fontFamilyList; tsdPtr->fontFamilyList = familyPtr; @@ -1844,7 +1848,7 @@ FreeFontFamily( { int i; FontFamily **familyPtrPtr; - ThreadSpecificData *tsdPtr = + ThreadSpecificData *tsdPtr = (ThreadSpecificData *) Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); if (familyPtr == NULL) { @@ -2048,7 +2052,10 @@ WinFontCanUseProc( fontPtr = canUsePtr->fontPtr; nameTriedPtr = canUsePtr->nameTriedPtr; - fallbackName = Tcl_WinTCharToUtf((LPCTSTR)lfPtr->elfLogFont.lfFaceName, -1, &faceString); + fallbackName = (char *) lfPtr->elfLogFont.lfFaceName; + Tcl_DStringInit(&faceString); + Tcl_WCharToUtfDString((WCHAR *)fallbackName, wcslen((WCHAR *)fallbackName), &faceString); + fallbackName = Tcl_DStringValue(&faceString); if (SeenName(fallbackName, nameTriedPtr) == 0) { subFontPtr = CanUseFallback(hdc, fontPtr, fallbackName, ch, @@ -2177,7 +2184,7 @@ FontMapLoadPage( USHORT *startCount, *endCount; char buf[16], src[4]; - subFontPtr->fontMap[row] = ckalloc(FONTMAP_BITSPERPAGE / 8); + subFontPtr->fontMap[row] = (char *)ckalloc(FONTMAP_BITSPERPAGE / 8); memset(subFontPtr->fontMap[row], 0, FONTMAP_BITSPERPAGE / 8); familyPtr = subFontPtr->familyPtr; @@ -2408,7 +2415,7 @@ CanUseFallback( if (fontPtr->numSubFonts >= SUBFONT_SPACE) { SubFont *newPtr; - newPtr = ckalloc(sizeof(SubFont) * (fontPtr->numSubFonts + 1)); + newPtr = (SubFont *)ckalloc(sizeof(SubFont) * (fontPtr->numSubFonts + 1)); memcpy(newPtr, fontPtr->subFontArray, fontPtr->numSubFonts * sizeof(SubFont)); if (fontPtr->subFontArray != fontPtr->staticSubFonts) { @@ -2456,7 +2463,6 @@ GetScreenFont( double angle) /* What is the desired orientation of the * font. */ { - Tcl_DString ds; HFONT hFont; LOGFONTW lf; @@ -2475,9 +2481,7 @@ GetScreenFont( lf.lfQuality = DEFAULT_QUALITY; lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; - Tcl_WinUtfToTChar(faceName, -1, &ds); - wcsncpy(lf.lfFaceName, (WCHAR *)Tcl_DStringValue(&ds), LF_FACESIZE-1); - Tcl_DStringFree(&ds); + MultiByteToWideChar(CP_UTF8, 0, faceName, -1, lf.lfFaceName, LF_FACESIZE); lf.lfFaceName[LF_FACESIZE-1] = 0; hFont = CreateFontIndirectW(&lf); return hFont; @@ -2526,7 +2530,8 @@ FamilyExists( return 0; } - Tcl_WinUtfToTChar(faceName, -1, &faceString); + Tcl_DStringInit(&faceString); + Tcl_UtfToWCharDString(faceName, -1, &faceString); /* * If the family exists, WinFontExistProc() will be called and @@ -2535,7 +2540,7 @@ FamilyExists( * non-zero value. */ - result = EnumFontFamiliesW(hdc, (WCHAR*) Tcl_DStringValue(&faceString), + result = EnumFontFamiliesW(hdc, (WCHAR *)Tcl_DStringValue(&faceString), (FONTENUMPROCW) WinFontExistProc, 0); Tcl_DStringFree(&faceString); return (result == 0); @@ -2723,7 +2728,7 @@ LoadFontRanges( endCount = NULL; *symbolPtr = 0; - hFont = SelectObject(hdc, hFont); + hFont = (HFONT)SelectObject(hdc, hFont); i = 0; s = (char *) &i; @@ -2778,8 +2783,8 @@ LoadFontRanges( segCount = subTable.segment.segCountX2 / 2; cbData = segCount * sizeof(USHORT); - startCount = ckalloc(cbData); - endCount = ckalloc(cbData); + startCount = (USHORT *)ckalloc(cbData); + endCount = (USHORT *)ckalloc(cbData); offset = encTable.offset + sizeof(subTable.segment); GetFontData(hdc, cmapKey, (DWORD) offset, endCount, cbData); @@ -2822,8 +2827,8 @@ LoadFontRanges( segCount = 1; cbData = segCount * sizeof(USHORT); - startCount = ckalloc(cbData); - endCount = ckalloc(cbData); + startCount = (USHORT *)ckalloc(cbData); + endCount = (USHORT *)ckalloc(cbData); startCount[0] = 0x0000; endCount[0] = 0x00ff; } |