diff options
author | Peter Hancock <phancock@apache.org> | 2011-09-05 09:42:00 +0000 |
---|---|---|
committer | Peter Hancock <phancock@apache.org> | 2011-09-05 09:42:00 +0000 |
commit | de056bce77c27b3a93acd62c2fad0c6628bff6b4 (patch) | |
tree | 0b7558b1a7c40964a06b24423fcd53853efb2339 /test/java/org/apache | |
parent | 2b875243aca4c436a611bdc974f3eaf6c6800bb8 (diff) | |
download | xmlgraphics-fop-de056bce77c27b3a93acd62c2fad0c6628bff6b4.tar.gz xmlgraphics-fop-de056bce77c27b3a93acd62c2fad0c6628bff6b4.zip |
Bugzill#51530: Improved support for EBCDIC encoded double byte fonts fo AFP.
Submitted by: Mehdi Houshmand <med1985.at.gmail.com>
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1165223 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/java/org/apache')
-rw-r--r-- | test/java/org/apache/fop/StandardTestSuite.java | 4 | ||||
-rw-r--r-- | test/java/org/apache/fop/afp/fonts/CharactersetEncoderTest.java | 108 |
2 files changed, 111 insertions, 1 deletions
diff --git a/test/java/org/apache/fop/StandardTestSuite.java b/test/java/org/apache/fop/StandardTestSuite.java index a2e6d7524..a49cc7f2e 100644 --- a/test/java/org/apache/fop/StandardTestSuite.java +++ b/test/java/org/apache/fop/StandardTestSuite.java @@ -22,8 +22,9 @@ package org.apache.fop; import junit.framework.Test; import junit.framework.TestSuite; -import org.apache.fop.area.ViewportTestSuite; +import org.apache.fop.afp.fonts.CharactersetEncoderTest; import org.apache.fop.afp.parser.MODCAParserTestCase; +import org.apache.fop.area.ViewportTestSuite; import org.apache.fop.fonts.DejaVuLGCSerifTest; import org.apache.fop.fonts.truetype.GlyfTableTestCase; import org.apache.fop.image.loader.batik.ImageLoaderTestCase; @@ -60,6 +61,7 @@ public class StandardTestSuite { suite.addTest(new TestSuite(PDFsRGBSettingsTestCase.class)); suite.addTest(new TestSuite(DejaVuLGCSerifTest.class)); suite.addTest(new TestSuite(MODCAParserTestCase.class)); + suite.addTest(new TestSuite(CharactersetEncoderTest.class)); suite.addTest(org.apache.fop.render.afp.AFPTestSuite.suite()); suite.addTest(PSTestSuite.suite()); suite.addTest(new TestSuite(GlyfTableTestCase.class)); diff --git a/test/java/org/apache/fop/afp/fonts/CharactersetEncoderTest.java b/test/java/org/apache/fop/afp/fonts/CharactersetEncoderTest.java new file mode 100644 index 000000000..5999a04d6 --- /dev/null +++ b/test/java/org/apache/fop/afp/fonts/CharactersetEncoderTest.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.afp.fonts; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.nio.charset.CharacterCodingException; + +import junit.framework.TestCase; + +/** + * Test {@link CharactersetEncoder} + */ +public class CharactersetEncoderTest extends TestCase { + private CharactersetEncoder singlebyteEncoder; + private CharactersetEncoder doublebyteEncoder; + + public void setUp() { + singlebyteEncoder = CharactersetEncoder.newInstance("cp500", false); + doublebyteEncoder = CharactersetEncoder.newInstance("cp937", true); + } + + // This is just an arbitrary CJK string + private final String testCJKText = "\u8ACB\u65BC\u627F\u505A\u65E5\u4E03\u65E5\u5167\u672A\u9054" + + "\u4E03\u65E5\u4E4B\u5B9A\u5B58\u8005\u4EE5\u5BE6\u969B\u5230\u671F\u65E5\u5167\u78BA" + + "\u8A8D\u672C\u4EA4\u6613\u5167\u5BB9\u3002\u5982\u672A\u65BC\u4E0A\u8FF0\u671F\u9593" + + "\u5167\u63D0\u51FA\u7570\u8B70\uFF0C\u8996\u540C\u610F\u627F\u8A8D\u672C\u4EA4\u6613" + + "\u3002"; + + private final byte[] test6CJKChars = { + (byte) 0x61, (byte) 0x99, + (byte) 0x50, (byte) 0xf4, + (byte) 0x50, (byte) 0xd4, + (byte) 0x56, (byte) 0x99, + (byte) 0x4c, (byte) 0xc9, + (byte) 0x4c, (byte) 0x44 }; + + private final String testEngText = "Hello World!"; + private final byte[] testEngChars = { + (byte) 0xc8, // H + (byte) 0x85, // e + (byte) 0x93, // l + (byte) 0x93, // l + (byte) 0x96, // o + (byte) 0x40, // " " + (byte) 0xe6, // W + (byte) 0x96, // o + (byte) 0x99, // r + (byte) 0x93, // l + (byte) 0x84, // d + (byte) 0x4f // ! + }; + + /** + * Tests canEncode() - tests that canEncode() responds properly to various input characters. + */ + public void testCanEncode() { + // Both SBCS and DBCS should support Latin characters + for (char c = '!'; c < '~'; c++) { + assertTrue(singlebyteEncoder.canEncode(c)); + assertTrue(doublebyteEncoder.canEncode(c)); + } + // ONLY the double byte characters can handle CJK text + for (char c : testCJKText.toCharArray()) { + assertFalse(singlebyteEncoder.canEncode(c)); + assertTrue(doublebyteEncoder.canEncode(c)); + } + // Ensure that double byte encoder doesn't just return true all the time... + assertFalse(doublebyteEncoder.canEncode('\u00BB')); + } + + public void testEncode() throws CharacterCodingException, IOException { + 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()); + byte[] bytes = bOut.toByteArray(); + for (int i = 0; i < 12; i++) { + assertEquals(test6CJKChars[i], bytes[i]); + } + bOut.reset();*/ + + encChars = singlebyteEncoder.encode(testEngText); + encChars.writeTo(bOut, 0, encChars.getLength()); + byte[] engBytes = bOut.toByteArray(); + for (int i = 0; i < testEngChars.length; i++) { + assertEquals(testEngChars[i], engBytes[i]); + } + assertEquals(testEngChars.length, engBytes.length); + } +} |