1 18 package org.apache.batik.bridge; 19 20 import java.text.AttributedCharacterIterator ; 21 import java.util.Map ; 22 23 import org.apache.batik.gvt.font.GVTFont; 24 import org.apache.batik.gvt.font.GVTFontFace; 25 import org.apache.batik.gvt.font.GVTFontFamily; 26 import org.apache.batik.gvt.text.GVTAttributedCharacterIterator; 27 import org.apache.batik.util.SVGConstants; 28 29 import org.w3c.dom.Element ; 30 import org.w3c.dom.Node ; 31 import org.w3c.dom.NodeList ; 32 33 39 public class SVGFontFamily implements GVTFontFamily { 40 41 public static final 42 AttributedCharacterIterator.Attribute TEXT_COMPOUND_DELIMITER = 43 GVTAttributedCharacterIterator.TextAttribute.TEXT_COMPOUND_DELIMITER; 44 45 protected GVTFontFace fontFace; 46 protected Element fontElement; 47 protected BridgeContext ctx; 48 protected Boolean complex = null; 49 50 51 52 60 public SVGFontFamily(GVTFontFace fontFace, 61 Element fontElement, 62 BridgeContext ctx) { 63 this.fontFace = fontFace; 64 this.fontElement = fontElement; 65 this.ctx = ctx; 66 } 67 68 73 public String getFamilyName() { 74 return fontFace.getFamilyName(); 75 } 76 77 82 public GVTFontFace getFontFace() { 83 return fontFace; 84 } 85 86 95 public GVTFont deriveFont(float size, AttributedCharacterIterator aci) { 96 return deriveFont(size, aci.getAttributes()); 97 } 98 99 104 public GVTFont deriveFont(float size, Map attrs) { 105 SVGFontElementBridge fontBridge; 106 fontBridge = (SVGFontElementBridge)ctx.getBridge(fontElement); 107 Element textElement; 108 textElement = (Element )attrs.get(TEXT_COMPOUND_DELIMITER); 109 return fontBridge.createFont(ctx, fontElement, textElement, 110 size, fontFace); 111 } 112 113 120 public boolean isComplex() { 121 if (complex != null) return complex.booleanValue(); 122 boolean ret = isComplex(fontElement, ctx); 123 complex = new Boolean (ret); 124 return ret; 125 } 126 127 public static boolean isComplex(Element fontElement, BridgeContext ctx) { 128 NodeList glyphElements = fontElement.getElementsByTagNameNS 129 (SVGConstants.SVG_NAMESPACE_URI, SVGConstants.SVG_GLYPH_TAG); 130 131 int numGlyphs = glyphElements.getLength(); 132 for (int i = 0; i < numGlyphs; i++) { 133 Element glyph = (Element )glyphElements.item(i); 134 Node child = glyph.getFirstChild(); 135 for (;child != null; child = child.getNextSibling()) { 136 if (child.getNodeType() != Node.ELEMENT_NODE) 137 continue; 138 Element e = (Element )child; 139 Bridge b = ctx.getBridge(e); 140 if ((b != null) && (b instanceof GraphicsNodeBridge)) { 141 return true; 142 } 143 } 144 } 145 return false; 146 } 147 } 148 | Popular Tags |