I'm trying to draw an SVG path in a PDF using itextsharp v5.
The approach I am following is roughly this:
- Reading the SVG path from the SVG file (Svg.SvgPath)
- Getting the list of segments from the path ({Svg.Pathing.SvgPathSegmentList})
- Creating an iTextSharp PdfAnnotation and associate a PdfAppearance to it
- Drawing each segment in the SvgPathSegmentList using the corresponding PdfContentByte method ( for SvgLineSegment I use PdfContentByte.LineTo, for SvgCubicCurveSegment I use PdfContentByte.CurveTo )
For most of the SvgPathSegments types, there is a clear mapping between values in the SvgPathSegments and the arguments in the PdfContentByte method. A few examples:
SvgMoveToSegment has the attribute End which is the target point (X, Y) and the PdfContentByte.MoveTo takes two parameters: X, Y
SvgLineSegment, very similar to the Move. It has the Target End and the PdfContentByte.LineTo takes two parameters X and Y and draws a line from the current position to the target point.
app.MoveTo(segment.Start.X, segment.Start.Y);
SvgCubicCurveSegment has all you need to create a Bezier curve (The Start point, the End point, and the first and second control point). With this I use PdfContentByte.CurveTo and get a curve in the PDF that looks exactly as it looks in the SVG editor.
var cubicCurve = (Svg.Pathing.SvgCubicCurveSegment)segment; app.CurveTo( cubicCurve.FirstControlPoint.X, cubicCurve.FirstControlPoint.Y, cubicCurve.SecondControlPoint.X, cubicCurve.SecondControlPoint.Y, cubicCurve.End.X, cubicCurve.End.Y);
The problem I have is with the ARC ("A" command in the SVG, SvgArcSegment)
The SvgArcSegment has the following values:
- Angle
- Start (X, Y)
- End (X, Y)
- RadiusX
- RadiusY
- Start
- Sweep
On the other hand, PdfContentByte.Arc method expect:
- X1, X2, Y1, Y2
- StartAngle,
- Extent
As per the itextsharp documentation, Arc draws a partial ellipse inscribed within the rectangle x1,y1,x2,y2 starting (counter-clockwise) at StartAngle degrees and covering extent degrees. I.e. startAng=0 and extent=180 yield an openside-down semi-circle inscribed in the rectangle.
My question is: How to "map" the values in the SvgArcSegment created from the SVG A command into the arguments that PdfContentByte.Arc method expects. I know that the Start and End values are indeed the origin and target of the curve I want, but no clue what RadiusX and RadiusY mean.