]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-2985: Revert AFP reset character spacing
authorSimon Steiner <ssteiner@apache.org>
Wed, 2 Aug 2023 08:01:31 +0000 (09:01 +0100)
committerSimon Steiner <ssteiner@apache.org>
Wed, 2 Aug 2023 08:01:31 +0000 (09:01 +0100)
fop-core/src/main/java/org/apache/fop/afp/ptoca/PtocaBuilder.java
fop-core/src/main/java/org/apache/fop/render/afp/AFPPainter.java
fop-core/src/test/java/org/apache/fop/render/afp/AFPPainterTestCase.java

index 63026ee84e22b8ccee9dbeb90978e2536f275853..084ba5daad75b76f2a52bc64d334a7190b79f5de 100644 (file)
@@ -360,26 +360,6 @@ public abstract class PtocaBuilder implements PtocaConstants {
         this.currentInterCharacterAdjustment = incr;
     }
 
-    /**
-     * Resets the intercharacter adjustment (additional increment or decrement between graphic
-     * characters) to 0.
-     * <p>
-     * This is a modal control sequence.
-     *
-     * @throws IOException if an I/O error occurs
-     */
-    public void resetInterCharacterAdjustment() throws IOException {
-        if (0 == this.currentInterCharacterAdjustment) {
-            return;
-        }
-        newControlSequence();
-        writeShort(0); //Increment
-        writeBytes(0); // Direction
-        commit(chained(SIA));
-
-        this.currentInterCharacterAdjustment = 0;
-    }
-
     /**
      * A control sequence is a sequence of bytes that specifies a control
      * function. A control sequence consists of a control sequence introducer
index 66ada9facb1f0cd657688a6331e60b8b4b5307a3..9a4a7b93e3245940daeb9b3bd65db38d4bba8eae 100644 (file)
@@ -1102,7 +1102,6 @@ public class AFPPainter extends AbstractIFPainter<AFPDocumentHandler> {
                     }
                 }
             }
-            builder.resetInterCharacterAdjustment();
             flushText(builder, sb, charSet);
             if (pto != null) {
                 bytesAvailable = pto.getBytesAvailable();
index b396d6d67d2ab09f45338c5fdae2135eec6ba5db..92bf91edb6cd0be2a3ea8a634a89a080239e54fe 100644 (file)
@@ -24,6 +24,7 @@ import java.awt.Dimension;
 import java.awt.Rectangle;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -44,8 +45,6 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import org.apache.commons.io.IOUtils;
-
 import org.apache.xmlgraphics.image.loader.Image;
 import org.apache.xmlgraphics.image.loader.ImageException;
 import org.apache.xmlgraphics.image.loader.ImageFlavor;
@@ -63,6 +62,9 @@ import org.apache.fop.afp.fonts.CharacterSet;
 import org.apache.fop.afp.fonts.CharactersetEncoder;
 import org.apache.fop.afp.fonts.OutlineFontTestCase;
 import org.apache.fop.afp.fonts.RasterFont;
+import org.apache.fop.afp.parser.MODCAParser;
+import org.apache.fop.afp.parser.UnparsedStructuredField;
+import org.apache.fop.afp.ptoca.PtocaConstants;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.FopFactory;
 import org.apache.fop.events.Event;
@@ -212,36 +214,37 @@ public class AFPPainterTestCase {
                 + "END DOCUMENT DOC00001\n");
     }
 
-    /**
-     * Checks that letter spacing is reset to 0 after the relevant text block.
-     */
     @Test
-    public void testLetterSpacingReset() throws Exception {
+    public void testLetterSpacing() throws Exception {
         List<String> strings = new ArrayList<>();
         strings.add("xxxx");
-        InputStream inputStream = getDocResultInputStream(strings, 10000);
-        byte[] bytes = IOUtils.toByteArray(inputStream);
-        // The 134th byte is incremented by 5 to account for the 5 extra bytes inserted for the reset.
-        Assert.assertEquals((byte)39, bytes[134]);
-        // And these are the 5 reset bytes.
-        Assert.assertEquals((byte)5, bytes[163]);
-        Assert.assertEquals((byte)195, bytes[164]);
-        Assert.assertEquals((byte)0, bytes[165]);
-        Assert.assertEquals((byte)0, bytes[166]);
-        Assert.assertEquals((byte)0, bytes[167]);
+        InputStream bis = getDocResultInputStream(strings, 10000);
+        MODCAParser parser = new MODCAParser(bis);
+        UnparsedStructuredField field;
+        while ((field = parser.readNextStructuredField()) != null) {
+            if (field.toString().contains("Data Presentation Text")) {
+                break;
+            }
+        }
+        DataInputStream data = new DataInputStream(new ByteArrayInputStream(field.getData()));
+        data.skip(13); //2 for controlInd
+        Assert.assertEquals(data.readByte(), 5); //len
+        Assert.assertEquals(data.readByte(), PtocaConstants.SIA  | PtocaConstants.CHAIN_BIT); //functionType
+        Assert.assertEquals(data.readShort(), 33); //Increment
+        Assert.assertEquals(data.readByte(), 0); //Direction
+        data.skip(4); //varSpaceCharacterIncrement
+        //flushText:
+        Assert.assertEquals(data.readByte(), 2); //len
+        Assert.assertEquals(data.readByte(), PtocaConstants.TRN  | PtocaConstants.CHAIN_BIT); //functionType
     }
 
     private String writeText(List<String> text) throws Exception {
-        InputStream bis = getDocResultInputStream(text);
+        InputStream bis = getDocResultInputStream(text, 0);
         StringBuilder sb = new StringBuilder();
         new AFPParser(false).read(bis, sb);
         return sb.toString();
     }
 
-    private static InputStream getDocResultInputStream(List<String> text) throws Exception {
-        return getDocResultInputStream(text, 0);
-    }
-
     private static InputStream getDocResultInputStream(List<String> text, int letterSpacing) throws Exception {
         FOUserAgent agent = FopFactory.newInstance(new URI(".")).newFOUserAgent();
         IFContext context = new IFContext(agent);
@@ -266,7 +269,6 @@ public class AFPPainterTestCase {
             afpPainter.drawText(0, 0, letterSpacing, 0, null, s);
         }
         doc.endDocument();
-
         return new ByteArrayInputStream(outputStream.toByteArray());
     }