swftools-common
[Top][All Lists]

## Re: [Swftools-common] swfc: Importing SVG elliptical arcs

 From: Vladimir Dzhuvinov Subject: Re: [Swftools-common] swfc: Importing SVG elliptical arcs Date: Mon, 26 Nov 2007 10:50:29 +0200 User-agent: Thunderbird 2.0.0.6 (X11/20070728)

```Jeez, I wanted to spend a pleasant day with no mention of geometry
whatsoever ;)

Yes, I now see the lib/drawer.c:draw_conicTo() function that tries to
solve the geometrical problem of "drawing an arc through 3 points".

It, however, does not check itself whether the arc hasn't gone through
more than a 90 deg angle.

Further down, in draw_string() you call this function to construct a
"circle" given its (x,y) centre and radius. There, before calling
draw_conicTo2() you make sure that the circle is broken down into four
90 degree segments.

According to
http://www.w3.org/TR/SVG11/paths.html#PathDataGeneralInformation the SVG
"Arc" command has the following parameters:

1. the r(x) and r(y) radii
2. the x-axis-rotation
3. large-arc-flag
4. sweep-flag
5. x,y end-point

Hm, let's now see what we have to do to transform the SVG:A command
parameters to the draw_conicTo() parameters:

We have the start and ending points -> good, so we only ;) have to do
the following:

1. Check angle of SVG arc. Break it down into 90 deg. segments if necessary.

2. Find a midpoint on the arc between start and end point.

I can't tell now in what reasonable order (1) and (2) should be tackled.
In any case, it seems that we cannot get around finding the ellipse
(x,y)centre given the A parameters.

Do you think it would be worth digging into the Inkscape codebase for clues?

>> Basically, in Inkscape I noticed that when I drew a smaller object (e.g.
>> rectangle) within the ellipse/circle and did a union of the two - the
>> resulting object - which should obviously have the unmodified outline of
>> the outer ellipse/circle, was no longer described with "arc" commands,
>> but instead with 4 usual "C" (bezier)commands which swfc understands well.
>
> Interesting. Probably Inkscape does the "union" operation on splines (or
> even lines), and hence before applying the union converts all Arcs to
> Beziers.
>
>> The first thing that came to my mind was to approximate the arcs with
>> bezier curves that you have already programmed into swftools.
>
> That's not needed- swftools already has a way to draw Arcs. The
> routine is called "conicTo". It approximates an arc using a 3rd-order
> bezier. (which is then internally converted back to a number of 2nd-order
> beziers at some point)
> It only works reliably for arcs smaller than 90°, though, which is
>
>> Tellingly, I also found a message
>> [http://uncommonplace.com/blog/?p=254#comment-1453] saying that Inkscape
>> was in fact using this approximation method to draw elliptical arcs by
>> using a bezier for every 90 deg.
>
> So I guess the SVG code would need to call that routine four times.

--
Vladimir Dzhuvinov * www.TheTransactionCompany.com * PGP key ID AC9A5C6C

```

signature.asc
Description: OpenPGP digital signature