Author: ssteiner Date: Wed Mar 25 16:36:47 2020 New Revision: 1875656 URL: http://svn.apache.org/viewvc?rev=1875656&view=rev Log: FOP-2926: Add artifact type to PDF header/footer
Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFContext.java xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFParser.java xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFRenderer.java xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFContentGenerator.java xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java?rev=1875656&r1=1875655&r2=1875656&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java Wed Mar 25 16:36:47 2020 @@ -91,7 +91,7 @@ public abstract class AbstractIFPainter< * Returns the intermediate format context object. * @return the context object */ - protected IFContext getContext() { + public IFContext getContext() { return documentHandler.getContext(); } Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFContext.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFContext.java?rev=1875656&r1=1875655&r2=1875656&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFContext.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFContext.java Wed Mar 25 16:36:47 2020 @@ -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 PageIn private int pageNumber = -1; + private RegionType regionType; + /** * Main constructor. * @param ua the user agent @@ -243,4 +246,32 @@ public class IFContext implements PageIn 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; + } + } } Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFParser.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFParser.java?rev=1875656&r1=1875655&r2=1875656&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFParser.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFParser.java Wed Mar 25 16:36:47 2020 @@ -582,6 +582,7 @@ public class IFParser implements IFConst 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 { Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFRenderer.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFRenderer.java?rev=1875656&r1=1875655&r2=1875656&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFRenderer.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFRenderer.java Wed Mar 25 16:36:47 2020 @@ -734,6 +734,7 @@ public class IFRenderer extends Abstract 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(); } Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java?rev=1875656&r1=1875655&r2=1875656&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java Wed Mar 25 16:36:47 2020 @@ -420,6 +420,9 @@ implements IFConstants, IFPainter, IFDoc 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); Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFContentGenerator.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFContentGenerator.java?rev=1875656&r1=1875655&r2=1875656&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFContentGenerator.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFContentGenerator.java Wed Mar 25 16:36:47 2020 @@ -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; Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java?rev=1875656&r1=1875655&r2=1875656&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java Wed Mar 25 16:36:47 2020 @@ -257,8 +257,7 @@ public class PDFDocumentHandler extends 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); Modified: xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java?rev=1875656&r1=1875655&r2=1875656&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java Wed Mar 25 16:36:47 2020 @@ -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"); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: fop-commits-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: fop-commits-h...@xmlgraphics.apache.org