01: /******************************************************************************
02: * TTFGlyph.java
03: * ****************************************************************************/package org.openlaszlo.media;
04:
05: import org.apache.batik.svggen.font.table.GlyphDescription;
06: import org.apache.batik.svggen.font.table.GlyfDescript;
07: import org.apache.batik.svggen.font.Point;
08:
09: // Logger
10: import org.apache.log4j.*;
11:
12: /**
13: * TrueType Glyph utility class
14: */
15: public class TTFGlyph {
16:
17: private Point[] points;
18:
19: /**
20: * Constructs a TTFGlyph from a GlyfDescription
21: * @param gd a glyph description
22: */
23: public TTFGlyph(GlyphDescription gd) {
24: int endPtIndex = 0;
25: points = new Point[gd.getPointCount()];
26: for (int i = 0; i < gd.getPointCount(); i++) {
27: boolean endPt = gd.getEndPtOfContours(endPtIndex) == i;
28: if (endPt) {
29: endPtIndex++;
30: }
31: points[i] = new Point(gd.getXCoordinate(i), gd
32: .getYCoordinate(i),
33: (gd.getFlags(i) & GlyfDescript.onCurve) != 0, endPt);
34: }
35: }
36:
37: /**
38: * @return the requested point from the glyph
39: */
40: public Point getPoint(int i) {
41: return points[i];
42: }
43:
44: /**
45: * @return the number of points in the glyph
46: */
47: public int getNumPoints() {
48: return points.length;
49: }
50:
51: /**
52: * Dump the glyph to the given logger's debug output
53: * @param logger
54: */
55: public void dump(Logger logger) {
56: for (int i = 0; i < points.length; i++) {
57: logger.debug("Point x " + points[i].x + " y " + points[i].y
58: + " " + points[i].onCurve + " "
59: + points[i].endOfContour);
60: }
61: }
62:
63: /**
64: * Scale the glyph and negate the Y axis.
65: * @param factor scale factor
66: */
67: public void scale(double factor) {
68: for (int i = 0; i < points.length; i++) {
69: points[i].x *= factor;
70: points[i].y *= -factor;
71: }
72: }
73: }
|