/**
   * Returns a list of Filter objects that represents the feMergeNode of the specified feMerge
   * filter element.
   *
   * @param filterElement the feMerge filter element
   * @param filteredElement the filtered element
   * @param filteredNode the filtered graphics node
   * @param inputFilter the <tt>Filter</tt> that represents the current filter input if the filter
   *     chain.
   * @param filterMap the filter map that contains named filter primitives
   * @param ctx the bridge context
   */
  protected static List extractFeMergeNode(
      Element filterElement,
      Element filteredElement,
      GraphicsNode filteredNode,
      Filter inputFilter,
      Map filterMap,
      BridgeContext ctx) {

    List srcs = null;
    for (Node n = filterElement.getFirstChild(); n != null; n = n.getNextSibling()) {

      if (n.getNodeType() != Node.ELEMENT_NODE) {
        continue;
      }

      Element e = (Element) n;
      Bridge bridge = ctx.getBridge(e);
      if (bridge == null || !(bridge instanceof SVGFeMergeNodeElementBridge)) {
        continue;
      }
      Filter filter =
          ((SVGFeMergeNodeElementBridge) bridge)
              .createFilter(ctx, e, filteredElement, filteredNode, inputFilter, filterMap);
      if (filter != null) {
        if (srcs == null) {
          srcs = new LinkedList();
        }
        srcs.add(filter);
      }
    }
    return srcs;
  }
Example #2
0
  public static List getFontFaces(Document doc, BridgeContext ctx) {
    // check fontFamilyMap to see if we have already created an
    // FontFamily that matches
    Map fontFamilyMap = ctx.getFontFamilyMap();
    List ret = (List) fontFamilyMap.get(doc);
    if (ret != null) return ret;

    ret = new LinkedList();

    NodeList fontFaceElements = doc.getElementsByTagNameNS(SVG_NAMESPACE_URI, SVG_FONT_FACE_TAG);

    SVGFontFaceElementBridge fontFaceBridge;
    fontFaceBridge = (SVGFontFaceElementBridge) ctx.getBridge(SVG_NAMESPACE_URI, SVG_FONT_FACE_TAG);

    for (int i = 0; i < fontFaceElements.getLength(); i++) {
      Element fontFaceElement = (Element) fontFaceElements.item(i);
      ret.add(fontFaceBridge.createFontFace(ctx, fontFaceElement));
    }

    CSSEngine engine = ((SVGOMDocument) doc).getCSSEngine();
    List sms = engine.getFontFaces();
    Iterator iter = sms.iterator();
    while (iter.hasNext()) {
      FontFaceRule ffr = (FontFaceRule) iter.next();
      ret.add(CSSFontFace.createCSSFontFace(engine, ffr));
    }
    return ret;
  }
Example #3
0
  /**
   * Returns a Color object that corresponds to the input Paint's ICC color value or null if the
   * related color profile could not be used or loaded for any reason.
   *
   * @param e the element using the color
   * @param c the ICC color definition
   * @param opacity the opacity
   * @param ctx the bridge context to use
   */
  public static Color convertICCColor(Element e, ICCColor c, float opacity, BridgeContext ctx) {
    // Get ICC Profile's name
    String iccProfileName = c.getColorProfile();
    if (iccProfileName == null) {
      return null;
    }
    // Ask the bridge to map the ICC profile name to an  ICC_Profile object
    SVGColorProfileElementBridge profileBridge =
        (SVGColorProfileElementBridge) ctx.getBridge(SVG_NAMESPACE_URI, SVG_COLOR_PROFILE_TAG);
    if (profileBridge == null) {
      return null; // no bridge for color profile
    }

    ICCColorSpaceExt profileCS = profileBridge.createICCColorSpaceExt(ctx, e, iccProfileName);
    if (profileCS == null) {
      return null; // no profile
    }

    // Now, convert the colors to an array of floats
    int n = c.getNumberOfColors();
    float[] colorValue = new float[n];
    if (n == 0) {
      return null;
    }
    for (int i = 0; i < n; i++) {
      colorValue[i] = c.getColor(i);
    }

    // Convert values to RGB
    float[] rgb = profileCS.intendedToRGB(colorValue);
    return new Color(rgb[0], rgb[1], rgb[2], opacity);
  }
Example #4
0
  /**
   * Returns a <code>Marker</code> defined on the specified element by the specified value, and for
   * the specified shape node.
   *
   * @param e the painted element
   * @param v the CSS value describing the marker to construct
   * @param ctx the bridge context
   */
  public static Marker convertMarker(Element e, Value v, BridgeContext ctx) {

    if (v.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) {
      return null; // 'none'
    } else {
      String uri = v.getStringValue();
      Element markerElement = ctx.getReferencedElement(e, uri);
      Bridge bridge = ctx.getBridge(markerElement);
      if (bridge == null || !(bridge instanceof MarkerBridge)) {
        throw new BridgeException(ctx, e, ERR_CSS_URI_BAD_TARGET, new Object[] {uri});
      }
      return ((MarkerBridge) bridge).createMarker(ctx, markerElement, e);
    }
  }
Example #5
0
  /**
   * Converts a Paint specified as a URI.
   *
   * @param paintedElement the element interested in a Paint
   * @param paintedNode the graphics node to paint (objectBoundingBox)
   * @param paintDef the paint definition
   * @param opacity the opacity to consider for the Paint
   * @param ctx the bridge context
   */
  public static Paint convertURIPaint(
      Element paintedElement,
      GraphicsNode paintedNode,
      Value paintDef,
      float opacity,
      BridgeContext ctx) {

    String uri = paintDef.getStringValue();
    Element paintElement = ctx.getReferencedElement(paintedElement, uri);

    Bridge bridge = ctx.getBridge(paintElement);
    if (bridge == null || !(bridge instanceof PaintBridge)) {
      throw new BridgeException(ctx, paintedElement, ERR_CSS_URI_BAD_TARGET, new Object[] {uri});
    }
    return ((PaintBridge) bridge)
        .createPaint(ctx, paintElement, paintedElement, paintedNode, opacity);
  }
Example #6
0
  /** Tries to build a GVTFontFamily from a URL reference */
  protected GVTFontFamily getFontFamily(BridgeContext ctx, ParsedURL purl) {
    String purlStr = purl.toString();

    Element e = getBaseElement(ctx);
    SVGDocument svgDoc = (SVGDocument) e.getOwnerDocument();
    String docURL = svgDoc.getURL();
    ParsedURL pDocURL = null;
    if (docURL != null) pDocURL = new ParsedURL(docURL);

    // try to load an SVG document
    String baseURI = AbstractNode.getBaseURI(e);
    purl = new ParsedURL(baseURI, purlStr);
    UserAgent userAgent = ctx.getUserAgent();

    try {
      userAgent.checkLoadExternalResource(purl, pDocURL);
    } catch (SecurityException ex) {
      // Can't load font - Security violation.
      // We should not throw the error that is for certain, just
      // move down the font list, but do we display the error or not???
      // I'll vote yes just because it is a security exception (other
      // exceptions like font not available etc I would skip).
      userAgent.displayError(ex);
      return null;
    }

    if (purl.getRef() != null) {
      // Reference must be to a SVGFont.
      Element ref = ctx.getReferencedElement(e, purlStr);
      if (!ref.getNamespaceURI().equals(SVG_NAMESPACE_URI)
          || !ref.getLocalName().equals(SVG_FONT_TAG)) {
        return null;
      }

      SVGDocument doc = (SVGDocument) e.getOwnerDocument();
      SVGDocument rdoc = (SVGDocument) ref.getOwnerDocument();

      Element fontElt = ref;
      if (doc != rdoc) {
        fontElt = (Element) doc.importNode(ref, true);
        String base = AbstractNode.getBaseURI(ref);
        Element g = doc.createElementNS(SVG_NAMESPACE_URI, SVG_G_TAG);
        g.appendChild(fontElt);
        g.setAttributeNS(XMLConstants.XML_NAMESPACE_URI, "xml:base", base);
        CSSUtilities.computeStyleAndURIs(ref, fontElt, purlStr);
      }

      // Search for a font-face element
      Element fontFaceElt = null;
      for (Node n = fontElt.getFirstChild(); n != null; n = n.getNextSibling()) {
        if ((n.getNodeType() == Node.ELEMENT_NODE)
            && n.getNamespaceURI().equals(SVG_NAMESPACE_URI)
            && n.getLocalName().equals(SVG_FONT_FACE_TAG)) {
          fontFaceElt = (Element) n;
          break;
        }
      }
      // todo : if the above loop fails to find a fontFaceElt, a null is passed to createFontFace()

      SVGFontFaceElementBridge fontFaceBridge;
      fontFaceBridge =
          (SVGFontFaceElementBridge) ctx.getBridge(SVG_NAMESPACE_URI, SVG_FONT_FACE_TAG);
      GVTFontFace gff = fontFaceBridge.createFontFace(ctx, fontFaceElt);

      return new SVGFontFamily(gff, fontElt, ctx);
    }
    // Must be a reference to a 'Web Font'.
    try {
      return ctx.getFontFamilyResolver().loadFont(purl.openStream(), this);
    } catch (Exception ex) {
    }
    return null;
  }