diff options
-rw-r--r-- | tests/font.test | 15 | ||||
-rw-r--r-- | unix/tkUnixRFont.c | 74 |
2 files changed, 50 insertions, 39 deletions
diff --git a/tests/font.test b/tests/font.test index 4a264f8..37132ad 100644 --- a/tests/font.test +++ b/tests/font.test @@ -2347,15 +2347,15 @@ test font-43.1 {FieldSpecified procedure: specified vs. non-specified} -body { } -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 { @@ -2364,6 +2364,13 @@ test font-44.2 {TkFontGetPoints: size >= 0} -constraints {noExceed haveTimes12Fo } -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 { diff --git a/unix/tkUnixRFont.c b/unix/tkUnixRFont.c index baf9071..2a3ecef 100644 --- a/unix/tkUnixRFont.c +++ b/unix/tkUnixRFont.c @@ -15,6 +15,16 @@ #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; @@ -184,19 +194,19 @@ GetTkFontAttributes( { 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; } @@ -209,12 +219,14 @@ GetTkFontAttributes( 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; @@ -458,9 +470,8 @@ TkpGetNativeFont( { 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) { @@ -496,10 +507,9 @@ TkpGetFontFromAttributes( 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); @@ -507,7 +517,7 @@ TkpGetFontFromAttributes( 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); } @@ -723,7 +733,7 @@ Tk_MeasureChars( 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 */ @@ -759,7 +769,7 @@ Tk_MeasureChars( sawNonSpace = 1; } -#ifdef DEBUG_FONTSEL +#if DEBUG_FONTSEL string[len++] = (char) c; #endif /* DEBUG_FONTSEL */ ftFont = GetFont(fontPtr, c, 0.0); @@ -802,9 +812,9 @@ Tk_MeasureChars( } 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; @@ -940,9 +950,7 @@ Tk_DrawChars( 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)); @@ -1081,9 +1089,7 @@ TkDrawAngledChars( 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)); @@ -1199,9 +1205,7 @@ TkDrawAngledChars( 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)); |