KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > faceless > pdf > PDFFont


1 // $Id: PDFFont.java,v 1.2 2003/10/06 12:40:07 mike Exp $
2

3 package org.faceless.pdf;
4
5 import java.util.*;
6
7 /**
8  * <p>
9  * The PDFFont is the abstract superclass for all Fonts in a PDF document.
10  * It defines properties which are common to all fonts, regardless of writing
11  * direction.
12  * </p>
13  * @see PDFSimpleFont
14  * @see StandardFont
15  * @see StandardCJKFont
16  * @version $Revision: 1.2 $
17  */

18 public class PDFFont extends PeeredObject
19 {
20     final org.faceless.pdf2.PDFFont font;
21
22     PDFFont(org.faceless.pdf2.PDFFont font)
23     {
24     this.font=font;
25     }
26
27     Object JavaDoc getPeer()
28     {
29         return font;
30     }
31
32     /**
33      * Return true if the specified Unicode character is defined in the font.
34      */

35     public boolean isDefined(char c)
36     {
37         return font.isDefined(c);
38     }
39
40     /**
41      * Return the width of the specific character in millipoints of this
42      * character in 1 point high text
43      * @since 1.2
44      */

45     public int getCharWidth(char c)
46     {
47         return font.getCharWidth(c);
48     }
49
50     /**
51      * Get the left-most X co-ordinate if this String was rendered in 1
52      * point high text at position (0,0)
53      */

54     public float getLeft(String JavaDoc s)
55     {
56         return font.getLeft(s);
57     }
58
59     /**
60      * Get the right-most X co-ordinate if this String was rendered in 1
61      * point high text at position (0,0)
62      */

63     public float getRight(String JavaDoc s)
64     {
65         return font.getRight(s);
66     }
67
68     /**
69      * Get the top-most Y co-ordinate if this String was rendered in 1
70      * point high text at position (0,0)
71      */

72     public float getTop(String JavaDoc s)
73     {
74         return font.getTop(s);
75     }
76
77     /**
78      * Get the bottom-most Y co-ordinate if this String was rendered in 1
79      * point high text at position (0,0)
80      */

81     public float getBottom(String JavaDoc s)
82     {
83         return font.getBottom(s);
84     }
85
86     /**
87      * Get the Ascender for the font (the maximum height above the baseline the
88      * font extends), as a proportion of the point size.
89      * @since 1.1
90      */

91     public float getAscender()
92     {
93         return font.getAscender();
94     }
95
96     /**
97      * Get the Descender for the font (the maximum height below the baseline the
98      * font extends), as a proportion of the point size. <i>The returned value is
99      * usually negative.</i>
100      * @since 1.1
101      */

102     public float getDescender()
103     {
104         return font.getDescender();
105     }
106
107     /**
108      * <p>
109      * Get the default leading for this font - the preferred distance between
110      * two successive baselines of text. Values are a ratio of the font size, and
111      * are typically between 1 and 1.3
112      * </p><p>
113      * Note that the values of the different spacing-between-lines methods have
114      * changed - in versions 1.0.4 and earlier this routine normally returned 1
115      * and the spacing was set by the {@link PDFStyle#setTextLineSpacing} method.
116      * Since 1.1, the values for these two methods are effectively reversed. See
117      * the relevant method comments in the {@link PDFStyle} class for more
118      * information.
119      * </p>
120      */

121     public float getDefaultLeading()
122     {
123         return font.getDefaultLeading();
124     }
125
126     /**
127      * Get the underline thickness, as a proportion of the font size.
128      * @since 1.1
129      */

130     public float getUnderlineThickness()
131     {
132         return font.getUnderlineThickness();
133     }
134
135     /**
136      * Get the underline position, as a proportion of the font size. Like
137      * the <code>getDescender()</code> method, the returned value is almost
138      * always negative, indicating below the baseline.
139      * @since 1.1
140      */

141     public float getUnderlinePosition()
142     {
143         return font.getUnderlinePosition();
144     }
145
146     /**
147      * Get the strikeout thickness, as a proportion of the font size.
148      * @since 1.1
149      */

150     public float getStrikeoutThickness()
151     {
152         return font.getStrikeoutThickness();
153     }
154
155     /**
156      * Get the strikeout position, as a proportion of the font size.
157      * @since 1.1
158      */

159     public float getStrikeoutPosition()
160     {
161         return font.getStrikeoutPosition();
162     }
163
164     /**
165      * <p>
166      * Get the recommended size of a super/sub script version of this font, as
167      * a proportion of the normal font size. Typical value is around 0.6.
168      * </p><p>
169      * For some fonts (like CJK or barcode fonts) where there is no concept
170      * of super or subscript, this value is entirely arbitrary.
171      * </p>
172      * @since 1.1
173      */

174     public float getSubscriptSize()
175     {
176         return font.getSubscriptSize();
177     }
178
179     /**
180      * <p>
181      * Get the recommended position of a super-script version of this font, as
182      * a proportion of the <i>sub-scripted</i> font size. Value is always positive.
183      * </p><p>
184      * For some fonts (like CJK or barcode fonts) where there is no concept
185      * of super or subscript, this value is entirely arbitrary.
186      * </p>
187      * @since 1.1
188      */

189     public float getSuperscriptPosition()
190     {
191         return font.getSuperscriptPosition();
192     }
193
194     /**
195      * <p>
196      * Get the recommended position of a sub-script version of this font, as
197      * a proportion of the <i>sub-scripted</i> font size. Value is almost always
198      * zero or negative.
199      * </p><p>
200      * For some fonts (like CJK or barcode fonts) where there is no concept
201      * of super or subscript, this value is entirely arbitrary.
202      * </p>
203      * @since 1.1
204      */

205     public float getSubscriptPosition()
206     {
207         return font.getSubscriptPosition();
208     }
209
210     /**
211      * Return true if the specified font is written Left-to-Right or
212      * Right-to-Left.
213      */

214     public boolean isHorizontal()
215     {
216         return font.isHorizontal();
217     }
218
219     /**
220      * Return true if every character has the same width (like Courier),
221      * false if every character is potentially a different width (like
222      * Times-Roman)
223      * @since 1.1.23
224      */

225     public boolean isMonospace()
226     {
227         return font.isMonospace();
228     }
229
230     /**
231      * All fonts can be cloned. The clone is identical but (if the font can
232      * be remapped) it will have the default mapping.
233      */

234     public Object JavaDoc clone()
235     {
236     PDFFont f=null;
237     try {
238         f = (PDFFont)super.clone();
239     } catch (CloneNotSupportedException JavaDoc e) {}
240     return f;
241     }
242
243     /**
244      * Return the Base Font Name for this font.
245      */

246     public final String JavaDoc getBaseName()
247     {
248     return font.getBaseName();
249     }
250
251     /**
252      * Get the horizontal character-to-character (or "pair-wise") kerning in this font
253      * for the specified characters, in millipoints. This is the distance to move the
254      * text cursor left after drawing character c1 in order to correctly position
255      * character c2. For many fonts and combinations of characters, this returns zero.
256      * (Method promoted from {@link PDFSimpleFont} in version 1.1.14)
257      *
258      * @see PDFStyle#setTrackKerning
259      */

260     public int getKerning(char c1, char c2)
261     {
262         return font.getKerning(c1,c2);
263     }
264
265     /**
266      * <p>
267      * Return the specified string with ligatures substituted where appropriate.
268      * Which ligatures are available depends on those that are defined in the font.
269      * The zero-width non-joiner (U+200D) can be used to inhibit ligatures
270      * </p>
271      * <p>
272      * Also replaces all instances of the Unicode Line or Paragraph separators (U+2028 and U+2029)
273      * with a standard newline character
274      * </p>
275      * @since 1.1
276      * @deprecated since 1.2.1 the {@link #ligaturize(char[],int,int,Locale)} method is preferred. This method will be
277      * removed in the near future.
278      */

279     public String JavaDoc ligaturize(String JavaDoc s, Locale locale)
280     {
281     return font.ligaturize(s,locale);
282     }
283
284     /**
285      * Substitute ligatures into the specified string where appropriate.
286      * As for {@link #ligaturize(String, Locale)} but takes a character array
287      * @param buf the buffer to modify
288      * @param off the offset into the buffer for the start of the data
289      * @param len the length of the data in the buffer
290      * @param locale controls which language the buffer is in. Currently not used.
291      * @return the new length of the buffer
292      * @since 1.2.1
293      */

294     public int ligaturize(char[] buf, int off, int len, Locale locale)
295     {
296     return font.ligaturize(buf,off,len,locale);
297     }
298
299     /**
300      * Substitute curly-quotes into the specified buffer where appropriate.
301      * As for {@link PDFPage#requote} but takes a character array.
302      * @param buf the buffer to modify
303      * @param off the offset into the buffer to the start of the data
304      * @param len the length of the data in the buffer
305      * @param locale determines which style of quote is substituted. Recognized languages are english, dutch, italian, spanish, portuguese, catalan, turkish, czech, german, slovak, danish, swedish, norwegian, finnish, polish and hungarian
306      * @return true if quotes were substituted, false otherwise
307      * @since 1.2.1
308      */

309     public boolean requote(char[] buf, int off, int len, Locale locale)
310     {
311     return font.requote(buf,off,len,locale);
312     }
313 }
314
Popular Tags