- /** DoubleBuffer mode */
- public X11DoubleBuffer(int w, int h) { this(w, h, true); }
- public X11DoubleBuffer(int w, int h, boolean shared_pixmap) {
- width = clipw = w;
- height = cliph = h;
- clipx = clipy = 0;
- this.shared_pixmap = shared_pixmap;
- natInit();
- }
-
- public void setClip(int x, int y, int x2, int y2) {
- clipx = x; if (clipx < 0) clipx = 0;
- clipy = y; if (clipy < 0) clipy = 0;
- clipw = x2 - x; if (clipw < 0) clipw = 0;
- cliph = y2 - y; if (cliph < 0) cliph = 0;
- }
-
- public void drawPicture(Picture source, int x, int y) {
- drawPicture(source, x, y, x + source.getWidth(), y + source.getHeight(), 0, 0, source.getWidth(), source.getHeight());
- }
-
- public void drawPicture(Picture source, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2) {
- if (!(dx2 - dx1 != sx2 - sx1 || dy2 - dy1 != sy2 - sy1) && ((X11Picture)source).doublebuf != null)
- fastDrawPicture(source, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2);
- else
- slowDrawPicture(source, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2);
- }
-
- /** fast path for image drawing (no scaling, all-or-nothing alpha) */
- public native void fastDrawPicture(Picture source, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2);
-
- /** slow path for image drawing */
- public native void slowDrawPicture(Picture source, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2);
-
- public int getWidth() { return width; }
- public int getHeight() { return height; }
- public native void natInit();
- public native void fillRect(int x, int y, int x2, int y2, int color);
- public native void drawString(String font, String text, int x, int y, int color);
- public native void finalize();
-
- }
-
-
- // 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();
- for(int k=0; k<fonts.length; k++) {
- String s = fonts[k].toLowerCase();
- StringTokenizer st = new StringTokenizer(s, "-", false);
- String[] font = new String[st.countTokens()];
-
- try {
- for(int i=0; st.hasMoreTokens(); i++) font[i] = st.nextToken();
- String name = font[1];
- String size = font[6];
- String slant = font[3].equals("i") ? "i" : "";
- String bold = font[2].equals("bold") ? "b" : "";
- String tail = s.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, s);
-
- }
- } catch (ArrayIndexOutOfBoundsException e) {
- if (Log.on) Log.log(this, "skipping incomplete font string " + s);
- 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);