FontFactory.java

1
/*
2
 * $Id: FontFactory.java 4065 2009-09-16 23:09:11Z psoares33 $
3
 * $Name$
4
 *
5
 * Copyright 2002 by Bruno Lowagie.
6
 *
7
 * The contents of this file are subject to the Mozilla Public License Version 1.1
8
 * (the "License"); you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
10
 *
11
 * Software distributed under the License is distributed on an "AS IS" basis,
12
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
 * for the specific language governing rights and limitations under the License.
14
 *
15
 * The Original Code is 'iText, a free JAVA-PDF library'.
16
 *
17
 * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
18
 * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
19
 * All Rights Reserved.
20
 * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
21
 * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
22
 *
23
 * Contributor(s): all the names of the contributors are added in the source code
24
 * where applicable.
25
 *
26
 * Alternatively, the contents of this file may be used under the terms of the
27
 * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
28
 * provisions of LGPL are applicable instead of those above.  If you wish to
29
 * allow use of your version of this file only under the terms of the LGPL
30
 * License and not to allow others to use your version of this file under
31
 * the MPL, indicate your decision by deleting the provisions above and
32
 * replace them with the notice and other provisions required by the LGPL.
33
 * If you do not delete the provisions above, a recipient may use your version
34
 * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
35
 *
36
 * This library is free software; you can redistribute it and/or modify it
37
 * under the terms of the MPL as stated above or under the terms of the GNU
38
 * Library General Public License as published by the Free Software Foundation;
39
 * either version 2 of the License, or any later version.
40
 *
41
 * This library is distributed in the hope that it will be useful, but WITHOUT
42
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
43
 * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
44
 * details.
45
 *
46
 * If you didn't download this code from the following link, you should check if
47
 * you aren't using an obsolete version:
48
 * http://www.lowagie.com/iText/
49
 */
50
51
package com.lowagie.text;
52
53
import java.awt.Color;
54
import java.util.Properties;
55
import java.util.Set;
56
import com.lowagie.text.error_messages.MessageLocalization;
57
58
import com.lowagie.text.pdf.BaseFont;
59
60
/**
61
 * If you are using True Type fonts, you can declare the paths of the different ttf- and ttc-files
62
 * to this static class first and then create fonts in your code using one of the static getFont-method
63
 * without having to enter a path as parameter.
64
 *
65
 * @author  Bruno Lowagie
66
 */
67
68
public final class FontFactory {
69
    
70
/** This is a possible value of a base 14 type 1 font */
71
    public static final String COURIER = BaseFont.COURIER;
72
    
73
/** This is a possible value of a base 14 type 1 font */
74
    public static final String COURIER_BOLD = BaseFont.COURIER_BOLD;
75
    
76
/** This is a possible value of a base 14 type 1 font */
77
    public static final String COURIER_OBLIQUE = BaseFont.COURIER_OBLIQUE;
78
    
79
/** This is a possible value of a base 14 type 1 font */
80
    public static final String COURIER_BOLDOBLIQUE = BaseFont.COURIER_BOLDOBLIQUE;
81
    
82
/** This is a possible value of a base 14 type 1 font */
83
    public static final String HELVETICA = BaseFont.HELVETICA;
84
    
85
/** This is a possible value of a base 14 type 1 font */
86
    public static final String HELVETICA_BOLD = BaseFont.HELVETICA_BOLD;
87
    
88
/** This is a possible value of a base 14 type 1 font */
89
    public static final String HELVETICA_OBLIQUE = BaseFont.HELVETICA_OBLIQUE;
90
    
91
/** This is a possible value of a base 14 type 1 font */
92
    public static final String HELVETICA_BOLDOBLIQUE = BaseFont.HELVETICA_BOLDOBLIQUE;
93
    
94
/** This is a possible value of a base 14 type 1 font */
95
    public static final String SYMBOL = BaseFont.SYMBOL;
96
    
97
/** This is a possible value of a base 14 type 1 font */
98
    public static final String TIMES = "Times";
99
    
100
/** This is a possible value of a base 14 type 1 font */
101
    public static final String TIMES_ROMAN = BaseFont.TIMES_ROMAN;
102
    
103
/** This is a possible value of a base 14 type 1 font */
104
    public static final String TIMES_BOLD = BaseFont.TIMES_BOLD;
105
    
106
/** This is a possible value of a base 14 type 1 font */
107
    public static final String TIMES_ITALIC = BaseFont.TIMES_ITALIC;
108
    
109
/** This is a possible value of a base 14 type 1 font */
110
    public static final String TIMES_BOLDITALIC = BaseFont.TIMES_BOLDITALIC;
111
    
112
/** This is a possible value of a base 14 type 1 font */
113
    public static final String ZAPFDINGBATS = BaseFont.ZAPFDINGBATS;
114
    
115
    private static FontFactoryImp fontImp = new FontFactoryImp();
116
    
117
/** This is the default encoding to use. */
118
    public static String defaultEncoding = BaseFont.WINANSI;
119
    
120
/** This is the default value of the <VAR>embedded</VAR> variable. */
121
    public static boolean defaultEmbedding = BaseFont.NOT_EMBEDDED;
122
    
123
/** Creates new FontFactory */
124
    private FontFactory() {
125
    }
126
    
127
/**
128
 * Constructs a <CODE>Font</CODE>-object.
129
 *
130
 * @param    fontname    the name of the font
131
 * @param    encoding    the encoding of the font
132
 * @param       embedded    true if the font is to be embedded in the PDF
133
 * @param    size        the size of this font
134
 * @param    style        the style of this font
135
 * @param    color        the <CODE>Color</CODE> of this font.
136
 * @return the Font constructed based on the parameters
137
 */
138
    
139
    public static Font getFont(String fontname, String encoding, boolean embedded, float size, int style, Color color) {
140
        return fontImp.getFont(fontname, encoding, embedded, size, style, color);
141
    }
142
    
143
/**
144
 * Constructs a <CODE>Font</CODE>-object.
145
 *
146
 * @param    fontname    the name of the font
147
 * @param    encoding    the encoding of the font
148
 * @param       embedded    true if the font is to be embedded in the PDF
149
 * @param    size        the size of this font
150
 * @param    style        the style of this font
151
 * @param    color        the <CODE>Color</CODE> of this font.
152
 * @param    cached         true if the font comes from the cache or is added to
153
 *                 the cache if new, false if the font is always created new
154
 * @return the Font constructed based on the parameters
155
 */
156
    
157
    public static Font getFont(String fontname, String encoding, boolean embedded, float size, int style, Color color, boolean cached) {
158
        return fontImp.getFont(fontname, encoding, embedded, size, style, color, cached);
159
    }
160
    
161
/**
162
 * Constructs a <CODE>Font</CODE>-object.
163
 *
164
 * @param   attributes  the attributes of a <CODE>Font</CODE> object.
165
 * @return the Font constructed based on the attributes
166
 */
167
    
168
    public static Font getFont(Properties attributes) {
169
        fontImp.defaultEmbedding = defaultEmbedding;
170
        fontImp.defaultEncoding = defaultEncoding;
171 1 1. getFont : mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return fontImp.getFont(attributes);
172
    }
173
    
174
/**
175
 * Constructs a <CODE>Font</CODE>-object.
176
 *
177
 * @param    fontname    the name of the font
178
 * @param    encoding    the encoding of the font
179
 * @param       embedded    true if the font is to be embedded in the PDF
180
 * @param    size        the size of this font
181
 * @param    style        the style of this font
182
 * @return the Font constructed based on the parameters
183
 */
184
    
185
    public static Font getFont(String fontname, String encoding, boolean embedded, float size, int style) {
186 1 1. getFont : mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return getFont(fontname, encoding, embedded, size, style, null);
187
    }
188
    
189
/**
190
 * Constructs a <CODE>Font</CODE>-object.
191
 *
192
 * @param    fontname    the name of the font
193
 * @param    encoding    the encoding of the font
194
 * @param       embedded    true if the font is to be embedded in the PDF
195
 * @param    size        the size of this font
196
 * @return the Font constructed based on the parameters
197
 */
198
    
199
    public static Font getFont(String fontname, String encoding, boolean embedded, float size) {
200 1 1. getFont : mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return getFont(fontname, encoding, embedded, size, Font.UNDEFINED, null);
201
    }
202
    
203
/**
204
 * Constructs a <CODE>Font</CODE>-object.
205
 *
206
 * @param    fontname    the name of the font
207
 * @param    encoding    the encoding of the font
208
 * @param       embedded    true if the font is to be embedded in the PDF
209
 * @return the Font constructed based on the parameters
210
 */
211
    
212
    public static Font getFont(String fontname, String encoding, boolean embedded) {
213 1 1. getFont : mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return getFont(fontname, encoding, embedded, Font.UNDEFINED, Font.UNDEFINED, null);
214
    }
215
    
216
/**
217
 * Constructs a <CODE>Font</CODE>-object.
218
 *
219
 * @param    fontname    the name of the font
220
 * @param    encoding    the encoding of the font
221
 * @param    size        the size of this font
222
 * @param    style        the style of this font
223
 * @param    color        the <CODE>Color</CODE> of this font.
224
 * @return the Font constructed based on the parameters
225
 */
226
    
227
    public static Font getFont(String fontname, String encoding, float size, int style, Color color) {
228 1 1. getFont : mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return getFont(fontname, encoding, defaultEmbedding, size, style, color);
229
    }
230
    
231
/**
232
 * Constructs a <CODE>Font</CODE>-object.
233
 *
234
 * @param    fontname    the name of the font
235
 * @param    encoding    the encoding of the font
236
 * @param    size        the size of this font
237
 * @param    style        the style of this font
238
 * @return the Font constructed based on the parameters
239
 */
240
    
241
    public static Font getFont(String fontname, String encoding, float size, int style) {
242 1 1. getFont : mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return getFont(fontname, encoding, defaultEmbedding, size, style, null);
243
    }
244
    
245
/**
246
 * Constructs a <CODE>Font</CODE>-object.
247
 *
248
 * @param    fontname    the name of the font
249
 * @param    encoding    the encoding of the font
250
 * @param    size        the size of this font
251
 * @return the Font constructed based on the parameters
252
 */
253
    
254
    public static Font getFont(String fontname, String encoding, float size) {
255 1 1. getFont : mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return getFont(fontname, encoding, defaultEmbedding, size, Font.UNDEFINED, null);
256
    }
257
    
258
/**
259
 * Constructs a <CODE>Font</CODE>-object.
260
 *
261
 * @param    fontname    the name of the font
262
 * @param    encoding    the encoding of the font
263
 * @return the Font constructed based on the parameters
264
 */
265
    
266
    public static Font getFont(String fontname, String encoding) {
267 1 1. getFont : mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return getFont(fontname, encoding, defaultEmbedding, Font.UNDEFINED, Font.UNDEFINED, null);
268
    }
269
    
270
/**
271
 * Constructs a <CODE>Font</CODE>-object.
272
 *
273
 * @param    fontname    the name of the font
274
 * @param    size        the size of this font
275
 * @param    style        the style of this font
276
 * @param    color        the <CODE>Color</CODE> of this font.
277
 * @return the Font constructed based on the parameters
278
 */
279
    
280
    public static Font getFont(String fontname, float size, int style, Color color) {
281 1 1. getFont : mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return getFont(fontname, defaultEncoding, defaultEmbedding, size, style, color);
282
    }
283
    
284
/**
285
 * Constructs a <CODE>Font</CODE>-object.
286
 *
287
 * @param    fontname    the name of the font
288
 * @param    size        the size of this font
289
 * @param    color        the <CODE>Color</CODE> of this font.
290
 * @return the Font constructed based on the parameters
291
 * @since 2.1.0
292
 */
293
    
294
    public static Font getFont(String fontname, float size, Color color) {
295 1 1. getFont : mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return getFont(fontname, defaultEncoding, defaultEmbedding, size, Font.UNDEFINED, color);
296
    }
297
    
298
/**
299
 * Constructs a <CODE>Font</CODE>-object.
300
 *
301
 * @param    fontname    the name of the font
302
 * @param    size        the size of this font
303
 * @param    style        the style of this font
304
 * @return the Font constructed based on the parameters
305
 */
306
    
307
    public static Font getFont(String fontname, float size, int style) {
308 1 1. getFont : mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return getFont(fontname, defaultEncoding, defaultEmbedding, size, style, null);
309
    }
310
    
311
/**
312
 * Constructs a <CODE>Font</CODE>-object.
313
 *
314
 * @param    fontname    the name of the font
315
 * @param    size        the size of this font
316
 * @return the Font constructed based on the parameters
317
 */
318
    
319
    public static Font getFont(String fontname, float size) {
320 1 1. getFont : mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return getFont(fontname, defaultEncoding, defaultEmbedding, size, Font.UNDEFINED, null);
321
    }
322
    
323
/**
324
 * Constructs a <CODE>Font</CODE>-object.
325
 *
326
 * @param    fontname    the name of the font
327
 * @return the Font constructed based on the parameters
328
 */
329
    
330
    public static Font getFont(String fontname) {
331 1 1. getFont : mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return getFont(fontname, defaultEncoding, defaultEmbedding, Font.UNDEFINED, Font.UNDEFINED, null);
332
    }
333
    
334
    /**
335
     * Register a font by giving explicitly the font family and name.
336
     * @param familyName the font family
337
     * @param fullName the font name
338
     * @param path the font path
339
     */
340
    public void registerFamily(String familyName, String fullName, String path) {
341
        fontImp.registerFamily(familyName, fullName, path);
342
    }
343
    
344
/**
345
 * Register a ttf- or a ttc-file.
346
 *
347
 * @param   path    the path to a ttf- or ttc-file
348
 */
349
    
350
    public static void register(String path) {
351 1 1. register : removed call to com/lowagie/text/FontFactory::register → NO_COVERAGE
        register(path, null);
352
    }
353
    
354
/**
355
 * Register a font file and use an alias for the font contained in it.
356
 *
357
 * @param   path    the path to a font file
358
 * @param   alias   the alias you want to use for the font
359
 */
360
    
361
    public static void register(String path, String alias) {
362
        fontImp.register(path, alias);
363
    }
364
365
    /** Register all the fonts in a directory.
366
     * @param dir the directory
367
     * @return the number of fonts registered
368
     */    
369
    public static int registerDirectory(String dir) {
370
        return fontImp.registerDirectory(dir);
371
    }
372
373
    /**
374
     * Register all the fonts in a directory and possibly its subdirectories.
375
     * @param dir the directory
376
     * @param scanSubdirectories recursively scan subdirectories if <code>true</true>
377
     * @return the number of fonts registered
378
     * @since 2.1.2
379
     */
380
    public static int registerDirectory(String dir, boolean scanSubdirectories) {
381
        return fontImp.registerDirectory(dir, scanSubdirectories);
382
    }
383
384
    /** Register fonts in some probable directories. It usually works in Windows,
385
     * Linux and Solaris.
386
     * @return the number of fonts registered
387
     */    
388
    public static int registerDirectories() {
389
        return fontImp.registerDirectories();
390
    }
391
392
/**
393
 * Gets a set of registered fontnames.
394
 * @return a set of registered fonts
395
 */
396
    
397
    public static Set getRegisteredFonts() {
398
        return fontImp.getRegisteredFonts();
399
    }
400
    
401
/**
402
 * Gets a set of registered fontnames.
403
 * @return a set of registered font families
404
 */
405
    
406
    public static Set getRegisteredFamilies() {
407
        return fontImp.getRegisteredFamilies();
408
    }
409
    
410
/**
411
 * Gets a set of registered fontnames.
412
 * @param fontname of a font that may or may not be registered
413
 * @return true if a given font is registered
414
 */
415
    
416
    public static boolean contains(String fontname) {
417
        return fontImp.isRegistered(fontname);
418
    }
419
    
420
/**
421
 * Checks if a certain font is registered.
422
 *
423
 * @param   fontname    the name of the font that has to be checked.
424
 * @return  true if the font is found
425
 */
426
    
427
    public static boolean isRegistered(String fontname) {
428
        return fontImp.isRegistered(fontname);
429
    }
430
    
431
    /**
432
     * Gets the font factory implementation.
433
     * @return the font factory implementation
434
     */    
435
    public static FontFactoryImp getFontImp() {
436
        return fontImp;
437
    }
438
    
439
    /**
440
     * Sets the font factory implementation.
441
     * @param fontImp the font factory implementation
442
     */    
443
    public static void setFontImp(FontFactoryImp fontImp) {
444 1 1. setFontImp : negated conditional → NO_COVERAGE
        if (fontImp == null)
445
            throw new NullPointerException(MessageLocalization.getComposedMessage("fontfactoryimp.cannot.be.null"));
446
        FontFactory.fontImp = fontImp;
447
    }
448
}

Mutations

171

1.1
Location : getFont
Killed by : none
mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

186

1.1
Location : getFont
Killed by : none
mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

200

1.1
Location : getFont
Killed by : none
mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

213

1.1
Location : getFont
Killed by : none
mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

228

1.1
Location : getFont
Killed by : none
mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

242

1.1
Location : getFont
Killed by : none
mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

255

1.1
Location : getFont
Killed by : none
mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

267

1.1
Location : getFont
Killed by : none
mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

281

1.1
Location : getFont
Killed by : none
mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

295

1.1
Location : getFont
Killed by : none
mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

308

1.1
Location : getFont
Killed by : none
mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

320

1.1
Location : getFont
Killed by : none
mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

331

1.1
Location : getFont
Killed by : none
mutated return of Object value for com/lowagie/text/FontFactory::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

351

1.1
Location : register
Killed by : none
removed call to com/lowagie/text/FontFactory::register → NO_COVERAGE

444

1.1
Location : setFontImp
Killed by : none
negated conditional → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.4.2