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 2011/10/03 17:19:11 UTC

svn commit: r1178428 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/encoding/Encoding.java

Author: lehmi
Date: Mon Oct  3 15:19:11 2011
New Revision: 1178428

URL: http://svn.apache.org/viewvc?rev=1178428&view=rev
Log:
PDFBOX-1127: added and transformation for unicode constants starting with an "u" within an encoding dictionary

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=1178428&r1=1178427&r2=1178428&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 Mon Oct  3 15:19:11 2011
@@ -44,7 +44,7 @@ public abstract class Encoding implement
     /**
      * Log instance.
      */
-    private static final Log log = LogFactory.getLog(Encoding.class);
+    private static final Log LOG = LogFactory.getLog(Encoding.class);
 
     /** Identifies a non-mapped character. */
     public static final String NOTDEF = ".notdef";
@@ -125,29 +125,30 @@ public abstract class Encoding implement
                     int semicolonIndex = line.indexOf( ';' );
                     if( semicolonIndex >= 0 )
                     {
+                        String unicodeValue = null;
                         try
                         {
                             String characterName = line.substring( 0, semicolonIndex );
-                            String unicodeValue = line.substring( semicolonIndex+1, line.length() );
+                            unicodeValue = line.substring( semicolonIndex+1, line.length() );
                             StringTokenizer tokenizer = new StringTokenizer( unicodeValue, " ", false );
-                            String value = "";
+                            StringBuilder value = new StringBuilder();
                             while(tokenizer.hasMoreTokens())
                             {
                                 int characterCode = Integer.parseInt( tokenizer.nextToken(), 16 );
-                                value += (char)characterCode;
+                                value.append((char)characterCode);
                             }
                             if (NAME_TO_CHARACTER.containsKey(characterName))
                             {
-                                log.warn("duplicate value for characterName="+characterName+","+value);
+                                LOG.warn("duplicate value for characterName="+characterName+","+value);
                             }
                             else
                             {
-                                NAME_TO_CHARACTER.put( characterName, value );
+                                NAME_TO_CHARACTER.put( characterName, value.toString() );
                             }
                         }
                         catch( NumberFormatException nfe )
                         {
-                            nfe.printStackTrace();
+                            LOG.error("malformed unicode value "+ unicodeValue, nfe);
                         }
                     }
                 }
@@ -155,7 +156,7 @@ public abstract class Encoding implement
         }
         catch( IOException io )
         {
-            io.printStackTrace();
+            LOG.error("error while reading the glyph list.", io);
         }
         finally
         {
@@ -167,7 +168,7 @@ public abstract class Encoding implement
                 }
                 catch( IOException e )
                 {
-                    e.printStackTrace();
+                    LOG.error("error when closing the glyph list.", e);
                 }
 
             }
@@ -305,9 +306,9 @@ public abstract class Encoding implement
                     {
                         int characterCode = Integer.parseInt( name.substring( chPos, chPos + 4), 16 );
 
-                        if ( ( characterCode > 0xD7FF ) && ( characterCode < 0xE000 ) )
+                        if ( characterCode > 0xD7FF && characterCode < 0xE000 )
                         {
-                            log.warn( "Unicode character name with not allowed code area: " + name );
+                            LOG.warn( "Unicode character name with not allowed code area: " + name );
                         }
                         else
                         {
@@ -319,7 +320,29 @@ public abstract class Encoding implement
                 }
                 catch (NumberFormatException nfe)
                 {
-                    log.warn( "Not a number in Unicode character name: " + name );
+                    LOG.warn( "Not a number in Unicode character name: " + name );
+                    character = name;
+                }
+            }
+            // test for an alternate Unicode name representation 
+            else if ( name.startsWith( "u" ) )
+            {
+                try
+                {
+                    int characterCode = Integer.parseInt( name.substring( 1 ), 16 );
+                    if ( characterCode > 0xD7FF && characterCode < 0xE000 )
+                    {
+                        LOG.warn( "Unicode character name with not allowed code area: " + name );
+                    }
+                    else
+                    {
+                        character = String.valueOf((char)characterCode);
+                        NAME_TO_CHARACTER.put(name, character);
+                    }
+                }
+                catch (NumberFormatException nfe)
+                {
+                    LOG.warn( "Not a number in Unicode character name: " + name );
                     character = name;
                 }
             }