1 18 package org.apache.batik.svggen.font.table; 19 20 import java.io.ByteArrayInputStream ; 21 22 26 public class GlyfCompositeComp { 27 28 public static final short ARG_1_AND_2_ARE_WORDS = 0x0001; 29 public static final short ARGS_ARE_XY_VALUES = 0x0002; 30 public static final short ROUND_XY_TO_GRID = 0x0004; 31 public static final short WE_HAVE_A_SCALE = 0x0008; 32 public static final short MORE_COMPONENTS = 0x0020; 33 public static final short WE_HAVE_AN_X_AND_Y_SCALE = 0x0040; 34 public static final short WE_HAVE_A_TWO_BY_TWO = 0x0080; 35 public static final short WE_HAVE_INSTRUCTIONS = 0x0100; 36 public static final short USE_MY_METRICS = 0x0200; 37 38 private int firstIndex; 39 private int firstContour; 40 private short argument1; 41 private short argument2; 42 private short flags; 43 private short glyphIndex; 44 private double xscale = 1.0; 45 private double yscale = 1.0; 46 private double scale01 = 0.0; 47 private double scale10 = 0.0; 48 private int xtranslate = 0; 49 private int ytranslate = 0; 50 private int point1 = 0; 51 private int point2 = 0; 52 53 protected GlyfCompositeComp(int firstIndex, int firstContour, ByteArrayInputStream bais) { 54 this.firstIndex = firstIndex; 55 this.firstContour = firstContour; 56 flags = (short)(bais.read()<<8 | bais.read()); 57 glyphIndex = (short)(bais.read()<<8 | bais.read()); 58 59 if ((flags & ARG_1_AND_2_ARE_WORDS) != 0) { 61 argument1 = (short)(bais.read()<<8 | bais.read()); 62 argument2 = (short)(bais.read()<<8 | bais.read()); 63 } else { 64 argument1 = (short) bais.read(); 65 argument2 = (short) bais.read(); 66 } 67 68 if ((flags & ARGS_ARE_XY_VALUES) != 0) { 70 xtranslate = argument1; 71 ytranslate = argument2; 72 } else { 73 point1 = argument1; 74 point2 = argument2; 75 } 76 77 if ((flags & WE_HAVE_A_SCALE) != 0) { 79 int i = (short)(bais.read()<<8 | bais.read()); 80 xscale = yscale = (double) i / (double) 0x4000; 81 } else if ((flags & WE_HAVE_AN_X_AND_Y_SCALE) != 0) { 82 short i = (short)(bais.read()<<8 | bais.read()); 83 xscale = (double) i / (double) 0x4000; 84 i = (short)(bais.read()<<8 | bais.read()); 85 yscale = (double) i / (double) 0x4000; 86 } else if ((flags & WE_HAVE_A_TWO_BY_TWO) != 0) { 87 int i = (short)(bais.read()<<8 | bais.read()); 88 xscale = (double) i / (double) 0x4000; 89 i = (short)(bais.read()<<8 | bais.read()); 90 scale01 = (double) i / (double) 0x4000; 91 i = (short)(bais.read()<<8 | bais.read()); 92 scale10 = (double) i / (double) 0x4000; 93 i = (short)(bais.read()<<8 | bais.read()); 94 yscale = (double) i / (double) 0x4000; 95 } 96 } 97 98 public int getFirstIndex() { 99 return firstIndex; 100 } 101 102 public int getFirstContour() { 103 return firstContour; 104 } 105 106 public short getArgument1() { 107 return argument1; 108 } 109 110 public short getArgument2() { 111 return argument2; 112 } 113 114 public short getFlags() { 115 return flags; 116 } 117 118 public short getGlyphIndex() { 119 return glyphIndex; 120 } 121 122 public double getScale01() { 123 return scale01; 124 } 125 126 public double getScale10() { 127 return scale10; 128 } 129 130 public double getXScale() { 131 return xscale; 132 } 133 134 public double getYScale() { 135 return yscale; 136 } 137 138 public int getXTranslate() { 139 return xtranslate; 140 } 141 142 public int getYTranslate() { 143 return ytranslate; 144 } 145 146 152 public int scaleX(int x, int y) { 153 return Math.round((float)(x * xscale + y * scale10)); 154 } 155 156 162 public int scaleY(int x, int y) { 163 return Math.round((float)(x * scale01 + y * yscale)); 164 } 165 } 166 | Popular Tags |