You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2010/05/20 11:52:27 UTC

svn commit: r946585 - in /xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts: AFPFont.java AbstractOutlineFont.java CharacterSet.java CharacterSetBuilder.java CharacterSetOrientation.java DoubleByteFont.java FopCharacterSet.java RasterFont.java

Author: jeremias
Date: Thu May 20 09:52:27 2010
New Revision: 946585

URL: http://svn.apache.org/viewvc?rev=946585&view=rev
Log:
Changed many variables and parameters from "int" to "char" because AFP font support mostly uses Unicode code points unlike Type 1 and TrueType support which use internal character code points (the result of Font.mapChar()). This should improve code readability.

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/AFPFont.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/AbstractOutlineFont.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSet.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSetOrientation.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/DoubleByteFont.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/FopCharacterSet.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/RasterFont.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/AFPFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/AFPFont.java?rev=946585&r1=946584&r2=946585&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/AFPFont.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/AFPFont.java Thu May 20 09:52:27 2010
@@ -115,6 +115,16 @@ public abstract class AFPFont extends Ty
         return this.embeddable;
     }
 
+    /**
+     * Maps mapped code points to Unicode code points.
+     * @param character the mapped code point
+     * @return the corresponding Unicode code point
+     */
+    protected static final char toUnicodeCodepoint(int character) {
+        //AFP fonts use Unicode directly as their mapped code points, so we can simply cast to char
+        return (char)character;
+    }
+
     /** {@inheritDoc} */
     public String toString() {
         return "name=" + name;

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/AbstractOutlineFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/AbstractOutlineFont.java?rev=946585&r1=946584&r2=946585&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/AbstractOutlineFont.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/AbstractOutlineFont.java Thu May 20 09:52:27 2010
@@ -127,7 +127,7 @@ public abstract class AbstractOutlineFon
      * @return the width of the character for the specified point size
      */
     public int getWidth(int character, int size) {
-        return charSet.getWidth(character) * size;
+        return charSet.getWidth(toUnicodeCodepoint(character)) * size;
     }
 
     /**

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSet.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSet.java?rev=946585&r1=946584&r2=946585&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSet.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSet.java Thu May 20 09:52:27 2010
@@ -219,20 +219,18 @@ public class CharacterSet {
     /**
      * Returns the first character in the character set
      *
-     * @return the first character in the character set
+     * @return the first character in the character set (Unicode codepoint)
      */
-    public int getFirstChar() {
-
+    public char getFirstChar() {
         return getCharacterSetOrientation().getFirstChar();
     }
 
     /**
      * Returns the last character in the character set
      *
-     * @return the last character in the character set
+     * @return the last character in the character set (Unicode codepoint)
      */
-    public int getLastChar() {
-
+    public char getLastChar() {
         return getCharacterSetOrientation().getLastChar();
     }
 
@@ -268,11 +266,10 @@ public class CharacterSet {
      * Get the width (in 1/1000ths of a point size) of the character
      * identified by the parameter passed.
      *
-     * @param character the character from which the width will be calculated
+     * @param character the Unicode character from which the width will be calculated
      * @return the width of the character
      */
-    public int getWidth(int character) {
-
+    public int getWidth(char character) {
         return getCharacterSetOrientation().getWidth(character);
     }
 
@@ -393,7 +390,7 @@ public class CharacterSet {
      * The code tables are already converted to Unicode therefore
      * we can use the identity mapping.
      *
-     * @param c character to map
+     * @param c the Unicode character to map
      * @return the mapped character
      */
     public char mapChar(char c) {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java?rev=946585&r1=946584&r2=946585&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java Thu May 20 09:52:27 2010
@@ -155,6 +155,10 @@ public class CharacterSetBuilder {
             throw new FileNotFoundException("Invalid filename: "
                     + filename + " (" + e.getMessage() + ")");
         }
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Opening " + uri);
+        }
         InputStream inputStream = accessor.createInputStream(uri);
         return inputStream;
     }
@@ -291,7 +295,7 @@ public class CharacterSetBuilder {
      * @param encoding
      *            the encoding to use for the character decoding
      * @param accessor the resource accessor
-     * @return a code page mapping
+     * @return a code page mapping (key: GCGID, value: Unicode character)
      * @throws IOException if an I/O exception of some sort has occurred.
      */
     protected Map/*<String,String>*/ loadCodePage(String codePage, String encoding,
@@ -323,6 +327,10 @@ public class CharacterSetBuilder {
                     charBytes[0] = data[index];
                     String gcgiString = new String(gcgiBytes,
                             AFPConstants.EBCIDIC_ENCODING);
+                    //Use the 8-bit char index to find the Unicode character using the Java encoding
+                    //given in the configuration. If the code page and the Java encoding don't
+                    //match, a wrong Unicode character will be associated with the AFP GCGID.
+                    //Idea: we could use IBM's GCGID to Unicode map and build code pages ourselves.
                     String charString = new String(charBytes, encoding);
                     codePages.put(gcgiString, charString);
                 } else {
@@ -510,8 +518,8 @@ public class CharacterSetBuilder {
         byte[] gcgid = new byte[8];
         byte[] fiData = new byte[20];
 
-        int lowest = 255;
-        int highest = 0;
+        char lowest = 255;
+        char highest = 0;
         String firstABCMismatch = null;
 
         // Read data, ignoring bytes 0 - 2
@@ -534,7 +542,7 @@ public class CharacterSetBuilder {
 
                 if (idx != null) {
 
-                    int cidx = idx.charAt(0);
+                    char cidx = idx.charAt(0);
                     int width = getUBIN(fiData, 0);
                     int a = getSBIN(fiData, 10);
                     int b = getUBIN(fiData, 12);

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSetOrientation.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSetOrientation.java?rev=946585&r1=946584&r2=946585&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSetOrientation.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSetOrientation.java Thu May 20 09:52:27 2010
@@ -58,7 +58,7 @@ public class CharacterSetOrientation {
     private int capHeight;
 
     /**
-     * The character widths in the character set
+     * The character widths in the character set (indexed using Unicode codepoints)
      */
     private int[] charsWidths = null;
 
@@ -68,14 +68,14 @@ public class CharacterSetOrientation {
     private int xHeight;
 
     /**
-     * The first character
+     * The first character (Unicode codepoint)
      */
-    private int firstChar;
+    private char firstChar;
 
     /**
-     * The last character
+     * The last character (Unicode codepoint)
      */
-    private int lastChar;
+    private char lastChar;
 
 
     /**
@@ -138,17 +138,17 @@ public class CharacterSetOrientation {
 
     /**
      * The first character in the character set
-     * @return the first character
+     * @return the first character (Unicode codepoint)
      */
-    public int getFirstChar() {
+    public char getFirstChar() {
         return firstChar;
     }
 
     /**
      * The last character in the character set
-     * @return the last character
+     * @return the last character (Unicode codepoint)
      */
-    public int getLastChar() {
+    public char getLastChar() {
         return lastChar;
     }
 
@@ -183,15 +183,16 @@ public class CharacterSetOrientation {
     /**
      * Get the width (in 1/1000ths of a point size) of the character
      * identified by the parameter passed.
-     * @param characterIndex the character to evaluate
+     * @param character the Unicode character to evaluate
      * @return the widths of the character
      */
-    public int getWidth(int characterIndex) {
-        if (characterIndex >= charsWidths.length) {
-            throw new IllegalArgumentException("Invalid character index: "
-                    + characterIndex + ", maximum is " + (charsWidths.length - 1));
+    public int getWidth(char character) {
+        if (character >= charsWidths.length) {
+            throw new IllegalArgumentException("Invalid character: "
+                    + character + " (" + Integer.toString(character)
+                    + "), maximum is " + (charsWidths.length - 1));
         }
-        return charsWidths[characterIndex];
+        return charsWidths[character];
     }
 
     /**
@@ -234,7 +235,7 @@ public class CharacterSetOrientation {
      * The first character in the character set
      * @param firstChar the first character
      */
-    public void setFirstChar(int firstChar) {
+    public void setFirstChar(char firstChar) {
         this.firstChar = firstChar;
     }
 
@@ -242,17 +243,17 @@ public class CharacterSetOrientation {
      * The last character in the character set
      * @param lastChar the last character
      */
-    public void setLastChar(int lastChar) {
+    public void setLastChar(char lastChar) {
         this.lastChar = lastChar;
     }
 
     /**
      * Set the width (in 1/1000ths of a point size) of the character
      * identified by the parameter passed.
-     * @param character the character for which the width is being set
+     * @param character the Unicode character for which the width is being set
      * @param width the widths of the character
      */
-    public void setWidth(int character, int width) {
+    public void setWidth(char character, int width) {
         if (character >= charsWidths.length) {
             // Increase the size of the array if necessary
             //  TODO Can we remove firstChar? surely firstChar==0 at this stage?

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/DoubleByteFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/DoubleByteFont.java?rev=946585&r1=946584&r2=946585&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/DoubleByteFont.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/DoubleByteFont.java Thu May 20 09:52:27 2010
@@ -55,7 +55,7 @@ public class DoubleByteFont extends Abst
     public int getWidth(int character, int size) {
         int charWidth;
         try {
-            charWidth = charSet.getWidth(character);
+            charWidth = charSet.getWidth(toUnicodeCodepoint(character));
         } catch (IllegalArgumentException e) {
             //  We shall try and handle characters that have no mapped width metric in font resource
             charWidth = -1;

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/FopCharacterSet.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/FopCharacterSet.java?rev=946585&r1=946584&r2=946585&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/FopCharacterSet.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/FopCharacterSet.java Thu May 20 09:52:27 2010
@@ -88,7 +88,7 @@ public class FopCharacterSet extends Cha
      * The first character in the character set
      * @return the first character
      */
-    public int getFirstChar() {
+    public char getFirstChar() {
         return 0;
     }
 
@@ -96,7 +96,7 @@ public class FopCharacterSet extends Cha
      * The last character in the character set
      * @return the last character
      */
-    public int getLastChar() {
+    public char getLastChar() {
         return 0;
     }
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/RasterFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/RasterFont.java?rev=946585&r1=946584&r2=946585&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/RasterFont.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/RasterFont.java Thu May 20 09:52:27 2010
@@ -232,7 +232,7 @@ public class RasterFont extends AFPFont 
      */
     public int getWidth(int character, int size) {
         CharacterSet cs = getCharacterSet(size);
-        return metricsToAbsoluteSize(cs, cs.getWidth(character), size);
+        return metricsToAbsoluteSize(cs, cs.getWidth(toUnicodeCodepoint(character)), size);
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Re: svn commit: r946585 - in /xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts: AFPFont.java AbstractOutlineFont.java CharacterSet.java CharacterSetBuilder.java CharacterSetOrientation.java DoubleByteFont.java FopCharacterSet.java RasterFont.java

Posted by Vincent Hennebert <vh...@gmail.com>.
Ok.

Thanks,
Vincent


Jeremias Maerki wrote:
> Hi Vincent,
> 
> in the long term, I agree with you. But as long as so many other parts
> of FOP (like Font.mapChar()) use "char", there's no point to use "int"
> in the backend. There will never be any characters outside the basic
> plane until the whole process from input through layout engine to
> rendering components are prepared for these characters. In the short
> term, my change really improves understandability which is usually one
> of your major concerns. It helped me a lot identifying a problem. The
> changes can easily be reverted once there is a concerted effort to
> make the whole of FOP compatible with the full range of Unicode
> characters. It's also important to note that the AFP part will need some
> special attention when these characters need to be used as some of the
> data structures in there will get insanely large if we start supporting
> characters beyong the basic plane. So unless there is a sustained veto
> against rev 946585 I'm inclined to leave it like it is.
> 
> On 21.05.2010 11:46:42 Vincent Hennebert wrote:
>> Hi,
>>
>>> Author: jeremias
>>> Date: Thu May 20 09:52:27 2010
>>> New Revision: 946585
>>>
>>> URL: http://svn.apache.org/viewvc?rev=946585&view=rev
>>> Log:
>>> Changed many variables and parameters from "int" to "char" because AFP font support mostly uses Unicode code points unlike Type 1 and TrueType support which use internal character code points (the result of Font.mapChar()). This should improve code readability.
>> Not sure this is a desirable change. char can only address characters
>> from the Basic Multilingual Plane. Java 1.5 have started to use int to
>> overcome that issue actually. So unless there is a fundamental
>> limitation in AFP such that characters beyond the BMP will never be
>> usable, I think we want to stick to int.
>>
>> <snip/>
>>
>> Vincent
> 
> 
> 
> 
> Jeremias Maerki
> 

Re: svn commit: r946585 - in /xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts: AFPFont.java AbstractOutlineFont.java CharacterSet.java CharacterSetBuilder.java CharacterSetOrientation.java DoubleByteFont.java FopCharacterSet.java RasterFont.java

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
Hi Vincent,

in the long term, I agree with you. But as long as so many other parts
of FOP (like Font.mapChar()) use "char", there's no point to use "int"
in the backend. There will never be any characters outside the basic
plane until the whole process from input through layout engine to
rendering components are prepared for these characters. In the short
term, my change really improves understandability which is usually one
of your major concerns. It helped me a lot identifying a problem. The
changes can easily be reverted once there is a concerted effort to
make the whole of FOP compatible with the full range of Unicode
characters. It's also important to note that the AFP part will need some
special attention when these characters need to be used as some of the
data structures in there will get insanely large if we start supporting
characters beyong the basic plane. So unless there is a sustained veto
against rev 946585 I'm inclined to leave it like it is.

On 21.05.2010 11:46:42 Vincent Hennebert wrote:
> Hi,
> 
> > Author: jeremias
> > Date: Thu May 20 09:52:27 2010
> > New Revision: 946585
> > 
> > URL: http://svn.apache.org/viewvc?rev=946585&view=rev
> > Log:
> > Changed many variables and parameters from "int" to "char" because AFP font support mostly uses Unicode code points unlike Type 1 and TrueType support which use internal character code points (the result of Font.mapChar()). This should improve code readability.
> 
> Not sure this is a desirable change. char can only address characters
> from the Basic Multilingual Plane. Java 1.5 have started to use int to
> overcome that issue actually. So unless there is a fundamental
> limitation in AFP such that characters beyond the BMP will never be
> usable, I think we want to stick to int.
> 
> <snip/>
> 
> Vincent




Jeremias Maerki


Re: svn commit: r946585 - in /xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts: AFPFont.java AbstractOutlineFont.java CharacterSet.java CharacterSetBuilder.java CharacterSetOrientation.java DoubleByteFont.java FopCharacterSet.java RasterFont.java

Posted by Vincent Hennebert <vh...@gmail.com>.
Hi,

> Author: jeremias
> Date: Thu May 20 09:52:27 2010
> New Revision: 946585
> 
> URL: http://svn.apache.org/viewvc?rev=946585&view=rev
> Log:
> Changed many variables and parameters from "int" to "char" because AFP font support mostly uses Unicode code points unlike Type 1 and TrueType support which use internal character code points (the result of Font.mapChar()). This should improve code readability.

Not sure this is a desirable change. char can only address characters
from the Basic Multilingual Plane. Java 1.5 have started to use int to
overcome that issue actually. So unless there is a fundamental
limitation in AFP such that characters beyond the BMP will never be
usable, I think we want to stick to int.

<snip/>

Vincent