13
13
# ' used to create the svg, and the computer used to render the
14
14
# ' svg. See the \code{fonts} vignette for more information.
15
15
# '
16
- # ' @param file The file where output will appear.
16
+ # ' @param filename The file where output will appear.
17
17
# ' @param height,width Height and width in inches.
18
18
# ' @param bg Default background color for the plot (defaults to "white").
19
19
# ' @param pointsize Default point size.
20
20
# ' @param standalone Produce a standalone svg file? If \code{FALSE}, omits
21
21
# ' xml header and default namespace.
22
- # ' @param system_fonts Named list of font names to be aliased with
23
- # ' fonts installed on your system. If unspecified, the R default
24
- # ' families \code{sans}, \code{serif}, \code{mono} and \code{symbol}
25
- # ' are aliased to the family returned by
26
- # ' \code{\link[gdtools]{match_family}()}.
27
- # ' @param user_fonts Named list of fonts to be aliased with font files
28
- # ' provided by the user rather than fonts properly installed on the
29
- # ' system. The aliases can be fonts from the fontquiver package,
30
- # ' strings containing a path to a font file, or a list containing
31
- # ' \code{name} and \code{file} elements with \code{name} indicating
32
- # ' the font alias in the SVG output and \code{file} the path to a
33
- # ' font file.
22
+ # ' @param always_valid Should the svgfile be a valid svg file while it is being
23
+ # ' written to? Setting this to `TRUE` will incur a considerable performance
24
+ # ' hit (>50% additional rendering time) so this should only be set to `TRUE`
25
+ # ' if the file is being parsed while it is still being written to.
26
+ # ' @param file Identical to `filename`. Provided for backward compatibility.
34
27
# ' @references \emph{W3C Scalable Vector Graphics (SVG)}:
35
- # ' \url{http://www.w3.org/Graphics/SVG/Overview.htm8 }
28
+ # ' \url{http://www.w3.org/Graphics/SVG/}
36
29
# ' @author This driver was written by T Jake Luciani
37
30
# ' \email{jakeluciani@@yahoo.com} 2012: updated by Matthieu Decorde
38
31
# ' \email{matthieu.decorde@@ens-lyon.fr}
39
32
# ' @seealso \code{\link{pictex}}, \code{\link{postscript}}, \code{\link{Devices}}
33
+ # '
40
34
# ' @examples
41
35
# ' # Save to file
42
- # ' svglite("Rplots.svg")
36
+ # ' svglite(tempfile( "Rplots.svg") )
43
37
# ' plot(1:11, (-5:5)^2, type = 'b', main = "Simple Example")
44
38
# ' dev.off()
45
39
# '
46
- # ' # Supply system font aliases. First check the font can be located:
47
- # ' gdtools::match_family("Verdana")
48
- # '
49
- # ' # Then supply a list of aliases:
50
- # ' fonts <- list(sans = "Verdana", mono = "Times New Roman")
51
- # ' svglite("Rplots.svg", system_fonts = fonts)
52
- # ' plot.new()
53
- # ' text(0.5, 0.5, "Some text", family = "mono")
54
- # ' dev.off()
55
- # '
56
- # ' # See the fonts vignettes for more options to deal with fonts
57
- # '
58
40
# ' @keywords device
59
- # ' @useDynLib svglite
60
- # ' @importFrom Rcpp sourceCpp
61
- # ' @importFrom gdtools raster_view
41
+ # ' @useDynLib svglite, .registration = TRUE
42
+ # ' @importFrom systemfonts match_font
62
43
# ' @export
63
- svglite <- function (file = " Rplots .svg" , width = 10 , height = 8 ,
44
+ svglite <- function (filename = " Rplot%03d .svg" , width = 10 , height = 8 ,
64
45
bg = " white" , pointsize = 12 , standalone = TRUE ,
65
- system_fonts = list (), user_fonts = list ()) {
66
- aliases <- validate_aliases(system_fonts , user_fonts )
67
- invisible (svglite_(file , bg , width , height , pointsize , standalone , aliases ))
46
+ always_valid = FALSE , file ) {
47
+ if (! missing(file )) {
48
+ filename <- file
49
+ }
50
+ if (invalid_filename(filename ))
51
+ stop(" invalid 'file': " , filename )
52
+ invisible (svglite_(filename , bg , width , height , pointsize , standalone , always_valid ))
68
53
}
69
54
70
55
# ' Access current SVG as a string.
@@ -75,7 +60,6 @@ svglite <- function(file = "Rplots.svg", width = 10, height = 8,
75
60
# ' See \code{\link{svglite}()} documentation for information about
76
61
# ' specifying fonts.
77
62
# '
78
- # ' @param ... Arguments passed on to \code{\link{svglite}}.
79
63
# ' @return A function with no arguments: call the function to get the
80
64
# ' current value of the string.
81
65
# ' @examples
@@ -92,19 +76,19 @@ svglite <- function(file = "Rplots.svg", width = 10, height = 8,
92
76
# ' @inheritParams svglite
93
77
# ' @export
94
78
svgstring <- function (width = 10 , height = 8 , bg = " white" ,
95
- pointsize = 12 , standalone = TRUE ,
96
- system_fonts = list (), user_fonts = list ()) {
97
- aliases <- validate_aliases(system_fonts , user_fonts )
98
-
79
+ pointsize = 12 , standalone = TRUE ) {
99
80
env <- new.env(parent = emptyenv())
100
81
string_src <- svgstring_(env , width = width , height = height , bg = bg ,
101
- pointsize = pointsize , standalone = standalone , aliases = aliases )
82
+ pointsize = pointsize , standalone = standalone )
102
83
103
84
function () {
104
- svgstr <- if (env $ is_closed ) env $ svg_string else get_svg_content(string_src )
85
+ svgstr <- env $ svg_string
86
+ if (! env $ is_closed ) {
87
+ svgstr <- c(svgstr , get_svg_content(string_src ))
88
+ }
105
89
structure(svgstr , class = " svg" )
106
90
}
107
91
}
108
92
109
93
# ' @export
110
- print.svg <- function (x , ... ) cat(x , " \n " , sep = " " )
94
+ print.svg <- function (x , ... ) cat(x , sep = " \n " )
0 commit comments