5252/**
5353 * Thin wrapper for the iText PDF library that handles writing PDF files. The
5454 * 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.
6257 */
6358public class PGraphicsPDF extends PGraphicsJava2D {
6459
@@ -81,10 +76,6 @@ public class PGraphicsPDF extends PGraphicsJava2D {
8176 static protected DefaultFontMapper mapper ;
8277 static protected String [] fontList ;
8378
84- /**
85- *
86- * @param path
87- */
8879 @ Override
8980 public void setPath (String path ) {
9081 this .path = path ;
@@ -167,12 +158,10 @@ public void beginDraw() {
167158 static protected DefaultFontMapper getMapper () {
168159 if (mapper == null ) {
169160 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 );
174164 }
175- }
176165 return mapper ;
177166 }
178167
@@ -186,8 +175,10 @@ static protected void checkDir(String path, DefaultFontMapper mapper) {
186175
187176 /**
188177 * 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+ *
191182 * @param folder
192183 * @param mapper
193184 */
@@ -258,45 +249,6 @@ public boolean displayable() {
258249 return false ;
259250 }
260251
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- //////////////////////////////////////////////////////////////
300252 @ Override
301253 protected void imageImpl (PImage image ,
302254 float x1 , float y1 , float x2 , float y2 ,
@@ -321,49 +273,36 @@ protected void imageImpl(PImage image,
321273 public void textFont (PFont which ) {
322274 super .textFont (which );
323275 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- // }
334276 }
335277
336278 /**
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
339281 * <EM>before</EM> any other commands that set the fill() or the textFont()
340282 * or anything. Unlike other renderers, use textMode() directly after the
341283 * size() command.
342284 */
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+ }
367306
368307 @ Override
369308 protected void textLineImpl (char buffer [], int start , int stop ,
@@ -418,7 +357,6 @@ public void set(int x, int y, PImage image) {
418357 }
419358
420359 //
421-
422360 /**
423361 *
424362 * @param alpha
@@ -516,6 +454,7 @@ public boolean save(String filename) {
516454 * On Linux or any other platform, you'll need to add the directories by
517455 * hand. (If there are actual standards here that we can use as a starting
518456 * point, please file a bug to make a note of it)
457+ *
519458 * @param directory
520459 */
521460 public void addFonts (String directory ) {
@@ -555,7 +494,8 @@ protected void checkFont() {
555494
556495 /**
557496 * 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+ *
559499 * @return
560500 */
561501 static public String [] listFonts () {
0 commit comments