- }
-
-
- // Font Handling ////////////////////////////////////////////////////////////////////
-
- static String[] fontList = null;
-
- /** hashtable of all built in X11 fonts; key is XWT font spec, value is X11 font string */
- static Hashtable nativeFontList = new Hashtable();
-
- /** cache of all already-looked-up X11 fonts; key is XWT font name, value is a WrappedRawData */
- static Hashtable xwtFontToFontStruct = new Hashtable();
-
- /** dumps a list of X11 font strings */
- private native String[] listNativeFonts();
-
- /** load native font list */
- public void initFonts() {
- // use the font list to build nativeFontList
- String[] fonts = listNativeFonts();
-
- Vector v = new Vector();
- for(int k=0; k<fonts.length; k++) {
-
- String s = fonts[k].toLowerCase();
- String s2 = s;
- try {
- v.setSize(0);
- s = s.substring(s.indexOf('-') + 1);
- while (s.indexOf('-') != -1) {
- v.addElement(s.substring(0, s.indexOf('-')));
- s = s.substring(s.indexOf('-') + 1);
- }
- v.addElement(s);
- String[] font = new String[v.size()];
- v.copyInto(font);
-
- // limit to iso8559 until we can do I18N properly....
- if (font.length > 12) {
- if (!font[12].equals("iso8859") && !font[12].equals("")) continue;
- if (font.length < 14 || !font[13].equals("1")) continue;
- }
-
- String name = font[1];
- String size = font[6];
- String slant = (font[3].equals("i") || font[3].equals("o")) ? "i" : "";
- String bold = font[2].equals("bold") ? "b" : "";
- String tail = s2.substring(1 + font[0].length() + 1 + font[1].length() + 1 + font[2].length() + 1 +
- font[3].length() + 1 + font[4].length() + 1);
-
- if (bold.equals("*") && slant.equals("*")) {
- nativeFontList.put(name + size, font[0] + "-" + font[1] + "-regular-r-" + font[4] + "-" + tail);
- nativeFontList.put(name + size + "b", font[0] + "-" + font[1] + "-bold-r-" + font[4] + "-" + tail);
- nativeFontList.put(name + size + "i", font[0] + "-" + font[1] + "-regular-i-" + font[4] + "-" + tail);
- nativeFontList.put(name + size + "bi", font[0] + "-" + font[1] + "-bold-i-" + font[4] + "-" + tail);
-
- } else if (bold.equals("*")) {
- nativeFontList.put(name + size + slant, font[0] + "-" + font[1] + "-regular-" + font[3] + "-" + font[4] + "-" + tail);
- nativeFontList.put(name + size + "b" + slant, font[0] + "-" + font[1] + "-bold-" + font[3] + "-" + font[4] + "-" + tail);
-
- } else if (slant.equals("*")) {
- nativeFontList.put(name + size + bold, font[0] + "-" + font[1] + "-" + font[2] + "-r-" + font[4] + "-" + tail);
- nativeFontList.put(name + size + bold + "i", font[0] + "-" + font[1] + "-" + font[2] + "-i-" + font[4] + "-" + tail);
-
- } else {
- nativeFontList.put(name + size + bold + slant, s2);
-
- }
- } catch (ArrayIndexOutOfBoundsException e) {
- if (Log.on) Log.log(this, "skipping incomplete font string " + s2);
- continue;
- }
- }
- fontList = new String[nativeFontList.size()];
- Enumeration e = nativeFontList.keys();
- for(int i=0; e.hasMoreElements(); i++) fontList[i] = (String)e.nextElement();
- }
-
- /** so we can put XFontStruct's into Hashtables */
- private static class WrappedRawData {
- public RawData wrapee = null;
- public WrappedRawData(RawData r) { wrapee = r; }
- }
-
- /** translates an X11 font string into an XFontStruct* */
- public static native gnu.gcj.RawData fontStringToStruct(String s);
-
- /** translates an XWT font string into an XFontStruct*, performing caching as well */
- public static RawData fontToXFont(String s) {
- if (s == null) s = "sansserif";
- s = s.toLowerCase();
-
- WrappedRawData wrap = (WrappedRawData)xwtFontToFontStruct.get(s);
- if (wrap != null) return wrap.wrapee;
-
- String bestmatch = "";
- int metric = -1 * Integer.MAX_VALUE;
- ParsedFont arg = new ParsedFont(s);
- ParsedFont pf = new ParsedFont();
-
- if (arg.size == -1) arg.size = 10;
- Enumeration e = nativeFontList.keys();
- while(e.hasMoreElements()) {
- String jfont = (String)e.nextElement();
- pf.parse(jfont);
- int thismetric = 0;
- if (!pf.name.equals(arg.name)) {
- if (pf.name.equals("lucidabright") && arg.name.equals("serif")) thismetric -= 1000;
- else if (pf.name.equals("times") && arg.name.equals("serif")) thismetric -= 2000;
- else if (pf.name.equals("helvetica") && arg.name.equals("sansserif")) thismetric -= 1000;
- else if (pf.name.equals("courier") && arg.name.equals("monospaced")) thismetric -= 1000;
- else if (pf.name.equals("lucida") && arg.name.equals("dialog")) thismetric -= 1000;
- else if (pf.name.equals("helvetica") && arg.name.equals("dialog")) thismetric -= 2000;
- else if (pf.name.equals("fixed") && arg.name.equals("tty")) thismetric -= 1000;
- else if (pf.name.equals("sansserif")) thismetric -= 4000;
- else thismetric -= 4004;
- }
- if (pf.size != 0) thismetric -= Math.abs(pf.size - arg.size) * 4;
- if (pf.bold != arg.bold) thismetric -= 1;
- if (pf.italic != arg.italic) thismetric -= 1;
- if (thismetric > metric) {
- metric = thismetric;
- bestmatch = jfont;
+ // FIXME: try to use os acceleration
+ public void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int argb) {
+ if (x1 == x3 && x2 == x4) {
+ fillRect(x1, y1, x4, y2, argb);
+ } else for(int y=y1; y<y2; y++) {
+ int _x1 = (int)Math.floor((y - y1) * (x3 - x1) / (y2 - y1) + x1);
+ int _y1 = (int)Math.floor(y);
+ int _x2 = (int)Math.ceil((y - y1) * (x4 - x2) / (y2 - y1) + x2);
+ int _y2 = (int)Math.floor(y) + 1;
+ if (_x1 > _x2) { int _x0 = _x1; _x1 = _x2; _x2 = _x0; }
+ fillRect(_x1, _y1, _x2, _y2, argb);