KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > gvt > font > GVTLineMetrics


1 /*
2
3    Copyright 2001-2002 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.gvt.font;
19
20 import java.awt.font.LineMetrics JavaDoc;
21
22 /**
23  * GVTLineMetrics is a GVT version of java.awt.font.LineMetrics.
24  *
25  * @author <a HREF="mailto:bella.robinson@cmis.csiro.au">Bella Robinson</a>
26  * @version $Id: GVTLineMetrics.java,v 1.7 2004/08/18 07:14:35 vhardy Exp $
27  */

28 public class GVTLineMetrics {
29
30     protected float ascent;
31     protected int baselineIndex;
32     protected float[] baselineOffsets;
33     protected float descent;
34     protected float height;
35     protected float leading;
36     protected int numChars;
37     protected float strikethroughOffset;
38     protected float strikethroughThickness;
39     protected float underlineOffset;
40     protected float underlineThickness;
41     protected float overlineOffset;
42     protected float overlineThickness;
43
44     /**
45      * Constructs a GVTLineMetrics object based on the specified line metrics.
46      *
47      * @param lineMetrics The lineMetrics object that this metrics object will
48      * be based upon.
49      */

50     public GVTLineMetrics(LineMetrics JavaDoc lineMetrics) {
51         this.ascent = lineMetrics.getAscent();
52         this.baselineIndex = lineMetrics.getBaselineIndex();
53         this.baselineOffsets = lineMetrics.getBaselineOffsets();
54         this.descent = lineMetrics.getDescent();
55         this.height = lineMetrics.getHeight();
56         this.leading = lineMetrics.getLeading();
57         this.numChars = lineMetrics.getNumChars();
58         this.strikethroughOffset = lineMetrics.getStrikethroughOffset();
59         this.strikethroughThickness = lineMetrics.getStrikethroughThickness();
60         this.underlineOffset = lineMetrics.getUnderlineOffset();
61         this.underlineThickness = lineMetrics.getUnderlineThickness();
62         this.overlineOffset = -this.ascent;
63         this.overlineThickness = this.underlineThickness;
64     }
65
66
67     /**
68      * Constructs a GVTLineMetrics object based on the specified line metrics
69      * with a scale factor applied.
70      *
71      * @param lineMetrics The lineMetrics object that this metrics object will
72      * be based upon.
73      * @param scaleFactor The scale factor to apply to all metrics.
74      */

75     public GVTLineMetrics(LineMetrics JavaDoc lineMetrics, float scaleFactor) {
76         this.ascent = lineMetrics.getAscent() * scaleFactor;
77         this.baselineIndex = lineMetrics.getBaselineIndex();
78         this.baselineOffsets = lineMetrics.getBaselineOffsets();
79         for (int i=0; i<baselineOffsets.length; i++) {
80             this.baselineOffsets[i] *= scaleFactor;
81         }
82         this.descent = lineMetrics.getDescent() * scaleFactor;
83         this.height = lineMetrics.getHeight() * scaleFactor;
84         this.leading = lineMetrics.getLeading();
85         this.numChars = lineMetrics.getNumChars();
86         this.strikethroughOffset =
87         lineMetrics.getStrikethroughOffset() * scaleFactor;
88         this.strikethroughThickness =
89         lineMetrics.getStrikethroughThickness() * scaleFactor;
90         this.underlineOffset = lineMetrics.getUnderlineOffset() * scaleFactor;
91         this.underlineThickness =
92         lineMetrics.getUnderlineThickness() * scaleFactor;
93         this.overlineOffset = -this.ascent;
94         this.overlineThickness = this.underlineThickness;
95     }
96
97
98     /**
99      * Constructs a GVTLineMetrics object with the specified attributes.
100      */

101     public GVTLineMetrics(float ascent,
102               int baselineIndex,
103               float[] baselineOffsets,
104                           float descent,
105               float height,
106               float leading, int numChars,
107                           float strikethroughOffset,
108               float strikethroughThickness,
109                           float underlineOffset,
110               float underlineThickness,
111                           float overlineOffset,
112               float overlineThickness) {
113
114         this.ascent = ascent;
115         this.baselineIndex = baselineIndex;
116         this.baselineOffsets = baselineOffsets;
117         this.descent = descent;
118         this.height = height;
119         this.leading = leading;
120         this.numChars = numChars;
121         this.strikethroughOffset = strikethroughOffset;
122         this.strikethroughThickness = strikethroughThickness;
123         this.underlineOffset = underlineOffset;
124         this.underlineThickness = underlineThickness;
125         this.overlineOffset = overlineOffset;
126         this.overlineThickness = overlineThickness;
127     }
128
129     /**
130      * Returns the ascent of the text.
131      */

132     public float getAscent() {
133         return ascent;
134     }
135
136     /**
137      * Returns the baseline index of the text.
138      */

139     public int getBaselineIndex() {
140         return baselineIndex;
141     }
142
143     /**
144      * Returns the baseline offsets of the text, relative to the baseline of
145      * the text.
146      */

147     public float[] getBaselineOffsets() {
148         return baselineOffsets;
149     }
150
151     /**
152      * Returns the descent of the text.
153      */

154     public float getDescent() {
155         return descent;
156     }
157
158     /**
159      * Returns the height of the text.
160      */

161     public float getHeight() {
162         return height;
163     }
164
165     /**
166      * Returns the leading of the text.
167      */

168     public float getLeading() {
169         return leading;
170     }
171
172     /**
173      * Returns the number of characters in the text whose metrics are
174      * encapsulated by this LineMetrics object.
175      */

176     public int getNumChars() {
177         return numChars;
178     }
179
180     /**
181      * Returns the position of the strike-through line relative to the baseline.
182      */

183     public float getStrikethroughOffset() {
184         return strikethroughOffset;
185     }
186
187     /**
188      * Returns the thickness of the strike-through line.
189      */

190     public float getStrikethroughThickness() {
191         return strikethroughThickness;
192     }
193
194     /**
195      * Returns the position of the underline relative to the baseline.
196      */

197     public float getUnderlineOffset() {
198         return underlineOffset;
199     }
200
201     /**
202      * Returns the thickness of the underline.
203      */

204     public float getUnderlineThickness() {
205         return underlineThickness;
206     }
207
208     /**
209      * Returns the position of the overline relative to the baseline.
210      */

211     public float getOverlineOffset() {
212         return overlineOffset;
213     }
214
215     /**
216      * Returns the thickness of the overline.
217      */

218     public float getOverlineThickness() {
219         return overlineThickness;
220     }
221
222 }
223
Popular Tags