/** * Sets an explicit document handler to use which overrides the one that would be * selected by default. * @param documentHandler the document handler instance to use */ public void setDocumentHandlerOverride(IFDocumentHandler documentHandler) { if (isAccessibilityEnabled()) { setStructureTreeEventHandler(documentHandler.getStructureTreeEventHandler()); } this.documentHandlerOverride = documentHandler; }
/** {@inheritDoc} */ public IFDocumentHandler makeIFDocumentHandler(IFContext ifContext) { IFSerializer handler = new IFSerializer(ifContext); FOUserAgent ua = ifContext.getUserAgent(); if (ua.isAccessibilityEnabled()) { ua.setStructureTreeEventHandler(handler.getStructureTreeEventHandler()); } return handler; }
@Override public IFDocumentHandler makeIFDocumentHandler(IFContext ifContext) { PDFDocumentHandler handler = new PDFDocumentHandler(ifContext); FOUserAgent ua = ifContext.getUserAgent(); if (ua.isAccessibilityEnabled()) { ua.setStructureTreeEventHandler(handler.getStructureTreeEventHandler()); } return handler; }
/** {@inheritDoc} */ @Override public void startPageHeader() throws IFException { try { handler.startElement(EL_PAGE_HEADER); if (this.getUserAgent().isAccessibilityEnabled()) { structureTreeBuilder.replayEventsForRetrievedMarkers(handler); } } catch (SAXException e) { throw new IFException("SAX error in startPageHeader()", e); } }
/** {@inheritDoc} */ public void startDocument() throws IFException { super.startDocument(); try { this.pdfDoc = pdfUtil.setupPDFDocument(this.outputStream); this.accessEnabled = getUserAgent().isAccessibilityEnabled(); if (accessEnabled) { setupAccessibility(); } } catch (IOException e) { throw new IFException("I/O error in startDocument()", e); } }
boolean handled = true; if (NAMESPACE.equals(uri)) { if (localName.equals(EL_PAGE_SEQUENCE) && userAgent.isAccessibilityEnabled()) { pageSequenceAttributes = new AttributesImpl(attributes); Locale language = getLanguage(attributes); if (userAgent.isAccessibilityEnabled()) { String type = attributes.getValue("type"); structureTreeHandler.startStructureTree(type);
/** {@inheritDoc} */ public void startPageSequence(String id) throws IFException { try { AttributesImpl atts = new AttributesImpl(); if (id != null) { atts.addAttribute(XML_NAMESPACE, "id", "xml:id", XMLUtil.CDATA, id); } Locale lang = getContext().getLanguage(); if (lang != null) { atts.addAttribute(XML_NAMESPACE, "lang", "xml:lang", XMLUtil.CDATA, LanguageTags.toLanguageTag(lang)); } XMLUtil.addAttribute(atts, XMLConstants.XML_SPACE, "preserve"); addForeignAttributes(atts); handler.startElement(EL_PAGE_SEQUENCE, atts); if (this.getUserAgent().isAccessibilityEnabled()) { assert (structureTreeBuilder != null); structureTreeBuilder.replayEventsForPageSequence(handler, pageSequenceIndex++); } } catch (SAXException e) { throw new IFException("SAX error in startPageSequence()", e); } }
/** * Creates a default {@link IFDocumentHandler} when none has been set. * @return the default IFDocumentHandler */ protected IFDocumentHandler createDefaultDocumentHandler() { FOUserAgent userAgent = getUserAgent(); IFSerializer serializer = new IFSerializer(new IFContext(userAgent)); if (userAgent.isAccessibilityEnabled()) { userAgent.setStructureTreeEventHandler(serializer.getStructureTreeEventHandler()); } return serializer; }
/** {@inheritDoc} */ public void renderLink(Link link) throws IFException { Rectangle targetRect = link.getTargetRect(); int pageHeight = documentHandler.getCurrentPageRef().getPageDimension().height; Rectangle2D targetRect2D = new Rectangle2D.Double( targetRect.getMinX() / 1000.0, (pageHeight - targetRect.getMinY() - targetRect.getHeight()) / 1000.0, targetRect.getWidth() / 1000.0, targetRect.getHeight() / 1000.0); PDFAction pdfAction = getAction(link.getAction()); //makeLink() currently needs a PDFAction and not a reference //TODO Revisit when PDFLink is converted to a PDFDictionary PDFLink pdfLink = getPDFDoc().getFactory().makeLink( targetRect2D, pdfAction); if (pdfLink != null) { PDFStructElem structure = (PDFStructElem) link.getAction().getStructureTreeElement(); if (documentHandler.getUserAgent().isAccessibilityEnabled() && structure != null) { documentHandler.getLogicalStructureHandler().addLinkContentItem(pdfLink, structure); } documentHandler.getCurrentPage().addAnnotation(pdfLink); } }
/** * Default constructor. * @param documentHandler the parent document handler * @param logicalStructureHandler the logical structure handler */ public PDFPainter(PDFDocumentHandler documentHandler, PDFLogicalStructureHandler logicalStructureHandler) { super(documentHandler); this.logicalStructureHandler = logicalStructureHandler; this.generator = documentHandler.getGenerator(); this.graphicsPainter = new PDFGraphicsPainter(this.generator); this.borderPainter = new BorderPainter(this.graphicsPainter); this.state = IFState.create(); accessEnabled = this.getUserAgent().isAccessibilityEnabled(); languageAvailabilityChecker = accessEnabled ? new LanguageAvailabilityChecker(documentHandler.getContext()) : null; }
/** {@inheritDoc} */ public void handleImage(RenderingContext context, Image image, Rectangle pos) throws IOException { assert context instanceof PDFRenderingContext; PDFRenderingContext pdfContext = (PDFRenderingContext)context; PDFContentGenerator generator = pdfContext.getGenerator(); PDFImage pdfimage = createPDFImage(image, image.getInfo().getOriginalURI()); PDFXObject xobj = generator.getDocument().addImage( generator.getResourceContext(), pdfimage); float x = (float)pos.getX() / 1000f; float y = (float)pos.getY() / 1000f; float w = (float)pos.getWidth() / 1000f; float h = (float)pos.getHeight() / 1000f; if (context.getUserAgent().isAccessibilityEnabled()) { MarkedContentInfo mci = pdfContext.getMarkedContentInfo(); generator.placeImage(x, y, w, h, xobj, mci.tag, mci.mcid); } else { generator.placeImage(x, y, w, h, xobj); } }
/** {@inheritDoc} */ public void renderLink(Link link) throws IFException { noteAction(link.getAction()); AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "rect", "rect", XMLConstants.CDATA, IFUtil.toString(link.getTargetRect())); if (getUserAgent().isAccessibilityEnabled()) { addStructRefAttribute(atts, ((IFStructureTreeElement) link.getAction().getStructureTreeElement()).getId()); } try { handler.startElement(DocumentNavigationExtensionConstants.LINK, atts); serializeXMLizable(link.getAction()); handler.endElement(DocumentNavigationExtensionConstants.LINK); } catch (SAXException e) { throw new IFException("SAX error serializing link", e); } }
/** * <code>FOTreeBuilder</code> constructor * * @param outputFormat the MIME type of the output format to use (ex. "application/pdf"). * @param foUserAgent the {@link FOUserAgent} in effect for this process * @param stream the <code>OutputStream</code> to direct the results to * @throws FOPException if the <code>FOTreeBuilder</code> cannot be properly created */ public FOTreeBuilder( String outputFormat, FOUserAgent foUserAgent, OutputStream stream) throws FOPException { this.userAgent = foUserAgent; this.elementMappingRegistry = userAgent.getElementMappingRegistry(); //This creates either an AreaTreeHandler and ultimately a Renderer, or //one of the RTF-, MIF- etc. Handlers. foEventHandler = foUserAgent.getRendererFactory().createFOEventHandler( foUserAgent, outputFormat, stream); if (userAgent.isAccessibilityEnabled()) { foEventHandler = new FO2StructureTreeConverter( foUserAgent.getStructureTreeEventHandler(), foEventHandler); } builderContext = new FOTreeBuilderContext(); builderContext.setPropertyListMaker(new PropertyListMaker() { public PropertyList make(FObj fobj, PropertyList parentPropertyList) { return new StaticPropertyList(fobj, parentPropertyList); } }); }
/** {@inheritDoc} */ public void bind(PropertyList pList) throws FOPException { super.bind(pList); alignmentAdjust = pList.get(PR_ALIGNMENT_ADJUST).getLength(); alignmentBaseline = pList.get(PR_ALIGNMENT_BASELINE).getEnum(); baselineShift = pList.get(PR_BASELINE_SHIFT).getLength(); dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum(); if (getUserAgent().isAccessibilityEnabled()) { abbreviation = pList.get(PR_X_ABBREVIATION).getString(); } }
if (context.getUserAgent().isAccessibilityEnabled()) { MarkedContentInfo mci = pdfContext.getMarkedContentInfo(); generator.beginMarkedContentSequence(mci.tag, mci.mcid); if (context.getUserAgent().isAccessibilityEnabled()) { generator.restoreGraphicsStateAccess(); } else {
this.pdfDoc.enableAccessibility(userAgent.isAccessibilityEnabled()); pdfDoc.setMergeFontsEnabled(rendererConfig.getMergeFontsEnabled()); pdfDoc.setLinearizationEnabled(rendererConfig.getLinearizationEnabled());
/** {@inheritDoc} */ public void bind(PropertyList pList) throws FOPException { super.bind(pList); alignmentAdjust = pList.get(PR_ALIGNMENT_ADJUST).getLength(); alignmentBaseline = pList.get(PR_ALIGNMENT_BASELINE).getEnum(); baselineShift = pList.get(PR_BASELINE_SHIFT).getLength(); dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum(); // destinationPlacementOffset = pList.get(PR_DESTINATION_PLACEMENT_OFFSET); externalDestination = pList.get(PR_EXTERNAL_DESTINATION).getString(); // indicateDestination = pList.get(PR_INDICATE_DESTINATION); internalDestination = pList.get(PR_INTERNAL_DESTINATION).getString(); showDestination = pList.get(PR_SHOW_DESTINATION).getEnum(); // targetProcessingContext = pList.get(PR_TARGET_PROCESSING_CONTEXT); // targetPresentationContext = pList.get(PR_TARGET_PRESENTATION_CONTEXT); // targetStylesheet = pList.get(PR_TARGET_STYLESHEET); // per spec, internal takes precedence if both specified if (internalDestination.length() > 0) { externalDestination = null; } else if (externalDestination.length() == 0) { // slightly stronger than spec "should be specified" getFOValidationEventProducer().missingLinkDestination(this, getName(), locator); } if (getUserAgent().isAccessibilityEnabled()) { altText = pList.get(PR_X_ALT_TEXT).getString(); if (altText.equals("") && getUserAgent().isPdfUAEnabled()) { getFOValidationEventProducer().altTextMissing(this, getLocalName(), getLocator()); } } }
boolean accessibilityEnabled = context.getUserAgent().isAccessibilityEnabled(); if (accessibilityEnabled) { MarkedContentInfo mci = pdfContext.getMarkedContentInfo();
/** {@inheritDoc} */ public void bind(PropertyList pList) throws FOPException { super.bind(pList); commonAccessibility = CommonAccessibility.getInstance(pList); commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps(); alignmentAdjust = pList.get(PR_ALIGNMENT_ADJUST).getLength(); alignmentBaseline = pList.get(PR_ALIGNMENT_BASELINE).getEnum(); baselineShift = pList.get(PR_BASELINE_SHIFT).getLength(); blockProgressionDimension = pList.get(PR_BLOCK_PROGRESSION_DIMENSION).getLengthRange(); // clip = pList.get(PR_CLIP); contentHeight = pList.get(PR_CONTENT_HEIGHT).getLength(); contentWidth = pList.get(PR_CONTENT_WIDTH).getLength(); displayAlign = pList.get(PR_DISPLAY_ALIGN).getEnum(); dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum(); height = pList.get(PR_HEIGHT).getLength(); inlineProgressionDimension = pList.get(PR_INLINE_PROGRESSION_DIMENSION).getLengthRange(); keepWithNext = pList.get(PR_KEEP_WITH_NEXT).getKeep(); keepWithPrevious = pList.get(PR_KEEP_WITH_PREVIOUS).getKeep(); lineHeight = pList.get(PR_LINE_HEIGHT).getSpace(); overflow = pList.get(PR_OVERFLOW).getEnum(); scaling = pList.get(PR_SCALING).getEnum(); textAlign = pList.get(PR_TEXT_ALIGN).getEnum(); width = pList.get(PR_WIDTH).getLength(); if (getUserAgent().isAccessibilityEnabled()) { altText = pList.get(PR_X_ALT_TEXT).getString(); if (altText.equals("")) { getFOValidationEventProducer().altTextMissing(this, getLocalName(), getLocator()); } } }