_TD_
YaBB Newbies
Offline
Posts: 15
textprocessing application +++ solved
Jul 14th , 2009, 6:20am
hi! my project is about analysing the act of writing. for this textprocessing application i was putting together a tool that allows you to see where someone was making errors. (using backspace key) the idea was that if text is deleted it becomes gray and the new correct text will be overprinted. +++ the functions and all works on screen, but i need to be able to export a pdf - unfortunately i was programming in a way that i am collecting a lot of junk... and the file becomes really big (60mb +) maybe someone can point me towards a working solution.. thanks! ++++++++++++++++++++++++++++++++++++++++++ +++ here is the code +++ ++++++++++++++++++++++++++++++++++++++++++ import processing.pdf.*; import controlP5.*; // GUI ControlP5 controlP5; int pdfCount=0; boolean savePdf = false; PGraphicsPDF pdf; ArrayList positions = new ArrayList(); ArrayList deletedLetters = new ArrayList(); ArrayList writtenLetters = new ArrayList(); String textField = ""; String str = ""; // Margins Top and Left int x = 20; int y = 80; // Textsize int tsize = 16; PFont fStandard, cursorFont; color[] cList = { #ADD8E6 , #DAA520 , #00FF00 , #FFC0CB }; color textColor; //// +++ Setup +++ void setup(){ size(800,900); frameRate(20); hint(ENABLE_NATIVE_FONTS); // not sure yet whats the difference for pdf output fStandard = createFont("DTLProkyonTBold", tsize, true); cursorFont = createFont("DTLProkyonTBold", 1.2*tsize, true); background(255); textColor = #000000; // Top Gui controlP5 = new ControlP5(this); controlP5.addButton("Print PDF",1,672,20,60,25).setId(1); controlP5.addButton("ESC",2,740,20,40,25).setId(2); controlP5.addButton("Clear Screen",3,589,20,75,25).setId(3); // clear controlP5.setColorActive(180); controlP5.setColorBackground(220); controlP5.setColorLabel(0); pdf = (PGraphicsPDF)beginRecord(PDF, "prints/app_03_" + pdfCount + ".pdf"); } //// +++ GUI Controller Events +++ void controlEvent(ControlEvent theEvent) { if(theEvent.isController()) { // an event from a controller e.g. button //println(theEvent.controller().value()+" from "+theEvent.controller()); //println(theEvent.controller().name()); if (theEvent.controller().id() == 1){ pdfCount++; save("images/app_03_" + pdfCount + ".jpg"); endRecord(); } if (theEvent.controller().id() == 2){ exit(); } if (theEvent.controller().id() == 3){ // clear <<<<<<<<<<<<<<<<<<<<<<<<<<< fill(255); noStroke(); //rect(0,0,900,900); textField = ""; x=20; y=80; str = ""; } } else if (theEvent.isGroup()) { // an event from a group e.g. scrollList //println(theEvent.group().value()+" from "+theEvent.group()); } } //// +++ writeChar +++ void writeChar(char key) { if( key == 8 ){ if( positions.isEmpty() ) return; textField = textField.substring(0 , textField.length()-1); Letter l = (Letter)positions.get( positions.size() - 1); positions.remove(positions.size() - 1); l.col = #B3B3B3; deletedLetters.add(l); writtenLetters.add(key); x = l.x; y = l.y; redrawText(); return; } textField += key; PFont pf; color col; fill(textColor); pf = fStandard; if( key == 10 ){ x = 20; y += pf.theight; textField += "\n"; } if( x > 800 ){ x = 20; y += pf.theight; textField += "\n"; } textFont(fStandard); positions.add( new Letter(key, fStandard, textColor, x , y) ); redrawText(); String str = "" + key; x += textWidth( str ); } //// +++ Redraw Text +++ void redrawText(){ fill(255); noStroke(); rect(0,0,900,900); textMode(SHAPE); // essential to get vector-data and the correct font in pdf render output! Letter letter = null; for(int i=0; i<deletedLetters.size(); i++){ letter = (Letter)deletedLetters.get(i); fill(letter.col); textFont(letter.font); text(letter.key, letter.x, letter.y); } for(int i=0; i<positions.size(); i++){ letter = (Letter)positions.get(i); fill(letter.col); textFont(letter.font); text(letter.key, letter.x, letter.y); } if( letter != null){ textFont(cursorFont); text("|", letter.x+6, letter.y); textFont(fStandard); } } //// +++ Keypress +++ void keyPressed() { if ((key >= 0x20 && key <= 0x7e)||(key ==8 )||(key==10)) { writeChar(key); } } //// +++ Draw +++ void draw() { } //// +++ Letter Class +++ public class Letter { PFont font; color col; int x; int y; char key; public Letter(char key, PFont font, color col, int x, int y){ this.x = x; this.y = y; this.font = font; this.col = col; this.key = key; } }