aboutsummaryrefslogtreecommitdiffstats
path: root/fop-core
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2020-03-25 16:36:47 +0000
committerSimon Steiner <ssteiner@apache.org>2020-03-25 16:36:47 +0000
commit811073a987d6b585222994615666ec699cf6d19b (patch)
tree6c179e293e5965846d65b521423093143b674fde /fop-core
parent698dd5fa4d20d372211770ece51c4634b75c24f7 (diff)
downloadxmlgraphics-fop-811073a987d6b585222994615666ec699cf6d19b.tar.gz
xmlgraphics-fop-811073a987d6b585222994615666ec699cf6d19b.zip
FOP-2926: Add artifact type to PDF header/footer
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1875656 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'fop-core')
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java2
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/intermediate/IFContext.java31
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/intermediate/IFParser.java1
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/intermediate/IFRenderer.java1
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java3
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/pdf/PDFContentGenerator.java16
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java3
-rw-r--r--fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java45
8 files changed, 97 insertions, 5 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java b/fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
index 19383be00..45996a2f4 100644
--- a/fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
+++ b/fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
@@ -91,7 +91,7 @@ public abstract class AbstractIFPainter<T extends IFDocumentHandler> implements
* Returns the intermediate format context object.
* @return the context object
*/
- protected IFContext getContext() {
+ public IFContext getContext() {
return documentHandler.getContext();
}
diff --git a/fop-core/src/main/java/org/apache/fop/render/intermediate/IFContext.java b/fop-core/src/main/java/org/apache/fop/render/intermediate/IFContext.java
index 6f5163a11..9c414174c 100644
--- a/fop-core/src/main/java/org/apache/fop/render/intermediate/IFContext.java
+++ b/fop-core/src/main/java/org/apache/fop/render/intermediate/IFContext.java
@@ -27,6 +27,7 @@ import org.apache.xmlgraphics.util.QName;
import org.apache.fop.accessibility.StructureTreeElement;
import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.fo.Constants;
/**
* This class provides a context object that is valid for a single processing run to create
@@ -59,6 +60,8 @@ public class IFContext implements PageIndexContext {
private int pageNumber = -1;
+ private RegionType regionType;
+
/**
* Main constructor.
* @param ua the user agent
@@ -243,4 +246,32 @@ public class IFContext implements PageIndexContext {
public void setPageNumber(int pageNumber) {
this.pageNumber = pageNumber;
}
+
+ private enum RegionType {
+ Footer,
+ Header
+ }
+
+ public String getRegionType() {
+ if (regionType != null) {
+ return regionType.name();
+ }
+ return null;
+ }
+
+ public void setRegionType(String type) {
+ regionType = null;
+ if (type != null) {
+ regionType = RegionType.valueOf(type);
+ }
+ }
+
+ public void setRegionType(int type) {
+ regionType = null;
+ if (type == Constants.FO_REGION_AFTER) {
+ regionType = RegionType.Footer;
+ } else if (type == Constants.FO_REGION_BEFORE) {
+ regionType = RegionType.Header;
+ }
+ }
}
diff --git a/fop-core/src/main/java/org/apache/fop/render/intermediate/IFParser.java b/fop-core/src/main/java/org/apache/fop/render/intermediate/IFParser.java
index 241d74fc3..3745da00e 100644
--- a/fop-core/src/main/java/org/apache/fop/render/intermediate/IFParser.java
+++ b/fop-core/src/main/java/org/apache/fop/render/intermediate/IFParser.java
@@ -582,6 +582,7 @@ public class IFParser implements IFConstants {
int height = Integer.parseInt(attributes.getValue("height"));
Rectangle clipRect = XMLUtil.getAttributeAsRectangle(attributes, "clip-rect");
painter.startViewport(transforms, new Dimension(width, height), clipRect);
+ documentHandler.getContext().setRegionType(attributes.getValue("region-type"));
}
public void endElement() throws IFException {
diff --git a/fop-core/src/main/java/org/apache/fop/render/intermediate/IFRenderer.java b/fop-core/src/main/java/org/apache/fop/render/intermediate/IFRenderer.java
index c0c70934c..5a401b1a7 100644
--- a/fop-core/src/main/java/org/apache/fop/render/intermediate/IFRenderer.java
+++ b/fop-core/src/main/java/org/apache/fop/render/intermediate/IFRenderer.java
@@ -734,6 +734,7 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
protected void renderRegionViewport(RegionViewport viewport) {
Dimension dim = new Dimension(viewport.getIPD(), viewport.getBPD());
viewportDimensionStack.push(dim);
+ documentHandler.getContext().setRegionType(viewport.getRegionReference().getRegionClass());
super.renderRegionViewport(viewport);
viewportDimensionStack.pop();
}
diff --git a/fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java b/fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java
index d12c13b35..ee6557d43 100644
--- a/fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java
+++ b/fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java
@@ -420,6 +420,9 @@ implements IFConstants, IFPainter, IFDocumentNavigationHandler {
if (clipRect != null) {
addAttribute(atts, "clip-rect", IFUtil.toString(clipRect));
}
+ if (getUserAgent().isAccessibilityEnabled() && getContext().getRegionType() != null) {
+ addAttribute(atts, "region-type", getContext().getRegionType());
+ }
handler.startElement(EL_VIEWPORT, atts);
} catch (SAXException e) {
throw new IFException("SAX error in startViewport()", e);
diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFContentGenerator.java b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFContentGenerator.java
index 4c6af0dc2..c11df3c94 100644
--- a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFContentGenerator.java
+++ b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFContentGenerator.java
@@ -37,6 +37,7 @@ import org.apache.fop.pdf.PDFStream;
import org.apache.fop.pdf.PDFText;
import org.apache.fop.pdf.PDFTextUtil;
import org.apache.fop.pdf.PDFXObject;
+import org.apache.fop.render.intermediate.IFContext;
/**
* Generator class encapsulating all object references and state necessary to generate a
@@ -64,6 +65,7 @@ public class PDFContentGenerator {
private boolean inMarkedContentSequence;
private boolean inArtifactMode;
private AffineTransform transform;
+ private IFContext context;
/**
* Main constructor. Creates a new PDF stream and additional helper classes for text painting
@@ -73,7 +75,12 @@ public class PDFContentGenerator {
* @param resourceContext the resource context
*/
public PDFContentGenerator(PDFDocument document, OutputStream out,
- PDFResourceContext resourceContext) {
+ PDFResourceContext resourceContext) {
+ this(document, out, resourceContext, null);
+ }
+
+ public PDFContentGenerator(PDFDocument document, OutputStream out,
+ PDFResourceContext resourceContext, IFContext context) {
this.document = document;
this.outputStream = out;
this.resourceContext = resourceContext;
@@ -90,6 +97,7 @@ public class PDFContentGenerator {
this.currentState = new PDFPaintingState();
this.colorHandler = new PDFColorHandler(document.getResources());
+ this.context = context;
}
public AffineTransform getAffineTransform() {
@@ -225,7 +233,11 @@ public class PDFContentGenerator {
+ actualTextProperty + ">>\n"
+ "BDC\n");
} else {
- getStream().add("/Artifact\nBMC\n");
+ if (context != null && context.getRegionType() != null) {
+ getStream().add("/Artifact\n<</Type /Pagination\n/Subtype /" + context.getRegionType() + ">>\nBDC\n");
+ } else {
+ getStream().add("/Artifact\nBMC\n");
+ }
this.inArtifactMode = true;
}
this.inMarkedContentSequence = true;
diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java
index da69fae63..ae2053061 100644
--- a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java
+++ b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java
@@ -257,8 +257,7 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler {
currentPageRef = new PageReference(currentPage, size);
this.pageReferences.put(index, currentPageRef);
- this.generator = new PDFContentGenerator(this.pdfDoc, this.outputStream,
- this.currentPage);
+ this.generator = new PDFContentGenerator(this.pdfDoc, this.outputStream, this.currentPage, getContext());
// Transform the PDF's default coordinate system (0,0 at lower left) to the PDFPainter's
AffineTransform basicPageTransform = new AffineTransform(1, 0, 0, -1, 0,
(scaleY * size.height) / 1000f);
diff --git a/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java b/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java
index 1c9c685f6..d0a29abcd 100644
--- a/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java
+++ b/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java
@@ -50,6 +50,7 @@ import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.fonts.MultiByteFont;
import org.apache.fop.pdf.PDFDocument;
+import org.apache.fop.pdf.PDFFilterList;
import org.apache.fop.pdf.PDFPage;
import org.apache.fop.pdf.PDFProfile;
import org.apache.fop.pdf.PDFResources;
@@ -260,4 +261,48 @@ public class PDFPainterTestCase {
structElem.output(bos);
return bos.toString();
}
+
+ @Test
+ public void testFooterText() throws IFException, IOException {
+ FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI());
+ foUserAgent = fopFactory.newFOUserAgent();
+ foUserAgent.setAccessibility(true);
+ PDFDocumentHandler pdfDocumentHandler = new PDFDocumentHandler(new IFContext(foUserAgent));
+ pdfDocumentHandler.getStructureTreeEventHandler();
+
+ pdfDocumentHandler.setResult(new StreamResult(new ByteArrayOutputStream()));
+ pdfDocumentHandler.startDocument();
+ pdfDocumentHandler.startPage(0, "", "", new Dimension());
+
+ FontInfo fi = new FontInfo();
+ fi.addFontProperties("f1", new FontTriplet("a", "italic", 700));
+ MultiByteFont font = new MultiByteFont(null, null);
+ font.setWidthArray(new int[1]);
+ fi.addMetrics("f1", font);
+ pdfDocumentHandler.setFontInfo(fi);
+ PDFDocument doc = pdfDocumentHandler.getPDFDocument();
+ PDFLogicalStructureHandler structureHandler = new PDFLogicalStructureHandler(doc);
+ MyPDFPainter pdfPainter = new MyPDFPainter(pdfDocumentHandler, structureHandler);
+ pdfPainter.getContext().setRegionType(Constants.FO_REGION_AFTER);
+ pdfPainter.setFont("a", "italic", 700, null, 12, null);
+ pdfPainter.drawText(0, 0, 0, 0, null, "test");
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ PDFFilterList filters = pdfPainter.generator.getStream().getFilterList();
+ filters.setDisableAllFilters(true);
+ pdfPainter.generator.getStream().output(bos);
+ Assert.assertEquals(bos.toString(), "<< /Length 1 0 R >>\n"
+ + "stream\n"
+ + "q\n"
+ + "1 0 0 -1 0 0 cm\n"
+ + "/Artifact\n"
+ + "<</Type /Pagination\n"
+ + "/Subtype /Footer>>\n"
+ + "BDC\n"
+ + "BT\n"
+ + "/f1 0.012 Tf\n"
+ + "1 0 0 -1 0 0 Tm [<0000000000000000>] TJ\n"
+ + "\n"
+ + "endstream");
+ }
}