2020import java .util .List ;
2121import java .awt .geom .Point2D ;
2222
23+ import org .apache .logging .log4j .LogManager ;
24+ import org .apache .logging .log4j .Logger ;
25+
2326import org .apache .pdfbox .contentstream .PDFGraphicsStreamEngine ;
2427import org .apache .pdfbox .contentstream .operator .MissingOperandException ;
25-
2628import org .apache .pdfbox .cos .COSBase ;
2729import org .apache .pdfbox .cos .COSNumber ;
2830import org .apache .pdfbox .contentstream .operator .Operator ;
3537 */
3638public final class CurveToReplicateFinalPoint extends GraphicsOperatorProcessor
3739{
40+ private static final Logger LOG = LogManager .getLogger (CurveToReplicateFinalPoint .class );
41+
3842 public CurveToReplicateFinalPoint (PDFGraphicsStreamEngine context )
3943 {
4044 super (context );
@@ -57,12 +61,22 @@ public void process(Operator operator, List<COSBase> operands) throws IOExceptio
5761 COSNumber y3 = (COSNumber )operands .get (3 );
5862
5963 PDFGraphicsStreamEngine context = getGraphicsContext ();
64+ Point2D currentPoint = context .getCurrentPoint ();
65+
6066 Point2D .Float point1 = context .transformedPoint (x1 .floatValue (), y1 .floatValue ());
6167 Point2D .Float point3 = context .transformedPoint (x3 .floatValue (), y3 .floatValue ());
6268
63- context .curveTo (point1 .x , point1 .y ,
64- point3 .x , point3 .y ,
65- point3 .x , point3 .y );
69+ if (currentPoint == null )
70+ {
71+ LOG .warn ("curveTo ({},{}) without initial MoveTo" , point3 .x , point3 .y );
72+ context .moveTo (point3 .x , point3 .y );
73+ }
74+ else
75+ {
76+ context .curveTo (point1 .x , point1 .y ,
77+ point3 .x , point3 .y ,
78+ point3 .x , point3 .y );
79+ }
6680 }
6781
6882 @ Override
0 commit comments