*
* @param codePage the code page identifier
* @param encoding the encoding of the font
- * @param isEBDCS if this is an EBCDIC double byte character set.
+ * @param charsetType the type of the characterset
* @param name the character set name
* @param accessor the resource accessor to load resource with
* @param eventProducer for handling AFP related events
*/
- CharacterSet(String codePage, String encoding, boolean isEBDCS, String name,
+ CharacterSet(String codePage, String encoding, CharacterSetType charsetType, String name,
ResourceAccessor accessor, AFPEventProducer eventProducer) {
if (name.length() > MAX_NAME_LEN) {
String msg = "Character set name '" + name + "' must be a maximum of "
}
this.codePage = codePage;
this.encoding = encoding;
- this.encoder = CharactersetEncoder.newInstance(encoding, isEBDCS);
+ this.encoder = CharactersetEncoder.newInstance(encoding, charsetType);
this.accessor = accessor;
this.characterSetOrientations = new HashMap<String, CharacterSetOrientation>(4);
*/
private CharacterSetOrientation getCharacterSetOrientation() {
CharacterSetOrientation c
- = (CharacterSetOrientation) characterSetOrientations.get(currentOrientation);
+ = characterSetOrientations.get(currentOrientation);
return c;
}
* @return CharacterSet object
* @throws IOException if an I/O error occurs
*/
- public CharacterSet build(String characterSetName, String codePageName, String encoding,
+ public CharacterSet buildSBCS(String characterSetName, String codePageName, String encoding,
ResourceAccessor accessor, AFPEventProducer eventProducer) throws IOException {
- return processFont(characterSetName, codePageName, encoding, false, accessor,
- eventProducer);
+ return processFont(characterSetName, codePageName, encoding, CharacterSetType.SINGLE_BYTE,
+ accessor, eventProducer);
}
/**
* @param characterSetName name of the characterset
* @param codePageName name of the code page file
* @param encoding encoding name
- * @param isEDBCS if this is an EBCDIC double byte character set (DBCS)
+ * @param charsetType the characterset type
* @param accessor used to load codepage and characterset
* @param eventProducer for handling AFP related events
* @return CharacterSet object
* @throws IOException if an I/O error occurs
*/
public CharacterSet buildDBCS(String characterSetName, String codePageName, String encoding,
- boolean isEDBCS, ResourceAccessor accessor, AFPEventProducer eventProducer)
+ CharacterSetType charsetType, ResourceAccessor accessor, AFPEventProducer eventProducer)
throws IOException {
- return processFont(characterSetName, codePageName, encoding, isEDBCS, accessor,
+ return processFont(characterSetName, codePageName, encoding, charsetType, accessor,
eventProducer);
}
}
private CharacterSet processFont(String characterSetName, String codePageName, String encoding,
- boolean isEDBCS, ResourceAccessor accessor, AFPEventProducer eventProducer)
+ CharacterSetType charsetType, ResourceAccessor accessor, AFPEventProducer eventProducer)
throws IOException {
// check for cached version of the characterset
String descriptor = characterSetName + "_" + encoding + "_" + codePageName;
}
// characterset not in the cache, so recreating
- characterSet = new CharacterSet(codePageName, encoding, isEDBCS, characterSetName,
+ characterSet = new CharacterSet(codePageName, encoding, charsetType, characterSetName,
accessor, eventProducer);
InputStream inputStream = null;
}
}
- return (CharacterSetOrientation[]) orientations
- .toArray(EMPTY_CSO_ARRAY);
+ return orientations.toArray(EMPTY_CSO_ARRAY);
}
/**
String gcgiString = new String(gcgid, AFPConstants.EBCIDIC_ENCODING);
- String idx = (String) codepage.get(gcgiString);
+ String idx = codepage.get(gcgiString);
if (idx != null) {
*
* @param chars the character sequence
* @param encoding the encoding type
- * @param isEDBCS if this encoding represents a double-byte character set
* @return encoded data
* @throws CharacterCodingException if encoding fails
*/
- public static EncodedChars encodeSBCS(CharSequence chars, String encoding, boolean isEDBCS)
+ public static EncodedChars encodeSBCS(CharSequence chars, String encoding)
throws CharacterCodingException {
- CharactersetEncoder encoder = newInstance(encoding, isEDBCS);
+ CharactersetEncoder encoder = newInstance(encoding, CharacterSetType.SINGLE_BYTE);
return encoder.encode(chars);
}
* 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 EbcdicDoubleByteEncoder extends CharactersetEncoder {
- private EbcdicDoubleByteEncoder(String encoding) {
+ private static final class EbcdicDoubleByteLineDataEncoder extends CharactersetEncoder {
+ private EbcdicDoubleByteLineDataEncoder(String encoding) {
super(encoding);
}
@Override
* byte character sets (DBCS).
*/
private static final class DefaultEncoder extends CharactersetEncoder {
- private DefaultEncoder(String encoding) {
+ private final boolean isDBCS;
+
+ private DefaultEncoder(String encoding, boolean isDBCS) {
super(encoding);
+ this.isDBCS = isDBCS;
}
@Override
EncodedChars getEncodedChars(byte[] byteArray, int length) {
- return new EncodedChars(byteArray, false);
+ return new EncodedChars(byteArray, isDBCS);
}
}
* @param isEbcdicDBCS whether or not this wraps a double-byte EBCDIC code page.
* @return the CharactersetEncoder
*/
- static CharactersetEncoder newInstance(String encoding, boolean isEbcdicDBCS) {
- if (isEbcdicDBCS) {
- return new EbcdicDoubleByteEncoder(encoding);
- } else {
- return new DefaultEncoder(encoding);
+ 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
public static class EncodedChars {
private final byte[] bytes;
*/
public FopCharacterSet(String codePage, String encoding, String name, Typeface charSet,
AFPEventProducer eventProducer) {
- super(codePage, encoding, false, name, (ResourceAccessor) null, eventProducer);
+ super(codePage, encoding, CharacterSetType.SINGLE_BYTE, name, (ResourceAccessor) null,
+ eventProducer);
this.charSet = charSet;
}
public char mapChar(char c) {
return charSet.mapChar(c);
}
-
}
import java.io.IOException;
/**
- * Producer interface that is passed to a {@link PresentationTextObject} to produce PTOCA control
- * sequences using a {@link PtocaBuilder}.
+ * Producer interface that is passed to a {@link org.apache.fop.afp.modca.PresentationTextObject}
+ * to produce PTOCA control sequences using a {@link PtocaBuilder}.
*/
public interface PtocaProducer {
// Add transparent data
String textString = textDataInfo.getString();
String encoding = textDataInfo.getEncoding();
- builder.addTransparentData(CharactersetEncoder.encodeSBCS(textString, encoding, false));
+ builder.addTransparentData(CharactersetEncoder.encodeSBCS(textString, encoding));
}
}
import org.apache.fop.afp.fonts.AFPFontInfo;
import org.apache.fop.afp.fonts.CharacterSet;
import org.apache.fop.afp.fonts.CharacterSetBuilder;
+import org.apache.fop.afp.fonts.CharacterSetType;
import org.apache.fop.afp.fonts.DoubleByteFont;
import org.apache.fop.afp.fonts.OutlineFont;
import org.apache.fop.afp.fonts.RasterFont;
}
} else {
font.addCharacterSet(sizeMpt, CharacterSetBuilder.getSingleByteInstance()
- .build(characterset, codepage, encoding, accessor, eventProducer));
+ .buildSBCS(characterset, codepage, encoding, accessor, eventProducer));
}
}
return font;
log.error(msg);
}
} else {
- characterSet = CharacterSetBuilder.getSingleByteInstance().build(
+ characterSet = CharacterSetBuilder.getSingleByteInstance().buildSBCS(
characterset, codepage, encoding, accessor, eventProducer);
}
// Return new font object
}
String name = afpFontCfg.getAttribute("name", characterset);
CharacterSet characterSet = null;
- boolean ebcdicDBCS = afpFontCfg.getAttributeAsBoolean("ebcdic-dbcs", false);
-
+ CharacterSetType charsetType = afpFontCfg.getAttributeAsBoolean("ebcdic-dbcs", false)
+ ? CharacterSetType.DOUBLE_BYTE_LINE_DATA : CharacterSetType.DOUBLE_BYTE;
characterSet = CharacterSetBuilder.getDoubleByteInstance().buildDBCS(characterset,
- codepage, encoding, ebcdicDBCS, accessor, eventProducer);
+ codepage, encoding, charsetType, accessor, eventProducer);
// Create a new font object
DoubleByteFont font = new DoubleByteFont(name, characterSet);
}
List<FontTriplet> fontTriplets = afi.getFontTriplets();
for (int j = 0; j < fontTriplets.size(); ++j) {
- FontTriplet triplet = (FontTriplet) fontTriplets.get(j);
+ FontTriplet triplet = fontTriplets.get(j);
if (log.isDebugEnabled()) {
log.debug(" Font triplet "
+ triplet.getName() + ", "
package org.apache.fop.afp.fonts;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.CharacterCodingException;
import org.junit.Before;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
/**
* Test {@link CharactersetEncoder}
*/
@Before
public void setUp() {
- singlebyteEncoder = CharactersetEncoder.newInstance("cp500", false);
- doublebyteEncoder = CharactersetEncoder.newInstance("cp937", true);
+ singlebyteEncoder = CharactersetEncoder.newInstance("cp500", CharacterSetType.SINGLE_BYTE);
+ doublebyteEncoder = CharactersetEncoder.newInstance("cp937",
+ CharacterSetType.DOUBLE_BYTE_LINE_DATA);
}
// This is just an arbitrary CJK string
@Test
public void testEncode() throws CharacterCodingException, IOException {
- CharactersetEncoder.EncodedChars encChars;// = doublebyteEncoder.encode(testCJKText);
+ CharactersetEncoder.EncodedChars encChars; // = doublebyteEncoder.encode(testCJKText);
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
// JAVA 1.5 has a bug in the JVM in which these err for some reason... JAVA 1.6 no issues
/*encChars.writeTo(bOut, 0, encChars.getLength());