Skip to content

Commit a092931

Browse files
committed
record PShape to PDF
1 parent fc369d1 commit a092931

File tree

1 file changed

+93
-4
lines changed

1 file changed

+93
-4
lines changed

core/src/processing/opengl/PShapeOpenGL.java

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4664,10 +4664,99 @@ public void draw(PGraphics g) {
46644664
post(gl);
46654665
}
46664666
} else {
4667-
// The renderer is not PGraphicsOpenGL, which probably means that
4668-
// the draw() method is being called by the recorder. We just use
4669-
// the default draw implementation from the parent class.
4670-
super.draw(g);
4667+
if (family == GEOMETRY) {
4668+
inGeoToVertices();
4669+
}
4670+
pre(g);
4671+
drawImpl(g);
4672+
post(g);
4673+
}
4674+
}
4675+
4676+
4677+
private void inGeoToVertices() {
4678+
vertexCount = 0;
4679+
vertexCodeCount = 0;
4680+
if (inGeo.codeCount == 0) {
4681+
for (int i = 0; i < inGeo.vertexCount; i++) {
4682+
int index = 3 * i;
4683+
float x = inGeo.vertices[index++];
4684+
float y = inGeo.vertices[index ];
4685+
super.vertex(x, y);
4686+
}
4687+
} else {
4688+
int v;
4689+
float x, y;
4690+
float cx, cy;
4691+
float x2, y2, x3, y3, x4, y4;
4692+
int idx = 0;
4693+
boolean insideContour = false;
4694+
4695+
for (int j = 0; j < inGeo.codeCount; j++) {
4696+
switch (inGeo.codes[j]) {
4697+
4698+
case VERTEX:
4699+
v = 3 * idx;
4700+
x = inGeo.vertices[v++];
4701+
y = inGeo.vertices[v ];
4702+
super.vertex(x, y);
4703+
4704+
idx++;
4705+
break;
4706+
4707+
case QUADRATIC_VERTEX:
4708+
v = 3 * idx;
4709+
cx = inGeo.vertices[v++];
4710+
cy = inGeo.vertices[v];
4711+
4712+
v = 3 * (idx + 1);
4713+
x3 = inGeo.vertices[v++];
4714+
y3 = inGeo.vertices[v];
4715+
4716+
super.quadraticVertex(cx, cy, x3, y3);
4717+
4718+
idx += 2;
4719+
break;
4720+
4721+
case BEZIER_VERTEX:
4722+
v = 3 * idx;
4723+
x2 = inGeo.vertices[v++];
4724+
y2 = inGeo.vertices[v ];
4725+
4726+
v = 3 * (idx + 1);
4727+
x3 = inGeo.vertices[v++];
4728+
y3 = inGeo.vertices[v ];
4729+
4730+
v = 3 * (idx + 2);
4731+
x4 = inGeo.vertices[v++];
4732+
y4 = inGeo.vertices[v ];
4733+
4734+
super.bezierVertex(x2, y2, x3, y3, x4, y4);
4735+
4736+
idx += 3;
4737+
break;
4738+
4739+
case CURVE_VERTEX:
4740+
v = 3 * idx;
4741+
x = inGeo.vertices[v++];
4742+
y = inGeo.vertices[v ];
4743+
4744+
super.curveVertex(x, y);
4745+
4746+
idx++;
4747+
break;
4748+
4749+
case BREAK:
4750+
if (insideContour) {
4751+
super.endContourImpl();
4752+
}
4753+
super.beginContourImpl();
4754+
insideContour = true;
4755+
}
4756+
}
4757+
if (insideContour) {
4758+
super.endContourImpl();
4759+
}
46714760
}
46724761
}
46734762

0 commit comments

Comments
 (0)