reader: Reading and writing svg files

readerR Documentation

Reading and writing svg files

Description

Various utilities for reading and creating svg files for use with inkscape

Usage

reader(filename)
write_svg(k, oldfile, safe=TRUE,
    regex1 ='sodipodi:docname=',
    regex2=' *d *= *" *M.*C.*[zZ] *"')

Arguments

filename

Name of a file to be read by reader(); usually an inkscape .svg file

safe

Boolean, with default TRUE meaning to save file “foo.svg” as “foo_smooth.svg” and FALSE meaning to overwrite foo.svg.

k, oldfile, regex1, regex2

Various arguments sent to write_svg(); see the source code for details. Argument k is a knot, oldfile an .svg file for reference.

Details

Function reader() is the way to get started with a new knot. This takes a filename which is an .svg file created with inkscape. Instructions for creating a suitable inkscape file are given in knotR-package.Rd.

Note

Inkscape's default is to use a mixture of absolute and relative coordinates. Function reader() assumes that the .svg file uses only absolute coordinates.

To ensure that only absolute coordinates are used, open the ‘SVG output’ menu in ‘inkscape preferences’ and uncheck the “Allow relative coordinates” option.

The format of .svg file is described in the W3C recommendation (2011) for Scalable Vector Graphics (SVG) 1.1, second edition.

Sometimes, reader() will fail with a valid .svg file if a node is sufficiently close to the x or y axis to require exponential notation (this typically happens with complicated rotational symmetry). If the file contains text like

...35.3635879230533 -1.323423734554e-15 , 10.3538368384142...

the second value is zero to numerical precision, but the text form of the number interferes with the operation of reader(). To deal with this we need to edit the file in a text editor and replace the offending number with an exact zero:

...35.3635879230533 0 , 10.3538368384142...

(I guess the ideal would be to incorporate some clever regexp technique into reader() but this turned out to be harder than I thought).

Author(s)

Robin K. S. Hankin

See Also

utilities,knotR-package

Examples

## Not run: 
a <- reader("6_3.svg")
b <- getcontrolpoints(a)
knotplot(a)


## End(Not run)

knotR documentation built on June 22, 2024, 6:56 p.m.