Index: .github/workflows/linux-build.yml ================================================================== --- .github/workflows/linux-build.yml +++ .github/workflows/linux-build.yml @@ -3,10 +3,11 @@ push: branches: - "main" - "core-8-branch" - "core-8-6-branch" + - "bug-8162e9b7a9" tags: - "core-**" permissions: contents: read defaults: Index: .github/workflows/mac-build.yml ================================================================== --- .github/workflows/mac-build.yml +++ .github/workflows/mac-build.yml @@ -3,10 +3,11 @@ push: branches: - "main" - "core-8-branch" - "core-8-6-branch" + - "bug-8162e9b7a9" tags: - "core-**" permissions: contents: read env: Index: .github/workflows/win-build.yml ================================================================== --- .github/workflows/win-build.yml +++ .github/workflows/win-build.yml @@ -3,10 +3,11 @@ push: branches: - "main" - "core-8-branch" - "core-8-6-branch" + - "bug-8162e9b7a9" tags: - "core-**" permissions: contents: read env: Index: tests/font.test ================================================================== --- tests/font.test +++ tests/font.test @@ -2345,27 +2345,34 @@ font actual -xyz-?-*-*-*-*-*-*-*-*-*-*-*-* lindex [font actual -xyz-times-*-*-*-*-*-*-*-*-*-*-*-*] 1 } -result [font actual {times 0} -family] -test font-44.1 {TkFontGetPixels: size < 0} -setup { +test font-44.1 {TkFontGetPixels: size < 0} -setup { set oldscale [tk scaling] } -body { - set oldsize [expr {-(-12.0 / $oldscale)}] + # if this test failed, start the investigations by reading ticket [8162e9b7a9] tk scaling 0.5 - expr {round([font actual {times -12} -size] / $oldscale * 0.5) - round($oldsize) == 0} + font actual {times -13} -size } -cleanup { tk scaling $oldscale -} -result 1 +} -result 26 test font-44.2 {TkFontGetPoints: size >= 0} -constraints {noExceed haveTimes12Font} -setup { set oldscale [tk scaling] } -body { tk scaling 0.5 font actual {times 12} -size } -cleanup { tk scaling $oldscale } -result 12 +test font-44.3 {font create with display scaling not 100% - bug 8162e9b7a9} -body { + set font1 TkDefaultFont + set font2 [font create Font2 {*}[font actual $font1]] + expr {[font actual $font1 -size] == [font actual $font2 -size]} +} -cleanup { + font delete $font2 +} -result 1 test font-45.1 {TkFontGetAliasList: no match} -body { font actual {snarky 10} -family } -result [font actual {-size 10} -family] Index: unix/tkUnixRFont.c ================================================================== --- unix/tkUnixRFont.c +++ unix/tkUnixRFont.c @@ -13,10 +13,20 @@ #include "tkFont.h" #include #define MAX_CACHED_COLORS 16 +/* + * Debugging support... + */ + +#define DEBUG_FONTSEL 0 +#define DEBUG(arguments) \ + if (DEBUG_FONTSEL) { \ + printf arguments; fflush(stdout); \ + } + typedef struct { XftFont *ftFont; XftFont *ft0Font; FcPattern *source; FcCharSet *charset; @@ -182,23 +192,23 @@ XftFont *ftFont, TkFontAttributes *faPtr) { const char *family = "Unknown"; const char *const *familyPtr = &family; - int weight, slant, pxsize; - double size, ptsize; + double ptSize, dblPxSize, size; + int intPxSize, weight, slant; (void) XftPatternGetString(ftFont->pattern, XFT_FAMILY, 0, familyPtr); - if (XftPatternGetDouble(ftFont->pattern, XFT_PIXEL_SIZE, 0, - &ptsize) == XftResultMatch) { - size = -ptsize; - } else if (XftPatternGetDouble(ftFont->pattern, XFT_SIZE, 0, - &ptsize) == XftResultMatch) { - size = ptsize; + if (XftPatternGetDouble(ftFont->pattern, XFT_SIZE, 0, + &ptSize) == XftResultMatch) { + size = ptSize; + } else if (XftPatternGetDouble(ftFont->pattern, XFT_PIXEL_SIZE, 0, + &dblPxSize) == XftResultMatch) { + size = -dblPxSize; } else if (XftPatternGetInteger(ftFont->pattern, XFT_PIXEL_SIZE, 0, - &pxsize) == XftResultMatch) { - size = (double)-pxsize; + &intPxSize) == XftResultMatch) { + size = (double)-intPxSize; } else { size = 12.0; } if (XftPatternGetInteger(ftFont->pattern, XFT_WEIGHT, 0, &weight) != XftResultMatch) { @@ -207,16 +217,18 @@ if (XftPatternGetInteger(ftFont->pattern, XFT_SLANT, 0, &slant) != XftResultMatch) { slant = XFT_SLANT_ROMAN; } -#ifdef DEBUG_FONTSEL - printf("family %s size %d weight %d slant %d\n", - family, (int)size, weight, slant); -#endif /* DEBUG_FONTSEL */ + DEBUG(("GetTkFontAttributes: family %s size %ld weight %d slant %d\n", + family, lround(size), weight, slant)); faPtr->family = Tk_GetUid(family); + /* + * Make sure that faPtr->size will be > 0 even + * in the very unprobable case that size < 0 + */ faPtr->size = TkFontGetPoints(tkwin, size); faPtr->weight = (weight > XFT_WEIGHT_MEDIUM) ? TK_FW_BOLD : TK_FW_NORMAL; faPtr->slant = (slant > XFT_SLANT_ROMAN) ? TK_FS_ITALIC : TK_FS_ROMAN; faPtr->underline = 0; faPtr->overstrike = 0; @@ -456,13 +468,12 @@ Tk_Window tkwin, /* For display where font will be used. */ const char *name) /* Platform-specific font name. */ { UnixFtFont *fontPtr; FcPattern *pattern; -#ifdef DEBUG_FONTSEL - printf("TkpGetNativeFont %s\n", name); -#endif /* DEBUG_FONTSEL */ + + DEBUG(("TkpGetNativeFont: %s\n", name)); pattern = XftXlfdParse(name, FcFalse, FcFalse); if (!pattern) { return NULL; } @@ -494,22 +505,21 @@ { XftPattern *pattern; int weight, slant; UnixFtFont *fontPtr; -#ifdef DEBUG_FONTSEL - printf("TkpGetFontFromAttributes %s-%d %d %d\n", faPtr->family, - (int)faPtr->size, faPtr->weight, faPtr->slant); -#endif /* DEBUG_FONTSEL */ + DEBUG(("TkpGetFontFromAttributes: %s %ld %d %d\n", faPtr->family, + lround(faPtr->size), faPtr->weight, faPtr->slant)); + pattern = XftPatternCreate(); if (faPtr->family) { XftPatternAddString(pattern, XFT_FAMILY, faPtr->family); } if (faPtr->size > 0.0) { XftPatternAddDouble(pattern, XFT_SIZE, faPtr->size); } else if (faPtr->size < 0.0) { - XftPatternAddDouble(pattern, XFT_PIXEL_SIZE, -faPtr->size); + XftPatternAddDouble(pattern, XFT_SIZE, TkFontGetPoints(tkwin, faPtr->size)); } else { XftPatternAddDouble(pattern, XFT_SIZE, 12.0); } switch (faPtr->weight) { case TK_FW_NORMAL: @@ -721,11 +731,11 @@ FcChar32 c; XGlyphInfo extents; int clen, curX, newX, curByte, newByte, sawNonSpace; int termByte = 0, termX = 0, errorFlag = 0; Tk_ErrorHandler handler; -#ifdef DEBUG_FONTSEL +#if DEBUG_FONTSEL char string[256]; int len = 0; #endif /* DEBUG_FONTSEL */ handler = Tk_CreateErrorHandler(fontPtr->display, @@ -757,11 +767,11 @@ } } else { sawNonSpace = 1; } -#ifdef DEBUG_FONTSEL +#if DEBUG_FONTSEL string[len++] = (char) c; #endif /* DEBUG_FONTSEL */ ftFont = GetFont(fontPtr, c, 0.0); if (!errorFlag) { @@ -800,13 +810,13 @@ curX = newX; curByte = newByte; } measureCharsEnd: Tk_DeleteErrorHandler(handler); -#ifdef DEBUG_FONTSEL +#if DEBUG_FONTSEL string[len] = '\0'; - printf("MeasureChars %s length %d bytes %d\n", string, curX, curByte); + DEBUG(("MeasureChars: %s length %d bytes %d\n", string, curX, curByte)); #endif /* DEBUG_FONTSEL */ *lengthPtr = curX; return curByte; } @@ -938,13 +948,11 @@ XGlyphInfo metrics; ThreadSpecificData *tsdPtr = (ThreadSpecificData *) Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); if (fontPtr->ftDraw == 0) { -#ifdef DEBUG_FONTSEL - printf("Switch to drawable 0x%lx\n", drawable); -#endif /* DEBUG_FONTSEL */ + DEBUG(("Switch to drawable 0x%lx\n", drawable)); fontPtr->ftDraw = XftDrawCreate(display, drawable, DefaultVisual(display, fontPtr->screen), DefaultColormap(display, fontPtr->screen)); } else { Tk_ErrorHandler handler = @@ -1079,13 +1087,11 @@ XGlyphInfo metrics; XftFont *currentFtFont; int originX, originY; if (fontPtr->ftDraw == 0) { -#ifdef DEBUG_FONTSEL - printf("Switch to drawable 0x%x\n", drawable); -#endif /* DEBUG_FONTSEL */ + DEBUG(("Switch to drawable 0x%x\n", drawable)); fontPtr->ftDraw = XftDrawCreate(display, drawable, DefaultVisual(display, fontPtr->screen), DefaultColormap(display, fontPtr->screen)); } else { Tk_ErrorHandler handler = @@ -1197,13 +1203,11 @@ XftGlyphFontSpec specs[NUM_SPEC]; XGlyphInfo metrics; double sinA = sin(angle * PI/180.0), cosA = cos(angle * PI/180.0); if (fontPtr->ftDraw == 0) { -#ifdef DEBUG_FONTSEL - printf("Switch to drawable 0x%lx\n", drawable); -#endif /* DEBUG_FONTSEL */ + DEBUG(("Switch to drawable 0x%lx\n", drawable)); fontPtr->ftDraw = XftDrawCreate(display, drawable, DefaultVisual(display, fontPtr->screen), DefaultColormap(display, fontPtr->screen)); } else { Tk_ErrorHandler handler =