KickJava   Java API By Example, From Geeks To Geeks.

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


1 // $Id: TrueTypeFont.java,v 1.5 2003/11/04 17:16:01 mike Exp $
2

3 package org.faceless.pdf;
4
5 import java.util.*;
6 import java.io.*;
7
8 /**
9  * <p>
10  * A concrete subclass of <code>PDFSimpleFont</code> representing a
11  * <code>TrueType</code> font.
12  * </p>
13  * <p>
14  * TrueType fonts are the standard font used by both Microsoft Windows
15  * and Apple's MacOS. They can be used and embedded in PDF documents, and
16  * the full range of Unicode characters used. This class can handle both
17  * Macintosh and Windows varients.
18  * </p>
19  * @see PDFEncoding
20  * @see Type1Font
21  * @version $Revision: 1.5 $
22  */

23 public class TrueTypeFont extends PDFSimpleFont
24 {
25     /**
26      * Create a new TrueType font from the specified InputStream. The
27      * <code>embed</code> flag controls whether the font is embedded
28      * or not. Some fonts have restrictions on embedding - these can
29      * still be embedded but a warning is printed to <code>System.err</code>.
30      * <i>Since 1.1, if this constructor is used and the font is embedded,
31      * the font is subset by default.</i>
32      *
33      * @param file the TrueType font file
34      * @param embed whether to embed the font in the PDF document or not.
35      * @throws IOException if the font file can't be fully read or parsed
36      * @throws IllegalArgumentException if the font file contains invalid data
37      */

38     public TrueTypeFont(InputStream file, boolean embed)
39         throws IOException, IllegalArgumentException JavaDoc
40     {
41     super(new org.faceless.pdf2.OpenTypeFont(file, embed ? 2 : 1));
42     ((org.faceless.pdf2.OpenTypeFont)font).setEmbed(embed);
43     }
44
45     /**
46      * <p>
47      * Create a new TrueType font from the specified InputStream. The
48      * <code>embed</code> flag controls whether the font is embedded
49      * or not. Some fonts have restrictions on embedding - these can
50      * still be embedded but a warning is printed to <code>System.err</code>.
51      * </p>
52      * <p>
53      * Since 1.1, the library has the ability to <b>subset</b> embedded
54      * TrueType fonts. This can result in a smaller file, but may be a
55      * time-consuming process. Font subsets contain only the characters
56      * that are actually used in the document, which can result in large
57      * space savings when the font has many glyphs that aren't used. On
58      * the other hand the font may wind up missing common characters,
59      * making it useless outside the context of the PDF it's embededded
60      * in (which may be an advantage in some situations).
61      * </p>
62      *
63      * @param file the TrueType font file
64      * @param embed whether to embed the font in the PDF document
65      * @param subset whether to subset the font (only if the font is embedded)
66      * @throws IOException if the font file can't be fully read or parsed
67      * @throws IllegalArgumentException if the font file contains invalid data
68      * @since 1.1
69      */

70     public TrueTypeFont(InputStream file, boolean embed, boolean subset)
71         throws IOException, IllegalArgumentException JavaDoc
72     {
73     super(new org.faceless.pdf2.OpenTypeFont(file, embed ? 2 : 1));
74     ((org.faceless.pdf2.OpenTypeFont)font).setEmbed(embed);
75     ((org.faceless.pdf2.OpenTypeFont)font).setSubset(subset);
76     }
77 }
78
Popular Tags