001: /*
002: * $Id: PDFGlyph.java,v 1.2 2007/12/20 18:33:32 rbair Exp $
003: *
004: * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
005: * Santa Clara, California 95054, U.S.A. All rights reserved.
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
020: */
021:
022: package com.sun.pdfview.font;
023:
024: import java.awt.geom.AffineTransform;
025: import java.awt.geom.GeneralPath;
026: import java.awt.geom.Point2D;
027:
028: import com.sun.pdfview.PDFPage;
029: import com.sun.pdfview.PDFShapeCmd;
030:
031: /**
032: * A single glyph in a stream of PDF text, which knows how to write itself
033: * onto a PDF command stream
034: */
035: public class PDFGlyph {
036: /** the character code of this glyph */
037: private char src;
038:
039: /** the name of this glyph */
040: private String name;
041:
042: /** the advance from this glyph */
043: private Point2D advance;
044:
045: /** the shape represented by this glyph (for all fonts but type 3) */
046: private GeneralPath shape;
047:
048: /** the PDFPage storing this glyph's commands (for type 3 fonts) */
049: private PDFPage page;
050:
051: /** Creates a new instance of PDFGlyph based on a shape */
052: public PDFGlyph(char src, String name, GeneralPath shape,
053: Point2D.Float advance) {
054: this .shape = shape;
055: this .advance = advance;
056: this .src = src;
057: this .name = name;
058: }
059:
060: /** Creates a new instance of PDFGlyph based on a page */
061: public PDFGlyph(char src, String name, PDFPage page, Point2D advance) {
062: this .page = page;
063: this .advance = advance;
064: this .src = src;
065: this .name = name;
066: }
067:
068: /** Get the character code of this glyph */
069: public char getChar() {
070: return src;
071: }
072:
073: /** Get the name of this glyph */
074: public String getName() {
075: return name;
076: }
077:
078: /** Get the shape of this glyph */
079: public GeneralPath getShape() {
080: return shape;
081: }
082:
083: /** Get the PDFPage for a type3 font glyph */
084: public PDFPage getPage() {
085: return page;
086: }
087:
088: /** Add commands for this glyph to a page */
089: public Point2D addCommands(PDFPage cmds, AffineTransform transform,
090: int mode) {
091: if (shape != null) {
092: GeneralPath outline = (GeneralPath) shape
093: .createTransformedShape(transform);
094: cmds.addCommand(new PDFShapeCmd(outline, mode));
095: } else if (page != null) {
096: cmds.addCommands(page, transform);
097: }
098:
099: return advance;
100: }
101:
102: }
|