Revision: 11837
http://sourceforge.net/p/foray/code/11837
Author: victormote
Date: 2021-01-20 09:53:22 +0000 (Wed, 20 Jan 2021)
Log Message:
-----------
Convert the current graphics state to the top item on a stack of such states.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java 2021-01-20 00:45:14 UTC (rev 11836)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java 2021-01-20 09:53:22 UTC (rev 11837)
@@ -46,6 +46,7 @@
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
+import java.util.Stack;
/**
* Specialized version of PdfStream with methods useful in creating PDF content
@@ -53,20 +54,27 @@
*/
public class PdfContentStream4a extends PdfStream implements PdfContentStream {
- /** The current graphics state. */
- private PdfGraphicsState currentGraphicsState = new PdfGraphicsState();
+ /** The stack of PDF Graphics States for this content stream. */
+ private Stack<PdfGraphicsState> graphicsStateStack = new Stack<PdfGraphicsState>();
/** State variable indicating whether a text object is currently open. */
private boolean textObjectOpen = false;
/**
- * Return the graphic state.
- * @return The graphic state.
+ * Constructor.
*/
- private PdfGraphicsState getGS() {
- return this.currentGraphicsState;
+ public PdfContentStream4a() {
+ this.graphicsStateStack.push(new PdfGraphicsState());
}
+ /**
+ * Returns the current graphics state.
+ * @return The current graphics state.
+ */
+ public PdfGraphicsState getCurrentGraphicsState() {
+ return this.graphicsStateStack.peek();
+ }
+
@Override
public void close() throws PdfException {
closeTextObject();
@@ -109,7 +117,7 @@
}
openTextObject();
final CharSequence stringOut =
- this.getGS().getFont().textToPdf(text, fontOptions, orthography);
+ this.getCurrentGraphicsState().getFont().textToPdf(text, fontOptions, orthography);
write(stringOut);
}
@@ -117,8 +125,8 @@
public void setFont(final PdfFont newFont, final float newFontSize) throws PdfException {
openTextObject();
boolean anyChange = false;
- anyChange |= this.getGS().setFont(newFont);
- anyChange |= this.getGS().setFontSize(newFontSize);
+ anyChange |= this.getCurrentGraphicsState().setFont(newFont);
+ anyChange |= this.getCurrentGraphicsState().setFontSize(newFontSize);
if (! anyChange) {
// Nothing needs to change.
return;
@@ -129,7 +137,7 @@
@Override
public void setStrokeColor(final PdfColor newColor) throws PdfException {
- if (! this.getGS().setStrokeColor(newColor)) {
+ if (! this.getCurrentGraphicsState().setStrokeColor(newColor)) {
// Nothing needs to change.
return;
}
@@ -138,7 +146,7 @@
@Override
public void setFillColor(final PdfColor newColor) throws PdfException {
- if (! this.getGS().setFillColor(newColor)) {
+ if (! this.getCurrentGraphicsState().setFillColor(newColor)) {
// Nothing needs to change.
return;
}
@@ -150,7 +158,7 @@
/* TODO: Remove following line. We do not need to be in a text object
* to set this parameter. */
openTextObject();
- if (! this.getGS().setWordSpacing(newWordSpacing)) {
+ if (! this.getCurrentGraphicsState().setWordSpacing(newWordSpacing)) {
// Nothing needs to change.
return;
}
@@ -162,7 +170,7 @@
/* TODO: Remove following line. We do not need to be in a text object
* to set this parameter. */
openTextObject();
- if (! this.getGS().setCharacterSpacing(newCharacterSpacing)) {
+ if (! this.getCurrentGraphicsState().setCharacterSpacing(newCharacterSpacing)) {
// Nothing needs to change.
return;
}
@@ -171,7 +179,7 @@
@Override
public void setHorizontalScaling(final float newHorizontalScaling) throws PdfException {
- if (! this.getGS().setHorizontalScaling(newHorizontalScaling)) {
+ if (! this.getCurrentGraphicsState().setHorizontalScaling(newHorizontalScaling)) {
// Nothing needs to change.
return;
}
@@ -180,7 +188,7 @@
@Override
public void setLeading(final float newLeading) throws PdfException {
- if (! this.getGS().setLeading(newLeading)) {
+ if (! this.getCurrentGraphicsState().setLeading(newLeading)) {
// Nothing needs to change.
return;
}
@@ -194,7 +202,7 @@
if (mode == null) {
mode = PdfTextRenderingMode.FILL;
}
- if (! this.getGS().setTextRenderingMode(mode)) {
+ if (! this.getCurrentGraphicsState().setTextRenderingMode(mode)) {
// Nothing needs to change.
return;
}
@@ -203,7 +211,7 @@
@Override
public void setTextRise(final float newTextRise) throws PdfException {
- if (! this.getGS().setTextRise(newTextRise)) {
+ if (! this.getCurrentGraphicsState().setTextRise(newTextRise)) {
// Nothing needs to change.
return;
}
@@ -222,7 +230,7 @@
@Override
public void setLineCapStyle(final PdfLineCapStyle newLineCapStyle) throws PdfException {
- if (! this.getGS().setLineCapStyle(newLineCapStyle)) {
+ if (! this.getCurrentGraphicsState().setLineCapStyle(newLineCapStyle)) {
// Nothing needs to change.
return;
}
@@ -310,7 +318,7 @@
@Override
public void setDashPattern(final float[] dashArray, final float dashPhase) throws PdfException {
- if (! this.getGS().setLineDashPattern(dashArray, dashPhase)) {
+ if (! this.getCurrentGraphicsState().setLineDashPattern(dashArray, dashPhase)) {
// Nothing needs to change.
return;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|