1 /* 2 3 ============================================================================ 4 The Apache Software License, Version 1.1 5 ============================================================================ 6 7 Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. 8 9 Redistribution and use in source and binary forms, with or without modifica- 10 tion, are permitted provided that the following conditions are met: 11 12 1. Redistributions of source code must retain the above copyright notice, 13 this list of conditions and the following disclaimer. 14 15 2. Redistributions in binary form must reproduce the above copyright notice, 16 this list of conditions and the following disclaimer in the documentation 17 and/or other materials provided with the distribution. 18 19 3. The end-user documentation included with the redistribution, if any, must 20 include the following acknowledgment: "This product includes software 21 developed by the Apache Software Foundation (http://www.apache.org/)." 22 Alternately, this acknowledgment may appear in the software itself, if 23 and wherever such third-party acknowledgments normally appear. 24 25 4. The names "Batik" and "Apache Software Foundation" must not be 26 used to endorse or promote products derived from this software without 27 prior written permission. For written permission, please contact 28 apache@apache.org. 29 30 5. Products derived from this software may not be called "Apache", nor may 31 "Apache" appear in their name, without prior written permission of the 32 Apache Software Foundation. 33 34 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 35 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 36 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 37 APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 38 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- 39 DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 40 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 41 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 42 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 43 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 45 This software consists of voluntary contributions made by many individuals 46 on behalf of the Apache Software Foundation. For more information on the 47 Apache Software Foundation, please see <http://www.apache.org/>. 48 49 */ 50 51 package jogamp.graph.font.typecast.ot.table; 52 53 import java.io.DataInput; 54 import java.io.IOException; 55 56 /** 57 * @version $Id: GlyfCompositeComp.java,v 1.3 2010-08-10 11:41:55 davidsch Exp $ 58 * @author <a href="mailto:davidsch@dev.java.net">David Schweinsberg</a> 59 */ 60 public class GlyfCompositeComp { 61 62 public static final short ARG_1_AND_2_ARE_WORDS = 0x0001; 63 public static final short ARGS_ARE_XY_VALUES = 0x0002; 64 public static final short ROUND_XY_TO_GRID = 0x0004; 65 public static final short WE_HAVE_A_SCALE = 0x0008; 66 public static final short MORE_COMPONENTS = 0x0020; 67 public static final short WE_HAVE_AN_X_AND_Y_SCALE = 0x0040; 68 public static final short WE_HAVE_A_TWO_BY_TWO = 0x0080; 69 public static final short WE_HAVE_INSTRUCTIONS = 0x0100; 70 public static final short USE_MY_METRICS = 0x0200; 71 72 private final int _firstIndex; 73 private final int _firstContour; 74 private short _argument1; 75 private short _argument2; 76 private final int _flags; 77 private final int _glyphIndex; 78 private double _xscale = 1.0; 79 private double _yscale = 1.0; 80 private double _scale01 = 0.0; 81 private double _scale10 = 0.0; 82 private int _xtranslate = 0; 83 private int _ytranslate = 0; 84 private int _point1 = 0; 85 private int _point2 = 0; 86 GlyfCompositeComp(final int firstIndex, final int firstContour, final DataInput di)87 protected GlyfCompositeComp(final int firstIndex, final int firstContour, final DataInput di) 88 throws IOException { 89 _firstIndex = firstIndex; 90 _firstContour = firstContour; 91 _flags = di.readUnsignedShort(); 92 _glyphIndex = di.readUnsignedShort(); 93 94 // Get the arguments as just their raw values 95 if ((_flags & ARG_1_AND_2_ARE_WORDS) != 0) { 96 _argument1 = di.readShort(); 97 _argument2 = di.readShort(); 98 } else { 99 _argument1 = di.readByte(); 100 _argument2 = di.readByte(); 101 } 102 103 // Assign the arguments according to the flags 104 if ((_flags & ARGS_ARE_XY_VALUES) != 0) { 105 _xtranslate = _argument1; 106 _ytranslate = _argument2; 107 } else { 108 _point1 = _argument1; 109 _point2 = _argument2; 110 } 111 112 // Get the scale values (if any) 113 if ((_flags & WE_HAVE_A_SCALE) != 0) { 114 final int i = di.readShort(); 115 _xscale = _yscale = (double) i / (double) 0x4000; 116 } else if ((_flags & WE_HAVE_AN_X_AND_Y_SCALE) != 0) { 117 short i = di.readShort(); 118 _xscale = (double) i / (double) 0x4000; 119 i = di.readShort(); 120 _yscale = (double) i / (double) 0x4000; 121 } else if ((_flags & WE_HAVE_A_TWO_BY_TWO) != 0) { 122 int i = di.readShort(); 123 _xscale = (double) i / (double) 0x4000; 124 i = di.readShort(); 125 _scale01 = (double) i / (double) 0x4000; 126 i = di.readShort(); 127 _scale10 = (double) i / (double) 0x4000; 128 i = di.readShort(); 129 _yscale = (double) i / (double) 0x4000; 130 } 131 } 132 getFirstIndex()133 public int getFirstIndex() { 134 return _firstIndex; 135 } 136 getFirstContour()137 public int getFirstContour() { 138 return _firstContour; 139 } 140 getArgument1()141 public short getArgument1() { 142 return _argument1; 143 } 144 getArgument2()145 public short getArgument2() { 146 return _argument2; 147 } 148 getFlags()149 public int getFlags() { 150 return _flags; 151 } 152 getGlyphIndex()153 public int getGlyphIndex() { 154 return _glyphIndex; 155 } 156 getScale01()157 public double getScale01() { 158 return _scale01; 159 } 160 getScale10()161 public double getScale10() { 162 return _scale10; 163 } 164 getXScale()165 public double getXScale() { 166 return _xscale; 167 } 168 getYScale()169 public double getYScale() { 170 return _yscale; 171 } 172 getXTranslate()173 public int getXTranslate() { 174 return _xtranslate; 175 } 176 getYTranslate()177 public int getYTranslate() { 178 return _ytranslate; 179 } 180 181 /** 182 * Transforms an x-coordinate of a point for this component. 183 * @param x The x-coordinate of the point to transform 184 * @param y The y-coordinate of the point to transform 185 * @return The transformed x-coordinate 186 */ scaleX(final int x, final int y)187 public int scaleX(final int x, final int y) { 188 return (int)(x * _xscale + y * _scale10); 189 } 190 191 /** 192 * Transforms a y-coordinate of a point for this component. 193 * @param x The x-coordinate of the point to transform 194 * @param y The y-coordinate of the point to transform 195 * @return The transformed y-coordinate 196 */ scaleY(final int x, final int y)197 public int scaleY(final int x, final int y) { 198 return (int)(x * _scale01 + y * _yscale); 199 } 200 } 201