- // Font Handling Stuff //////////////////////////////////////////////////////////
-
- protected String[] _listFonts() { return fontList; }
- private static String[] fontList;
- static {
- String[] awtfonts = Toolkit.getDefaultToolkit().getFontList();
- fontList = new String[awtfonts.length * 4];
- for(int i=0; i<awtfonts.length; i++) {
- fontList[i * 4] = awtfonts[i] + "*";
- fontList[i * 4 + 1] = awtfonts[i] + "*b";
- fontList[i * 4 + 2] = awtfonts[i] + "*i";
- fontList[i * 4 + 3] = awtfonts[i] + "*bi";
- }
- }
-
- private static Hash fontCache = new Hash();
- private static ParsedFont pf = new ParsedFont();
- private static MetricatedFont getFont(String font) {
- MetricatedFont ret = (MetricatedFont)fontCache.get(font);
- if (ret == null) {
- pf.parse(font);
- if (pf.name.equals("tty")) pf.name = "monospace";
-
- // Java's fonts tend to be, on average, two points smaller than Win32/X11 fonts. This is most acute in
- // the proxy password dialog on Linux
- ret = new MetricatedFont(pf.name, (pf.bold ? Font.BOLD : 0) | (pf.italic ? Font.ITALIC : 0), pf.size + 2);
-
- fontCache.put(font, ret);
- }
- return ret;
- }
-
- private static class MetricatedFont extends Font {
- public FontMetrics metrics = null;
- public MetricatedFont(String name, int size, int style) {
- super(name, size, style);
- metrics = Toolkit.getDefaultToolkit().getFontMetrics(this);
+ protected Picture _decodeJPEG(InputStream is, String name) {
+ try {
+ Image i = Toolkit.getDefaultToolkit().createImage(InputStreamToByteArray.convert(is));
+ MediaTracker mediatracker = new MediaTracker(new Canvas());
+ mediatracker.addImage(i, 1);
+ try { mediatracker.waitForAll(); } catch (InterruptedException e) { }
+ mediatracker.removeImage(i);
+ final int width = i.getWidth(null);
+ final int height = i.getHeight(null);
+ final int[] data = new int[width * height];
+ PixelGrabber pg = new PixelGrabber(i, 0, 0, width, height, data, 0, width);
+ pg.grabPixels();
+ if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
+ Log.log(this, "PixelGrabber reported an error while decoding JPEG image " + name);
+ return null;
+ }
+ return Platform.createPicture(data, width, height);
+ } catch (Exception e) {
+ Log.log(this, "Exception caught while decoding JPEG image " + name);
+ Log.log(this, e);
+ return null;