]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-2989: Missing text in AFP output when using high resolution
authorSimon Steiner <ssteiner@apache.org>
Tue, 15 Dec 2020 13:28:47 +0000 (13:28 +0000)
committerSimon Steiner <ssteiner@apache.org>
Tue, 15 Dec 2020 13:28:47 +0000 (13:28 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1884462 13f79535-47bb-0310-9956-ffa450edef68

fop-core/src/main/java/org/apache/fop/render/afp/AFPPainter.java
fop-core/src/test/java/org/apache/fop/afp/fonts/OutlineFontTestCase.java [new file with mode: 0644]
fop-core/src/test/java/org/apache/fop/render/afp/AFPPainterTestCase.java

index 69cfb4f80659c9d49d62f8beb7839dc9c6088d94..a0ca446f4838c20ae9af9d67bea4a9b254197dcd 100644 (file)
@@ -915,7 +915,7 @@ public class AFPPainter extends AbstractIFPainter<AFPDocumentHandler> {
         final Font font;
         final AFPFont afpFont;
         final CharacterSet charSet;
-        final PresentationTextObject pto;
+        PresentationTextObject pto;
 
         private DefaultPtocaProducer(int x, int y,
                                       final int letterSpacing, final int wordSpacing, final int[][] dp,
@@ -960,7 +960,12 @@ public class AFPPainter extends AbstractIFPainter<AFPDocumentHandler> {
                     page.endPresentationObject();
                 }
                 pto = page.getPresentationTextObject();
-                pto.createControlSequences(this);
+                boolean success = pto.createControlSequences(this);
+                if (!success) {
+                    page.endPresentationObject();
+                    pto = page.getPresentationTextObject();
+                    pto.createControlSequences(this);
+                }
             } catch (IOException ioe) {
                 throw new IFException("I/O error in drawText()", ioe);
             }
diff --git a/fop-core/src/test/java/org/apache/fop/afp/fonts/OutlineFontTestCase.java b/fop-core/src/test/java/org/apache/fop/afp/fonts/OutlineFontTestCase.java
new file mode 100644 (file)
index 0000000..92571cf
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+
+/* $Id$ */
+package org.apache.fop.afp.fonts;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.fop.fonts.Font;
+
+public class OutlineFontTestCase {
+    @Test
+    public void testWidth() {
+        CharacterSet characterSet = getCharacterSet();
+        OutlineFont outlineFont = new OutlineFont(null, true, characterSet, null);
+        Font font = new Font(null, null, outlineFont, 26000);
+        Assert.assertEquals(font.getWidth(' '), 0);
+    }
+
+    public static CharacterSet getCharacterSet() {
+        CharacterSet characterSet = new CharacterSet(null, "utf-8", CharacterSetType.SINGLE_BYTE, "", null, null);
+        characterSet.addCharacterSetOrientation(new CharacterSetOrientation(0, 0, 0, 0));
+        return characterSet;
+    }
+}
index abb1ecdcbb9ac2d46ddebb15de856f5b5e162f16..6354a5909568828ceca5dafc456ab3842b87bd78 100644 (file)
@@ -57,6 +57,7 @@ import org.apache.fop.afp.AFPPaintingState;
 import org.apache.fop.afp.AFPResourceManager;
 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.apps.FOUserAgent;
 import org.apache.fop.apps.FopFactory;
@@ -248,14 +249,45 @@ public class AFPPainterTestCase {
         documentHandler.startDocument();
         documentHandler.startPage(0, "", "", new Dimension());
         AFPPainter afpPainter = new AFPPainter(documentHandler);
-        int style = Constants.EN_DOTTED;
-        BorderProps.Mode mode = BorderProps.Mode.COLLAPSE_OUTER;
-        Color color = ColorUtil.parseColorString(ua, "fop-rgb-icc(0.5019608,0.5019608,0.5019608,#CMYK,,0,0,0,0.5)");
-        int borderWidth = 500;
-        int radiusStart = 0;
-        int radiusEnd = 0;
-        BorderProps border1 = new BorderProps(style, borderWidth, radiusStart, radiusEnd, color, mode);
-        afpPainter.drawBorderRect(new Rectangle(0, 0, 552755, 16090), null, border1, null, null, Color.WHITE);
+        drawBorder(afpPainter, ua);
+        documentHandler.endDocument();
+
+        InputStream bis = new ByteArrayInputStream(os.toByteArray());
+        StringBuilder sb = new StringBuilder();
+        new AFPParser(false).read(bis, sb);
+        Assert.assertEquals(sb.toString(), "BEGIN DOCUMENT DOC00001\n"
+                + "BEGIN PAGE PGN00001\n"
+                + "BEGIN ACTIVE_ENVIRONMENT_GROUP AEG00001\n"
+                + "DESCRIPTOR PAGE\n"
+                + "MIGRATION PRESENTATION_TEXT\n"
+                + "END ACTIVE_ENVIRONMENT_GROUP AEG00001\n"
+                + "BEGIN PRESENTATION_TEXT PT000001\n"
+                + "DATA PRESENTATION_TEXT\n"
+                + "END PRESENTATION_TEXT PT000001\n"
+                + "BEGIN PRESENTATION_TEXT PT000002\n"
+                + "DATA PRESENTATION_TEXT\n"
+                + "END PRESENTATION_TEXT PT000002\n"
+                + "END PAGE PGN00001\n"
+                + "END DOCUMENT DOC00001\n");
+    }
+
+    @Test
+    public void testDrawBorderRectAndText() throws IFException, PropertyException, IOException {
+        FOUserAgent ua = FopFactory.newInstance(new File(".").toURI()).newFOUserAgent();
+        AFPDocumentHandler documentHandler = new AFPDocumentHandler(new IFContext(ua));
+        documentHandler.setResolution(480);
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        documentHandler.setResult(new StreamResult(os));
+        documentHandler.startDocument();
+        documentHandler.startPage(0, "", "", new Dimension());
+        AFPPainter afpPainter = new AFPPainter(documentHandler);
+        setFont(documentHandler, afpPainter);
+        drawBorder(afpPainter, ua);
+        StringBuilder text = new StringBuilder();
+        for (int i = 0; i < 4770; i++) {
+            text.append("a");
+        }
+        afpPainter.drawText(0, 0, 0, 0, null, text.toString());
         documentHandler.endDocument();
 
         InputStream bis = new ByteArrayInputStream(os.toByteArray());
@@ -273,7 +305,32 @@ public class AFPPainterTestCase {
                 + "BEGIN PRESENTATION_TEXT PT000002\n"
                 + "DATA PRESENTATION_TEXT\n"
                 + "END PRESENTATION_TEXT PT000002\n"
+                + "BEGIN PRESENTATION_TEXT PT000003\n"
+                + "DATA PRESENTATION_TEXT\n"
+                + "END PRESENTATION_TEXT PT000003\n"
                 + "END PAGE PGN00001\n"
                 + "END DOCUMENT DOC00001\n");
     }
+
+    private void setFont(AFPDocumentHandler doc, AFPPainter afpPainter) throws IFException {
+        FontInfo fi = new FontInfo();
+        fi.addFontProperties("", Font.DEFAULT_FONT);
+        RasterFont rf = new RasterFont("", true);
+        CharacterSet cs = OutlineFontTestCase.getCharacterSet();
+        rf.addCharacterSet(12000, cs);
+        fi.addMetrics("", rf);
+        doc.setFontInfo(fi);
+        afpPainter.setFont("any", "normal", 400, "", 12000, Color.BLACK);
+    }
+
+    private void drawBorder(AFPPainter afpPainter, FOUserAgent ua) throws IFException, PropertyException {
+        int style = Constants.EN_DOTTED;
+        BorderProps.Mode mode = BorderProps.Mode.COLLAPSE_OUTER;
+        Color color = ColorUtil.parseColorString(ua, "fop-rgb-icc(0.5019608,0.5019608,0.5019608,#CMYK,,0,0,0,0.5)");
+        int borderWidth = 500;
+        int radiusStart = 0;
+        int radiusEnd = 0;
+        BorderProps border1 = new BorderProps(style, borderWidth, radiusStart, radiusEnd, color, mode);
+        afpPainter.drawBorderRect(new Rectangle(0, 0, 552755, 16090), null, border1, null, null, Color.WHITE);
+    }
 }