11/*
22 Part of the Processing project - http://processing.org
33
4- Copyright (c) 2005-10 Ben Fry and Casey Reas
4+ Copyright (c) 2005-11 Ben Fry and Casey Reas
55
66 This library is free software; you can redistribute it and/or
77 modify it under the terms of the GNU Lesser General Public
2121package processing .pdf ;
2222
2323import java .awt .Font ;
24+ import java .awt .Graphics2D ;
2425import java .io .*;
2526import java .util .*;
2627
@@ -100,6 +101,12 @@ protected void allocate() {
100101 }
101102
102103
104+ protected void defaultSettings () { // ignore
105+ super .defaultSettings ();
106+ textMode = SHAPE ;
107+ }
108+
109+
103110 public void beginDraw () {
104111// long t0 = System.currentTimeMillis();
105112
@@ -125,7 +132,13 @@ public void beginDraw() {
125132 }
126133
127134// System.out.println("beginDraw fonts " + (System.currentTimeMillis() - t));
128- g2 = content .createGraphics (width , height , getMapper ());
135+ // g2 = content.createGraphics(width, height, getMapper());
136+ // if (textMode == SHAPE) {
137+ g2 = content .createGraphicsShapes (width , height );
138+ // } else if (textMode == MODEL) {
139+ // g2 = content.createGraphics(width, height, getMapper());
140+ // }
141+ // g2 = createGraphics();
129142// g2 = template.createGraphics(width, height, mapper);
130143 }
131144// System.out.println("beginDraw " + (System.currentTimeMillis() - t0));
@@ -299,13 +312,20 @@ public void nextPage() {
299312 } catch (Exception e ) {
300313 e .printStackTrace ();
301314 }
315+ g2 = createGraphics ();
316+ beginDraw ();
317+ style (savedStyle );
318+ }
319+
320+
321+ protected Graphics2D createGraphics () {
302322 if (textMode == SHAPE ) {
303- g2 = content .createGraphicsShapes (width , height );
323+ return content .createGraphicsShapes (width , height );
304324 } else if (textMode == MODEL ) {
305- g2 = content .createGraphics (width , height , mapper );
325+ return content .createGraphics (width , height , getMapper () );
306326 }
307- beginDraw ();
308- style ( savedStyle );
327+ // Should not be reachable...
328+ throw new RuntimeException ( "Invalid textMode() selected for PDF." );
309329 }
310330
311331
@@ -417,7 +437,7 @@ public void textFont(PFont which) {
417437 /**
418438 * Change the textMode() to either SHAPE or MODEL.
419439 * <br/>
420- * This resets all renderer settings, and should therefore
440+ * This resets all renderer settings, and therefore must
421441 * be called <EM>before</EM> any other commands that set the fill()
422442 * or the textFont() or anything. Unlike other renderers,
423443 * use textMode() directly after the size() command.
@@ -427,11 +447,13 @@ public void textMode(int mode) {
427447 if (mode == SHAPE ) {
428448 textMode = SHAPE ;
429449 g2 .dispose ();
430- g2 = content .createGraphicsShapes (width , height );
450+ // g2 = content.createGraphicsShapes(width, height);
451+ g2 = createGraphics ();
431452 } else if (mode == MODEL ) {
432453 textMode = MODEL ;
433454 g2 .dispose ();
434- g2 = content .createGraphics (width , height , mapper );
455+ // g2 = content.createGraphics(width, height, mapper);
456+ g2 = createGraphics ();
435457// g2 = template.createGraphics(width, height, mapper);
436458 } else if (mode == SCREEN ) {
437459 throw new RuntimeException ("textMode(SCREEN) not supported with PDF" );
@@ -591,10 +613,18 @@ protected void checkFont() {
591613 ".ttf and .otf files with createFont()." );
592614 } else if (mapper .getAliases ().get (textFont .getName ()) == null ) {
593615 //System.out.println("alias for " + name + " = " + mapper.getAliases().get(name));
594- System .err .println ("Use PGraphicsPDF.listFonts() to get a list of " +
595- "fonts that can be used with PDF." );
596- throw new RuntimeException ("The font “" + textFont .getName () + "” " +
597- "cannot be used with PDF Export." );
616+ // System.err.println("Use PGraphicsPDF.listFonts() to get a list of " +
617+ // "fonts that can be used with PDF.");
618+ // throw new RuntimeException("The font “" + textFont.getName() + "” " +
619+ // "cannot be used with PDF Export.");
620+ if (textFont .getName ().equals ("Lucida Sans" )) {
621+ throw new RuntimeException ("Use textMode(SHAPE) with the default " +
622+ "font when exporting to PDF." );
623+ } else {
624+ throw new RuntimeException ("Use textMode(SHAPE) with " +
625+ "“" + textFont .getName () + "” " +
626+ "when exporting to PDF." );
627+ }
598628 }
599629 }
600630 }
0 commit comments