diff options
author | Mehdi Houshmand <mehdi@apache.org> | 2011-11-18 16:23:43 +0000 |
---|---|---|
committer | Mehdi Houshmand <mehdi@apache.org> | 2011-11-18 16:23:43 +0000 |
commit | 3d2b970d8e559003aea495c0e2a941d0c7d81160 (patch) | |
tree | 00c7c749534489eb2177af38e43f20f2f3da5430 | |
parent | 32ad33cda1ee32f8bb6fa5212933827485787d37 (diff) | |
download | xmlgraphics-fop-3d2b970d8e559003aea495c0e2a941d0c7d81160.tar.gz xmlgraphics-fop-3d2b970d8e559003aea495c0e2a941d0c7d81160.zip |
Bugzilla #52177: Changed the AFP double-byte characterset builder to a singleton, this now matches the behaviour of the single byte characterset builder
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1203719 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java | 58 | ||||
-rw-r--r-- | src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java | 8 |
2 files changed, 41 insertions, 25 deletions
diff --git a/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java b/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java index 16893a152..c8f604584 100644 --- a/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java +++ b/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.net.URISyntaxException; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.WeakHashMap; @@ -56,7 +57,7 @@ import org.apache.xmlgraphics.image.loader.util.SoftMapCache; * formatted object. <p/> * */ -public class CharacterSetBuilder { +public abstract class CharacterSetBuilder { /** * Static logging instance @@ -64,11 +65,6 @@ public class CharacterSetBuilder { protected static final Log LOG = LogFactory.getLog(CharacterSetBuilder.class); /** - * Singleton reference - */ - private static CharacterSetBuilder instance; - - /** * Template used to convert lists to arrays. */ private static final CharacterSetOrientation[] EMPTY_CSO_ARRAY = new CharacterSetOrientation[0]; @@ -104,8 +100,8 @@ public class CharacterSetBuilder { /** * The collection of code pages */ - private final Map/*<String, Map<String, String>>*/ codePagesCache - = new WeakHashMap/*<String, Map<String, String>>*/(); + private final Map<String, Map<String, String>> codePagesCache + = Collections.synchronizedMap(new WeakHashMap<String, Map<String, String>>()); /** * Cache of charactersets @@ -120,11 +116,8 @@ public class CharacterSetBuilder { * Factory method for the single-byte implementation of AFPFontReader. * @return AFPFontReader */ - public static CharacterSetBuilder getInstance() { - if (instance == null) { - instance = new CharacterSetBuilder(); - } - return instance; + public static CharacterSetBuilder getSingleByteInstance() { + return SingleByteLoader.getInstance(); } /** @@ -132,7 +125,7 @@ public class CharacterSetBuilder { * @return AFPFontReader */ public static CharacterSetBuilder getDoubleByteInstance() { - return new DoubleByteLoader(); + return DoubleByteLoader.getInstance(); } @@ -251,13 +244,14 @@ public class CharacterSetBuilder { * information to map the unicode character id to the graphic * chracter global identifier. */ + Map<String, String> codePage; + synchronized (codePagesCache) { + codePage = codePagesCache.get(codePageName); - Map/*<String,String>*/ codePage - = (Map/*<String,String>*/)codePagesCache.get(codePageName); - - if (codePage == null) { - codePage = loadCodePage(codePageName, encoding, accessor); - codePagesCache.put(codePageName, codePage); + if (codePage == null) { + codePage = loadCodePage(codePageName, encoding, accessor); + codePagesCache.put(codePageName, codePage); + } } inputStream = openInputStream(accessor, characterSetName); @@ -671,10 +665,32 @@ public class CharacterSetBuilder { } } + private static final class SingleByteLoader extends CharacterSetBuilder { + + private static final SingleByteLoader INSTANCE = new SingleByteLoader(); + + private SingleByteLoader() { + super(); + } + + private static SingleByteLoader getInstance() { + return INSTANCE; + } + } + /** * Double-byte (CID Keyed font (Type 0)) implementation of AFPFontReader. */ - private static class DoubleByteLoader extends CharacterSetBuilder { + private static final class DoubleByteLoader extends CharacterSetBuilder { + + private static final DoubleByteLoader INSTANCE = new DoubleByteLoader(); + + private DoubleByteLoader() { + } + + static DoubleByteLoader getInstance() { + return INSTANCE; + } protected Map/*<String,String>*/ loadCodePage(String codePage, String encoding, ResourceAccessor accessor) throws IOException { diff --git a/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java b/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java index 25d684e42..54eb6c87d 100644 --- a/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java +++ b/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java @@ -190,7 +190,7 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator try { Typeface tf = clazz.newInstance(); font.addCharacterSet(sizeMpt, - CharacterSetBuilder.getInstance() + CharacterSetBuilder.getSingleByteInstance() .build(characterset, codepage, encoding, tf)); } catch (Exception ie) { String msg = "The base 14 font class " + clazz.getName() @@ -204,7 +204,7 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator } } else { try { - font.addCharacterSet(sizeMpt, CharacterSetBuilder.getInstance() + font.addCharacterSet(sizeMpt, CharacterSetBuilder.getSingleByteInstance() .build(characterset, codepage, encoding, accessor)); } catch (IOException ioe) { toConfigurationException(codepage, characterset, ioe); @@ -228,7 +228,7 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator + base14).asSubclass(Typeface.class); try { Typeface tf = clazz.newInstance(); - characterSet = CharacterSetBuilder.getInstance() + characterSet = CharacterSetBuilder.getSingleByteInstance() .build(characterset, codepage, encoding, tf); } catch (Exception ie) { String msg = "The base 14 font class " + clazz.getName() @@ -242,7 +242,7 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator } } else { try { - characterSet = CharacterSetBuilder.getInstance().build( + characterSet = CharacterSetBuilder.getSingleByteInstance().build( characterset, codepage, encoding, accessor); } catch (IOException ioe) { toConfigurationException(codepage, characterset, ioe); |