KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > quercus > lib > pdf > PDFFont


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.quercus.lib.pdf;
31
32 import com.caucho.util.L10N;
33
34 import java.io.IOException JavaDoc;
35 import java.util.logging.Logger JavaDoc;
36
37 /**
38  * pdf object oriented API facade
39  */

40 public class PDFFont extends PDFObject {
41   private static final Logger JavaDoc log
42     = Logger.getLogger(PDFFont.class.getName());
43   private static final L10N L = new L10N(PDFFont.class);
44
45   private int _id;
46
47   private final Font _face;
48
49   private final String JavaDoc _encoding;
50   private final String JavaDoc _opt;
51
52   PDFFont(Font face, String JavaDoc encoding, String JavaDoc opt)
53   {
54     _face = face;
55     _encoding = encoding;
56     _opt = opt;
57   }
58
59   void setId(int id)
60   {
61     _id = id;
62   }
63
64   public int getId()
65   {
66     return _id;
67   }
68
69   public String JavaDoc getFontName()
70   {
71     return _face.getFontName();
72   }
73
74   public String JavaDoc getFontStyle()
75   {
76     return _face.getWeight();
77   }
78
79   public double getAscender()
80   {
81     return _face.getAscender();
82   }
83
84   public double getCapHeight()
85   {
86     return _face.getCapHeight();
87   }
88
89   public double getDescender()
90   {
91     return _face.getDescender();
92   }
93
94   public double stringWidth(String JavaDoc text)
95   {
96     return _face.stringWidth(text);
97   }
98
99   public String JavaDoc getPDFName()
100   {
101     return "F" + _id;
102   }
103
104   String JavaDoc getResource()
105   {
106     return("/Font << /F" + _id + " " + _id + " 0 R>>");
107   }
108
109   public void writeObject(PDFWriter out)
110     throws IOException JavaDoc
111   {
112     out.println("<< /Type /Font");
113     out.println(" /Subtype /Type1");
114     out.println(" /Name /" + _face.getFontName());
115     out.println(" /BaseFont /Helvetica");
116     out.println(" /Encoding /MacRomanEncoding");
117     out.println(">>");
118   }
119
120   public int hashCode()
121   {
122     int hash = 37;
123
124     hash = 65521 * hash + _face.hashCode();
125     hash = 65521 * hash + _encoding.hashCode();
126     hash = 65521 * hash + _opt.hashCode();
127
128     return hash;
129   }
130
131   public boolean equals(Object JavaDoc o)
132   {
133     if (this == o)
134       return true;
135     else if (! (o instanceof PDFFont))
136       return false;
137
138     PDFFont font = (PDFFont) o;
139
140     return (_face == font._face &&
141             _encoding.equals(font._encoding) &&
142             _opt.equals(font._opt));
143   }
144
145   public String JavaDoc toString()
146   {
147     return "PDFFont[" + _face.getFontName() + "," + _encoding + "," + _opt + "]";
148   }
149 }
150
Popular Tags