Skip to content

Commit 50b45ac

Browse files
ptzieglerakurtakov
authored andcommitted
[GTK] Initialize text-antialias when initializing GC object
On some platforms, the default text-antialias of the system might differ from Cairo. When creating a new GC object is created, the Cairo default is used. But when setTextAntialias(SWT.DEFAULT) is called, the system default is used instead. To avoid this ambiguity, setTextAntialias(SWT.DEFAULT) should always be called when creating a GC object, in order to always use the system default.
1 parent 4fecda7 commit 50b45ac

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java

+1
Original file line numberDiff line numberDiff line change
@@ -2659,6 +2659,7 @@ void init(Drawable drawable, GCData data, long gdkGC) {
26592659
Cairo.cairo_set_fill_rule(cairo, Cairo.CAIRO_FILL_RULE_EVEN_ODD);
26602660
data.state &= ~(BACKGROUND | FOREGROUND | FONT | LINE_WIDTH | LINE_CAP | LINE_JOIN | LINE_STYLE | DRAW_OFFSET);
26612661
setClipping(data.clipRgn);
2662+
setTextAntialias(SWT.DEFAULT);
26622663
initCairo();
26632664
if ((data.style & SWT.MIRRORED) != 0) {
26642665
// Don't overwrite the Cairo transformation matrix in GTK 3.14 and above; it contains a translation relative to the parent widget.

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Image.java

+42
Original file line numberDiff line numberDiff line change
@@ -1257,4 +1257,46 @@ public void test_updateWidthHeightAfterDPIChange() {
12571257
DPIUtil.setDeviceZoom(deviceZoom);
12581258
}
12591259
}
1260+
1261+
@Test
1262+
public void test_paintWithTextAntialias() {
1263+
// Must be executed on e.g. a Gnome system
1264+
// where anti-alias is set to use Grayscale
1265+
// whereas Cairo is using RGB by default
1266+
int[] modes = {SWT.ON, SWT.OFF, SWT.DEFAULT};
1267+
int width = (modes.length + 1) * 100;
1268+
int height = 100;
1269+
1270+
Image image1 = new Image(display, width, height);
1271+
GC g1 = new GC(image1);
1272+
g1.setAdvanced(true);
1273+
1274+
g1.drawString("OWVO", 35, 20);
1275+
for (int i = 0 ; i < modes.length; ++i) {
1276+
g1.setTextAntialias(modes[i]);
1277+
g1.drawString("OWVO", 135 + i * 100, 20);
1278+
}
1279+
1280+
Image image2 = new Image(display, width, height);
1281+
GC g2 = new GC(image2);
1282+
g2.setAdvanced(true);
1283+
1284+
for (int i = modes.length - 1 ; i >= 0; --i) {
1285+
g2.setTextAntialias(modes[i]);
1286+
g2.drawString("OWVO", 135 + i * 100, 20);
1287+
}
1288+
g2.setTextAntialias(SWT.DEFAULT);
1289+
g2.drawString("OWVO", 35, 20);
1290+
1291+
ImageData data1 = image1.getImageData();
1292+
ImageData data2 = image2.getImageData();
1293+
1294+
g1.dispose();
1295+
g2.dispose();
1296+
image1.dispose();
1297+
image2.dispose();
1298+
1299+
ImageTestUtil.assertImagesEqual(data1, data2);
1300+
}
1301+
12601302
}

0 commit comments

Comments
 (0)