.
gdtools/tools/ 0000755 0001762 0000144 00000000000 14512740476 013077 5 ustar ligges users gdtools/tools/winlibs.R 0000644 0001762 0000144 00000001574 14512740476 014700 0 ustar ligges users if(!file.exists("../windows/cairo/include/cairo/cairo.h")){
unlink("../windows", recursive = TRUE)
url <- if(grepl("aarch", R.version$platform)){
"https://github.com/r-windows/bundles/releases/download/cairo-1.18.0/cairo-1.18.0-clang-aarch64.tar.xz"
} else if(grepl("clang", Sys.getenv('R_COMPILED_BY'))){
"https://github.com/r-windows/bundles/releases/download/cairo-1.18.0/cairo-1.18.0-clang-x86_64.tar.xz"
} else if(getRversion() >= "4.2") {
"https://github.com/r-windows/bundles/releases/download/cairo-1.18.0/cairo-1.18.0-ucrt-x86_64.tar.xz"
} else {
"https://github.com/rwinlib/cairo/archive/v1.16.0.tar.gz"
}
download.file(url, basename(url), quiet = TRUE)
dir.create("../windows", showWarnings = FALSE)
untar(basename(url), exdir = "../windows", tar = 'internal')
unlink(basename(url))
setwd("../windows")
file.rename(list.files(), 'cairo')
}
gdtools/README.md 0000644 0001762 0000144 00000004007 14535106106 013206 0 ustar ligges users
# gdtools
[](https://CRAN.R-project.org/package=gdtools)
[](https://github.com/davidgohel/gdtools/actions)
[](https://app.codecov.io/gh/davidgohel/gdtools)
The package `gdtools` provides functionalities to get font metrics and
to generate base64 encoded string from raster matrix. It is used by
package ‘flextable’ and ‘rvg’ to allow font metric calculation but can
also be used to compute the exact size a text would have with specific
font options (size, bold, italic).
``` r
library(gdtools)
str_extents(c("a string", "a longer string"),
fontsize = 24, bold = TRUE, italic = TRUE)
#> [,1] [,2]
#> [1,] 86.68359 22.60547
#> [2,] 166.68750 22.60547
```
Another set of functions is provided to support the collection of fonts
from ‘Google Fonts’ in a cache. Their use is simple within ‘R Markdown’
documents and ‘shiny’ applications but also with graphic productions
generated with the ‘ggiraph’, ‘ragg’ and ‘svglite’ packages or with
tabular productions from the ‘flextable’ package.
``` r
# Download to a user cache and register the font with systemfonts
register_gfont(family = "Open Sans")
```
If you need a ‘Google Font’ to be installed on your machine, you can use
`install_gfont_script()`.
``` r
install_gfont_script("Fira Sans", file = "firafont.sh")
```
You then have to run `./firafont.sh`.
## Installation
You can install the released version of gdtools from
[CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("gdtools")
```
And the development version from
[GitHub](https://github.com/davidgohel/gdtools) with:
``` r
# install.packages("remotes")
remotes::install_github("davidgohel/gdtools")
```
gdtools/man/ 0000755 0001762 0000144 00000000000 14512757245 012514 5 ustar ligges users gdtools/man/str_extents.Rd 0000644 0001762 0000144 00000001317 14373642552 015366 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/str-metrics.R
\name{str_extents}
\alias{str_extents}
\title{Compute string extents.}
\usage{
str_extents(
x,
fontname = "sans",
fontsize = 12,
bold = FALSE,
italic = FALSE,
fontfile = ""
)
}
\arguments{
\item{x}{Character vector of strings to measure}
\item{fontname}{Font name}
\item{fontsize}{Font size}
\item{bold, italic}{Is text bold/italic?}
\item{fontfile}{Font file}
}
\description{
Determines the width and height of a bounding box that's big enough
to (just) enclose the provided text.
}
\examples{
str_extents(letters)
str_extents("Hello World!", bold = TRUE, italic = FALSE,
fontname = "sans", fontsize = 12)
}
gdtools/man/register_liberationsans.Rd 0000644 0001762 0000144 00000001521 14402665446 017722 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/font-caching.R
\name{register_liberationsans}
\alias{register_liberationsans}
\title{Register font 'Liberation Sans'}
\usage{
register_liberationsans()
}
\value{
TRUE if the operation went ok.
}
\description{
Register font 'Liberation Sans' so that it can be used
with devices using the 'systemfonts' package, i.e. the 'flextable'
package and graphic outputs generated with the 'ragg', 'svglite'
and 'ggiraph' packages.
}
\seealso{
Other functions for font management:
\code{\link{addGFontHtmlDependency}()},
\code{\link{fonts_cache_dir}()},
\code{\link{gfontHtmlDependency}()},
\code{\link{install_gfont_script}()},
\code{\link{installed_gfonts}()},
\code{\link{liberationsansHtmlDependency}()},
\code{\link{register_gfont}()}
}
\concept{functions for font management}
gdtools/man/sys_fonts.Rd 0000644 0001762 0000144 00000000537 14373655307 015040 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/font_family_exists.R
\name{sys_fonts}
\alias{sys_fonts}
\title{List fonts for 'systemfonts'.}
\usage{
sys_fonts()
}
\description{
List system and registryfonts details into a data.frame
containing columns foundry, family, file, slant and weight.
}
\examples{
sys_fonts()
}
gdtools/man/liberationsansHtmlDependency.Rd 0000644 0001762 0000144 00000001375 14402665446 020651 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fonts.R
\name{liberationsansHtmlDependency}
\alias{liberationsansHtmlDependency}
\title{'Liberation Sans' Font HTML dependency}
\usage{
liberationsansHtmlDependency()
}
\description{
Create an HTML dependency ready
to be used in 'Shiny' or 'R Markdown' with
'Liberation Sans' Font.
}
\seealso{
\code{\link[=gfontHtmlDependency]{gfontHtmlDependency()}}
Other functions for font management:
\code{\link{addGFontHtmlDependency}()},
\code{\link{fonts_cache_dir}()},
\code{\link{gfontHtmlDependency}()},
\code{\link{install_gfont_script}()},
\code{\link{installed_gfonts}()},
\code{\link{register_gfont}()},
\code{\link{register_liberationsans}()}
}
\concept{functions for font management}
gdtools/man/m_str_extents.Rd 0000644 0001762 0000144 00000002170 14373642552 015700 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/str-metrics.R
\name{m_str_extents}
\alias{m_str_extents}
\title{Compute string extents for a vector of string.}
\usage{
m_str_extents(
x,
fontname = "sans",
fontsize = 10,
bold = FALSE,
italic = FALSE,
fontfile = NULL
)
}
\arguments{
\item{x}{Character vector of strings to measure}
\item{fontname}{Font name. A vector of character to match with x.}
\item{fontsize}{Font size. A vector of numeric to match with x.}
\item{bold, italic}{Is text bold/italic?. A vector of logical to match with x.}
\item{fontfile}{Font file. A vector of character to match with x.}
}
\description{
For each \code{x} element, determines the width and height of a bounding box that's big enough
to (just) enclose the provided text. Unit is pixel.
}
\examples{
\donttest{
# The first run can be slow when font caches are missing
# as font files are then being scanned to build those font caches.
m_str_extents(letters, fontsize = 1:26)
m_str_extents(letters[1:3],
bold = c(TRUE, FALSE, TRUE),
italic = c(FALSE, TRUE, TRUE),
fontname = c("sans", "sans", "sans") )
}
}
gdtools/man/fontconfig_reinit.Rd 0000644 0001762 0000144 00000000654 14360611071 016501 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fontconfig.R
\name{fontconfig_reinit}
\alias{fontconfig_reinit}
\title{reload Fontconfig configuration}
\usage{
fontconfig_reinit()
}
\description{
This function can be used to make fontconfig
reload font configuration files.
}
\note{
Fontconfig is not used anymore and that function will be deprecated
in the next release.
}
\author{
Paul Murrell
}
gdtools/man/install_gfont_script.Rd 0000644 0001762 0000144 00000005314 14535104355 017226 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fonts.R
\name{install_gfont_script}
\alias{install_gfont_script}
\title{Shell command to install a font from 'Google Fonts'}
\usage{
install_gfont_script(
family = "Open Sans",
subset = c("latin", "latin-ext"),
platform = c("debian", "windows", "macos"),
file = NULL
)
}
\arguments{
\item{family}{family name of a 'Google Fonts', for example, "Open Sans", "Roboto",
"Fira Code" or "Fira Sans Condensed". Complete list is available with the
following command:
\if{html}{\out{}}\preformatted{gfonts::get_all_fonts()$family |>
unlist() |>
unique() |>
sort()
}\if{html}{\out{
}}}
\item{subset}{font subset, a character vector, it defaults to only "latin" and
"latin-ext" and can contains values such as "greek", "emoji", "chinese-traditional",
Run the following code to get a complete list:
\if{html}{\out{}}\preformatted{gfonts::get_all_fonts()$subsets |> unlist() |> unique() |> sort()
}\if{html}{\out{
}}}
\item{platform}{"debian" and "windows" and "macos" are supported.}
\item{file}{script file to generate, optional. If the parameter is
specified, a file will be generated ready for execution. If the
platform is Windows, administration rights are required to run
the script.}
}
\value{
the 'shell' or 'PowerShell' command as a string
}
\description{
Create a string containing a system command to execute
so that the font from 'Google Fonts' is installed on the system.
Its execution may require root permissions, in dockerfile for example.
}
\details{
It allows users to use fonts from 'Google Fonts' in an HTML page generated by 'shiny' or 'R Markdown'.
At the first request, the font files will be downloaded and stored in a cache on the
user's machine, thus avoiding many useless downloads or allowing to work with
these fonts afterwards without an Internet connection, in a docker image for example.
See \code{\link[=fonts_cache_dir]{fonts_cache_dir()}}.
The server delivering the font files should not be too busy. That's
why a one second pause is added after each download to respect the server's
limits. This time can be set with the option \code{GFONTS_DOWNLOAD_SLEEPTIME} which
must be a number of seconds.
}
\examples{
\dontrun{
if (curl::has_internet()) {
dummy_setup()
install_gfont_script(family = "Roboto", platform = "macos")
}
}
}
\seealso{
Other functions for font management:
\code{\link{addGFontHtmlDependency}()},
\code{\link{fonts_cache_dir}()},
\code{\link{gfontHtmlDependency}()},
\code{\link{installed_gfonts}()},
\code{\link{liberationsansHtmlDependency}()},
\code{\link{register_gfont}()},
\code{\link{register_liberationsans}()}
}
\concept{functions for font management}
gdtools/man/glyphs_match.Rd 0000644 0001762 0000144 00000001265 14373642552 015470 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/str-metrics.R
\name{glyphs_match}
\alias{glyphs_match}
\title{Validate glyph entries}
\usage{
glyphs_match(x, fontname = "sans", bold = FALSE, italic = FALSE, fontfile = "")
}
\arguments{
\item{x}{Character vector of strings}
\item{fontname}{Font name}
\item{bold, italic}{Is text bold/italic?}
\item{fontfile}{Font file}
}
\value{
a logical vector, if a character element is containing at least
a glyph that can not be matched in the font table, FALSE is returned.
}
\description{
Determines if strings contain glyphs not part of a font.
}
\examples{
glyphs_match(letters)
glyphs_match("\u265E", bold = TRUE)
}
gdtools/man/raster_write.Rd 0000644 0001762 0000144 00000001310 14360611071 015473 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/raster.R
\name{raster_write}
\alias{raster_write}
\title{Draw/preview a raster to a png file}
\usage{
raster_write(x, path, width = 480, height = 480, interpolate = FALSE)
}
\arguments{
\item{x}{A raster object}
\item{path}{name of the file to create}
\item{width, height}{Width and height in pixels.}
\item{interpolate}{A logical value indicating whether to linearly
interpolate the image.}
}
\description{
Draw/preview a raster to a png file
}
\examples{
r <- as.raster(matrix(hcl(0, 80, seq(50, 80, 10)),
nrow = 4, ncol = 5))
filepng <- tempfile(fileext = ".png")
raster_write(x = r, path = filepng, width = 50, height = 50)
}
gdtools/man/dummy_setup.Rd 0000644 0001762 0000144 00000000420 14360635440 015343 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/font-caching.R
\name{dummy_setup}
\alias{dummy_setup}
\title{dummy 'Google Fonts' cache}
\usage{
dummy_setup()
}
\description{
dummy 'Google Fonts' cache
used for examples.
}
\keyword{internal}
gdtools/man/addGFontHtmlDependency.Rd 0000644 0001762 0000144 00000004620 14512757245 017317 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fonts.R
\name{addGFontHtmlDependency}
\alias{addGFontHtmlDependency}
\title{Use a font in Shiny or Markdown}
\usage{
addGFontHtmlDependency(family = "Open Sans", subset = c("latin", "latin-ext"))
}
\arguments{
\item{family}{family name of a 'Google Fonts', for example, "Open Sans", "Roboto",
"Fira Code" or "Fira Sans Condensed". Complete list is available with the
following command:
\if{html}{\out{}}\preformatted{gfonts::get_all_fonts()$family |>
unlist() |>
unique() |>
sort()
}\if{html}{\out{
}}}
\item{subset}{font subset, a character vector, it defaults to only "latin" and
"latin-ext" and can contains values such as "greek", "emoji", "chinese-traditional",
Run the following code to get a complete list:
\if{html}{\out{}}\preformatted{gfonts::get_all_fonts()$subsets |> unlist() |> unique() |> sort()
}\if{html}{\out{
}}}
}
\value{
an HTML object
}
\description{
Add an empty HTML element attached
to an 'HTML Dependency' containing
the css and the font files so that the font is available
in the HTML page. Multiple families are supported.
The htmlDependency is defined with function \code{\link[=gfontHtmlDependency]{gfontHtmlDependency()}}.
}
\details{
It allows users to use fonts from 'Google Fonts' in an HTML page generated by 'shiny' or 'R Markdown'.
At the first request, the font files will be downloaded and stored in a cache on the
user's machine, thus avoiding many useless downloads or allowing to work with
these fonts afterwards without an Internet connection, in a docker image for example.
See \code{\link[=fonts_cache_dir]{fonts_cache_dir()}}.
The server delivering the font files should not be too busy. That's
why a one second pause is added after each download to respect the server's
limits. This time can be set with the option \code{GFONTS_DOWNLOAD_SLEEPTIME} which
must be a number of seconds.
}
\examples{
\dontrun{
if (curl::has_internet()) {
dummy_setup()
addGFontHtmlDependency(family = "Open Sans")
}
}
}
\seealso{
Other functions for font management:
\code{\link{fonts_cache_dir}()},
\code{\link{gfontHtmlDependency}()},
\code{\link{install_gfont_script}()},
\code{\link{installed_gfonts}()},
\code{\link{liberationsansHtmlDependency}()},
\code{\link{register_gfont}()},
\code{\link{register_liberationsans}()}
}
\concept{functions for font management}
gdtools/man/match_family.Rd 0000644 0001762 0000144 00000001137 14360611071 015425 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fontconfig.R
\name{match_family}
\alias{match_family}
\title{Find best family match with systemfonts}
\usage{
match_family(font = "sans", bold = TRUE, italic = TRUE, debug = NULL)
}
\arguments{
\item{font}{family or face to match.}
\item{bold}{Wheter to match a font featuring a \code{bold} face.}
\item{italic}{Wheter to match a font featuring an \code{italic} face.}
\item{debug}{deprecated}
}
\description{
\code{match_family()} returns the best font family match.
}
\examples{
match_family("sans")
match_family("serif")
}
gdtools/man/version_cairo.Rd 0000644 0001762 0000144 00000000672 14360611071 015635 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/RcppExports.R, R/gdtools.R
\name{version_freetype}
\alias{version_freetype}
\alias{version_cairo}
\title{Version numbers of C libraries}
\usage{
version_freetype()
version_cairo()
}
\description{
\code{version_cairo()} and \code{version_freetype()} return the
runtime version. These helpers return version objects as with
\code{\link[utils]{packageVersion}()}.
}
gdtools/man/font_family_exists.Rd 0000644 0001762 0000144 00000000757 14360611071 016705 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/font_family_exists.R
\name{font_family_exists}
\alias{font_family_exists}
\title{Check if font family exists.}
\usage{
font_family_exists(font_family = "sans")
}
\arguments{
\item{font_family}{font family name (case sensitive)}
}
\value{
A logical value
}
\description{
Check if a font family exists in system fonts.
}
\examples{
font_family_exists("sans")
font_family_exists("Arial")
font_family_exists("Courier")
}
gdtools/man/installed_gfonts.Rd 0000644 0001762 0000144 00000001472 14512757245 016346 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fonts.R
\name{installed_gfonts}
\alias{installed_gfonts}
\title{List installed 'Google Fonts'}
\usage{
installed_gfonts()
}
\value{
families names as a character vector
}
\description{
List installed 'Google Fonts' that can be
found in the user cache directory.
}
\examples{
\dontrun{
if (curl::has_internet()) {
dummy_setup()
register_gfont(family = "Roboto")
installed_gfonts()
}
}
}
\seealso{
Other functions for font management:
\code{\link{addGFontHtmlDependency}()},
\code{\link{fonts_cache_dir}()},
\code{\link{gfontHtmlDependency}()},
\code{\link{install_gfont_script}()},
\code{\link{liberationsansHtmlDependency}()},
\code{\link{register_gfont}()},
\code{\link{register_liberationsans}()}
}
\concept{functions for font management}
gdtools/man/register_gfont.Rd 0000644 0001762 0000144 00000004474 14512757245 016035 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fonts.R
\name{register_gfont}
\alias{register_gfont}
\title{Register a 'Google Fonts'}
\usage{
register_gfont(family = "Open Sans", subset = c("latin", "latin-ext"))
}
\arguments{
\item{family}{family name of a 'Google Fonts', for example, "Open Sans", "Roboto",
"Fira Code" or "Fira Sans Condensed". Complete list is available with the
following command:
\if{html}{\out{}}\preformatted{gfonts::get_all_fonts()$family |>
unlist() |>
unique() |>
sort()
}\if{html}{\out{
}}}
\item{subset}{font subset, a character vector, it defaults to only "latin" and
"latin-ext" and can contains values such as "greek", "emoji", "chinese-traditional",
Run the following code to get a complete list:
\if{html}{\out{}}\preformatted{gfonts::get_all_fonts()$subsets |> unlist() |> unique() |> sort()
}\if{html}{\out{
}}}
}
\value{
TRUE if the operation went ok.
}
\description{
Register a font from 'Google Fonts' so that it can be used
with devices using the 'systemfonts' package, i.e. the 'flextable'
package and graphic outputs generated with the 'ragg', 'svglite'
and 'ggiraph' packages.
}
\details{
It allows users to use fonts from 'Google Fonts' in an HTML page generated by 'shiny' or 'R Markdown'.
At the first request, the font files will be downloaded and stored in a cache on the
user's machine, thus avoiding many useless downloads or allowing to work with
these fonts afterwards without an Internet connection, in a docker image for example.
See \code{\link[=fonts_cache_dir]{fonts_cache_dir()}}.
The server delivering the font files should not be too busy. That's
why a one second pause is added after each download to respect the server's
limits. This time can be set with the option \code{GFONTS_DOWNLOAD_SLEEPTIME} which
must be a number of seconds.
}
\examples{
\dontrun{
if (curl::has_internet()) {
dummy_setup()
register_gfont(family = "Roboto")
}
}
}
\seealso{
Other functions for font management:
\code{\link{addGFontHtmlDependency}()},
\code{\link{fonts_cache_dir}()},
\code{\link{gfontHtmlDependency}()},
\code{\link{install_gfont_script}()},
\code{\link{installed_gfonts}()},
\code{\link{liberationsansHtmlDependency}()},
\code{\link{register_liberationsans}()}
}
\concept{functions for font management}
gdtools/man/str_metrics.Rd 0000644 0001762 0000144 00000001127 14373642552 015341 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/str-metrics.R
\name{str_metrics}
\alias{str_metrics}
\title{Get font metrics for a string.}
\usage{
str_metrics(
x,
fontname = "sans",
fontsize = 12,
bold = FALSE,
italic = FALSE,
fontfile = ""
)
}
\arguments{
\item{x}{Character vector of strings to measure}
\item{fontname}{Font name}
\item{fontsize}{Font size}
\item{bold, italic}{Is text bold/italic?}
\item{fontfile}{Font file}
}
\value{
A named numeric vector
}
\description{
Get font metrics for a string.
}
\examples{
str_metrics("Hello World!")
}
gdtools/man/raster_str.Rd 0000644 0001762 0000144 00000001534 14360611071 015161 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/raster.R
\name{raster_str}
\alias{raster_str}
\alias{raster_view}
\title{Draw/preview a raster into a string}
\usage{
raster_str(x, width = 480, height = 480, interpolate = FALSE)
raster_view(code)
}
\arguments{
\item{x}{A raster object}
\item{width, height}{Width and height in pixels.}
\item{interpolate}{A logical value indicating whether to linearly
interpolate the image.}
\item{code}{base64 code of a raster}
}
\description{
\code{raster_view} is a helper function for testing. It uses \code{htmltools}
to render a png as an image with base64 encoded data image.
}
\examples{
r <- as.raster(matrix(hcl(0, 80, seq(50, 80, 10)),
nrow = 4, ncol = 5))
code <- raster_str(r, width = 50, height = 50)
if (interactive() && require("htmltools")) {
raster_view(code = code)
}
}
gdtools/man/fonts_cache_dir.Rd 0000644 0001762 0000144 00000002651 14402665446 016120 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/font-caching.R
\name{fonts_cache_dir}
\alias{fonts_cache_dir}
\alias{rm_fonts_cache}
\alias{init_fonts_cache}
\title{manage font working directory}
\usage{
fonts_cache_dir()
rm_fonts_cache()
init_fonts_cache()
}
\description{
Initialize or remove font directory used
to store downloaded font files.
This directory is managed by R function \code{\link[=R_user_dir]{R_user_dir()}} but can also
be defined in a non-user location by setting ENV variable \code{GDTOOLS_CACHE_DIR}
or by setting R option \code{GDTOOLS_CACHE_DIR}.
Its value can be read with the \code{fonts_cache_dir()} function.
The directory can be deleted with \code{rm_fonts_cache()} and
created with \code{init_fonts_cache()}.
}
\examples{
fonts_cache_dir()
options(GDTOOLS_CACHE_DIR = tempdir())
fonts_cache_dir()
options(GDTOOLS_CACHE_DIR = NULL)
Sys.setenv(GDTOOLS_CACHE_DIR=tempdir())
fonts_cache_dir()
Sys.setenv(GDTOOLS_CACHE_DIR="")
init_fonts_cache()
dir.exists(fonts_cache_dir())
rm_fonts_cache()
dir.exists(fonts_cache_dir())
}
\seealso{
Other functions for font management:
\code{\link{addGFontHtmlDependency}()},
\code{\link{gfontHtmlDependency}()},
\code{\link{install_gfont_script}()},
\code{\link{installed_gfonts}()},
\code{\link{liberationsansHtmlDependency}()},
\code{\link{register_gfont}()},
\code{\link{register_liberationsans}()}
}
\concept{functions for font management}
gdtools/man/set_dummy_conf.Rd 0000644 0001762 0000144 00000000670 14360611071 016004 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fontconfig.R
\name{set_dummy_conf}
\alias{set_dummy_conf}
\alias{unset_dummy_conf}
\title{Set and unset a minimalistic Fontconfig configuration}
\usage{
set_dummy_conf()
unset_dummy_conf()
}
\description{
Set and unset a minimalistic Fontconfig configuration
}
\note{
Fontconfig is not used anymore and these functions will be deprecated
in the next release.
}
gdtools/man/gfontHtmlDependency.Rd 0000644 0001762 0000144 00000004353 14512757245 016751 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fonts.R
\name{gfontHtmlDependency}
\alias{gfontHtmlDependency}
\title{'Google Font' HTML dependency}
\usage{
gfontHtmlDependency(family = "Open Sans", subset = c("latin", "latin-ext"))
}
\arguments{
\item{family}{family name of a 'Google Fonts', for example, "Open Sans", "Roboto",
"Fira Code" or "Fira Sans Condensed". Complete list is available with the
following command:
\if{html}{\out{}}\preformatted{gfonts::get_all_fonts()$family |>
unlist() |>
unique() |>
sort()
}\if{html}{\out{
}}}
\item{subset}{font subset, a character vector, it defaults to only "latin" and
"latin-ext" and can contains values such as "greek", "emoji", "chinese-traditional",
Run the following code to get a complete list:
\if{html}{\out{}}\preformatted{gfonts::get_all_fonts()$subsets |> unlist() |> unique() |> sort()
}\if{html}{\out{
}}}
}
\value{
an object defined with \code{\link[=htmlDependency]{htmlDependency()}}.
}
\description{
Create an HTML dependency ready
to be used in 'Shiny' or 'R Markdown'.
}
\details{
It allows users to use fonts from 'Google Fonts' in an HTML page generated by 'shiny' or 'R Markdown'.
At the first request, the font files will be downloaded and stored in a cache on the
user's machine, thus avoiding many useless downloads or allowing to work with
these fonts afterwards without an Internet connection, in a docker image for example.
See \code{\link[=fonts_cache_dir]{fonts_cache_dir()}}.
The server delivering the font files should not be too busy. That's
why a one second pause is added after each download to respect the server's
limits. This time can be set with the option \code{GFONTS_DOWNLOAD_SLEEPTIME} which
must be a number of seconds.
}
\examples{
\dontrun{
if (curl::has_internet()) {
dummy_setup()
gfontHtmlDependency(family = "Open Sans")
}
}
}
\seealso{
Other functions for font management:
\code{\link{addGFontHtmlDependency}()},
\code{\link{fonts_cache_dir}()},
\code{\link{install_gfont_script}()},
\code{\link{installed_gfonts}()},
\code{\link{liberationsansHtmlDependency}()},
\code{\link{register_gfont}()},
\code{\link{register_liberationsans}()}
}
\concept{functions for font management}
gdtools/DESCRIPTION 0000644 0001762 0000144 00000003573 14535116431 013446 0 ustar ligges users Package: gdtools
Version: 0.3.5
License: GPL-3 | file LICENSE
Title: Utilities for Graphical Rendering and Fonts Management
Description: Tools are provided to compute metrics of
formatted strings and to check the availability of a font.
Another set of functions is provided to support the collection
of fonts from 'Google Fonts' in a cache. Their use is simple within
'R Markdown' documents and 'shiny' applications but also with graphic
productions generated with the 'ggiraph', 'ragg' and 'svglite' packages
or with tabular productions from the 'flextable' package.
Authors@R: c(
person("David", "Gohel", , "david.gohel@ardata.fr", c("aut", "cre")),
person("Hadley", "Wickham", , "hadley@rstudio.com", "aut"),
person("Lionel", "Henry", , "lionel@rstudio.com", "aut"),
person("Jeroen", "Ooms", role = "aut", email = "jeroen@berkeley.edu",
comment = c(ORCID = "0000-0002-4035-0289")),
person("Yixuan", "Qiu", role = "ctb"),
person("R Core Team", role = "cph", comment = "Cairo code from X11 device"),
person(given = "ArData", role = "cph"),
person("RStudio", role = "cph")
)
Depends: R (>= 4.0.0)
Imports: Rcpp (>= 0.12.12), systemfonts (>= 0.1.1), htmltools, gfonts,
tools, curl, fontquiver (>= 0.2.0)
Suggests: testthat, methods
Encoding: UTF-8
LinkingTo: Rcpp
SystemRequirements: cairo, freetype2, fontconfig
URL: https://davidgohel.github.io/gdtools/
BugReports: https://github.com/davidgohel/gdtools/issues
RoxygenNote: 7.2.3
NeedsCompilation: yes
Packaged: 2023-12-09 16:11:29 UTC; davidgohel
Author: David Gohel [aut, cre],
Hadley Wickham [aut],
Lionel Henry [aut],
Jeroen Ooms [aut] (),
Yixuan Qiu [ctb],
R Core Team [cph] (Cairo code from X11 device),
ArData [cph],
RStudio [cph]
Maintainer: David Gohel
Repository: CRAN
Date/Publication: 2023-12-09 17:00:09 UTC
gdtools/tests/ 0000755 0001762 0000144 00000000000 14360611071 013066 5 ustar ligges users gdtools/tests/testthat/ 0000755 0001762 0000144 00000000000 14535116431 014732 5 ustar ligges users gdtools/tests/testthat/test-str_metrics.R 0000644 0001762 0000144 00000000567 14360611071 020374 0 ustar ligges users context("font file metric info")
test_that("a string has positive dimensions", {
skip_if_not_installed("fontquiver")
file <- fontquiver::font("Bitstream Vera", "Sans", "Bold")$ttf
value <- str_metrics(x = "Hello World", fontsize = 12, fontfile = file )
expect_true( value["width"] > 0)
expect_true( value["ascent"] > 0 )
expect_false( value["descent"] < 0 )
})
gdtools/tests/testthat/test-str_extents.R 0000755 0001762 0000144 00000001745 14360611071 020422 0 ustar ligges users context("metric info")
test_that("a string has positive dimensions", {
value <- str_extents("Hello World!")
expect_true(all( value > 0 ))
})
extents <- function(font, ...) {
extents <- str_extents("foobar", fontfile = font$ttf, ...)
as.vector(round(extents, 4))
}
test_that("known fonts have correct metrics", {
skip_if_not_installed("fontquiver")
sans <- fontquiver::font("Liberation", "Sans", "Regular")
mono_bi <- fontquiver::font("Bitstream Vera", "Sans Mono", "Bold Oblique")
expect_equal(extents(sans), c(34.0254, 8.8281), tolerance = .1)
expect_equal(extents(mono_bi), c(43.3477, 9.2969), tolerance = .1)
})
test_that("fractional font sizes are correctly measured", {
skip_if_not_installed("fontquiver")
sans <- fontquiver::font("Liberation", "Sans", "Regular")
if (version_freetype() < "2.6.0") {
skip("Old FreeType return different extents for fractional sizes")
}
expect_equal(extents(sans, fontsize = 15.05), c(42.5317, 11.0156), tolerance = .2)
})
gdtools/tests/testthat/test-raster.R 0000755 0001762 0000144 00000000700 14360611071 017326 0 ustar ligges users context("raster")
test_that("raster_str", {
r <- as.raster(matrix(hcl(0, 80, seq(40, 80, 10)), nrow = 5, ncol = 4))
code <- raster_str(r, width = 50, height = 50)
expect_gt(nchar(x = code), 50)
})
test_that("raster_write", {
r <- as.raster(matrix(hcl(0, 80, seq(40, 80, 10)), nrow = 5, ncol = 4))
filename <- tempfile(fileext = ".png")
raster_write(r, path = filename, width = 50, height = 50)
expect_true(file.exists(filename))
})
gdtools/tests/testthat/helper-fontconfig.R 0000644 0001762 0000144 00000000106 14360611071 020457 0 ustar ligges users
local <- function() {
identical(Sys.getenv("NOT_CRAN"), "true")
}
gdtools/tests/testthat.R 0000644 0001762 0000144 00000000072 14360611071 015050 0 ustar ligges users library(testthat)
library(gdtools)
test_check("gdtools")
gdtools/src/ 0000755 0001762 0000144 00000000000 14535110661 012516 5 ustar ligges users gdtools/src/CairoContext.cpp 0000644 0001762 0000144 00000011171 14360611071 015622 0 ustar ligges users #include
#include