/** Reads color value from the document. */
 protected Color getColor(Element element, String attributeName) {
   if (getDocument() == null || getDocument() != element.getOwnerDocument()) {
     return null;
   }
   Color color = null;
   // Make sure that CSSEngine is available.
   BridgeContext ctx = transcoder.initCSSEngine();
   try {
     color = SVGUtils.toSWTColor(element, attributeName);
   } finally {
     if (ctx != null) {
       ctx.dispose();
     }
   }
   return color;
 }
Example #2
0
  /** 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 = (Vector) inputs.clone();
    }

    //
    // 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 document now if we are printing a new page
    //
    if (curIndex != pageIndex) {
      if (theCtx != null) theCtx.dispose();

      // The following call will invoke this class' transcode
      // method which takes a document as an input. That method
      // builds the GVT root tree.{
      try {
        width = (int) pageFormat.getImageableWidth();
        height = (int) pageFormat.getImageableHeight();
        super.transcode((TranscoderInput) printedInputs.elementAt(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 document 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;
  }