Package org.apache.xmlgraphics.image.loader.impl

Examples of org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM


                    (int)Math.round(intrinsicDimensions.getX() * 1000),
                    (int)Math.round(intrinsicDimensions.getY() * 1000));
            size.calcPixelsFromSize();
            info.setSize(size);

            ImageXMLDOM image = new ImageXMLDOM(info, doc, ns);

            FOUserAgent userAgent = ifo.getUserAgent();
            ImageManager manager = userAgent.getFactory().getImageManager();
            Map hints = ImageUtil.getDefaultHints(ua.getImageSessionContext());
            Image converted = manager.convertImage(image, FLAVORS, hints);
View Full Code Here


                setCursorPos(x, y);
                gen.paintBitmap(ri,
                        new Dimension(posInt.width, posInt.height),
                        false);
            } else if (img instanceof ImageXMLDOM) {
                ImageXMLDOM imgXML = (ImageXMLDOM)img;
                renderDocument(imgXML.getDocument(), imgXML.getRootNamespace(),
                        pos, foreignAttributes);
            } else {
                throw new UnsupportedOperationException("Unsupported image type: " + img);
            }
View Full Code Here

    /** {@inheritDoc} */
    public PDFXObject generateImage(RendererContext context, Image image,
            Point origin, Rectangle pos)
            throws IOException {
        PDFRenderer renderer = (PDFRenderer)context.getRenderer();
        ImageXMLDOM imgXML = (ImageXMLDOM)image;
        Document doc = imgXML.getDocument();
        String ns = imgXML.getRootNamespace();
        Map foreignAttributes = (Map)context.getProperty(
                PDFRendererContextConstants.FOREIGN_ATTRIBUTES);
        renderer.renderDocument(doc, ns, pos, foreignAttributes);
        return null;
    }
View Full Code Here

    /** {@inheritDoc} */
    public void handleImage(RenderingContext context, Image image, Rectangle pos)
                throws IOException {
        AFPRenderingContext afpContext = (AFPRenderingContext)context;
        ImageXMLDOM imageSVG = (ImageXMLDOM)image;
        FOUserAgent userAgent = afpContext.getUserAgent();

        AFPGraphicsObjectInfo graphicsObjectInfo = (AFPGraphicsObjectInfo)createDataObjectInfo();
        AFPResourceInfo resourceInfo = graphicsObjectInfo.getResourceInfo();
        setDefaultToInlineResourceLevel(graphicsObjectInfo);

        // Create a new AFPGraphics2D
        final boolean textAsShapes = false; //afpInfo.strokeText(); //TODO make configurable
        AFPGraphics2D g2d = new AFPGraphics2D(
                textAsShapes,
                afpContext.getPaintingState(),
                afpContext.getResourceManager(),
                resourceInfo,
                afpContext.getFontInfo());
        g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());

        AFPPaintingState paintingState = g2d.getPaintingState();
        paintingState.setImageUri(image.getInfo().getOriginalURI());

        // Create an AFPBridgeContext
        BridgeContext bridgeContext = AFPSVGHandler.createBridgeContext(userAgent, g2d);

        // Cloning SVG DOM as Batik attaches non-thread-safe facilities (like the CSS engine)
        // to it.
        Document clonedDoc = BatikUtil.cloneSVGDocument(imageSVG.getDocument());

        // Build the SVG DOM and provide the painter with it
        GraphicsNode root;
        try {
            GVTBuilder builder = new GVTBuilder();
View Full Code Here

            //TODO color profile overrides aren't handled, yet!
            //ICCColorSpaceExt colorspaceOverride = extractColorSpace(e, ctx);
            AbstractGraphicsNode specializedNode = null;
            if (image instanceof ImageXMLDOM) {
                ImageXMLDOM xmlImage = (ImageXMLDOM)image;
                if (xmlImage.getDocument() instanceof SVGDocument) {
                    return createSVGImageNode(ctx, imageElement,
                            (SVGDocument)xmlImage.getDocument());
                } else {
                    //Convert image to Graphics2D
                    image = manager.convertImage(xmlImage,
                            new ImageFlavor[] {ImageFlavor.GRAPHICS2D});
                }
View Full Code Here

    /** {@inheritDoc} */
    public AFPDataObjectInfo generateDataObjectInfo(AFPRendererImageInfo rendererImageInfo)
            throws IOException {
        RendererContext rendererContext = rendererImageInfo.getRendererContext();
        AFPRenderer renderer = (AFPRenderer)rendererContext.getRenderer();
        ImageXMLDOM imgXML = (ImageXMLDOM)rendererImageInfo.getImage();
        Document doc = imgXML.getDocument();
        String ns = imgXML.getRootNamespace();
        Map foreignAttributes = (Map)rendererContext.getProperty(
                RendererContextConstants.FOREIGN_ATTRIBUTES);
        Rectangle2D pos = rendererImageInfo.getPosition();
        renderer.renderDocument(doc, ns, pos, foreignAttributes);
        return null;
View Full Code Here

    /** {@inheritDoc} */
    public void handleImage(RenderingContext context, Image image, final Rectangle pos)
            throws IOException {
        SVGRenderingContext svgContext = (SVGRenderingContext)context;
        ImageXMLDOM svg = (ImageXMLDOM)image;
        ContentHandler handler = svgContext.getContentHandler();
        AttributesImpl atts = new AttributesImpl();
        atts.addAttribute("", "x", "x", CDATA, SVGUtil.formatMptToPt(pos.x));
        atts.addAttribute("", "y", "y", CDATA, SVGUtil.formatMptToPt(pos.y));
        atts.addAttribute("", "width", "width", CDATA, SVGUtil.formatMptToPt(pos.width));
        atts.addAttribute("", "height", "height", CDATA, SVGUtil.formatMptToPt(pos.height));
        try {

            Document doc = (Document)svg.getDocument();
            Element svgEl = (Element)doc.getDocumentElement();
            if (svgEl.getAttribute("viewBox").length() == 0) {
                log.warn("SVG doesn't have a viewBox. The result might not be scaled correctly!");
            }

            TransformerFactory tFactory = TransformerFactory.newInstance();
            Transformer transformer = tFactory.newTransformer();
            DOMSource src = new DOMSource(svg.getDocument());
            SAXResult res = new SAXResult(new DelegatingFragmentContentHandler(handler) {

                private boolean topLevelSVGFound = false;

                private void setAttribute(AttributesImpl atts, String localName, String value) {
View Full Code Here

        if (targetContext instanceof SVGRenderingContext) {
            if (image == null) {
                return true;
            }
            if (image instanceof ImageXMLDOM) {
                ImageXMLDOM svg = (ImageXMLDOM)image;
                return NAMESPACE.equals(svg.getRootNamespace());
            }
        }
        return false;
    }
View Full Code Here

    /** {@inheritDoc} */
    public void handleImage(RenderingContext context, Image image, Rectangle pos)
                throws IOException {
        PSRenderingContext psContext = (PSRenderingContext)context;
        PSGenerator gen = psContext.getGenerator();
        ImageXMLDOM imageSVG = (ImageXMLDOM)image;

        //Controls whether text painted by Batik is generated using text or path operations
        boolean strokeText = false;
        //TODO Configure text stroking

        SVGUserAgent ua
             = new SVGUserAgent(context.getUserAgent(), new AffineTransform());

        PSGraphics2D graphics = new PSGraphics2D(strokeText, gen);
        graphics.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());

        BridgeContext ctx = new PSBridgeContext(ua,
                (strokeText ? null : psContext.getFontInfo()),
                context.getUserAgent().getFactory().getImageManager(),
                context.getUserAgent().getImageSessionContext());

        GraphicsNode root;
        try {
            GVTBuilder builder = new GVTBuilder();
            root = builder.build(ctx, imageSVG.getDocument());
        } catch (Exception e) {
            SVGEventProducer eventProducer = SVGEventProducer.Provider.get(
                    context.getUserAgent().getEventBroadcaster());
            eventProducer.svgNotBuilt(this, e, image.getInfo().getOriginalURI());
            return;
View Full Code Here

    private static Log log = LogFactory.getLog(ImageConverterSVG2G2D.class);

    /** {@inheritDoc} */
    public Image convert(final Image src, Map hints) throws ImageException {
        checkSourceFlavor(src);
        final ImageXMLDOM svg = (ImageXMLDOM)src;
        if (!SVGDOMImplementation.SVG_NAMESPACE_URI.equals(svg.getRootNamespace())) {
            throw new IllegalArgumentException("XML DOM is not in the SVG namespace: "
                    + svg.getRootNamespace());
        }

        //Prepare
        float pxToMillimeter = UnitConv.IN2MM / GraphicsConstants.DEFAULT_DPI;
        Number ptm = (Number)hints.get(ImageProcessingHints.SOURCE_RESOLUTION);
        if (ptm != null) {
            pxToMillimeter = (float)(UnitConv.IN2MM / ptm.doubleValue());
        }
        UserAgent ua = createBatikUserAgent(pxToMillimeter);
        GVTBuilder builder = new GVTBuilder();

        final ImageManager imageManager = (ImageManager)hints.get(
                ImageProcessingHints.IMAGE_MANAGER);
        final ImageSessionContext sessionContext = (ImageSessionContext)hints.get(
                ImageProcessingHints.IMAGE_SESSION_CONTEXT);

        boolean useEnhancedBridgeContext = (imageManager != null && sessionContext != null);
        final BridgeContext ctx = (useEnhancedBridgeContext
                ? new GenericFOPBridgeContext(ua, null, imageManager, sessionContext)
                : new BridgeContext(ua));

        Document doc = svg.getDocument();
        //Cloning SVG DOM as Batik attaches non-thread-safe facilities (like the CSS engine)
        //to it.
        Document clonedDoc = BatikUtil.cloneSVGDocument(doc);

        //Build the GVT tree
        final GraphicsNode root;
        try {
            root = builder.build(ctx, clonedDoc);
        } catch (Exception e) {
            throw new ImageException("GVT tree could not be built for SVG graphic", e);
        }

        //Create the painter
        int width = svg.getSize().getWidthMpt();
        int height = svg.getSize().getHeightMpt();
        Dimension imageSize = new Dimension(width, height);
        Graphics2DImagePainter painter = createPainter(ctx, root, imageSize);

        //Create g2d image
        ImageInfo imageInfo = src.getInfo();
View Full Code Here

TOP

Related Classes of org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM

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.