Skip to content

[GTK] Initialize text-antialias when initializing GC object #1839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2659,6 +2659,9 @@ void init(Drawable drawable, GCData data, long gdkGC) {
Cairo.cairo_set_fill_rule(cairo, Cairo.CAIRO_FILL_RULE_EVEN_ODD);
data.state &= ~(BACKGROUND | FOREGROUND | FONT | LINE_WIDTH | LINE_CAP | LINE_JOIN | LINE_STYLE | DRAW_OFFSET);
setClipping(data.clipRgn);
if (image != null) {
setTextAntialias(SWT.DEFAULT);
}
initCairo();
if ((data.style & SWT.MIRRORED) != 0) {
// Don't overwrite the Cairo transformation matrix in GTK 3.14 and above; it contains a translation relative to the parent widget.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1257,4 +1257,46 @@ public void test_updateWidthHeightAfterDPIChange() {
DPIUtil.setDeviceZoom(deviceZoom);
}
}

@Test
public void test_paintWithTextAntialias() {
// Must be executed on e.g. a Gnome system
// where anti-alias is set to use Grayscale
// whereas Cairo is using RGB by default
int[] modes = {SWT.ON, SWT.OFF, SWT.DEFAULT};
int width = (modes.length + 1) * 100;
int height = 100;

Image image1 = new Image(display, width, height);
GC g1 = new GC(image1);
g1.setAdvanced(true);

g1.drawString("OWVO", 35, 20);
for (int i = 0 ; i < modes.length; ++i) {
g1.setTextAntialias(modes[i]);
g1.drawString("OWVO", 135 + i * 100, 20);
}

Image image2 = new Image(display, width, height);
GC g2 = new GC(image2);
g2.setAdvanced(true);

for (int i = modes.length - 1 ; i >= 0; --i) {
g2.setTextAntialias(modes[i]);
g2.drawString("OWVO", 135 + i * 100, 20);
}
g2.setTextAntialias(SWT.DEFAULT);
g2.drawString("OWVO", 35, 20);

ImageData data1 = image1.getImageData();
ImageData data2 = image2.getImageData();

g1.dispose();
g2.dispose();
image1.dispose();
image2.dispose();

ImageTestUtil.assertImagesEqual(data1, data2);
}

}
Loading