diff options
Diffstat (limited to 'src/java/org/apache/fop/afp/fonts')
4 files changed, 37 insertions, 28 deletions
diff --git a/src/java/org/apache/fop/afp/fonts/CharacterSet.java b/src/java/org/apache/fop/afp/fonts/CharacterSet.java index 8881a2649..49e7f99ba 100644 --- a/src/java/org/apache/fop/afp/fonts/CharacterSet.java +++ b/src/java/org/apache/fop/afp/fonts/CharacterSet.java @@ -115,7 +115,7 @@ public class CharacterSet { } this.codePage = codePage; this.encoding = encoding; - this.encoder = CharactersetEncoder.newInstance(encoding, charsetType); + this.encoder = charsetType.getEncoder(encoding); this.accessor = accessor; this.characterSetOrientations = new HashMap<String, CharacterSetOrientation>(4); diff --git a/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java b/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java index e145de745..7331178f5 100644 --- a/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java +++ b/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java @@ -40,6 +40,7 @@ import org.apache.fop.afp.AFPConstants; import org.apache.fop.afp.AFPEventProducer; import org.apache.fop.afp.util.AFPResourceAccessor; import org.apache.fop.afp.util.StructuredFieldReader; +import org.apache.fop.apps.io.InternalResourceResolver; import org.apache.fop.fonts.Typeface; /** @@ -148,7 +149,7 @@ public abstract class CharacterSetBuilder { throws IOException { URI uri; try { - uri = new URI(uriStr.trim()); + uri = InternalResourceResolver.cleanURI(uriStr.trim()); } catch (URISyntaxException e) { throw new MalformedURLException("Invalid uri: " + uriStr + " (" + e.getMessage() + ")"); } diff --git a/src/java/org/apache/fop/afp/fonts/CharacterSetType.java b/src/java/org/apache/fop/afp/fonts/CharacterSetType.java index 8eaaa089b..060d949ac 100644 --- a/src/java/org/apache/fop/afp/fonts/CharacterSetType.java +++ b/src/java/org/apache/fop/afp/fonts/CharacterSetType.java @@ -19,13 +19,39 @@ package org.apache.fop.afp.fonts; +import org.apache.fop.afp.fonts.CharactersetEncoder.DefaultEncoder; +import org.apache.fop.afp.fonts.CharactersetEncoder.EbcdicDoubleByteLineDataEncoder; + /** * An enumeration of AFP characterset types. */ public enum CharacterSetType { /** Double byte character sets; these do NOT have the shift-in;shift-out operators */ - DOUBLE_BYTE, + DOUBLE_BYTE { + @Override + CharactersetEncoder getEncoder(String encoding) { + return new DefaultEncoder(encoding, true); + } + }, /** Double byte character sets; these can have the shift-in;shift-out operators */ - DOUBLE_BYTE_LINE_DATA, - SINGLE_BYTE; + DOUBLE_BYTE_LINE_DATA { + @Override + CharactersetEncoder getEncoder(String encoding) { + return new EbcdicDoubleByteLineDataEncoder(encoding); + } + }, + SINGLE_BYTE { + @Override + CharactersetEncoder getEncoder(String encoding) { + return new DefaultEncoder(encoding, false); + } + }; + + /** + * Returns the character-set encoder + * + * @param encoding + * @return + */ + abstract CharactersetEncoder getEncoder(String encoding); } diff --git a/src/java/org/apache/fop/afp/fonts/CharactersetEncoder.java b/src/java/org/apache/fop/afp/fonts/CharactersetEncoder.java index f101bdab4..983c308cd 100644 --- a/src/java/org/apache/fop/afp/fonts/CharactersetEncoder.java +++ b/src/java/org/apache/fop/afp/fonts/CharactersetEncoder.java @@ -87,7 +87,7 @@ public abstract class CharactersetEncoder { */ public static EncodedChars encodeSBCS(CharSequence chars, String encoding) throws CharacterCodingException { - CharactersetEncoder encoder = newInstance(encoding, CharacterSetType.SINGLE_BYTE); + CharactersetEncoder encoder = CharacterSetType.SINGLE_BYTE.getEncoder(encoding); return encoder.encode(chars); } @@ -97,8 +97,8 @@ public abstract class CharactersetEncoder { * sequence it will return its EBCDIC code-point, however, the "Shift In - Shift Out" operators * are removed from the sequence of bytes. These are only used in Line Data. */ - private static final class EbcdicDoubleByteLineDataEncoder extends CharactersetEncoder { - private EbcdicDoubleByteLineDataEncoder(String encoding) { + static final class EbcdicDoubleByteLineDataEncoder extends CharactersetEncoder { + EbcdicDoubleByteLineDataEncoder(String encoding) { super(encoding); } @Override @@ -115,10 +115,10 @@ public abstract class CharactersetEncoder { * the primary format for most Latin character sets. This can also be used for Unicode double- * byte character sets (DBCS). */ - private static final class DefaultEncoder extends CharactersetEncoder { + static final class DefaultEncoder extends CharactersetEncoder { private final boolean isDBCS; - private DefaultEncoder(String encoding, boolean isDBCS) { + DefaultEncoder(String encoding, boolean isDBCS) { super(encoding); this.isDBCS = isDBCS; } @@ -130,24 +130,6 @@ public abstract class CharactersetEncoder { } /** - * Returns an new instance of a {@link CharactersetEncoder}. - * - * @param encoding the encoding for the underlying character encoder - * @param isEbcdicDBCS whether or not this wraps a double-byte EBCDIC code page. - * @return the CharactersetEncoder - */ - static CharactersetEncoder newInstance(String encoding, CharacterSetType charsetType) { - switch (charsetType) { - case DOUBLE_BYTE_LINE_DATA: - return new EbcdicDoubleByteLineDataEncoder(encoding); - case DOUBLE_BYTE: - return new DefaultEncoder(encoding, true); - default: - return new DefaultEncoder(encoding, false); - } - } - - /** * A container for encoded character bytes */ // CSOFF: FinalClass - disabling "final" modifier so that this class can be mocked |