52
52
/**
53
53
* Thin wrapper for the iText PDF library that handles writing PDF files. The
54
54
* majority of the work in this library is done by
55
- * <a href="http://www.lowagie.com/iText/">iText</a>.
56
- * This is currently using iText 2.1.7.
57
- * The issue is that versions from the 5.x series were slow to handle lots of
58
- * fonts with the DefaultFontMapper. 2.x seemed a little slower than 1.x, but
59
- * 5.x took up to 10 times the time to load, meaning a lag of several seconds
60
- * when starting sketches on a machine that had a good handful of fonts
61
- * installed. (Like, say, anyone in our target audience. Or me.)
55
+ * <a href="https://github.com/itext/itextpdf">itextpdf</a>. This is currently using
56
+ * itextpdf-5.5.13.2.
62
57
*/
63
58
public class PGraphicsPDF extends PGraphicsJava2D {
64
59
@@ -81,10 +76,6 @@ public class PGraphicsPDF extends PGraphicsJava2D {
81
76
static protected DefaultFontMapper mapper ;
82
77
static protected String [] fontList ;
83
78
84
- /**
85
- *
86
- * @param path
87
- */
88
79
@ Override
89
80
public void setPath (String path ) {
90
81
this .path = path ;
@@ -167,12 +158,10 @@ public void beginDraw() {
167
158
static protected DefaultFontMapper getMapper () {
168
159
if (mapper == null ) {
169
160
mapper = new DefaultFontMapper ();
170
- if (PApplet .platform == PConstants .LINUX ) {
171
- checkDir ("/usr/share/fonts/" , mapper );
172
- checkDir ("/usr/local/share/fonts/" , mapper );
173
- checkDir (System .getProperty ("user.home" ) + "/.fonts" , mapper );
161
+ checkDir ("/usr/share/fonts/" , mapper );
162
+ checkDir ("/usr/local/share/fonts/" , mapper );
163
+ checkDir (System .getProperty ("user.home" ) + "/.fonts" , mapper );
174
164
}
175
- }
176
165
return mapper ;
177
166
}
178
167
@@ -186,8 +175,10 @@ static protected void checkDir(String path, DefaultFontMapper mapper) {
186
175
187
176
/**
188
177
* Recursive walk to get all subdirectories for font fun.Patch submitted by
189
- Matthias Breuer.(<a href="http://dev.processing.org/bugs/show_bug.cgi?id=1566">Bug
190
- 1566</a>)
178
+ * Matthias
179
+ * Breuer.(<a href="http://dev.processing.org/bugs/show_bug.cgi?id=1566">Bug
180
+ * 1566</a>)
181
+ *
191
182
* @param folder
192
183
* @param mapper
193
184
*/
@@ -258,45 +249,6 @@ public boolean displayable() {
258
249
return false ;
259
250
}
260
251
261
- /*
262
- protected void finalize() throws Throwable {
263
- System.out.println("calling finalize");
264
- //document.close(); // do this in dispose instead?
265
- }
266
- */
267
- //////////////////////////////////////////////////////////////
268
- /*
269
- public void endRecord() {
270
- super.endRecord();
271
- dispose();
272
- }
273
-
274
-
275
- public void endRaw() {
276
- System.out.println("ending raw");
277
- super.endRaw();
278
- System.out.println("disposing");
279
- dispose();
280
- System.out.println("done");
281
- }
282
- */
283
- //////////////////////////////////////////////////////////////
284
- /*
285
- protected void rectImpl(float x1, float y1, float x2, float y2) {
286
- //rect.setFrame(x1, y1, x2-x1, y2-y1);
287
- //draw_shape(rect);
288
- System.out.println("rect implements");
289
- g2.fillRect((int)x1, (int)y1, (int) (x2-x1), (int) (y2-y1));
290
- }
291
- *
292
-
293
- /*
294
- public void clear() {
295
- g2.setColor(Color.red);
296
- g2.fillRect(0, 0, width, height);
297
- }
298
- */
299
- //////////////////////////////////////////////////////////////
300
252
@ Override
301
253
protected void imageImpl (PImage image ,
302
254
float x1 , float y1 , float x2 , float y2 ,
@@ -321,49 +273,36 @@ protected void imageImpl(PImage image,
321
273
public void textFont (PFont which ) {
322
274
super .textFont (which );
323
275
checkFont ();
324
- // Make sure a native version of the font is available.
325
- // if (textFont.getFont() == null) {
326
- // throw new RuntimeException("Use createFont() instead of loadFont() " +
327
- // "when drawing text using the PDF library.");
328
- // }
329
- // Make sure that this is a font that the PDF library can deal with.
330
- // if ((textMode != SHAPE) && !checkFont(which.getName())) {
331
- // System.err.println("Use PGraphicsPDF.listFonts() to get a list of available fonts.");
332
- // throw new RuntimeException("The font “" + which.getName() + "” cannot be used with PDF Export.");
333
- // }
334
276
}
335
277
336
278
/**
337
- * Change the textMode() to either SHAPE or MODEL.
338
- * This resets all renderer settings, and therefore must be called
279
+ * Change the textMode() to either SHAPE or MODEL. This resets all renderer
280
+ * settings, and therefore must be called
339
281
* <EM>before</EM> any other commands that set the fill() or the textFont()
340
282
* or anything. Unlike other renderers, use textMode() directly after the
341
283
* size() command.
342
284
*/
343
- @ Override
344
- public void textMode (int mode ) {
345
- if (textMode != mode ) {
346
- switch (mode ) {
347
- case SHAPE :
348
- textMode = SHAPE ;
349
- g2 .dispose ();
350
- // g2 = content.createGraphicsShapes(width, height);
351
- g2 = createGraphics ();
352
- break ;
353
- case MODEL :
354
- textMode = MODEL ;
355
- g2 .dispose ();
356
- // g2 = content.createGraphics(width, height, mapper);
357
- g2 = createGraphics ();
358
- // g2 = template.createGraphics(width, height, mapper);
359
- break ;
360
- case SCREEN :
361
- throw new RuntimeException ("textMode(SCREEN) not supported with PDF" );
362
- default :
363
- throw new RuntimeException ("That textMode() does not exist" );
364
- }
365
- }
366
- }
285
+ @ Override
286
+ public void textMode (int mode ) {
287
+ if (textMode != mode ) {
288
+ switch (mode ) {
289
+ case SHAPE :
290
+ textMode = SHAPE ;
291
+ g2 .dispose ();
292
+ g2 = createGraphics ();
293
+ break ;
294
+ case MODEL :
295
+ textMode = MODEL ;
296
+ g2 .dispose ();
297
+ g2 = createGraphics ();
298
+ break ;
299
+ case SCREEN :
300
+ throw new RuntimeException ("textMode(SCREEN) not supported with PDF" );
301
+ default :
302
+ throw new RuntimeException ("That textMode() does not exist" );
303
+ }
304
+ }
305
+ }
367
306
368
307
@ Override
369
308
protected void textLineImpl (char buffer [], int start , int stop ,
@@ -418,7 +357,6 @@ public void set(int x, int y, PImage image) {
418
357
}
419
358
420
359
//
421
-
422
360
/**
423
361
*
424
362
* @param alpha
@@ -516,6 +454,7 @@ public boolean save(String filename) {
516
454
* On Linux or any other platform, you'll need to add the directories by
517
455
* hand. (If there are actual standards here that we can use as a starting
518
456
* point, please file a bug to make a note of it)
457
+ *
519
458
* @param directory
520
459
*/
521
460
public void addFonts (String directory ) {
@@ -555,7 +494,8 @@ protected void checkFont() {
555
494
556
495
/**
557
496
* List the fonts known to the PDF renderer.This is like PFont.list(),
558
- however not all those fonts are available by default.
497
+ * however not all those fonts are available by default.
498
+ *
559
499
* @return
560
500
*/
561
501
static public String [] listFonts () {
0 commit comments