Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,7 @@ public void drawImage(PDImageXObject image, float x, float y) throws IOException
*/
public void drawImage(PDImageXObject image, float x, float y, float width, float height) throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: drawImage is not allowed within a text block.");
}
assertNotInTextMode("drawImage");

saveGraphicsState();

Expand All @@ -444,10 +441,7 @@ public void drawImage(PDImageXObject image, float x, float y, float width, float
*/
public void drawImage(PDImageXObject image, Matrix matrix) throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: drawImage is not allowed within a text block.");
}
assertNotInTextMode("drawImage");

saveGraphicsState();

Expand Down Expand Up @@ -488,10 +482,7 @@ public void drawImage(PDInlineImage inlineImage, float x, float y) throws IOExce
*/
public void drawImage(PDInlineImage inlineImage, float x, float y, float width, float height) throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: drawImage is not allowed within a text block.");
}
assertNotInTextMode("drawImage");

saveGraphicsState();
transform(new Matrix(width, 0, 0, height, x, y));
Expand Down Expand Up @@ -553,10 +544,7 @@ public void drawImage(PDInlineImage inlineImage, float x, float y, float width,
*/
public void drawForm(PDFormXObject form) throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: drawForm is not allowed within a text block.");
}
assertNotInTextMode("drawForm");

writeOperand(resources.add(form));
writeOperator(OperatorName.DRAW_OBJECT);
Expand Down Expand Up @@ -899,10 +887,7 @@ public void setNonStrokingColor(float g) throws IOException
*/
public void addRect(float x, float y, float width, float height) throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: addRect is not allowed within a text block.");
}
assertNotInTextMode("addRect");
writeOperand(x);
writeOperand(y);
writeOperand(width);
Expand All @@ -925,10 +910,7 @@ public void addRect(float x, float y, float width, float height) throws IOExcept
*/
public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3) throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: curveTo is not allowed within a text block.");
}
assertNotInTextMode("curveTo");
writeOperand(x1);
writeOperand(y1);
writeOperand(x2);
Expand All @@ -951,10 +933,7 @@ public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3)
*/
public void curveTo2(float x2, float y2, float x3, float y3) throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: curveTo2 is not allowed within a text block.");
}
assertNotInTextMode("curveTo2");
writeOperand(x2);
writeOperand(y2);
writeOperand(x3);
Expand All @@ -975,10 +954,7 @@ public void curveTo2(float x2, float y2, float x3, float y3) throws IOException
*/
public void curveTo1(float x1, float y1, float x3, float y3) throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: curveTo1 is not allowed within a text block.");
}
assertNotInTextMode("curveTo1");
writeOperand(x1);
writeOperand(y1);
writeOperand(x3);
Expand All @@ -996,10 +972,7 @@ public void curveTo1(float x1, float y1, float x3, float y3) throws IOException
*/
public void moveTo(float x, float y) throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: moveTo is not allowed within a text block.");
}
assertNotInTextMode("moveTo");
writeOperand(x);
writeOperand(y);
writeOperator(OperatorName.MOVE_TO);
Expand All @@ -1015,10 +988,7 @@ public void moveTo(float x, float y) throws IOException
*/
public void lineTo(float x, float y) throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: lineTo is not allowed within a text block.");
}
assertNotInTextMode("lineTo");
writeOperand(x);
writeOperand(y);
writeOperator(OperatorName.LINE_TO);
Expand All @@ -1032,10 +1002,7 @@ public void lineTo(float x, float y) throws IOException
*/
public void stroke() throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: stroke is not allowed within a text block.");
}
assertNotInTextMode("stroke");
writeOperator(OperatorName.STROKE_PATH);
}

Expand All @@ -1047,10 +1014,7 @@ public void stroke() throws IOException
*/
public void closeAndStroke() throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: closeAndStroke is not allowed within a text block.");
}
assertNotInTextMode("closeAndStroke");
writeOperator(OperatorName.CLOSE_AND_STROKE);
}

Expand All @@ -1062,10 +1026,7 @@ public void closeAndStroke() throws IOException
*/
public void fill() throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: fill is not allowed within a text block.");
}
assertNotInTextMode("fill");
writeOperator(OperatorName.FILL_NON_ZERO);
}

Expand All @@ -1077,10 +1038,7 @@ public void fill() throws IOException
*/
public void fillEvenOdd() throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: fillEvenOdd is not allowed within a text block.");
}
assertNotInTextMode("fillEvenOdd");
writeOperator(OperatorName.FILL_EVEN_ODD);
}

Expand All @@ -1094,10 +1052,7 @@ public void fillEvenOdd() throws IOException
*/
public void fillAndStroke() throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: fillAndStroke is not allowed within a text block.");
}
assertNotInTextMode("fillAndStroke");
writeOperator(OperatorName.FILL_NON_ZERO_AND_STROKE);
}

Expand All @@ -1111,10 +1066,7 @@ public void fillAndStroke() throws IOException
*/
public void fillAndStrokeEvenOdd() throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: fillAndStrokeEvenOdd is not allowed within a text block.");
}
assertNotInTextMode("fillAndStrokeEvenOdd");
writeOperator(OperatorName.FILL_EVEN_ODD_AND_STROKE);
}

Expand All @@ -1128,10 +1080,7 @@ public void fillAndStrokeEvenOdd() throws IOException
*/
public void closeAndFillAndStroke() throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: closeAndFillAndStroke is not allowed within a text block.");
}
assertNotInTextMode("closeAndFillAndStroke");
writeOperator(OperatorName.CLOSE_FILL_NON_ZERO_AND_STROKE);
}

Expand All @@ -1145,10 +1094,7 @@ public void closeAndFillAndStroke() throws IOException
*/
public void closeAndFillAndStrokeEvenOdd() throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: closeAndFillAndStrokeEvenOdd is not allowed within a text block.");
}
assertNotInTextMode("closeAndFillAndStrokeEvenOdd");
writeOperator(OperatorName.CLOSE_FILL_EVEN_ODD_AND_STROKE);
}

Expand All @@ -1161,10 +1107,7 @@ public void closeAndFillAndStrokeEvenOdd() throws IOException
*/
public void shadingFill(PDShading shading) throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: shadingFill is not allowed within a text block.");
}
assertNotInTextMode("shadingFill");

writeOperand(resources.add(shading));
writeOperator(OperatorName.SHADING_FILL);
Expand All @@ -1178,10 +1121,7 @@ public void shadingFill(PDShading shading) throws IOException
*/
public void closePath() throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: closePath is not allowed within a text block.");
}
assertNotInTextMode("closePath");
writeOperator(OperatorName.CLOSE_PATH);
}

Expand All @@ -1193,10 +1133,7 @@ public void closePath() throws IOException
*/
public void clip() throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: clip is not allowed within a text block.");
}
assertNotInTextMode("clip");
writeOperator(OperatorName.CLIP_NON_ZERO);

// end path without filling or stroking
Expand All @@ -1211,10 +1148,7 @@ public void clip() throws IOException
*/
public void clipEvenOdd() throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: clipEvenOdd is not allowed within a text block.");
}
assertNotInTextMode("clipEvenOdd");
writeOperator(OperatorName.CLIP_EVEN_ODD);

// end path without filling or stroking
Expand Down Expand Up @@ -1569,6 +1503,15 @@ private boolean isOutsideOneInterval(double val)
return val < 0 || val > 1;
}

private void assertNotInTextMode(String operation)
{
if (inTextMode)
{
throw new IllegalStateException(
"Error: " + operation + " is not allowed within a text block.");
}
}

protected void setStrokingColorSpaceStack(PDColorSpace colorSpace)
{
if (strokingColorSpaceStack.isEmpty())
Expand Down