KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Copyright 2001 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
21 /**
22  * The KerningTable class holds a kerning table (a collection of Kern
23  * elements). It provides a more convenient method of looking up kerning values
24  * when laying out glyphs.
25  *
26  * @author <a HREF="mailto:dean.jackson@cmis.csiro.au">Dean Jackson</a>
27  * @version $Id: KerningTable.java,v 1.6 2004/09/01 09:35:23 deweese Exp $
28  */

29 public class KerningTable {
30
31     private Kern[] entries;
32
33     /**
34      * Creates a KerningTable from an array of Kern entries.
35      *
36      * @param entries The array of Kern objects that represent the kerning
37      * entries for the font that this kerning table belongs to.
38      */

39     public KerningTable(Kern[] entries) {
40         this.entries = entries;
41     }
42
43     /**
44      * Returns the amount of kerning that should be added between the given
45      * glyphs. Returns 0 if the glyphs should not be kerned.
46      *
47      * @param glyphCode1 The id of the first glyph in the kerning pair
48      * @param glyphCode2 The id of the second glyph in the kerning pair
49      * @param glyphUnicode1 The unicode value of the first glyph in
50      * the kerning pair
51      * @param glyphUnicode2 The unicode vlaue of the second glyph in
52      * the kerning pair
53      * @return The amount of kerning to be added when laying out the glyphs
54      */

55     public float getKerningValue(int glyphCode1,
56                  int glyphCode2,
57                                  String JavaDoc glyphUnicode1,
58                  String JavaDoc glyphUnicode2) {
59         for (int i = 0; i < entries.length; i++) {
60             if (entries[i].matchesFirstGlyph(glyphCode1, glyphUnicode1) &&
61                 entries[i].matchesSecondGlyph(glyphCode2, glyphUnicode2)) {
62                 return entries[i].getAdjustValue();
63             }
64         }
65         return 0f;
66     }
67 }
68
Popular Tags