Hello,
I wrote the attached patch to reduce the size of ps or eps file. I added basic
shortcuts to postscript commands and gave an access to the property
clippingDisabled. With these modifications (and in using the added method
disableClipping) I can divide by 3 the size of eps files (generated from svg).
I'll be happy if you can push them for the next release.
Best regards,
Calixte
Index: src/java/org/apache/xmlgraphics/ps/PSProcSets.java
===================================================================
--- src/java/org/apache/xmlgraphics/ps/PSProcSets.java (révision 912227)
+++ src/java/org/apache/xmlgraphics/ps/PSProcSets.java (copie de travail)
@@ -55,9 +55,22 @@
gen.writeln("/ld{load def}bd");
gen.writeln("/M/moveto ld");
gen.writeln("/RM/rmoveto ld");
+ gen.writeln("/C/curveto ld");
+ gen.writeln("/L/lineto ld");
gen.writeln("/t/show ld");
gen.writeln("/A/ashow ld");
gen.writeln("/cp/closepath ld");
+ gen.writeln("/RC/setrgbcolor ld");
+ gen.writeln("/GC/setgray ld");
+ gen.writeln("/CC/setcmykcolor ld");
+ gen.writeln("/N/newpath ld");
+ gen.writeln("/ML/setmiterlimit ld");
+ gen.writeln("/LW/setlinewidth ld");
+ gen.writeln("/LJ/setlinejoin ld");
+ gen.writeln("/GR/grestore ld");
+ gen.writeln("/GS/gsave ld");
+ gen.writeln("/f/fill ld");
+ gen.writeln("/S/stroke ld");
gen.writeln("/re {4 2 roll M"); //define rectangle
gen.writeln("1 index 0 rlineto");
@@ -127,7 +140,7 @@
gen.writeln(" grestore");
gen.writeln("} bd");
- gen.writeln("/QUADTO {");
+ gen.writeln("/QT {");
gen.writeln("/Y22 exch store");
gen.writeln("/X22 exch store");
gen.writeln("/Y21 exch store");
Index: src/java/org/apache/xmlgraphics/ps/PSGenerator.java
===================================================================
--- src/java/org/apache/xmlgraphics/ps/PSGenerator.java (révision 912227)
+++ src/java/org/apache/xmlgraphics/ps/PSGenerator.java (copie de travail)
@@ -384,7 +384,7 @@
* @exception IOException In case of an I/O problem
*/
public void saveGraphicsState() throws IOException {
- writeln("gsave");
+ writeln("GS");
PSState state = new PSState(this.currentState, false);
this.graphicsStateStack.push(this.currentState);
@@ -398,7 +398,7 @@
*/
public boolean restoreGraphicsState() throws IOException {
if (this.graphicsStateStack.size() > 0) {
- writeln("grestore");
+ writeln("GR");
this.currentState = (PSState)this.graphicsStateStack.pop();
return true;
} else {
@@ -537,7 +537,7 @@
*/
public void useMiterLimit(float miterlimit) throws IOException {
if (getCurrentState().useMiterLimit(miterlimit)) {
- writeln(miterlimit + " setmiterlimit");
+ writeln(miterlimit + " ML");
}
}
@@ -548,7 +548,7 @@
*/
public void useLineWidth(double width) throws IOException {
if (getCurrentState().useLineWidth(width)) {
- writeln(formatDouble(width) + " setlinewidth");
+ writeln(formatDouble(width) + " LW");
}
}
@@ -608,9 +608,9 @@
}
}
if (same) {
- p.append(" setgray");
+ p.append(" GC");
} else {
- p.append(" setrgbcolor");
+ p.append(" RC");
}
} else if (col.getColorSpace().getType() == ColorSpace.TYPE_CMYK) {
// colorspace is CMYK
@@ -620,12 +620,12 @@
}
p.append(formatDouble(comps[i]));
}
- p.append(" setcmykcolor");
+ p.append(" CC");
} else {
// means we're in DeviceGray or Unknown.
// assume we're in DeviceGray, because otherwise we're screwed.
p.append(formatDouble(comps[0]));
- p.append(" setgray");
+ p.append(" GC");
}
return p.toString();
}
Index: src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java
===================================================================
--- src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java (révision 912227)
+++ src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java (copie de travail)
@@ -69,9 +69,10 @@
/** the PostScript generator being created */
protected PSGenerator gen;
+
+ /** Disable or enable clipping */
+ protected boolean clippingDisabled = false;
- private boolean clippingDisabled = false;
-
/** Fallback text handler */
protected TextHandler fallbackTextHandler = new StrokingTextHandler();
@@ -372,12 +373,12 @@
+ gen.formatDouble(vals[3]) + " "
+ gen.formatDouble(vals[4]) + " "
+ gen.formatDouble(vals[5])
- + " curveto");
+ + " C");
break;
case PathIterator.SEG_LINETO:
gen.writeln(gen.formatDouble(vals[0]) + " "
+ gen.formatDouble(vals[1])
- + " lineto");
+ + " L");
break;
case PathIterator.SEG_MOVETO:
gen.writeln(gen.formatDouble(vals[0]) + " "
@@ -388,10 +389,10 @@
gen.writeln(gen.formatDouble(vals[0]) + " "
+ gen.formatDouble(vals[1]) + " "
+ gen.formatDouble(vals[2]) + " "
- + gen.formatDouble(vals[3]) + " QUADTO ");
+ + gen.formatDouble(vals[3]) + " QT ");
break;
case PathIterator.SEG_CLOSE:
- gen.writeln("closepath");
+ gen.writeln("cp");
break;
default:
break;
@@ -435,7 +436,7 @@
applyPaint(getPaint(), false);
applyStroke(getStroke());
- gen.writeln("newpath");
+ gen.writeln("N");
PathIterator iter = s.getPathIterator(IDENTITY_TRANSFORM);
processPathIterator(iter);
doDrawing(false, true, false);
@@ -456,7 +457,7 @@
if (!this.clippingDisabled) {
preparePainting();
try {
- gen.writeln("newpath");
+ gen.writeln("N");
PathIterator iter = s.getPathIterator(IDENTITY_TRANSFORM);
processPathIterator(iter);
// clip area
@@ -556,11 +557,11 @@
break;
case BasicStroke.JOIN_ROUND:
gen.useLineJoin(1);
- gen.writeln("1 setlinejoin");
+ gen.writeln("1 LJ");
break;
case BasicStroke.JOIN_BEVEL:
gen.useLineJoin(2);
- gen.writeln("2 setlinejoin");
+ gen.writeln("2 LJ");
break;
default: System.err.println("Unsupported line join: " + lj);
}
@@ -722,7 +723,7 @@
applyPaint(getPaint(), true);
- gen.writeln("newpath");
+ gen.writeln("N");
PathIterator iter = s.getPathIterator(IDENTITY_TRANSFORM);
processPathIterator(iter);
doDrawing(true, false,
@@ -746,20 +747,20 @@
if (fill) {
if (stroke) {
if (!nonzero) {
- gen.writeln("gsave fill grestore stroke");
+ gen.writeln("GS f GR S");
} else {
- gen.writeln("gsave eofill grestore stroke");
+ gen.writeln("GS eofill GR S");
}
} else {
if (!nonzero) {
- gen.writeln("fill");
+ gen.writeln("f");
} else {
gen.writeln("eofill");
}
}
} else {
// if(stroke)
- gen.writeln("stroke");
+ gen.writeln("S");
}
}
Index: src/java/org/apache/xmlgraphics/java2d/ps/AbstractPSDocumentGraphics2D.java
===================================================================
--- src/java/org/apache/xmlgraphics/java2d/ps/AbstractPSDocumentGraphics2D.java (révision 912227)
+++ src/java/org/apache/xmlgraphics/java2d/ps/AbstractPSDocumentGraphics2D.java (copie de travail)
@@ -89,6 +89,15 @@
writeFileHeader();
}
+ /**
+ * Disable clipping on each draw commands.
+ *
+ * @param b set to true avoids clipping.
+ */
+ public void disableClipping(boolean b) {
+ this.clippingDisabled = b;
+ }
+
protected abstract void writeFileHeader() throws IOException;
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]