You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2010/01/30 18:24:39 UTC
svn commit: r904817 - in /pdfbox/fontbox/trunk/src:
main/java/org/apache/fontbox/cmap/ test/ test/java/ test/java/org/
test/java/org/apache/ test/java/org/apache/fontbox/
test/java/org/apache/fontbox/cff/ test/java/org/apache/fontbox/cmap/
Author: lehmi
Date: Sat Jan 30 17:24:38 2010
New Revision: 904817
URL: http://svn.apache.org/viewvc?rev=904817&view=rev
Log:
PDFBOX-608: fixed single byte encoding within a CMap. Patch by Nicolas Peninguy (nico+asf at lostgeeks dot org)
Added:
pdfbox/fontbox/trunk/src/test/
pdfbox/fontbox/trunk/src/test/java/
pdfbox/fontbox/trunk/src/test/java/org/
pdfbox/fontbox/trunk/src/test/java/org/apache/
pdfbox/fontbox/trunk/src/test/java/org/apache/fontbox/
pdfbox/fontbox/trunk/src/test/java/org/apache/fontbox/cff/
pdfbox/fontbox/trunk/src/test/java/org/apache/fontbox/cff/Type1CharStringTest.java
pdfbox/fontbox/trunk/src/test/java/org/apache/fontbox/cff/Type1FontUtilTest.java
pdfbox/fontbox/trunk/src/test/java/org/apache/fontbox/cmap/
pdfbox/fontbox/trunk/src/test/java/org/apache/fontbox/cmap/TestCMap.java (with props)
Modified:
pdfbox/fontbox/trunk/src/main/java/org/apache/fontbox/cmap/CMap.java
Modified: pdfbox/fontbox/trunk/src/main/java/org/apache/fontbox/cmap/CMap.java
URL: http://svn.apache.org/viewvc/pdfbox/fontbox/trunk/src/main/java/org/apache/fontbox/cmap/CMap.java?rev=904817&r1=904816&r2=904817&view=diff
==============================================================================
--- pdfbox/fontbox/trunk/src/main/java/org/apache/fontbox/cmap/CMap.java (original)
+++ pdfbox/fontbox/trunk/src/main/java/org/apache/fontbox/cmap/CMap.java Sat Jan 30 17:24:38 2010
@@ -108,7 +108,7 @@
{
if( src.length == 1 )
{
- singleByteMappings.put( new Integer( src[0] ), dest );
+ singleByteMappings.put( new Integer( 0xFF & src[0] ), dest );
}
else if( src.length == 2 )
{
Added: pdfbox/fontbox/trunk/src/test/java/org/apache/fontbox/cff/Type1CharStringTest.java
URL: http://svn.apache.org/viewvc/pdfbox/fontbox/trunk/src/test/java/org/apache/fontbox/cff/Type1CharStringTest.java?rev=904817&view=auto
==============================================================================
--- pdfbox/fontbox/trunk/src/test/java/org/apache/fontbox/cff/Type1CharStringTest.java (added)
+++ pdfbox/fontbox/trunk/src/test/java/org/apache/fontbox/cff/Type1CharStringTest.java Sat Jan 30 17:24:38 2010
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+package org.apache.fontbox.cff;
+
+import static org.junit.Assert.assertEquals;
+import java.io.IOException;
+import org.junit.Test;
+import java.util.List;
+import java.util.ArrayList;
+
+public class Type1CharStringTest
+{
+
+ @Test
+ public void commandEncoding() throws IOException
+ {
+ List<Object> commands = createCommandSequence(new int[] { 0 },
+ new int[] { 12, 0 }, new int[] { 31 });
+
+ byte[] encodedCommands = new Type1CharStringFormatter().format(commands);
+ List<Object> decodedCommands = new Type1CharStringParser().parse(encodedCommands);
+
+ assertEquals(1 + 2 + 1, encodedCommands.length);
+
+ assertEquals(commands, decodedCommands);
+ }
+
+ @Test
+ public void numberEncoding() throws IOException
+ {
+ List<Object> numbers = createNumberSequence(-10000, -1131, -108, -107,
+ 0, 107, 108, 1131, 10000);
+
+ byte[] encodedNumbers = new Type1CharStringFormatter().format(numbers);
+ List<Object> decodedNumbers = new Type1CharStringParser()
+ .parse(encodedNumbers);
+
+ assertEquals(5 + 2 * 2 + 3 * 1 + 2 * 2 + 5, encodedNumbers.length);
+
+ assertEquals(numbers, decodedNumbers);
+ }
+
+ private static List<Object> createCommandSequence(int[]... values)
+ {
+ List<Object> sequence = new ArrayList<Object>();
+
+ for (int[] value : values)
+ {
+ sequence.add(value.length > 1 ? new CharStringCommand(value[0],
+ value[1]) : new CharStringCommand(value[0]));
+ }
+ return sequence;
+ }
+
+ private static List<Object> createNumberSequence(int... values)
+ {
+ List<Object> sequence = new ArrayList<Object>();
+
+ for (int value : values)
+ {
+ sequence.add(Integer.valueOf(value));
+ }
+
+ return sequence;
+ }
+}
\ No newline at end of file
Added: pdfbox/fontbox/trunk/src/test/java/org/apache/fontbox/cff/Type1FontUtilTest.java
URL: http://svn.apache.org/viewvc/pdfbox/fontbox/trunk/src/test/java/org/apache/fontbox/cff/Type1FontUtilTest.java?rev=904817&view=auto
==============================================================================
--- pdfbox/fontbox/trunk/src/test/java/org/apache/fontbox/cff/Type1FontUtilTest.java (added)
+++ pdfbox/fontbox/trunk/src/test/java/org/apache/fontbox/cff/Type1FontUtilTest.java Sat Jan 30 17:24:38 2010
@@ -0,0 +1,73 @@
+/*
+ * 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.
+ */
+package org.apache.fontbox.cff;
+
+import static org.junit.Assert.assertArrayEquals;
+import java.util.Random;
+import org.junit.Test;
+
+public class Type1FontUtilTest
+{
+
+ @Test
+ public void hexEncoding()
+ {
+ byte[] bytes = randomBytes(128);
+
+ String encodedBytes = Type1FontUtil.hexEncode(bytes);
+ byte[] decodedBytes = Type1FontUtil.hexDecode(encodedBytes);
+
+ assertArrayEquals(bytes, decodedBytes);
+ }
+
+ @Test
+ public void eexecEncryption()
+ {
+ byte[] bytes = randomBytes(128);
+
+ byte[] encryptedBytes = Type1FontUtil.eexecEncrypt(bytes);
+ byte[] decryptedBytes = Type1FontUtil.eexecDecrypt(encryptedBytes);
+
+ assertArrayEquals(bytes, decryptedBytes);
+ }
+
+ @Test
+ public void charstringEncryption()
+ {
+ byte[] bytes = randomBytes(128);
+
+ byte[] encryptedBytes = Type1FontUtil.charstringEncrypt(bytes, 4);
+ byte[] decryptedBytes = Type1FontUtil.charstringDecrypt(encryptedBytes,
+ 4);
+
+ assertArrayEquals(bytes, decryptedBytes);
+ }
+
+ private static byte[] randomBytes(int length)
+ {
+ byte[] bytes = new byte[length];
+
+ for (int i = 0; i < length; i++)
+ {
+ bytes[i] = (byte) RANDOM.nextInt(256);
+ }
+
+ return bytes;
+ }
+
+ private static final Random RANDOM = new Random();
+}
\ No newline at end of file
Added: pdfbox/fontbox/trunk/src/test/java/org/apache/fontbox/cmap/TestCMap.java
URL: http://svn.apache.org/viewvc/pdfbox/fontbox/trunk/src/test/java/org/apache/fontbox/cmap/TestCMap.java?rev=904817&view=auto
==============================================================================
--- pdfbox/fontbox/trunk/src/test/java/org/apache/fontbox/cmap/TestCMap.java (added)
+++ pdfbox/fontbox/trunk/src/test/java/org/apache/fontbox/cmap/TestCMap.java Sat Jan 30 17:24:38 2010
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+package org.apache.fontbox.cmap;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+/**
+ * This will test the CMap implementation.
+ *
+ * @version $Revision$
+ */
+public class TestCMap extends TestCase
+{
+
+ /**
+ * Check whether the mapping is working correct.
+ * @throws IOException If something went wrong during adding a mapping
+ */
+ public void testLookup() throws IOException
+ {
+ byte[] bs = new byte[1];
+ bs[0] = (byte)200;
+
+ CMap cMap = new CMap();
+ cMap.addMapping(bs, "a");
+ assertTrue("a".equals(cMap.lookup(bs, 0, 1)));
+ }
+}
Propchange: pdfbox/fontbox/trunk/src/test/java/org/apache/fontbox/cmap/TestCMap.java
------------------------------------------------------------------------------
svn:eol-style = native