aboutsummaryrefslogtreecommitdiffstats
path: root/fop-core
diff options
context:
space:
mode:
Diffstat (limited to 'fop-core')
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/afp/AFPPainter.java9
-rw-r--r--fop-core/src/test/java/org/apache/fop/afp/fonts/OutlineFontTestCase.java40
-rw-r--r--fop-core/src/test/java/org/apache/fop/render/afp/AFPPainterTestCase.java73
3 files changed, 112 insertions, 10 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/render/afp/AFPPainter.java b/fop-core/src/main/java/org/apache/fop/render/afp/AFPPainter.java
index 69cfb4f80..a0ca446f4 100644
--- a/fop-core/src/main/java/org/apache/fop/render/afp/AFPPainter.java
+++ b/fop-core/src/main/java/org/apache/fop/render/afp/AFPPainter.java
@@ -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
index 000000000..92571cf67
--- /dev/null
+++ b/fop-core/src/test/java/org/apache/fop/afp/fonts/OutlineFontTestCase.java
@@ -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;
+ }
+}
diff --git a/fop-core/src/test/java/org/apache/fop/render/afp/AFPPainterTestCase.java b/fop-core/src/test/java/org/apache/fop/render/afp/AFPPainterTestCase.java
index abb1ecdcb..6354a5909 100644
--- a/fop-core/src/test/java/org/apache/fop/render/afp/AFPPainterTestCase.java
+++ b/fop-core/src/test/java/org/apache/fop/render/afp/AFPPainterTestCase.java
@@ -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);
+ }
}