From 11be1683cc7b0a5da6f6a73ecfc5c5ec034c4622 Mon Sep 17 00:00:00 2001 From: benfry Date: Thu, 12 Jan 2006 01:38:20 +0000 Subject: [PATCH] first stages of pdf with filename working --- build/macosx/make.sh | 11 +++++++++++ core/PApplet.java | 32 +++++++++++++++++++++++--------- core/PGraphics.java | 7 ------- core/todo.txt | 9 ++++++++- pdf/PGraphicsPDF.java | 36 ++++++++++++------------------------ 5 files changed, 54 insertions(+), 41 deletions(-) diff --git a/build/macosx/make.sh b/build/macosx/make.sh index d78e4d42a..129f1332f 100755 --- a/build/macosx/make.sh +++ b/build/macosx/make.sh @@ -195,6 +195,17 @@ mkdir -p $LIBRARIES/opengl/library/ cp library/opengl.jar $LIBRARIES/opengl/library/ +# PDF LIBRARY +echo Building PDF library... +cd ../pdf +$JIKES -target 1.1 +D -classpath "library/itext-1.3.jar:$CLASSPATH" -d . *.java +rm -f library/pdf.jar +zip -r0q library/pdf.jar processing +rm -rf processing +mkdir -p $LIBRARIES/pdf/library/ +cp library/pdf.jar $LIBRARIES/pdf/library/ + + CLASSPATH=../$CLASSPATH JIKES=../../build/$PLATFORM/work/jikes CORE=../../build/$PLATFORM/work/lib/core.jar diff --git a/core/PApplet.java b/core/PApplet.java index 1ce18b123..4177b6fe6 100644 --- a/core/PApplet.java +++ b/core/PApplet.java @@ -952,6 +952,9 @@ public class PApplet extends Applet new Integer(iwidth), new Integer(iheight), applet }; } else { + // first make sure that this in a nice, full, absolute path + ipath = applet.savePath(ipath); + constructorParams = new Class[] { Integer.TYPE, Integer.TYPE, PApplet.class, String.class }; @@ -971,10 +974,15 @@ public class PApplet extends Applet if ((msg != null) && (msg.indexOf("no jogl in java.library.path") != -1)) { throw new RuntimeException(openglError); + } else { - //ite.getTargetException().printStackTrace(); + ite.getTargetException().printStackTrace(); Throwable target = ite.getTargetException(); - target.printStackTrace(); + target.printStackTrace(System.out); // macosx bug + // neither of these help, or work + //target.printStackTrace(System.err); + //System.err.flush(); + //System.out.println(System.err); // and the object isn't null throw new RuntimeException(target.getMessage()); } @@ -987,6 +995,7 @@ public class PApplet extends Applet } } catch (Exception e) { + System.out.println("ex3"); if ((e instanceof IllegalArgumentException) || (e instanceof NoSuchMethodException) || (e instanceof IllegalAccessException)) { @@ -999,8 +1008,10 @@ public class PApplet extends Applet throw new RuntimeException(msg); } else { - e.printStackTrace(); - return null; + e.printStackTrace(System.out); + //System.err.flush(); + //return null; + throw new RuntimeException(e.getMessage()); //die("Could not create " + irenderer); } @@ -5836,6 +5847,14 @@ public class PApplet extends Applet } + public PGraphics recordRaw(String renderer, String filename) { + filename = savePath(filename); // ensure an absolute path + PGraphics rec = createGraphics(width, height, renderer, filename); + g.recordRaw(rec); + return rec; + } + + ////////////////////////////////////////////////////////////// @@ -6974,9 +6993,4 @@ public class PApplet extends Applet if (recorder != null) recorder.recordRaw(recorderRaw); g.recordRaw(recorderRaw); } - - - public PGraphics recordRaw(String renderer, String filename) { - return g.recordRaw(renderer, filename); - } } diff --git a/core/PGraphics.java b/core/PGraphics.java index a9fa6a259..c7298a7fd 100644 --- a/core/PGraphics.java +++ b/core/PGraphics.java @@ -3537,11 +3537,4 @@ public class PGraphics extends PImage implements PConstants { throw new RuntimeException("recordRaw() not supported " + "by this renderer."); } - - public PGraphics recordRaw(String renderer, String filename) { - PGraphics rec = - PApplet.createGraphics(width, height, renderer, null, filename); - recordRaw(rec); - return rec; - } } diff --git a/core/todo.txt b/core/todo.txt index 909c02303..4bcd6f890 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -2,7 +2,14 @@ X user.dir wasn't getting set properly X when graphics can be resized, resize rather than creating new context X change savePath() et al a great deal, include better docs -_ +X http://dev.processing.org/bugs/show_bug.cgi?id=199 + +_ passing applet into createGraphics.. problems with re-adding listeners +_ since the listeners are added to the PApplet + +_ on osx, System.err isn't writing in things like createGraphics() +_ but doing a printStackTrace(System.out) works +_ something weird happening with one of the streams shutting down? _ registering font directories in pdf.. is it necessary? _ (commented out for 0100) diff --git a/pdf/PGraphicsPDF.java b/pdf/PGraphicsPDF.java index 250b794c9..e8c0c4016 100644 --- a/pdf/PGraphicsPDF.java +++ b/pdf/PGraphicsPDF.java @@ -45,12 +45,16 @@ public class PGraphicsPDF extends PGraphics2 { public PGraphicsPDF(int width, int height, PApplet applet, String path) { super(width, height, null); + //System.out.println("trying " + path); + file = new File(path); if (!file.isAbsolute() || (path == null)) { throw new RuntimeException("PGraphicsPDF requires an absolute path " + "for the location of the output file."); } + //System.out.println("making " + path); + //if (path == null) path = "output.pdf"; //this.file = new File(path); @@ -92,29 +96,9 @@ public class PGraphicsPDF extends PGraphics2 { * along the way and wants to hork things up. */ protected void allocate() { - //temp = File.createTempFile("frame", ".pdf"); - - /* - if (document != null) { - throw new RuntimeException("Need to write PGraphicsPDF code " + - "for multiple calls to allocate()"); - } - - // temporary - file = new File("test.pdf"); - - //document = new Document(); - document = new Document(new Rectangle(width, height)); - try { - writer = PdfWriter.getInstance(document, new FileOutputStream(file)); - document.open(); - content = writer.getDirectContent(); - - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException("Problem saving the PDF file."); - } - */ + // can't do anything here, because this will be called by the + // superclass PGraphics, and the file/path object won't be set yet + // (since super() called right at the beginning of the constructor) } @@ -147,8 +131,9 @@ public class PGraphicsPDF extends PGraphics2 { public void beginFrame() { // temporary //file = new File(filename); //"test.pdf"); - + //System.out.println("pdf beginFrame()"); //document = new Document(); + document = new Document(new Rectangle(width, height)); try { writer = PdfWriter.getInstance(document, new FileOutputStream(file)); @@ -189,6 +174,9 @@ public class PGraphicsPDF extends PGraphics2 { */ + /** + * Call to explicitly go to the next page from within a single draw(). + */ public void nextPage() { g2.dispose(); try {