|
45 | 45 | import org.eclipse.swt.graphics.FontData; |
46 | 46 | import org.eclipse.swt.graphics.GC; |
47 | 47 | import org.eclipse.swt.graphics.Image; |
| 48 | +import org.eclipse.swt.graphics.ImageGcDrawer; |
48 | 49 | import org.eclipse.swt.graphics.Point; |
49 | 50 | import org.eclipse.swt.graphics.RGB; |
50 | 51 | import org.eclipse.swt.graphics.Rectangle; |
| 52 | +import org.eclipse.swt.internal.TransparencyColorImageGcDrawer; |
51 | 53 | import org.eclipse.swt.layout.GridData; |
52 | 54 | import org.eclipse.swt.layout.GridLayout; |
53 | 55 | import org.eclipse.swt.widgets.Button; |
@@ -1306,48 +1308,54 @@ Image colorImage (Color color) { |
1306 | 1308 | } |
1307 | 1309 |
|
1308 | 1310 | 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); |
1351 | 1359 | return image; |
1352 | 1360 | } |
1353 | 1361 |
|
|
0 commit comments