I normally use PDF export method to save my outputs as vector files. beginRecord
and endRecord
always are enough to do this. However I am unable to save Handy Library (https://github.com/gicentre/handy) outputs as PDFs. In the same code I have some standard lines and rectangles and also some Handy lines. I can see the normal lines & rectangles in the PDF but not the Handy lines.
Do you have any experience or recommendation about this issue, basically any vector output format will work for me?
Thanks very much in advance.
1 Like
Are you sure you are enclosing handy drawing within beginRecord
and endRecord
? Can you post your code too?
1 Like
It seems that yes, all Handy codes are between beginRecord
and endRecord
, please see my messy code below:
import org.gicentre.handy.*;
HandyRenderer h1, h2, h3, h4;
import processing.pdf.*;
import processing.dxf.*;
import processing.svg.*;
void setup()
{
size(640, 640);
noLoop();
beginRecord(PDF, "test.pdf");
h1 = HandyPresets.createPencil(this);
fill(0, 204);
noStroke();
h1.setOverrideStrokeColour(true);
h1.setStrokeColour(0);
h1.setRoughness(1);
//h1.setFillGap(0.5);
//h1.setFillWeight(5);
float myStep = 4;
int numberOfBox = 4;
int miniBoxSize = 75;
float edgeOffset = 80;
float boxGaps = ((width - edgeOffset*2) - (miniBoxSize * numberOfBox) ) / (numberOfBox - 1);
for (float ll=0; ll<=width; ll=ll+myStep) {
//stroke(255, 0, 0);
strokeWeight(2);
line(ll, 0, ll, height);
stroke(1);
//noStroke();
}
pushMatrix();
for (int j=0; j<numberOfBox; j++) {
pushMatrix();
translate (0, edgeOffset + (boxGaps+miniBoxSize)*j);
for (int i=0; i<numberOfBox; i++) {
pushMatrix();
translate (edgeOffset + (boxGaps+miniBoxSize)*i, 0);
if (random(16) < 1) {stroke(255,0,0);} else {stroke(0);}
rotate(random(-.1, .1));
for (float rr=0; rr<miniBoxSize; rr=rr+myStep) {
h1.line(0, rr + random(-.99,.99), miniBoxSize, rr+ random(-.1,.1));
}
popMatrix();
}
popMatrix();
}
popMatrix();
endRecord();
save("normal.png");
}
1 Like
beginRecord()
works by intercepting method calls to the PApplet, pointing them to a recorder
PGraphics
object internally (see an example from the source code below). I’m guessing the calls to the Handy instance aren’t being captured and pointed to that PGraphics
object because Handy draws to its own PGraphics
object, and not the PApplet.
public void ellipse(float a, float b, float c, float d) {
if (recorder != null) recorder.ellipse(a, b, c, d);
g.ellipse(a, b, c, d);
}
So try this instead (here we point handy to draw into the PDF PGraphics
):
PGraphics pdf = beginRecord(PDF, “test.pdf”);
h1 = HandyPresets.createPencil(this);
h1.setGraphics(pdf);
(note that you might not see what Handy has drawn in the sketch now)
3 Likes
Wow! It worked like a charm, thanks very much!
I guess I can redraw the same Handy objects with another instance if I need to see them on screen.