Skip to content

Commit ec914a9

Browse files
amartya4256HeikoKlare
authored andcommitted
Adapt Tab#fontImage to use TransparencyColorImageGcDrawer
This commit adapts Tab#fontImage to replace ImageGcDrawer with TransparencyColorImageGcDrawer as the operation GC#drawRectangle with GC#fillRecatngle do not work the best together and cause an overfilled rectangle.
1 parent 6376e25 commit ec914a9

File tree

1 file changed

+50
-42
lines changed
  • examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample

1 file changed

+50
-42
lines changed

examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.java

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@
4545
import org.eclipse.swt.graphics.FontData;
4646
import org.eclipse.swt.graphics.GC;
4747
import org.eclipse.swt.graphics.Image;
48+
import org.eclipse.swt.graphics.ImageGcDrawer;
4849
import org.eclipse.swt.graphics.Point;
4950
import org.eclipse.swt.graphics.RGB;
5051
import org.eclipse.swt.graphics.Rectangle;
52+
import org.eclipse.swt.internal.TransparencyColorImageGcDrawer;
5153
import org.eclipse.swt.layout.GridData;
5254
import org.eclipse.swt.layout.GridLayout;
5355
import org.eclipse.swt.widgets.Button;
@@ -1306,48 +1308,54 @@ Image colorImage (Color color) {
13061308
}
13071309

13081310
Image fontImage (Font font) {
1309-
Image image = new Image (display, IMAGE_SIZE, IMAGE_SIZE);
1310-
GC gc = new GC(image);
1311-
Rectangle bounds = image.getBounds();
1312-
gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
1313-
gc.fillRectangle(0, 0, bounds.width, bounds.height);
1314-
gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
1315-
gc.drawRectangle(0, 0, bounds.width - 1, bounds.height - 1);
1316-
FontData data[] = font.getFontData();
1317-
int style = data[0].getStyle();
1318-
switch (style) {
1319-
case SWT.NORMAL:
1320-
gc.drawLine(3, 3, 3, 8);
1321-
gc.drawLine(4, 3, 7, 8);
1322-
gc.drawLine(8, 3, 8, 8);
1323-
break;
1324-
case SWT.BOLD:
1325-
gc.drawLine(3, 2, 3, 9);
1326-
gc.drawLine(4, 2, 4, 9);
1327-
gc.drawLine(5, 2, 7, 2);
1328-
gc.drawLine(5, 3, 8, 3);
1329-
gc.drawLine(5, 5, 7, 5);
1330-
gc.drawLine(5, 6, 7, 6);
1331-
gc.drawLine(5, 8, 8, 8);
1332-
gc.drawLine(5, 9, 7, 9);
1333-
gc.drawLine(7, 4, 8, 4);
1334-
gc.drawLine(7, 7, 8, 7);
1335-
break;
1336-
case SWT.ITALIC:
1337-
gc.drawLine(6, 2, 8, 2);
1338-
gc.drawLine(7, 3, 4, 8);
1339-
gc.drawLine(3, 9, 5, 9);
1340-
break;
1341-
case SWT.BOLD | SWT.ITALIC:
1342-
gc.drawLine(5, 2, 8, 2);
1343-
gc.drawLine(5, 3, 8, 3);
1344-
gc.drawLine(6, 4, 4, 7);
1345-
gc.drawLine(7, 4, 5, 7);
1346-
gc.drawLine(3, 8, 6, 8);
1347-
gc.drawLine(3, 9, 6, 9);
1348-
break;
1349-
}
1350-
gc.dispose();
1311+
Color transparentcolor = display.getSystemColor(SWT.COLOR_CYAN);
1312+
@SuppressWarnings("restriction")
1313+
ImageGcDrawer igc = new TransparencyColorImageGcDrawer(transparentcolor) {
1314+
@Override
1315+
public void drawOn(GC gc, int iwidth, int iheight) {
1316+
gc.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
1317+
gc.fillRectangle(0, 0, iwidth, iheight);
1318+
gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
1319+
gc.fillRectangle(0, 0, iwidth - 1, iheight - 1);
1320+
gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
1321+
gc.drawRectangle(0, 0, iwidth - 1, iheight- 1);
1322+
FontData data[] = font.getFontData();
1323+
int style = data[0].getStyle();
1324+
switch (style) {
1325+
case SWT.NORMAL:
1326+
gc.drawLine(3, 3, 3, 8);
1327+
gc.drawLine(4, 3, 7, 8);
1328+
gc.drawLine(8, 3, 8, 8);
1329+
break;
1330+
case SWT.BOLD:
1331+
gc.drawLine(3, 2, 3, 9);
1332+
gc.drawLine(4, 2, 4, 9);
1333+
gc.drawLine(5, 2, 7, 2);
1334+
gc.drawLine(5, 3, 8, 3);
1335+
gc.drawLine(5, 5, 7, 5);
1336+
gc.drawLine(5, 6, 7, 6);
1337+
gc.drawLine(5, 8, 8, 8);
1338+
gc.drawLine(5, 9, 7, 9);
1339+
gc.drawLine(7, 4, 8, 4);
1340+
gc.drawLine(7, 7, 8, 7);
1341+
break;
1342+
case SWT.ITALIC:
1343+
gc.drawLine(6, 2, 8, 2);
1344+
gc.drawLine(7, 3, 4, 8);
1345+
gc.drawLine(3, 9, 5, 9);
1346+
break;
1347+
case SWT.BOLD | SWT.ITALIC:
1348+
gc.drawLine(5, 2, 8, 2);
1349+
gc.drawLine(5, 3, 8, 3);
1350+
gc.drawLine(6, 4, 4, 7);
1351+
gc.drawLine(7, 4, 5, 7);
1352+
gc.drawLine(3, 8, 6, 8);
1353+
gc.drawLine(3, 9, 6, 9);
1354+
break;
1355+
}
1356+
}
1357+
};
1358+
Image image = new Image (display, igc, IMAGE_SIZE, IMAGE_SIZE);
13511359
return image;
13521360
}
13531361

0 commit comments

Comments
 (0)