1 18 package org.apache.batik.svggen.font.table; 19 20 import java.io.ByteArrayInputStream ; 21 import java.util.Vector ; 22 23 31 public class GlyfCompositeDescript extends GlyfDescript { 32 33 private Vector components = new Vector (); 34 35 public GlyfCompositeDescript(GlyfTable parentTable, 36 ByteArrayInputStream bais) { 37 super(parentTable, (short) -1, bais); 38 39 GlyfCompositeComp comp; 41 int firstIndex = 0; 42 int firstContour = 0; 43 do { 44 comp = new GlyfCompositeComp(firstIndex, firstContour, bais); 45 components.addElement(comp); 46 47 GlyphDescription desc; 48 desc = parentTable.getDescription(comp.getGlyphIndex()); 49 if (desc != null) { 50 firstIndex += desc.getPointCount(); 51 firstContour += desc.getContourCount(); 52 } 53 } while ((comp.getFlags() & GlyfCompositeComp.MORE_COMPONENTS) != 0); 54 55 if ((comp.getFlags() & GlyfCompositeComp.WE_HAVE_INSTRUCTIONS) != 0) { 57 readInstructions(bais, (bais.read()<<8 | bais.read())); 58 } 59 } 60 61 public int getEndPtOfContours(int i) { 62 GlyfCompositeComp c = getCompositeCompEndPt(i); 63 if (c != null) { 64 GlyphDescription gd = parentTable.getDescription(c.getGlyphIndex()); 65 return gd.getEndPtOfContours(i - c.getFirstContour()) + c.getFirstIndex(); 66 } 67 return 0; 68 } 69 70 public byte getFlags(int i) { 71 GlyfCompositeComp c = getCompositeComp(i); 72 if (c != null) { 73 GlyphDescription gd = parentTable.getDescription(c.getGlyphIndex()); 74 return gd.getFlags(i - c.getFirstIndex()); 75 } 76 return 0; 77 } 78 79 public short getXCoordinate(int i) { 80 GlyfCompositeComp c = getCompositeComp(i); 81 if (c != null) { 82 GlyphDescription gd = parentTable.getDescription(c.getGlyphIndex()); 83 int n = i - c.getFirstIndex(); 84 int x = gd.getXCoordinate(n); 85 int y = gd.getYCoordinate(n); 86 short x1 = (short) c.scaleX(x, y); 87 x1 += c.getXTranslate(); 88 return x1; 89 } 90 return 0; 91 } 92 93 public short getYCoordinate(int i) { 94 GlyfCompositeComp c = getCompositeComp(i); 95 if (c != null) { 96 GlyphDescription gd = parentTable.getDescription(c.getGlyphIndex()); 97 int n = i - c.getFirstIndex(); 98 int x = gd.getXCoordinate(n); 99 int y = gd.getYCoordinate(n); 100 short y1 = (short) c.scaleY(x, y); 101 y1 += c.getYTranslate(); 102 return y1; 103 } 104 return 0; 105 } 106 107 public boolean isComposite() { 108 return true; 109 } 110 111 public int getPointCount() { 112 GlyfCompositeComp c = (GlyfCompositeComp) components.elementAt(components.size()-1); 113 return c.getFirstIndex() + parentTable.getDescription(c.getGlyphIndex()).getPointCount(); 114 } 115 116 public int getContourCount() { 117 GlyfCompositeComp c = (GlyfCompositeComp) components.elementAt(components.size()-1); 118 return c.getFirstContour() + parentTable.getDescription(c.getGlyphIndex()).getContourCount(); 119 } 120 121 public int getComponentIndex(int i) { 122 return ((GlyfCompositeComp)components.elementAt(i)).getFirstIndex(); 123 } 124 125 public int getComponentCount() { 126 return components.size(); 127 } 128 129 protected GlyfCompositeComp getCompositeComp(int i) { 130 GlyfCompositeComp c; 131 for (int n = 0; n < components.size(); n++) { 132 c = (GlyfCompositeComp) components.elementAt(n); 133 GlyphDescription gd = parentTable.getDescription(c.getGlyphIndex()); 134 if (c.getFirstIndex() <= i && i < (c.getFirstIndex() + gd.getPointCount())) { 135 return c; 136 } 137 } 138 return null; 139 } 140 141 protected GlyfCompositeComp getCompositeCompEndPt(int i) { 142 GlyfCompositeComp c; 143 for (int j = 0; j < components.size(); j++) { 144 c = (GlyfCompositeComp) components.elementAt(j); 145 GlyphDescription gd = parentTable.getDescription(c.getGlyphIndex()); 146 if (c.getFirstContour() <= i && i < (c.getFirstContour() + gd.getContourCount())) { 147 return c; 148 } 149 } 150 return null; 151 } 152 } 153 | Popular Tags |