예제 #1
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;
  }
예제 #2
0
 /** Clears the view CSS. */
 public void clearViewCSS() {
   defaultView = null;
   if (cssEngine != null) {
     cssEngine.dispose();
   }
   cssEngine = null;
 }
 protected void initCSSPropertyIndexes(Element e) {
   CSSEngine eng = CSSUtilities.getCSSEngine(e);
   marginTopIndex = eng.getPropertyIndex(SVG12CSSConstants.CSS_MARGIN_TOP_PROPERTY);
   marginRightIndex = eng.getPropertyIndex(SVG12CSSConstants.CSS_MARGIN_RIGHT_PROPERTY);
   marginBottomIndex = eng.getPropertyIndex(SVG12CSSConstants.CSS_MARGIN_BOTTOM_PROPERTY);
   marginLeftIndex = eng.getPropertyIndex(SVG12CSSConstants.CSS_MARGIN_LEFT_PROPERTY);
   indentIndex = eng.getPropertyIndex(SVG12CSSConstants.CSS_INDENT_PROPERTY);
   textAlignIndex = eng.getPropertyIndex(SVG12CSSConstants.CSS_TEXT_ALIGN_PROPERTY);
   lineHeightIndex = eng.getPropertyIndex(SVG12CSSConstants.CSS_LINE_HEIGHT_PROPERTY);
 }
  /**
   * Implements {@link
   * ValueManager#computeValue(CSSStylableElement,String,CSSEngine,int,StyleMap,Value)}.
   */
  public Value computeValue(
      CSSStylableElement elt, String pseudo, CSSEngine engine, int idx, StyleMap sm, Value value) {
    if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_PERCENTAGE) {
      sm.putLineHeightRelative(idx, true);

      int fsi = engine.getLineHeightIndex();
      CSSStylableElement parent;
      parent = (CSSStylableElement) elt.getParentNode();
      if (parent == null) {
        // Hmmm somthing pretty odd - can't happen accordint to spec,
        // should always have text parent.
        // http://www.w3.org/TR/SVG11/text.html#BaselineShiftProperty
        parent = elt;
      }
      Value fs = engine.getComputedStyle(parent, pseudo, fsi);
      float fsv = fs.getFloatValue();
      float v = value.getFloatValue();
      return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, (fsv * v) / 100f);
    }
    return super.computeValue(elt, pseudo, engine, idx, sm, value);
  }