[FOray-commit] SF.net SVN: foray:[11840] trunk/foray/foray-pdf/src/main/java/org/foray/ pdf
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2021-01-20 12:02:55
|
Revision: 11840
http://sourceforge.net/p/foray/code/11840
Author: victormote
Date: 2021-01-20 12:02:48 +0000 (Wed, 20 Jan 2021)
Log Message:
-----------
Break the text state parts of the PdfGraphicsState into a separate class.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfGraphicsState.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java
Added Paths:
-----------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfTextState.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfGraphicsState.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfGraphicsState.java 2021-01-20 11:06:58 UTC (rev 11839)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfGraphicsState.java 2021-01-20 12:02:48 UTC (rev 11840)
@@ -31,9 +31,7 @@
import org.foray.pdf.object.PdfColor4a;
import org.axsl.pdf.PdfColor;
-import org.axsl.pdf.PdfFont;
import org.axsl.pdf.PdfLineCapStyle;
-import org.axsl.pdf.PdfTextRenderingMode;
/**
* Represents a PDF Graphics State object. The Graphics State is ordinarily
@@ -53,6 +51,9 @@
/** The "non-stroke" or "other" color. */
private PdfColor fillColor;
+ /** The text state. */
+ private PdfTextState textState = new PdfTextState();
+
/** The dash array. */
private float[] dashArray;
@@ -62,37 +63,7 @@
/** The line cap style. */
private PdfLineCapStyle lineCapStyle;
- /*--------------------- Start Text State Parameters. -------------------- */
- /** The character spacing, in points. */
- private float characterSpacing;
-
- /** The word spacing, in points. */
- private float wordSpacing;
-
- /** The horizontal scaling percentage. */
- private float horizontalScaling;
-
- /** The text leading, expressed in unscaled text units. */
- private float leading;
-
- /** The font. */
- private PdfFont font;
-
- /** The font size. */
- private float fontSize;
-
- /** The text rendering mode. */
- private PdfTextRenderingMode textRenderingMode;
-
- /** The text rise, expressed in unscaled text space units. */
- private float textRise;
-
- /** The text knockout flag. */
- private boolean textKnockout;
-
- /*---------------------- End Text State Parameters. --------------------- */
-
/**
* Create a PdfGraphicsState instance.
*/
@@ -115,15 +86,7 @@
this.dashPhase = existingState.dashPhase;
this.lineCapStyle = existingState.lineCapStyle;
- this.characterSpacing = existingState.characterSpacing;
- this.wordSpacing = existingState.wordSpacing;
- this.horizontalScaling = existingState.horizontalScaling;
- this.leading = existingState.leading;
- this.font = existingState.font;
- this.fontSize = existingState.fontSize;
- this.textRenderingMode = existingState.textRenderingMode;
- this.textRise = existingState.textRise;
- this.textKnockout = existingState.textKnockout;
+ this.textState = new PdfTextState(this.textState);
}
/**
@@ -133,19 +96,10 @@
public void reset() {
this.strokeColor = PdfColor4a.BLACK;
this.fillColor = PdfColor4a.BLACK;
+ this.textState.reset();
this.dashArray = new float[0];
this.dashPhase = 0;
this.lineCapStyle = PdfLineCapStyle.BUTT_CAP;
-
- this.characterSpacing = 0;
- this.wordSpacing = 0;
- this.horizontalScaling = PdfGraphicsState.INITIAL_HORIZONTAL_SCALING;
- this.leading = 0;
- this.font = null;
- this.fontSize = -1;
- this.textRenderingMode = PdfTextRenderingMode.FILL;
- this.textRise = 0;
- this.textKnockout = true;
}
/**
@@ -203,78 +157,14 @@
}
/**
- * Sets the character spacing.
- * @param newCharacterSpacing The new character spacing, in points.
- * @return True iff the character spacing was changed.
+ * Returns the text state.
+ * @return The text state.
*/
- public boolean setCharacterSpacing(final float newCharacterSpacing) {
- boolean anyChange = false;
- if (newCharacterSpacing != this.characterSpacing) {
- this.characterSpacing = newCharacterSpacing;
- anyChange = true;
- }
- return anyChange;
+ public PdfTextState getTextState() {
+ return this.textState;
}
/**
- * Sets the word spacing.
- * @param newWordSpacing The new word spacing, in points.
- * @return True iff the word spacing was changed.
- */
- public boolean setWordSpacing(final float newWordSpacing) {
- boolean anyChange = false;
- if (newWordSpacing != this.wordSpacing) {
- this.wordSpacing = newWordSpacing;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
- * Sets the font.
- * @param newFont The new font.
- * @return True iff the font was changed.
- */
- public boolean setFont(final PdfFont newFont) {
- boolean anyChange = false;
- if (! newFont.equals(this.font)) {
- this.font = newFont;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
- * Returns the font.
- * @return The font.
- */
- public PdfFont getFont() {
- return this.font;
- }
-
- /**
- * Sets the font-size.
- * @param newFontSize The new font-size, in points.
- * @return True iff the font-size was changed.
- */
- public boolean setFontSize(final float newFontSize) {
- boolean anyChange = false;
- if (newFontSize != this.fontSize) {
- this.fontSize = newFontSize;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
- * Return the font-size.
- * @return The font-size.
- */
- public float getFontSize() {
- return this.fontSize;
- }
-
- /**
* Sets the line dash pattern. See PDF Reference, 3rd Edition, Section 4.3.
* @param newDashArray The new dash array.
* @param newDashPhase The new dash phase.
@@ -348,79 +238,5 @@
return anyChange;
}
- /**
- * Sets the horizontal scaling. See PDF Reference, 3rd Edition, Section
- * 5.2.3.
- * @param newHorizontalScaling The new horizontal scaling percentage.
- * @return True iff the Graphics State was changed by this operation.
- */
- public boolean setHorizontalScaling(final float newHorizontalScaling) {
- boolean anyChange = false;
- if (newHorizontalScaling != this.horizontalScaling) {
- this.horizontalScaling = newHorizontalScaling;
- anyChange = true;
- }
- return anyChange;
- }
- /**
- * Sets the text leading. See PDF Reference, 3rd Edition, Section 5.2.4.
- * @param newLeading The new leading value.
- * @return True iff the Graphics State was changed by this operation.
- */
- public boolean setLeading(final float newLeading) {
- boolean anyChange = false;
- if (newLeading != this.leading) {
- this.leading = newLeading;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
- * Sets the text rendering mode. See PDF Reference, 3rd Edition, Section
- * 5.2.5.
- * @param newTextRenderingMode The new text rendering mode.
- * @return True iff the Graphics State was changed by this operation.
- */
- public boolean setTextRenderingMode(
- final PdfTextRenderingMode newTextRenderingMode) {
- boolean anyChange = false;
- if (newTextRenderingMode != this.textRenderingMode) {
- this.textRenderingMode = newTextRenderingMode;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
- * Sets the text rise. See PDF Reference, 3rd Edition, Section 5.2.6.
- * @param newTextRise The new text rise value.
- * @return True iff the Graphics State was changed by this operation.
- */
- public boolean setTextRise(final float newTextRise) {
- boolean anyChange = false;
- if (newTextRise != this.textRise) {
- this.textRise = newTextRise;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
- * Sets the text knockout flag. See PDF Reference, 3rd Edition, Section
- * 5.2.7.
- * @param newTextKnockout The new text rise value.
- * @return True iff the Graphics State was changed by this operation.
- */
- public boolean setTextKnockout(final boolean newTextKnockout) {
- boolean anyChange = false;
- if (newTextKnockout != this.textKnockout) {
- this.textKnockout = newTextKnockout;
- anyChange = true;
- }
- return anyChange;
-
- }
-
}
Added: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfTextState.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfTextState.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfTextState.java 2021-01-20 12:02:48 UTC (rev 11840)
@@ -0,0 +1,255 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.pdf;
+
+import org.axsl.pdf.PdfFont;
+import org.axsl.pdf.PdfTextRenderingMode;
+
+/**
+ * The text state for the PDF graphics state.
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 5.2."
+ */
+public class PdfTextState {
+
+ /** The character spacing, in points. */
+ private float characterSpacing;
+
+ /** The word spacing, in points. */
+ private float wordSpacing;
+
+ /** The horizontal scaling percentage. */
+ private float horizontalScaling;
+
+ /** The text leading, expressed in unscaled text units. */
+ private float leading;
+
+ /** The font. */
+ private PdfFont font;
+
+ /** The font size. */
+ private float fontSize;
+
+ /** The text rendering mode. */
+ private PdfTextRenderingMode textRenderingMode;
+
+ /** The text rise, expressed in unscaled text space units. */
+ private float textRise;
+
+ /** The text knockout flag. */
+ private boolean textKnockout;
+
+ /**
+ * Create a new instance.
+ */
+ public PdfTextState() {
+ reset();
+ }
+
+ /**
+ * Creates a new PdfGraphicsState instance, initilializing its values to
+ * those of an existing instance.
+ * @param existingState The instance whose values should be copied into the
+ * new instance.
+ */
+ public PdfTextState(final PdfTextState existingState) {
+ this.characterSpacing = existingState.characterSpacing;
+ this.wordSpacing = existingState.wordSpacing;
+ this.horizontalScaling = existingState.horizontalScaling;
+ this.leading = existingState.leading;
+ this.font = existingState.font;
+ this.fontSize = existingState.fontSize;
+ this.textRenderingMode = existingState.textRenderingMode;
+ this.textRise = existingState.textRise;
+ this.textKnockout = existingState.textKnockout;
+ }
+
+ /**
+ * Resets the Graphics State to its original state, as documented in
+ * PDF Reference, 3rd Edition, Section 4.3.
+ */
+ public void reset() {
+ this.characterSpacing = 0;
+ this.wordSpacing = 0;
+ this.horizontalScaling = PdfGraphicsState.INITIAL_HORIZONTAL_SCALING;
+ this.leading = 0;
+ this.font = null;
+ this.fontSize = -1;
+ this.textRenderingMode = PdfTextRenderingMode.FILL;
+ this.textRise = 0;
+ this.textKnockout = true;
+ }
+
+ /**
+ * Sets the character spacing.
+ * @param newCharacterSpacing The new character spacing, in points.
+ * @return True iff the character spacing was changed.
+ */
+ public boolean setCharacterSpacing(final float newCharacterSpacing) {
+ boolean anyChange = false;
+ if (newCharacterSpacing != this.characterSpacing) {
+ this.characterSpacing = newCharacterSpacing;
+ anyChange = true;
+ }
+ return anyChange;
+ }
+
+ /**
+ * Sets the word spacing.
+ * @param newWordSpacing The new word spacing, in points.
+ * @return True iff the word spacing was changed.
+ */
+ public boolean setWordSpacing(final float newWordSpacing) {
+ boolean anyChange = false;
+ if (newWordSpacing != this.wordSpacing) {
+ this.wordSpacing = newWordSpacing;
+ anyChange = true;
+ }
+ return anyChange;
+ }
+
+ /**
+ * Sets the font.
+ * @param newFont The new font.
+ * @return True iff the font was changed.
+ */
+ public boolean setFont(final PdfFont newFont) {
+ boolean anyChange = false;
+ if (! newFont.equals(this.font)) {
+ this.font = newFont;
+ anyChange = true;
+ }
+ return anyChange;
+ }
+
+ /**
+ * Returns the font.
+ * @return The font.
+ */
+ public PdfFont getFont() {
+ return this.font;
+ }
+
+ /**
+ * Sets the font-size.
+ * @param newFontSize The new font-size, in points.
+ * @return True iff the font-size was changed.
+ */
+ public boolean setFontSize(final float newFontSize) {
+ boolean anyChange = false;
+ if (newFontSize != this.fontSize) {
+ this.fontSize = newFontSize;
+ anyChange = true;
+ }
+ return anyChange;
+ }
+
+ /**
+ * Return the font-size.
+ * @return The font-size.
+ */
+ public float getFontSize() {
+ return this.fontSize;
+ }
+
+ /**
+ * Sets the horizontal scaling. See PDF Reference, 3rd Edition, Section
+ * 5.2.3.
+ * @param newHorizontalScaling The new horizontal scaling percentage.
+ * @return True iff the Graphics State was changed by this operation.
+ */
+ public boolean setHorizontalScaling(final float newHorizontalScaling) {
+ boolean anyChange = false;
+ if (newHorizontalScaling != this.horizontalScaling) {
+ this.horizontalScaling = newHorizontalScaling;
+ anyChange = true;
+ }
+ return anyChange;
+ }
+
+ /**
+ * Sets the text leading. See PDF Reference, 3rd Edition, Section 5.2.4.
+ * @param newLeading The new leading value.
+ * @return True iff the Graphics State was changed by this operation.
+ */
+ public boolean setLeading(final float newLeading) {
+ boolean anyChange = false;
+ if (newLeading != this.leading) {
+ this.leading = newLeading;
+ anyChange = true;
+ }
+ return anyChange;
+ }
+
+ /**
+ * Sets the text rendering mode. See PDF Reference, 3rd Edition, Section
+ * 5.2.5.
+ * @param newTextRenderingMode The new text rendering mode.
+ * @return True iff the Graphics State was changed by this operation.
+ */
+ public boolean setTextRenderingMode(
+ final PdfTextRenderingMode newTextRenderingMode) {
+ boolean anyChange = false;
+ if (newTextRenderingMode != this.textRenderingMode) {
+ this.textRenderingMode = newTextRenderingMode;
+ anyChange = true;
+ }
+ return anyChange;
+ }
+
+ /**
+ * Sets the text rise. See PDF Reference, 3rd Edition, Section 5.2.6.
+ * @param newTextRise The new text rise value.
+ * @return True iff the Graphics State was changed by this operation.
+ */
+ public boolean setTextRise(final float newTextRise) {
+ boolean anyChange = false;
+ if (newTextRise != this.textRise) {
+ this.textRise = newTextRise;
+ anyChange = true;
+ }
+ return anyChange;
+ }
+
+ /**
+ * Sets the text knockout flag. See PDF Reference, 3rd Edition, Section
+ * 5.2.7.
+ * @param newTextKnockout The new text rise value.
+ * @return True iff the Graphics State was changed by this operation.
+ */
+ public boolean setTextKnockout(final boolean newTextKnockout) {
+ boolean anyChange = false;
+ if (newTextKnockout != this.textKnockout) {
+ this.textKnockout = newTextKnockout;
+ anyChange = true;
+ }
+ return anyChange;
+
+ }
+
+}
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 11:06:58 UTC (rev 11839)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java 2021-01-20 12:02:48 UTC (rev 11840)
@@ -117,7 +117,7 @@
}
openTextObject();
final CharSequence stringOut =
- this.getCurrentGraphicsState().getFont().textToPdf(text, fontOptions, orthography);
+ this.getCurrentGraphicsState().getTextState().getFont().textToPdf(text, fontOptions, orthography);
write(stringOut);
}
@@ -125,8 +125,8 @@
public void setFont(final PdfFont newFont, final float newFontSize) throws PdfException {
openTextObject();
boolean anyChange = false;
- anyChange |= this.getCurrentGraphicsState().setFont(newFont);
- anyChange |= this.getCurrentGraphicsState().setFontSize(newFontSize);
+ anyChange |= this.getCurrentGraphicsState().getTextState().setFont(newFont);
+ anyChange |= this.getCurrentGraphicsState().getTextState().setFontSize(newFontSize);
if (! anyChange) {
// Nothing needs to change.
return;
@@ -158,7 +158,7 @@
/* TODO: Remove following line. We do not need to be in a text object
* to set this parameter. */
openTextObject();
- if (! this.getCurrentGraphicsState().setWordSpacing(newWordSpacing)) {
+ if (! this.getCurrentGraphicsState().getTextState().setWordSpacing(newWordSpacing)) {
// Nothing needs to change.
return;
}
@@ -170,7 +170,7 @@
/* TODO: Remove following line. We do not need to be in a text object
* to set this parameter. */
openTextObject();
- if (! this.getCurrentGraphicsState().setCharacterSpacing(newCharacterSpacing)) {
+ if (! this.getCurrentGraphicsState().getTextState().setCharacterSpacing(newCharacterSpacing)) {
// Nothing needs to change.
return;
}
@@ -179,7 +179,7 @@
@Override
public void setHorizontalScaling(final float newHorizontalScaling) throws PdfException {
- if (! this.getCurrentGraphicsState().setHorizontalScaling(newHorizontalScaling)) {
+ if (! this.getCurrentGraphicsState().getTextState().setHorizontalScaling(newHorizontalScaling)) {
// Nothing needs to change.
return;
}
@@ -188,7 +188,7 @@
@Override
public void setLeading(final float newLeading) throws PdfException {
- if (! this.getCurrentGraphicsState().setLeading(newLeading)) {
+ if (! this.getCurrentGraphicsState().getTextState().setLeading(newLeading)) {
// Nothing needs to change.
return;
}
@@ -202,7 +202,7 @@
if (mode == null) {
mode = PdfTextRenderingMode.FILL;
}
- if (! this.getCurrentGraphicsState().setTextRenderingMode(mode)) {
+ if (! this.getCurrentGraphicsState().getTextState().setTextRenderingMode(mode)) {
// Nothing needs to change.
return;
}
@@ -211,7 +211,7 @@
@Override
public void setTextRise(final float newTextRise) throws PdfException {
- if (! this.getCurrentGraphicsState().setTextRise(newTextRise)) {
+ if (! this.getCurrentGraphicsState().getTextState().setTextRise(newTextRise)) {
// Nothing needs to change.
return;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|