xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbowdi...@apache.org
Subject svn commit: r1232845 - in /xmlgraphics/fop/trunk: ./ src/java/org/apache/fop/afp/fonts/ src/java/org/apache/fop/afp/goca/ src/java/org/apache/fop/afp/modca/ src/java/org/apache/fop/afp/svg/ test/java/org/apache/fop/afp/goca/
Date Wed, 18 Jan 2012 11:54:37 GMT
Author: cbowditch
Date: Wed Jan 18 11:54:36 2012
New Revision: 1232845

URL: http://svn.apache.org/viewvc?rev=1232845&view=rev
Log:
Bugzilla #51209:
SVG text in AFP creates miscoded GOCA text
Submitted by: Luis Bernardo

Added:
    xmlgraphics/fop/trunk/test/java/org/apache/fop/afp/goca/
    xmlgraphics/fop/trunk/test/java/org/apache/fop/afp/goca/GraphicsCharacterStringTestCase.java
Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharactersetEncoder.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/goca/GraphicsCharacterString.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/GraphicsObject.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/svg/AFPTextHandler.java
    xmlgraphics/fop/trunk/status.xml

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharactersetEncoder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharactersetEncoder.java?rev=1232845&r1=1232844&r2=1232845&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharactersetEncoder.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharactersetEncoder.java Wed Jan
18 11:54:36 2012
@@ -209,5 +209,17 @@ public abstract class CharactersetEncode
         public int getLength() {
             return length;
         }
+
+        /**
+         * The bytes
+         * 
+         * @return the bytes
+         */
+        public byte[] getBytes() {
+            // return copy just in case
+            byte[] copy = new byte[bytes.length];
+            System.arraycopy(bytes, 0, copy, 0, bytes.length);
+            return copy;
+        }
     }
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/goca/GraphicsCharacterString.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/goca/GraphicsCharacterString.java?rev=1232845&r1=1232844&r2=1232845&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/goca/GraphicsCharacterString.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/goca/GraphicsCharacterString.java Wed
Jan 18 11:54:36 2012
@@ -22,8 +22,9 @@ package org.apache.fop.afp.goca;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
+import java.nio.charset.CharacterCodingException;
 
-import org.apache.fop.afp.AFPConstants;
+import org.apache.fop.afp.fonts.CharacterSet;
 
 /**
  * A GOCA graphics string
@@ -34,7 +35,12 @@ public class GraphicsCharacterString ext
     protected static final int MAX_STR_LEN = 255;
 
     /** the string to draw */
-    protected final String str;
+    private final String str;
+
+    /**
+     * The character set encoding to use
+     */
+    private final CharacterSet charSet;
 
     /**
      * Constructor (absolute positioning)
@@ -42,20 +48,12 @@ public class GraphicsCharacterString ext
      * @param str the character string
      * @param x the x coordinate
      * @param y the y coordinate
+     * @param charSet the character set
      */
-    public GraphicsCharacterString(String str, int x, int y) {
+    public GraphicsCharacterString(String str, int x, int y, CharacterSet charSet) {
         super(x, y);
         this.str = truncate(str, MAX_STR_LEN);
-    }
-
-    /**
-     * Constructor (relative positioning)
-     *
-     * @param str the character string
-     */
-    public GraphicsCharacterString(String str) {
-        super(null);
-        this.str = truncate(str, MAX_STR_LEN);
+        this.charSet = charSet;
     }
 
     /** {@inheritDoc} */
@@ -84,9 +82,11 @@ public class GraphicsCharacterString ext
      * Returns the text string as an encoded byte array
      *
      * @return the text string as an encoded byte array
+     * @throws UnsupportedEncodingException, CharacterCodingException
      */
-    private byte[] getStringAsBytes() throws UnsupportedEncodingException {
-        return str.getBytes(AFPConstants.EBCIDIC_ENCODING);
+    private byte[] getStringAsBytes() throws UnsupportedEncodingException, 
+            CharacterCodingException {
+        return charSet.encodeChars(str).getBytes();
     }
 
     /** {@inheritDoc} */

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/GraphicsObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/GraphicsObject.java?rev=1232845&r1=1232844&r2=1232845&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/GraphicsObject.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/GraphicsObject.java Wed Jan 18
11:54:36 2012
@@ -33,6 +33,7 @@ import org.apache.fop.afp.AFPObjectAreaI
 import org.apache.fop.afp.Completable;
 import org.apache.fop.afp.Factory;
 import org.apache.fop.afp.StructuredData;
+import org.apache.fop.afp.fonts.CharacterSet;
 import org.apache.fop.afp.goca.GraphicsAreaBegin;
 import org.apache.fop.afp.goca.GraphicsAreaEnd;
 import org.apache.fop.afp.goca.GraphicsBox;
@@ -229,9 +230,9 @@ public class GraphicsObject extends Abst
      */
     public void setCharacterSet(int characterSet) {
         if (characterSet != graphicsState.characterSet) {
-            addObject(new GraphicsSetCharacterSet(characterSet));
             graphicsState.characterSet = characterSet;
         }
+        addObject(new GraphicsSetCharacterSet(characterSet));
     }
 
     /**
@@ -325,12 +326,8 @@ public class GraphicsObject extends Abst
      * @param x the x coordinate
      * @param y the y coordinate
      */
-    public void addString(String str, int x, int y) {
-        //Work-around for InfoPrint's AFP which loses character set state over Graphics Data
-        //boundaries.
-        addObject(new GraphicsSetCharacterSet(graphicsState.characterSet));
-
-        addObject(new GraphicsCharacterString(str, x, y));
+    public void addString(String str, int x, int y, CharacterSet charSet) {
+        addObject(new GraphicsCharacterString(str, x, y, charSet));
     }
 
     /**

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/svg/AFPTextHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/svg/AFPTextHandler.java?rev=1232845&r1=1232844&r2=1232845&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/svg/AFPTextHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/svg/AFPTextHandler.java Wed Jan 18 11:54:36
2012
@@ -147,10 +147,15 @@ public class AFPTextHandler extends FOPT
             fontSize = (int)Math.round(
                     g2d.convertToAbsoluteLength(fontSize));
             fontReference = registerPageFont(pageFonts, internalFontName, fontSize);
+            // TODO: re-think above registerPageFont code...
+            AFPFont afpFont = (AFPFont) fontInfo.getFonts().get(internalFontName);
+            final CharacterSet charSet = afpFont.getCharacterSet(fontSize);
+            // Work-around for InfoPrint's AFP which loses character set state
+            // over Graphics Data
+            // boundaries.
             graphicsObj.setCharacterSet(fontReference);
-
             // add the character string
-            graphicsObj.addString(str, Math.round(x), Math.round(y));
+            graphicsObj.addString(str, Math.round(x), Math.round(y), charSet);
         } else {
             //Inside Batik's SVG filter operations, you won't get an AFPGraphics2D
             g.drawString(str, x, y);

Modified: xmlgraphics/fop/trunk/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=1232845&r1=1232844&r2=1232845&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Wed Jan 18 11:54:36 2012
@@ -61,6 +61,9 @@
       documents. Example: the fix of marks layering will be such a case when it's done.
     -->
     <release version="FOP Trunk" date="TBD">
+      <action context="Code" dev="CB" type="add" fixes-bug="51209" due-to="Luis Bernardo">
+        SVG text in AFP creates miscoded GOCA text
+      </action>
       <action context="Code" dev="CB" type="add" fixes-bug="50391" due-to="Peter Hancock">
         Add support for different flow-name of fo:region-body in FOP
       </action>

Added: xmlgraphics/fop/trunk/test/java/org/apache/fop/afp/goca/GraphicsCharacterStringTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/afp/goca/GraphicsCharacterStringTestCase.java?rev=1232845&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/afp/goca/GraphicsCharacterStringTestCase.java
(added)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/afp/goca/GraphicsCharacterStringTestCase.java
Wed Jan 18 11:54:36 2012
@@ -0,0 +1,72 @@
+/*
+ * 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.fop.afp.goca;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.apache.fop.afp.fonts.CharacterSet;
+import org.apache.fop.afp.fonts.CharacterSetBuilder;
+import org.apache.fop.fonts.Typeface;
+import org.junit.Before;
+import org.junit.Test;
+
+public class GraphicsCharacterStringTestCase {
+    private GraphicsCharacterString gcsCp500;
+    private GraphicsCharacterString gcsCp1146;
+    // consider the EBCDIC code page variants Cp500 and Cp1146
+    // the £ corresponds to byte 5B (position 91) in the CCSID 285 and CCSID 1146
+    // the $ corresponds to byte 5B (position 91) in the CCSID 500
+    private final String poundsText = "££££";
+    private final String dollarsText = "$$$$";
+    private final byte[] bytesToCheck = {(byte) 0x5b, (byte) 0x5b, (byte) 0x5b, (byte) 0x5b};
+
+    @Before
+    public void setUp() throws Exception {
+        CharacterSetBuilder csb = CharacterSetBuilder.getSingleByteInstance();
+        CharacterSet cs1146 = csb.build("C0H200B0", "T1V10500", "Cp1146",
+                Class.forName("org.apache.fop.fonts.base14.Helvetica").asSubclass(Typeface.class)
+                .newInstance(), null);
+        gcsCp1146 = new GraphicsCharacterString(poundsText, 0, 0, cs1146);
+        CharacterSet cs500 = csb.build("C0H200B0", "T1V10500", "Cp500",
+                Class.forName("org.apache.fop.fonts.base14.Helvetica").asSubclass(Typeface.class)
+                .newInstance(), null);
+        gcsCp500 = new GraphicsCharacterString(dollarsText, 0, 0, cs500);
+    }
+
+    @Test
+    public void testWriteToStream() throws IOException {
+        // check pounds
+        ByteArrayOutputStream baos1146 = new ByteArrayOutputStream();
+        gcsCp1146.writeToStream(baos1146);
+        byte[] bytes1146 = baos1146.toByteArray();
+        for (int i = 0; i < bytesToCheck.length; i++) {
+            assertEquals(bytesToCheck[i], bytes1146[6 + i]);
+        }
+        assertEquals(bytesToCheck.length + 6, bytes1146.length);
+        // check dollars
+        ByteArrayOutputStream baos500 = new ByteArrayOutputStream();
+        gcsCp500.writeToStream(baos500);
+        byte[] bytes500 = baos500.toByteArray();
+        for (int i = 0; i < bytesToCheck.length; i++) {
+            assertEquals(bytesToCheck[i], bytes500[6 + i]);
+        }
+        assertEquals(bytesToCheck.length + 6, bytes500.length);
+    }
+}



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


Mime
View raw message