aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRoman <Roman@Roman-NB>2014-07-24 22:15:40 +0300
committerRoman <Roman@Roman-NB>2014-07-24 22:15:40 +0300
commit628509b39ea7c16210315d191860511d6be4aa69 (patch)
tree9f612e4ba70f00ab9a8673273ca7ff9c057ec310 /src
parent37760af388303834e359703aad9562ce6165845f (diff)
Added possibility to load font using InputStream parameter
Diffstat (limited to 'src')
-rw-r--r--src/jogl/classes/com/jogamp/graph/font/FontFactory.java5
-rw-r--r--src/jogl/classes/jogamp/graph/font/FontConstructor.java2
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastFontConstructor.java24
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/ot/OTFontCollection.java17
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")) {