org.apache.batik.bridge.BridgeContext - java examples

Here are the examples of the java api org.apache.batik.bridge.BridgeContext taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

97 Examples 7

19 View Complete Implementation : SVGFlowRootElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
protected AttributedString getFlowDiv(BridgeContext ctx, Element element) {
    Element flowDiv = getFlowDivElement(element);
    if (flowDiv == null)
        return null;
    return gatherFlowPara(ctx, flowDiv);
}

19 View Complete Implementation : JSVGMemoryLeakTest.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
public void registerResourceContext(String uriSubstring, String desc) {
    UpdateManager um = getTheCanvas().getUpdateManager();
    BridgeContext bc = um.getBridgeContext();
    BridgeContext[] ctxs = bc.getChildContexts();
    for (int i = 0; i < ctxs.length; i++) {
        bc = ctxs[i];
        if (bc == null) {
            continue;
        }
        String url = ((SVGOMDoreplacedent) bc.getDoreplacedent()).getURL();
        if (url.indexOf(uriSubstring) != -1) {
            registerObjectDesc(ctxs[i], desc);
        }
    }
}

19 View Complete Implementation : SVGFlowRootElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
/**
 * Returns a list of Shapes that define the flow regions.
 */
protected List getRegions(BridgeContext ctx, Element element) {
    // Element comes in as flowDiv element we want flowRoot.
    element = (Element) element.getParentNode();
    List ret = new LinkedList();
    for (Node n = getFirstChild(element); n != null; n = getNextSibling(n)) {
        if (n.getNodeType() != Node.ELEMENT_NODE)
            continue;
        if (!SVG12Constants.SVG_NAMESPACE_URI.equals(n.getNamespaceURI()))
            continue;
        Element e = (Element) n;
        String ln = e.getLocalName();
        if (!SVG12Constants.SVG_FLOW_REGION_TAG.equals(ln))
            continue;
        // our default alignment is to the top of the flow rect.
        float verticalAlignment = 0.0f;
        gatherRegionInfo(ctx, e, verticalAlignment, ret);
    }
    return ret;
}

19 View Complete Implementation : BatikBridgeExtension.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
/**
 * This method should update the BridgeContext with support
 * for the tags in this extension.  In some rare cases it may
 * be necessary to replace existing tag handlers, although this
 * is discouraged.
 *
 * @param ctx The BridgeContext instance to be updated
 */
public void registerTags(BridgeContext ctx) {
    ctx.putBridge(new BatikRegularPolygonElementBridge());
    ctx.putBridge(new BatikStarElementBridge());
    ctx.putBridge(new BatikHistogramNormalizationElementBridge());
    ctx.putBridge(new BatikFlowTextElementBridge());
    ctx.putBridge(new ColorSwitchBridge());
}

19 View Complete Implementation : XBLContentElementBridge.java
Copyright GNU General Public License v3.0
Author : srnsw
/**
 * Creates a <tt>GraphicsNode</tt> according to the specified parameters.
 *
 * @param ctx the bridge context to use
 * @param e the element that describes the graphics node to build
 * @return a graphics node that represents the specified element
 */
public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) {
    CompositeGraphicsNode gn = buildCompositeGraphicsNode(ctx, e, null);
    return gn;
}

19 View Complete Implementation : XBLContentElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
/**
 * Creates a <code>GraphicsNode</code> according to the specified parameters.
 *
 * @param ctx the bridge context to use
 * @param e the element that describes the graphics node to build
 * @return a graphics node that represents the specified element
 */
public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) {
    CompositeGraphicsNode gn = buildCompositeGraphicsNode(ctx, e, null);
    return gn;
}

19 View Complete Implementation : JSVGMemoryLeakTest.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
public void canvasRendered(JSVGCanvas canvas) {
    // System.err.println("Rendered");
    registerObjectDesc(canvas.getGraphicsNode(), "GVT");
    UpdateManager um = canvas.getUpdateManager();
    if (um == null) {
        return;
    }
    BridgeContext bc = um.getBridgeContext();
    registerObjectDesc(um, "updateManager");
    registerObjectDesc(bc, "bridgeContext");
    BridgeContext[] subCtxs = bc.getChildContexts();
    for (int i = 0; i < subCtxs.length; i++) {
        if (subCtxs[i] != null) {
            SVGOMDoreplacedent doc = (SVGOMDoreplacedent) subCtxs[i].getDoreplacedent();
            registerObjectDesc(subCtxs[i], "BridgeContext_" + doc.getURL());
        }
    }
}

19 View Complete Implementation : BindableElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
/**
 * Creates a <code>GraphicsNode</code> according to the specified parameters.
 *
 * @param ctx the bridge context to use
 * @param e the element that describes the graphics node to build
 * @return a graphics node that represents the specified element
 */
public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) {
    // 'requiredFeatures', 'requiredExtensions' and 'systemLanguage'
    if (!SVGUtilities.matchUserAgent(e, ctx.getUserAgent())) {
        return null;
    }
    CompositeGraphicsNode gn = buildCompositeGraphicsNode(ctx, e, null);
    return gn;
}

19 View Complete Implementation : BindableElementBridge.java
Copyright GNU General Public License v3.0
Author : srnsw
/**
 * Creates a <tt>GraphicsNode</tt> according to the specified parameters.
 *
 * @param ctx the bridge context to use
 * @param e the element that describes the graphics node to build
 * @return a graphics node that represents the specified element
 */
public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) {
    // 'requiredFeatures', 'requiredExtensions' and 'systemLanguage'
    if (!SVGUtilities.matchUserAgent(e, ctx.getUserAgent())) {
        return null;
    }
    CompositeGraphicsNode gn = buildCompositeGraphicsNode(ctx, e, null);
    return gn;
}

19 View Complete Implementation : Location.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
/**
 * This clreplaced implements the org.w3c.dom.Location interface for Batik
 *
 * @author <a href="mailto:[email protected]">G. Wade Johnson</a>
 * @version $Id: Location.java$
 */
public clreplaced Location implements org.w3c.dom.Location {

    private BridgeContext bridgeContext;

    /**
     * Creates a new Location.
     * @param ctx the bridge context
     */
    public Location(BridgeContext ctx) {
        bridgeContext = ctx;
    }

    /**
     * Invocation of this method causes the user agent to navigate to the
     * supplied location.
     *
     * @param url A string containing the URL where the user agent should
     *    navigate to.
     */
    public void replacedign(String url) {
        ((UserAgent) bridgeContext.getUserAgent()).loadDoreplacedent(url);
    }

    /**
     * The user agent reloads the current doreplacedent.
     */
    public void reload() {
        String url = ((AbstractDoreplacedent) bridgeContext.getDoreplacedent()).getDoreplacedentURI();
        ((UserAgent) bridgeContext.getUserAgent()).loadDoreplacedent(url);
    }

    /**
     * Returns the URL of this location as a String.
     */
    public String toString() {
        return ((AbstractDoreplacedent) bridgeContext.getDoreplacedent()).getDoreplacedentURI();
    }
}

19 View Complete Implementation : SVGFlowRootElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
/**
 * Creates the attributed string which represents the given text
 * element children.
 *
 * @param ctx the bridge context to use
 * @param element the text element
 */
protected AttributedString buildAttributedString(BridgeContext ctx, Element element) {
    if (element == null)
        return null;
    List rgns = getRegions(ctx, element);
    AttributedString ret = getFlowDiv(ctx, element);
    if (ret == null)
        return ret;
    ret.addAttribute(FLOW_REGIONS, rgns, 0, 1);
    TextLineBreaks.findLineBrk(ret);
    // dumpACIWord(ret);
    return ret;
}

19 View Complete Implementation : SVGFlowRootElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
protected float getLineHeight(BridgeContext ctx, Element element, float fontSize) {
    if (lineHeightIndex == -1)
        initCSSPropertyIndexes(element);
    Value v = CSSUtilities.getComputedStyle(element, lineHeightIndex);
    if ((v == ValueConstants.INHERIT_VALUE) || (v == SVG12ValueConstants.NORMAL_VALUE)) {
        return fontSize * 1.1f;
    }
    float lineHeight = v.getFloatValue();
    if (v instanceof ComputedValue)
        v = ((ComputedValue) v).getComputedValue();
    if ((v instanceof LineHeightValue) && ((LineHeightValue) v).getFontSizeRelative())
        lineHeight *= fontSize;
    return lineHeight;
}

19 View Complete Implementation : SVGFlowRootElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
/**
 * Returns the text node location In this case the text node may
 * have serveral effective locations (one for each flow region).
 * So it always returns 0,0.
 *
 * @param ctx the bridge context to use
 * @param e the text element
 */
protected Point2D getLocation(BridgeContext ctx, Element e) {
    return new Point2D.Float(0, 0);
}

18 View Complete Implementation : SVGSolidColorElementBridge.java
Copyright GNU General Public License v3.0
Author : srnsw
/**
 * Creates a <tt>Paint</tt> according to the specified parameters.
 *
 * @param ctx the bridge context to use
 * @param paintElement the element that defines a Paint
 * @param paintedElement the element referencing the paint
 * @param paintedNode the graphics node on which the Paint will be applied
 * @param opacity the opacity of the Paint to create
 */
public Paint createPaint(BridgeContext ctx, Element paintElement, Element paintedElement, GraphicsNode paintedNode, float opacity) {
    opacity = extractOpacity(paintElement, opacity, ctx);
    return extractColor(paintElement, opacity, ctx);
}

18 View Complete Implementation : SVGFlowRootElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
protected Map getAttributeMap(BridgeContext ctx, Element element, TextPath textPath, Integer bidiLevel, Map result) {
    Map inheritingMap = super.getAttributeMap(ctx, element, textPath, bidiLevel, result);
    float fontSize = TextUtilities.convertFontSize(element).floatValue();
    float lineHeight = getLineHeight(ctx, element, fontSize);
    result.put(LINE_HEIGHT, new Float(lineHeight));
    return inheritingMap;
}

18 View Complete Implementation : PrintTranscoder.java
Copyright GNU General Public License v3.0
Author : srnsw
/**
 * This clreplaced is a <tt>Transcoder</tt> that prints SVG images.
 * This clreplaced works as follows: any-time the transcode method
 * is invoked, the corresponding input is cached and nothing
 * else happens. <br />
 * However, the <tt>PrintTranscoder</tt> is also a Printable. If used
 * in a print operation, it will print each of the input
 * it cached, one input per page.
 * <br />
 * The <tt>PrintTranscoder</tt> uses several different hints that
 * guide its printing:<br />
 * <ul>
 *   <li><tt>KEY_LANGUAGE, KEY_USER_STYLESHEET_URI, KEY_PIXEL_TO_MM,
 *       KEY_XML_PARSER_CLreplacedNAME</tt> can be used to set the defaults for
 *       the various SVG properties.</li>
 *   <li><tt>KEY_PAGE_WIDTH, KEY_PAGE_HEIGHT, KEY_MARGIN_TOP, KEY_MARGIN_BOTTOM,
 *       KEY_MARGIN_LEFT, KEY_MARGIN_RIGHT</tt> and <tt>KEY_PAGE_ORIENTATION</tt>
 *       can be used to specify the printing page characteristics.</li>
 *   <li><tt>KEY_WIDTH, KEY_HEIGHT</tt> can be used to specify how to scale the
 *       SVG image</li>
 *   <li><tt>KEY_SCALE_TO_PAGE</tt> can be used to specify whether or not the
 *       SVG image should be scaled uniformly to fit into the printed page or
 *       if it should just be centered into the printed page.</li>
 * </ul>
 *
 * @author <a href="mailto:[email protected]">Vincent Hardy</a>
 * @version $Id$
 */
public clreplaced PrintTranscoder extends SVGAbstractTranscoder implements Printable {

    public static final String KEY_AOI_STR = "aoi";

    public static final String KEY_HEIGHT_STR = "height";

    public static final String KEY_LANGUAGE_STR = "language";

    public static final String KEY_MARGIN_BOTTOM_STR = "marginBottom";

    public static final String KEY_MARGIN_LEFT_STR = "marginLeft";

    public static final String KEY_MARGIN_RIGHT_STR = "marginRight";

    public static final String KEY_MARGIN_TOP_STR = "marginTop";

    public static final String KEY_PAGE_HEIGHT_STR = "pageHeight";

    public static final String KEY_PAGE_ORIENTATION_STR = "pageOrientation";

    public static final String KEY_PAGE_WIDTH_STR = "pageWidth";

    public static final String KEY_PIXEL_TO_MM_STR = "pixelToMm";

    public static final String KEY_SCALE_TO_PAGE_STR = "scaleToPage";

    public static final String KEY_SHOW_PAGE_DIALOG_STR = "showPageDialog";

    public static final String KEY_SHOW_PRINTER_DIALOG_STR = "showPrinterDialog";

    public static final String KEY_USER_STYLESHEET_URI_STR = "userStylesheet";

    public static final String KEY_WIDTH_STR = "width";

    public static final String KEY_XML_PARSER_CLreplacedNAME_STR = "xmlParserClreplacedName";

    public static final String VALUE_MEDIA_PRINT = "print";

    public static final String VALUE_PAGE_ORIENTATION_LANDSCAPE = "landscape";

    public static final String VALUE_PAGE_ORIENTATION_PORTRAIT = "portrait";

    public static final String VALUE_PAGE_ORIENTATION_REVERSE_LANDSCAPE = "reverseLandscape";

    /**
     * Set of inputs this transcoder has been requested to
     * transcode so far.
     * Purpose is not really clear: some data is added, and it is copied into
     * printedInputs. But it is never read or cleared...
     */
    private List inputs = new ArrayList();

    /**
     * Currently printing set of pages. This vector is
     * created as a clone of inputs when the first page is printed.
     */
    private List printedInputs = null;

    /**
     * Index of the page corresponding to root
     */
    private int curIndex = -1;

    /**
     * Place to cache BridgeContext so we can dispose of it when
     * it is appropriate.  The Baseclreplaced would dispose of it too
     * soon.
     */
    private BridgeContext theCtx;

    /**
     * Constructs a new transcoder that prints images.
     */
    public PrintTranscoder() {
        super();
        hints.put(KEY_MEDIA, VALUE_MEDIA_PRINT);
    }

    public void transcode(TranscoderInput in, TranscoderOutput out) {
        if (in != null) {
            inputs.add(in);
        }
    }

    /**
     * Transcodes the specified Doreplacedent as an image in the specified output.
     *
     * @param doreplacedent the doreplacedent to transcode
     * @param uri the uri of the doreplacedent or null if any
     * @param output the ouput where to transcode
     * @exception TranscoderException if an error occured while transcoding
     */
    protected void transcode(Doreplacedent doreplacedent, String uri, TranscoderOutput output) throws TranscoderException {
        super.transcode(doreplacedent, uri, output);
        // We do this to hide 'ctx' from the SVGAbstractTranscoder
        // otherwise it will dispose of the context before we can
        // print the doreplacedent.
        theCtx = ctx;
        ctx = null;
    }

    /**
     * Convenience method
     */
    public void print() throws PrinterException {
        // 
        // Now, request the transcoder to actually perform the
        // printing job.
        // 
        PrinterJob printerJob = PrinterJob.getPrinterJob();
        PageFormat pageFormat = printerJob.defaultPage();
        // 
        // Set the page parameters from the hints
        // 
        Paper paper = pageFormat.getPaper();
        Float pageWidth = (Float) hints.get(KEY_PAGE_WIDTH);
        Float pageHeight = (Float) hints.get(KEY_PAGE_HEIGHT);
        if (pageWidth != null) {
            paper.setSize(pageWidth.floatValue(), paper.getHeight());
        }
        if (pageHeight != null) {
            paper.setSize(paper.getWidth(), pageHeight.floatValue());
        }
        float x = 0, y = 0;
        float width = (float) paper.getWidth();
        float height = (float) paper.getHeight();
        Float leftMargin = (Float) hints.get(KEY_MARGIN_LEFT);
        Float topMargin = (Float) hints.get(KEY_MARGIN_TOP);
        Float rightMargin = (Float) hints.get(KEY_MARGIN_RIGHT);
        Float bottomMargin = (Float) hints.get(KEY_MARGIN_BOTTOM);
        if (leftMargin != null) {
            x = leftMargin.floatValue();
            width -= leftMargin.floatValue();
        }
        if (topMargin != null) {
            y = topMargin.floatValue();
            height -= topMargin.floatValue();
        }
        if (rightMargin != null) {
            width -= rightMargin.floatValue();
        }
        if (bottomMargin != null) {
            height -= bottomMargin.floatValue();
        }
        paper.setImageableArea(x, y, width, height);
        String pageOrientation = (String) hints.get(KEY_PAGE_ORIENTATION);
        if (VALUE_PAGE_ORIENTATION_PORTRAIT.equalsIgnoreCase(pageOrientation)) {
            pageFormat.setOrientation(PageFormat.PORTRAIT);
        } else if (VALUE_PAGE_ORIENTATION_LANDSCAPE.equalsIgnoreCase(pageOrientation)) {
            pageFormat.setOrientation(PageFormat.LANDSCAPE);
        } else if (VALUE_PAGE_ORIENTATION_REVERSE_LANDSCAPE.equalsIgnoreCase(pageOrientation)) {
            pageFormat.setOrientation(PageFormat.REVERSE_LANDSCAPE);
        }
        pageFormat.setPaper(paper);
        pageFormat = printerJob.validatePage(pageFormat);
        // 
        // If required, pop up a dialog to adjust the page format
        // 
        Boolean showPageFormat = (Boolean) hints.get(KEY_SHOW_PAGE_DIALOG);
        if ((showPageFormat != null) && (showPageFormat.booleanValue())) {
            PageFormat tmpPageFormat = printerJob.pageDialog(pageFormat);
            if (tmpPageFormat == pageFormat) {
                // Dialog was cancelled, meaning that the print process should
                // be stopped.
                return;
            }
            pageFormat = tmpPageFormat;
        }
        // Set printable before showing printer dialog so
        // it can update the pageFormat if it wishes...
        printerJob.setPrintable(this, pageFormat);
        // 
        // If required, pop up a dialog to select the printer
        // 
        Boolean showPrinterDialog;
        showPrinterDialog = (Boolean) hints.get(KEY_SHOW_PRINTER_DIALOG);
        if (showPrinterDialog != null && showPrinterDialog.booleanValue()) {
            if (!printerJob.printDialog()) {
                // Dialog was cancelled, meaning that the print process
                // should be stopped.
                return;
            }
        }
        // Print now
        printerJob.print();
    }

    /**
     * Printable implementation
     */
    public int print(Graphics _g, PageFormat pageFormat, int pageIndex) {
        // 
        // On the first page, take a snapshot of the vector of
        // TranscodeInputs.
        // 
        if (printedInputs == null) {
            printedInputs = new ArrayList(inputs);
        }
        // 
        // If we have already printed each page, return
        // 
        if (pageIndex >= printedInputs.size()) {
            curIndex = -1;
            if (theCtx != null)
                theCtx.dispose();
            userAgent.displayMessage("Done");
            return NO_SUCH_PAGE;
        }
        // 
        // Load a new doreplacedent now if we are printing a new page
        // 
        if (curIndex != pageIndex) {
            if (theCtx != null)
                theCtx.dispose();
            // The following call will invoke this clreplaced' transcode
            // method which takes a doreplacedent as an input. That method
            // builds the GVT root tree.{
            try {
                width = (int) pageFormat.getImageableWidth();
                height = (int) pageFormat.getImageableHeight();
                super.transcode((TranscoderInput) printedInputs.get(pageIndex), null);
                curIndex = pageIndex;
            } catch (TranscoderException e) {
                drawError(_g, e);
                return PAGE_EXISTS;
            }
        }
        // Cast to Graphics2D to access Java 2D features
        Graphics2D g = (Graphics2D) _g;
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g.setRenderingHint(RenderingHintsKeyExt.KEY_TRANSCODING, RenderingHintsKeyExt.VALUE_TRANSCODING_PRINTING);
        // 
        // Compute transform so that the SVG doreplacedent fits on one page
        // 
        AffineTransform t = g.getTransform();
        Shape clip = g.getClip();
        // System.err.println("X/Y: " + pageFormat.getImageableX() + ", " +
        // pageFormat.getImageableY());
        // System.err.println("W/H: " + width + ", " + height);
        // System.err.println("Clip: " + clip.getBounds2D());
        // Offset 0,0 to the start of the imageable Area.
        g.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
        // 
        // Append transform to selected area
        // 
        g.transform(curTxf);
        // 
        // Delegate rendering to painter
        // 
        try {
            root.paint(g);
        } catch (Exception e) {
            g.setTransform(t);
            g.setClip(clip);
            drawError(_g, e);
        }
        // 
        // Restore transform and clip
        // 
        g.setTransform(t);
        g.setClip(clip);
        // g.setPaint(Color.black);
        // g.drawString(uris[pageIndex], 30, 30);
        // 
        // Return status indicated that we did paint a page
        // 
        return PAGE_EXISTS;
    }

    /**
     * Sets doreplacedent size according to the hints.
     * Global variables width and height are modified.
     *
     * @param docWidth Width of the doreplacedent.
     * @param docHeight Height of the doreplacedent.
     */
    protected void setImageSize(float docWidth, float docHeight) {
        // Check hint to know if scaling is really needed
        Boolean scaleToPage = (Boolean) hints.get(KEY_SCALE_TO_PAGE);
        if (scaleToPage != null && !scaleToPage.booleanValue()) {
            float w = docWidth;
            float h = docHeight;
            if (hints.containsKey(KEY_AOI)) {
                Rectangle2D aoi = (Rectangle2D) hints.get(KEY_AOI);
                w = (float) aoi.getWidth();
                h = (float) aoi.getHeight();
            }
            super.setImageSize(w, h);
        }
    }

    /**
     * Prints an error on the output page
     */
    private void drawError(Graphics g, Exception e) {
        userAgent.displayError(e);
    // Should also probably draw exception on page.
    }

    // --------------------------------------------------------------------
    // Keys definition
    // --------------------------------------------------------------------
    /**
     * The showPageDialog key.
     * <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Key: </TH>
     * <TD VALIGN="TOP">KEY_SHOW_PAGE_DIALOG</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Value: </TH>
     * <TD VALIGN="TOP">Boolean</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Default: </TH>
     * <TD VALIGN="TOP">false</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Required: </TH>
     * <TD VALIGN="TOP">No</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Description: </TH>
     * <TD VALIGN="TOP">Specifies whether or not the transcoder
     *                  should pop up a dialog box for selecting
     *                  the page format.</TD></TR>
     * </TABLE>
     */
    public static final TranscodingHints.Key KEY_SHOW_PAGE_DIALOG = new BooleanKey();

    /**
     * The showPrinterDialog key.
     * <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Key: </TH>
     * <TD VALIGN="TOP">KEY_SHOW_PAGE_DIALOG</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Value: </TH>
     * <TD VALIGN="TOP">Boolean</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Default: </TH>
     * <TD VALIGN="TOP">false</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Required: </TH>
     * <TD VALIGN="TOP">No</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Description: </TH>
     * <TD VALIGN="TOP">Specifies whether or not the transcoder
     *                  should pop up a dialog box for selecting
     *                  the printer. If the dialog box is not
     *                  shown, the transcoder will use the default
     *                  printer.</TD></TR>
     * </TABLE>
     */
    public static final TranscodingHints.Key KEY_SHOW_PRINTER_DIALOG = new BooleanKey();

    /**
     * The pageWidth key.
     * <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Key: </TH>
     * <TD VALIGN="TOP">KEY_PAGE_WIDTH</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Value: </TH>
     * <TD VALIGN="TOP">Length</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Default: </TH>
     * <TD VALIGN="TOP">None</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Required: </TH>
     * <TD VALIGN="TOP">No</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Description: </TH>
     * <TD VALIGN="TOP">The width of the print page</TD></TR>
     * </TABLE>
     */
    public static final TranscodingHints.Key KEY_PAGE_WIDTH = new LengthKey();

    /**
     * The pageHeight key.
     * <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Key: </TH>
     * <TD VALIGN="TOP">KEY_PAGE_HEIGHT</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Value: </TH>
     * <TD VALIGN="TOP">Length</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Default: </TH>
     * <TD VALIGN="TOP">None</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Required: </TH>
     * <TD VALIGN="TOP">No</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Description: </TH>
     * <TD VALIGN="TOP">The height of the print page</TD></TR>
     * </TABLE>
     */
    public static final TranscodingHints.Key KEY_PAGE_HEIGHT = new LengthKey();

    /**
     * The marginTop key.
     * <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Key: </TH>
     * <TD VALIGN="TOP">KEY_MARGIN_TOP</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Value: </TH>
     * <TD VALIGN="TOP">Length</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Default: </TH>
     * <TD VALIGN="TOP">None</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Required: </TH>
     * <TD VALIGN="TOP">No</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Description: </TH>
     * <TD VALIGN="TOP">The print page top margin</TD></TR>
     * </TABLE>
     */
    public static final TranscodingHints.Key KEY_MARGIN_TOP = new LengthKey();

    /**
     * The marginRight key.
     * <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Key: </TH>
     * <TD VALIGN="TOP">KEY_MARGIN_RIGHT</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Value: </TH>
     * <TD VALIGN="TOP">Length</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Default: </TH>
     * <TD VALIGN="TOP">None</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Required: </TH>
     * <TD VALIGN="TOP">No</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Description: </TH>
     * <TD VALIGN="TOP">The print page right margin</TD></TR>
     * </TABLE>
     */
    public static final TranscodingHints.Key KEY_MARGIN_RIGHT = new LengthKey();

    /**
     * The marginBottom key.
     * <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Key: </TH>
     * <TD VALIGN="TOP">KEY_MARGIN_BOTTOM</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Value: </TH>
     * <TD VALIGN="TOP">Length</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Default: </TH>
     * <TD VALIGN="TOP">None</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Required: </TH>
     * <TD VALIGN="TOP">No</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Description: </TH>
     * <TD VALIGN="TOP">The print page bottom margin</TD></TR>
     * </TABLE>
     */
    public static final TranscodingHints.Key KEY_MARGIN_BOTTOM = new LengthKey();

    /**
     * The marginLeft key.
     * <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Key: </TH>
     * <TD VALIGN="TOP">KEY_MARGIN_LEFT</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Value: </TH>
     * <TD VALIGN="TOP">Length</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Default: </TH>
     * <TD VALIGN="TOP">None</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Required: </TH>
     * <TD VALIGN="TOP">No</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Description: </TH>
     * <TD VALIGN="TOP">The print page left margin</TD></TR>
     * </TABLE>
     */
    public static final TranscodingHints.Key KEY_MARGIN_LEFT = new LengthKey();

    /**
     * The pageOrientation key.
     * <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Key: </TH>
     * <TD VALIGN="TOP">KEY_PAGE_ORIENTATION</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Value: </TH>
     * <TD VALIGN="TOP">String</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Default: </TH>
     * <TD VALIGN="TOP">VALUE_PAGE_ORIENTATION_PORTRAIT</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Required: </TH>
     * <TD VALIGN="TOP">No</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Description: </TH>
     * <TD VALIGN="TOP">The print page's orientation</TD></TR>
     * </TABLE>
     */
    public static final TranscodingHints.Key KEY_PAGE_ORIENTATION = new StringKey();

    /**
     * The scaleToPage key.
     * <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Key: </TH>
     * <TD VALIGN="TOP">KEY_SCALE_TO_PAGE</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Value: </TH>
     * <TD VALIGN="TOP">Boolean</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Default: </TH>
     * <TD VALIGN="TOP">true</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Required: </TH>
     * <TD VALIGN="TOP">No</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Description: </TH>
     * <TD VALIGN="TOP">Specifies whether or not the SVG images are scaled to
     *                  fit into the printed page</TD></TR>
     * </TABLE>
     */
    public static final TranscodingHints.Key KEY_SCALE_TO_PAGE = new BooleanKey();

    public static final String USAGE = "java org.apache.batik.transcoder.print.PrintTranscoder <svgFileToPrint>";

    public static void main(String[] args) throws Exception {
        if (args.length < 1) {
            System.err.println(USAGE);
            System.exit(0);
        }
        // 
        // Builds a PrintTranscoder
        // 
        PrintTranscoder transcoder = new PrintTranscoder();
        // 
        // Set the hints, from the command line arguments
        // 
        // Language
        setTranscoderFloatHint(transcoder, KEY_LANGUAGE_STR, KEY_LANGUAGE);
        // User stylesheet
        setTranscoderFloatHint(transcoder, KEY_USER_STYLESHEET_URI_STR, KEY_USER_STYLESHEET_URI);
        // XML parser
        setTranscoderStringHint(transcoder, KEY_XML_PARSER_CLreplacedNAME_STR, KEY_XML_PARSER_CLreplacedNAME);
        // Scale to page
        setTranscoderBooleanHint(transcoder, KEY_SCALE_TO_PAGE_STR, KEY_SCALE_TO_PAGE);
        // AOI
        setTranscoderRectangleHint(transcoder, KEY_AOI_STR, KEY_AOI);
        // Image size
        setTranscoderFloatHint(transcoder, KEY_WIDTH_STR, KEY_WIDTH);
        setTranscoderFloatHint(transcoder, KEY_HEIGHT_STR, KEY_HEIGHT);
        // Pixel to millimeter
        setTranscoderFloatHint(transcoder, KEY_PIXEL_TO_MM_STR, KEY_PIXEL_UNIT_TO_MILLIMETER);
        // Page orientation
        setTranscoderStringHint(transcoder, KEY_PAGE_ORIENTATION_STR, KEY_PAGE_ORIENTATION);
        // Page size
        setTranscoderFloatHint(transcoder, KEY_PAGE_WIDTH_STR, KEY_PAGE_WIDTH);
        setTranscoderFloatHint(transcoder, KEY_PAGE_HEIGHT_STR, KEY_PAGE_HEIGHT);
        // Margins
        setTranscoderFloatHint(transcoder, KEY_MARGIN_TOP_STR, KEY_MARGIN_TOP);
        setTranscoderFloatHint(transcoder, KEY_MARGIN_RIGHT_STR, KEY_MARGIN_RIGHT);
        setTranscoderFloatHint(transcoder, KEY_MARGIN_BOTTOM_STR, KEY_MARGIN_BOTTOM);
        setTranscoderFloatHint(transcoder, KEY_MARGIN_LEFT_STR, KEY_MARGIN_LEFT);
        // Dialog options
        setTranscoderBooleanHint(transcoder, KEY_SHOW_PAGE_DIALOG_STR, KEY_SHOW_PAGE_DIALOG);
        setTranscoderBooleanHint(transcoder, KEY_SHOW_PRINTER_DIALOG_STR, KEY_SHOW_PRINTER_DIALOG);
        // 
        // First, request the transcoder to transcode
        // each of the input files
        // 
        for (int i = 0; i < args.length; i++) {
            transcoder.transcode(new TranscoderInput(new File(args[i]).toURL().toString()), null);
        }
        // 
        // Now, print...
        // 
        transcoder.print();
        System.exit(0);
    }

    public static void setTranscoderFloatHint(Transcoder transcoder, String property, TranscodingHints.Key key) {
        String str = System.getProperty(property);
        if (str != null) {
            try {
                Float value = new Float(Float.parseFloat(str));
                transcoder.addTranscodingHint(key, value);
            } catch (NumberFormatException e) {
                handleValueError(property, str);
            }
        }
    }

    public static void setTranscoderRectangleHint(Transcoder transcoder, String property, TranscodingHints.Key key) {
        String str = System.getProperty(property);
        if (str != null) {
            StringTokenizer st = new StringTokenizer(str, " ,");
            if (st.countTokens() != 4) {
                handleValueError(property, str);
            }
            try {
                String x = st.nextToken();
                String y = st.nextToken();
                String width = st.nextToken();
                String height = st.nextToken();
                Rectangle2D r = new Rectangle2D.Float(Float.parseFloat(x), Float.parseFloat(y), Float.parseFloat(width), Float.parseFloat(height));
                transcoder.addTranscodingHint(key, r);
            } catch (NumberFormatException e) {
                handleValueError(property, str);
            }
        }
    }

    public static void setTranscoderBooleanHint(Transcoder transcoder, String property, TranscodingHints.Key key) {
        String str = System.getProperty(property);
        if (str != null) {
            Boolean value = "true".equalsIgnoreCase(str) ? Boolean.TRUE : Boolean.FALSE;
            transcoder.addTranscodingHint(key, value);
        }
    }

    public static void setTranscoderStringHint(Transcoder transcoder, String property, TranscodingHints.Key key) {
        String str = System.getProperty(property);
        if (str != null) {
            transcoder.addTranscodingHint(key, str);
        }
    }

    public static void handleValueError(String property, String value) {
        System.err.println("Invalid " + property + " value : " + value);
        System.exit(1);
    }
}

18 View Complete Implementation : SVGHandler.java
Copyright Eclipse Public License 1.0
Author : yamcs
/**
 * Creates a new bridge context.
 */
protected BridgeContext createBridgeContext(SVGOMDoreplacedent doc) {
    if (loader == null) {
        loader = new DoreplacedentLoader(userAgent);
    }
    BridgeContext result = null;
    if (doc.isSVG12()) {
        result = new org.csstudio.utility.batik.util.SVG12BridgeContext(userAgent, loader);
    } else {
        result = new org.csstudio.utility.batik.util.BridgeContext(userAgent, loader);
    }
    return result;
}

18 View Complete Implementation : SVGFlowRootElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
/**
 * Add to the element children of the node, a
 * <code>SVGContext</code> to support dynamic update. This is
 * recursive, the children of the nodes are also traversed to add
 * to the support elements their context
 *
 * @param ctx a <code>BridgeContext</code> value
 * @param e an <code>Element</code> value
 *
 * @see org.apache.batik.dom.svg.SVGContext
 * @see org.apache.batik.bridge.BridgeUpdateHandler
 */
protected void addContextToChild(BridgeContext ctx, Element e) {
    if (SVG_NAMESPACE_URI.equals(e.getNamespaceURI())) {
        String ln = e.getLocalName();
        if (ln.equals(SVG12Constants.SVG_FLOW_DIV_TAG) || ln.equals(SVG12Constants.SVG_FLOW_LINE_TAG) || ln.equals(SVG12Constants.SVG_FLOW_PARA_TAG) || ln.equals(SVG12Constants.SVG_FLOW_SPAN_TAG)) {
            ((SVGOMElement) e).setSVGContext(new FlowContentBridge(ctx, this, e));
        }
    }
    // traverse the children to add SVGContext
    Node child = getFirstChild(e);
    while (child != null) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            addContextToChild(ctx, (Element) child);
        }
        child = getNextSibling(child);
    }
}

18 View Complete Implementation : SVGFlowRootElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
/**
 * From the <code>SVGContext</code> from the element children of the node.
 *
 * @param ctx the <code>BridgeContext</code> for the doreplacedent
 * @param e the <code>Element</code> whose subtree's elements will have
 *   threir <code>SVGContext</code>s removed
 *
 * @see org.apache.batik.dom.svg.SVGContext
 * @see org.apache.batik.bridge.BridgeUpdateHandler
 */
protected void removeContextFromChild(BridgeContext ctx, Element e) {
    if (SVG_NAMESPACE_URI.equals(e.getNamespaceURI())) {
        String ln = e.getLocalName();
        if (ln.equals(SVG12Constants.SVG_FLOW_DIV_TAG) || ln.equals(SVG12Constants.SVG_FLOW_LINE_TAG) || ln.equals(SVG12Constants.SVG_FLOW_PARA_TAG) || ln.equals(SVG12Constants.SVG_FLOW_SPAN_TAG)) {
            ((AbstractTextChildBridgeUpdateHandler) ((SVGOMElement) e).getSVGContext()).dispose();
        }
    }
    Node child = getFirstChild(e);
    while (child != null) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            removeContextFromChild(ctx, (Element) child);
        }
        child = getNextSibling(child);
    }
}

18 View Complete Implementation : SVGMultiImageElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
public void buildGraphicsNode(BridgeContext ctx, Element e, GraphicsNode node) {
    initializeDynamicSupport(ctx, e, node);
    // Handle children elements such as <replacedle>
    // SVGUtilities.bridgeChildren(ctx, e);
    // super.buildGraphicsNode(ctx, e, node);
    ctx.closeViewport(e);
}

18 View Complete Implementation : SVGMultiImageElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
/**
 * Returns the bounds of the specified image element.
 *
 * @param ctx the bridge context
 * @param element the image element
 */
protected static Rectangle2D getImageBounds(BridgeContext ctx, Element element) {
    UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, element);
    // 'x' attribute - default is 0
    String s = element.getAttributeNS(null, SVG_X_ATTRIBUTE);
    float x = 0;
    if (s.length() != 0) {
        x = UnitProcessor.svgHorizontalCoordinateToUserSpace(s, SVG_X_ATTRIBUTE, uctx);
    }
    // 'y' attribute - default is 0
    s = element.getAttributeNS(null, SVG_Y_ATTRIBUTE);
    float y = 0;
    if (s.length() != 0) {
        y = UnitProcessor.svgVerticalCoordinateToUserSpace(s, SVG_Y_ATTRIBUTE, uctx);
    }
    // 'width' attribute - required
    s = element.getAttributeNS(null, SVG_WIDTH_ATTRIBUTE);
    float w;
    if (s.length() == 0) {
        throw new BridgeException(ctx, element, ERR_ATTRIBUTE_MISSING, new Object[] { SVG_WIDTH_ATTRIBUTE });
    } else {
        w = UnitProcessor.svgHorizontalLengthToUserSpace(s, SVG_WIDTH_ATTRIBUTE, uctx);
    }
    // 'height' attribute - required
    s = element.getAttributeNS(null, SVG_HEIGHT_ATTRIBUTE);
    float h;
    if (s.length() == 0) {
        throw new BridgeException(ctx, element, ERR_ATTRIBUTE_MISSING, new Object[] { SVG_HEIGHT_ATTRIBUTE });
    } else {
        h = UnitProcessor.svgVerticalLengthToUserSpace(s, SVG_HEIGHT_ATTRIBUTE, uctx);
    }
    return new Rectangle2D.Float(x, y, w, h);
}

18 View Complete Implementation : SVGSolidColorElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
/**
 * Creates a <code>Paint</code> according to the specified parameters.
 *
 * @param ctx the bridge context to use
 * @param paintElement the element that defines a Paint
 * @param paintedElement the element referencing the paint
 * @param paintedNode the graphics node on which the Paint will be applied
 * @param opacity the opacity of the Paint to create
 */
public Paint createPaint(BridgeContext ctx, Element paintElement, Element paintedElement, GraphicsNode paintedNode, float opacity) {
    opacity = extractOpacity(paintElement, opacity, ctx);
    return extractColor(paintElement, opacity, ctx);
}

18 View Complete Implementation : XBLShadowTreeElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
/**
 * Creates a <code>GraphicsNode</code> according to the specified parameters.
 *
 * @param ctx the bridge context to use
 * @param e the element that describes the graphics node to build
 * @return a graphics node that represents the specified element
 */
public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) {
    // 'requiredFeatures', 'requiredExtensions' and 'systemLanguage'
    if (!SVGUtilities.matchUserAgent(e, ctx.getUserAgent())) {
        return null;
    }
    CompositeGraphicsNode cgn = new CompositeGraphicsNode();
    replacedociateSVGContext(ctx, e, cgn);
    return cgn;
}

18 View Complete Implementation : BatikFlowTextElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
protected void addContextToChild(BridgeContext ctx, Element e) {
    if (getNamespaceURI().equals(e.getNamespaceURI())) {
        String ln = e.getLocalName();
        if (ln.equals(BATIK_EXT_FLOW_PARA_TAG) || ln.equals(BATIK_EXT_FLOW_REGION_BREAK_TAG) || ln.equals(BATIK_EXT_FLOW_LINE_TAG) || ln.equals(BATIK_EXT_FLOW_SPAN_TAG) || ln.equals(SVG_A_TAG) || ln.equals(SVG_TREF_TAG)) {
            ((SVGOMElement) e).setSVGContext(new BatikFlowContentBridge(ctx, this, e));
        }
    }
    // traverse the children to add SVGContext
    Node child = getFirstChild(e);
    while (child != null) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            addContextToChild(ctx, (Element) child);
        }
        child = getNextSibling(child);
    }
}

18 View Complete Implementation : BatikFlowTextElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
protected AttributedString getFlowDiv(BridgeContext ctx, Element element) {
    for (Node n = element.getFirstChild(); n != null; n = n.getNextSibling()) {
        if (n.getNodeType() != Node.ELEMENT_NODE)
            continue;
        if (!getNamespaceURI().equals(n.getNamespaceURI()))
            continue;
        Element e = (Element) n;
        String ln = n.getLocalName();
        if (ln.equals(BATIK_EXT_FLOW_DIV_TAG)) {
            return gatherFlowPara(ctx, e);
        }
    }
    return null;
}

18 View Complete Implementation : BatikFlowTextElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
protected void addChildGlyphPositionAttributes(AttributedString as, Element element, BridgeContext ctx) {
    // Add Paint attributres for children of text element
    for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (child.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }
        String cNS = child.getNamespaceURI();
        if ((!getNamespaceURI().equals(cNS)) && (!SVG_NAMESPACE_URI.equals(cNS))) {
            continue;
        }
        String ln = child.getLocalName();
        if (ln.equals(BATIK_EXT_FLOW_PARA_TAG) || ln.equals(BATIK_EXT_FLOW_REGION_BREAK_TAG) || ln.equals(BATIK_EXT_FLOW_LINE_TAG) || ln.equals(BATIK_EXT_FLOW_SPAN_TAG) || ln.equals(SVG_A_TAG) || ln.equals(SVG_TREF_TAG)) {
            addGlyphPositionAttributes(as, (Element) child, ctx);
        }
    }
}

18 View Complete Implementation : BatikFlowTextElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
protected void addChildPaintAttributes(AttributedString as, Element element, TextNode node, TextPaintInfo parentPI, BridgeContext ctx) {
    // Add Paint attributres for children of text element
    for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (child.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }
        String cNS = child.getNamespaceURI();
        if ((!getNamespaceURI().equals(cNS)) && (!SVG_NAMESPACE_URI.equals(cNS))) {
            continue;
        }
        String ln = child.getLocalName();
        if (ln.equals(BATIK_EXT_FLOW_PARA_TAG) || ln.equals(BATIK_EXT_FLOW_REGION_BREAK_TAG) || ln.equals(BATIK_EXT_FLOW_LINE_TAG) || ln.equals(BATIK_EXT_FLOW_SPAN_TAG) || ln.equals(SVG_A_TAG) || ln.equals(SVG_TREF_TAG)) {
            Element childElement = (Element) child;
            TextPaintInfo pi = getTextPaintInfo(childElement, node, parentPI, ctx);
            addPaintAttributes(as, childElement, node, pi, ctx);
        }
    }
}

18 View Complete Implementation : PrintRecordSheet.java
Copyright GNU General Public License v2.0
Author : MegaMek
protected GraphicsNode build() {
    GVTBuilder builder = new GVTBuilder();
    BridgeContext ctx = new BridgeContext(new UserAgentAdapter() {

        @Override
        public // rather than throwing an exception.
        SVGDoreplacedent getBrokenLinkDoreplacedent(Element e, String url, String message) {
            MegaMekLab.getLogger().log(PrintRecordSheet.clreplaced, "build()", LogLevel.WARNING, "Cannot render image: " + message);
            DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
            SVGDoreplacedent doc = (SVGDoreplacedent) impl.createDoreplacedent(svgNS, SVGConstants.SVG_SVG_TAG, null);
            Element text = doc.createElementNS(svgNS, SVGConstants.SVG_TEXT_TAG);
            text.setTextContent("?");
            doc.getDoreplacedentElement().appendChild(text);
            return doc;
        }
    });
    ctx.setDynamic(true);
    return builder.build(ctx, svgDoreplacedent);
}

18 View Complete Implementation : SVGFlowRootElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
public BlockInfo makeBlockInfo(BridgeContext ctx, Element element) {
    if (marginTopIndex == -1)
        initCSSPropertyIndexes(element);
    Value v;
    v = CSSUtilities.getComputedStyle(element, marginTopIndex);
    float top = v.getFloatValue();
    v = CSSUtilities.getComputedStyle(element, marginRightIndex);
    float right = v.getFloatValue();
    v = CSSUtilities.getComputedStyle(element, marginBottomIndex);
    float bottom = v.getFloatValue();
    v = CSSUtilities.getComputedStyle(element, marginLeftIndex);
    float left = v.getFloatValue();
    v = CSSUtilities.getComputedStyle(element, indentIndex);
    float indent = v.getFloatValue();
    v = CSSUtilities.getComputedStyle(element, textAlignIndex);
    if (v == ValueConstants.INHERIT_VALUE) {
        v = CSSUtilities.getComputedStyle(element, SVGCSSEngine.DIRECTION_INDEX);
        if (v == ValueConstants.LTR_VALUE)
            v = SVG12ValueConstants.START_VALUE;
        else
            v = SVG12ValueConstants.END_VALUE;
    }
    int textAlign;
    if (v == SVG12ValueConstants.START_VALUE)
        textAlign = BlockInfo.ALIGN_START;
    else if (v == SVG12ValueConstants.MIDDLE_VALUE)
        textAlign = BlockInfo.ALIGN_MIDDLE;
    else if (v == SVG12ValueConstants.END_VALUE)
        textAlign = BlockInfo.ALIGN_END;
    else
        textAlign = BlockInfo.ALIGN_FULL;
    Map fontAttrs = new HashMap(20);
    List fontList = getFontList(ctx, element, fontAttrs);
    Float fs = (Float) fontAttrs.get(TextAttribute.SIZE);
    float fontSize = fs.floatValue();
    float lineHeight = getLineHeight(ctx, element, fontSize);
    String ln = element.getLocalName();
    boolean rgnBr;
    rgnBr = ln.equals(SVG12Constants.SVG_FLOW_REGION_BREAK_TAG);
    return new BlockInfo(top, right, bottom, left, indent, textAlign, lineHeight, fontList, fontAttrs, rgnBr);
}

18 View Complete Implementation : XBLShadowTreeElementBridge.java
Copyright GNU General Public License v3.0
Author : srnsw
/**
 * Creates a <tt>GraphicsNode</tt> according to the specified parameters.
 *
 * @param ctx the bridge context to use
 * @param e the element that describes the graphics node to build
 * @return a graphics node that represents the specified element
 */
public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) {
    // 'requiredFeatures', 'requiredExtensions' and 'systemLanguage'
    if (!SVGUtilities.matchUserAgent(e, ctx.getUserAgent())) {
        return null;
    }
    CompositeGraphicsNode cgn = new CompositeGraphicsNode();
    replacedociateSVGContext(ctx, e, cgn);
    return cgn;
}

18 View Complete Implementation : BatikFlowTextElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
protected Map getAttributeMap(BridgeContext ctx, Element element, TextPath textPath, Integer bidiLevel, Map result) {
    Map initialMap = super.getAttributeMap(ctx, element, textPath, bidiLevel, result);
    String s;
    s = element.getAttribute(BATIK_EXT_PREFORMATTED_ATTRIBUTE);
    if (s.length() != 0) {
        if (s.equals("true")) {
            result.put(PREFORMATTED, Boolean.TRUE);
        }
    }
    return initialMap;
}

18 View Complete Implementation : BindableElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
/**
 * Builds using the specified BridgeContext and element, the
 * specified graphics node.
 *
 * @param ctx the bridge context to use
 * @param e the element that describes the graphics node to build
 * @param node the graphics node to build
 */
public void buildGraphicsNode(BridgeContext ctx, Element e, GraphicsNode node) {
    initializeDynamicSupport(ctx, e, node);
}

18 View Complete Implementation : BatikFlowTextElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
/**
 * Creates the attributed string which represents the given text
 * element children.
 *
 * @param ctx the bridge context to use
 * @param element the text element
 */
protected AttributedString buildAttributedString(BridgeContext ctx, Element element) {
    List rgns = getRegions(ctx, element);
    AttributedString ret = getFlowDiv(ctx, element);
    if (ret == null)
        return ret;
    ret.addAttribute(FLOW_REGIONS, rgns, 0, 1);
    return ret;
}

18 View Complete Implementation : BatikHistogramNormalizationElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
/**
 * Stolen from AbstractSVGFilterPrimitiveElementBridge.
 * Converts on the specified filter primitive element, the specified
 * attribute that represents an integer and with the specified
 * default value.
 *
 * @param filterElement the filter primitive element
 * @param attrName the name of the attribute
 * @param defaultValue the default value of the attribute
 * @param ctx the BridgeContext to use for error information
 */
protected static int convertSides(Element filterElement, String attrName, int defaultValue, BridgeContext ctx) {
    String s = filterElement.getAttributeNS(null, attrName);
    if (s.length() == 0) {
        return defaultValue;
    } else {
        int ret = 0;
        try {
            ret = SVGUtilities.convertSVGInteger(s);
        } catch (NumberFormatException nfEx) {
            throw new BridgeException(ctx, filterElement, nfEx, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object[] { attrName, s });
        }
        if (ret < 3)
            throw new BridgeException(ctx, filterElement, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object[] { attrName, s });
        return ret;
    }
}

18 View Complete Implementation : SVGFlowRootElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
protected void computeLaidoutText(BridgeContext ctx, Element e, GraphicsNode node) {
    super.computeLaidoutText(ctx, getFlowDivElement(e), node);
}

18 View Complete Implementation : PrintTranscoder.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
/**
 * This clreplaced is a <code>Transcoder</code> that prints SVG images.
 * This clreplaced works as follows: any-time the transcode method
 * is invoked, the corresponding input is cached and nothing
 * else happens. <br />
 * However, the <code>PrintTranscoder</code> is also a Printable. If used
 * in a print operation, it will print each of the input
 * it cached, one input per page.
 * <br />
 * The <code>PrintTranscoder</code> uses several different hints that
 * guide its printing:<br />
 * <ul>
 *   <li><code>KEY_LANGUAGE, KEY_USER_STYLESHEET_URI, KEY_PIXEL_TO_MM,
 *       KEY_XML_PARSER_CLreplacedNAME</code> can be used to set the defaults for
 *       the various SVG properties.</li>
 *   <li><code>KEY_PAGE_WIDTH, KEY_PAGE_HEIGHT, KEY_MARGIN_TOP, KEY_MARGIN_BOTTOM,
 *       KEY_MARGIN_LEFT, KEY_MARGIN_RIGHT</code> and <code>KEY_PAGE_ORIENTATION</code>
 *       can be used to specify the printing page characteristics.</li>
 *   <li><code>KEY_WIDTH, KEY_HEIGHT</code> can be used to specify how to scale the
 *       SVG image</li>
 *   <li><code>KEY_SCALE_TO_PAGE</code> can be used to specify whether or not the
 *       SVG image should be scaled uniformly to fit into the printed page or
 *       if it should just be centered into the printed page.</li>
 * </ul>
 *
 * @author <a href="mailto:[email protected]">Vincent Hardy</a>
 * @version $Id: PrintTranscoder.java 1636249 2014-11-03 04:35:18Z gadams $
 */
public clreplaced PrintTranscoder extends SVGAbstractTranscoder implements Printable {

    public static final String KEY_AOI_STR = "aoi";

    public static final String KEY_HEIGHT_STR = "height";

    public static final String KEY_LANGUAGE_STR = "language";

    public static final String KEY_MARGIN_BOTTOM_STR = "marginBottom";

    public static final String KEY_MARGIN_LEFT_STR = "marginLeft";

    public static final String KEY_MARGIN_RIGHT_STR = "marginRight";

    public static final String KEY_MARGIN_TOP_STR = "marginTop";

    public static final String KEY_PAGE_HEIGHT_STR = "pageHeight";

    public static final String KEY_PAGE_ORIENTATION_STR = "pageOrientation";

    public static final String KEY_PAGE_WIDTH_STR = "pageWidth";

    public static final String KEY_PIXEL_TO_MM_STR = "pixelToMm";

    public static final String KEY_SCALE_TO_PAGE_STR = "scaleToPage";

    public static final String KEY_SHOW_PAGE_DIALOG_STR = "showPageDialog";

    public static final String KEY_SHOW_PRINTER_DIALOG_STR = "showPrinterDialog";

    public static final String KEY_USER_STYLESHEET_URI_STR = "userStylesheet";

    public static final String KEY_WIDTH_STR = "width";

    public static final String KEY_XML_PARSER_CLreplacedNAME_STR = "xmlParserClreplacedName";

    public static final String VALUE_MEDIA_PRINT = "print";

    public static final String VALUE_PAGE_ORIENTATION_LANDSCAPE = "landscape";

    public static final String VALUE_PAGE_ORIENTATION_PORTRAIT = "portrait";

    public static final String VALUE_PAGE_ORIENTATION_REVERSE_LANDSCAPE = "reverseLandscape";

    /**
     * Set of inputs this transcoder has been requested to
     * transcode so far.
     * Purpose is not really clear: some data is added, and it is copied into
     * printedInputs. But it is never read or cleared...
     */
    private List inputs = new ArrayList();

    /**
     * Currently printing set of pages. This vector is
     * created as a clone of inputs when the first page is printed.
     */
    private List printedInputs = null;

    /**
     * Index of the page corresponding to root
     */
    private int curIndex = -1;

    /**
     * Place to cache BridgeContext so we can dispose of it when
     * it is appropriate.  The Baseclreplaced would dispose of it too
     * soon.
     */
    private BridgeContext theCtx;

    /**
     * Constructs a new transcoder that prints images.
     */
    public PrintTranscoder() {
        super();
        hints.put(KEY_MEDIA, VALUE_MEDIA_PRINT);
    }

    public void transcode(TranscoderInput in, TranscoderOutput out) {
        if (in != null) {
            inputs.add(in);
        }
    }

    /**
     * Transcodes the specified Doreplacedent as an image in the specified output.
     *
     * @param doreplacedent the doreplacedent to transcode
     * @param uri the uri of the doreplacedent or null if any
     * @param output the ouput where to transcode
     * @exception TranscoderException if an error occured while transcoding
     */
    protected void transcode(Doreplacedent doreplacedent, String uri, TranscoderOutput output) throws TranscoderException {
        super.transcode(doreplacedent, uri, output);
        // We do this to hide 'ctx' from the SVGAbstractTranscoder
        // otherwise it will dispose of the context before we can
        // print the doreplacedent.
        theCtx = ctx;
        ctx = null;
    }

    /**
     * Convenience method
     */
    public void print() throws PrinterException {
        // 
        // Now, request the transcoder to actually perform the
        // printing job.
        // 
        PrinterJob printerJob = PrinterJob.getPrinterJob();
        PageFormat pageFormat = printerJob.defaultPage();
        // 
        // Set the page parameters from the hints
        // 
        Paper paper = pageFormat.getPaper();
        Float pageWidth = (Float) hints.get(KEY_PAGE_WIDTH);
        Float pageHeight = (Float) hints.get(KEY_PAGE_HEIGHT);
        if (pageWidth != null) {
            paper.setSize(pageWidth.floatValue(), paper.getHeight());
        }
        if (pageHeight != null) {
            paper.setSize(paper.getWidth(), pageHeight.floatValue());
        }
        float x = 0, y = 0;
        float width = (float) paper.getWidth();
        float height = (float) paper.getHeight();
        Float leftMargin = (Float) hints.get(KEY_MARGIN_LEFT);
        Float topMargin = (Float) hints.get(KEY_MARGIN_TOP);
        Float rightMargin = (Float) hints.get(KEY_MARGIN_RIGHT);
        Float bottomMargin = (Float) hints.get(KEY_MARGIN_BOTTOM);
        if (leftMargin != null) {
            x = leftMargin.floatValue();
            width -= leftMargin.floatValue();
        }
        if (topMargin != null) {
            y = topMargin.floatValue();
            height -= topMargin.floatValue();
        }
        if (rightMargin != null) {
            width -= rightMargin.floatValue();
        }
        if (bottomMargin != null) {
            height -= bottomMargin.floatValue();
        }
        paper.setImageableArea(x, y, width, height);
        String pageOrientation = (String) hints.get(KEY_PAGE_ORIENTATION);
        if (VALUE_PAGE_ORIENTATION_PORTRAIT.equalsIgnoreCase(pageOrientation)) {
            pageFormat.setOrientation(PageFormat.PORTRAIT);
        } else if (VALUE_PAGE_ORIENTATION_LANDSCAPE.equalsIgnoreCase(pageOrientation)) {
            pageFormat.setOrientation(PageFormat.LANDSCAPE);
        } else if (VALUE_PAGE_ORIENTATION_REVERSE_LANDSCAPE.equalsIgnoreCase(pageOrientation)) {
            pageFormat.setOrientation(PageFormat.REVERSE_LANDSCAPE);
        }
        pageFormat.setPaper(paper);
        pageFormat = printerJob.validatePage(pageFormat);
        // 
        // If required, pop up a dialog to adjust the page format
        // 
        Boolean showPageFormat = (Boolean) hints.get(KEY_SHOW_PAGE_DIALOG);
        if ((showPageFormat != null) && (showPageFormat.booleanValue())) {
            PageFormat tmpPageFormat = printerJob.pageDialog(pageFormat);
            if (tmpPageFormat == pageFormat) {
                // Dialog was cancelled, meaning that the print process should
                // be stopped.
                return;
            }
            pageFormat = tmpPageFormat;
        }
        // Set printable before showing printer dialog so
        // it can update the pageFormat if it wishes...
        printerJob.setPrintable(this, pageFormat);
        // 
        // If required, pop up a dialog to select the printer
        // 
        Boolean showPrinterDialog;
        showPrinterDialog = (Boolean) hints.get(KEY_SHOW_PRINTER_DIALOG);
        if (showPrinterDialog != null && showPrinterDialog.booleanValue()) {
            if (!printerJob.printDialog()) {
                // Dialog was cancelled, meaning that the print process
                // should be stopped.
                return;
            }
        }
        // Print now
        printerJob.print();
    }

    /**
     * Printable implementation
     */
    public int print(Graphics _g, PageFormat pageFormat, int pageIndex) {
        // 
        // On the first page, take a snapshot of the vector of
        // TranscodeInputs.
        // 
        if (printedInputs == null) {
            printedInputs = new ArrayList(inputs);
        }
        // 
        // If we have already printed each page, return
        // 
        if (pageIndex >= printedInputs.size()) {
            curIndex = -1;
            if (theCtx != null)
                theCtx.dispose();
            userAgent.displayMessage("Done");
            return NO_SUCH_PAGE;
        }
        // 
        // Load a new doreplacedent now if we are printing a new page
        // 
        if (curIndex != pageIndex) {
            if (theCtx != null)
                theCtx.dispose();
            // The following call will invoke this clreplaced' transcode
            // method which takes a doreplacedent as an input. That method
            // builds the GVT root tree.{
            try {
                width = (int) pageFormat.getImageableWidth();
                height = (int) pageFormat.getImageableHeight();
                super.transcode((TranscoderInput) printedInputs.get(pageIndex), null);
                curIndex = pageIndex;
            } catch (TranscoderException e) {
                drawError(_g, e);
                return PAGE_EXISTS;
            }
        }
        // Cast to Graphics2D to access Java 2D features
        Graphics2D g = (Graphics2D) _g;
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g.setRenderingHint(RenderingHintsKeyExt.KEY_TRANSCODING, RenderingHintsKeyExt.VALUE_TRANSCODING_PRINTING);
        // 
        // Compute transform so that the SVG doreplacedent fits on one page
        // 
        AffineTransform t = g.getTransform();
        Shape clip = g.getClip();
        // System.err.println("X/Y: " + pageFormat.getImageableX() + ", " +
        // pageFormat.getImageableY());
        // System.err.println("W/H: " + width + ", " + height);
        // System.err.println("Clip: " + clip.getBounds2D());
        // Offset 0,0 to the start of the imageable Area.
        g.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
        // 
        // Append transform to selected area
        // 
        g.transform(curTxf);
        // 
        // Delegate rendering to painter
        // 
        try {
            root.paint(g);
        } catch (Exception e) {
            g.setTransform(t);
            g.setClip(clip);
            drawError(_g, e);
        }
        // 
        // Restore transform and clip
        // 
        g.setTransform(t);
        g.setClip(clip);
        // g.setPaint(Color.black);
        // g.drawString(uris[pageIndex], 30, 30);
        // 
        // Return status indicated that we did paint a page
        // 
        return PAGE_EXISTS;
    }

    /**
     * Sets doreplacedent size according to the hints.
     * Global variables width and height are modified.
     *
     * @param docWidth Width of the doreplacedent.
     * @param docHeight Height of the doreplacedent.
     */
    protected void setImageSize(float docWidth, float docHeight) {
        // Check hint to know if scaling is really needed
        Boolean scaleToPage = (Boolean) hints.get(KEY_SCALE_TO_PAGE);
        if (scaleToPage != null && !scaleToPage.booleanValue()) {
            float w = docWidth;
            float h = docHeight;
            if (hints.containsKey(KEY_AOI)) {
                Rectangle2D aoi = (Rectangle2D) hints.get(KEY_AOI);
                w = (float) aoi.getWidth();
                h = (float) aoi.getHeight();
            }
            super.setImageSize(w, h);
        }
    }

    /**
     * Prints an error on the output page
     */
    private void drawError(Graphics g, Exception e) {
        userAgent.displayError(e);
    // Should also probably draw exception on page.
    }

    // --------------------------------------------------------------------
    // Keys definition
    // --------------------------------------------------------------------
    /**
     * The showPageDialog key.
     * <table border="0" cellspacing="0" cellpadding="1">
     *   <tr>
     *     <th valign="top" align="right">Key:</th>
     *     <td valign="top">KEY_SHOW_PAGE_DIALOG</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Value:</th>
     *     <td valign="top">Boolean</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Default:</th>
     *     <td valign="top">false</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Required:</th>
     *     <td valign="top">No</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Description:</th>
     *     <td valign="top">Specifies whether or not the transcoder
     *       should pop up a dialog box for selecting
     *       the page format.</td>
     *   </tr>
     * </table>
     */
    public static final TranscodingHints.Key KEY_SHOW_PAGE_DIALOG = new BooleanKey();

    /**
     * The showPrinterDialog key.
     * <table border="0" cellspacing="0" cellpadding="1">
     *   <tr>
     *     <th valign="top" align="right">Key:</th>
     *     <td valign="top">KEY_SHOW_PAGE_DIALOG</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Value:</th>
     *     <td valign="top">Boolean</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Default:</th>
     *     <td valign="top">false</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Required:</th>
     *     <td valign="top">No</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Description:</th>
     *     <td valign="top">Specifies whether or not the transcoder
     *       should pop up a dialog box for selecting
     *       the printer. If the dialog box is not
     *       shown, the transcoder will use the default
     *       printer.</td>
     *   </tr>
     * </table>
     */
    public static final TranscodingHints.Key KEY_SHOW_PRINTER_DIALOG = new BooleanKey();

    /**
     * The pageWidth key.
     * <table border="0" cellspacing="0" cellpadding="1">
     *   <tr>
     *     <th valign="top" align="right">Key:</th>
     *     <td valign="top">KEY_PAGE_WIDTH</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Value:</th>
     *     <td valign="top">Length</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Default:</th>
     *     <td valign="top">None</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Required:</th>
     *     <td valign="top">No</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Description:</th>
     *     <td valign="top">The width of the print page</td>
     *   </tr>
     * </table>
     */
    public static final TranscodingHints.Key KEY_PAGE_WIDTH = new LengthKey();

    /**
     * The pageHeight key.
     * <table border="0" cellspacing="0" cellpadding="1">
     *   <tr>
     *     <th valign="top" align="right">Key:</th>
     *     <td valign="top">KEY_PAGE_HEIGHT</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Value:</th>
     *     <td valign="top">Length</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Default:</th>
     *     <td valign="top">none</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Required:</th>
     *     <td valign="top">No</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Description:</th>
     *     <td valign="top">The height of the print page</td>
     *   </tr>
     * </table>
     */
    public static final TranscodingHints.Key KEY_PAGE_HEIGHT = new LengthKey();

    /**
     * The marginTop key.
     * <table border="0" cellspacing="0" cellpadding="1">
     *   <tr>
     *     <th valign="top" align="right">Key:</th>
     *     <td valign="top">KEY_MARGIN_TOP</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Value:</th>
     *     <td valign="top">Length</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Default:</th>
     *     <td valign="top">None</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Required:</th>
     *     <td valign="top">No</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Description:</th>
     *     <td valign="top">The print page top margin</td>
     *   </tr>
     * </table>
     */
    public static final TranscodingHints.Key KEY_MARGIN_TOP = new LengthKey();

    /**
     * The marginRight key.
     * <table border="0" cellspacing="0" cellpadding="1">
     *   <tr>
     *     <th valign="top" align="right">Key:</th>
     *     <td valign="top">KEY_MARGIN_RIGHT</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Value:</th>
     *     <td valign="top">Length</TD>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Default:</th>
     *     <td valign="top">None</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Required:</th>
     *     <td valign="top">No</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Description:</th>
     *     <td valign="top">The print page right margin</td>
     *   </tr>
     * </table>
     */
    public static final TranscodingHints.Key KEY_MARGIN_RIGHT = new LengthKey();

    /**
     * The marginBottom key.
     * <table border="0" cellspacing="0" cellpadding="1">
     *   <tr>
     *     <th valign="top" align="right">Key:</th>
     *     <td valign="top">KEY_MARGIN_BOTTOM</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Value:</th>
     *     <td valign="top">Length</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Default:</th>
     *     <td valign="top">None</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Required:</th>
     *     <td valign="top">No</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Description:</th>
     *     <td valign="top">The print page bottom margin</td>
     *   </tr>
     * </table>
     */
    public static final TranscodingHints.Key KEY_MARGIN_BOTTOM = new LengthKey();

    /**
     * The marginLeft key.
     * <table border="0" cellspacing="0" cellpadding="1">
     * <tr>
     * <th valign="top" align="right">Key:</th>
     * <td valign="top">KEY_MARGIN_LEFT</td></tr>
     * <tr>
     * <th valign="top" align="right">Value:</th>
     * <td valign="top">Length</td></tr>
     * <tr>
     * <th valign="top" align="right">Default:</th>
     * <td valign="top">None</td></tr>
     * <tr>
     * <th valign="top" align="right">Required:</th>
     * <td valign="top">No</td></tr>
     * <tr>
     * <th valign="top" align="right">Description:</th>
     * <td valign="top">The print page left margin</td></tr>
     * </table>
     */
    public static final TranscodingHints.Key KEY_MARGIN_LEFT = new LengthKey();

    /**
     * The pageOrientation key.
     * <table border="0" cellspacing="0" cellpadding="1">
     *   <tr>
     *     <th valign="top" align="right">Key:</th>
     *     <td valign="top">KEY_PAGE_ORIENTATION</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Value:</th>
     *     <td valign="top">String</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Default:</th>
     *     <td valign="top">VALUE_PAGE_ORIENTATION_PORTRAIT</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Required:</th>
     *     <td valign="top">No</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Description:</th>
     *     <td valign="top">The print page's orientation</td>
     *   </tr>
     * </table>
     */
    public static final TranscodingHints.Key KEY_PAGE_ORIENTATION = new StringKey();

    /**
     * The scaleToPage key.
     * <table border="0" cellspacing="0" cellpadding="1">
     *   <tr>
     *     <th valign="top" align="right">Key:</th>
     *     <td valign="top">KEY_SCALE_TO_PAGE</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Value:</th>
     *     <td valign="top">Boolean</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Default:</th>
     *     <td valign="top">true</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Required:</th>
     *     <td valign="top">No</td>
     *   </tr>
     *   <tr>
     *     <th valign="top" align="right">Description:</th>
     *     <td valign="top">Specifies whether or not the SVG images are scaled to
     *       fit into the printed page</td>
     *   </tr>
     * </table>
     */
    public static final TranscodingHints.Key KEY_SCALE_TO_PAGE = new BooleanKey();

    public static final String USAGE = "java org.apache.batik.transcoder.print.PrintTranscoder <svgFileToPrint>";

    public static void main(String[] args) throws Exception {
        if (args.length < 1) {
            System.err.println(USAGE);
            System.exit(0);
        }
        // 
        // Builds a PrintTranscoder
        // 
        PrintTranscoder transcoder = new PrintTranscoder();
        // 
        // Set the hints, from the command line arguments
        // 
        // Language
        setTranscoderFloatHint(transcoder, KEY_LANGUAGE_STR, KEY_LANGUAGE);
        // User stylesheet
        setTranscoderFloatHint(transcoder, KEY_USER_STYLESHEET_URI_STR, KEY_USER_STYLESHEET_URI);
        // XML parser
        setTranscoderStringHint(transcoder, KEY_XML_PARSER_CLreplacedNAME_STR, KEY_XML_PARSER_CLreplacedNAME);
        // Scale to page
        setTranscoderBooleanHint(transcoder, KEY_SCALE_TO_PAGE_STR, KEY_SCALE_TO_PAGE);
        // AOI
        setTranscoderRectangleHint(transcoder, KEY_AOI_STR, KEY_AOI);
        // Image size
        setTranscoderFloatHint(transcoder, KEY_WIDTH_STR, KEY_WIDTH);
        setTranscoderFloatHint(transcoder, KEY_HEIGHT_STR, KEY_HEIGHT);
        // Pixel to millimeter
        setTranscoderFloatHint(transcoder, KEY_PIXEL_TO_MM_STR, KEY_PIXEL_UNIT_TO_MILLIMETER);
        // Page orientation
        setTranscoderStringHint(transcoder, KEY_PAGE_ORIENTATION_STR, KEY_PAGE_ORIENTATION);
        // Page size
        setTranscoderFloatHint(transcoder, KEY_PAGE_WIDTH_STR, KEY_PAGE_WIDTH);
        setTranscoderFloatHint(transcoder, KEY_PAGE_HEIGHT_STR, KEY_PAGE_HEIGHT);
        // Margins
        setTranscoderFloatHint(transcoder, KEY_MARGIN_TOP_STR, KEY_MARGIN_TOP);
        setTranscoderFloatHint(transcoder, KEY_MARGIN_RIGHT_STR, KEY_MARGIN_RIGHT);
        setTranscoderFloatHint(transcoder, KEY_MARGIN_BOTTOM_STR, KEY_MARGIN_BOTTOM);
        setTranscoderFloatHint(transcoder, KEY_MARGIN_LEFT_STR, KEY_MARGIN_LEFT);
        // Dialog options
        setTranscoderBooleanHint(transcoder, KEY_SHOW_PAGE_DIALOG_STR, KEY_SHOW_PAGE_DIALOG);
        setTranscoderBooleanHint(transcoder, KEY_SHOW_PRINTER_DIALOG_STR, KEY_SHOW_PRINTER_DIALOG);
        // 
        // First, request the transcoder to transcode
        // each of the input files
        // 
        for (int i = 0; i < args.length; i++) {
            transcoder.transcode(new TranscoderInput(new File(args[i]).toURI().toURL().toString()), null);
        }
        // 
        // Now, print...
        // 
        transcoder.print();
        System.exit(0);
    }

    public static void setTranscoderFloatHint(Transcoder transcoder, String property, TranscodingHints.Key key) {
        String str = System.getProperty(property);
        if (str != null) {
            try {
                Float value = new Float(Float.parseFloat(str));
                transcoder.addTranscodingHint(key, value);
            } catch (NumberFormatException e) {
                handleValueError(property, str);
            }
        }
    }

    public static void setTranscoderRectangleHint(Transcoder transcoder, String property, TranscodingHints.Key key) {
        String str = System.getProperty(property);
        if (str != null) {
            StringTokenizer st = new StringTokenizer(str, " ,");
            if (st.countTokens() != 4) {
                handleValueError(property, str);
            }
            try {
                String x = st.nextToken();
                String y = st.nextToken();
                String width = st.nextToken();
                String height = st.nextToken();
                Rectangle2D r = new Rectangle2D.Float(Float.parseFloat(x), Float.parseFloat(y), Float.parseFloat(width), Float.parseFloat(height));
                transcoder.addTranscodingHint(key, r);
            } catch (NumberFormatException e) {
                handleValueError(property, str);
            }
        }
    }

    public static void setTranscoderBooleanHint(Transcoder transcoder, String property, TranscodingHints.Key key) {
        String str = System.getProperty(property);
        if (str != null) {
            Boolean value = "true".equalsIgnoreCase(str) ? Boolean.TRUE : Boolean.FALSE;
            transcoder.addTranscodingHint(key, value);
        }
    }

    public static void setTranscoderStringHint(Transcoder transcoder, String property, TranscodingHints.Key key) {
        String str = System.getProperty(property);
        if (str != null) {
            transcoder.addTranscodingHint(key, str);
        }
    }

    public static void handleValueError(String property, String value) {
        System.err.println("Invalid " + property + " value : " + value);
        System.exit(1);
    }
}

17 View Complete Implementation : SVGFigure.java
Copyright GNU General Public License v2.0
Author : bonitasoft
/**
 * Reads color value from the doreplacedent.
 */
protected Color getColor(final Element element, final String attributeName) {
    if (getDoreplacedent() == null || getDoreplacedent() != element.getOwnerDoreplacedent()) {
        return null;
    }
    Color color = null;
    // Make sure that CSSEngine is available.
    final BridgeContext ctx = transcoder.initCSSEngine();
    try {
        color = SVGUtils.toSWTColor(element, attributeName);
    } finally {
        if (ctx != null) {
            ctx.dispose();
        }
    }
    return color;
}

17 View Complete Implementation : SVG12BridgeEventSupport.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
/**
 * Is called only for the root element in order to dispatch GVT
 * events to the DOM.
 */
public static void addGVTListener(BridgeContext ctx, Doreplacedent doc) {
    UserAgent ua = ctx.getUserAgent();
    if (ua != null) {
        EventDispatcher dispatcher = ua.getEventDispatcher();
        if (dispatcher != null) {
            final Listener listener = new Listener(ctx, ua);
            dispatcher.addGraphicsNodeMouseListener(listener);
            dispatcher.addGraphicsNodeMouseWheelListener(listener);
            dispatcher.addGraphicsNodeKeyListener(listener);
            // add an unload listener on the SVGDoreplacedent to remove
            // that listener for dispatching events
            EventListener l = new GVTUnloadListener(dispatcher, listener);
            NodeEventTarget target = (NodeEventTarget) doc;
            target.addEventListenerNS(XMLConstants.XML_EVENTS_NAMESPACE_URI, "SVGUnload", l, false, null);
            storeEventListenerNS(ctx, target, XMLConstants.XML_EVENTS_NAMESPACE_URI, "SVGUnload", l, false);
        }
    }
}

17 View Complete Implementation : SVGMultiImageElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
/**
 * This method is invoked during the build phase if the doreplacedent
 * is dynamic. The responsability of this method is to ensure that
 * any dynamic modifications of the element this bridge is
 * dedicated to, happen on its replacedociated GVT product.
 */
protected void initializeDynamicSupport(BridgeContext ctx, Element e, GraphicsNode node) {
    if (ctx.isInteractive()) {
        // HACK due to the way images are represented in GVT
        ImageNode imgNode = (ImageNode) node;
        ctx.bind(e, imgNode.getImage());
    }
}

17 View Complete Implementation : BatikFlowTextElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
/**
 * Adds painting attributes to an AttributedString.
 */
protected void addPaintAttributes(AttributedString as, Element element, TextNode node, TextPaintInfo parentPI, BridgeContext ctx) {
    if (element.getNodeType() != Node.ELEMENT_NODE)
        return;
    String eNS = element.getNamespaceURI();
    if ((!eNS.equals(getNamespaceURI())) && (!eNS.equals(SVG_NAMESPACE_URI)))
        return;
    if (element.getLocalName() != BATIK_EXT_FLOW_TEXT_TAG) {
        // System.out.println("Elem: " + element);
        super.addPaintAttributes(as, element, node, parentPI, ctx);
        return;
    }
    for (Node n = element.getFirstChild(); n != null; n = n.getNextSibling()) {
        if (n.getNodeType() != Node.ELEMENT_NODE)
            continue;
        if (!getNamespaceURI().equals(n.getNamespaceURI()))
            continue;
        Element e = (Element) n;
        String ln = e.getLocalName();
        if (ln.equals(BATIK_EXT_FLOW_DIV_TAG)) {
            // System.out.println("D Elem: " + e);
            super.addPaintAttributes(as, e, node, parentPI, ctx);
            return;
        }
    }
}

17 View Complete Implementation : BatikFlowTextElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
/**
 * Adds glyph position attributes to an AttributedString.
 */
protected void addGlyphPositionAttributes(AttributedString as, Element element, BridgeContext ctx) {
    if (element.getNodeType() != Node.ELEMENT_NODE)
        return;
    String eNS = element.getNamespaceURI();
    if ((!eNS.equals(getNamespaceURI())) && (!eNS.equals(SVG_NAMESPACE_URI)))
        return;
    if (element.getLocalName() != BATIK_EXT_FLOW_TEXT_TAG) {
        // System.out.println("Elem: " + element);
        super.addGlyphPositionAttributes(as, element, ctx);
        return;
    }
    for (Node n = element.getFirstChild(); n != null; n = n.getNextSibling()) {
        if (n.getNodeType() != Node.ELEMENT_NODE)
            continue;
        String nNS = n.getNamespaceURI();
        if ((!getNamespaceURI().equals(nNS)) && (!SVG_NAMESPACE_URI.equals(nNS))) {
            continue;
        }
        Element e = (Element) n;
        String ln = e.getLocalName();
        if (ln.equals(BATIK_EXT_FLOW_DIV_TAG)) {
            // System.out.println("D Elem: " + e);
            super.addGlyphPositionAttributes(as, e, ctx);
            return;
        }
    }
}

17 View Complete Implementation : BatikFlowTextElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
protected List getRegions(BridgeContext ctx, Element element) {
    List ret = new LinkedList();
    for (Node n = element.getFirstChild(); n != null; n = n.getNextSibling()) {
        if (n.getNodeType() != Node.ELEMENT_NODE)
            continue;
        if (!getNamespaceURI().equals(n.getNamespaceURI()))
            continue;
        Element e = (Element) n;
        String ln = e.getLocalName();
        if (!BATIK_EXT_FLOW_REGION_TAG.equals(ln))
            continue;
        // our default alignment is to the top of the flow rect.
        float verticalAlignment = 0.0f;
        String verticalAlignmentAttribute = e.getAttribute(BATIK_EXT_VERTICAL_ALIGN_ATTRIBUTE);
        if ((verticalAlignmentAttribute != null) && (verticalAlignmentAttribute.length() > 0)) {
            if (BATIK_EXT_ALIGN_TOP_VALUE.equals(verticalAlignmentAttribute)) {
                verticalAlignment = 0.0f;
            } else if (BATIK_EXT_ALIGN_MIDDLE_VALUE.equals(verticalAlignmentAttribute)) {
                verticalAlignment = 0.5f;
            } else if (BATIK_EXT_ALIGN_BOTTOM_VALUE.equals(verticalAlignmentAttribute)) {
                verticalAlignment = 1.0f;
            }
        }
        gatherRegionInfo(ctx, e, verticalAlignment, ret);
    }
    return ret;
}

17 View Complete Implementation : BatikFlowTextElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
protected void gatherRegionInfo(BridgeContext ctx, Element rgn, float verticalAlign, List regions) {
    for (Node n = rgn.getFirstChild(); n != null; n = n.getNextSibling()) {
        if (n.getNodeType() != Node.ELEMENT_NODE)
            continue;
        if (!getNamespaceURI().equals(n.getNamespaceURI()))
            continue;
        Element e = (Element) n;
        String ln = n.getLocalName();
        if (ln.equals(SVGConstants.SVG_RECT_TAG)) {
            UnitProcessor.Context uctx;
            uctx = UnitProcessor.createContext(ctx, e);
            RegionInfo ri = buildRegion(uctx, e, verticalAlign);
            if (ri != null)
                regions.add(ri);
        }
    }
}

17 View Complete Implementation : JSVGMemoryLeakTest.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
public void registerElement(Element e, String desc) {
    registerObjectDesc(e, desc);
    UpdateManager um = getTheCanvas().getUpdateManager();
    BridgeContext bc = um.getBridgeContext();
    GraphicsNode gn = bc.getGraphicsNode(e);
    if (gn != null)
        registerObjectDesc(gn, desc + "_GN");
    if (e instanceof SVGOMElement) {
        SVGOMElement svge = (SVGOMElement) e;
        SVGContext svgctx = svge.getSVGContext();
        if (svgctx != null) {
            registerObjectDesc(svgctx, desc + "_CTX");
        }
    }
}

17 View Complete Implementation : SVGHandler.java
Copyright Eclipse Public License 1.0
Author : yamcs
private void buildElementsToUpdateList(BridgeContext ctx, Doreplacedent doc) {
    if (doc == null) {
        return;
    }
    elementsToUpdate.clear();
    SVGCSSEngine cssEngine = (SVGCSSEngine) ctx.getCSSEngineForElement(doc.getDoreplacedentElement());
    if (cssEngine == null) {
        return;
    }
    List<?> styleSheetsList = cssEngine.getStyleSheetNodes();
    for (Object node : styleSheetsList) {
        if (node instanceof CSSStyleSheetNode) {
            CSSStyleSheetNode cssNode = (CSSStyleSheetNode) node;
            StyleSheet styleSheet = cssNode.getCSSStyleSheet();
            elementsToUpdate.add(new StyleSheetCSSHandler(cssEngine, styleSheet));
        }
    }
    rBuidElementsList(cssEngine, doc.getDoreplacedentElement());
}

16 View Complete Implementation : SVG12BridgeExtension.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
/**
 * This method should update the BridgeContext with support
 * for the tags in this extension.  In some rare cases it may
 * be necessary to replace existing tag handlers, although this
 * is discouraged.
 *
 * @param ctx The BridgeContext instance to be updated
 */
public void registerTags(BridgeContext ctx) {
    // bridges to handle elements in the SVG namespace
    super.registerTags(ctx);
    // Bridges for SVG 1.2 elements
    ctx.putBridge(new SVGFlowRootElementBridge());
    ctx.putBridge(new SVGMultiImageElementBridge());
    ctx.putBridge(new SVGSolidColorElementBridge());
    ctx.putBridge(new SVG12TextElementBridge());
    // Bridges for XBL shadow trees and content elements
    ctx.putBridge(new XBLShadowTreeElementBridge());
    ctx.putBridge(new XBLContentElementBridge());
    // Default bridge to handle bindable elements
    ctx.setDefaultBridge(new BindableElementBridge());
    // Namespaces to avoid for default bridges
    ctx.putReservedNamespaceURI(null);
    ctx.putReservedNamespaceURI(SVGConstants.SVG_NAMESPACE_URI);
    ctx.putReservedNamespaceURI(XBLConstants.XBL_NAMESPACE_URI);
}

16 View Complete Implementation : SVG12TextElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
/**
 * Adds the DOM listeners for this text bridge.
 */
protected void addTextEventListeners(BridgeContext ctx, NodeEventTarget e) {
    if (childNodeRemovedEventListener == null) {
        childNodeRemovedEventListener = new DOMChildNodeRemovedEventListener();
    }
    if (subtreeModifiedEventListener == null) {
        subtreeModifiedEventListener = new DOMSubtreeModifiedEventListener();
    }
    SVG12BridgeContext ctx12 = (SVG12BridgeContext) ctx;
    AbstractNode n = (AbstractNode) e;
    XBLEventSupport evtSupport = (XBLEventSupport) n.initializeEventSupport();
    // to be notified when a child is removed from the
    // <text> element.
    evtSupport.addImplementationEventListenerNS(XMLConstants.XML_EVENTS_NAMESPACE_URI, "DOMNodeRemoved", childNodeRemovedEventListener, true);
    ctx12.storeImplementationEventListenerNS(e, XMLConstants.XML_EVENTS_NAMESPACE_URI, "DOMNodeRemoved", childNodeRemovedEventListener, true);
    // to be notified when the modification of the subtree
    // of the <text> element is done
    evtSupport.addImplementationEventListenerNS(XMLConstants.XML_EVENTS_NAMESPACE_URI, "DOMSubtreeModified", subtreeModifiedEventListener, false);
    ctx12.storeImplementationEventListenerNS(e, XMLConstants.XML_EVENTS_NAMESPACE_URI, "DOMSubtreeModified", subtreeModifiedEventListener, false);
}

16 View Complete Implementation : SVG12TextElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
/**
 * Removes the DOM listeners for this text bridge.
 */
protected void removeTextEventListeners(BridgeContext ctx, NodeEventTarget e) {
    AbstractNode n = (AbstractNode) e;
    XBLEventSupport evtSupport = (XBLEventSupport) n.initializeEventSupport();
    evtSupport.removeImplementationEventListenerNS(XMLConstants.XML_EVENTS_NAMESPACE_URI, "DOMNodeRemoved", childNodeRemovedEventListener, true);
    evtSupport.removeImplementationEventListenerNS(XMLConstants.XML_EVENTS_NAMESPACE_URI, "DOMSubtreeModified", subtreeModifiedEventListener, false);
}

16 View Complete Implementation : SVGFlowRootElementBridge.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
protected AttributedString gatherFlowPara(BridgeContext ctx, Element div) {
    TextPaintInfo divTPI = new TextPaintInfo();
    // Set some basic props so we can get bounds info for complex paints.
    divTPI.visible = true;
    divTPI.fillPaint = Color.black;
    elemTPI.put(div, divTPI);
    AttributedStringBuffer asb = new AttributedStringBuffer();
    List paraEnds = new ArrayList();
    List paraElems = new ArrayList();
    List lnLocs = new ArrayList();
    for (Node n = getFirstChild(div); n != null; n = getNextSibling(n)) {
        if (n.getNodeType() != Node.ELEMENT_NODE || !getNamespaceURI().equals(n.getNamespaceURI())) {
            continue;
        }
        Element e = (Element) n;
        String ln = e.getLocalName();
        if (ln.equals(SVG12Constants.SVG_FLOW_PARA_TAG)) {
            fillAttributedStringBuffer(ctx, e, true, null, null, asb, lnLocs);
            paraElems.add(e);
            paraEnds.add(new Integer(asb.length()));
        } else if (ln.equals(SVG12Constants.SVG_FLOW_REGION_BREAK_TAG)) {
            fillAttributedStringBuffer(ctx, e, true, null, null, asb, lnLocs);
            paraElems.add(e);
            paraEnds.add(new Integer(asb.length()));
        }
    }
    divTPI.startChar = 0;
    divTPI.endChar = asb.length() - 1;
    // Layer in the PARAGRAPH/LINE_BREAK Attributes so we can
    // break up text chunks.
    AttributedString ret = asb.toAttributedString();
    if (ret == null)
        return null;
    // Note: The Working Group (in conjunction with XHTML working
    // group) has decided that multiple line elements collapse.
    int prevLN = 0;
    Iterator lnIter = lnLocs.iterator();
    while (lnIter.hasNext()) {
        int nextLN = ((Integer) lnIter.next()).intValue();
        if (nextLN == prevLN)
            continue;
        // System.out.println("Attr: [" + prevLN + "," + nextLN + "]");
        ret.addAttribute(FLOW_LINE_BREAK, new Object(), prevLN, nextLN);
        prevLN = nextLN;
    }
    int start = 0;
    int end;
    List emptyPara = null;
    for (int i = 0; i < paraElems.size(); i++, start = end) {
        Element elem = (Element) paraElems.get(i);
        end = ((Integer) paraEnds.get(i)).intValue();
        if (start == end) {
            if (emptyPara == null)
                emptyPara = new LinkedList();
            emptyPara.add(makeBlockInfo(ctx, elem));
            continue;
        }
        // System.out.println("Para: [" + start + ", " + end + "]");
        ret.addAttribute(FLOW_PARAGRAPH, makeBlockInfo(ctx, elem), start, end);
        if (emptyPara != null) {
            ret.addAttribute(FLOW_EMPTY_PARAGRAPH, emptyPara, start, end);
            emptyPara = null;
        }
    }
    return ret;
}

16 View Complete Implementation : GVTTreeBuilder.java
Copyright GNU Lesser General Public License v3.0
Author : git-moss
/**
 * This clreplaced represents an object which builds asynchroneaously
 * a GVT tree.
 *
 * @author <a href="mailto:[email protected]">Stephane Hillion</a>
 * @version $Id: GVTTreeBuilder.java 475477 2006-11-15 22:44:28Z cam $
 */
public clreplaced GVTTreeBuilder extends HaltingThread {

    /**
     * The SVG doreplacedent to give to the bridge.
     */
    protected SVGDoreplacedent svgDoreplacedent;

    /**
     * The bridge context to use.
     */
    protected BridgeContext bridgeContext;

    /**
     * The listeners.
     */
    protected List listeners = Collections.synchronizedList(new LinkedList());

    /**
     * The exception thrown.
     */
    protected Exception exception;

    /**
     * Creates a new GVTTreeBuilder.
     */
    public GVTTreeBuilder(SVGDoreplacedent doc, BridgeContext bc) {
        svgDoreplacedent = doc;
        bridgeContext = bc;
    }

    /**
     * Runs this builder.
     */
    public void run() {
        GVTTreeBuilderEvent ev;
        ev = new GVTTreeBuilderEvent(this, null);
        try {
            fireEvent(startedDispatcher, ev);
            if (isHalted()) {
                fireEvent(cancelledDispatcher, ev);
                return;
            }
            GVTBuilder builder = null;
            if (bridgeContext.isDynamic()) {
                builder = new DynamicGVTBuilder();
            } else {
                builder = new GVTBuilder();
            }
            GraphicsNode gvtRoot = builder.build(bridgeContext, svgDoreplacedent);
            if (isHalted()) {
                fireEvent(cancelledDispatcher, ev);
                return;
            }
            ev = new GVTTreeBuilderEvent(this, gvtRoot);
            fireEvent(completedDispatcher, ev);
        } catch (InterruptedBridgeException e) {
            fireEvent(cancelledDispatcher, ev);
        } catch (BridgeException e) {
            exception = e;
            ev = new GVTTreeBuilderEvent(this, e.getGraphicsNode());
            fireEvent(failedDispatcher, ev);
        } catch (Exception e) {
            exception = e;
            fireEvent(failedDispatcher, ev);
        } catch (ThreadDeath td) {
            exception = new Exception(td.getMessage());
            fireEvent(failedDispatcher, ev);
            throw td;
        } catch (Throwable t) {
            t.printStackTrace();
            exception = new Exception(t.getMessage());
            fireEvent(failedDispatcher, ev);
        } finally {
        // bridgeContext.getDoreplacedentLoader().dispose();
        }
    }

    /**
     * Returns the exception, if any occured.
     */
    public Exception getException() {
        return exception;
    }

    /**
     * Adds a GVTTreeBuilderListener to this GVTTreeBuilder.
     */
    public void addGVTTreeBuilderListener(GVTTreeBuilderListener l) {
        listeners.add(l);
    }

    /**
     * Removes a GVTTreeBuilderListener from this GVTTreeBuilder.
     */
    public void removeGVTTreeBuilderListener(GVTTreeBuilderListener l) {
        listeners.remove(l);
    }

    public void fireEvent(Dispatcher dispatcher, Object event) {
        EventDispatcher.fireEvent(dispatcher, listeners, event, true);
    }

    static Dispatcher startedDispatcher = new Dispatcher() {

        public void dispatch(Object listener, Object event) {
            ((GVTTreeBuilderListener) listener).gvtBuildStarted((GVTTreeBuilderEvent) event);
        }
    };

    static Dispatcher completedDispatcher = new Dispatcher() {

        public void dispatch(Object listener, Object event) {
            ((GVTTreeBuilderListener) listener).gvtBuildCompleted((GVTTreeBuilderEvent) event);
        }
    };

    static Dispatcher cancelledDispatcher = new Dispatcher() {

        public void dispatch(Object listener, Object event) {
            ((GVTTreeBuilderListener) listener).gvtBuildCancelled((GVTTreeBuilderEvent) event);
        }
    };

    static Dispatcher failedDispatcher = new Dispatcher() {

        public void dispatch(Object listener, Object event) {
            ((GVTTreeBuilderListener) listener).gvtBuildFailed((GVTTreeBuilderEvent) event);
        }
    };
}