Skip to content

Commit 9d4052e

Browse files
committed
cleaning up pdf and font selection
1 parent 5b28a97 commit 9d4052e

File tree

4 files changed

+57
-22
lines changed

4 files changed

+57
-22
lines changed

core/src/processing/core/PApplet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7339,7 +7339,7 @@ static public void runSketch(String args[], final PApplet constructedApplet) {
73397339

73407340
// remove the grow box by default
73417341
// users who want it back can call frame.setResizable(true)
7342-
//frame.setResizable(false);
7342+
// frame.setResizable(false);
73437343
// moved later (issue #467)
73447344

73457345
// Set the trimmings around the image

core/todo.txt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,28 @@ X need to finish font changes wrt native fonts before any release
1010
X right now not in a good place--default font will be bitmapped and ugly
1111
X http://code.google.com/p/processing/issues/detail?id=416
1212
o need to have some kind of subsetting mode, but 'subsetting' a bad name
13+
X changing PDF to use textMode(SHAPE) by default
14+
_ need to update the reference for textMode(MODEL)
15+
16+
_ saving a PGraphics as jpg using save() makes a cmyk file
17+
_ need to shut off the alpha channel when writing
18+
_ http://code.google.com/p/processing/issues/detail?id=415
19+
20+
_ present mode is no longer centering on osx?
21+
_ bug: textAlign(RIGHT) is shutting off native fonts
22+
_ makes salaryper super ugly
1323

1424
_ make sure that loadXxxx() methods are used after init()
1525
_ nasty errors when loadImage/Font/createFont/etc used outside
1626

1727
_ selectInput() and selectOutput() freeze on OS X
1828
_ http://code.google.com/p/processing/issues/detail?id=445
1929

20-
_ saving a PGraphics as jpg using save() makes a cmyk file
21-
_ need to shut off the alpha channel when writing
22-
_ http://code.google.com/p/processing/issues/detail?id=415
23-
2430
_ definite present-mode weirdness with background colors
2531

2632
_ OpenGL Applets won't load with JRE 6 update 21 or higher
2733
_ http://code.google.com/p/processing/issues/detail?id=429
2834

29-
_ present mode is no longer centering on osx?
30-
_ bug: textAlign(RIGHT) is shutting off native fonts
31-
_ makes salaryper super ugly
32-
3335
_ clipping
3436
_ http://mrl.nyu.edu/~perlin/experiments/borg/render/index.html
3537
_ http://en.wikipedia.org/wiki/Clip_Mapping

java/libraries/pdf/src/processing/pdf/PGraphicsPDF.java

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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
@@ -21,6 +21,7 @@
2121
package processing.pdf;
2222

2323
import java.awt.Font;
24+
import java.awt.Graphics2D;
2425
import java.io.*;
2526
import 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
}

todo.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ X make sure that android is working again
112112
X export is broken in 0192
113113
X http://code.google.com/p/processing/issues/detail?id=487
114114

115+
***
116+
_ exceptions in setup() are locking the PDE
117+
115118
_ strange window flicker when first opened
116119
_ test libraries on android
117120
_ test .java files on desktop version

0 commit comments

Comments
 (0)