KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > media > TTFGlyph


1 /******************************************************************************
2  * TTFGlyph.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.media;
11
12 import org.apache.batik.svggen.font.table.GlyphDescription;
13 import org.apache.batik.svggen.font.table.GlyfDescript;
14 import org.apache.batik.svggen.font.Point;
15
16 // Logger
17
import org.apache.log4j.*;
18
19 /**
20  * TrueType Glyph utility class
21  */

22 public class TTFGlyph {
23
24     private Point[] points;
25
26     /**
27      * Constructs a TTFGlyph from a GlyfDescription
28      * @param gd a glyph description
29      */

30     public TTFGlyph(GlyphDescription gd) {
31         int endPtIndex = 0;
32         points = new Point[gd.getPointCount()];
33         for (int i = 0; i < gd.getPointCount(); i++) {
34             boolean endPt = gd.getEndPtOfContours(endPtIndex) == i;
35             if (endPt) {
36                 endPtIndex++;
37             }
38             points[i] = new Point(
39                     gd.getXCoordinate(i),
40                     gd.getYCoordinate(i),
41                     (gd.getFlags(i) & GlyfDescript.onCurve) != 0,
42                     endPt);
43         }
44     }
45
46     /**
47      * @return the requested point from the glyph
48      */

49     public Point getPoint(int i) {
50         return points[i];
51     }
52
53     /**
54      * @return the number of points in the glyph
55      */

56     public int getNumPoints() {
57         return points.length;
58     }
59
60     /**
61      * Dump the glyph to the given logger's debug output
62      * @param logger
63      */

64     public void dump(Logger logger) {
65         for (int i = 0; i < points.length; i++) {
66             logger.debug( "Point x " + points[i].x +
67                            " y " + points[i].y +
68                            " " + points[i].onCurve +
69                            " " + points[i].endOfContour);
70         }
71     }
72
73     /**
74      * Scale the glyph and negate the Y axis.
75      * @param factor scale factor
76      */

77     public void scale(double factor) {
78         for (int i = 0; i < points.length; i++) {
79             points[i].x *= factor;
80             points[i].y *= -factor;
81         }
82     }
83 }
84
Popular Tags