summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfvogel <fvogelnew1@free.fr>2023-11-15 19:55:23 (GMT)
committerfvogel <fvogelnew1@free.fr>2023-11-15 19:55:23 (GMT)
commit5b7abe20b40cbe5307cb458ec1af39b1f47346f3 (patch)
tree6b2206cdcaf41f5a4548efc27016547b9b295260
parent77f93393c12a891b1f70d1d192302b41fe82a5a8 (diff)
parent26f4d2bf8b589ae78776a8228188384588ffd24c (diff)
downloadtk-5b7abe20b40cbe5307cb458ec1af39b1f47346f3.zip
tk-5b7abe20b40cbe5307cb458ec1af39b1f47346f3.tar.gz
tk-5b7abe20b40cbe5307cb458ec1af39b1f47346f3.tar.bz2
Fix [61550f38bf]: font actual returns wrong font size with Xft.
-rw-r--r--tests/font.test7
-rw-r--r--unix/tkUnixRFont.c19
2 files changed, 14 insertions, 12 deletions
diff --git a/tests/font.test b/tests/font.test
index 69d3b15..d57b998 100644
--- a/tests/font.test
+++ b/tests/font.test
@@ -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 {
diff --git a/unix/tkUnixRFont.c b/unix/tkUnixRFont.c
index a295173..2c017e2 100644
--- a/unix/tkUnixRFont.c
+++ b/unix/tkUnixRFont.c
@@ -178,6 +178,7 @@ GetFont(
static void
GetTkFontAttributes(
+ Tk_Window tkwin,
XftFont *ftFont,
TkFontAttributes *faPtr)
{
@@ -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;
@@ -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;
@@ -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) {
@@ -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);
}
@@ -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 */
@@ -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;
}