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/05/16 18:11:36 UTC

svn commit: r944875 - in /pdfbox/trunk/pdfbox/src/main: java/org/apache/pdfbox/encoding/Encoding.java resources/Resources/additional_glyphlist.txt

Author: lehmi
Date: Sun May 16 16:11:36 2010
New Revision: 944875

URL: http://svn.apache.org/viewvc?rev=944875&view=rev
Log:
PDFBOX-534: added some more algos for font encoding to improve text parsing of pdfs created with TeX/LateX

Added:
    pdfbox/trunk/pdfbox/src/main/resources/Resources/additional_glyphlist.txt
Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/encoding/Encoding.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/encoding/Encoding.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/encoding/Encoding.java?rev=944875&r1=944874&r2=944875&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/encoding/Encoding.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/encoding/Encoding.java Sun May 16 16:11:36 2010
@@ -47,26 +47,18 @@ public abstract class Encoding implement
     /**
      * This is a mapping from a character code to a character name.
      */
-//    protected final Map<Integer, COSName> codeToName =
-//        new HashMap<Integer, COSName>();
     protected final Map<Integer, String> codeToName =
         new HashMap<Integer, String>();
 
     /**
      * This is a mapping from a character name to a character code.
      */
-//    protected final Map<COSName, Integer> nameToCode =
-//        new HashMap<COSName, Integer>();
     protected final Map<String, Integer> nameToCode =
         new HashMap<String, Integer>();
 
-//    private static final Map<COSName, String> NAME_TO_CHARACTER =
-//        new HashMap<COSName, String>();
     private static final Map<String, String> NAME_TO_CHARACTER =
         new HashMap<String, String>();
 
-//    private static final Map<String, COSName> CHARACTER_TO_NAME =
-//        new HashMap<String, COSName>();
     private static final Map<String, String> CHARACTER_TO_NAME =
         new HashMap<String, String>();
 
@@ -74,6 +66,8 @@ public abstract class Encoding implement
     {
         //Loads the official Adobe Glyph List
         loadGlyphList("Resources/glyphlist.txt");
+        //Loads some additional glyph mappings
+        loadGlyphList("Resources/additional_glyphlist.txt");
 
         // Load an external glyph list file that user can give as JVM property
         String location = System.getProperty("glyphlist_ext");
@@ -93,16 +87,6 @@ public abstract class Encoding implement
         NAME_TO_CHARACTER.put( "ff", "ff" );
         NAME_TO_CHARACTER.put( "pi", "pi" );
 
-        // add some (alternative) glyph mappings. These are missing in
-        // the original copy of the adobe glyphlist.txt 
-        // also mapped as anglebracketleft
-        NAME_TO_CHARACTER.put("angbracketleft", "\u3008");
-        // also mapped as anglebracketright
-        NAME_TO_CHARACTER.put("angbracketright", "\u3009");
-        // also mapped as copyright
-        NAME_TO_CHARACTER.put("circlecopyrt", "\u00A9");
-        NAME_TO_CHARACTER.put("controlNULL", "\u0000");
-
         for( Map.Entry<String, String> entry : NAME_TO_CHARACTER.entrySet() )
         {
             CHARACTER_TO_NAME.put( entry.getValue(), entry.getKey() );
@@ -142,7 +126,14 @@ public abstract class Encoding implement
                                 int characterCode = Integer.parseInt( tokenizer.nextToken(), 16 );
                                 value += (char)characterCode;
                             }
-                            NAME_TO_CHARACTER.put( characterName, value );
+                            if (NAME_TO_CHARACTER.containsKey(characterName))
+                            {
+                                log.warn("duplicate value for characterName="+characterName+","+value);
+                            }
+                            else
+                            {
+                                NAME_TO_CHARACTER.put( characterName, value );
+                            }
                         }
                         catch( NumberFormatException nfe )
                         {
@@ -238,8 +229,6 @@ public abstract class Encoding implement
         {
             //lets be forgiving for now
             name = "space";
-            //throw new IOException( getClass().getName() +
-            //                       ": No name for character code '" + code + "'" );
         }
         return name;
     }
@@ -274,8 +263,7 @@ public abstract class Encoding implement
      */
     public String getCharacter( int code ) throws IOException
     {
-        String character = getCharacter( getName( code ) );
-        return character;
+        return getCharacter( getName( code ) );
     }
 
     /**
@@ -288,7 +276,6 @@ public abstract class Encoding implement
     public static String getCharacter( String name )
     {
         String baseName = name;
- 
         String character = NAME_TO_CHARACTER.get( baseName );
         if( character == null )
         {
@@ -321,6 +308,31 @@ public abstract class Encoding implement
                     }
                 }
                 character = uniStr.toString();
+                NAME_TO_CHARACTER.put(name, character);
+            }
+            // this hexadecimal encoding is used in pdfs generated by TeX/LateX 
+            else if (nameStr.startsWith("x")) 
+            {
+                try {
+                    int value = Integer.parseInt(nameStr.substring(1), 16);
+                    character = ""+(char)value;
+                    NAME_TO_CHARACTER.put(name, character);
+                }
+                catch(NumberFormatException exception) {
+                    log.warn( "Not a number in hexadecimal character name: " + nameStr );
+                }
+            }
+            // this decimal encoding is used in pdfs generated by TeX/LateX 
+            else if (nameStr.startsWith("a")) 
+            {
+                try {
+                    int value = Integer.parseInt(nameStr.substring(1));
+                    character = ""+(char)value;
+                    NAME_TO_CHARACTER.put(name, character);
+                }
+                catch(NumberFormatException exception) {
+                    log.warn( "Not a number in dezimal character name: " + nameStr );
+                }
             }
             else 
             {

Added: pdfbox/trunk/pdfbox/src/main/resources/Resources/additional_glyphlist.txt
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/resources/Resources/additional_glyphlist.txt?rev=944875&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/resources/Resources/additional_glyphlist.txt (added)
+++ pdfbox/trunk/pdfbox/src/main/resources/Resources/additional_glyphlist.txt Sun May 16 16:11:36 2010
@@ -0,0 +1,134 @@
+#
+# 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.
+#
+# Format: Semicolon-delimited fields:
+#            (1) glyph name
+#            (2) Unicode scalar value
+#
+# These mappings are missing in the original copy of the adobe glyphlist.txt 
+# 
+angbracketleft;3008
+angbracketright;3009
+circlecopyrt;00A9
+controlNULL;0000
+#
+# TeX-related mappings
+#
+angbracketleftbig;2329
+angbracketleftBig;2329
+angbracketleftbigg;2329
+angbracketleftBigg;2329
+angbracketrightBig;232A
+angbracketrightbig;232A
+angbracketrightBigg;232A
+angbracketrightbigg;232A
+backslashbig;2216
+backslashBig;2216
+backslashBigg;2216
+backslashbigg;2216
+bardbl;2016
+bracehtipdownleft;FE37
+bracehtipdownright;FE37
+bracehtipupleft;FE38
+bracehtipupright;FE38
+braceleftBig;007B
+braceleftbig;007B
+braceleftbigg;007B
+braceleftBigg;007B
+bracerightBig;007D
+bracerightbig;007D
+bracerightbigg;007D
+bracerightBigg;007D
+bracketleftbig;005B
+bracketleftBig;005B
+bracketleftbigg;005B
+bracketleftBigg;005B
+bracketrightBig;005D
+bracketrightbig;005D
+bracketrightbigg;005D
+bracketrightBigg;005D
+ceilingleftbig;2308
+ceilingleftBig;2308
+ceilingleftBigg;2308
+ceilingleftbigg;2308
+ceilingrightbig;2309
+ceilingrightBig;2309
+ceilingrightbigg;2309
+ceilingrightBigg;2309
+circledotdisplay;2299
+circledottext;2299
+circlemultiplydisplay;2297
+circlemultiplytext;2297
+circleplusdisplay;2295
+circleplustext;2295
+contintegraldisplay;222E
+contintegraltext;222E
+coproductdisplay;2210
+coproducttext;2210
+floorleftBig;230A
+floorleftbig;230A
+floorleftbigg;230A
+floorleftBigg;230A
+floorrightbig;230B
+floorrightBig;230B
+floorrightBigg;230B
+floorrightbigg;230B
+hatwide;0302
+hatwider;0302
+hatwidest;0302
+integraldisplay;222B
+integraltext;222B
+intersectiondisplay;22C2
+intersectiontext;22C2
+logicalanddisplay;2227
+logicalandtext;2227
+logicalordisplay;2228
+logicalortext;2228
+parenleftBig;0028
+parenleftbig;0028
+parenleftBigg;0028
+parenleftbigg;0028
+parenrightBig;0029
+parenrightbig;0029
+parenrightBigg;0029
+parenrightbigg;0029
+prime;2032
+productdisplay;220F
+producttext;220F
+radicalbig;221A
+radicalBig;221A
+radicalBigg;221A
+radicalbigg;221A
+radicalbt;221A
+radicaltp;221A
+radicalvertex;221A
+slashbig;002F
+slashBig;002F
+slashBigg;002F
+slashbigg;002F
+summationdisplay;2211
+summationtext;2211
+tildewide;02DC
+tildewider;02DC
+tildewidest;02DC
+uniondisplay;22C3
+unionmultidisplay;228E
+unionmultitext;228E
+unionsqdisplay;2294
+unionsqtext;2294
+uniontext;22C3
+vextenddouble;2225
+vextendsingle;2223