1 18 package org.apache.batik.svggen.font.table; 19 20 import java.io.ByteArrayInputStream ; 21 22 26 public class GlyfSimpleDescript extends GlyfDescript { 27 28 private int[] endPtsOfContours; 29 private byte[] flags; 30 private short[] xCoordinates; 31 private short[] yCoordinates; 32 private int count; 33 34 public GlyfSimpleDescript(GlyfTable parentTable, short numberOfContours, ByteArrayInputStream bais) { 35 36 super(parentTable, numberOfContours, bais); 37 38 endPtsOfContours = new int[numberOfContours]; 40 for (int i = 0; i < numberOfContours; i++) { 41 endPtsOfContours[i] = (bais.read()<<8 | bais.read()); 42 } 43 44 count = endPtsOfContours[numberOfContours-1] + 1; 46 flags = new byte[count]; 47 xCoordinates = new short[count]; 48 yCoordinates = new short[count]; 49 50 int instructionCount = (bais.read()<<8 | bais.read()); 51 readInstructions(bais, instructionCount); 52 readFlags(count, bais); 53 readCoords(count, bais); 54 } 55 56 public int getEndPtOfContours(int i) { 57 return endPtsOfContours[i]; 58 } 59 60 public byte getFlags(int i) { 61 return flags[i]; 62 } 63 64 public short getXCoordinate(int i) { 65 return xCoordinates[i]; 66 } 67 68 public short getYCoordinate(int i) { 69 return yCoordinates[i]; 70 } 71 72 public boolean isComposite() { 73 return false; 74 } 75 76 public int getPointCount() { 77 return count; 78 } 79 80 public int getContourCount() { 81 return getNumberOfContours(); 82 } 83 92 95 private void readCoords(int count, ByteArrayInputStream bais) { 96 short x = 0; 97 short y = 0; 98 for (int i = 0; i < count; i++) { 99 if ((flags[i] & xDual) != 0) { 100 if ((flags[i] & xShortVector) != 0) { 101 x += (short) bais.read(); 102 } 103 } else { 104 if ((flags[i] & xShortVector) != 0) { 105 x += (short) -((short) bais.read()); 106 } else { 107 x += (short)(bais.read()<<8 | bais.read()); 108 } 109 } 110 xCoordinates[i] = x; 111 } 112 113 for (int i = 0; i < count; i++) { 114 if ((flags[i] & yDual) != 0) { 115 if ((flags[i] & yShortVector) != 0) { 116 y += (short) bais.read(); 117 } 118 } else { 119 if ((flags[i] & yShortVector) != 0) { 120 y += (short) -((short) bais.read()); 121 } else { 122 y += (short)(bais.read()<<8 | bais.read()); 123 } 124 } 125 yCoordinates[i] = y; 126 } 127 } 128 129 132 private void readFlags(int flagCount, ByteArrayInputStream bais) { 133 try { 134 for (int index = 0; index < flagCount; index++) { 135 flags[index] = (byte) bais.read(); 136 if ((flags[index] & repeat) != 0) { 137 int repeats = bais.read(); 138 for (int i = 1; i <= repeats; i++) { 139 flags[index + i] = flags[index]; 140 } 141 index += repeats; 142 } 143 } 144 } catch (ArrayIndexOutOfBoundsException e) { 145 System.out.println("error: array index out of bounds"); 146 } 147 } 148 } 149 | Popular Tags |