001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.quercus.lib.pdf;
031:
032: import com.caucho.util.L10N;
033:
034: import java.io.IOException;
035: import java.util.logging.Logger;
036:
037: /**
038: * pdf object oriented API facade
039: */
040: public class PDFFont extends PDFObject {
041: private static final Logger log = Logger.getLogger(PDFFont.class
042: .getName());
043: private static final L10N L = new L10N(PDFFont.class);
044:
045: private int _id;
046:
047: private final Font _face;
048:
049: private final String _encoding;
050: private final String _opt;
051:
052: PDFFont(Font face, String encoding, String opt) {
053: _face = face;
054: _encoding = encoding;
055: _opt = opt;
056: }
057:
058: void setId(int id) {
059: _id = id;
060: }
061:
062: public int getId() {
063: return _id;
064: }
065:
066: public String getFontName() {
067: return _face.getFontName();
068: }
069:
070: public String getFontStyle() {
071: return _face.getWeight();
072: }
073:
074: public double getAscender() {
075: return _face.getAscender();
076: }
077:
078: public double getCapHeight() {
079: return _face.getCapHeight();
080: }
081:
082: public double getDescender() {
083: return _face.getDescender();
084: }
085:
086: public double stringWidth(String text) {
087: return _face.stringWidth(text);
088: }
089:
090: public String getPDFName() {
091: return "F" + _id;
092: }
093:
094: String getResource() {
095: return ("/Font << /F" + _id + " " + _id + " 0 R>>");
096: }
097:
098: public void writeObject(PDFWriter out) throws IOException {
099: out.println("<< /Type /Font");
100: out.println(" /Subtype /Type1");
101: out.println(" /Name /" + _face.getFontName());
102: out.println(" /BaseFont /Helvetica");
103: out.println(" /Encoding /MacRomanEncoding");
104: out.println(">>");
105: }
106:
107: public int hashCode() {
108: int hash = 37;
109:
110: hash = 65521 * hash + _face.hashCode();
111: hash = 65521 * hash + _encoding.hashCode();
112: hash = 65521 * hash + _opt.hashCode();
113:
114: return hash;
115: }
116:
117: public boolean equals(Object o) {
118: if (this == o)
119: return true;
120: else if (!(o instanceof PDFFont))
121: return false;
122:
123: PDFFont font = (PDFFont) o;
124:
125: return (_face == font._face && _encoding.equals(font._encoding) && _opt
126: .equals(font._opt));
127: }
128:
129: public String toString() {
130: return "PDFFont[" + _face.getFontName() + "," + _encoding + ","
131: + _opt + "]";
132: }
133: }
|