diff options
Diffstat (limited to 'src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java')
-rw-r--r-- | src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java | 102 |
1 files changed, 47 insertions, 55 deletions
diff --git a/src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java b/src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java index 76947873e..bbf022657 100644 --- a/src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java +++ b/src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java @@ -28,18 +28,17 @@ package jogamp.graph.font; import java.io.IOException; +import java.io.InputStream; +import com.jogamp.common.net.Uri; import com.jogamp.common.os.Platform; import com.jogamp.common.util.IntObjectHashMap; -import com.jogamp.common.util.IOUtil; import com.jogamp.common.util.JarUtil; import com.jogamp.common.util.cache.TempJarCache; import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontSet; import com.jogamp.graph.font.FontFactory; -import java.net.URI; -import java.net.URLConnection; import java.security.AccessController; import java.security.PrivilegedAction; @@ -48,8 +47,8 @@ public class UbuntuFontLoader implements FontSet { // FIXME: Add cache size to limit memory usage private static final IntObjectHashMap fontMap = new IntObjectHashMap(); - private static final String jarSubDir = "atomic/" ; - private static final String jarName = "jogl-fonts-p0.jar" ; + private static final Uri.Encoded jarSubDir = Uri.Encoded.cast("atomic/"); + private static final Uri.Encoded jarName = Uri.Encoded.cast("jogl-fonts-p0.jar"); private static final String relFontPath = "fonts/ubuntu/" ; private static final String absFontPath = "jogamp/graph/font/fonts/ubuntu/" ; @@ -130,71 +129,64 @@ public class UbuntuFontLoader implements FontSet { } private static boolean attemptedJARLoading = false; - private static boolean useTempJarCache = false; + private static boolean useTempJARCache = false; private synchronized Font abspath(final String fname, final int family, final int style) throws IOException { - final String err = "Problem loading font "+fname+", stream "+relFontPath+fname; - final Exception[] privErr = { null }; - try { - final Font f0 = abspathImpl(fname, family, style); - if(null != f0) { - return f0; - } - if( !attemptedJARLoading ) { - attemptedJARLoading = true; - Platform.initSingleton(); - if( TempJarCache.isInitialized() ) { - final URI uri = JarUtil.getRelativeOf(UbuntuFontLoader.class, jarSubDir, jarName); - AccessController.doPrivileged(new PrivilegedAction<Object>() { + if( !attemptedJARLoading ) { + attemptedJARLoading = true; + Platform.initSingleton(); + if( TempJarCache.isInitialized() ) { + try { + final Uri uri = JarUtil.getRelativeOf(UbuntuFontLoader.class, jarSubDir, jarName); + final Exception e0 = AccessController.doPrivileged(new PrivilegedAction<Exception>() { @Override - public Object run() { + public Exception run() { try { TempJarCache.addResources(UbuntuFontLoader.class, uri); - } catch (final Exception e) { privErr[0] = e; } - return null; + useTempJARCache = true; + return null; + } catch (final Exception e) { + return e; + } } } ); - if( null == privErr[0] ) { - useTempJarCache = true; - final Font f1 = abspathImpl(fname, family, style); - if(null != f1) { - return f1; - } + if( null != e0 ) { + throw e0; } + } catch(final Exception e1) { + System.err.println("Caught "+e1.getMessage()); + e1.printStackTrace(); } } - } catch(final Exception e) { - throw new IOException(err, e); } - if( null != privErr[0] ) { - throw new IOException(err, privErr[0]); + final String path = useTempJARCache ? absFontPath : relFontPath; + try { + final Font f = abspathImpl(path+fname, family, style); + if( null != f ) { + return f; + } + throw new IOException(String.format("Problem loading font %s, stream %s%s", fname, path, fname)); + } catch(final Exception e) { + throw new IOException(String.format("Problem loading font %s, stream %s%s", fname, path, fname), e); } - throw new IOException(err); } private Font abspathImpl(final String fname, final int family, final int style) throws IOException { - final URLConnection conn; - if( useTempJarCache ) { - // this code-path throws .. all exceptions - final Exception[] privErr = { null }; - final URLConnection[] privConn = { null }; - AccessController.doPrivileged(new PrivilegedAction<Object>() { - @Override - public Object run() { - try { - final URI uri = TempJarCache.getResource(absFontPath+fname); - privConn[0] = null != uri ? uri.toURL().openConnection() : null; - } catch (final Exception e) { privErr[0] = e; } + final Exception[] privErr = { null }; + final InputStream stream = AccessController.doPrivileged(new PrivilegedAction<InputStream>() { + @Override + public InputStream run() { + try { + final Uri uri = TempJarCache.getResourceUri(fname); + return null != uri ? uri.toURL().openConnection().getInputStream() : null; + } catch (final Exception e) { + privErr[0] = e; return null; - } } ); - if( null != privErr[0] ) { - throw new IOException(privErr[0]); - } - conn = privConn[0]; - } else { - // no exceptions .. - conn = IOUtil.getResource(UbuntuFontLoader.class, relFontPath+fname); + } + } } ); + if( null != privErr[0] ) { + throw new IOException(privErr[0]); } - if(null != conn) { - final Font f= FontFactory.get ( conn ) ; + if(null != stream) { + final Font f= FontFactory.get ( stream, true ) ; if(null != f) { fontMap.put( ( family << 8 ) | style, f ); return f; |