svglite/ 0000755 0001762 0000144 00000000000 14534641075 011740 5 ustar ligges users svglite/NAMESPACE 0000644 0001762 0000144 00000001013 14006257645 013152 0 ustar ligges users # Generated by roxygen2: do not edit by hand
S3method(print,font_face)
S3method(print,svg)
export(create_svgz)
export(editSVG)
export(font_face)
export(font_feature)
export(htmlSVG)
export(register_font)
export(register_variant)
export(stringSVG)
export(svglite)
export(svgstring)
export(xmlSVG)
importFrom(systemfonts,font_feature)
importFrom(systemfonts,font_info)
importFrom(systemfonts,match_font)
importFrom(systemfonts,register_font)
importFrom(systemfonts,register_variant)
useDynLib(svglite, .registration = TRUE)
svglite/tools/ 0000755 0001762 0000144 00000000000 14534342073 013074 5 ustar ligges users svglite/tools/winlibs.R 0000644 0001762 0000144 00000000570 14155671704 014675 0 ustar ligges users VERSION <- commandArgs(TRUE)
if(!file.exists(sprintf("../windows/harfbuzz-%s/include/png.h", VERSION))){
if(getRversion() < "3.3.0") setInternet2()
download.file(sprintf("https://github.com/rwinlib/harfbuzz/archive/v%s.zip", VERSION), "lib.zip", quiet = TRUE)
dir.create("../windows", showWarnings = FALSE)
unzip("lib.zip", exdir = "../windows")
unlink("lib.zip")
}
svglite/README.md 0000644 0001762 0000144 00000010110 14511445574 013211 0 ustar ligges users
# svglite
[](https://github.com/r-lib/svglite/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/r-lib/svglite?branch=main)
[](https://cran.r-project.org/package=svglite)
svglite is a graphics device that produces clean svg output, suitable
for use on the web, or hand editing. Compared to the built-in `svg()`,
svglite produces smaller files, and leaves text as is, making it easier
to edit the result after creation. It also supports multiple nice
features such as embedding of web fonts.
## Installation
svglite is available on CRAN using `install.packages("svglite")`. You
can install the development version from github with:
``` r
# install.packages("pak")
pak::pak("r-lib/svglite")
```
## Motivation
The grDevices package bundled with R already comes with an SVG device
(using the eponymous `svg()` call). The development of svglite is
motivated by the following considerations:
### Speed
`svglite()` is considerably faster than `svg()`. If you are rendering
SVGs dynamically to serve over the web this can be quite important:
``` r
library(svglite)
x <- runif(1e3)
y <- runif(1e3)
tmp1 <- tempfile()
tmp2 <- tempfile()
svglite_test <- function() {
svglite(tmp1)
plot(x, y)
dev.off()
}
svg_test <- function() {
svg(tmp2, onefile = TRUE)
plot(x, y)
dev.off()
}
bench::mark(svglite_test(), svg_test(), min_iterations = 250, check = FALSE)
#> # A tibble: 2 × 6
#> expression min median `itr/sec` mem_alloc `gc/sec`
#>
#> 1 svglite_test() 2.08ms 2.23ms 438. 691KB 7.13
#> 2 svg_test() 6.07ms 6.26ms 159. 179KB 0.638
```
### File size
Another point with high relevance when serving SVGs over the web is the
size. `svglite()` produces much smaller files
``` r
# svglite
fs::file_size(tmp1)
#> 75K
# svg
fs::file_size(tmp2)
#> 321K
```
In both cases, compressing to make `.svgz` (gzipped svg) is worthwhile.
svglite supports compressed output directly which will be triggered if
the provided path has a `".svgz"` (or `".svg.gz"`) extension.
``` r
tmp3 <- tempfile(fileext = ".svgz")
svglite(tmp3)
plot(x, y)
invisible(dev.off())
# svglite - svgz
fs::file_size(tmp3)
#> 9.42K
```
### Editability
One of the main reasons for the size difference between the size of the
output of `svglite()` and `svg()` is the fact that `svglite()` encodes
text as styled `` elements, whereas `svg()` converts the glyphs to
polygons and renders these. The latter approach means that the output of
`svg()` does not require the font to be present on the system that
displays the SVG but makes it more or less impossible to edit the text
after the fact. svglite focuses on providing maximal editability of the
output, so that you can open up the result in a vector drawing program
such as Inkscape or Illustrator and polish the output if you so choose.
### Font support
svglite uses systemfonts for font discovery which means that all
installed fonts on your system is available to use. The systemfonts
foundation means that fonts registered with `register_font()` or
`register_variant()` will also be available. If any of these contains
non-standard weights or OpenType features (e.g. ligatures or tabular
numerics) this will be correctly encoded in the style block. systemfonts
also allows you to embed webfont `@imports` in your file to ensure that
the file looks as expected even on systems without the used font
installed.
## Code of Conduct
Please note that the svglite project is released with a [Contributor
Code of Conduct](https://svglite.r-lib.org/CODE_OF_CONDUCT.html). By
contributing to this project, you agree to abide by its terms.
svglite/man/ 0000755 0001762 0000144 00000000000 14534576401 012513 5 ustar ligges users svglite/man/svgstring.Rd 0000644 0001762 0000144 00000007173 14511445621 015032 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/SVG.R
\name{svgstring}
\alias{svgstring}
\title{Access current SVG as a string.}
\usage{
svgstring(
width = 10,
height = 8,
bg = "white",
pointsize = 12,
standalone = TRUE,
system_fonts = list(),
user_fonts = list(),
web_fonts = list(),
id = NULL,
fix_text_size = TRUE,
scaling = 1
)
}
\arguments{
\item{height, width}{Height and width in inches.}
\item{bg}{Default background color for the plot (defaults to "white").}
\item{pointsize}{Default point size.}
\item{standalone}{Produce a standalone svg file? If \code{FALSE}, omits
xml header and default namespace.}
\item{system_fonts}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}} \emph{Consider using
\code{\link[systemfonts:register_font]{systemfonts::register_font()}} instead}. Named list of font
names to be aliased with fonts installed on your system. If unspecified,
the R default families \code{sans}, \code{serif}, \code{mono} and
\code{symbol} are aliased to the family returned by
\code{\link[systemfonts]{font_info}()}.}
\item{user_fonts}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}} \emph{Consider using
\code{\link[systemfonts:register_font]{systemfonts::register_font()}} instead}. Named list of fonts to
be aliased with font files provided by the user rather than fonts properly
installed on the system. The aliases can be fonts from the fontquiver
package, strings containing a path to a font file, or a list containing
\code{name} and \code{file} elements with \code{name} indicating
the font alias in the SVG output and \code{file} the path to a
font file.}
\item{web_fonts}{A list containing web fonts to use in the SVG. The fonts
will still need to be available locally on the computer running the code,
but viewers of the final SVG will not need the font if specified as a web
font. Web fonts can either be specified using \code{\link[=font_face]{font_face()}} or given as a
single string in which case they are taken to be URL's for an \verb{@import}
directive to e.g. Google Fonts.}
\item{id}{A character vector of ids to assign to the generated SVG's. If
creating more SVG files than supplied ids the exceeding SVG's will not have
an id tag and a warning will be thrown.}
\item{fix_text_size}{Should the width of strings be fixed so that it doesn't
change between svg renderers depending on their font rendering? Defaults to
\code{TRUE}. If \code{TRUE} each string will have the \code{textLength} CSS property set
to the width calculated by systemfonts and
\code{lengthAdjust='spacingAndGlyphs'}. Setting this to \code{FALSE} can be
beneficial for heavy post-processing that may change content or style of
strings, but may lead to inconsistencies between strings and graphic
elements that depend on the dimensions of the string (e.g. label borders
and background).}
\item{scaling}{A scaling factor to apply to the rendered line width and text
size. Useful for getting the right sizing at the dimension that you
need.}
}
\value{
A function with no arguments: call the function to get the
current value of the string.
}
\description{
This is a variation on \code{\link{svglite}} that makes it easy to access
the current value as a string.
}
\details{
See \code{\link{svglite}()} documentation for information about
specifying fonts.
}
\examples{
s <- svgstring()
s()
plot.new()
s()
text(0.5, 0.5, "Hi!")
s()
dev.off()
s <- svgstring()
plot(rnorm(5), rnorm(5))
s()
dev.off()
}
svglite/man/xmlSVG.Rd 0000644 0001762 0000144 00000001401 14357213724 014155 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/inlineSVG.R
\name{xmlSVG}
\alias{xmlSVG}
\title{Run plotting code and return svg}
\usage{
xmlSVG(code, ..., standalone = FALSE, height = 7, width = 7)
}
\arguments{
\item{code}{Plotting code to execute.}
\item{...}{Other arguments passed on to \code{\link{svglite}}.}
\item{standalone}{Produce a standalone svg file? If \code{FALSE}, omits
xml header and default namespace.}
\item{height, width}{Height and width in inches.}
}
\value{
A \code{xml2::xml_document} object.
}
\description{
This is useful primarily for testing. Requires the \code{xml2} package.
}
\examples{
if (require("xml2")) {
x <- xmlSVG(plot(1, axes = FALSE))
x
xml_find_all(x, ".//text")
}
}
\keyword{internal}
svglite/man/figures/ 0000755 0001762 0000144 00000000000 14534576401 014157 5 ustar ligges users svglite/man/figures/README-unnamed-chunk-3-1.png 0000644 0001762 0000144 00000067177 14006275101 020660 0 ustar ligges users PNG
IHDR z4 iCCPkCGColorSpaceGenericRGB 8U]hU>+$Ԧ5lRфem,lAݝi&3i)>A['!j-P(G 3k~s,[%,-:t}
}-+*&¿ gPG݅ج8"e Ų]A b ;l õ Wϙ2_E,(ۈ#Zsێ<5)"E6N#ӽEkۃO0}*rUt.iei # ]r
>cU{t7+ԙg߃xu