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/08/04 19:20:13 UTC

svn commit: r982333 - in /pdfbox/trunk/fontbox/src: main/java/org/apache/fontbox/cmap/CMapParser.java test/java/org/apache/fontbox/cmap/TestCMapParser.java test/resources/ test/resources/cmap/ test/resources/cmap/CMapTest

Author: lehmi
Date: Wed Aug  4 17:20:12 2010
New Revision: 982333

URL: http://svn.apache.org/viewvc?rev=982333&view=rev
Log:
PDFBOX-787: fixed CMapParser reading "begincidrange". Added a test case for the CMapParser

Added:
    pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/cmap/TestCMapParser.java
    pdfbox/trunk/fontbox/src/test/resources/
    pdfbox/trunk/fontbox/src/test/resources/cmap/
    pdfbox/trunk/fontbox/src/test/resources/cmap/CMapTest
Modified:
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java?rev=982333&r1=982332&r2=982333&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java Wed Aug  4 17:20:12 2010
@@ -165,10 +165,10 @@ public class CMapParser
                         Object nextToken = parseNextToken( cmapStream );
                         List<byte[]> array = null;
                         byte[] tokenBytes = null;
-                        if( nextToken instanceof List )
+                        if( nextToken instanceof List<?> )
                         {
-                            array = (List)nextToken;
-                            tokenBytes = (byte[])array.get( 0 );
+                            array = (List<byte[]>)nextToken;
+                            tokenBytes = array.get( 0 );
                         }
                         else
                         {
@@ -487,7 +487,7 @@ public class CMapParser
     {
         byte[] bytes = new byte[2];
         bytes[1] = (byte)(value % 256);
-        bytes[0] = (byte)(value & 0x00 >> 8);
+        bytes[0] = (byte)(value / 256);
         return bytes;
     }
 

Added: pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/cmap/TestCMapParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/cmap/TestCMapParser.java?rev=982333&view=auto
==============================================================================
--- pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/cmap/TestCMapParser.java (added)
+++ pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/cmap/TestCMapParser.java Wed Aug  4 17:20:12 2010
@@ -0,0 +1,54 @@
+/*
+ * 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.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+/**
+ * This will test the CMapParser implementation.
+ *
+ * @version $Revision$
+ */
+public class TestCMapParser extends TestCase 
+{
+
+    /**
+     * Check whether the parser and the resulting mapping is working correct.
+     * @throws IOException If something went wrong
+     */
+    public void testLookup() throws IOException
+    {
+        final String resourceDir= "src/test/resources/cmap"; 
+        File inDir = new File(resourceDir);
+        
+        CMapParser parser = new CMapParser();
+        CMap cMap = parser.parse( resourceDir, new FileInputStream(new File(inDir,"CMapTest")));
+        
+        byte[] bytes1 = {0,65};
+        assertTrue("A".equals(cMap.lookup(bytes1, 0, 2)));
+
+        byte[] bytes2 = {1,24};
+        String str2 = "\u0118";
+        assertTrue(str2.equals(cMap.lookup(bytes2, 0, 2)));
+
+    }
+
+}

Added: pdfbox/trunk/fontbox/src/test/resources/cmap/CMapTest
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/test/resources/cmap/CMapTest?rev=982333&view=auto
==============================================================================
--- pdfbox/trunk/fontbox/src/test/resources/cmap/CMapTest (added)
+++ pdfbox/trunk/fontbox/src/test/resources/cmap/CMapTest Wed Aug  4 17:20:12 2010
@@ -0,0 +1,33 @@
+%% 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.
+%%
+%% This file isn't a valid CMap file, but it contains everything what
+%% is needed to test the CMapParser
+%%
+%%EndComments
+
+1 begincodespacerange
+  <0000> <02FF>
+endcodespacerange
+
+3 begincidrange
+<0000> <00ff> 0
+<0100> <01ff> 256
+<0200> <02ff> 512
+
+endcmap
+
+%%EndResource
+%%EOF