diff options
author | Sven Gothel <[email protected]> | 2014-09-24 06:08:12 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-09-24 06:08:12 +0200 |
commit | f197d38d0ea31416645ac69cebb3f9b3544d903f (patch) | |
tree | f81fc1a48af5515164ad2c64ad0fa80bd2ad8521 /src/jogl | |
parent | ca357af70d46a6c12ff8810565874ecabb564d87 (diff) | |
parent | 628509b39ea7c16210315d191860511d6be4aa69 (diff) |
Merge remote-tracking branch 'picoworm/master'
Diffstat (limited to 'src/jogl')
4 files changed, 44 insertions, 4 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/font/FontFactory.java b/src/jogl/classes/com/jogamp/graph/font/FontFactory.java index db775e8dc..cfd06cf6c 100644 --- a/src/jogl/classes/com/jogamp/graph/font/FontFactory.java +++ b/src/jogl/classes/com/jogamp/graph/font/FontFactory.java @@ -29,6 +29,7 @@ package com.jogamp.graph.font; import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.net.URI; import java.net.URLConnection; @@ -91,6 +92,10 @@ public class FontFactory { return fontConstr.create(file); } + public static final Font get(final InputStream stream) throws IOException { + return fontConstr.create(stream); + } + public static final Font get(final URLConnection conn) throws IOException { return fontConstr.create(conn); } diff --git a/src/jogl/classes/jogamp/graph/font/FontConstructor.java b/src/jogl/classes/jogamp/graph/font/FontConstructor.java index b452ae548..76b5dbb8b 100644 --- a/src/jogl/classes/jogamp/graph/font/FontConstructor.java +++ b/src/jogl/classes/jogamp/graph/font/FontConstructor.java @@ -29,11 +29,13 @@ package jogamp.graph.font; import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.net.URLConnection; import com.jogamp.graph.font.Font; public interface FontConstructor { Font create(File file) throws IOException ; + Font create(InputStream stream) throws IOException ; Font create(URLConnection url) throws IOException ; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFontConstructor.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFontConstructor.java index 6154484d5..0b42a65d4 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFontConstructor.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFontConstructor.java @@ -29,6 +29,7 @@ package jogamp.graph.font.typecast; import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.net.URLConnection; import java.security.AccessController; import java.security.PrivilegedAction; @@ -67,6 +68,29 @@ public class TypecastFontConstructor implements FontConstructor { } @Override + public Font create(final InputStream istream) throws IOException { + final Object o = AccessController.doPrivileged(new PrivilegedAction<Object>() { + @Override + public Object run() { + OTFontCollection fontset; + try { + fontset = OTFontCollection.create(istream); + return new TypecastFont(fontset); + } catch (final IOException e) { + return e; + } + } + }); + if(o instanceof Font) { + return (Font)o; + } + if(o instanceof IOException) { + throw (IOException)o; + } + throw new InternalError("Unexpected Object: "+o); + } + + @Override public Font create(final URLConnection fconn) throws IOException { return AccessController.doPrivileged(new PrivilegedAction<Font>() { @Override diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/OTFontCollection.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/OTFontCollection.java index e5ad2900a..87c68eae8 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/OTFontCollection.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/OTFontCollection.java @@ -25,6 +25,7 @@ import java.io.BufferedInputStream; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; @@ -58,9 +59,9 @@ public class OTFontCollection { /** * @param file The OpenType font file */ - public static OTFontCollection create(final File file) throws IOException { + public static OTFontCollection create(final InputStream istream) throws IOException { final OTFontCollection fc = new OTFontCollection(); - fc.read(file); + fc.read(istream); return fc; } @@ -119,11 +120,19 @@ public class OTFontCollection { } _resourceFork = true; } + + read(new FileInputStream(file)); + } + + /** + * @param inputstream The OpenType font stream + */ + protected void read(InputStream file) throws IOException { final DataInputStream dis = new DataInputStream( new BufferedInputStream( - new FileInputStream(file), (int) file.length())); - dis.mark((int) file.length()); + file)); + //dis.mark((int) file.length()); if (_resourceFork || _pathName.endsWith(".dfont")) { |