* position.
*
* A note on coordinates: the Box class represents regions
- * internally as x,y,w,h tuples, even though the DoubleBuffer class
+ * internally as x,y,w,h tuples, even though the PixelBuffer class
* uses x1,y1,x2,y2 tuples.
*/
public final class Box extends JS.Scope {
private LENGTH hpad = 0;
private LENGTH vpad = 0;
private String text = null;
- private String font = null;
+ private Res font = null;
+ private int fontsize = 10;
private LENGTH textwidth = 0;
private LENGTH textheight = 0;
// Rendering Pipeline /////////////////////////////////////////////////////////////////////
/** Renders self and children within the specified region. All rendering operations are clipped to xIn,yIn,wIn,hIn */
- void render(int parentx, int parenty, int clipx, int clipy, int clipw, int cliph, DoubleBuffer buf) {
+ void render(int parentx, int parenty, int clipx, int clipy, int clipw, int cliph, PixelBuffer buf) {
if (Surface.abort || (flags & INVISIBLE_FLAG) != 0) return;
int globalx = parentx + (parent == null ? 0 : x);
int globaly = parenty + (parent == null ? 0 : y);
else renderStretchedImage(globalx, globaly, clipx, clipy, clipw, cliph, buf);
if (text != null && !text.equals(""))
- renderText(x, y, clipx, clipy, clipw, cliph, buf);
+ renderText(globalx, globaly, clipx, clipy, clipw, cliph, buf);
// now subtract the pad region from the clip region before proceeding
clipw = min(max(clipx, globalx + hpad) + clipw, globalx + width - hpad) - clipx;
b.render(globalx, globaly, clipx, clipy, clipw, cliph, buf);
}
- void renderStretchedImage(int globalx, int globaly, int clipx, int clipy, int clipw, int cliph, DoubleBuffer buf) {
+ void renderStretchedImage(int globalx, int globaly, int clipx, int clipy, int clipw, int cliph, PixelBuffer buf) {
//buf.setClip(x, y, w + x, h + y);
System.out.println("draw " + clipx + " " + clipy + " " + (clipx + clipw) + " " + (clipy + cliph));
buf.drawPicture(image,
//buf.setClip(0, 0, buf.getWidth(), buf.getHeight());
}
- void renderTiledImage(int globalx, int globaly, int x, int y, int w, int h, DoubleBuffer buf) {
+ void renderTiledImage(int globalx, int globaly, int x, int y, int w, int h, PixelBuffer buf) {
int iw = image.getWidth();
int ih = image.getHeight();
for(int i=(x - x)/iw; i <= (x + w - x)/iw; i++) {
}
}
- void renderText(int x, int y, int clipx, int clipy, int clipw, int cliph, DoubleBuffer buf) {
- /*
- // hack because (believe it or not) libgcj doesn't support UTF16.
- byte[] b = new byte[text.length() * 2 + 2];
- for(int i=0; i<text.length(); i++) {
- b[i * 2] = (byte)((((short)text.charAt(i)) & 0xff00) >> 8);
- b[i * 2 + 1] = (byte)(((short)text.charAt(i)) & 0xff);
- }
- b[text.length()] = 0;
- b[text.length() + 1] = 0;
- */
- /*
- try {
- ImageDecoder id = org.xwt.translators.Font.render(new FileInputStream("COMIC.TTF"), 24, text, false);
- Picture p = Platform.createPicture(id);
- // FIXME: clipping (don't use setClip)
- buf.drawPicture(p,
- x + hpad, y + vpad,
- x + hpad + p.getWidth(), y + vpad + p.getHeight(),
+ void renderText(int x, int y, int clipx, int clipy, int clipw, int cliph, PixelBuffer buf) {
+ for(int i=0; i<text.length(); i++) {
+ // FIXME: clipping
+ char c = text.charAt(i);
+ Glyph g = Glyph.getGlyph(font, fontsize, c);
+ System.out.println("rendering glyph for " + c + " as " + g + " @ " + (x+hpad) + ", " + (y+vpad));
+ buf.drawPicture(g.p,
+ x + hpad,
+ y + vpad + g.max_ascent - g.baseline,
+ x + hpad + g.p.getWidth(),
+ y + vpad + g.max_ascent - g.baseline + g.p.getHeight(),
0, 0,
- p.getWidth(), p.getHeight());
- } catch (Exception e) {
- Log.log(this, e);
- }
- */
+ g.p.getWidth(), g.p.getHeight());
+ x += g.advance;
+ }
}
} else if ("apply".equals(method)) {
if (checkOnly) return Boolean.TRUE;
if (args.elementAt(0) instanceof Res) {
+ try {
Res res = (Res)args.elementAt(0);
- res = res.addExtension(".xwt");
- Template t = Template.buildTemplate(res, "fromResource");
+ // res = res.addExtension(".xwt");
+ Template t = Template.buildTemplate(res.getInputStream(), "fromResource");
if (ThreadMessage.suspendThread()) try {
JS.Callable callback = args.length() < 2 ? null : (Callable)args.elementAt(1);
t.apply(this, null, null, callback, 0, t.numUnits());
} finally {
ThreadMessage.resumeThread();
}
+ } catch (IOException e) {
+ Log.log(this, e);
+ }
} else if (args.elementAt(0) instanceof String) {
String templatename = (String)args.elementAt(0);
Template t = Template.getTemplate(templatename, null);
Log.log(this, "invalid color " + s);
return;
}
- else if (SVG.colors.get(s) != null)
- newcolor = 0xFF000000 | ((Integer)SVG.colors.get(s)).intValue();
+ else if (org.xwt.translators.SVG.colors.get(s) != null)
+ newcolor = 0xFF000000 | ((Integer)org.xwt.translators.SVG.colors.get(s)).intValue();
if (newcolor == b.fillcolor) return;
b.fillcolor = newcolor;
b.dirty();
b.textwidth = b.textheight = 0;
} else {
try {
- ImageDecoder id = org.xwt.translators.Font.render(new FileInputStream("COMIC.TTF"), 24, b.text, true);
- if (id.getWidth() != b.textwidth || id.getHeight() != b.textheight) MARK_FOR_REFLOW_b;
- b.textwidth = id.getWidth();
- b.textheight = id.getHeight();
+ MARK_FOR_REFLOW_b;
+ b.textwidth = 0;
+ for(int i=0; i<b.text.length(); i++) {
+ Glyph g = Glyph.getGlyph(b.font, b.fontsize, b.text.charAt(i));
+ b.textwidth += g.advance;
+ b.textheight = g.max_ascent + g.max_descent;
+ }
} catch (Exception e) {
Log.log(this, e);
}
specialBoxProperties.put("font", new SpecialBoxProperty() {
public Object get(Box b) { return b.font; }
public void put(Box b, Object value) {
- b.font = value == null ? null : value.toString();
- // FIXME: translate value into a resource
+ // FIXME: translate value into a resource if it is a string
+ b.font = value == null ? null : (Res)value;
+ MARK_FOR_REFLOW_b;
+ b.flags |= FONT_CHANGED_FLAG;
+ b.dirty();
+ } });
+
+ specialBoxProperties.put("fontsize", new SpecialBoxProperty() {
+ public Object get(Box b) { return b.font; }
+ public void put(Box b, Object value) {
+ if (b.fontsize == stoi(value)) return;
+ b.fontsize = stoi(value);
MARK_FOR_REFLOW_b;
b.flags |= FONT_CHANGED_FLAG;
b.dirty();
// Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
package org.xwt;
import org.xwt.translators.*;
+import org.xwt.util.*;
public class Glyph {
- char c;
- int line_height; // same value for every glyph in font; the max height of all chars
- int baseline; // within the picture, this is the y-coordinate of the baseline
- int advance; // amount to increment the x-coordinate
- Picture p;
+ public char c;
+ public int max_ascent; // same value for every glyph in font; the max ascent of all chars
+ public int max_descent; // same value for every glyph in font; the max descent of all chars
+ public int baseline; // within the picture, this is the y-coordinate of the baseline
+ public int advance; // amount to increment the x-coordinate
+ public Picture p;
// k1=font.res k2=(c << 16 | pointsize)
private static Cache glyphCache = new Cache();
// FEATURE: be smarter here
if (c < 256)
- org.xwt.translators.Font.renderGlyphs(res, pointsize, 0, 255, glyphCache);
+ Font.renderGlyphs(res, pointsize, 0, 255, glyphCache);
else
- org.xwt.translators.Font.renderGlyphs(res, pointsize, (int)c, (int)c, glyphCache);
+ Font.renderGlyphs(res, pointsize, (int)c, (int)c, glyphCache);
ret = (Glyph)glyphCache.get(res, new Integer((((int)c) << 16) | pointsize));
if (ret != null) return ret;
+++ /dev/null
-// Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
-package org.xwt;
-
-import java.util.*;
-import java.net.*;
-import java.io.*;
-import org.xwt.js.*;
-import org.xwt.util.*;
-
-/*
- * While entities are limited to a subset of Unicode characters ,
- * numeric character references can specify any character. Numeric
- * character references may be given in decimal or hexadecimal, though
- * browser support is stronger for decimal references. Decimal
- * references are of the form &#number; while hexadecimal references
- * take the case-insensitive form &#xnumber;. Examples of numeric
- * character references include © or © for the copyright
- * symbol, Α or Α for the Greek capital letter alpha, and
- * ا or ا for the Arabic letter ALEF.
- *
- * http://www.htmlhelp.com/reference/html40/entities/special.html
- * http://www.htmlhelp.com/reference/html40/entities/symbols.html
- * http://www.htmlhelp.com/reference/html40/entities/latin1.html
- */
-
-/**
- * This class parses an InputStream containing HTML and returns it
- * as an XWT DOM tree. Each HTML Element is returned as a struct,
- * with the following members:
- *
- * Since HTML may have multiple top level elements (unlike XML),
- * this class will search all top level elements for one with a tag
- * name 'html'. If such a node is found, only it is returned. If no
- * top-level element has the tag name 'html', such a node is
- * fabricated, and all top level elements become the children of
- * that node, which is then returned.
- */
-public class HTML {
-
- // FIXME: fill in
- private final static String[] bodylessTags = new String[] { "br", "hr", "input", "img", "isindex" };
-
- /** we keep a char[] around for use by removeRedundantWhitespace() */
- private static char[] cbuf = null;
-
- /** we keep a StringBuffer around for use by removeRedundantWhitespace() */
- private static StringBuffer sbuf = null;
-
- /** true iff we have encountered an LI more recently than the last OL/UL */
- private static boolean withinLI = false;
-
- public static synchronized JS parseReader(Reader r) throws IOException {
- CharStream cs = new CharStream(r);
- JS.Obj h = new JS.Obj();
-
- withinLI = false;
- h.put("$name", "html");
-
- try {
- while (true) parseBody(cs, h, null);
- } catch (EOFException e) {
- // continue until we get an EOFException
- }
-
- Object[] ids = h.keys();
- for(int i=0; i<ids.length; i++) {
- Object el = h.get((String)ids[i]);
- if (el instanceof JS && "html".equals(((JS)el).get("$name")))
- return (JS)el;
- }
-
- return h;
- }
-
- /**
- * Parses a single element and stores it in <tt>h</tt>. The
- * CharStream should be positioned immediately <i>after</i> the
- * open bracket.
- *
- * If a close tag not matching this open tag is found, the
- * tagname on the close tag will be returned in order to
- * facilitate correcting broken HTML. Otherwise, this returns
- * null.
- */
- private static String parseElement(CharStream cs, JS h) throws IOException {
- // scan element name
- while(Character.isSpace(cs.peek())) cs.get();
- String elementName = parseElementName(cs);
-
- // FIXME: this might not deal correctly with EOFExceptions
- boolean saveWithinLI = withinLI;
- if (elementName.equals("li")) {
- if (withinLI) {
- cs.unread(new char[] { '<', 'l', 'i', ' ' });
- return "li";
- } else {
- withinLI = true;
- }
- } else if (elementName.equals("ol") || elementName.equals("ul")) {
- withinLI = false;
- }
-
- h.put("$name", elementName);
- if (elementName.equals("!--")) {
- h.put("0", parseComment(cs));
- h.put("$numchildren", new Integer(0));
- return null;
- }
-
- // scan attributes
- while (cs.peek() != '>') {
- String name = parseAttributeName(cs);
- if (name.equals("")) break;
- String value = expandEntities(parseAttributeValue(cs));
- h.put(name, value);
- }
-
- // eat the close-angle bracket
- cs.get();
-
- // bodyless tags return here
- for(int i=0; i<bodylessTags.length; i++)
- if (bodylessTags[i].equals(elementName))
- return null;
-
- // scan body
- String ret = parseBody(cs, h, elementName);
- withinLI = saveWithinLI;
- return ret;
- }
-
- /**
- * Parses the body of an element. The CharStream should be
- * positioned at the character immediately after the right
- * bracket closing the start-tag
- */
- private static String parseBody(CharStream cs, JS h, String elementName) throws IOException {
- String cdata = "";
- int length = h.get("$numchildren") == null ? 0 : Integer.parseInt(h.get("$numchildren").toString());
- while(true) {
- String closetag = null;
-
- try {
- char c = cs.get();
- if (c != '<') { cdata += c; continue; }
- String expanded = removeRedundantWhitespace(expandEntities(cdata));
- if (expanded.length() > 0) {
- h.put(String.valueOf(length), expanded);
- h.put("$numchildren", new Integer(++length));
- }
- cdata = "";
-
- } catch (EOFException e) {
- String expanded = removeRedundantWhitespace(expandEntities(cdata));
- if (expanded.length() > 0) {
- h.put(String.valueOf(length), expanded);
- h.put("$numchildren", new Integer(++length));
- }
- throw e;
- }
-
- try {
- // scan subelement
- if (cs.peek() != '/') {
- JS kid = new JS.Obj();
- closetag = parseElement(cs, kid);
- h.put(String.valueOf(length), kid);
- h.put("$numchildren", new Integer(++length));
-
- // scan close-tag
- } else {
- cs.get(); // drop the slash
- closetag = parseElementName(cs);
- while(cs.get() != '>');
- }
- } catch (EOFException e) {
- throw e;
-
- }
-
- if (closetag != null)
- return closetag.equals(elementName) ? null : closetag;
- }
- }
-
- /** Parses an element name and returns it. The CharStream should
- * be positioned at the first character of the name.
- */
- private static String parseElementName(CharStream cs) throws IOException {
- String ret = "";
- while (cs.peek() != '>' && !Character.isSpace(cs.peek())) ret += cs.get();
- return ret.toLowerCase();
- }
-
- /** Parses an attribute name and returns it. The CharStream should
- * be positioned at the first character of the name, possibly
- * with intervening whitespace.
- */
- private static String parseAttributeName(CharStream cs) throws IOException {
- while(Character.isSpace(cs.peek())) cs.get();
- String ret = "";
- while(!Character.isSpace(cs.peek()) && cs.peek() != '=' && cs.peek() != '>') ret += cs.get();
- return ret.toLowerCase();
- }
-
- /** Parses an attribute value and returns it. The CharStream
- * should be positioned at the equals sign, possibly with
- * intervening whitespace.
- */
- private static String parseAttributeValue(CharStream cs) throws IOException {
-
- // eat whitespace and equals sign
- while(Character.isSpace(cs.peek())) cs.get();
- if (cs.peek() != '=') return "";
- cs.get();
- while(Character.isSpace(cs.peek())) cs.get();
-
- boolean doublequoted = false;
- boolean singlequoted = false;
- String ret = "";
-
- if (cs.peek() == '\"') { doublequoted = true; cs.get(); }
- else if (cs.peek() == '\'') { singlequoted = true; cs.get(); }
-
- while(true) {
- char c = cs.peek();
- if (!doublequoted && !singlequoted && (Character.isSpace(c) || c == '>')) break;
- if (singlequoted && c == '\'') { cs.get(); break; }
- if (doublequoted && c == '\"') { cs.get(); break; }
- ret += cs.get();
- }
- return ret;
- }
-
- /** Parses a comment and returns its body. The CharStream should
- * be positioned immediately after the <!--
- */
- private static String parseComment(CharStream cs) throws IOException {
- int dashes = 0;
- String ret = "";
- while(true) {
- char c = cs.get();
- if (c == '>' && dashes == 2) return ret.substring(0, ret.length() - 2);
- if (c == '-') dashes++;
- else dashes = 0;
- ret += c;
- }
- }
-
- /** Expands all SGML entities in string <tt>s</tt> */
- public static String expandEntities(String s) throws IOException {
- if (s.indexOf('&') == -1) return s;
- StringBuffer sb = new StringBuffer();
- int i=0;
- int nextamp = 0;
- while(nextamp != -1) {
- nextamp = s.indexOf('&', i);
- sb.append(nextamp == -1 ? s.substring(i) : s.substring(i, nextamp));
- if (nextamp == -1) break;
- if (s.regionMatches(nextamp, "&", 0, 5)) {
- sb.append("&");
- i = nextamp + 5;
- } else if (s.regionMatches(nextamp, ">", 0, 4)) {
- sb.append(">");
- i = nextamp + 4;
- } else if (s.regionMatches(nextamp, "<", 0, 4)) {
- sb.append("<");
- i = nextamp + 4;
- } else if (s.regionMatches(nextamp, """, 0, 6)) {
- sb.append("\"");
- i = nextamp + 6;
- } else if (s.regionMatches(nextamp, " ", 0, 6)) {
- // FIXME: should have a way to indicate this...
- sb.append(" ");
- i = nextamp + 6;
- } else {
- sb.append("&");
- i = nextamp + 1;
- }
- }
- return sb.toString();
- }
-
- // FIXME double check this
- /** removes all redundant whitespace */
- private static String removeRedundantWhitespace(String s) {
-
- if (s.indexOf(' ') == -1 && s.indexOf('\n') == -1 && s.indexOf('\t') == -1 && s.indexOf('\r') == -1) return s;
-
- int len = s.length();
- if (cbuf == null || cbuf.length < len) {
- cbuf = new char[len * 2];
- sbuf = new StringBuffer(len * 2);
- }
- sbuf.setLength(0);
- s.getChars(0, len, cbuf, 0);
-
- int last = 0;
- boolean lastWasWhitespace = false;
- for(int i=0; i<len; i++) {
- boolean lastlast = lastWasWhitespace;
- switch(cbuf[i]) {
- case '\n': case '\r': case '\t':
- cbuf[i] = ' ';
- case ' ':
- lastWasWhitespace = true;
- break;
- default:
- lastWasWhitespace = false;
- break;
- }
- if (lastWasWhitespace && lastlast) {
- if (last != i) sbuf.append(cbuf, last, i - last);
- last = i+1;
- }
- }
-
- if (last != len) sbuf.append(cbuf, last, len - last);
- return sbuf.toString().trim();
- }
-
- // CharStream /////////////////////////////////////////////////////////////////////
-
- private static class CharStream extends PushbackReader {
- public CharStream(Reader r) { super(r, 1024); }
-
- public char peek() throws IOException {
- char c = get();
- unread(c);
- return c;
- }
-
- public char get() throws IOException {
- int i = read();
- if (i == -1) throw new EOFException();
- return (char)i;
- }
- }
-
-}
-
return ret;
}
+
+ // Proxy ///////////////////////////////////////////////////////////
+
+ /** encapsulates most of the proxy logic; some is shared in HTTP.java */
+ public static class Proxy {
+
+ public Proxy() { }
+
+ /** the HTTP Proxy host to use */
+ public String httpProxyHost = null;
+
+ /** the HTTP Proxy port to use */
+ public int httpProxyPort = -1;
+
+ /** if a seperate proxy should be used for HTTPS, this is the hostname; otherwise, httpProxyHost is used */
+ public String httpsProxyHost = null;
+
+ /** if a seperate proxy should be used for HTTPS, this is the port */
+ public int httpsProxyPort = -1;
+
+ /** the SOCKS Proxy Host to use */
+ public String socksProxyHost = null;
+
+ /** the SOCKS Proxy Port to use */
+ public int socksProxyPort = -1;
+
+ /** hosts to be excluded from proxy use; wildcards permitted */
+ public String[] excluded = null;
+
+ /** the PAC script */
+ public JS.Callable proxyAutoConfigFunction = null;
+
+ public static Proxy detectProxyViaManual() {
+ Proxy ret = new Proxy();
+
+ ret.httpProxyHost = Platform.getEnv("http_proxy");
+ if (ret.httpProxyHost != null) {
+ if (ret.httpProxyHost.startsWith("http://")) ret.httpProxyHost = ret.httpProxyHost.substring(7);
+ if (ret.httpProxyHost.endsWith("/")) ret.httpProxyHost = ret.httpProxyHost.substring(0, ret.httpProxyHost.length() - 1);
+ if (ret.httpProxyHost.indexOf(':') != -1) {
+ ret.httpProxyPort = Integer.parseInt(ret.httpProxyHost.substring(ret.httpProxyHost.indexOf(':') + 1));
+ ret.httpProxyHost = ret.httpProxyHost.substring(0, ret.httpProxyHost.indexOf(':'));
+ } else {
+ ret.httpProxyPort = 80;
+ }
+ }
+
+ ret.httpsProxyHost = Platform.getEnv("https_proxy");
+ if (ret.httpsProxyHost != null) {
+ if (ret.httpsProxyHost.startsWith("https://")) ret.httpsProxyHost = ret.httpsProxyHost.substring(7);
+ if (ret.httpsProxyHost.endsWith("/")) ret.httpsProxyHost = ret.httpsProxyHost.substring(0, ret.httpsProxyHost.length() - 1);
+ if (ret.httpsProxyHost.indexOf(':') != -1) {
+ ret.httpsProxyPort = Integer.parseInt(ret.httpsProxyHost.substring(ret.httpsProxyHost.indexOf(':') + 1));
+ ret.httpsProxyHost = ret.httpsProxyHost.substring(0, ret.httpsProxyHost.indexOf(':'));
+ } else {
+ ret.httpsProxyPort = 80;
+ }
+ }
+
+ ret.socksProxyHost = Platform.getEnv("socks_proxy");
+ if (ret.socksProxyHost != null) {
+ if (ret.socksProxyHost.startsWith("socks://")) ret.socksProxyHost = ret.socksProxyHost.substring(7);
+ if (ret.socksProxyHost.endsWith("/")) ret.socksProxyHost = ret.socksProxyHost.substring(0, ret.socksProxyHost.length() - 1);
+ if (ret.socksProxyHost.indexOf(':') != -1) {
+ ret.socksProxyPort = Integer.parseInt(ret.socksProxyHost.substring(ret.socksProxyHost.indexOf(':') + 1));
+ ret.socksProxyHost = ret.socksProxyHost.substring(0, ret.socksProxyHost.indexOf(':'));
+ } else {
+ ret.socksProxyPort = 80;
+ }
+ }
+
+ String noproxy = Platform.getEnv("no_proxy");
+ if (noproxy != null) {
+ StringTokenizer st = new StringTokenizer(noproxy, ",");
+ ret.excluded = new String[st.countTokens()];
+ for(int i=0; st.hasMoreTokens(); i++) ret.excluded[i] = st.nextToken();
+ }
+
+ if (ret.httpProxyHost == null && ret.socksProxyHost == null) return null;
+ return ret;
+ }
+
+ public static JS.Scope proxyAutoConfigRootScope = new ProxyAutoConfigRootScope();
+ public static JS.Callable getProxyAutoConfigFunction(String url) {
+ try {
+ BufferedReader br = new BufferedReader(new InputStreamReader(new HTTP(url, true).GET()));
+ String s = null;
+ String script = "";
+ while((s = br.readLine()) != null) script += s + "\n";
+ if (Log.on) Log.log(Proxy.class, "successfully retrieved WPAD PAC:");
+ if (Log.on) Log.log(Proxy.class, script);
+
+ // MS CARP hack
+ Vector carpHosts = new Vector();
+ for(int i=0; i<script.length(); i++)
+ if (script.regionMatches(i, "new Node(", 0, 9)) {
+ String host = script.substring(i + 10, script.indexOf('\"', i + 11));
+ if (Log.on) Log.log(Proxy.class, "Detected MS Proxy Server CARP Script, Host=" + host);
+ carpHosts.addElement(host);
+ }
+ if (carpHosts.size() > 0) {
+ script = "function FindProxyForURL(url, host) {\nreturn \"";
+ for(int i=0; i<carpHosts.size(); i++)
+ script += "PROXY " + carpHosts.elementAt(i) + "; ";
+ script += "\";\n}";
+ if (Log.on) Log.log(Proxy.class, "DeCARPed PAC script:");
+ if (Log.on) Log.log(Proxy.class, script);
+ }
+
+ JS.CompiledFunction scr = JS.parse("PAC script at " + url, 0, new StringReader(script));
+ scr.call(new JS.Array(), proxyAutoConfigRootScope);
+ return (JS.Callable)proxyAutoConfigRootScope.get("FindProxyForURL");
+ } catch (Exception e) {
+ if (Log.on) {
+ Log.log(Platform.class, "WPAD detection failed due to:");
+ if (e instanceof JS.Exn) {
+ try {
+ org.xwt.js.JS.Array arr = new org.xwt.js.JS.Array();
+ arr.addElement(((JS.Exn)e).getObject());
+ // FIXME
+ //XWT.recursivePrintObject.call();
+ } catch (Exception e2) {
+ Log.log(Platform.class, e);
+ }
+ }
+ else Log.log(Platform.class, e);
+ }
+ return null;
+ }
+ }
+
+
+ // Authorization ///////////////////////////////////////////////////////////////////////////////////
+
+ public static class Authorization {
+
+ static public String authorization = null;
+ static public String authorization2 = null;
+ static public Semaphore waitingForUser = new Semaphore();
+
+ public static synchronized void getPassword(final String realm, final String style, final String proxyIP, String oldAuth) {
+
+ // this handles cases where multiple threads hit the proxy auth at the same time -- all but one will block on the
+ // synchronized keyword. If 'authorization' changed while the thread was blocked, it means that the user entered
+ // a password, so we should reattempt authorization.
+
+ if (authorization != oldAuth) return;
+ if (Log.on) Log.log(Authorization.class, "displaying proxy authorization dialog");
+ MessageQueue.add(new Message() {
+ public void perform() {
+ Box b = new Box();
+ Template.getTemplate("org.xwt.builtin.proxy_authorization", null).apply(b, null, null, null, 0, 0);
+ b.put("realm", realm);
+ b.put("proxyIP", proxyIP);
+ }
+ });
+
+ waitingForUser.block();
+ if (Log.on) Log.log(Authorization.class, "got proxy authorization info; re-attempting connection");
+
+ }
+ }
+
+
+ // ProxyAutoConfigRootScope ////////////////////////////////////////////////////////////////////
+
+ public static class ProxyAutoConfigRootScope extends JS.Scope {
+
+ public ProxyAutoConfigRootScope() { super(null); }
+
+ // FIXME: needs "standard objects"
+
+ public Object get(Object name) {
+ if (name.equals("isPlainHostName")) return isPlainHostName;
+ else if (name.equals("dnsDomainIs")) return dnsDomainIs;
+ else if (name.equals("localHostOrDomainIs")) return localHostOrDomainIs;
+ else if (name.equals("isResolvable")) return isResolvable;
+ else if (name.equals("isInNet")) return isInNet;
+ else if (name.equals("dnsResolve")) return dnsResolve;
+ else if (name.equals("myIpAddress")) return myIpAddress;
+ else if (name.equals("dnsDomainLevels")) return dnsDomainLevels;
+ else if (name.equals("shExpMatch")) return shExpMatch;
+ else if (name.equals("weekdayRange")) return weekdayRange;
+ else if (name.equals("dateRange")) return dateRange;
+ else if (name.equals("timeRange")) return timeRange;
+ else if (name.equals("ProxyConfig")) return ProxyConfig;
+ else return super.get(name);
+ }
+
+ private static final JS.Obj proxyConfigBindings = new JS.Obj();
+ private static final JS.Obj ProxyConfig = new JS.Obj() {
+ public Object get(Object name) {
+ if (name.equals("bindings")) return proxyConfigBindings;
+ return null;
+ }
+ };
+
+ private static final JS.Callable isPlainHostName = new JS.Callable() {
+ public Object call(org.xwt.js.JS.Array args) throws JS.Exn {
+ return (args.elementAt(0).toString().indexOf('.') == -1) ? Boolean.TRUE : Boolean.FALSE;
+ }
+ };
+
+ private static final JS.Callable dnsDomainIs = new JS.Callable() {
+ public Object call(org.xwt.js.JS.Array args) throws JS.Exn {
+ return (args.elementAt(0).toString().endsWith(args.elementAt(1).toString())) ? Boolean.TRUE : Boolean.FALSE;
+ }
+ };
+
+ private static final JS.Callable localHostOrDomainIs = new JS.Callable() {
+ public Object call(org.xwt.js.JS.Array args) throws JS.Exn {
+ return (args.elementAt(0).toString().equals(args.elementAt(1).toString()) ||
+ (args.elementAt(0).toString().indexOf('.') == -1 && args.elementAt(1).toString().startsWith(args.elementAt(0).toString()))) ?
+ Boolean.TRUE : Boolean.FALSE;
+ }
+ };
+
+ private static final JS.Callable isResolvable = new JS.Callable() {
+ public Object call(org.xwt.js.JS.Array args) throws JS.Exn {
+ try {
+ return (InetAddress.getByName(args.elementAt(0).toString()) != null) ? Boolean.TRUE : Boolean.FALSE;
+ } catch (UnknownHostException e) {
+ return Boolean.FALSE;
+ }
+ }
+ };
+
+ private static final JS.Callable isInNet = new JS.Callable() {
+ public Object call(org.xwt.js.JS.Array args) throws JS.Exn {
+ if (args.length() != 3) return Boolean.FALSE;
+ try {
+ byte[] host = InetAddress.getByName(args.elementAt(0).toString()).getAddress();
+ byte[] net = InetAddress.getByName(args.elementAt(1).toString()).getAddress();
+ byte[] mask = InetAddress.getByName(args.elementAt(2).toString()).getAddress();
+ return ((host[0] & mask[0]) == net[0] &&
+ (host[1] & mask[1]) == net[1] &&
+ (host[2] & mask[2]) == net[2] &&
+ (host[3] & mask[3]) == net[3]) ?
+ Boolean.TRUE : Boolean.FALSE;
+ } catch (Exception e) {
+ throw new JS.Exn("exception in isInNet(): " + e);
+ }
+ }
+ };
+
+ private static final JS.Callable dnsResolve = new JS.Callable() {
+ public Object call(org.xwt.js.JS.Array args) throws JS.Exn {
+ try {
+ return InetAddress.getByName(args.elementAt(0).toString()).getHostAddress();
+ } catch (UnknownHostException e) {
+ return null;
+ }
+ }
+ };
+
+ private static final JS.Callable myIpAddress = new JS.Callable() {
+ public Object call(org.xwt.js.JS.Array args) throws JS.Exn {
+ try {
+ return InetAddress.getLocalHost().getHostAddress();
+ } catch (UnknownHostException e) {
+ if (Log.on) Log.log(this, "strange... host does not know its own address");
+ return null;
+ }
+ }
+ };
+
+ private static final JS.Callable dnsDomainLevels = new JS.Callable() {
+ public Object call(org.xwt.js.JS.Array args) throws JS.Exn {
+ String s = args.elementAt(0).toString();
+ int i = 0;
+ while((i = s.indexOf('.', i)) != -1) i++;
+ return new Integer(i);
+ }
+ };
+
+ private static boolean match(String[] arr, String s, int index) {
+ if (index >= arr.length) return true;
+ for(int i=0; i<s.length(); i++) {
+ String s2 = s.substring(i);
+ if (s2.startsWith(arr[index]) && match(arr, s2.substring(arr[index].length()), index + 1)) return true;
+ }
+ return false;
+ }
+
+ private static final JS.Callable shExpMatch = new JS.Callable() {
+ public Object call(org.xwt.js.JS.Array args) throws JS.Exn {
+ StringTokenizer st = new StringTokenizer(args.elementAt(1).toString(), "*", false);
+ String[] arr = new String[st.countTokens()];
+ String s = args.elementAt(0).toString();
+ for (int i=0; st.hasMoreTokens(); i++) arr[i] = st.nextToken();
+ return match(arr, s, 0) ? Boolean.TRUE : Boolean.FALSE;
+ }
+ };
+
+ public static String[] days = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
+
+ private static final JS.Callable weekdayRange = new JS.Callable() {
+ public Object call(org.xwt.js.JS.Array args) throws JS.Exn {
+ TimeZone tz = (args.length() < 3 || args.elementAt(2) == null || !args.elementAt(2).equals("GMT")) ? TimeZone.getTimeZone("UTC") : TimeZone.getDefault();
+ Calendar c = new GregorianCalendar();
+ c.setTimeZone(tz);
+ c.setTime(new java.util.Date());
+ java.util.Date d = c.getTime();
+ int day = d.getDay();
+
+ String d1s = args.elementAt(0).toString().toUpperCase();
+ int d1 = 0, d2 = 0;
+ for(int i=0; i<days.length; i++) if (days[i].equals(d1s)) d1 = i;
+
+ if (args.length() == 1)
+ return d1 == day ? Boolean.TRUE : Boolean.FALSE;
+
+ String d2s = args.elementAt(1).toString().toUpperCase();
+ for(int i=0; i<days.length; i++) if (days[i].equals(d2s)) d2 = i;
+
+ return
+ ((d1 <= d2 && day >= d1 && day <= d2) ||
+ (d1 > d2 && (day >= d1 || day <= d2))) ?
+ Boolean.TRUE : Boolean.FALSE;
+ }
+ };
+
+ private static final JS.Callable dateRange = new JS.Callable() {
+ public Object call(org.xwt.js.JS.Array args) throws JS.Exn {
+ throw new JS.Exn("XWT does not support dateRange() in PAC scripts");
+ }
+ };
+
+ private static final JS.Callable timeRange = new JS.Callable() {
+ public Object call(org.xwt.js.JS.Array args) throws JS.Exn {
+ throw new JS.Exn("XWT does not support timeRange() in PAC scripts");
+ }
+ };
+
+ }
+
+ }
+
}
static boolean alreadyDetectedProxy = false;
/** the result of proxy autodetection */
- static Proxy cachedProxyInfo = null;
+ static HTTP.Proxy cachedProxyInfo = null;
/** the current build */
public static String build = "unknown";
/** creates and returns a doublebuffer 'belonging' to <tt>owner</tt>; we need to associate PixelBuffers to surfaces
* due to AWT 1.1 requirements (definately for Navigator, possibly also for MSJVM).
*/
- protected PixelBuffer _createDoubleBuffer(int w, int h, Surface owner) { return null; }
+ protected PixelBuffer _createPixelBuffer(int w, int h, Surface owner) { return null; }
/** creates and returns a new surface */
protected Surface _createSurface(Box b, boolean framed) { return null; }
}
/** Returns null if XWT should always use direct connection; otherwise returns a ProxyInfo object with proxy settings */
- protected synchronized Proxy _detectProxy() { return null; }
+ protected synchronized HTTP.Proxy _detectProxy() { return null; }
/** displays a platform-specific "open file" dialog and returns the chosen filename, or null if the user hit cancel */
protected String _fileDialog(String suggestedFileName, boolean write) { return null; }
public static int getScreenHeight() { return platform._getScreenHeight(); }
/** creates and returns a doublebuffer 'belonging' to <tt>owner</tt> */
- public static PixelBuffer createDoubleBuffer(int w, int h, Surface s) { return platform._createDoubleBuffer(w, h, s); }
+ public static PixelBuffer createPixelBuffer(int w, int h, Surface s) { return platform._createPixelBuffer(w, h, s); }
/** creates and returns a picture */
public static Picture createPicture(int[] data, int w, int h) { return platform._createPicture(data, w, h); }
}
/** detects proxy settings */
- public static synchronized Proxy detectProxy() {
+ public static synchronized HTTP.Proxy detectProxy() {
if (cachedProxyInfo != null) return cachedProxyInfo;
if (alreadyDetectedProxy) return null;
alreadyDetectedProxy = true;
if (Log.on) Log.log(Platform.class, "attempting environment-variable DNS proxy detection");
- cachedProxyInfo = Proxy.detectProxyViaManual();
+ cachedProxyInfo = HTTP.Proxy.detectProxyViaManual();
if (cachedProxyInfo != null) return cachedProxyInfo;
if (Log.on) Log.log(Platform.class, "attempting " + platform.getClass().getName() + " proxy detection");
+++ /dev/null
-// Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
-package org.xwt;
-
-import java.net.*;
-import java.io.*;
-import java.util.*;
-import org.xwt.js.*;
-import org.xwt.util.*;
-import org.bouncycastle.util.encoders.Base64;
-
-/** encapsulates most of the proxy logic; some is shared in HTTP.java */
-public class Proxy {
-
- public Proxy() { }
-
- /** the HTTP Proxy host to use */
- public String httpProxyHost = null;
-
- /** the HTTP Proxy port to use */
- public int httpProxyPort = -1;
-
- /** if a seperate proxy should be used for HTTPS, this is the hostname; otherwise, httpProxyHost is used */
- public String httpsProxyHost = null;
-
- /** if a seperate proxy should be used for HTTPS, this is the port */
- public int httpsProxyPort = -1;
-
- /** the SOCKS Proxy Host to use */
- public String socksProxyHost = null;
-
- /** the SOCKS Proxy Port to use */
- public int socksProxyPort = -1;
-
- /** hosts to be excluded from proxy use; wildcards permitted */
- public String[] excluded = null;
-
- /** the PAC script */
- public JS.Callable proxyAutoConfigFunction = null;
-
- public static Proxy detectProxyViaManual() {
- Proxy ret = new Proxy();
-
- ret.httpProxyHost = Platform.getEnv("http_proxy");
- if (ret.httpProxyHost != null) {
- if (ret.httpProxyHost.startsWith("http://")) ret.httpProxyHost = ret.httpProxyHost.substring(7);
- if (ret.httpProxyHost.endsWith("/")) ret.httpProxyHost = ret.httpProxyHost.substring(0, ret.httpProxyHost.length() - 1);
- if (ret.httpProxyHost.indexOf(':') != -1) {
- ret.httpProxyPort = Integer.parseInt(ret.httpProxyHost.substring(ret.httpProxyHost.indexOf(':') + 1));
- ret.httpProxyHost = ret.httpProxyHost.substring(0, ret.httpProxyHost.indexOf(':'));
- } else {
- ret.httpProxyPort = 80;
- }
- }
-
- ret.httpsProxyHost = Platform.getEnv("https_proxy");
- if (ret.httpsProxyHost != null) {
- if (ret.httpsProxyHost.startsWith("https://")) ret.httpsProxyHost = ret.httpsProxyHost.substring(7);
- if (ret.httpsProxyHost.endsWith("/")) ret.httpsProxyHost = ret.httpsProxyHost.substring(0, ret.httpsProxyHost.length() - 1);
- if (ret.httpsProxyHost.indexOf(':') != -1) {
- ret.httpsProxyPort = Integer.parseInt(ret.httpsProxyHost.substring(ret.httpsProxyHost.indexOf(':') + 1));
- ret.httpsProxyHost = ret.httpsProxyHost.substring(0, ret.httpsProxyHost.indexOf(':'));
- } else {
- ret.httpsProxyPort = 80;
- }
- }
-
- ret.socksProxyHost = Platform.getEnv("socks_proxy");
- if (ret.socksProxyHost != null) {
- if (ret.socksProxyHost.startsWith("socks://")) ret.socksProxyHost = ret.socksProxyHost.substring(7);
- if (ret.socksProxyHost.endsWith("/")) ret.socksProxyHost = ret.socksProxyHost.substring(0, ret.socksProxyHost.length() - 1);
- if (ret.socksProxyHost.indexOf(':') != -1) {
- ret.socksProxyPort = Integer.parseInt(ret.socksProxyHost.substring(ret.socksProxyHost.indexOf(':') + 1));
- ret.socksProxyHost = ret.socksProxyHost.substring(0, ret.socksProxyHost.indexOf(':'));
- } else {
- ret.socksProxyPort = 80;
- }
- }
-
- String noproxy = Platform.getEnv("no_proxy");
- if (noproxy != null) {
- StringTokenizer st = new StringTokenizer(noproxy, ",");
- ret.excluded = new String[st.countTokens()];
- for(int i=0; st.hasMoreTokens(); i++) ret.excluded[i] = st.nextToken();
- }
-
- if (ret.httpProxyHost == null && ret.socksProxyHost == null) return null;
- return ret;
- }
-
- public static JS.Scope proxyAutoConfigRootScope = new ProxyAutoConfigRootScope();
- public static JS.Callable getProxyAutoConfigFunction(String url) {
- try {
- BufferedReader br = new BufferedReader(new InputStreamReader(new HTTP(url, true).GET()));
- String s = null;
- String script = "";
- while((s = br.readLine()) != null) script += s + "\n";
- if (Log.on) Log.log(Proxy.class, "successfully retrieved WPAD PAC:");
- if (Log.on) Log.log(Proxy.class, script);
-
- // MS CARP hack
- Vector carpHosts = new Vector();
- for(int i=0; i<script.length(); i++)
- if (script.regionMatches(i, "new Node(", 0, 9)) {
- String host = script.substring(i + 10, script.indexOf('\"', i + 11));
- if (Log.on) Log.log(Proxy.class, "Detected MS Proxy Server CARP Script, Host=" + host);
- carpHosts.addElement(host);
- }
- if (carpHosts.size() > 0) {
- script = "function FindProxyForURL(url, host) {\nreturn \"";
- for(int i=0; i<carpHosts.size(); i++)
- script += "PROXY " + carpHosts.elementAt(i) + "; ";
- script += "\";\n}";
- if (Log.on) Log.log(Proxy.class, "DeCARPed PAC script:");
- if (Log.on) Log.log(Proxy.class, script);
- }
-
- JS.CompiledFunction scr = JS.parse("PAC script at " + url, 0, new StringReader(script));
- scr.call(new JS.Array(), proxyAutoConfigRootScope);
- return (JS.Callable)proxyAutoConfigRootScope.get("FindProxyForURL");
- } catch (Exception e) {
- if (Log.on) {
- Log.log(Platform.class, "WPAD detection failed due to:");
- if (e instanceof JS.Exn) {
- try {
- org.xwt.js.JS.Array arr = new org.xwt.js.JS.Array();
- arr.addElement(((JS.Exn)e).getObject());
- // FIXME
- //XWT.recursivePrintObject.call();
- } catch (Exception e2) {
- Log.log(Platform.class, e);
- }
- }
- else Log.log(Platform.class, e);
- }
- return null;
- }
- }
-
-
- // Authorization ///////////////////////////////////////////////////////////////////////////////////
-
- public static class Authorization {
-
- static public String authorization = null;
- static public String authorization2 = null;
- static public Semaphore waitingForUser = new Semaphore();
-
- public static synchronized void getPassword(final String realm, final String style, final String proxyIP, String oldAuth) {
-
- // this handles cases where multiple threads hit the proxy auth at the same time -- all but one will block on the
- // synchronized keyword. If 'authorization' changed while the thread was blocked, it means that the user entered
- // a password, so we should reattempt authorization.
-
- if (authorization != oldAuth) return;
- if (Log.on) Log.log(Authorization.class, "displaying proxy authorization dialog");
- MessageQueue.add(new Message() {
- public void perform() {
- Box b = new Box();
- Template.getTemplate("org.xwt.builtin.proxy_authorization", null).apply(b, null, null, null, 0, 0);
- b.put("realm", realm);
- b.put("proxyIP", proxyIP);
- }
- });
-
- waitingForUser.block();
- if (Log.on) Log.log(Authorization.class, "got proxy authorization info; re-attempting connection");
-
- }
- }
-
-
- // ProxyAutoConfigRootScope ////////////////////////////////////////////////////////////////////
-
- public static class ProxyAutoConfigRootScope extends JS.Scope {
-
- public ProxyAutoConfigRootScope() { super(null); }
-
- // FIXME: needs "standard objects"
-
- public Object get(Object name) {
- if (name.equals("isPlainHostName")) return isPlainHostName;
- else if (name.equals("dnsDomainIs")) return dnsDomainIs;
- else if (name.equals("localHostOrDomainIs")) return localHostOrDomainIs;
- else if (name.equals("isResolvable")) return isResolvable;
- else if (name.equals("isInNet")) return isInNet;
- else if (name.equals("dnsResolve")) return dnsResolve;
- else if (name.equals("myIpAddress")) return myIpAddress;
- else if (name.equals("dnsDomainLevels")) return dnsDomainLevels;
- else if (name.equals("shExpMatch")) return shExpMatch;
- else if (name.equals("weekdayRange")) return weekdayRange;
- else if (name.equals("dateRange")) return dateRange;
- else if (name.equals("timeRange")) return timeRange;
- else if (name.equals("ProxyConfig")) return ProxyConfig;
- else return super.get(name);
- }
-
- private static final JS.Obj proxyConfigBindings = new JS.Obj();
- private static final JS.Obj ProxyConfig = new JS.Obj() {
- public Object get(Object name) {
- if (name.equals("bindings")) return proxyConfigBindings;
- return null;
- }
- };
-
- private static final JS.Callable isPlainHostName = new JS.Callable() {
- public Object call(org.xwt.js.JS.Array args) throws JS.Exn {
- return (args.elementAt(0).toString().indexOf('.') == -1) ? Boolean.TRUE : Boolean.FALSE;
- }
- };
-
- private static final JS.Callable dnsDomainIs = new JS.Callable() {
- public Object call(org.xwt.js.JS.Array args) throws JS.Exn {
- return (args.elementAt(0).toString().endsWith(args.elementAt(1).toString())) ? Boolean.TRUE : Boolean.FALSE;
- }
- };
-
- private static final JS.Callable localHostOrDomainIs = new JS.Callable() {
- public Object call(org.xwt.js.JS.Array args) throws JS.Exn {
- return (args.elementAt(0).toString().equals(args.elementAt(1).toString()) ||
- (args.elementAt(0).toString().indexOf('.') == -1 && args.elementAt(1).toString().startsWith(args.elementAt(0).toString()))) ?
- Boolean.TRUE : Boolean.FALSE;
- }
- };
-
- private static final JS.Callable isResolvable = new JS.Callable() {
- public Object call(org.xwt.js.JS.Array args) throws JS.Exn {
- try {
- return (InetAddress.getByName(args.elementAt(0).toString()) != null) ? Boolean.TRUE : Boolean.FALSE;
- } catch (UnknownHostException e) {
- return Boolean.FALSE;
- }
- }
- };
-
- private static final JS.Callable isInNet = new JS.Callable() {
- public Object call(org.xwt.js.JS.Array args) throws JS.Exn {
- if (args.length() != 3) return Boolean.FALSE;
- try {
- byte[] host = InetAddress.getByName(args.elementAt(0).toString()).getAddress();
- byte[] net = InetAddress.getByName(args.elementAt(1).toString()).getAddress();
- byte[] mask = InetAddress.getByName(args.elementAt(2).toString()).getAddress();
- return ((host[0] & mask[0]) == net[0] &&
- (host[1] & mask[1]) == net[1] &&
- (host[2] & mask[2]) == net[2] &&
- (host[3] & mask[3]) == net[3]) ?
- Boolean.TRUE : Boolean.FALSE;
- } catch (Exception e) {
- throw new JS.Exn("exception in isInNet(): " + e);
- }
- }
- };
-
- private static final JS.Callable dnsResolve = new JS.Callable() {
- public Object call(org.xwt.js.JS.Array args) throws JS.Exn {
- try {
- return InetAddress.getByName(args.elementAt(0).toString()).getHostAddress();
- } catch (UnknownHostException e) {
- return null;
- }
- }
- };
-
- private static final JS.Callable myIpAddress = new JS.Callable() {
- public Object call(org.xwt.js.JS.Array args) throws JS.Exn {
- try {
- return InetAddress.getLocalHost().getHostAddress();
- } catch (UnknownHostException e) {
- if (Log.on) Log.log(this, "strange... host does not know its own address");
- return null;
- }
- }
- };
-
- private static final JS.Callable dnsDomainLevels = new JS.Callable() {
- public Object call(org.xwt.js.JS.Array args) throws JS.Exn {
- String s = args.elementAt(0).toString();
- int i = 0;
- while((i = s.indexOf('.', i)) != -1) i++;
- return new Integer(i);
- }
- };
-
- private static boolean match(String[] arr, String s, int index) {
- if (index >= arr.length) return true;
- for(int i=0; i<s.length(); i++) {
- String s2 = s.substring(i);
- if (s2.startsWith(arr[index]) && match(arr, s2.substring(arr[index].length()), index + 1)) return true;
- }
- return false;
- }
-
- private static final JS.Callable shExpMatch = new JS.Callable() {
- public Object call(org.xwt.js.JS.Array args) throws JS.Exn {
- StringTokenizer st = new StringTokenizer(args.elementAt(1).toString(), "*", false);
- String[] arr = new String[st.countTokens()];
- String s = args.elementAt(0).toString();
- for (int i=0; st.hasMoreTokens(); i++) arr[i] = st.nextToken();
- return match(arr, s, 0) ? Boolean.TRUE : Boolean.FALSE;
- }
- };
-
- public static String[] days = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
-
- private static final JS.Callable weekdayRange = new JS.Callable() {
- public Object call(org.xwt.js.JS.Array args) throws JS.Exn {
- TimeZone tz = (args.length() < 3 || args.elementAt(2) == null || !args.elementAt(2).equals("GMT")) ? TimeZone.getTimeZone("UTC") : TimeZone.getDefault();
- Calendar c = new GregorianCalendar();
- c.setTimeZone(tz);
- c.setTime(new java.util.Date());
- java.util.Date d = c.getTime();
- int day = d.getDay();
-
- String d1s = args.elementAt(0).toString().toUpperCase();
- int d1 = 0, d2 = 0;
- for(int i=0; i<days.length; i++) if (days[i].equals(d1s)) d1 = i;
-
- if (args.length() == 1)
- return d1 == day ? Boolean.TRUE : Boolean.FALSE;
-
- String d2s = args.elementAt(1).toString().toUpperCase();
- for(int i=0; i<days.length; i++) if (days[i].equals(d2s)) d2 = i;
-
- return
- ((d1 <= d2 && day >= d1 && day <= d2) ||
- (d1 > d2 && (day >= d1 || day <= d2))) ?
- Boolean.TRUE : Boolean.FALSE;
- }
- };
-
- private static final JS.Callable dateRange = new JS.Callable() {
- public Object call(org.xwt.js.JS.Array args) throws JS.Exn {
- throw new JS.Exn("XWT does not support dateRange() in PAC scripts");
- }
- };
-
- private static final JS.Callable timeRange = new JS.Callable() {
- public Object call(org.xwt.js.JS.Array args) throws JS.Exn {
- throw new JS.Exn("XWT does not support timeRange() in PAC scripts");
- }
- };
-
- }
-
-}
package org.xwt;
import java.io.*;
+import java.util.*;
+import java.util.zip.*;
import org.xwt.js.*;
+import org.xwt.util.*;
// FIXME: ByteStream fileName property
/** base class for XWT resources */
public abstract class Res extends JS {
- public String toString() { return "Resource, source=FIXME"; }
-
- public final InputStream getInputStream() { return getInputStream(""); }
+ public final InputStream getInputStream() throws IOException { return getInputStream(""); }
public Res graft(Object newResource) { throw new JS.Exn("cannot graft onto this resource"); }
public Object get(Object key) { return new Ref(this, key); }
public void put(Object key, Object val) { throw new JS.Exn("cannot put to a resource"); }
public Object[] keys() { throw new JS.Exn("cannot enumerate a resource"); }
- public abstract InputStream getInputStream(String path) { return getInputStream(""); }
- public abstract Res addExtension(String extension);
+ public abstract InputStream getInputStream(String path) throws IOException;
+ //public abstract Res addExtension(String extension);
public static Res stringToRes(String url) {
- if (url.indexOf('!') == -1)
- return new Zip(stringToRes(url.substring(0, url.lastIndexOf('!'))),
- url.substring(url.lastIndexOf('!') + 1));
+ if (url.indexOf('!') != -1)
+ return (Res)(new Zip(stringToRes(url.substring(0, url.lastIndexOf('!')))).get(url.substring(url.lastIndexOf('!') + 1)));
if (url.startsWith("http://")) return new HTTP(url);
if (url.startsWith("https://")) return new HTTP(url);
+ if (url.startsWith("file:")) return new File(url.substring(5));
+ if (url.startsWith("cab:")) return new CAB(stringToRes(url.substring(4)));
throw new JS.Exn("invalid resource specifier");
}
public static class HTTP extends Res {
private String url;
HTTP(String url) { this.url = url; }
- public InputStream getInputStream(String path) { return new HTTP(url + path).GET(); }
+ public InputStream getInputStream(String path) throws IOException { return new org.xwt.HTTP(url + path).GET(); }
+ }
+
+ // FIXME: dangerous
+ /** a file */
+ public static class File extends Res {
+ private String path;
+ File(String path) { this.path = path; }
+ public InputStream getInputStream(String rest) throws IOException { return new FileInputStream((path + rest).replace('/', java.io.File.separatorChar)); }
}
/** wrap a Res around a preexisting InputStream */
public static class IS extends Res {
InputStream parent;
IS(InputStream parent) { this.parent = parent; }
- public InputStream getInputStream() { return parent; }
public InputStream getInputStream(String path) {
if (!"".equals(path)) throw new JS.Exn("can't access subresources of IS");
return parent;
public static class Zip extends Res {
private Res parent;
Zip(Res parent) { this.parent = parent; }
- public InputStream getInputStream(String path) {
+ public InputStream getInputStream(String path) throws IOException {
ZipInputStream zis = new ZipInputStream(parent.getInputStream());
ZipEntry ze = zis.getNextEntry();
while(ze != null && !ze.getName().equals(path)) ze = zis.getNextEntry();
Res parent;
Object key;
Ref(Res parent, Object key) { this.parent = parent; this.key = key; }
- public InputStream getInputStream(path) {
+ public InputStream getInputStream(String path) throws IOException {
return parent.getInputStream("/" + key + path);
}
public Res graft(Object newResource) { return new Graft(parent, key, newResource); }
Graft(Res graftee, Object key, Object val) {
this.graftee = graftee; replaced_key = key; replaced_val = val; }
public boolean equals(Object o) { return (this == o || graftee.equals(o)); }
+ public int hashCode() { return graftee.hashCode(); }
+ public InputStream getInputStream(String s) throws IOException { return graftee.getInputStream(s); }
public Object get(Object key) {
return replaced_key.equals(key) ? replaced_val : graftee.get(key);
}
}
- /////////////// bytestream
+ /** unpacks a Microsoft CAB file (possibly embedded in another file; we scan for 'MSCF' */
+ public static class CAB extends Res {
+ private Res parent;
+ CAB(Res parent) { this.parent = parent; }
+ private int swap_endian(int i) {
+ return ((i & 0xff) << 24) | ((i & 0xff00) << 8) | ((i & 0xff0000) >>> 8) | (i >>> 24);
+ }
+ public InputStream getInputStream(String path) throws IOException {
+ InputStream is = new InputStream(parent.getInputStream());
+ byte[] scan = new byte[4];
+ while(scan[0] != 'M' || scan[1] != 'S' || scan[2] != 'C' || scan[3] != 'F') {
+ System.arraycopy(scan, 1, scan, 0, 3);
+ int read = is.read();
+ if (read == -1) throw new JS.Exn("MSCF header tag not found in file");
+ scan[3] = (byte)read;
+ }
+ return org.xwt.util.CAB.getFileInputStream(is, path);
+ }
+ }
public Object callMethod(Object method, Array args, boolean checkOnly) throws JS.Exn {
if (method.equals("getUTF")) {
}
return caw.toString();
} catch (IOException e) {
- if (Log.on) Log.log(ByteStream.class, "IO Exception while reading from file");
- if (Log.on) Log.log(ByteStream.class, e);
- throw new JS.Exn("error while reading from ByteStream");
+ if (Log.on) Log.log(Res.class, "IO Exception while reading from file");
+ if (Log.on) Log.log(Res.class, e);
+ throw new JS.Exn("error while reading from Resource");
}
- } else if (name.equals("getDOM")) {
+ } else if (method.equals("getDOM")) {
if (checkOnly) return Boolean.TRUE;
if (args.length() != 0) return null;
return new XMLHelper().doParse();
} catch (XML.XMLException e) {
throw new JS.Exn("error parsing XML: " + e.toString());
} catch (IOException e) {
- if (Log.on) Log.log(ByteStream.class, "IO Exception while reading from file");
- if (Log.on) Log.log(ByteStream.class, e);
- throw new JS.Exn("error reading from ByteStream");
+ if (Log.on) Log.log(this, "IO Exception while reading from file");
+ if (Log.on) Log.log(this, e);
+ throw new JS.Exn("error reading from Resource");
}
return obStack.size() >= 1 ? (JS)obStack.elementAt(0) : null;
}
objects.addElement(new String(content.getBuf(), 0, content.size()).intern());
content.reset();
+ // FIXME
+ /*
} else if (me instanceof byte[]) {
objects.removeElementAt(objects.size() - 1);
objects.addElement(new ByteStream(Base64.decode(new String(content.getBuf(), 0, content.size()))));
content.reset();
-
+ */
} else if (me instanceof Integer) {
objects.removeElementAt(objects.size() - 1);
objects.addElement(new Integer(new String(content.getBuf(), 0, content.size())));
sb.append(((Boolean)o).booleanValue() ? "true" : "false");
sb.append("</" + name + ">\r\n");
+ /* FIXME
} else if (o instanceof ByteStream) {
try {
sb.append(" <" + name + " xsi:type=\"SOAP-ENC:base64\">\r\n");
if (Log.on) Log.log(this, e);
throw new JS.Exn("caught IOException while attempting to send a ByteStream via SOAP");
}
-
+ */
} else if (o instanceof String) {
sb.append(" <" + name + " xsi:type=\"xsd:string\">");
String s = (String)o;
+++ /dev/null
-// Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
-package org.xwt;
-import java.util.*;
-
-public class SVG {
-
- /** Copied verbatim from the SVG specification */
- public static Hashtable colors = new Hashtable(400);
- static {
- colors.put("aliceblue", new Integer((240 << 16) | (248 << 8) | 255));
- colors.put("antiquewhite", new Integer((250 << 16) | (235 << 8) | 215));
- colors.put("aqua", new Integer((0 << 16) | (255 << 8) | 255));
- colors.put("aquamarine", new Integer((127 << 16) | (255 << 8) | 212));
- colors.put("azure", new Integer((240 << 16) | (255 << 8) | 255));
- colors.put("beige", new Integer((245 << 16) | (245 << 8) | 220));
- colors.put("bisque", new Integer((255 << 16) | (228 << 8) | 196));
- colors.put("black", new Integer((0 << 16) | (0 << 8) | 0));
- colors.put("blanchedalmond", new Integer((255 << 16) | (235 << 8) | 205));
- colors.put("blue", new Integer((0 << 16) | (0 << 8) | 255));
- colors.put("blueviolet", new Integer((138 << 16) | (43 << 8) | 226));
- colors.put("brown", new Integer((165 << 16) | (42 << 8) | 42));
- colors.put("burlywood", new Integer((222 << 16) | (184 << 8) | 135));
- colors.put("cadetblue", new Integer((95 << 16) | (158 << 8) | 160));
- colors.put("chartreuse", new Integer((127 << 16) | (255 << 8) | 0));
- colors.put("chocolate", new Integer((210 << 16) | (105 << 8) | 30));
- colors.put("coral", new Integer((255 << 16) | (127 << 8) | 80));
- colors.put("cornflowerblue", new Integer((100 << 16) | (149 << 8) | 237));
- colors.put("cornsilk", new Integer((255 << 16) | (248 << 8) | 220));
- colors.put("crimson", new Integer((220 << 16) | (20 << 8) | 60));
- colors.put("cyan", new Integer((0 << 16) | (255 << 8) | 255));
- colors.put("darkblue", new Integer((0 << 16) | (0 << 8) | 139));
- colors.put("darkcyan", new Integer((0 << 16) | (139 << 8) | 139));
- colors.put("darkgoldenrod", new Integer((184 << 16) | (134 << 8) | 11));
- colors.put("darkgray", new Integer((169 << 16) | (169 << 8) | 169));
- colors.put("darkgreen", new Integer((0 << 16) | (100 << 8) | 0));
- colors.put("darkgrey", new Integer((169 << 16) | (169 << 8) | 169));
- colors.put("darkkhaki", new Integer((189 << 16) | (183 << 8) | 107));
- colors.put("darkmagenta", new Integer((139 << 16) | (0 << 8) | 139));
- colors.put("darkolivegreen", new Integer((85 << 16) | (107 << 8) | 47));
- colors.put("darkorange", new Integer((255 << 16) | (140 << 8) | 0));
- colors.put("darkorchid", new Integer((153 << 16) | (50 << 8) | 204));
- colors.put("darkred", new Integer((139 << 16) | (0 << 8) | 0));
- colors.put("darksalmon", new Integer((233 << 16) | (150 << 8) | 122));
- colors.put("darkseagreen", new Integer((143 << 16) | (188 << 8) | 143));
- colors.put("darkslateblue", new Integer((72 << 16) | (61 << 8) | 139));
- colors.put("darkslategray", new Integer((47 << 16) | (79 << 8) | 79));
- colors.put("darkslategrey", new Integer((47 << 16) | (79 << 8) | 79));
- colors.put("darkturquoise", new Integer((0 << 16) | (206 << 8) | 209));
- colors.put("darkviolet", new Integer((148 << 16) | (0 << 8) | 211));
- colors.put("deeppink", new Integer((255 << 16) | (20 << 8) | 147));
- colors.put("deepskyblue", new Integer((0 << 16) | (191 << 8) | 255));
- colors.put("dimgray", new Integer((105 << 16) | (105 << 8) | 105));
- colors.put("dimgrey", new Integer((105 << 16) | (105 << 8) | 105));
- colors.put("dodgerblue", new Integer((30 << 16) | (144 << 8) | 255));
- colors.put("firebrick", new Integer((178 << 16) | (34 << 8) | 34));
- colors.put("floralwhite", new Integer((255 << 16) | (250 << 8) | 240));
- colors.put("forestgreen", new Integer((34 << 16) | (139 << 8) | 34));
- colors.put("fuchsia", new Integer((255 << 16) | (0 << 8) | 255));
- colors.put("gainsboro", new Integer((220 << 16) | (220 << 8) | 220));
- colors.put("ghostwhite", new Integer((248 << 16) | (248 << 8) | 255));
- colors.put("gold", new Integer((255 << 16) | (215 << 8) | 0));
- colors.put("goldenrod", new Integer((218 << 16) | (165 << 8) | 32));
- colors.put("gray", new Integer((128 << 16) | (128 << 8) | 128));
- colors.put("grey", new Integer((128 << 16) | (128 << 8) | 128));
- colors.put("green", new Integer((0 << 16) | (128 << 8) | 0));
- colors.put("greenyellow", new Integer((173 << 16) | (255 << 8) | 47));
- colors.put("honeydew", new Integer((240 << 16) | (255 << 8) | 240));
- colors.put("hotpink", new Integer((255 << 16) | (105 << 8) | 180));
- colors.put("indianred", new Integer((205 << 16) | (92 << 8) | 92));
- colors.put("indigo", new Integer((75 << 16) | (0 << 8) | 130));
- colors.put("ivory", new Integer((255 << 16) | (255 << 8) | 240));
- colors.put("khaki", new Integer((240 << 16) | (230 << 8) | 140));
- colors.put("lavender", new Integer((230 << 16) | (230 << 8) | 250));
- colors.put("lavenderblush", new Integer((255 << 16) | (240 << 8) | 245));
- colors.put("lawngreen", new Integer((124 << 16) | (252 << 8) | 0));
- colors.put("lemonchiffon", new Integer((255 << 16) | (250 << 8) | 205));
- colors.put("lightblue", new Integer((173 << 16) | (216 << 8) | 230));
- colors.put("lightcoral", new Integer((240 << 16) | (128 << 8) | 128));
- colors.put("lightcyan", new Integer((224 << 16) | (255 << 8) | 255));
- colors.put("lightgoldenrodyellow", new Integer((250 << 16) | (250 << 8) | 210));
- colors.put("lightgray", new Integer((211 << 16) | (211 << 8) | 211));
- colors.put("lightgreen", new Integer((144 << 16) | (238 << 8) | 144));
- colors.put("lightgrey", new Integer((211 << 16) | (211 << 8) | 211));
- colors.put("lightpink", new Integer((255 << 16) | (182 << 8) | 193));
- colors.put("lightsalmon", new Integer((255 << 16) | (160 << 8) | 122));
- colors.put("lightseagreen", new Integer((32 << 16) | (178 << 8) | 170));
- colors.put("lightskyblue", new Integer((135 << 16) | (206 << 8) | 250));
- colors.put("lightslategray", new Integer((119 << 16) | (136 << 8) | 153));
- colors.put("lightslategrey", new Integer((119 << 16) | (136 << 8) | 153));
- colors.put("lightsteelblue", new Integer((176 << 16) | (196 << 8) | 222));
- colors.put("lightyellow", new Integer((255 << 16) | (255 << 8) | 224));
- colors.put("lime", new Integer((0 << 16) | (255 << 8) | 0));
- colors.put("limegreen", new Integer((50 << 16) | (205 << 8) | 50));
- colors.put("linen", new Integer((250 << 16) | (240 << 8) | 230));
- colors.put("magenta", new Integer((255 << 16) | (0 << 8) | 255));
- colors.put("maroon", new Integer((128 << 16) | (0 << 8) | 0));
- colors.put("mediumaquamarine", new Integer((102 << 16) | (205 << 8) | 170));
- colors.put("mediumblue", new Integer((0 << 16) | (0 << 8) | 205));
- colors.put("mediumorchid", new Integer((186 << 16) | (85 << 8) | 211));
- colors.put("mediumpurple", new Integer((147 << 16) | (112 << 8) | 219));
- colors.put("mediumseagreen", new Integer((60 << 16) | (179 << 8) | 113));
- colors.put("mediumslateblue", new Integer((123 << 16) | (104 << 8) | 238));
- colors.put("mediumspringgreen", new Integer((0 << 16) | (250 << 8) | 154));
- colors.put("mediumturquoise", new Integer((72 << 16) | (209 << 8) | 204));
- colors.put("mediumvioletred", new Integer((199 << 16) | (21 << 8) | 133));
- colors.put("midnightblue", new Integer((25 << 16) | (25 << 8) | 112));
- colors.put("mintcream", new Integer((245 << 16) | (255 << 8) | 250));
- colors.put("mistyrose", new Integer((255 << 16) | (228 << 8) | 225));
- colors.put("moccasin", new Integer((255 << 16) | (228 << 8) | 181));
- colors.put("navajowhite", new Integer((255 << 16) | (222 << 8) | 173));
- colors.put("navy", new Integer((0 << 16) | (0 << 8) | 128));
- colors.put("oldlace", new Integer((253 << 16) | (245 << 8) | 230));
- colors.put("olive", new Integer((128 << 16) | (128 << 8) | 0));
- colors.put("olivedrab", new Integer((107 << 16) | (142 << 8) | 35));
- colors.put("orange", new Integer((255 << 16) | (165 << 8) | 0));
- colors.put("orangered", new Integer((255 << 16) | (69 << 8) | 0));
- colors.put("orchid", new Integer((218 << 16) | (112 << 8) | 214));
- colors.put("palegoldenrod", new Integer((238 << 16) | (232 << 8) | 170));
- colors.put("palegreen", new Integer((152 << 16) | (251 << 8) | 152));
- colors.put("paleturquoise", new Integer((175 << 16) | (238 << 8) | 238));
- colors.put("palevioletred", new Integer((219 << 16) | (112 << 8) | 147));
- colors.put("papayawhip", new Integer((255 << 16) | (239 << 8) | 213));
- colors.put("peachpuff", new Integer((255 << 16) | (218 << 8) | 185));
- colors.put("peru", new Integer((205 << 16) | (133 << 8) | 63));
- colors.put("pink", new Integer((255 << 16) | (192 << 8) | 203));
- colors.put("plum", new Integer((221 << 16) | (160 << 8) | 221));
- colors.put("powderblue", new Integer((176 << 16) | (224 << 8) | 230));
- colors.put("purple", new Integer((128 << 16) | (0 << 8) | 128));
- colors.put("red", new Integer((255 << 16) | (0 << 8) | 0));
- colors.put("rosybrown", new Integer((188 << 16) | (143 << 8) | 143));
- colors.put("royalblue", new Integer((65 << 16) | (105 << 8) | 225));
- colors.put("saddlebrown", new Integer((139 << 16) | (69 << 8) | 19));
- colors.put("salmon", new Integer((250 << 16) | (128 << 8) | 114));
- colors.put("sandybrown", new Integer((244 << 16) | (164 << 8) | 96));
- colors.put("seagreen", new Integer((46 << 16) | (139 << 8) | 87));
- colors.put("seashell", new Integer((255 << 16) | (245 << 8) | 238));
- colors.put("sienna", new Integer((160 << 16) | (82 << 8) | 45));
- colors.put("silver", new Integer((192 << 16) | (192 << 8) | 192));
- colors.put("skyblue", new Integer((135 << 16) | (206 << 8) | 235));
- colors.put("slateblue", new Integer((106 << 16) | (90 << 8) | 205));
- colors.put("slategray", new Integer((112 << 16) | (128 << 8) | 144));
- colors.put("slategrey", new Integer((112 << 16) | (128 << 8) | 144));
- colors.put("snow", new Integer((255 << 16) | (250 << 8) | 250));
- colors.put("springgreen", new Integer((0 << 16) | (255 << 8) | 127));
- colors.put("steelblue", new Integer((70 << 16) | (130 << 8) | 180));
- colors.put("tan", new Integer((210 << 16) | (180 << 8) | 140));
- colors.put("teal", new Integer((0 << 16) | (128 << 8) | 128));
- colors.put("thistle", new Integer((216 << 16) | (191 << 8) | 216));
- colors.put("tomato", new Integer((255 << 16) | (99 << 8) | 71));
- colors.put("turquoise", new Integer((64 << 16) | (224 << 8) | 208));
- colors.put("violet", new Integer((238 << 16) | (130 << 8) | 238));
- colors.put("wheat", new Integer((245 << 16) | (222 << 8) | 179));
- colors.put("white", new Integer((255 << 16) | (255 << 8) | 255));
- colors.put("whitesmoke", new Integer((245 << 16) | (245 << 8) | 245));
- colors.put("yellow", new Integer((255 << 16) | (255 << 8) | 0));
- colors.put("yellowgreen", new Integer((154 << 16) | (205 << 8) | 50));
- }
-
-}
--- /dev/null
+// Copyright 2002 Adam Megacz, see the COPYING file for licensing [GPL]
+package org.xwt;
+import org.xwt.util.*;
+import java.util.*;
+
+// NOTE: we have to make sure that a box is never smaller than the
+// bounding box of its path unless the user specifically forced
+// it to be so.
+
+// FIXME: fracture when realizing instead of when parsing?
+/*
+ v1.0
+ - Base64 "data:" URL support
+ - textpath
+ - gradients
+ - patterns
+ - clipping/masking
+ - filters (filtering of a group must be performed AFTER the group is assembled; sep. canvas)
+ - style sheets
+
+ v1.1
+ - markers (do this in the parser; remember the order: fill, stroke, marker)
+ - bump caps [requires Paint that can fill circles...] [remember to distinguish between closed/unclosed]
+ - line joins
+ - mitre (hard)
+ - bevel (easy)
+ - bump (easy, but requires 'round' Paint)
+ - subtree sharing? otherwise the memory consumption might be outrageous... clone="" attribute?
+ - better clipping
+ - intersect clip regions (linearity)
+ - clip on trapezoids, not pixels
+ - faster gradients and patterns:
+ - transform each corner of the trapezoid and then interpolate
+
+ */
+
+/** XWT's fully conformant Static SVG Viewer; see SVG spec, section G.7 */
+public final class VectorGraphics {
+ /*
+ // Public entry points /////////////////////////////////////////////////////////////////
+
+ // FIXME
+ public static SVG.Font currentFont = null;
+
+ public static VectorPath parseVectorPath(String s) {
+ PathTokenizer t = new PathTokenizer(s);
+ VectorPath ret = new VectorPath();
+ char last_command = 'M';
+ boolean first = true;
+ while(t.hasMoreTokens()) {
+ char command = t.parseCommand();
+ if (first && command != 'M') throw new RuntimeException("the first command of a path must be 'M'");
+ first = false;
+ boolean relative = Character.toLowerCase(command) == command;
+ command = Character.toLowerCase(command);
+ ret.parseSingleCommandAndArguments(t, command, relative);
+ last_command = command;
+ }
+ return ret;
+ }
+
+ public static void parseNode(String name, String[] keys, Object[] vals, Template t) {
+ Hash h = new Hash();
+ for(int i=0; i<keys.length; i++) if (vals[i] != null) h.put(keys[i], vals[i]);
+
+ Hash props = new Hash();
+ props.put("transform", h.get("transform"));
+ props.put("fill", h.get("fill"));
+ props.put("stroke", h.get("stroke"));
+ if ("visible".equals(h.get("overflow")) || "auto".equals(h.get("overflow")))
+ Log.log(SVG.class, "warning: overflow={auto|visible} not supported; ignoring");
+ if (h.get("display") != null) props.put("invisible", new Boolean("none".equals(h.get("display"))));
+
+
+ // FIXME: "the automatic transformation that is created due to
+ // a viewBox does not affect the x, y, width and height
+ // attributes". Also, transform+viewbox together?
+
+ if (h.get("preserveAspectRatio") != null) {
+ StringTokenizer st = new StringTokenizer((String)h.get("preserveAspectRatio"), " ");
+ String align = st.nextToken();
+ if ("defer".equals(align)) align = st.nextToken();
+ if (!align.equals("none")) {
+ // FIXME, need to beef up XWT's align property
+ align = "";
+ if (align.startsWith("yMin")) align = "top";
+ else if (align.startsWith("yMax")) align = "bottom";
+ if (align.startsWith("xMin")) align += "left";
+ else if (align.startsWith("xMax")) align += "right";
+ props.put("align", align);
+ }
+ // FIXME: need to implement scaling property on boxes, also size-to-viewbox
+ props.put("scaling", "uniform");
+ if (st.hasMoreTokens()) {
+ String meetOrSlice = st.nextToken();
+ if (meetOrSlice.equals("meet")) props.put("scaling", "meet"); // keep within viewport
+ else if (meetOrSlice.equals("slice")) props.put("scaling", "slice"); // expand beyond viewport
+ }
+ }
+
+ // FIXME: insert an extra layer of boxen and put this transform on the inner layer
+ if (h.get("viewBox") != null) {
+ PathTokenizer pt = new PathTokenizer(h.get("viewBox").toString());
+ String transform = (String)props.get("transform");
+ if (transform == null) transform = "";
+ transform = "translate(" + (-1 * pt.parseFloat()) + ", " + (-1 * pt.parseFloat()) + ") " +
+ "scale(" + pt.parseFloat() + "%, " + pt.parseFloat() + "%) ";
+ }
+
+ String path = (String)h.get("d");
+ if (name.equals("g")) {
+ path = null;
+
+ } else if (name.equals("font")) {
+ SVG.Font f = currentFont = new SVG.Font();
+ if (h.get("horiz-origin-x") != null) f.horiz_origin_x = Float.parseFloat(h.get("horiz-origin-x").toString());
+ if (h.get("horiz-origin-y") != null) f.horiz_origin_y = Float.parseFloat(h.get("horiz-origin-y").toString());
+ if (h.get("horiz-adv-x") != null) f.horiz_adv_x = Float.parseFloat(h.get("horiz-adv-x").toString());
+ if (h.get("vert-origin-x") != null) f.vert_origin_x = Float.parseFloat(h.get("vert-origin-x").toString());
+ if (h.get("vert-origin-y") != null) f.vert_origin_y = Float.parseFloat(h.get("vert-origin_y").toString());
+ if (h.get("vert-adv-y") != null) f.vert_adv_y = Float.parseFloat(h.get("vert-adv-y").toString());
+
+ } else if (name.equals("hkern")) {
+ //FIXME
+
+ } else if (name.equals("vkern")) {
+ //FIXME
+
+ } else if (name.equals("font-face")) {
+ //FIXME
+
+ } else if (name.equals("glyph") || name.equals("missing-glyph")) {
+ String glyphName = name.equals("missing-glyph") ? "missing-glyph" : (String)h.get("glyph-name");
+ SVG.Font.Glyph g = new SVG.Font.Glyph(glyphName, (String)h.get("unicode"), t, currentFont);
+ if (h.get("horiz-adv-x") != null) g.horiz_adv_x = Float.parseFloat(h.get("horiz-adv-x").toString());
+ if (h.get("vert-origin-x") != null) g.vert_origin_x = Float.parseFloat(h.get("vert-origin-x").toString());
+ if (h.get("vert-origin-y") != null) g.vert_origin_y = Float.parseFloat(h.get("vert-origin-y").toString());
+ if (h.get("vert-adv-y") != null) g.vert_adv_y = Float.parseFloat(h.get("vert-adv-y").toString());
+ if ("v".equals(h.get("orientation"))) g.isVerticallyOriented = true;
+
+ } else if (name.equals("svg")) {
+ // FIXME: handle percentages
+ // FIXME: what if these aren't provided?
+ // FIXME (in general)
+ float x = Float.parseFloat(h.get("x").toString());
+ float y = Float.parseFloat(h.get("y").toString());
+ float width = Float.parseFloat(h.get("width").toString());
+ float height = Float.parseFloat(h.get("height").toString());
+ h.put("viewBox", x + ", " + y + ", " + (x + width) + ", " + (y + height));
+ path = "";
+
+ } else if (name.equals("path")) {
+ path = h.get("d").toString();
+
+ } else if (name.equals("rect")) {
+ float x = Float.parseFloat(h.get("x").toString());
+ float y = Float.parseFloat(h.get("y").toString());
+ float width = Float.parseFloat(h.get("width").toString());
+ float height = Float.parseFloat(h.get("height").toString());
+ float rx = Float.parseFloat(h.get("rx").toString());
+ float ry = Float.parseFloat(h.get("ry").toString());
+ path =
+ "M" + (x + rx) + "," + y +
+ "H" + (x + width - rx) +
+ "A" + rx + "," + rx + ",0,0,1," + (x + width) + "," + (y + ry) +
+ "V" + (y + width - ry) +
+ "A" + rx + "," + rx + ",0,0,1," + (x + width - rx) + "," +
+ (y + height) +
+ "H" + (x + rx) +
+ "A" + rx + "," + rx + ",0,0,1," + x + "," + (y + height - ry) +
+ "V" + (y + ry) +
+ "A" + rx + "," + rx + ",0,0,1," + (x + rx) + "," + (y + ry) +
+ "Z";
+
+ } else if (name.equals("circle")) {
+ float r = Float.parseFloat(h.get("r").toString());
+ float cx = Float.parseFloat(h.get("cx").toString());
+ float cy = Float.parseFloat(h.get("cy").toString());
+ path = "A " + r + " " + r + " 1 1 " + cx + " " + cy;
+
+ } else if (name.equals("ellipse")) {
+ float rx = Float.parseFloat(h.get("rx").toString());
+ float ry = Float.parseFloat(h.get("ry").toString());
+ float cx = Float.parseFloat(h.get("cx").toString());
+ float cy = Float.parseFloat(h.get("cy").toString());
+ path = "A " + rx + " " + ry + " 1 1 " + cx + " " + cy;
+
+ } else if (name.equals("line")) {
+ float x1 = Float.parseFloat(h.get("x1").toString());
+ float y1 = Float.parseFloat(h.get("y1").toString());
+ float x2 = Float.parseFloat(h.get("x2").toString());
+ float y2 = Float.parseFloat(h.get("y2").toString());
+ path = "M " + x1 + " " + y1 + " L " + x2 + " " + y2;
+
+ } else if (name.equals("polyline") || name.equals("polygon")) {
+ StringTokenizer st = new StringTokenizer(h.get("points").toString(), ", ", false);
+ String s = "M ";
+ while(st.hasMoreTokens()) s += st.nextToken() + " " + st.nextToken() + " ";
+ path = s + (name.equals("polygon") ? "z" : "");
+
+ } else {
+ Log.log(SVG.class, "unknown element in SVG namespace: " + name);
+ }
+ props.put("path", path);
+ t.keys = new String[props.size()];
+ System.arraycopy(props.keys(), 0, t.keys, 0, t.keys.length);
+ t.vals = new String[props.size()];
+ for(int i=0; i<t.keys.length; i++) t.vals[i] = props.get(t.keys[i]);
+
+
+ // FIXME!!!!
+ if (h.get("viewBox") != null) {
+ StringTokenizer st = new StringTokenizer(h.get("viewBox").toString(), ", ", false);
+ if (t.transform == null) t.transform = "";
+ Point p1, p2;
+ SVG.RasterPath.fromString(path).getBoundingBox(p1, p2);
+
+ float minx = st.parseFloat();
+ float miny = st.parseFloat();
+ float width = st.parseFloat();
+ float height = st.parseFloat();
+ t.transform += "translate(" + (-1 * p1.x) + ", " + (-1 * p1.y) + ") " +
+ "scale(" + ((p2.x - p1.x) / width) + ", " + ((p2.y - p1.y) / height) + ") " +
+ "translate(" + minx + ", " + miny + ") ";
+
+ // FIXME: preserveAspectRatio
+ }
+
+ }
+
+
+ public static class Font {
+ Font() { }
+ float horiz_origin_x = 0, horiz_origin_y = 0, horiz_adv_x = 0;
+ float vert_origin_x = 0, vert_origin_y = 0, vert_adv_y = 0;
+
+ // FIXME: avoid using substring() in here ore creating any objects
+ public void render(String text, DoubleBuffer buf, int x, int y, int fillcolor, int strokecolor, int size) {
+ // FIXME: points, not pixels
+ Affine a = buf.a;
+ float scaleFactor = (float)(1.0/1000.0) * (float)size;
+ for(int pos=0; pos<text.length(); pos++) {
+ Glyph g;
+ for(g = (Glyph)glyphByUnicode.get(text.substring(pos, pos+1));
+ g != null && !g.unicode.equals(text.substring(pos, pos + g.unicode.length()));
+ g = g.next);
+ if (g == null) {
+ g = (Glyph)glyphByName.get("missing-glyph");
+ } else {
+ pos += g.unicode.length() - 1;
+ }
+ if (g != null) {
+ System.out.println(" " + g.unicode);
+ g.render(buf, x, y, fillcolor, strokecolor, scaleFactor);
+ x += (int)(g.horiz_adv_x * size / 1000.0);
+ } else {
+ x += (int)(horiz_adv_x * size / 1000.0);
+ }
+ }
+ buf.setTransform(a);
+ }
+
+ / ** all glyphs, keyed by their <tt>name</tt> property * /
+ Hashtable glyphByName = new Hashtable();
+
+ / ** linked list of glyphs, stored by the first character of their <tt>unicode</tt> property * /
+ Hashtable glyphByUnicode = new Hashtable();
+
+ / ** a Glyph in an SVG font * /
+ public static class Glyph {
+
+ // FIXME: lang attribute
+ boolean isVerticallyOriented = false;
+ Template t = null;
+ Box b = null;
+
+ float horiz_adv_x = 0;
+ float vert_origin_x = 0;
+ float vert_origin_y = 0;
+ float vert_adv_y = 0;
+
+ String unicode = null;
+
+ / ** forms the linked list in glyphByUnicode; glyphs appear in the order specified in the font * /
+ public Glyph next = null;
+
+ Glyph(String name, String unicode, Template t, SVG.Font f) {
+ if (unicode != null)
+ if (f.glyphByUnicode.get(unicode.substring(0, 1)) == null) {
+ f.glyphByUnicode.put(unicode.substring(0, 1), this);
+ } else {
+ Glyph g;
+ for(g = (Glyph)f.glyphByUnicode.get(unicode.substring(0, 1)); g.next != null; g = g.next);
+ g.next = this;
+ }
+ if (name != null) f.glyphByUnicode.put(name, this);
+ this.unicode = unicode;
+ this.t = t;
+ horiz_adv_x = f.horiz_adv_x;
+ vert_origin_x = f.vert_origin_x;
+ vert_origin_y = f.vert_origin_y;
+ vert_adv_y = f.vert_adv_y;
+ }
+ public void render(DoubleBuffer buf, int x, int y, int fillcolor, int strokecolor, float scaleFactor) {
+ // FEATURE: make b double-buffered for increased performance
+ if (b == null) {
+ b = new Box(t, new org.xwt.util.Vec(), new org.xwt.util.Vec(), null, 0, 0);
+ b.put("absolute", Boolean.TRUE);
+ b.prerender();
+ t = null;
+ }
+ // FIXME
+ b.put("width", new Integer(1000));
+ b.put("height", new Integer(1000));
+ b.fillcolor = fillcolor;
+ b.strokecolor = strokecolor;
+
+ // we toss an extra flip on the ctm so that fonts stick "up" instead of down
+ b.render(0, 0, buf.getWidth(), buf.getHeight(), buf,
+ Affine.flip(false, true).multiply(Affine.scale(scaleFactor, scaleFactor).multiply(Affine.translate(x, y))).multiply(buf.a));
+ }
+ }
+ }
+
+ // Affine //////////////////////////////////////////////////////////////////////////////
+
+ / ** an affine transform; all operations are destructive * /
+ public static final class Affine {
+
+ // [ a b e ]
+ // [ c d f ]
+ // [ 0 0 1 ]
+ public float a, b, c, d, e, f;
+
+ Affine(float _a, float _b, float _c, float _d, float _e, float _f) { a = _a; b = _b; c = _c; d = _d; e = _e; f = _f; }
+ public String toString() { return "[ " + a + ", " + b + ", " + c + ", " + d + ", " + e + ", " + f + " ]"; }
+ public Affine copy() { return new Affine(a, b, c, d, e, f); }
+ public static Affine identity() { return new Affine(1, 0, 0, 1, 0, 0); }
+ public static Affine scale(float sx, float sy) { return new Affine(sx, 0, 0, sy, 0, 0); }
+ public static Affine shear(float degrees) {
+ return new Affine(1, 0, (float)Math.tan(degrees * (float)(Math.PI / 180.0)), 1, 0, 0); }
+ public static Affine translate(float tx, float ty) { return new Affine(1, 0, 0, 1, tx, ty); }
+ public static Affine flip(boolean horiz, boolean vert) { return new Affine(horiz ? -1 : 1, 0, 0, vert ? -1 : 1, 0, 0); }
+ public float multiply_px(float x, float y) { return x * a + y * c + e; }
+ public float multiply_py(float x, float y) { return x * b + y * d + f; }
+
+ public static Affine rotate(float degrees) {
+ float s = (float)Math.sin(degrees * (float)(Math.PI / 180.0));
+ float c = (float)Math.cos(degrees * (float)(Math.PI / 180.0));
+ return new Affine(c, s, -s, c, 0, 0);
+ }
+
+ / ** this = this * a * /
+ public Affine multiply(Affine A) {
+ float _a = this.a * A.a + this.b * A.c;
+ float _b = this.a * A.b + this.b * A.d;
+ float _c = this.c * A.a + this.d * A.c;
+ float _d = this.c * A.b + this.d * A.d;
+ float _e = this.e * A.a + this.f * A.c + A.e;
+ float _f = this.e * A.b + this.f * A.d + A.f;
+ a = _a; b = _b; c = _c; d = _d; e = _e; f = _f;
+ return this;
+ }
+
+ public void invert() {
+ float det = 1 / (a * d - b * c);
+ float _a = d * det;
+ float _b = -1 * b * det;
+ float _c = -1 * c * det;
+ float _d = a * det;
+ float _e = -1 * e * a - f * c;
+ float _f = -1 * e * b - f * d;
+ a = _a; b = _b; c = _c; d = _d; e = _e; f = _f;
+ }
+ }
+
+
+ // PathTokenizer //////////////////////////////////////////////////////////////////////////////
+
+ public static final float PX_PER_INCH = 72;
+ public static final float INCHES_PER_CM = (float)0.3937;
+ public static final float INCHES_PER_MM = INCHES_PER_CM / 10;
+
+ public static class PathTokenizer {
+ // FIXME: check array bounds exception for improperly terminated string
+ String s;
+ int i = 0;
+ char lastCommand = 'M';
+ public PathTokenizer(String s) { this.s = s; }
+ private void consumeWhitespace() {
+ while(i < s.length() && (Character.isWhitespace(s.charAt(i)))) i++;
+ if (i < s.length() && s.charAt(i) == ',') i++;
+ while(i < s.length() && (Character.isWhitespace(s.charAt(i)))) i++;
+ }
+ public boolean hasMoreTokens() { consumeWhitespace(); return i < s.length(); }
+ public char parseCommand() {
+ consumeWhitespace();
+ char c = s.charAt(i);
+ if (!Character.isLetter(c)) return lastCommand;
+ i++;
+ return lastCommand = c;
+ }
+ public float parseFloat() {
+ consumeWhitespace();
+ int start = i;
+ float multiplier = 1;
+ for(; i < s.length(); i++) {
+ char c = s.charAt(i);
+ if (Character.isWhitespace(c) || c == ',' || (c == '-' && i != start)) break;
+ if (!((c >= '0' && c <= '9') || c == '.' || c == 'e' || c == 'E' || c == '-')) {
+ if (c == '%') { // FIXME
+ } else if (s.regionMatches(i, "pt", 0, i+2)) { // FIXME
+ } else if (s.regionMatches(i, "em", 0, i+2)) { // FIXME
+ } else if (s.regionMatches(i, "pc", 0, i+2)) { // FIXME
+ } else if (s.regionMatches(i, "ex", 0, i+2)) { // FIXME
+ } else if (s.regionMatches(i, "mm", 0, i+2)) { i += 2; multiplier = INCHES_PER_MM * PX_PER_INCH; break;
+ } else if (s.regionMatches(i, "cm", 0, i+2)) { i += 2; multiplier = INCHES_PER_CM * PX_PER_INCH; break;
+ } else if (s.regionMatches(i, "in", 0, i+2)) { i += 2; multiplier = PX_PER_INCH; break;
+ } else if (s.regionMatches(i, "px", 0, i+2)) { i += 2; break;
+ } else if (Character.isLetter(c)) break;
+ throw new RuntimeException("didn't expect character \"" + c + "\" in a numeric constant");
+ }
+ }
+ if (start == i) throw new RuntimeException("FIXME");
+ return Float.parseFloat(s.substring(start, i)) * multiplier;
+ }
+ }
+
+
+ // Abstract Path //////////////////////////////////////////////////////////////////////////////
+
+ / ** an abstract path; may contain splines and arcs * /
+ public static class VectorPath {
+
+ // the number of vertices on this path
+ int numvertices = 0;
+
+ // the vertices of the path
+ float[] x = new float[DEFAULT_PATHLEN];
+ float[] y = new float[DEFAULT_PATHLEN];
+
+ // the type of each edge; type[i] is the type of the edge from x[i],y[i] to x[i+1],y[i+1]
+ byte[] type = new byte[DEFAULT_PATHLEN];
+
+ // bezier control points
+ float[] c1x = new float[DEFAULT_PATHLEN]; // or rx (arcto)
+ float[] c1y = new float[DEFAULT_PATHLEN]; // or ry (arcto)
+ float[] c2x = new float[DEFAULT_PATHLEN]; // or x-axis-rotation (arcto)
+ float[] c2y = new float[DEFAULT_PATHLEN]; // or large-arc << 1 | sweep (arcto)
+
+ boolean closed = false;
+
+ static final byte TYPE_MOVETO = 0;
+ static final byte TYPE_LINETO = 1;
+ static final byte TYPE_ARCTO = 2;
+ static final byte TYPE_CUBIC = 3;
+ static final byte TYPE_QUADRADIC = 4;
+
+ / ** Creates a concrete vector path transformed through the given matrix. * /
+ public RasterPath realize(Affine a) {
+
+ RasterPath ret = new RasterPath();
+ int NUMSTEPS = 5; // FIXME
+ ret.numvertices = 1;
+ ret.x[0] = (int)Math.round(a.multiply_px(x[0], y[0]));
+ ret.y[0] = (int)Math.round(a.multiply_py(x[0], y[0]));
+
+ for(int i=1; i<numvertices; i++) {
+ if (type[i] == TYPE_LINETO) {
+ float rx = x[i];
+ float ry = y[i];
+ ret.x[ret.numvertices] = (int)Math.round(a.multiply_px(rx, ry));
+ ret.y[ret.numvertices] = (int)Math.round(a.multiply_py(rx, ry));
+ ret.edges[ret.numedges++] = ret.numvertices - 1; ret.numvertices++;
+
+ } else if (type[i] == TYPE_MOVETO) {
+ float rx = x[i];
+ float ry = y[i];
+ ret.x[ret.numvertices] = (int)Math.round(a.multiply_px(rx, ry));
+ ret.y[ret.numvertices] = (int)Math.round(a.multiply_py(rx, ry));
+ ret.numvertices++;
+
+ } else if (type[i] == TYPE_ARCTO) {
+ float rx = c1x[i];
+ float ry = c1y[i];
+ float phi = c2x[i];
+ float fa = ((int)c2y[i]) >> 1;
+ float fs = ((int)c2y[i]) & 1;
+ float x1 = x[i];
+ float y1 = y[i];
+ float x2 = x[i+1];
+ float y2 = y[i+1];
+
+ // F.6.5: given x1,y1,x2,y2,fa,fs, compute cx,cy,theta1,dtheta
+ float x1_ = (float)Math.cos(phi) * (x1 - x2) / 2 + (float)Math.sin(phi) * (y1 - y2) / 2;
+ float y1_ = -1 * (float)Math.sin(phi) * (x1 - x2) / 2 + (float)Math.cos(phi) * (y1 - y2) / 2;
+ float tmp = (float)Math.sqrt((rx * rx * ry * ry - rx * rx * y1_ * y1_ - ry * ry * x1_ * x1_) /
+ (rx * rx * y1_ * y1_ + ry * ry * x1_ * x1_));
+ float cx_ = (fa == fs ? -1 : 1) * tmp * (rx * y1_ / ry);
+ float cy_ = (fa == fs ? -1 : 1) * -1 * tmp * (ry * x1_ / rx);
+ float cx = (float)Math.cos(phi) * cx_ - (float)Math.sin(phi) * cy_ + (x1 + x2) / 2;
+ float cy = (float)Math.sin(phi) * cx_ + (float)Math.cos(phi) * cy_ + (y1 + y2) / 2;
+
+ // F.6.4 Conversion from center to endpoint parameterization
+ float ux = 1, uy = 0, vx = (x1_ - cx_) / rx, vy = (y1_ - cy_) / ry;
+ float det = ux * vy - uy * vx;
+ float theta1 = (det < 0 ? -1 : 1) *
+ (float)Math.acos((ux * vx + uy * vy) /
+ ((float)Math.sqrt(ux * ux + uy * uy) * (float)Math.sqrt(vx * vx + vy * vy)));
+ ux = (x1_ - cx_) / rx; uy = (y1_ - cy_) / ry;
+ vx = (-1 * x1_ - cx_) / rx; vy = (-1 * y1_ - cy_) / ry;
+ det = ux * vy - uy * vx;
+ float dtheta = (det < 0 ? -1 : 1) *
+ (float)Math.acos((ux * vx + uy * vy) /
+ ((float)Math.sqrt(ux * ux + uy * uy) * (float)Math.sqrt(vx * vx + vy * vy)));
+ dtheta = dtheta % (float)(2 * Math.PI);
+
+ if (fs == 0 && dtheta > 0) theta1 -= 2 * PI;
+ if (fs == 1 && dtheta < 0) theta1 += 2 * PI;
+
+ if (fa == 1 && dtheta < 0) dtheta = 2 * PI + dtheta;
+ else if (fa == 1 && dtheta > 0) dtheta = -1 * (2 * PI - dtheta);
+
+ // FIXME: integrate F.6.6
+ // FIXME: isn't quite ending where it should...
+
+ // F.6.3: Parameterization alternatives
+ float theta = theta1;
+ for(int j=0; j<NUMSTEPS; j++) {
+ float rasterx = rx * (float)Math.cos(theta) * (float)Math.cos(phi) -
+ ry * (float)Math.sin(theta) * (float)Math.sin(phi) + cx;
+ float rastery = rx * (float)Math.cos(theta) * (float)Math.sin(phi) +
+ ry * (float)Math.cos(phi) * (float)Math.sin(theta) + cy;
+ ret.x[ret.numvertices] = (int)Math.round(a.multiply_px(rasterx, rastery));
+ ret.y[ret.numvertices] = (int)Math.round(a.multiply_py(rasterx, rastery));
+ ret.edges[ret.numedges++] = ret.numvertices - 1; ret.numvertices++;
+ theta += dtheta / NUMSTEPS;
+ }
+
+ } else if (type[i] == TYPE_CUBIC) {
+
+ float ax = x[i+1] - 3 * c2x[i] + 3 * c1x[i] - x[i];
+ float bx = 3 * c2x[i] - 6 * c1x[i] + 3 * x[i];
+ float cx = 3 * c1x[i] - 3 * x[i];
+ float dx = x[i];
+ float ay = y[i+1] - 3 * c2y[i] + 3 * c1y[i] - y[i];
+ float by = 3 * c2y[i] - 6 * c1y[i] + 3 * y[i];
+ float cy = 3 * c1y[i] - 3 * y[i];
+ float dy = y[i];
+
+ for(float t=0; t<1; t += 1 / (float)NUMSTEPS) {
+ float rx = ax * t * t * t + bx * t * t + cx * t + dx;
+ float ry = ay * t * t * t + by * t * t + cy * t + dy;
+ ret.x[ret.numvertices] = (int)Math.round(a.multiply_px(rx, ry));
+ ret.y[ret.numvertices] = (int)Math.round(a.multiply_py(rx, ry));
+ ret.edges[ret.numedges++] = ret.numvertices - 1; ret.numvertices++;
+ }
+
+
+ } else if (type[i] == TYPE_QUADRADIC) {
+
+ float bx = x[i+1] - 2 * c1x[i] + x[i];
+ float cx = 2 * c1x[i] - 2 * x[i];
+ float dx = x[i];
+ float by = y[i+1] - 2 * c1y[i] + y[i];
+ float cy = 2 * c1y[i] - 2 * y[i];
+ float dy = y[i];
+
+ for(float t=0; t<1; t += 1 / (float)NUMSTEPS) {
+ float rx = bx * t * t + cx * t + dx;
+ float ry = by * t * t + cy * t + dy;
+ ret.x[ret.numvertices] = (int)Math.round(a.multiply_px(rx, ry));
+ ret.y[ret.numvertices] = (int)Math.round(a.multiply_py(rx, ry));
+ ret.edges[ret.numedges++] = ret.numvertices - 1; ret.numvertices++;
+ }
+
+ }
+
+ }
+
+ if (ret.numedges > 0) ret.sort(0, ret.numedges - 1, false);
+ return ret;
+ }
+
+ protected void parseSingleCommandAndArguments(PathTokenizer t, char command, boolean relative) {
+ if (numvertices == 0 && command != 'm') throw new RuntimeException("first command MUST be an 'm'");
+ if (numvertices > x.length - 2) {
+ float[] new_x = new float[x.length * 2]; System.arraycopy(x, 0, new_x, 0, x.length); x = new_x;
+ float[] new_y = new float[y.length * 2]; System.arraycopy(y, 0, new_y, 0, y.length); y = new_y;
+ }
+ switch(command) {
+ case 'z': {
+ int where;
+ type[numvertices-1] = TYPE_LINETO;
+ for(where = numvertices - 1; where > 0; where--)
+ if (type[where - 1] == TYPE_MOVETO) break;
+ x[numvertices] = x[where];
+ y[numvertices] = y[where];
+ numvertices++;
+ closed = true;
+ break;
+ }
+
+ case 'm': {
+ if (numvertices > 0) type[numvertices-1] = TYPE_MOVETO;
+ x[numvertices] = t.parseFloat() + (relative ? x[numvertices - 1] : 0);
+ y[numvertices] = t.parseFloat() + (relative ? y[numvertices - 1] : 0);
+ numvertices++;
+ break;
+ }
+
+ case 'l': case 'h': case 'v': {
+ type[numvertices-1] = TYPE_LINETO;
+ float first = t.parseFloat(), second;
+ if (command == 'h') {
+ second = relative ? 0 : y[numvertices - 1];
+ } else if (command == 'v') {
+ second = first; first = relative ? 0 : x[numvertices - 1];
+ } else {
+ second = t.parseFloat();
+ }
+ x[numvertices] = first + (relative ? x[numvertices - 1] : 0);
+ y[numvertices] = second + (relative ? y[numvertices - 1] : 0);
+ numvertices++;
+ break;
+ }
+
+ case 'a': {
+ type[numvertices-1] = TYPE_ARCTO;
+ c1x[numvertices-1] = t.parseFloat() + (relative ? x[numvertices - 1] : 0);
+ c1y[numvertices-1] = t.parseFloat() + (relative ? y[numvertices - 1] : 0);
+ c2x[numvertices-1] = (t.parseFloat() / 360) * 2 * PI;
+ c2y[numvertices-1] = (((int)t.parseFloat()) << 1) | (int)t.parseFloat();
+ x[numvertices] = t.parseFloat() + (relative ? x[numvertices - 1] : 0);
+ y[numvertices] = t.parseFloat() + (relative ? y[numvertices - 1] : 0);
+ numvertices++;
+ break;
+ }
+
+ case 's': case 'c': {
+ type[numvertices-1] = TYPE_CUBIC;
+ if (command == 'c') {
+ c1x[numvertices-1] = t.parseFloat() + (relative ? x[numvertices - 1] : 0);
+ c1y[numvertices-1] = t.parseFloat() + (relative ? y[numvertices - 1] : 0);
+ } else if (numvertices > 1 && type[numvertices-2] == TYPE_CUBIC) {
+ c1x[numvertices-1] = 2 * x[numvertices - 1] - c2x[numvertices-2];
+ c1y[numvertices-1] = 2 * y[numvertices - 1] - c2y[numvertices-2];
+ } else {
+ c1x[numvertices-1] = x[numvertices-1];
+ c1y[numvertices-1] = y[numvertices-1];
+ }
+ c2x[numvertices-1] = t.parseFloat() + (relative ? x[numvertices - 1] : 0);
+ c2y[numvertices-1] = t.parseFloat() + (relative ? y[numvertices - 1] : 0);
+ x[numvertices] = t.parseFloat() + (relative ? x[numvertices - 1] : 0);
+ y[numvertices] = t.parseFloat() + (relative ? y[numvertices - 1] : 0);
+ numvertices++;
+ break;
+ }
+
+ case 't': case 'q': {
+ type[numvertices-1] = TYPE_QUADRADIC;
+ if (command == 'q') {
+ c1x[numvertices-1] = t.parseFloat() + (relative ? x[numvertices - 1] : 0);
+ c1y[numvertices-1] = t.parseFloat() + (relative ? y[numvertices - 1] : 0);
+ } else if (numvertices > 1 && type[numvertices-2] == TYPE_QUADRADIC) {
+ c1x[numvertices-1] = 2 * x[numvertices - 1] - c1x[numvertices-2];
+ c1y[numvertices-1] = 2 * y[numvertices - 1] - c1y[numvertices-2];
+ } else {
+ c1x[numvertices-1] = x[numvertices-1];
+ c1y[numvertices-1] = y[numvertices-1];
+ }
+ x[numvertices] = t.parseFloat() + (relative ? x[numvertices - 1] : 0);
+ y[numvertices] = t.parseFloat() + (relative ? y[numvertices - 1] : 0);
+ numvertices++;
+ break;
+ }
+
+ default:
+ // FIXME
+ }
+ / *
+ // invariant: after this loop, no two lines intersect other than at a vertex
+ // FIXME: cleanup
+ int index = numvertices - 2;
+ for(int i=0; i<Math.min(numvertices - 3, index); i++) {
+ for(int j = index; j < numvertices - 1; j++) {
+
+ // I'm not sure how to deal with vertical lines...
+ if (x[i+1] == x[i] || x[j+1] == x[j]) continue;
+
+ float islope = (y[i+1] - y[i]) / (x[i+1] - x[i]);
+ float jslope = (y[j+1] - y[j]) / (x[j+1] - x[j]);
+ if (islope == jslope) continue; // parallel lines can't intersect
+
+ float _x = (islope * x[i] - jslope * x[j] + y[j] - y[i]) / (islope - jslope);
+ float _y = islope * (_x - x[i]) + y[i];
+
+ if (_x > Math.min(x[i+1], x[i]) && _x < Math.max(x[i+1], x[i]) &&
+ _x > Math.min(x[j+1], x[j]) && _x < Math.max(x[j+1], x[j])) {
+ // FIXME: something's not right in here. See if we can do without fracturing line 'i'.
+ for(int k = ++numvertices; k>i; k--) { x[k] = x[k - 1]; y[k] = y[k - 1]; }
+ x[i+1] = _x;
+ y[i+1] = _y;
+ x[numvertices] = x[numvertices - 1]; x[numvertices - 1] = _x;
+ y[numvertices] = y[numvertices - 1]; y[numvertices - 1] = _y;
+ edges[numedges++] = numvertices - 1; numvertices++;
+ index++;
+ break; // actually 'continue' the outermost loop
+ }
+ }
+ }
+ * /
+
+ }
+ }
+
+
+
+
+ // Concrete Vector Path //////////////////////////////////////////////////////////////////////////////
+
+ / ** a vector path * /
+ public static class RasterPath {
+
+ // the vertices of this path
+ int[] x = new int[DEFAULT_PATHLEN];
+ int[] y = new int[DEFAULT_PATHLEN];
+ int numvertices = 0;
+
+ / **
+ * A list of the vertices on this path which *start* an edge (rather than a moveto), sorted by increasing y.
+ * example: x[edges[1]],y[edges[1]] - x[edges[i]+1],y[edges[i]+1] is the second-topmost edge
+ * note that if x[i],y[i] - x[i+1],y[i+1] is a MOVETO, then no element in edges will be equal to i
+ * /
+ int[] edges = new int[DEFAULT_PATHLEN];
+ int numedges = 0;
+
+ / ** FIXME: if a path is closed "manually" you get caps on the ends; otherwise you get a marker... * /
+ boolean closed = false;
+
+ / ** simple quicksort, from http://sourceforge.net/snippet/detail.php?type=snippet&id=100240 * /
+ int sort(int left, int right, boolean partition) {
+ if (partition) {
+ int i, j, middle;
+ middle = (left + right) / 2;
+ int s = edges[right]; edges[right] = edges[middle]; edges[middle] = s;
+ for (i = left - 1, j = right; ; ) {
+ while (y[edges[++i]] < y[edges[right]]);
+ while (j > left && y[edges[--j]] > y[edges[right]]);
+ if (i >= j) break;
+ s = edges[i]; edges[i] = edges[j]; edges[j] = s;
+ }
+ s = edges[right]; edges[right] = edges[i]; edges[i] = s;
+ return i;
+ } else {
+ if (left >= right) return 0;
+ int p = sort(left, right, true);
+ sort(left, p - 1, false);
+ sort(p + 1, right, false);
+ return 0;
+ }
+ }
+
+ / ** finds the x value at which the line intercepts the line y=_y * /
+ private int intercept(int i, float _y, boolean includeTop, boolean includeBottom) {
+ if (includeTop ? (_y < Math.min(y[i], y[i+1])) : (_y <= Math.min(y[i], y[i+1])))
+ return Integer.MIN_VALUE;
+ if (includeBottom ? (_y > Math.max(y[i], y[i+1])) : (_y >= Math.max(y[i], y[i+1])))
+ return Integer.MIN_VALUE;
+ return (int)Math.round((((float)(x[i + 1] - x[i])) /
+ ((float)(y[i + 1] - y[i])) ) * ((float)(_y - y[i])) + x[i]);
+ }
+
+ / ** fill the interior of the path * /
+ public void fill(DoubleBuffer buf, RasterPath pen, Paint paint) {
+ if (numedges == 0) return;
+ int y0 = y[edges[0]], y1 = y0;
+ boolean useEvenOdd = false;
+
+ // we iterate over all endpoints in increasing y-coordinate order
+ for(int index = 1; index<numedges; index++) {
+ int count = 0;
+
+ // we now examine the horizontal band between y=y0 and y=y1
+ y0 = y1;
+ y1 = y[edges[index]];
+ if (y0 == y1) continue;
+
+ // within this band, we iterate over all edges
+ int x0 = Integer.MIN_VALUE;
+ int leftSegment = -1;
+ while(true) {
+ int x1 = Integer.MAX_VALUE;
+ int rightSegment = Integer.MAX_VALUE;
+ for(int i=0; i<numedges; i++) {
+ if (y[edges[i]] == y[edges[i]+1]) continue; // ignore horizontal lines; they are irrelevant.
+ // we order the segments by the x-coordinate of their midpoint;
+ // since segments cannot intersect, this is a well-ordering
+ int i0 = intercept(edges[i], y0, true, false);
+ int i1 = intercept(edges[i], y1, false, true);
+ if (i0 == Integer.MIN_VALUE || i1 == Integer.MIN_VALUE) continue;
+ int midpoint = i0 + i1;
+ if (midpoint < x0) continue;
+ if (midpoint == x0 && i <= leftSegment) continue;
+ if (midpoint > x1) continue;
+ if (midpoint == x1 && i >= rightSegment) continue;
+ rightSegment = i;
+ x1 = midpoint;
+ }
+ if (leftSegment == rightSegment || rightSegment == Integer.MAX_VALUE) break;
+ if (leftSegment != -1)
+ if ((useEvenOdd && count % 2 != 0) || (!useEvenOdd && count != 0))
+ paint.fillTrapezoid(intercept(edges[leftSegment], y0, true, true),
+ intercept(edges[rightSegment], y0, true, true), y0,
+ intercept(edges[leftSegment], y1, true, true),
+ intercept(edges[rightSegment], y1, true, true), y1,
+ buf);
+ if (useEvenOdd) count++;
+ else count += (y[edges[rightSegment]] < y[edges[rightSegment]+1]) ? -1 : 1;
+ leftSegment = rightSegment; x0 = x1;
+ }
+ }
+ }
+
+ / ** stroke the outline of the path * /
+ public void stroke(DoubleBuffer buf, int width, int color, boolean mitre,
+ String dashArray, int dashOffset, float segLength) {
+ if (dashArray != null) {
+ float ratio = 1;
+ if (segLength > 0) {
+ float actualLength = 0;
+ for(int i=0; i<numvertices; i++) {
+ // skip over MOVETOs -- they do not contribute to path length
+ if (x[i] == x[i+1] && y[i] == y[i+1]) continue;
+ if (x[i+1] == x[i+2] && y[i+1] == y[i+2]) continue;
+ int x1 = x[i];
+ int x2 = x[i + 1];
+ int y1 = y[i];
+ int y2 = y[i + 1];
+ actualLength += java.lang.Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
+ }
+ ratio = actualLength / segLength;
+ }
+ PathTokenizer pt = new PathTokenizer(dashArray);
+ Vector v = new Vector();
+ while (pt.hasMoreTokens()) v.addElement(new Float(pt.parseFloat()));
+ float[] dashes = new float[v.size() % 2 == 0 ? v.size() : 2 * v.size()];
+ for(int i=0; i<dashes.length; i++) dashes[i] = ((Float)v.elementAt(i % v.size())).floatValue();
+ float length = 0;
+ int dashpos = dashOffset;
+ boolean on = dashpos % 2 == 0;
+ for(int i=0; i<numvertices; i++) {
+ // skip over MOVETOs -- they do not contribute to path length
+ if (x[i] == x[i+1] && y[i] == y[i+1]) continue;
+ if (x[i+1] == x[i+2] && y[i+1] == y[i+2]) continue;
+ int x1 = (int)x[i];
+ int x2 = (int)x[i + 1];
+ int y1 = (int)y[i];
+ int y2 = (int)y[i + 1];
+ float segmentLength = (float)java.lang.Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
+ int _x1 = x1, _y1 = y1;
+ float pos = 0;
+ do {
+ pos = Math.min(segmentLength, pos + dashes[dashpos] * ratio);
+ if (pos != segmentLength) dashpos = (dashpos + 1) % dashes.length;
+ int _x2 = (int)((x2 * pos + x1 * (segmentLength - pos)) / segmentLength);
+ int _y2 = (int)((y2 * pos + y1 * (segmentLength - pos)) / segmentLength);
+ if (on) buf.drawLine(_x1, _y1, _x2, _y2, width, color);
+ on = !on;
+ _x1 = _x2; _y1 = _y2;
+ } while(pos < segmentLength);
+ }
+
+ } else {
+ for(int i=0; i<numedges; i++)
+ buf.drawLine((int)x[edges[i]],
+ (int)y[edges[i]], (int)x[edges[i]+1], (int)y[edges[i]+1], width, color);
+ }
+ }
+ }
+
+
+ // Paint //////////////////////////////////////////////////////////////////////////////
+
+ public static interface Paint {
+ public abstract void
+ fillTrapezoid(int tx1, int tx2, int ty1, int tx3, int tx4, int ty2, DoubleBuffer buf);
+ }
+
+ public static class SingleColorPaint implements Paint {
+ int color;
+ public SingleColorPaint(int color) { this.color = color; }
+ public void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, DoubleBuffer buf) {
+ buf.fillTrapezoid(x1, x2, y1, x3, x4, y2, color);
+ }
+ }
+ / *
+ public static abstract class GradientPaint extends Paint {
+ public GradientPaint(boolean reflect, boolean repeat, Affine gradientTransform,
+ int[] stop_colors, float[] stop_offsets) {
+ this.reflect = reflect; this.repeat = repeat;
+ this.gradientTransform = gradientTransform;
+ this.stop_colors = stop_colors;
+ this.stop_offsets = stop_offsets;
+ }
+ Affine gradientTransform = Affine.identity();
+ boolean useBoundingBox = false; // FIXME not supported
+ boolean patternUseBoundingBox = false; // FIXME not supported
+
+ // it's invalid for both of these to be true
+ boolean reflect = false; // FIXME not supported
+ boolean repeat = false; // FIXME not supported
+ int[] stop_colors;
+ float[] stop_offsets;
+
+ public void fillTrapezoid(float tx1, float tx2, float ty1, float tx3, float tx4, float ty2, DoubleBuffer buf) {
+ Affine a = buf.a;
+ Affine inverse = a.copy().invert();
+ float slope1 = (tx3 - tx1) / (ty2 - ty1);
+ float slope2 = (tx4 - tx2) / (ty2 - ty1);
+ for(float y=ty1; y<ty2; y++) {
+ float _x1 = (y - ty1) * slope1 + tx1;
+ float _x2 = (y - ty1) * slope2 + tx2;
+ if (_x1 > _x2) { float _x0 = _x1; _x1 = _x2; _x2 = _x0; }
+
+ for(float x=_x1; x<_x2; x++) {
+
+ float distance = isLinear ?
+ // length of projection of <x,y> onto the gradient vector == {<x,y> \dot {grad \over |grad|}}
+ (x * (x2 - x1) + y * (y2 - y1)) / (float)Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) :
+
+ // radial form is simple! FIXME, not quite right
+ (float)Math.sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy));
+
+ // FIXME: offsets are 0..1, not 0..length(gradient)
+ int i = 0; for(; i<stop_offsets.length; i++) if (distance < stop_offsets[i]) break;
+
+ // FIXME: handle points beyond the bounds
+ if (i < 0 || i >= stop_offsets.length) continue;
+
+ // gradate from offsets[i - 1] to offsets[i]
+ float percentage = ((distance - stop_offsets[i - 1]) / (stop_offsets[i] - stop_offsets[i - 1]));
+
+ int a = (int)((((stop_colors[i] >> 24) & 0xff) - ((stop_colors[i - 1] >> 24) & 0xff)) * percentage) +
+ ((stop_colors[i - 1] >> 24) & 0xff);
+ int r = (int)((((stop_colors[i] >> 16) & 0xff) - ((stop_colors[i - 1] >> 16) & 0xff)) * percentage) +
+ ((stop_colors[i - 1] >> 16) & 0xff);
+ int g = (int)((((stop_colors[i] >> 8) & 0xff) - ((stop_colors[i - 1] >> 8) & 0xff)) * percentage) +
+ ((stop_colors[i - 1] >> 8) & 0xff);
+ int b = (int)((((stop_colors[i] >> 0) & 0xff) - ((stop_colors[i - 1] >> 0) & 0xff)) * percentage) +
+ ((stop_colors[i - 1] >> 0) & 0xff);
+ int argb = (a << 24) | (r << 16) | (g << 8) | b;
+ buf.drawPoint((int)x, (int)Math.floor(y), argb);
+ }
+ }
+ }
+ }
+
+ public static class LinearGradientPaint extends GradientPaint {
+ public LinearGradientPaint(float x1, float y1, float x2, float y2, boolean reflect, boolean repeat,
+ Affine gradientTransform, int[] stop_colors, float[] stop_offsets) {
+ super(reflect, repeat, gradientTransform, stop_colors, stop_offsets);
+ this.x1 = x1; this.x2 = x2; this.y1 = y1; this.y2 = y2;
+ }
+ float x1 = 0, y1 = 0, x2 = 300, y2 = 300;
+ }
+
+ public static class RadialGradientPaint extends GradientPaint {
+ public RadialGradientPaint(float cx, float cy, float fx, float fy, float r, boolean reflect, boolean repeat,
+ Affine gradientTransform, int[] stop_colors, float[] stop_offsets) {
+ super(reflect, repeat, gradientTransform, stop_colors, stop_offsets);
+ this.cx = cx; this.cy = cy; this.fx = fx; this.fy = fy; this.r = r;
+ }
+
+ float cx, cy, r, fx, fy;
+
+ }
+ * /
+
+ // Private Constants //////////////////////////////////////////////////////////////////////////////////
+
+ private static final int DEFAULT_PATHLEN = 1000;
+
+ / ** Copied verbatim from the SVG specification * /
+ public static Hashtable colors = new Hashtable(400);
+ static {
+ colors.put("aliceblue", new Integer((240 << 16) | (248 << 8) | 255));
+ colors.put("antiquewhite", new Integer((250 << 16) | (235 << 8) | 215));
+ colors.put("aqua", new Integer((0 << 16) | (255 << 8) | 255));
+ colors.put("aquamarine", new Integer((127 << 16) | (255 << 8) | 212));
+ colors.put("azure", new Integer((240 << 16) | (255 << 8) | 255));
+ colors.put("beige", new Integer((245 << 16) | (245 << 8) | 220));
+ colors.put("bisque", new Integer((255 << 16) | (228 << 8) | 196));
+ colors.put("black", new Integer((0 << 16) | (0 << 8) | 0));
+ colors.put("blanchedalmond", new Integer((255 << 16) | (235 << 8) | 205));
+ colors.put("blue", new Integer((0 << 16) | (0 << 8) | 255));
+ colors.put("blueviolet", new Integer((138 << 16) | (43 << 8) | 226));
+ colors.put("brown", new Integer((165 << 16) | (42 << 8) | 42));
+ colors.put("burlywood", new Integer((222 << 16) | (184 << 8) | 135));
+ colors.put("cadetblue", new Integer((95 << 16) | (158 << 8) | 160));
+ colors.put("chartreuse", new Integer((127 << 16) | (255 << 8) | 0));
+ colors.put("chocolate", new Integer((210 << 16) | (105 << 8) | 30));
+ colors.put("coral", new Integer((255 << 16) | (127 << 8) | 80));
+ colors.put("cornflowerblue", new Integer((100 << 16) | (149 << 8) | 237));
+ colors.put("cornsilk", new Integer((255 << 16) | (248 << 8) | 220));
+ colors.put("crimson", new Integer((220 << 16) | (20 << 8) | 60));
+ colors.put("cyan", new Integer((0 << 16) | (255 << 8) | 255));
+ colors.put("darkblue", new Integer((0 << 16) | (0 << 8) | 139));
+ colors.put("darkcyan", new Integer((0 << 16) | (139 << 8) | 139));
+ colors.put("darkgoldenrod", new Integer((184 << 16) | (134 << 8) | 11));
+ colors.put("darkgray", new Integer((169 << 16) | (169 << 8) | 169));
+ colors.put("darkgreen", new Integer((0 << 16) | (100 << 8) | 0));
+ colors.put("darkgrey", new Integer((169 << 16) | (169 << 8) | 169));
+ colors.put("darkkhaki", new Integer((189 << 16) | (183 << 8) | 107));
+ colors.put("darkmagenta", new Integer((139 << 16) | (0 << 8) | 139));
+ colors.put("darkolivegreen", new Integer((85 << 16) | (107 << 8) | 47));
+ colors.put("darkorange", new Integer((255 << 16) | (140 << 8) | 0));
+ colors.put("darkorchid", new Integer((153 << 16) | (50 << 8) | 204));
+ colors.put("darkred", new Integer((139 << 16) | (0 << 8) | 0));
+ colors.put("darksalmon", new Integer((233 << 16) | (150 << 8) | 122));
+ colors.put("darkseagreen", new Integer((143 << 16) | (188 << 8) | 143));
+ colors.put("darkslateblue", new Integer((72 << 16) | (61 << 8) | 139));
+ colors.put("darkslategray", new Integer((47 << 16) | (79 << 8) | 79));
+ colors.put("darkslategrey", new Integer((47 << 16) | (79 << 8) | 79));
+ colors.put("darkturquoise", new Integer((0 << 16) | (206 << 8) | 209));
+ colors.put("darkviolet", new Integer((148 << 16) | (0 << 8) | 211));
+ colors.put("deeppink", new Integer((255 << 16) | (20 << 8) | 147));
+ colors.put("deepskyblue", new Integer((0 << 16) | (191 << 8) | 255));
+ colors.put("dimgray", new Integer((105 << 16) | (105 << 8) | 105));
+ colors.put("dimgrey", new Integer((105 << 16) | (105 << 8) | 105));
+ colors.put("dodgerblue", new Integer((30 << 16) | (144 << 8) | 255));
+ colors.put("firebrick", new Integer((178 << 16) | (34 << 8) | 34));
+ colors.put("floralwhite", new Integer((255 << 16) | (250 << 8) | 240));
+ colors.put("forestgreen", new Integer((34 << 16) | (139 << 8) | 34));
+ colors.put("fuchsia", new Integer((255 << 16) | (0 << 8) | 255));
+ colors.put("gainsboro", new Integer((220 << 16) | (220 << 8) | 220));
+ colors.put("ghostwhite", new Integer((248 << 16) | (248 << 8) | 255));
+ colors.put("gold", new Integer((255 << 16) | (215 << 8) | 0));
+ colors.put("goldenrod", new Integer((218 << 16) | (165 << 8) | 32));
+ colors.put("gray", new Integer((128 << 16) | (128 << 8) | 128));
+ colors.put("grey", new Integer((128 << 16) | (128 << 8) | 128));
+ colors.put("green", new Integer((0 << 16) | (128 << 8) | 0));
+ colors.put("greenyellow", new Integer((173 << 16) | (255 << 8) | 47));
+ colors.put("honeydew", new Integer((240 << 16) | (255 << 8) | 240));
+ colors.put("hotpink", new Integer((255 << 16) | (105 << 8) | 180));
+ colors.put("indianred", new Integer((205 << 16) | (92 << 8) | 92));
+ colors.put("indigo", new Integer((75 << 16) | (0 << 8) | 130));
+ colors.put("ivory", new Integer((255 << 16) | (255 << 8) | 240));
+ colors.put("khaki", new Integer((240 << 16) | (230 << 8) | 140));
+ colors.put("lavender", new Integer((230 << 16) | (230 << 8) | 250));
+ colors.put("lavenderblush", new Integer((255 << 16) | (240 << 8) | 245));
+ colors.put("lawngreen", new Integer((124 << 16) | (252 << 8) | 0));
+ colors.put("lemonchiffon", new Integer((255 << 16) | (250 << 8) | 205));
+ colors.put("lightblue", new Integer((173 << 16) | (216 << 8) | 230));
+ colors.put("lightcoral", new Integer((240 << 16) | (128 << 8) | 128));
+ colors.put("lightcyan", new Integer((224 << 16) | (255 << 8) | 255));
+ colors.put("lightgoldenrodyellow", new Integer((250 << 16) | (250 << 8) | 210));
+ colors.put("lightgray", new Integer((211 << 16) | (211 << 8) | 211));
+ colors.put("lightgreen", new Integer((144 << 16) | (238 << 8) | 144));
+ colors.put("lightgrey", new Integer((211 << 16) | (211 << 8) | 211));
+ colors.put("lightpink", new Integer((255 << 16) | (182 << 8) | 193));
+ colors.put("lightsalmon", new Integer((255 << 16) | (160 << 8) | 122));
+ colors.put("lightseagreen", new Integer((32 << 16) | (178 << 8) | 170));
+ colors.put("lightskyblue", new Integer((135 << 16) | (206 << 8) | 250));
+ colors.put("lightslategray", new Integer((119 << 16) | (136 << 8) | 153));
+ colors.put("lightslategrey", new Integer((119 << 16) | (136 << 8) | 153));
+ colors.put("lightsteelblue", new Integer((176 << 16) | (196 << 8) | 222));
+ colors.put("lightyellow", new Integer((255 << 16) | (255 << 8) | 224));
+ colors.put("lime", new Integer((0 << 16) | (255 << 8) | 0));
+ colors.put("limegreen", new Integer((50 << 16) | (205 << 8) | 50));
+ colors.put("linen", new Integer((250 << 16) | (240 << 8) | 230));
+ colors.put("magenta", new Integer((255 << 16) | (0 << 8) | 255));
+ colors.put("maroon", new Integer((128 << 16) | (0 << 8) | 0));
+ colors.put("mediumaquamarine", new Integer((102 << 16) | (205 << 8) | 170));
+ colors.put("mediumblue", new Integer((0 << 16) | (0 << 8) | 205));
+ colors.put("mediumorchid", new Integer((186 << 16) | (85 << 8) | 211));
+ colors.put("mediumpurple", new Integer((147 << 16) | (112 << 8) | 219));
+ colors.put("mediumseagreen", new Integer((60 << 16) | (179 << 8) | 113));
+ colors.put("mediumslateblue", new Integer((123 << 16) | (104 << 8) | 238));
+ colors.put("mediumspringgreen", new Integer((0 << 16) | (250 << 8) | 154));
+ colors.put("mediumturquoise", new Integer((72 << 16) | (209 << 8) | 204));
+ colors.put("mediumvioletred", new Integer((199 << 16) | (21 << 8) | 133));
+ colors.put("midnightblue", new Integer((25 << 16) | (25 << 8) | 112));
+ colors.put("mintcream", new Integer((245 << 16) | (255 << 8) | 250));
+ colors.put("mistyrose", new Integer((255 << 16) | (228 << 8) | 225));
+ colors.put("moccasin", new Integer((255 << 16) | (228 << 8) | 181));
+ colors.put("navajowhite", new Integer((255 << 16) | (222 << 8) | 173));
+ colors.put("navy", new Integer((0 << 16) | (0 << 8) | 128));
+ colors.put("oldlace", new Integer((253 << 16) | (245 << 8) | 230));
+ colors.put("olive", new Integer((128 << 16) | (128 << 8) | 0));
+ colors.put("olivedrab", new Integer((107 << 16) | (142 << 8) | 35));
+ colors.put("orange", new Integer((255 << 16) | (165 << 8) | 0));
+ colors.put("orangered", new Integer((255 << 16) | (69 << 8) | 0));
+ colors.put("orchid", new Integer((218 << 16) | (112 << 8) | 214));
+ colors.put("palegoldenrod", new Integer((238 << 16) | (232 << 8) | 170));
+ colors.put("palegreen", new Integer((152 << 16) | (251 << 8) | 152));
+ colors.put("paleturquoise", new Integer((175 << 16) | (238 << 8) | 238));
+ colors.put("palevioletred", new Integer((219 << 16) | (112 << 8) | 147));
+ colors.put("papayawhip", new Integer((255 << 16) | (239 << 8) | 213));
+ colors.put("peachpuff", new Integer((255 << 16) | (218 << 8) | 185));
+ colors.put("peru", new Integer((205 << 16) | (133 << 8) | 63));
+ colors.put("pink", new Integer((255 << 16) | (192 << 8) | 203));
+ colors.put("plum", new Integer((221 << 16) | (160 << 8) | 221));
+ colors.put("powderblue", new Integer((176 << 16) | (224 << 8) | 230));
+ colors.put("purple", new Integer((128 << 16) | (0 << 8) | 128));
+ colors.put("red", new Integer((255 << 16) | (0 << 8) | 0));
+ colors.put("rosybrown", new Integer((188 << 16) | (143 << 8) | 143));
+ colors.put("royalblue", new Integer((65 << 16) | (105 << 8) | 225));
+ colors.put("saddlebrown", new Integer((139 << 16) | (69 << 8) | 19));
+ colors.put("salmon", new Integer((250 << 16) | (128 << 8) | 114));
+ colors.put("sandybrown", new Integer((244 << 16) | (164 << 8) | 96));
+ colors.put("seagreen", new Integer((46 << 16) | (139 << 8) | 87));
+ colors.put("seashell", new Integer((255 << 16) | (245 << 8) | 238));
+ colors.put("sienna", new Integer((160 << 16) | (82 << 8) | 45));
+ colors.put("silver", new Integer((192 << 16) | (192 << 8) | 192));
+ colors.put("skyblue", new Integer((135 << 16) | (206 << 8) | 235));
+ colors.put("slateblue", new Integer((106 << 16) | (90 << 8) | 205));
+ colors.put("slategray", new Integer((112 << 16) | (128 << 8) | 144));
+ colors.put("slategrey", new Integer((112 << 16) | (128 << 8) | 144));
+ colors.put("snow", new Integer((255 << 16) | (250 << 8) | 250));
+ colors.put("springgreen", new Integer((0 << 16) | (255 << 8) | 127));
+ colors.put("steelblue", new Integer((70 << 16) | (130 << 8) | 180));
+ colors.put("tan", new Integer((210 << 16) | (180 << 8) | 140));
+ colors.put("teal", new Integer((0 << 16) | (128 << 8) | 128));
+ colors.put("thistle", new Integer((216 << 16) | (191 << 8) | 216));
+ colors.put("tomato", new Integer((255 << 16) | (99 << 8) | 71));
+ colors.put("turquoise", new Integer((64 << 16) | (224 << 8) | 208));
+ colors.put("violet", new Integer((238 << 16) | (130 << 8) | 238));
+ colors.put("wheat", new Integer((245 << 16) | (222 << 8) | 179));
+ colors.put("white", new Integer((255 << 16) | (255 << 8) | 255));
+ colors.put("whitesmoke", new Integer((245 << 16) | (245 << 8) | 245));
+ colors.put("yellow", new Integer((255 << 16) | (255 << 8) | 0));
+ colors.put("yellowgreen", new Integer((154 << 16) | (205 << 8) | 50));
+ }
+
+ private static final float PI = (float)Math.PI;
+ */
+}
else if (c.localName.equals("double"))
objects.setElementAt(new Double(new String(content.getBuf(), 0, content.size())), objects.size() - 1);
+ // FIXME
+ /*
else if (c.localName.equals("base64"))
objects.setElementAt(new ByteStream(Base64.decode(new String(content.getBuf(), 0, content.size()))), objects.size() - 1);
-
+ */
+
else if (c.localName.equals("name"))
objects.addElement(new String(content.getBuf(), 0, content.size()));
sb.append(((Boolean)o).booleanValue() ? "1" : "0");
sb.append("</boolean></value>\n");
+ //FIXME
+ /*
} else if (o instanceof ByteStream) {
try {
sb.append(" <value><base64>\n");
if (Log.on) Log.log(this, e);
throw new JS.Exn("caught IOException while attempting to send a ByteStream via XML-RPC");
}
+ */
} else if (o instanceof String) {
sb.append(" <value><string>");
else if (name.equals("clipboard")) Platform.setClipBoard(value.toString());
else if (name.equals("proxyAuthorization")) {
// FIXME: undocumented, possibly insecure
- Proxy.Authorization.authorization = value.toString();
- Proxy.Authorization.waitingForUser.release();
+ HTTP.Proxy.Authorization.authorization = value.toString();
+ HTTP.Proxy.Authorization.waitingForUser.release();
} else super.put(name, value);
}
}});
super.put("load", new JS.Callable() { public Object call(JS.Array args) throws JS.Exn {
- return Res.stringToResource(args.elementAt(0).toString());
+ return Res.stringToRes(args.elementAt(0).toString());
}});
super.put("theme", new JS.Callable() { public Object call(JS.Array args) throws JS.Exn {
return null;
}});
+ /* FIXME
super.put("openFile", new JS.Callable() { public Object call(JS.Array args) throws JS.Exn {
if (args.length() != 1) return null;
String file = Platform.fileDialog(args.elementAt(0).toString(), false);
}
}
});
-
+ */
super.put("recursivePrintObject", new JS.Callable() { public Object call(JS.Array args) {
if (args.length() != 1) return null;
recurse("", "", args.elementAt(0));
public class AWT extends JVM {
protected String getDescriptiveName() { return "Generic JDK 1.1+ with AWT"; }
- protected PixelBuffer _createDoubleBuffer(int w, int h, Surface owner) { return new AWTDoubleBuffer(w, h); }
+ protected PixelBuffer _createPixelBuffer(int w, int h, Surface owner) { return new AWTPixelBuffer(w, h); }
protected Picture _createPicture(int[] b, int w, int h) { return new AWTPicture(b, w, h); }
protected int _getScreenWidth() { return Toolkit.getDefaultToolkit().getScreenSize().width; }
protected int _getScreenHeight() { return Toolkit.getDefaultToolkit().getScreenSize().height; }
}
}
- protected static class AWTPixelBuffer extends DoubleBuffer {
+ protected static class AWTPixelBuffer extends PixelBuffer {
protected Image i = null;
protected Graphics g = null;