Skip to content

Commit ed5ebc6

Browse files
committed
[GTK] Restore changes in text-antialias behavior of images
On some platforms, creating a surface via cairo_image_surface_create(), rather than gdk_window_create_similar_surface(), causes the text-antialias property to be improperly initialized. Even though getTextAntialias() returns SWT.DEFAULT, any text is painted in an undefined way. This change restores the original way images are created as part of 5c2611d.
1 parent da081e9 commit ed5ebc6

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,11 @@ void init(int width, int height) {
12601260
this.type = SWT.BITMAP;
12611261

12621262
/* Create the pixmap */
1263-
surface = Cairo.cairo_image_surface_create(Cairo.CAIRO_FORMAT_ARGB32, width, height);
1263+
if (GTK.GTK4) {
1264+
surface = Cairo.cairo_image_surface_create(Cairo.CAIRO_FORMAT_RGB24, width, height);
1265+
} else {
1266+
surface = GDK.gdk_window_create_similar_surface(GDK.gdk_get_default_root_window(), Cairo.CAIRO_CONTENT_COLOR, width, height);
1267+
}
12641268
if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES);
12651269
// When we create a blank image we need to set it to 100 in GTK3 as we draw using 100% scale.
12661270
// Cairo will take care of scaling for us when image needs to be scaled.

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,4 +1257,43 @@ public void test_updateWidthHeightAfterDPIChange() {
12571257
DPIUtil.setDeviceZoom(deviceZoom);
12581258
}
12591259
}
1260+
1261+
@Test
1262+
public void test_paintWithTextAntialias() {
1263+
int[] modes = {SWT.ON, SWT.OFF, SWT.DEFAULT};
1264+
int width = (modes.length + 1) * 100;
1265+
int height = 100;
1266+
1267+
Image image1 = new Image(display, width, height);
1268+
GC g1 = new GC(image1);
1269+
g1.setAdvanced(true);
1270+
1271+
g1.drawString("OWVO", 35, 20);
1272+
for (int i = 0 ; i < modes.length; ++i) {
1273+
g1.setTextAntialias(modes[i]);
1274+
g1.drawString("OWVO", 135 + i * 100, 20);
1275+
}
1276+
1277+
Image image2 = new Image(display, width, height);
1278+
GC g2 = new GC(image2);
1279+
g2.setAdvanced(true);
1280+
1281+
for (int i = modes.length - 1 ; i >= 0; --i) {
1282+
g2.setTextAntialias(modes[i]);
1283+
g2.drawString("OWVO", 135 + i * 100, 20);
1284+
}
1285+
g2.setTextAntialias(SWT.DEFAULT);
1286+
g2.drawString("OWVO", 35, 20);
1287+
1288+
ImageData data1 = image1.getImageData();
1289+
ImageData data2 = image2.getImageData();
1290+
1291+
g1.dispose();
1292+
g2.dispose();
1293+
image1.dispose();
1294+
image2.dispose();
1295+
1296+
ImageTestUtil.assertImagesEqual(data1, data2);
1297+
}
1298+
12601299
}

0 commit comments

Comments
 (0)