Debian Codegraph @

src/main/java/org/jfree/pdf/internal/PDFFont.java

raw
1 /* =====================================================================
2 * JFreePDF : a fast, light-weight PDF library for the Java(tm) platform
3 * =====================================================================
4 *
5 * (C)opyright 2013-2022, by David Gilbert. All rights reserved.
6 *
7 * https://github.com/jfree/orsonpdf
8 *
9 * This program 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 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program 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. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates.
23 * Other names may be trademarks of their respective owners.]
24 *
25 * If you do not wish to be bound by the terms of the GPL, an alternative
26 * runtime license is available to JFree sponsors:
27 *
28 * https://github.com/sponsors/jfree
29 *
30 */
31
32 package org.jfree.pdf.internal;
33
34 import org.jfree.pdf.dictionary.Dictionary;
35
36 /**
37 * A {@link PDFObject} representing a PDF font.
38 */
39 public class PDFFont extends PDFObject {
40
41 /** Identifier for the standard PDF font 'Helvetica'. */
42 public static final String HELVETICA = "Helvetica";
43
44 /** Identifier for the standard PDF font 'Helvetica-Bold'. */
45 public static final String HELVETICA_BOLD = "Helvetica-Bold";
46
47 /** Identifier for the standard PDF font 'Helvetica-Oblique'. */
48 public static final String HELVETICA_OBLIQUE = "Helvetica-Oblique";
49
50 /** Identifier for the standard PDF font 'Helvetica-BoldOblique'. */
51 public static final String HELVETICA_BOLDOBLIQUE = "Helvetica-BoldOblique";
52
53 /** Identifier for the standard PDF font 'Times-Roman'. */
54 public static final String TIMES_ROMAN = "Times-Roman";
55
56 /** Identifier for the standard PDF font 'Times-Bold'. */
57 public static final String TIMES_BOLD = "Times-Bold";
58
59 /** Identifier for the standard PDF font 'Times-Italic'. */
60 public static final String TIMES_ITALIC = "Times-Italic";
61
62 /** Identifier for the standard PDF font 'Times-BoldItalic'. */
63 public static final String TIMES_BOLDITALIC = "Times-BoldItalic";
64
65 /** Identifier for the standard PDF font 'Courier'. */
66 public static final String COURIER = "Courier";
67
68 /** Identifier for the standard PDF font 'Courier-Bold'. */
69 public static final String COURIER_BOLD = "Courier-Bold";
70
71 /** Identifier for the standard PDF font 'Courier-Italic'. */
72 public static final String COURIER_ITALIC = "Courier-Italic";
73
74 /** Identifier for the standard PDF font 'Courier-BoldItalic'. */
75 public static final String COURIER_BOLDITALIC = "Courier-BoldItalic";
76
77 private String name;
78
79 /** The BaseFont (for example, "/Helvetica"). */
80 private String baseFont;
81
82 private String encoding;
83
84 /**
85 * Creates a new {@code PDFFont} instance.
86 *
87 * @param number the PDF object number.
88 * @param generation the PDF object generation number.
89 * @param name the font name within the PDF document.
90 * @param baseFont the base font name.
91 * @param encoding the encoding.
92 */
93 public PDFFont(int number, int generation, String name, String baseFont,
94 String encoding) {
95 super(number, generation);
96 this.name = name;
97 this.baseFont = baseFont;
98 this.encoding = encoding;
99 }
100
101 /**
102 * Returns the name of the font within the PDF document (this is not the
103 * same as the font name).
104 *
105 * @return The font name.
106 */
107 public String getName() {
108 return this.name;
109 }
110
111 /**
112 * Returns the bytes that go between the 'obj' and 'endobj' in the
113 * PDF output for this object.
114 *
115 * @return A byte array.
116 */
117 @Override
118 public byte[] getObjectBytes() {
119 return createDictionary().toPDFBytes();
120 }
121
122 private Dictionary createDictionary() {
123 Dictionary dictionary = new Dictionary("/Font");
124 dictionary.put("/Subtype", "/Type1");
125 dictionary.put("/Name", this.name);
126 dictionary.put("/BaseFont", this.baseFont);
127 dictionary.put("/Encoding", this.encoding);
128 return dictionary;
129 }
130
131 }