// FIXME: unframed windows should appear in the window menu
// This probably needs a hack similar to whats in Cocoa.mm
WindowAttributes attr = kWindowStandardHandlerAttribute|
- (framed ? kWindowInWindowMenuAttribute|kWindowStandardDocumentAttributes|kWindowLiveResizeAttribute : 0);
+ (framed ? kWindowInWindowMenuAttribute|kWindowStandardDocumentAttributes|kWindowLiveResizeAttribute : 0);
OSStatus r;
rect.top = 0; rect.left = 0; rect.bottom = 300; rect.right=300;
EventHandlerUPP upp = WC(NewEventHandlerUPP)(our_windowEventHandler);
WindowDefSpec myCustomWindowSpec;
myCustomWindowSpec.defType = kWindowDefObjectClass;
myCustomWindowSpec.u.classRef = customWindow;
+
r = WC(CreateCustomWindow) (&myCustomWindowSpec,
- kDocumentWindowClass,
- kWindowStandardHandlerAttribute | kWindowStandardDocumentAttributes,
- &rect,
- &window);
+ kDocumentWindowClass,
+ kWindowStandardHandlerAttribute | kWindowStandardDocumentAttributes,
+ &rect,
+ &window);
+ //r = CreateNewWindow(kDocumentWindowClass, attr, &rect, &window);
Darwin$CarbonSurface* me = this;
WC(SetWindowProperty) (window, 'XWT!', 'XWT!', sizeof(me), &me);
checkStatus(r,"WC(CreateNewWindow)");
void Darwin$CarbonSurface::natSetIcon(org::xwt::Picture *_p) {
}
-void Darwin$CarbonSurface::natSetLocation(jint x, jint y) {
+void Darwin$CarbonSurface::natSetLocation() {
WindowRef window = (WindowRef) rawWindowRef;
Rect rect;
+ jint x = root->x;
+ jint y = root->y;
OSStatus r = WC(GetWindowBounds)(window,kWindowStructureRgn,&rect);
checkStatus(r,"WC(GetWindowBounds)");
rect.bottom = y + (rect.bottom - rect.top);
WC(CFRelease)(url);
}
-void Darwin::_exit() {
- WC(QuitApplicationEventLoop)();
-}
-
void Darwin::natInit() {
OSStatus r;
#ifdef XWT_CARBON_NO_BUNDLE_HACK
#endif
}
-void Darwin::_running() {
+void Darwin::runApplicationEventLoop() {
WC(RunApplicationEventLoop)();
WC(ExitToShell)();
}
private CarbonOpenGL openGL;
boolean jaguar; // true if we are on OS X >= 10.2
- // TEMPORARY HACKS (remove these when we ditch platform fonts)
- protected int _stringWidth(String font, String text) { return (int)Math.round(6.5 * text.length()); }
- protected int _getMaxAscent(String font) { return 10; }
- protected int _getMaxDescent(String font) { return 2; }
-
// General Methods
protected String _getAltKeyName() { return "Option"; }
protected boolean _needsAutoClick() { return false; }
protected native void _newBrowserWindow(String url);
protected native HTTP.Proxy natDetectProxy();
private native void natInit();
- protected native void _exit();
private native String natGetClipBoard();
private native void natSetClipBoard(String text);
}
- // Called by main thread after initialization, this is the event handler
- protected native void _running();
-
static void abort(String err) {
throw new Error(err);
}
private static native final boolean isJaguar();
+ // Called by main thread after initialization, this is the event handler
+ protected native void runApplicationEventLoop();
+
public void init() {
super.init();
jaguar = isJaguar();
throw new Error("No OpenGL support");
}
natInit();
+ new Thread() {
+ public void run() {
+ runApplicationEventLoop();
+ }
+ }.start();
}
private final class CarbonOpenGL extends OpenGL {
protected native void activateSharedContext();
}
- static abstract class CarbonSurface extends Surface {
+ static abstract class CarbonSurface extends Surface.DoubleBufferedSurface {
RawData rawWindowRef;
RawData rawEventHandlerUPP;
int modifiers;
public void setTitleBarText(final String s) { CarbonMessage.add(new CarbonMessage() { public void perform() { natSetTitleBarText(s); } }); }
private native void natSetSize(int w, int h);
public void setSize(final int w, final int h) { CarbonMessage.add(new CarbonMessage() { public void perform() { natSetSize(w,h); } }); }
- private native void natSetLocation(int x, int y);
- public void setLocation(final int x, final int y) { CarbonMessage.add(new CarbonMessage() { public void perform() { natSetLocation(x,y); } }); }
+ private native void natSetLocation();
+ public void setLocation() { CarbonMessage.add(new CarbonMessage() { public void perform() { natSetLocation(); } }); }
private native void natToFront();
public void toFront() { CarbonMessage.add(new CarbonMessage() { public void perform() { natToFront(); } }); }
private native void natToBack();
#include <setjmp.h>
#include "jpeglib.h"
}
+#include <org/xwt/Platform.h>
+#include <org/xwt/Picture.h>
#include <org/xwt/plat/GCJ.h>
#include <java/io/InputStream.h>
#include <java/io/ByteArrayInputStream.h>
}
}
-void org::xwt::plat::GCJ$JPEG::nativeDecompress() {
+org::xwt::Picture* org::xwt::plat::GCJ$JPEG::_decodeJPEG(java::io::InputStream* is, jstring name) {
struct jpeg_decompress_struct cinfo;
+ jIntArray data;
+ jint width;
+ jint height;
// set up our error handler
struct jpeg_error_mgr error_handler;
throw t;
}
jpeg_destroy_decompress(&cinfo);
+ return org::xwt::Platform::createPicture(data, width, height);
}
// C++ new/delete operators (JvMalloc never fails)
protected native InputStream _getBuiltinInputStream();
// FIXME
- protected ImageDecoder _decodeJPEG(InputStream is, String name) {
- try {
- return new JPEG(is);
- } catch (Exception e) {
- Log.log(this, "Exception while decoding JPEG image " + name);
- Log.log(this, e);
- return null;
- }
- }
+ protected native Picture _decodeJPEG(InputStream is, String name);
- /** Converts an InputStream carrying a JPEG image into an ARGB int[] */
- private static class JPEG extends ImageDecoder {
- int[] data;
- byte[] buffer;
- int width, height;
- InputStream is;
-
- public final int[] getData() { return data; }
- public final int getWidth() { return width; }
- public final int getHeight() { return height; }
- private JPEG(InputStream is) { this.is = is; nativeDecompress(); buffer = null; }
- private native void nativeDecompress();
- }
-
// FIXME: This could be optimized (a lot) by using a custom hashtable
public final static class Retainer {
private static Hash table = new Hash();
public void deleteTexture(final int tex) {
// CHECKME: Is this safe to do from finalize()?
// natDeleteTexture MUST be run from the message queue thread
- MessageQueue.add(new Message() { public void perform() {
+ Message.Q.add(new Message() { public void perform() {
natDeleteTexture(tex);
}});
}
#include <org/xwt/Picture.h>
#include <org/xwt/ByteStream.h>
#include <org/xwt/Platform.h>
-#include <org/xwt/Platform$ParsedFont.h>
#include <org/xwt/plat/Win32.h>
-#include <org/xwt/plat/Win32$Win32Font.h>
#include <org/xwt/plat/Win32$Win32Surface.h>
#include <org/xwt/plat/Win32$Win32PixelBuffer.h>
#include <org/xwt/plat/Win32$Win32Picture.h>
}
}
-// This function iterates over each family (lparam == 0), and then over each size (lparam == 1)
-int CALLBACK fontproc(const LOGFONTA* enumlogfont, const TEXTMETRICA* tm, long unsigned int type, LPARAM lparam) {
-
- if (lparam == 0) {
- LOGFONT lf;
- lf.lfCharSet = ANSI_CHARSET;
- strncpy(lf.lfFaceName, enumlogfont->lfFaceName, 32);
- lf.lfPitchAndFamily = 0;
- EnumFontFamiliesEx((HDC)org::xwt::plat::Win32::desktop_dc, &lf, fontproc, 1, 0);
-
- } else {
- org::xwt::plat::Win32::addFont(JvNewStringLatin1(enumlogfont->lfFaceName),
- ((type & RASTER_FONTTYPE) == 0) ? 0 : tm->tmHeight,
- tm->tmItalic == 0 ? 0 : 1,
- tm->tmWeight <= 400 ? 0 : 1);
- }
- return 1;
-}
-
// Initialization ////////////////////////////////////////////////////////////////////
org::xwt::plat::Win32::sizewe_cursor = (jint)LoadCursor(NULL, IDC_SIZEWE);
org::xwt::plat::Win32::hand_cursor = (jint)CreateCursor(GetModuleHandle(NULL), 14, 1, 32, 32, hand_cursor_and, hand_cursor_xor);
- // enumerate fonts
- LOGFONT lf;
- lf.lfCharSet = ANSI_CHARSET;
- lf.lfFaceName[0] = 0;
- lf.lfPitchAndFamily = 0;
- EnumFontFamiliesEx((HDC)desktop_dc, &lf, fontproc, 0, 0);
-
messagePumpThread = (jint)GetCurrentThreadId();
messagePumpStarted->release();
return rect.bottom - rect.top;
}
-org::xwt::plat::Win32$Win32Font* org::xwt::plat::Win32::mapFont(org::xwt::Platform$ParsedFont* pf) {
- org::xwt::plat::Win32$Win32Font* ret = new org::xwt::plat::Win32$Win32Font();
- LOGFONT logfont;
- memset(&logfont, 0, sizeof(LOGFONT));
- logfont.lfHeight = -MulDiv(pf->size, GetDeviceCaps((HDC)org::xwt::plat::Win32::desktop_dc, LOGPIXELSY), 72);
- if (pf->italic) logfont.lfItalic = 1;
- if (pf->bold) logfont.lfWeight = FW_BOLD;
- logfont.lfCharSet = ANSI_CHARSET;
-
- JvGetStringUTFRegion(pf->name, 0, min(31, JvGetStringUTFLength(pf->name)), logfont.lfFaceName);
- logfont.lfFaceName[min(31, JvGetStringUTFLength(pf->name))] = 0;
-
- ret->hfont = (jint)CreateFontIndirect(&logfont);
- SelectObject((HDC)desktop_dc, (HFONT)(ret->hfont));
-
- TEXTMETRIC tm;
- GetTextMetrics((HDC)desktop_dc, &tm);
- POINT p;
- p.x = 0; p.y = tm.tmAscent;
- LPtoDP((HDC)desktop_dc, &p, 1);
- ret->maxAscent = p.y;
-
- p.x = 0; p.y = tm.tmDescent;
- LPtoDP((HDC)desktop_dc, &p, 1);
- ret->maxDescent = p.y;
-
- return ret;
-}
-
-jint org::xwt::plat::Win32::_stringWidth(jstring font, jstring text) {
-
- HFONT hfont = (HFONT)(getFont(font)->hfont);
- SelectObject((HDC)org::xwt::plat::Win32::desktop_dc, hfont);
-
- int len = min(1024, JvGetStringUTFLength(text));
- char buf[len + 1];
- buf[len] = '\0';
- JvGetStringUTFRegion(text, 0, len, buf);
-
- SIZE size;
- GetTextExtentPoint32((HDC)org::xwt::plat::Win32::desktop_dc, buf, len, &size);
- return size.cx;
-}
-
jboolean org::xwt::plat::Win32::_newBrowserWindow_(jstring url) {
int len = min(2048, JvGetStringUTFLength(url));
}
-void org::xwt::plat::Win32$Win32PixelBuffer::drawString(jstring font, jstring text, jint x, jint y, jint color) {
-
- org::xwt::plat::Win32$Win32Font* wf = org::xwt::plat::Win32::getFont(font);
- SelectObject((HDC)hdc, (HFONT)(wf->hfont));
-
- // Platform API passes us the y-pos of the bottom of the text; we need the top
- y -= wf->maxAscent;
-
- int len = min(1024, JvGetStringUTFLength(text));
- char buf[len + 1];
- buf[len] = '\0';
- JvGetStringUTFRegion(text, 0, len, buf);
-
- SetTextColor((HDC)hdc, PALETTERGB((color & 0xFF0000) >> 16, (color & 0xFF00) >> 8, color & 0xFF));
- TextOut((HDC)hdc, x, y, buf, len);
-}
-
void org::xwt::plat::Win32$Win32PixelBuffer::fillRect(jint x, jint y, jint x2, jint y2, jint color) {
jint w = x2 - x;
jint h = y2 - y;
void org::xwt::plat::Win32$Win32Surface::_setMaximized(jboolean m) { ShowWindow((HWND)hwnd, m ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL); }
void org::xwt::plat::Win32$Win32Surface::postCursorChange() { PostMessage((HWND)hwnd, WM_USER_SETCURSOR, 0, 0); }
-void org::xwt::plat::Win32$Win32Surface::setLocation(jint x, jint y) {
+void org::xwt::plat::Win32$Win32Surface::setLocation() {
POINT point;
RECT rect;
point.x = 0;
point.y = 0;
ClientToScreen((HWND)hwnd, &point);
GetWindowRect((HWND)hwnd, &rect);
- SetWindowPos((HWND)hwnd, NULL, x - (point.x - rect.left), y - (point.y - rect.top), 0, 0, SWP_NOZORDER | SWP_NOSIZE);
+ SetWindowPos((HWND)hwnd, NULL, root->x - (point.x - rect.left), root->y - (point.y - rect.top), 0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
void org::xwt::plat::Win32$Win32Surface::setSize(jint w, jint h) {
switch(iMsg) {
case WM_DEVMODECHANGE: break; // FEATURE: color depth changed
case WM_DISPLAYCHANGE: break; // FEATURE: screen size changed
- case WM_FONTCHANGE: break; // FEATURE: set of fonts changed
case WM_MOUSEWHEEL: break; // FEATURE: Mouse Wheel
case WM_SYSKEYDOWN: if (GetKeyState(VK_MENU) >> (sizeof(SHORT) * 8 - 1) == 0) return 0;
new Thread() { public void run() { natInit(); } }.start();
messagePumpStarted.block();
- fontList = new String[fontListVec.size()];
- fontListVec.toArray(fontList);
- fontListVec = null;
- }
-
-
- // Font Handling ////////////////////////////////////////////////////////////////////////////
-
- // FEATURE: query the registry for the user's default font
- protected String _getDefaultFont() { return "dialog8"; }
- protected int _getMaxAscent(String font) { return getFont(font).maxAscent; }
- protected int _getMaxDescent(String font) { return getFont(font).maxDescent; }
- protected native int _stringWidth(String font, String text);
-
- // methods/members used to enumerate platform fonts on startup
- public static Vector fontListVec = new Vector();
- public static String[] fontList = null;
- protected String[] _listFonts() { return fontList; }
- public static void addFont(String name, int height, boolean italic, boolean bold) {
- fontListVec.addElement(name.replace(' ', '_').toLowerCase() + "" + height + (italic ? "i" : "") + (bold ? "b" : ""));
- }
-
- static Hash fontCache = new Hash();
- public static class Win32Font {
- int hfont;
- int maxAscent;
- int maxDescent;
- }
-
- /** Called once XWT is initialized and the application is running. On Win32, we need to block the main thread
- * on a semaphore because if the main thread exits, the whole application quits. */
- protected void _running() {
- // gcj-win32 exit()'s when the original thread dies, so we have to deadlock ourselves
- if (Log.on) Log.log(Main.class, "main thread blocking on new semaphore");
- new org.xwt.util.Semaphore().block();
- }
-
- /** takes a parsed font and finds the closest platform-specific font */
- static native Win32Font mapFont(Platform.ParsedFont pf);
-
- /** takes an unparsed font and finds the closest platform-specific font */
- static Win32Font getFont(String font) {
- Win32Font ret = (Win32Font)fontCache.get(font);
- if (ret != null) return ret;
-
- Platform.ParsedFont pf = new Platform.ParsedFont(font);
- if (pf.name.equals("serif")) pf.name = "Times New Roman";
- else if (pf.name.equals("sansserif")) pf.name = "Arial";
- else if (pf.name.equals("monospace")) pf.name = "Courier New";
- else if (pf.name.equals("dialog")) pf.name = "MS Sans Serif";
- else if (pf.name.equals("tty")) pf.name = "FixedSys";
-
- ret = mapFont(pf);
- fontCache.put(font, ret);
- return ret;
}
// Win32Surface ////////////////////////////////////////////////////////////////////////////
- public static class Win32Surface extends Surface {
+ public static class Win32Surface extends Surface.DoubleBufferedSurface {
/** used to block while waiting for the message pump thread to create a hwnd for us */
public Semaphore hwndCreated = new Semaphore();
public native void setInvisible(boolean i);
public native void _setMaximized(boolean m);
public native void setSize(int w, int h);
- public native void setLocation(int x, int y);
+ public native void setLocation();
public native void setTitleBarText(String s);
public native void setIcon(Picture p);
public native void _dispose();
public native void setClip(int x, int y, int x2, int y2);
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 drawPicture(Picture source, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2);
public native void finalize();
public void drawPicture(Picture source, int x, int y) {
XFlush(display);
}
-void org::xwt::plat::X11$X11Surface::setLocation (jint x, jint y) { XMoveWindow(display, (*((Window*)window)), x, y); }
+void org::xwt::plat::X11$X11Surface::setLocation () { XMoveWindow(display, (*((Window*)window)), root->x, root->y); }
void org::xwt::plat::X11$X11Surface::toFront() { XRaiseWindow(display, (*((Window*)window))); }
void org::xwt::plat::X11$X11Surface::toBack() { XLowerWindow(display, (*((Window*)window))); }
// General Methods ///////////////////////////////////////////////////////
protected String _getAltKeyName() { return System.getProperty("os.name", "").indexOf("SunOS") != -1 ? "Meta" : "Alt"; }
- protected String[] _listFonts() { return fontList; }
protected Picture _createPicture(int[] data, int w, int h) { return new X11Picture(data, w, h); }
protected PixelBuffer _createPixelBuffer(int w, int h, Surface owner) { return new X11PixelBuffer(w, h); }
protected native int _getScreenHeight();
protected native String _getClipBoard();
protected native void _setClipBoard(String s);
- protected native int _stringWidth(String font, String text);
- protected native int _getMaxAscent(String font);
- protected native int _getMaxDescent(String font);
protected boolean _needsAutoDoubleClick() { return true; }
protected native void eventThread();
private native void natInit();
public void init() {
natInit();
(new Thread() { public void run() { eventThread(); } }).start();
- initFonts();
}
// X11Surface /////////////////////////////////////////////////////
/** Implements a Surface as an X11 Window */
- public static class X11Surface extends Surface {
+ public static class X11Surface extends Surface.DoubleBufferedSurface {
gnu.gcj.RawData window;
gnu.gcj.RawData gc;
public native void _setMinimized(boolean b);
public native void setTitleBarText(String s);
public native void setSize(int w, int h);
- public native void setLocation(int x, int y);
+ public native void setLocation();
public native void natInit();
public native void toFront();
public native void toBack();
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();
-
- 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;
- }
- }
-
- pf.parse(bestmatch);
- String target = (String)nativeFontList.get(bestmatch);
- if (pf.size == 0) {
- int i = 0;
- for(int j=0; j<6; j++) i = target.indexOf('-', i + 1);
- target = target.substring(0, i + 1) + arg.size + target.substring(target.indexOf('-', i+1));
- }
- if (Log.on) Log.log(X11.class, "mapping font \"" + s + "\" to \"" + target + "\"");
- RawData ret = fontStringToStruct(target);
- if (ret == null) ret = fontStringToStruct("fixed");
- xwtFontToFontStruct.put(s, new WrappedRawData(ret));
- return ret;
- }
-
}
InputStream bis = Platform.getBuiltinInputStream();
ZipInputStream zis = new ZipInputStream(bis);
- for(ZipEntry ze = zis.getNextEntry(); ze != null && !ze.getName().equals("freetype.mips"); ze = zis.getNextEntry());
- byte[] image = Resources.isToByteArray(zis);
+ for(ZipEntry ze = zis.getNextEntry(); ze != null && !ze.getName().equals("freetype.mips"); ze = zis.getNextEntry()) { }
+ byte[] image = InputStreamToByteArray.convert(zis);
vm = new org.xwt.mips.Interpreter(image);
vm.start(new String[]{ "freetype.mips" });
vm.execute();
int FONT_RESERVED = 256*1024;
int baseAddr = vm.sbrk(FONT_RESERVED);
- byte[] fontstream = Resources.isToByteArray(res.getInputStream());
+ byte[] fontstream = InputStreamToByteArray.convert(res.getInputStream());
vm.copyout(fontstream, baseAddr, fontstream.length);
vm.setUserInfo(0, baseAddr);
vm.setUserInfo(1, fontstream.length);
glyph.advance = vm.getUserInfo(11);
glyph.c = (char)g;
- gid.width = vm.getUserInfo(6);
- gid.height = vm.getUserInfo(7);
- if (gid.data == null || gid.data.length < gid.width * gid.height)
- gid.data = new int[gid.width * gid.height];
+ int width = vm.getUserInfo(6);
+ int height = vm.getUserInfo(7);
+ int[] data = new int[width * height];
int addr = vm.getUserInfo(5);
- for(int i=0; i<gid.width * gid.height; i += 4) {
+ for(int i=0; i<width * height; i += 4) {
int val = vm.memRead(addr + i);
for (int k = 3; k >= 0; k--) {
- if (i + k < gid.width * gid.height)
- gid.data[i + k] = (val & 0xff) << 24;
+ if (i + k < width * height)
+ data[i + k] = (val & 0xff) << 24;
val >>>= 8;
}
}
- glyph.p = Platform.createPicture(gid);
+ glyph.p = Platform.createPicture(data, width, height);
glyphCache.put(res, new Integer((g << 16) | pointsize), glyph);
}
} catch (Exception e) {
Log.log(Font.class, e);
}
}
-
- private static GlyphImageDecoder gid = new GlyphImageDecoder();
- private static class GlyphImageDecoder extends ImageDecoder {
- int[] data = null;
- int width, height;
- public int getWidth() { return width; }
- public int getHeight() { return height; }
- public int[] getData() { return data; }
- }
}
import java.io.PrintWriter;
/** Converts an InputStream carrying a GIF image into an ARGB int[] */
-public class GIF extends ImageDecoder {
+public class GIF {
// Public Methods /////////////////////////////////////////////////////////
+ public GIF() { }
+
public int[] getData() { return data; }
public int getWidth() { return width; }
public int getHeight() { return height; }
/** Processes an image from InputStream is; returns null if there is an error
@param name A string describing the image; used for error reporting.
*/
- public static GIF decode(InputStream is, String name) {
+ public Picture fromInputStream(InputStream is, String name) {
try {
- return new GIF(is, name);
+ if (is instanceof BufferedInputStream) _in = (BufferedInputStream)is;
+ else _in = new BufferedInputStream(is);
+ decodeAsBufferedImage(0);
+ return Platform.createPicture(data, width, height);
} catch (Exception e) {
if (Log.on) Log.log(GIF.class, e);
return null;
}
}
- private GIF(InputStream is, String name) throws IOException {
- if (is instanceof BufferedInputStream) _in = (BufferedInputStream)is;
- else _in = new BufferedInputStream(is);
- decodeAsBufferedImage(0);
- }
// Private Methods /////////////////////////////////////////////////////////
import java.util.zip.*;
/** Converts an InputStream carrying a PNG image into an ARGB int[] */
-public class PNG extends ImageDecoder {
+public class PNG {
+ public PNG() { }
+
// Public Methods ///////////////////////////////////////////////////////////////////////////////
- /** returns the ARGB int[] representing the last image processed */
- public final int[] getData() { return data; }
-
- /** returns the width of the last image processed */
- public final int getWidth() { return width; }
-
- /** returns the height of the last image processed */
- public final int getHeight() { return height; }
-
/** process a PNG as an inputstream; returns null if there is an error
@param name A string describing the image, to be used when logging errors
*/
- public static PNG decode(InputStream is, String name) {
- try {
- return new PNG(is, name);
- } catch (Exception e) {
- if (Log.on) Log.log(PNG.class, e);
- return null;
- }
- }
-
- private PNG(InputStream is, String name) throws IOException {
+ public Picture fromInputStream(InputStream is, String name) throws IOException {
underlyingStream = is;
target_offset = 0;
inputStream = new DataInputStream(underlyingStream);
Log.log(this, "PNG: error: input file " + name + " is not a PNG file");
data = new int[] { };
width = height = 0;
- return;
+ return null;
}
DONE: while (!error) {
int crc = inputStream.readInt();
needChunkInfo = true;
}
+
+ return Platform.createPicture(data, width, height);
}
// Chunk Handlers ///////////////////////////////////////////////////////////////////////
--- /dev/null
+package org.xwt.util;
+import java.io.*;
+
+public class InputStreamToByteArray {
+
+ /** scratch space for isToByteArray() */
+ private static byte[] workspace = new byte[16 * 1024];
+
+ /** Trivial method to completely read an InputStream */
+ public static synchronized byte[] convert(InputStream is) throws IOException {
+ int pos = 0;
+ while (true) {
+ int numread = is.read(workspace, pos, workspace.length - pos);
+ if (numread == -1) break;
+ else if (pos + numread < workspace.length) pos += numread;
+ else {
+ pos += numread;
+ byte[] temp = new byte[workspace.length * 2];
+ System.arraycopy(workspace, 0, temp, 0, workspace.length);
+ workspace = temp;
+ }
+ }
+ byte[] ret = new byte[pos];
+ System.arraycopy(workspace, 0, ret, 0, pos);
+ return ret;
+ }
+
+}
public Vec() { this(10); }
public Vec(int i) { store = new Object[i]; }
+ public Vec(int i, Object[] store) { size = i; this.store = store; }
private void grow() { grow(store.length * 2); }
private void grow(int newsize) {