Skip to content

Commit f6ace53

Browse files
author
jan.nijtmans
committed
Merge 9.0
2 parents c3f0cb7 + b0f89cb commit f6ace53

File tree

5 files changed

+83
-35
lines changed

5 files changed

+83
-35
lines changed

generic/tkFont.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,12 @@ Tk_AllocFontFromObj(
11321132

11331133
FreeFontObj(objPtr);
11341134
oldFontPtr = NULL;
1135-
} else if (Tk_Screen(tkwin) == oldFontPtr->screen) {
1135+
} else if (Tk_Screen(tkwin) == oldFontPtr->screen
1136+
#ifdef HAVE_XFT
1137+
&& Tk_Colormap(tkwin) == oldFontPtr->colormap
1138+
&& Tk_Visual(tkwin) == oldFontPtr->visual
1139+
#endif
1140+
) {
11361141
oldFontPtr->resourceRefCount++;
11371142
return (Tk_Font) oldFontPtr;
11381143
}
@@ -1154,7 +1159,12 @@ Tk_AllocFontFromObj(
11541159
firstFontPtr = (TkFont *)Tcl_GetHashValue(cacheHashPtr);
11551160
for (fontPtr = firstFontPtr; (fontPtr != NULL);
11561161
fontPtr = fontPtr->nextPtr) {
1157-
if (Tk_Screen(tkwin) == fontPtr->screen) {
1162+
if (Tk_Screen(tkwin) == fontPtr->screen
1163+
#ifdef HAVE_XFT
1164+
&& Tk_Colormap(tkwin) == fontPtr->colormap
1165+
&& Tk_Visual(tkwin) == fontPtr->visual
1166+
#endif
1167+
) {
11581168
fontPtr->resourceRefCount++;
11591169
fontPtr->objRefCount++;
11601170
objPtr->internalRep.twoPtrValue.ptr1 = fontPtr;
@@ -1225,6 +1235,8 @@ Tk_AllocFontFromObj(
12251235
fontPtr->cacheHashPtr = cacheHashPtr;
12261236
fontPtr->namedHashPtr = namedHashPtr;
12271237
fontPtr->screen = Tk_Screen(tkwin);
1238+
fontPtr->colormap = Tk_Colormap(tkwin);
1239+
fontPtr->visual = Tk_Visual(tkwin);
12281240
fontPtr->nextPtr = firstFontPtr;
12291241
Tcl_SetHashValue(cacheHashPtr, fontPtr);
12301242

@@ -1317,7 +1329,12 @@ Tk_GetFontFromObj(
13171329

13181330
FreeFontObj(objPtr);
13191331
fontPtr = NULL;
1320-
} else if (Tk_Screen(tkwin) == fontPtr->screen) {
1332+
} else if (Tk_Screen(tkwin) == fontPtr->screen
1333+
#ifdef HAVE_XFT
1334+
&& Tk_Colormap(tkwin) == fontPtr->colormap
1335+
&& Tk_Visual(tkwin) == fontPtr->visual
1336+
#endif
1337+
) {
13211338
return (Tk_Font) fontPtr;
13221339
}
13231340
}
@@ -1336,7 +1353,12 @@ Tk_GetFontFromObj(
13361353
if (hashPtr != NULL) {
13371354
for (fontPtr = (TkFont *)Tcl_GetHashValue(hashPtr); fontPtr != NULL;
13381355
fontPtr = fontPtr->nextPtr) {
1339-
if (Tk_Screen(tkwin) == fontPtr->screen) {
1356+
if (Tk_Screen(tkwin) == fontPtr->screen
1357+
#ifdef HAVE_XFT
1358+
&& Tk_Colormap(tkwin) == fontPtr->colormap
1359+
&& Tk_Visual(tkwin) == fontPtr->visual
1360+
#endif
1361+
) {
13401362
fontPtr->objRefCount++;
13411363
objPtr->internalRep.twoPtrValue.ptr1 = fontPtr;
13421364
objPtr->internalRep.twoPtrValue.ptr2 = fiPtr;

generic/tkFont.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ typedef struct TkFont {
131131
* that was used to create this font. */
132132
TkFontMetrics fm; /* Font metrics determined when font was
133133
* created. */
134+
Colormap colormap; /* Only used with HAVE_XFT */
135+
Visual* visual; /* Only used with HAVE_XFT */
134136
struct TkFont *nextPtr; /* Points to the next TkFont structure with
135137
* the same name. All fonts with the same name
136138
* (but different displays) are chained

tests/visual.test

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,20 @@ update
3838
set default "[winfo visual .] [winfo depth .]"
3939
set avail [winfo visualsavailable .]
4040
set other {}
41+
set 32bitsVisual {}
4142
if {[llength $avail] > 1} {
4243
foreach visual $avail {
4344
if {$visual != $default} {
4445
set other $visual
4546
break
4647
}
4748
}
49+
foreach visual $avail {
50+
if {[lindex $visual 1] == 32} {
51+
set 32bitsVisual $visual
52+
break
53+
}
54+
}
4855
}
4956

5057
#
@@ -54,6 +61,8 @@ if {[llength $avail] > 1} {
5461
testConstraint haveOtherVisual [expr {$other ne ""}]
5562
testConstraint havePseudocolorVisual [string match *pseudocolor* $avail]
5663
testConstraint haveMultipleVisuals [expr {[llength $avail] > 1}]
64+
testConstraint haveDefault24bitsVisual [expr {[winfo depth .] == 24}]
65+
testConstraint have32bitsVisual [expr {$32bitsVisual ne ""}]
5766

5867
#
5968
# TESTS
@@ -542,6 +551,20 @@ test visual-8.2 {Tk_FreeColormap procedure} -constraints haveOtherVisual -setup
542551
} -result {}
543552

544553
#
554+
test visual-9.1 {Using two different visuals on the same screen - bug c23f79ef96} -constraints {
555+
haveDefault24bitsVisual have32bitsVisual
556+
} -setup {
557+
deleteWindows
558+
} -body {
559+
set res [winfo depth .]
560+
toplevel .t -visual $32bitsVisual
561+
pack [label .t.l -text "Any text"] ; # Shall not crash ("X Error of failed request: BadValue [...]")
562+
update
563+
lappend res [winfo depth .t]
564+
} -cleanup {
565+
deleteWindows
566+
} -result {24 32}
567+
545568
# TESTFILE CLEANUP
546569
#
547570

unix/tkUnixRFont.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ typedef struct {
4848

4949
Display *display;
5050
int screen;
51+
Colormap colormap;
52+
Visual *visual;
5153
XftDraw *ftDraw;
5254
int ncolors;
5355
int firstColor;
@@ -351,6 +353,8 @@ InitFont(
351353

352354
fontPtr->display = Tk_Display(tkwin);
353355
fontPtr->screen = Tk_ScreenNumber(tkwin);
356+
fontPtr->colormap = Tk_Colormap(tkwin);
357+
fontPtr->visual = Tk_Visual(tkwin);
354358
fontPtr->ftDraw = 0;
355359
fontPtr->ncolors = 0;
356360
fontPtr->firstColor = -1;
@@ -907,7 +911,7 @@ LookUpColor(Display *display, /* Display to lookup colors on */
907911
* Translate the pixel value to a color. Needs a server round-trip.
908912
*/
909913
xcolor.pixel = pixel;
910-
XQueryColor(display, DefaultColormap(display, fontPtr->screen), &xcolor);
914+
XQueryColor(display, fontPtr->colormap, &xcolor);
911915

912916
fontPtr->colors[last].color.color.red = xcolor.red;
913917
fontPtr->colors[last].color.color.green = xcolor.green;
@@ -961,9 +965,8 @@ Tk_DrawChars(
961965
if (fontPtr->ftDraw == 0) {
962966
DEBUG(("Switch to drawable 0x%lx\n", drawable));
963967
fontPtr->ftDraw = XftDrawCreate(display, drawable,
964-
DefaultVisual(display, fontPtr->screen),
965-
DefaultColormap(display, fontPtr->screen));
966-
} else {
968+
fontPtr->visual, fontPtr->colormap);
969+
} else {
967970
Tk_ErrorHandler handler =
968971
Tk_CreateErrorHandler(display, -1, -1, -1, NULL, NULL);
969972

@@ -1100,8 +1103,7 @@ TkDrawAngledChars(
11001103
if (fontPtr->ftDraw == 0) {
11011104
DEBUG(("Switch to drawable 0x%lx\n", drawable));
11021105
fontPtr->ftDraw = XftDrawCreate(display, drawable,
1103-
DefaultVisual(display, fontPtr->screen),
1104-
DefaultColormap(display, fontPtr->screen));
1106+
fontPtr->visual, fontPtr->colormap);
11051107
} else {
11061108
Tk_ErrorHandler handler =
11071109
Tk_CreateErrorHandler(display, -1, -1, -1, NULL, NULL);
@@ -1217,8 +1219,7 @@ TkDrawAngledChars(
12171219
if (fontPtr->ftDraw == 0) {
12181220
DEBUG(("Switch to drawable 0x%lx\n", drawable));
12191221
fontPtr->ftDraw = XftDrawCreate(display, drawable,
1220-
DefaultVisual(display, fontPtr->screen),
1221-
DefaultColormap(display, fontPtr->screen));
1222+
fontPtr->visual, fontPtr->colormap);
12221223
} else {
12231224
Tk_ErrorHandler handler =
12241225
Tk_CreateErrorHandler(display, -1, -1, -1, NULL, NULL);

win/tkWinDraw.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,29 +1258,29 @@ DrawOrFillArc(
12581258
yend = (int)((yr + sin(-radian_end)*height/2.0) + 0.5);
12591259

12601260
if ((xstart == xend) && (ystart == yend) && !extent_is_360_deg) {
1261-
/*
1262-
* The extent is so small that the arc size is less than one pixel.
1263-
* If the Arc, Chord, or Pie GDI function later received this, then
1264-
* a complete ellipse would be drawn instead of the desired 1-pixel
1265-
* size arc. The end point must be made different from the start
1266-
* point. Since (at this level in the code) arcs are always drawn
1267-
* counterclockwise, either xend or yend needs adjustment, depending
1268-
* on the sub-range where radian_start lies (it was constrained to
1269-
* the [0 ; 2*PI[ range earlier). See bug [6051a9fc]
1270-
*/
1271-
if (radian_start > PI/4) {
1272-
if (radian_start < 3*PI/4) {
1273-
xend--;
1274-
} else if (radian_start < 5*PI/4) {
1275-
yend++;
1276-
} else if (radian_start < 7*PI/4) {
1277-
xend++;
1278-
} else {
1279-
yend--;
1280-
}
1281-
} else {
1282-
yend--;
1283-
}
1261+
/*
1262+
* The extent is so small that the arc size is less than one pixel.
1263+
* If the Arc, Chord, or Pie GDI function later received this, then
1264+
* a complete ellipse would be drawn instead of the desired 1-pixel
1265+
* size arc. The end point must be made different from the start
1266+
* point. Since (at this level in the code) arcs are always drawn
1267+
* counterclockwise, either xend or yend needs adjustment, depending
1268+
* on the sub-range where radian_start lies (it was constrained to
1269+
* the [0 ; 2*PI[ range earlier). See bug [6051a9fc]
1270+
*/
1271+
if (radian_start > PI/4) {
1272+
if (radian_start < 3*PI/4) {
1273+
xend--;
1274+
} else if (radian_start < 5*PI/4) {
1275+
yend++;
1276+
} else if (radian_start < 7*PI/4) {
1277+
xend++;
1278+
} else {
1279+
yend--;
1280+
}
1281+
} else {
1282+
yend--;
1283+
}
12841284
}
12851285

12861286
/*

0 commit comments

Comments
 (0)