* Returns the intermediate format context object.
* @return the context object
*/
- protected IFContext getContext() {
+ public IFContext getContext() {
return documentHandler.getContext();
}
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
private int pageNumber = -1;
+ private RegionType regionType;
+
/**
* Main constructor.
* @param ua the user agent
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;
+ }
+ }
}
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 {
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();
}
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);
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
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
* @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;
this.currentState = new PDFPaintingState();
this.colorHandler = new PDFColorHandler(document.getResources());
+ this.context = context;
}
public AffineTransform getAffineTransform() {
+ 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;
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);
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;
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");
+ }
}