1 18 package org.apache.batik.svggen.font; 19 20 import org.apache.batik.svggen.font.table.GlyfDescript; 21 import org.apache.batik.svggen.font.table.GlyphDescription; 22 23 28 public class Glyph { 29 30 protected short leftSideBearing; 31 protected int advanceWidth; 32 private Point[] points; 33 34 public Glyph(GlyphDescription gd, short lsb, int advance) { 35 leftSideBearing = lsb; 36 advanceWidth = advance; 37 describe(gd); 38 } 39 40 public int getAdvanceWidth() { 41 return advanceWidth; 42 } 43 44 public short getLeftSideBearing() { 45 return leftSideBearing; 46 } 47 48 public Point getPoint(int i) { 49 return points[i]; 50 } 51 52 public int getPointCount() { 53 return points.length; 54 } 55 56 59 public void reset() { 60 } 61 62 65 public void scale(int factor) { 66 for (int i = 0; i < points.length; i++) { 67 points[i].x = ((points[i].x<<10) * factor) >> 26; 70 points[i].y = ((points[i].y<<10) * factor) >> 26; 71 } 72 leftSideBearing = (short)(( leftSideBearing * factor) >> 6); 73 advanceWidth = (advanceWidth * factor) >> 6; 74 } 75 76 79 private void describe(GlyphDescription gd) { 80 int endPtIndex = 0; 81 points = new Point[gd.getPointCount() + 2]; 82 for (int i = 0; i < gd.getPointCount(); i++) { 83 boolean endPt = gd.getEndPtOfContours(endPtIndex) == i; 84 if (endPt) { 85 endPtIndex++; 86 } 87 points[i] = new Point( 88 gd.getXCoordinate(i), 89 gd.getYCoordinate(i), 90 (gd.getFlags(i) & GlyfDescript.onCurve) != 0, 91 endPt); 92 } 93 94 points[gd.getPointCount()] = new Point(0, 0, true, true); 96 points[gd.getPointCount()+1] = new Point(advanceWidth, 0, true, true); 97 } 98 } 99 | Popular Tags |