summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/font.test15
-rw-r--r--unix/tkUnix.c2
-rw-r--r--unix/tkUnixRFont.c74
3 files changed, 52 insertions, 39 deletions
diff --git a/tests/font.test b/tests/font.test
index 8794b98..ca38269 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/tkUnix.c b/unix/tkUnix.c
index c0c0288..1c61603 100644
--- a/unix/tkUnix.c
+++ b/unix/tkUnix.c
@@ -135,6 +135,8 @@ Tk_UpdatePointer(
*----------------------------------------------------------------------
*/
+extern int XUnionRegion(Region srca, Region srcb, Region dr_return);
+
void
TkpCopyRegion(
TkRegion dst,
diff --git a/unix/tkUnixRFont.c b/unix/tkUnixRFont.c
index e728137..a99c57b 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;
@@ -191,19 +201,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;
}
@@ -216,12 +226,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;
@@ -465,9 +477,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) {
@@ -503,10 +514,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);
@@ -514,7 +524,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);
}
@@ -731,7 +741,7 @@ Tk_MeasureChars(
int 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 */
@@ -767,7 +777,7 @@ Tk_MeasureChars(
sawNonSpace = 1;
}
-#ifdef DEBUG_FONTSEL
+#if DEBUG_FONTSEL
string[len++] = (char) c;
#endif /* DEBUG_FONTSEL */
ftFont = GetFont(fontPtr, c, 0.0);
@@ -810,9 +820,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;
@@ -948,9 +958,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));
@@ -1089,9 +1097,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));
@@ -1208,9 +1214,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));