KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > svggen > font > table > GlyfCompositeComp


1 /*
2
3    Copyright 2001,2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.svggen.font.table;
19
20 import java.io.ByteArrayInputStream JavaDoc;
21
22 /**
23  * @version $Id: GlyfCompositeComp.java,v 1.4 2004/08/18 07:15:20 vhardy Exp $
24  * @author <a HREF="mailto:david@steadystate.co.uk">David Schweinsberg</a>
25  */

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 JavaDoc 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         // Get the arguments as just their raw values
60
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         // Assign the arguments according to the flags
69
if ((flags & ARGS_ARE_XY_VALUES) != 0) {
70             xtranslate = argument1;
71             ytranslate = argument2;
72         } else {
73             point1 = argument1;
74             point2 = argument2;
75         }
76
77         // Get the scale values (if any)
78
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     /**
147      * Transforms an x-coordinate of a point for this component.
148      * @param x The x-coordinate of the point to transform
149      * @param y The y-coordinate of the point to transform
150      * @return The transformed x-coordinate
151      */

152     public int scaleX(int x, int y) {
153         return Math.round((float)(x * xscale + y * scale10));
154     }
155
156     /**
157      * Transforms a y-coordinate of a point for this component.
158      * @param x The x-coordinate of the point to transform
159      * @param y The y-coordinate of the point to transform
160      * @return The transformed y-coordinate
161      */

162     public int scaleY(int x, int y) {
163         return Math.round((float)(x * scale01 + y * yscale));
164     }
165 }
166
Popular Tags