You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2021/07/10 11:00:10 UTC
svn commit: r1891430 - in /pdfbox/trunk/pdfbox/src:
main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java
test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java
Author: lehmi
Date: Sat Jul 10 11:00:10 2021
New Revision: 1891430
URL: http://svn.apache.org/viewvc?rev=1891430&view=rev
Log:
PDFBOX-5236: allow general graphics state operators within text mode
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java?rev=1891430&r1=1891429&r2=1891430&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java Sat Jul 10 11:00:10 2021
@@ -1221,14 +1221,9 @@ abstract class PDAbstractContentStream i
*
* @param lineWidth The width which is used for drawing.
* @throws IOException If the content stream could not be written
- * @throws IllegalStateException If the method was called within a text block.
*/
public void setLineWidth(float lineWidth) throws IOException
{
- if (inTextMode)
- {
- throw new IllegalStateException("Error: setLineWidth is not allowed within a text block.");
- }
writeOperand(lineWidth);
writeOperator(OperatorName.SET_LINE_WIDTH);
}
@@ -1238,15 +1233,10 @@ abstract class PDAbstractContentStream i
*
* @param lineJoinStyle 0 for miter join, 1 for round join, and 2 for bevel join.
* @throws IOException If the content stream could not be written.
- * @throws IllegalStateException If the method was called within a text block.
* @throws IllegalArgumentException If the parameter is not a valid line join style.
*/
public void setLineJoinStyle(int lineJoinStyle) throws IOException
{
- if (inTextMode)
- {
- throw new IllegalStateException("Error: setLineJoinStyle is not allowed within a text block.");
- }
if (lineJoinStyle >= 0 && lineJoinStyle <= 2)
{
writeOperand(lineJoinStyle);
@@ -1263,15 +1253,10 @@ abstract class PDAbstractContentStream i
*
* @param lineCapStyle 0 for butt cap, 1 for round cap, and 2 for projecting square cap.
* @throws IOException If the content stream could not be written.
- * @throws IllegalStateException If the method was called within a text block.
* @throws IllegalArgumentException If the parameter is not a valid line cap style.
*/
public void setLineCapStyle(int lineCapStyle) throws IOException
{
- if (inTextMode)
- {
- throw new IllegalStateException("Error: setLineCapStyle is not allowed within a text block.");
- }
if (lineCapStyle >= 0 && lineCapStyle <= 2)
{
writeOperand(lineCapStyle);
@@ -1289,14 +1274,9 @@ abstract class PDAbstractContentStream i
* @param pattern The pattern array
* @param phase The phase of the pattern
* @throws IOException If the content stream could not be written.
- * @throws IllegalStateException If the method was called within a text block.
*/
public void setLineDashPattern(float[] pattern, float phase) throws IOException
{
- if (inTextMode)
- {
- throw new IllegalStateException("Error: setLineDashPattern is not allowed within a text block.");
- }
write("[");
for (float value : pattern)
{
@@ -1312,13 +1292,10 @@ abstract class PDAbstractContentStream i
*
* @param miterLimit the new miter limit.
* @throws IOException If the content stream could not be written.
+ * @throws IllegalArgumentException If the parameter is <= 0.
*/
public void setMiterLimit(float miterLimit) throws IOException
{
- if (inTextMode)
- {
- throw new IllegalStateException("Error: setMiterLimit is not allowed within a text block.");
- }
if (miterLimit <= 0.0)
{
throw new IllegalArgumentException("A miter limit <= 0 is invalid and will not render in Acrobat Reader");
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java?rev=1891430&r1=1891429&r2=1891430&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java Sat Jul 10 11:00:10 2021
@@ -25,6 +25,7 @@ import org.apache.pdfbox.contentstream.o
import org.apache.pdfbox.cos.COSNumber;
import org.apache.pdfbox.pdfparser.PDFStreamParser;
import org.apache.pdfbox.pdmodel.PDPageContentStream.AppendMode;
+import org.apache.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState;
import org.junit.jupiter.api.Test;
/**
@@ -167,4 +168,36 @@ class TestPDPageContentStream
contentStream.close();
}
}
+
+ /**
+ * Check that general graphics state operators are allowed in text mode.
+ *
+ * @throws IOException
+ */
+ @Test
+ void testGeneralGraphicStateOperatorTextMode() throws IOException
+ {
+ try (PDDocument doc = new PDDocument())
+ {
+ PDPage page = new PDPage();
+ doc.addPage(page);
+ PDPageContentStream contentStream = new PDPageContentStream(doc, page);
+ contentStream.beginText();
+ // J
+ contentStream.setLineCapStyle(0);
+ // j
+ contentStream.setLineJoinStyle(0);
+ // w
+ contentStream.setLineWidth(10f);
+ // d
+ contentStream.setLineDashPattern(new float[] { 2, 1 }, 0f);
+ // M
+ contentStream.setMiterLimit(1.0f);
+ // gs
+ contentStream.setGraphicsStateParameters(new PDExtendedGraphicsState());
+ // ri, i are not supported with a specific setter
+ contentStream.endText();
+ contentStream.close();
+ }
+ }
}