Package org.apache.fop.apps

Examples of org.apache.fop.apps.FOUserAgent


    }

    /** @see org.apache.fop.visual.BitmapProducer */
    public BufferedImage produce(File src, ProducerContext context) {
        try {
            FOUserAgent userAgent = fopFactory.newFOUserAgent();
            userAgent.setTargetResolution(context.getTargetResolution());
            userAgent.setBaseURL(src.getParentFile().toURL().toString());
           
            File outputFile = new File(context.getTargetDir(), src.getName() + ".java2d.png");
            OutputStream out = new FileOutputStream(outputFile);
            out = new BufferedOutputStream(out);
            try {
View Full Code Here


       
        checkSVGFile(uri);
    }

    private void checkSVGFile(String uri) throws ImageException, IOException {
        FOUserAgent userAgent = fopFactory.newFOUserAgent();
       
        ImageManager manager = fopFactory.getImageManager();
        ImageInfo info = manager.preloadImage(uri, userAgent.getImageSessionContext());
        assertNotNull("ImageInfo must not be null", info);
        assertEquals(MimeConstants.MIME_SVG, info.getMimeType());
        assertEquals(uri, info.getOriginalURI());
        assertEquals(16, info.getSize().getWidthPx());
        assertEquals(16, info.getSize().getHeightPx());
        assertEquals(userAgent.getSourceResolution(), info.getSize().getDpiHorizontal(), 0.1);
        assertEquals(16000, info.getSize().getWidthMpt());
        assertEquals(16000, info.getSize().getHeightMpt());
    }
View Full Code Here

        assertEquals(16000, info.getSize().getHeightMpt());
    }
   
    public void testSVGNoSize() throws Exception {
        String uri = "test/resources/images/img.svg";
        FOUserAgent userAgent = fopFactory.newFOUserAgent();
       
        ImageManager manager = fopFactory.getImageManager();
        ImageInfo info = manager.preloadImage(uri, userAgent.getImageSessionContext());
        assertNotNull("ImageInfo must not be null", info);
        assertEquals(MimeConstants.MIME_SVG, info.getMimeType());
        assertEquals(uri, info.getOriginalURI());
        assertEquals(100, info.getSize().getWidthPx()); //100 = default viewport size
        assertEquals(100, info.getSize().getHeightPx());
        assertEquals(userAgent.getSourceResolution(), info.getSize().getDpiHorizontal(), 0.1);
        assertEquals(100000, info.getSize().getWidthMpt());
        assertEquals(100000, info.getSize().getHeightMpt());
    }
View Full Code Here

        assertEquals(100000, info.getSize().getHeightMpt());
    }

    public void testSVGWithDOM() throws Exception {
        String uri = "my:SVGImage";
        FOUserAgent userAgent = fopFactory.newFOUserAgent();
       
        userAgent.setURIResolver(new URIResolver() {

            public Source resolve(String href, String base) throws TransformerException {
                if (href.startsWith("my:")) {
                    DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
                    String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
                    Document doc = impl.createDocument(svgNS, "svg", null);
                    Element element = doc.getDocumentElement();
                    element.setAttribute("viewBox", "0 0 20 20");
                    element.setAttribute("width", "20pt");
                    element.setAttribute("height", "20pt");
                   
                    Element rect = doc.createElementNS(svgNS, "rect");
                    rect.setAttribute("x", "5");
                    rect.setAttribute("y", "5");
                    rect.setAttribute("width", "10");
                    rect.setAttribute("height", "10");
                    element.appendChild(rect);
                   
                    DOMSource src = new DOMSource(doc);
                    return src;
                } else {
                    return null;
                }
            }
           
        });
       
        ImageManager manager = fopFactory.getImageManager();
        ImageInfo info = manager.preloadImage(uri, userAgent.getImageSessionContext());
        assertNotNull("ImageInfo must not be null", info);
        assertEquals(MimeConstants.MIME_SVG, info.getMimeType());
        assertEquals(uri, info.getOriginalURI());
        assertEquals(20, info.getSize().getWidthPx()); //100 = default viewport size
        assertEquals(20, info.getSize().getHeightPx());
        assertEquals(userAgent.getSourceResolution(), info.getSize().getDpiHorizontal(), 0.1);
        assertEquals(20000, info.getSize().getWidthMpt());
        assertEquals(20000, info.getSize().getHeightMpt());
    }
View Full Code Here

    }

    public void testWMF() throws Exception {
        String uri = "test/resources/images/testChart.wmf";
       
        FOUserAgent userAgent = fopFactory.newFOUserAgent();
       
        ImageManager manager = fopFactory.getImageManager();
        ImageInfo info = manager.preloadImage(uri, userAgent.getImageSessionContext());
        assertNotNull("ImageInfo must not be null", info);
        assertEquals(ImageWMF.MIME_WMF, info.getMimeType());
        assertEquals(uri, info.getOriginalURI());
        assertEquals(27940, info.getSize().getWidthPx());
        assertEquals(21590, info.getSize().getHeightPx());
View Full Code Here

     * {@inheritDoc}
     */
    protected void render(Source src, Transformer transformer, HttpServletResponse response)
            throws FOPException, TransformerException, IOException {

        FOUserAgent foUserAgent = getFOUserAgent();
       
        //Setup FOP
        Fop fop = fopFactory.newFop(MimeConstants.MIME_FOP_PRINT, foUserAgent);
       
        //Make sure the XSL transformation's result is piped through to FOP
View Full Code Here

     * @throws IOException In case of an I/O problem
     */
    protected void render(Source src, Transformer transformer, HttpServletResponse response)
                throws FOPException, TransformerException, IOException {

        FOUserAgent foUserAgent = getFOUserAgent();

        //Setup output
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        //Setup FOP
View Full Code Here

        sendPDF(out.toByteArray(), response);
    }
   
    /** @return a new FOUserAgent for FOP */
    protected FOUserAgent getFOUserAgent() {
        FOUserAgent userAgent = fopFactory.newFOUserAgent();
        //Configure foUserAgent as desired
        return userAgent;
    }
View Full Code Here

            return;
        }
        int xOffset = pdfInfo.currentXPosition;
        int yOffset = pdfInfo.currentYPosition;

        FOUserAgent userAgent = context.getUserAgent();
        log.debug("Generating SVG at "
                + userAgent.getTargetResolution()
                + "dpi.");
        final float deviceResolution = userAgent.getTargetResolution();
        log.debug("Generating SVG at " + deviceResolution + "dpi.");
        log.debug("Generating SVG at " + deviceResolution + "dpi.");
       
        final float uaResolution = userAgent.getSourceResolution();
        SVGUserAgent ua = new SVGUserAgent(25.4f / uaResolution, new AffineTransform());

        //Scale for higher resolution on-the-fly images from Batik
        double s = uaResolution / deviceResolution;
        AffineTransform resolutionScaling = new AffineTransform();
        resolutionScaling.scale(s, s);
       
        GVTBuilder builder = new GVTBuilder();
       
        //Controls whether text painted by Batik is generated using text or path operations
        boolean strokeText = false;
        Configuration cfg = pdfInfo.cfg;
        if (cfg != null) {
            strokeText = cfg.getChild("stroke-text", true).getValueAsBoolean(strokeText);
        }
       
        BridgeContext ctx = new PDFBridgeContext(ua,
                (strokeText ? null : pdfInfo.fi),
                userAgent.getFactory().getImageManager(),
                userAgent.getImageSessionContext(),
                new AffineTransform());
       
        GraphicsNode root;
        try {
            root = builder.build(ctx, doc);
View Full Code Here

        try {
            String uri = eg.getURL();

            //set image data
            FOUserAgent userAgent = eg.getUserAgent();
            ImageManager manager = userAgent.getFactory().getImageManager();
            ImageInfo info = manager.getImageInfo(uri, userAgent.getImageSessionContext());
            if (info == null) {
                log.error("Image could not be found: " + uri);
                return;
            }
           
View Full Code Here

TOP

Related Classes of org.apache.fop.apps.FOUserAgent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.