Class CurveTo

java.lang.Object
com.itextpdf.svg.renderers.path.impl.AbstractPathShape
com.itextpdf.svg.renderers.path.impl.CurveTo
All Implemented Interfaces:
IControlPointCurve, IPathShape
Direct Known Subclasses:
SmoothSCurveTo

public class CurveTo extends AbstractPathShape implements IControlPointCurve
Implements curveTo(C) attribute of SVG's path element
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) static final int
     
    private static double
     

    Fields inherited from class com.itextpdf.svg.renderers.path.impl.AbstractPathShape

    coordinates, copier, properties, relative
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    CurveTo(boolean relative)
     
    CurveTo(boolean relative, IOperatorConverter copier)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private static void
    addTValueToList(double t, List<Double> tValuesList)
    Check that t is in the range [0, 1] and add it to list
    private static double
    calculateExtremeCoordinate(double t, double p0, double p1, double p2, double p3)
     
    private static List<Double>
    calculateTValues(double p0, double p1, double p2, double p3)
    Calculate the quadratic function 3a*t^2 + 2b*t + c = 0 to obtain the values of t
    void
    draw(PdfCanvas canvas)
    Draws this instruction to a canvas object.
    private static double[]
    getBezierMinMaxPoints(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3)
    Initial function of cubic bezier is f(t) = (t-1)^3*P0 + 3*(1-t)^2*t*P1 + 3*(1-t)*t^2*P2 + t^3*P3, where 0 invalid input: '<'= t invalid input: '<'= 1 After opening brackets it can be reduced to f(t) = a*t^3 + b*t^2 + c*t + d, where a = P3-3*P2+3*P1-P0 b = 3*P2-6*P1+3*P0 c = 3*P1-3*P0 d = P0 First we must find the values of t at which the function reaches its extreme points.
    private Point
     
    Returns coordinates of the last control point (the one closest to the ending point) in the Bezier curve, in SVG space coordinates
    Get bounding rectangle of the current path shape.
    private static double[]
    getTValuesInExtremePoints(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3)
    Calculate values of t at which the function reaches its extreme points.
    void
    setCoordinates(String[] inputCoordinates, Point startPoint)
    This method sets the coordinates for the path painting operator and does internal preprocessing, if necessary

    Methods inherited from class com.itextpdf.svg.renderers.path.impl.AbstractPathShape

    createPoint, getEndingPoint, isRelative

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ARGUMENT_SIZE

      static final int ARGUMENT_SIZE
      See Also:
    • ZERO_EPSILON

      private static double ZERO_EPSILON
  • Constructor Details

    • CurveTo

      public CurveTo()
    • CurveTo

      public CurveTo(boolean relative)
    • CurveTo

      public CurveTo(boolean relative, IOperatorConverter copier)
  • Method Details

    • draw

      public void draw(PdfCanvas canvas)
      Description copied from interface: IPathShape
      Draws this instruction to a canvas object.
      Specified by:
      draw in interface IPathShape
      Parameters:
      canvas - to which this instruction is drawn
    • setCoordinates

      public void setCoordinates(String[] inputCoordinates, Point startPoint)
      Description copied from interface: IPathShape
      This method sets the coordinates for the path painting operator and does internal preprocessing, if necessary
      Specified by:
      setCoordinates in interface IPathShape
      Parameters:
      inputCoordinates - an array containing point values for path coordinates
      startPoint - the ending point of the previous operator, or, in broader terms, the point that the coordinates should be absolutized against, for relative operators
    • getLastControlPoint

      public Point getLastControlPoint()
      Description copied from interface: IControlPointCurve
      Returns coordinates of the last control point (the one closest to the ending point) in the Bezier curve, in SVG space coordinates
      Specified by:
      getLastControlPoint in interface IControlPointCurve
      Returns:
      coordinates of the last control point in SVG space coordinates
    • getPathShapeRectangle

      public Rectangle getPathShapeRectangle(Point lastPoint)
      Description copied from class: AbstractPathShape
      Get bounding rectangle of the current path shape.
      Specified by:
      getPathShapeRectangle in interface IPathShape
      Overrides:
      getPathShapeRectangle in class AbstractPathShape
      Parameters:
      lastPoint - start point for this shape
      Returns:
      calculated rectangle
    • getFirstControlPoint

      private Point getFirstControlPoint()
    • getBezierMinMaxPoints

      private static double[] getBezierMinMaxPoints(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3)
      Initial function of cubic bezier is f(t) = (t-1)^3*P0 + 3*(1-t)^2*t*P1 + 3*(1-t)*t^2*P2 + t^3*P3, where 0 invalid input: '<'= t invalid input: '<'= 1 After opening brackets it can be reduced to f(t) = a*t^3 + b*t^2 + c*t + d, where a = P3-3*P2+3*P1-P0 b = 3*P2-6*P1+3*P0 c = 3*P1-3*P0 d = P0 First we must find the values of t at which the function reaches its extreme points. This happens in the method getTValuesInExtremePoints(double, double, double, double, double, double, double, double). Next we get x and y values in extremes and compare it with the start and ending points coordinates to get the borders of the bounding box.
      Parameters:
      x0 - x coordinate of the starting point
      y0 - y coordinate of the starting point
      x1 - x coordinate of the first control point
      y1 - y coordinate of the first control point
      x2 - x coordinate of the second control point
      y2 - y coordinate of the second control point
      x3 - x coordinate of the ending point
      y3 - y coordinate of the ending point
      Returns:
      array of {xMin, yMin, xMax, yMax} values
    • getTValuesInExtremePoints

      private static double[] getTValuesInExtremePoints(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3)
      Calculate values of t at which the function reaches its extreme points. To do this, we get the derivative of the function and equate it to 0: f'(t) = 3a*t^2 + 2b*t + c. This is parabola and for finding we calculate the discriminant. t can only be in the range [0, 1] and it discarded otherwise.
      Parameters:
      x0 - x coordinate of the starting point
      y0 - y coordinate of the starting point
      x1 - x coordinate of the first control point
      y1 - y coordinate of the first control point
      x2 - x coordinate of the second control point
      y2 - y coordinate of the second control point
      x3 - x coordinate of the ending point
      y3 - y coordinate of the ending point
      Returns:
      array of theta values corresponding to extreme points
    • calculateTValues

      private static List<Double> calculateTValues(double p0, double p1, double p2, double p3)
      Calculate the quadratic function 3a*t^2 + 2b*t + c = 0 to obtain the values of t
      Parameters:
      p0 - coordinate of the starting point
      p1 - coordinate of the first control point
      p2 - coordinate of the second control point
      p3 - coordinate of the ending point
      Returns:
      list of t values. t should be in range [0, 1]
    • addTValueToList

      private static void addTValueToList(double t, List<Double> tValuesList)
      Check that t is in the range [0, 1] and add it to list
      Parameters:
      t - value of t
      tValuesList - list storing t values
    • calculateExtremeCoordinate

      private static double calculateExtremeCoordinate(double t, double p0, double p1, double p2, double p3)