1 18 package org.apache.batik.bridge; 19 20 import org.apache.batik.gvt.text.ArabicTextHandler; 21 import org.apache.batik.gvt.font.GVTFontFace; 22 import org.w3c.dom.Element ; 23 import org.w3c.dom.NodeList ; 24 25 31 public class SVGFontElementBridge extends AbstractSVGBridge { 32 33 36 public SVGFontElementBridge() { 37 } 38 39 42 public String getLocalName() { 43 return SVG_FONT_TAG; 44 } 45 46 58 public SVGGVTFont createFont(BridgeContext ctx, 59 Element fontElement, 60 Element textElement, 61 float size, 62 GVTFontFace fontFace) { 63 64 65 NodeList glyphElements = fontElement.getElementsByTagNameNS 68 (SVG_NAMESPACE_URI, SVG_GLYPH_TAG); 69 int numGlyphs = glyphElements.getLength(); 70 String [] glyphCodes = new String [numGlyphs]; 71 String [] glyphNames = new String [numGlyphs]; 72 String [] glyphLangs = new String [numGlyphs]; 73 String [] glyphOrientations = new String [numGlyphs]; 74 String [] glyphForms = new String [numGlyphs]; 75 Element [] glyphElementArray = new Element [numGlyphs]; 76 77 for (int i = 0; i < numGlyphs; i++) { 78 Element glyphElement = (Element )glyphElements.item(i); 79 glyphCodes[i] = glyphElement.getAttributeNS(null, SVG_UNICODE_ATTRIBUTE); 80 if (glyphCodes[i].length() > 1) { 81 if (ArabicTextHandler.arabicChar(glyphCodes[i].charAt(0))) { 83 glyphCodes[i] = (new StringBuffer (glyphCodes[i])).reverse().toString(); 84 } 85 } 86 glyphNames[i] = glyphElement.getAttributeNS(null, SVG_GLYPH_NAME_ATTRIBUTE); 87 glyphLangs[i] = glyphElement.getAttributeNS(null, SVG_LANG_ATTRIBUTE); 88 glyphOrientations[i] = glyphElement.getAttributeNS(null, SVG_ORIENTATION_ATTRIBUTE); 89 glyphForms[i] = glyphElement.getAttributeNS(null, SVG_ARABIC_FORM_ATTRIBUTE); 90 glyphElementArray[i] = glyphElement; 91 } 92 93 NodeList missingGlyphElements = fontElement.getElementsByTagNameNS 95 (SVG_NAMESPACE_URI, SVG_MISSING_GLYPH_TAG); 96 Element missingGlyphElement = null; 97 if (missingGlyphElements.getLength() > 0) { 98 missingGlyphElement = (Element )missingGlyphElements.item(0); 99 } 100 101 NodeList hkernElements = fontElement.getElementsByTagNameNS 103 (SVG_NAMESPACE_URI, SVG_HKERN_TAG); 104 Element [] hkernElementArray = new Element [hkernElements.getLength()]; 105 106 for (int i = 0; i < hkernElementArray.length; i++) { 107 Element hkernElement = (Element )hkernElements.item(i); 108 hkernElementArray[i] = hkernElement; 109 } 110 111 NodeList vkernElements = fontElement.getElementsByTagNameNS 113 (SVG_NAMESPACE_URI, SVG_VKERN_TAG); 114 Element [] vkernElementArray = new Element [vkernElements.getLength()]; 115 116 for (int i = 0; i < vkernElementArray.length; i++) { 117 Element vkernElement = (Element )vkernElements.item(i); 118 vkernElementArray[i] = vkernElement; 119 } 120 121 return new SVGGVTFont 123 (size, fontFace, glyphCodes, glyphNames, glyphLangs, 124 glyphOrientations, glyphForms, ctx, 125 glyphElementArray, missingGlyphElement, 126 hkernElementArray, vkernElementArray, textElement); 127 } 128 } 129 | Popular Tags |