Skip to content

Commit

Permalink
Fix [61550f38bf]: font actual returns wrong font size with Xft.
Browse files Browse the repository at this point in the history
  • Loading branch information
fvogelnew1 committed Nov 15, 2023
2 parents 77f9339 + 26f4d2b commit 5b7abe2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
7 changes: 4 additions & 3 deletions tests/font.test
Original file line number Diff line number Diff line change
Expand Up @@ -2339,14 +2339,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} -constraints failsOnUbuntu -setup {
test font-44.1 {TkFontGetPixels: size < 0} -setup {
set oldscale [tk scaling]
} -body {
set oldsize [expr {-(-12.0 / $oldscale)}]
tk scaling 0.5
font actual {times -12} -size
expr {round([font actual {times -12} -size] / $oldscale * 0.5) - round($oldsize) == 0}
} -cleanup {
tk scaling $oldscale
} -result 24
} -result 1
test font-44.2 {TkFontGetPoints: size >= 0} -constraints {noExceed haveTimes12Font} -setup {
set oldscale [tk scaling]
} -body {
Expand Down
19 changes: 10 additions & 9 deletions unix/tkUnixRFont.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ GetFont(

static void
GetTkFontAttributes(
Tk_Window tkwin,
XftFont *ftFont,
TkFontAttributes *faPtr)
{
Expand All @@ -187,12 +188,12 @@ GetTkFontAttributes(
double size, ptsize;

(void) XftPatternGetString(ftFont->pattern, XFT_FAMILY, 0, familyPtr);
if (XftPatternGetDouble(ftFont->pattern, XFT_SIZE, 0,
&ptsize) == XftResultMatch) {
size = ptsize;
} else if (XftPatternGetDouble(ftFont->pattern, XFT_PIXEL_SIZE, 0,
if (XftPatternGetDouble(ftFont->pattern, XFT_PIXEL_SIZE, 0,
&ptsize) == XftResultMatch) {
size = -ptsize;
} else if (XftPatternGetDouble(ftFont->pattern, XFT_SIZE, 0,
&ptsize) == XftResultMatch) {
size = ptsize;
} else if (XftPatternGetInteger(ftFont->pattern, XFT_PIXEL_SIZE, 0,
&pxsize) == XftResultMatch) {
size = (double)-pxsize;
Expand All @@ -214,7 +215,7 @@ GetTkFontAttributes(
#endif /* DEBUG_FONTSEL */

faPtr->family = Tk_GetUid(family);
faPtr->size = size;
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;
Expand Down Expand Up @@ -350,7 +351,7 @@ InitFont(
return NULL;
}
fontPtr->font.fid = XLoadFont(Tk_Display(tkwin), "fixed");
GetTkFontAttributes(ftFont, &fontPtr->font.fa);
GetTkFontAttributes(tkwin, ftFont, &fontPtr->font.fa);
GetTkFontMetrics(ftFont, &fontPtr->font.fm);
Tk_DeleteErrorHandler(handler);
if (errorFlag) {
Expand Down Expand Up @@ -506,7 +507,7 @@ TkpGetFontFromAttributes(
if (faPtr->size > 0.0) {
XftPatternAddDouble(pattern, XFT_SIZE, faPtr->size);
} else if (faPtr->size < 0.0) {
XftPatternAddDouble(pattern, XFT_SIZE, TkFontGetPoints(tkwin, faPtr->size));
XftPatternAddDouble(pattern, XFT_PIXEL_SIZE, -faPtr->size);
} else {
XftPatternAddDouble(pattern, XFT_SIZE, 12.0);
}
Expand Down Expand Up @@ -675,7 +676,7 @@ TkpGetSubFonts(

void
TkpGetFontAttrsForChar(
TCL_UNUSED(Tk_Window), /* Window on the font's display */
Tk_Window tkwin, /* Window on the font's display */
Tk_Font tkfont, /* Font to query */
int c, /* Character of interest */
TkFontAttributes *faPtr) /* Output: Font attributes */
Expand All @@ -687,7 +688,7 @@ TkpGetFontAttrsForChar(
XftFont *ftFont = GetFont(fontPtr, ucs4, 0.0);
/* Actual font used to render the character */

GetTkFontAttributes(ftFont, faPtr);
GetTkFontAttributes(tkwin, ftFont, faPtr);
faPtr->underline = fontPtr->font.fa.underline;
faPtr->overstrike = fontPtr->font.fa.overstrike;
}
Expand Down

0 comments on commit 5b7abe2

Please sign in to comment.