gdtools/0000755000176200001440000000000014712112032011716 5ustar liggesusersgdtools/tests/0000755000176200001440000000000014360611071013066 5ustar liggesusersgdtools/tests/testthat/0000755000176200001440000000000014712112032014720 5ustar liggesusersgdtools/tests/testthat/test-utils.R0000644000176200001440000000040614574413361017177 0ustar liggesuserstest_that("generic utils work", { ve_c <- version_cairo() expect_true(ve_c > numeric_version('0')) expect_s3_class(ve_c, "package_version") expect_s3_class(ve_c, "numeric_version") skip_on_cran() expect_true(is.character(match_family("serif"))) }) gdtools/tests/testthat/test-str_metrics.R0000644000176200001440000000146614574413361020404 0ustar liggesuserscontext("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) }) test_that("m_str_extents and gplyphs_match works ", { expect_true(all(glyphs_match(letters))) mstre <- m_str_extents(letters, fontsize = 1:26) expect_equal(dim(mstre), c(26, 2)) expect_true(all(is.numeric(mstre))) mstre <- m_str_extents(letters[1:3], bold = c(TRUE, FALSE, TRUE), italic = c(FALSE, TRUE, TRUE), fontname = c("sans", "sans", "sans") ) expect_equal(dim(mstre), c(3, 2)) expect_true(all(is.numeric(mstre))) }) gdtools/tests/testthat/test-fonts.R0000644000176200001440000000521414662457152017176 0ustar liggesusersds <- dummy_setup() test_that("fonts work", { skip_if_not(check_gfonts(errors = FALSE)) fontlist <- gfontHtmlDependency(family = "Open Sans") expect_identical(fontlist$name, "open-sans") expect_true(grepl("open-sans", fontlist$src[[1]])) expect_true(grepl("open-sans.css", fontlist$stylesheet)) expect_s3_class(fontlist, "html_dependency") out <- addGFontHtmlDependency(family = "Roboto") expect_s3_class(out, "shiny.tag") expect_identical(attr(out, which = "html_dependencies")[[1]]$name, "roboto") expect_identical(out$name, "style") out <- addGFontHtmlDependency(family = "Open Sans") expect_error(addGFontHtmlDependency("notafont")) expect_identical(attr(out, which = "html_dependencies")[[1]], fontlist) expect_true(register_gfont(family = gfonts::get_all_fonts()$family[4])) expect_identical( installed_gfonts(), c("Roboto", "Open Sans", "Montserrat") ) flib <- liberationsansHtmlDependency() expect_identical(flib$name, "liberation-sans") expect_true(grepl("liberation-sans", flib$src[[1]])) expect_true(grepl("liberation-sans.css", flib$stylesheet)) expect_s3_class(flib, "html_dependency") expect_true(register_liberationsans()) }) test_that("system dependent font installation works", { skip_if_not(check_gfonts(errors = FALSE)) si <- Sys.info() if (si["sysname"] == "Linux") { sysnm <- "debian" } else if (si["sysname"] == "Darwin") { sysnm <- "macos" } else if (si["sysname"] == "macOS") { sysnm <- "macos" } else if (si["sysname"] == "Windows") { sysnm <- "windows" } else { sysnm <- NULL } if (!is.null(sysnm)) { expect_silent(command <- install_gfont_script(family = "Roboto", platform = sysnm)) expect_silent(install_gfont_script(file = tempfile())) # Check some part of the command -> Windows is different if (si["sysname"] %in% c("Linux", "macOS", "Darwin")) { expect_true(grepl(paste0(ds, "/roboto/fonts"), command)) } } else { skip("Skipping install_gfont_script test because the platform is not supported") } }) test_that("font-caching works", { expect_warning(ds <- dummy_setup()) expect_silent(fcd <- fonts_cache_dir()) expect_true(dir.exists(fcd)) expect_true(grepl("GDTOOLS_CACHE_DIR", fcd)) options(GDTOOLS_CACHE_DIR = tempdir()) expect_silent(fcd <- fonts_cache_dir()) expect_true(dir.exists(fcd)) expect_false(grepl("GDTOOLS_CACHE_DIR", fcd)) options(GDTOOLS_CACHE_DIR = NULL) Sys.setenv(GDTOOLS_CACHE_DIR = "") init_fonts_cache() expect_silent(fcd <- fonts_cache_dir()) expect_true(dir.exists(fcd)) expect_true(grepl("gdtools", fcd)) rm_fonts_cache() expect_false(dir.exists(fonts_cache_dir())) }) gdtools/tests/testthat/test-raster.R0000755000176200001440000000070014360611071017326 0ustar liggesuserscontext("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/test-str_extents.R0000755000176200001440000000174514360611071020422 0ustar liggesuserscontext("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/helper-fontconfig.R0000644000176200001440000000010614360611071020457 0ustar liggesusers local <- function() { identical(Sys.getenv("NOT_CRAN"), "true") } gdtools/tests/testthat.R0000644000176200001440000000007214360611071015050 0ustar liggesuserslibrary(testthat) library(gdtools) test_check("gdtools") gdtools/MD50000644000176200001440000000647714712112032012244 0ustar liggesusersc5d6191dcf7405ab19e3f25fe1824135 *DESCRIPTION d32239bcb673463ab874e80d47fae504 *LICENSE 771f1a9b29fe0de6b491a145f797b6dd *NAMESPACE f8b1686886304d58feb4c15001395435 *NEWS.md f0b63e0e1999064c425ca8e457c0db15 *R/RcppExports.R c2d525dcbc829bcf3f9a921557a92c2b *R/font-caching.R 04ba65529ada0c9d17ad549fe7b6706f *R/font_family_exists.R ff338d89b51c821f9ba652ef63bd76d5 *R/fontconfig.R 8b2899278d027998130af0612d5d1be9 *R/fonts.R 2e563f8a3cb1302aeb80eae50324529e *R/gdtools.R e08fa22eadf9188e86d8906d687ec2f1 *R/liberation-sans.R 94780024b9e98d4c01a56e06e239f668 *R/raster.R 4f1bcc24bacae82428ddb12020a7a722 *R/str-metrics.R a9a515e25509bbd0e70365962d69ed39 *R/sysdata.rda e9153cb1d2ca36fb59e0d492d0736c47 *README.md bc7baead3b6080f04dc81efd2fe1ff39 *cleanup fa71cebc4b7a5f9c9daed0a8ad2033c3 *configure d41d8cd98f00b204e9800998ecf8427e *configure.win f0484399ab52a5dafecafdbd5b8417c1 *inst/css/liberation-sans.css 1dd40cfbddcb72173c6d8c2f6b3c8df9 *inst/include/gdtools.h 02ccd021b0ef8f143602d8585ca29ee2 *inst/include/gdtools_RcppExports.h d41d8cd98f00b204e9800998ecf8427e *inst/include/gdtools_types.cpp 2dca6b353cb2cd15593657282218b299 *inst/include/gdtools_types.h e3156e7c6e824c2c922dc0197bb72641 *man/addGFontHtmlDependency.Rd 959ecce11324c4c581da228876488ced *man/check_gfonts.Rd 0ac2418bcc65250ddd001c45d3ea39fd *man/dummy_setup.Rd 0eb091ca1aaad54395a3bd0201079e36 *man/font_family_exists.Rd 7a1d9ec664e2782a674ab250d3de635f *man/fontconfig_reinit.Rd 3c15454d9364e56d541d4c3b2ff1b640 *man/fonts_cache_dir.Rd d9b33e5ed6aca4af6b42048b55626dca *man/gfontHtmlDependency.Rd a342fb166d40577af315ad731882f42d *man/glyphs_match.Rd 1edfd03cceac9769d33198677f2b7bce *man/install_gfont_script.Rd 42610a62e5b1316b4b0e18c2fe07a2a6 *man/installed_gfonts.Rd e89ab3cc3a71212e71d1f4306b928a3b *man/liberationsansHtmlDependency.Rd 5ecbead9d286dbbfd6a2c91e2eb37a23 *man/m_str_extents.Rd 4dab2884581711ea97cfce4ec03c2716 *man/match_family.Rd 79c3fe71d0572cdddd1f5faf661559e2 *man/raster_str.Rd 9ec0dc2f294656184a81f2dd91529fa8 *man/raster_write.Rd 59ed0063cf1eb5f8f91689f57be64188 *man/register_gfont.Rd 81a6dbc5cafe4559d0c6e18f3d09012d *man/register_liberationsans.Rd 9bc98cdde728bd01bd614abb107953bb *man/set_dummy_conf.Rd c68e9c707af2d9c8b2c526e181ca5075 *man/str_extents.Rd 7543c3d22324af177742dfb1622720d2 *man/str_metrics.Rd 75c1a6c8471d9a8ad578c071775f2d02 *man/sys_fonts.Rd 06afbcca1d0a00c5635944cceb0f3a8e *man/version_cairo.Rd 1406cbb642867f1cec46d30ce148c67d *src/CairoContext.cpp 131e8f2086512f6bd15d7a46fd2998f4 *src/Makevars.in 51ff70aba2efc97d6d291061f2d8d8cc *src/Makevars.win ad490335dc913639f2b1f1edf882a20e *src/RcppExports.cpp 2053aadb4276b4066e13af220812b9b8 *src/font_metrics.cpp bc6a9479fe9002fc251f3bbca282c303 *src/gdtools.cpp d15f803daf529add0e3c695271bbede3 *src/raster_to_base64.cpp e88be22bd4f02671ef54bf42f42065b8 *src/tests/sysdeps.c 8dabb51a7c1a30785bf722556222a85f *src/versions.cpp d8252437453801ecb341846f83005a7f *tests/testthat.R 3f1839b260441de56baeb401d2b22b7b *tests/testthat/helper-fontconfig.R b9b2c45c12db52d8dbe2b253e49f4fe8 *tests/testthat/test-fonts.R 2f541f9d74d8ef19bcda19a7ab42729d *tests/testthat/test-raster.R df90cd2644166b7e6efde5b4c377f5fc *tests/testthat/test-str_extents.R 53829c4aefa5ee65449d1c9923e011ce *tests/testthat/test-str_metrics.R bb27cf0bca8f019aa368cd99fbb9d9bf *tests/testthat/test-utils.R 08e104261e69b705be125dd4390ae8dd *tools/winlibs.R gdtools/configure.win0000644000176200001440000000000014360611071014412 0ustar liggesusersgdtools/R/0000755000176200001440000000000014712103265012127 5ustar liggesusersgdtools/R/RcppExports.R0000644000176200001440000000520614712103251014541 0ustar liggesusers# Generated by using Rcpp::compileAttributes() -> do not edit by hand # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 str_extents_ <- function(x, fontname = "sans", fontsize = 12, bold = FALSE, italic = FALSE, fontfile = "") { .Call('_gdtools_str_extents_', PACKAGE = 'gdtools', x, fontname, fontsize, bold, italic, fontfile) } str_metrics_ <- function(x, fontname = "sans", fontsize = 12, bold = FALSE, italic = FALSE, fontfile = "") { .Call('_gdtools_str_metrics_', PACKAGE = 'gdtools', x, fontname, fontsize, bold, italic, fontfile) } m_str_extents_ <- function(x, fontname, fontsize, bold, italic, fontfile) { .Call('_gdtools_m_str_extents_', PACKAGE = 'gdtools', x, fontname, fontsize, bold, italic, fontfile) } glyphs_match_ <- function(x, fontname = "sans", bold = FALSE, italic = FALSE, fontfile = "") { .Call('_gdtools_glyphs_match_', PACKAGE = 'gdtools', x, fontname, bold, italic, fontfile) } context_create <- function() { .Call('_gdtools_context_create', PACKAGE = 'gdtools') } context_set_font <- function(cc, fontname, fontsize, bold, italic, fontfile = "") { .Call('_gdtools_context_set_font', PACKAGE = 'gdtools', cc, fontname, fontsize, bold, italic, fontfile) } context_extents <- function(cc, x) { .Call('_gdtools_context_extents', PACKAGE = 'gdtools', cc, x) } raster_to_str <- function(raster, w, h, width, height, interpolate) { .Call('_gdtools_raster_to_str', PACKAGE = 'gdtools', raster, w, h, width, height, interpolate) } raster_to_file <- function(raster, w, h, width, height, interpolate, filename) { .Call('_gdtools_raster_to_file', PACKAGE = 'gdtools', raster, w, h, width, height, interpolate, filename) } raster_png_ <- function(raster_, w, h, width, height, interpolate, filename) { .Call('_gdtools_raster_png_', PACKAGE = 'gdtools', raster_, w, h, width, height, interpolate, filename) } base64_raster_encode <- function(raster_, w, h, width, height, interpolate) { .Call('_gdtools_base64_raster_encode', PACKAGE = 'gdtools', raster_, w, h, width, height, interpolate) } base64_file_encode <- function(filename) { .Call('_gdtools_base64_file_encode', PACKAGE = 'gdtools', filename) } base64_string_encode <- function(string) { .Call('_gdtools_base64_string_encode', PACKAGE = 'gdtools', string) } #' @rdname version_cairo #' @export version_freetype <- function() { .Call('_gdtools_version_freetype', PACKAGE = 'gdtools') } version_cairo_ <- function() { .Call('_gdtools_version_cairo_', PACKAGE = 'gdtools') } # Register entry points for exported C++ functions methods::setLoadAction(function(ns) { .Call('_gdtools_RcppExport_registerCCallable', PACKAGE = 'gdtools') }) gdtools/R/font_family_exists.R0000644000176200001440000000275514663061402016172 0ustar liggesusers#' @title Check if font family exists. #' #' @description Check if a font family exists in system fonts. #' #' @return A logical value #' @param font_family font family name (case sensitive) #' @examples #' font_family_exists("sans") #' font_family_exists("Arial") #' font_family_exists("Courier") #' @export font_family_exists <- function( font_family = "sans" ){ datafonts <- sys_fonts() tolower(font_family) %in% tolower(datafonts$family) } #' @title List fonts for 'systemfonts'. #' #' @description List system and registryfonts details into a data.frame #' containing columns foundry, family, file, slant and weight. #' @examples #' sys_fonts() #' @export #' @importFrom systemfonts system_fonts registry_fonts sys_fonts <- function() { db_sys <- system_fonts() db_reg <- registry_fonts() nam <- intersect(colnames(db_sys), colnames(db_reg)) db_sys <- db_sys[,nam] db_reg <- db_reg[,nam] font_db <- rbind(db_sys, db_reg, default_sys_fonts()) font_db } default_sys_fonts <- function() { dat <- data.frame( path = rep(NA_character_, 16), index = rep(NA_integer_, 16), family = rep(c("sans", "serif", "mono", "symbol"), each = 4), style = rep(c("Regular", "Bold", "Italic", "Bold Italic"), 4), weight = rep(c("normal", "bold", "normal", "bold"), 4), italic = rep(c(FALSE, FALSE, TRUE, TRUE), 4), stringsAsFactors = FALSE ) res <- match_fonts(family = dat$family, weight = dat$weight, italic = dat$italic) dat$path <- res$path dat$index <- res$index dat } gdtools/R/font-caching.R0000644000176200001440000001035514662454251014626 0ustar liggesusers#' @importFrom tools R_user_dir #' @export #' @title manage font working directory #' @description Initialize or remove font directory used #' to store downloaded font files. #' #' This directory is managed by R function [R_user_dir()] but can also #' be defined in a non-user location by setting ENV variable `GDTOOLS_CACHE_DIR` #' or by setting R option `GDTOOLS_CACHE_DIR`. #' #' Its value can be read with the `fonts_cache_dir()` function. #' #' The directory can be deleted with `rm_fonts_cache()` and #' created with `init_fonts_cache()`. #' @family functions for font management #' @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()) fonts_cache_dir <- function() { if (dir.exists(Sys.getenv("GDTOOLS_CACHE_DIR"))) { dir <- Sys.getenv("GDTOOLS_CACHE_DIR") } else if (!is.null(getOption("GDTOOLS_CACHE_DIR")) && dir.exists(getOption("GDTOOLS_CACHE_DIR"))) { dir <- getOption("GDTOOLS_CACHE_DIR") } else { dir <- R_user_dir(package = "gdtools", which = "data") } if (is.null(getOption("GFONTS_DOWNLOAD_SLEEPTIME"))) { options(GFONTS_DOWNLOAD_SLEEPTIME = 1) } dir } #' @title dummy 'Google Fonts' cache #' @description dummy 'Google Fonts' cache #' used for examples. #' @export #' @keywords internal dummy_setup <- function() { options(GDTOOLS_CACHE_DIR = file.path(tempdir(), "GDTOOLS_CACHE_DIR")) dir.create(getOption("GDTOOLS_CACHE_DIR"), recursive = TRUE, showWarnings = TRUE) fonts_cache_dir() } user_cache_exists <- function() { fonts_cache_dir() == R_user_dir(package = "gdtools", which = "data") } #' @export #' @rdname fonts_cache_dir rm_fonts_cache <- function() { dir <- fonts_cache_dir() unlink(dir, recursive = TRUE, force = TRUE) } #' @export #' @rdname fonts_cache_dir init_fonts_cache <- function() { rm_fonts_cache() dir.create(fonts_cache_dir(), showWarnings = FALSE, recursive = TRUE) liberationsans_to_cache() fonts_cache_dir() } css_filepath <- function(id) { file.path(css_dir(id = id), paste0(id, ".css")) } css_dir <- function(id) { file.path(fonts_cache_dir(), id, "css") } font_dir <- function(id) { file.path(fonts_cache_dir(), id, "fonts") } reduce_faces <- function(variants) { faces <- c( plain = "regular", italic = "italic", bold = "700", bolditalic = "700italic" ) faces <- faces[faces %in% variants] faces <- faces[!is.na(faces)] faces } font_to_cache <- function(family, faces = NULL, subset = c("latin", "latin-ext")) { stopifnot(`'family' is expected to be a character value` = is.character(family), `family is expected to be a single value` = length(family) == 1L) x <- gfonts_summary() if (!family %in% x$family) { stop("family ", shQuote(family), " is not in the fonts provided by 'google fonts'.") } font_id <- x[x$family %in% family, ]$id css_file <- css_filepath(id = font_id) if (file.exists(css_file)) { return(TRUE) } check_gfonts(errors = TRUE) if (is.null(faces)) { faces <- reduce_faces(x[x$id %in% font_id, ]$variants[[1]]) } subsets <- intersect(x[x$id %in% font_id, ]$subsets[[1]], subset) .font_dir <- font_dir(id = font_id) .css_dir <- css_dir(id = font_id) dir.create(.font_dir, recursive = TRUE, showWarnings = FALSE) dir.create(.css_dir, recursive = TRUE, showWarnings = FALSE) gfonts::download_font( id = font_id, subsets = paste0(subsets, collapse = ","), variants = faces, output_dir = .font_dir ) Sys.sleep(getOption("GFONTS_DOWNLOAD_SLEEPTIME")) gfonts::generate_css( prefer_local_source = FALSE, browser_support = "best", subsets = paste0(subsets, collapse = ","), id = font_id, variants = faces, font_dir = "../fonts/", output = css_file ) # drop IE support as it generates issues - enough with IE8 css_str <- readLines(css_file, encoding = "UTF-8") css_str <- css_str[!grepl("/* IE6-IE8 */", css_str, fixed = TRUE)] writeLines(css_str, css_file, useBytes = TRUE) TRUE } ## gfonts_summary ----- gfonts_summary <- function() { all_gfonts } gdtools/R/fonts.R0000644000176200001440000002157014662716567013433 0ustar liggesusers#' @importFrom htmltools htmlDependency #' @importFrom utils packageVersion #' @export #' @title 'Google Font' HTML dependency #' @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 [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 `GFONTS_DOWNLOAD_SLEEPTIME` which #' must be a number of seconds. #' @param 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: #' #' ``` #' gfonts::get_all_fonts()$family |> #' unlist() |> #' unique() |> #' sort() #' ``` #' @param 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: #' ``` #' gfonts::get_all_fonts()$subsets |> unlist() |> unique() |> sort() #' ``` #' #' @family functions for font management #' @return an object defined with [htmltools::htmlDependency()]. #' @examples #' \dontrun{ #' if (check_gfonts()) { #' dummy_setup() #' gfontHtmlDependency(family = "Open Sans") #' } #' } gfontHtmlDependency <- function(family = "Open Sans", subset = c("latin", "latin-ext")) { pkg_version <- packageVersion("gdtools") pkg_version_str <- format(pkg_version) font_id <- get_font_id(family) register_gfont(family = family, subset = subset) htmlDependency( all_files = TRUE, name = font_id, version = pkg_version_str, src = file.path(fonts_cache_dir(), font_id), stylesheet = paste0("css/", font_id, ".css") ) } #' @export #' @importFrom htmltools tags attachDependencies #' @title Use a font in Shiny or Markdown #' @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 [gfontHtmlDependency()]. #' @inherit gfontHtmlDependency params details #' @return an HTML object #' @family functions for font management #' @examples #' \dontrun{ #' if (check_gfonts()) { #' dummy_setup() #' addGFontHtmlDependency(family = "Open Sans") #' } #' } addGFontHtmlDependency <- function(family = "Open Sans", subset = c("latin", "latin-ext")) { attachDependencies( x = tags$style(""), lapply(family, gfontHtmlDependency, subset = subset) ) } get_font_id <- function(family) { x <- gfonts_summary() if (!family %in% x$family) { stop("Font family ", shQuote(family), " has not been found.", call. = FALSE ) } x[x$family %in% family, ]$id } #' @importFrom systemfonts register_font #' @export #' @title Register a 'Google Fonts' #' @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. #' @inherit gfontHtmlDependency params details #' @return TRUE if the operation went ok. #' @family functions for font management #' @examples #' \dontrun{ #' if (check_gfonts()) { #' dummy_setup() #' register_gfont(family = "Roboto") #' } #' } register_gfont <- function(family = "Open Sans", subset = c("latin", "latin-ext")) { font_id <- get_font_id(family) x <- gfonts_summary() faces <- reduce_faces(x[x$id %in% font_id, ]$variants[[1]]) font_to_cache(family = family, faces = faces, subset = subset) files <- lapply(faces, function(face) { list.files( path = font_dir(font_id), pattern = paste0(font_id, "(.*)-", face, "\\.ttf"), full.names = TRUE ) }) if (!font_family_exists(family)) { files[["name"]] <- family do.call(register_font, files) } font_family_exists(family) } #' @export #' @title Shell command to install a font from 'Google Fonts' #' @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. #' @inherit gfontHtmlDependency params details #' @param platform "debian" and "windows" and "macos" are supported. #' @param 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. #' @return the 'shell' or 'PowerShell' command as a string #' @family functions for font management #' @examples #' \dontrun{ #' if (check_gfonts()) { #' dummy_setup() #' install_gfont_script(family = "Roboto", platform = "macos") #' } #' } install_gfont_script <- function(family = "Open Sans", subset = c("latin", "latin-ext"), platform = c("debian", "windows", "macos"), file = NULL) { platform <- match.arg(platform) font_id <- get_font_id(family) x <- gfonts_summary() faces <- reduce_faces(x[x$id %in% font_id, ]$variants[[1]]) font_to_cache(family = family, faces = faces, subset = subset) if ("debian" %in% platform) { str <- debian_sysinstall_command(font_id, dir = "custom-fonts") } else if ("windows" %in% platform) { str <- windows_sysinstall_command(font_id) } else { str <- macos_sysinstall_command(font_id, dir = if (user_cache_exists()) "~/Library/Fonts" else "/Library/Fonts") } if (!is.null(file)) { writeLines(str, file, useBytes = TRUE) Sys.chmod(file, mode = "755") } invisible(str) } #' @export #' @title List installed 'Google Fonts' #' @description List installed 'Google Fonts' that can be #' found in the user cache directory. #' @return families names as a character vector #' @family functions for font management #' @examples #' \dontrun{ #' if (check_gfonts()) { #' dummy_setup() #' register_gfont(family = "Roboto") #' installed_gfonts() #' } #' } installed_gfonts <- function() { x <- gfonts_summary() fonts_ids <- basename(list.dirs(fonts_cache_dir(), recursive = FALSE)) x$family[x$id %in% fonts_ids] } #' @export #' @title Checks the operability of 'gfonts' #' @description Checks that 'gfonts' is installed and can be used. #' Packages 'curl' and 'gfonts' must be installed and internet #' connectivity must be active. #' @param errors if TRUE, function is triggering errors if a condition #' is not satisfied. #' @return TRUE or FALSE #' @keywords internal check_gfonts <- function(errors = FALSE) { has_curl <- requireNamespace("curl", quietly = TRUE) has_gfonts <- requireNamespace("gfonts", quietly = TRUE) if (!has_curl && errors) { stop("package 'curl' is required to download fonts from 'fonts.google'.") } if (!has_curl) { return(FALSE) } if (!has_gfonts && errors) { stop("package 'gfonts' is required to download fonts from 'fonts.google'.") } if (!has_gfonts) { return(FALSE) } has_connectivity <- curl::has_internet() if (!has_connectivity && errors) { stop("an internet connection is required to download the font files.") } if (!has_connectivity) { return(FALSE) } TRUE } # utils ---- windows_sysinstall_command <- function(font_id) { # https://www.jordanmalcolm.com/deploying-windows-10-fonts-at-scale/ id_dir <- font_dir(font_id) install_cmd <- c( sprintf("$FontFolder = \"%s\"", id_dir), "$FontItem = Get-Item -Path $FontFolder", "$FontList = Get-ChildItem -Path \"$FontItem\\*\" -Include ('*.otf','*.ttc','*.ttf')", "", "foreach ($Font in $FontList) {", " Copy-Item $Font \"C:\\Windows\\Fonts\"", " New-ItemProperty -Name $Font.BaseName -Path \"HKLM:\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\" -PropertyType string -Value $Font.name", "}", "" ) install_cmd <- paste0(install_cmd, collapse = "\n") install_cmd } debian_sysinstall_command <- function(font_id, dir = "custom-fonts") { id_dir <- font_dir(font_id) create_dir <- sprintf("mkdir -p /usr/share/fonts/truetype/%s", dir) id_dir <- font_dir(font_id) install_cmd <- sprintf( "find %s -name \"*.ttf\" -exec install -m644 {} /usr/share/fonts/truetype/%s/ \\; || return 1", gsub(" ", "\\ ", id_dir, fixed = TRUE), dir ) paste(create_dir, install_cmd, "fc-cache -f", sep = ";") } macos_sysinstall_command <- function(font_id, dir = "~/Library/Fonts") { id_dir <- font_dir(font_id) sprintf("cp %s/* %s", gsub(" ", "\\ ", id_dir, fixed = TRUE), dir) } gdtools/R/raster.R0000644000176200001440000000354414360611071013556 0ustar liggesusers#' Draw/preview a raster into a string #' #' \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. #' #' @param x A raster object #' @param width,height Width and height in pixels. #' @param interpolate A logical value indicating whether to linearly #' interpolate the image. #' @param code base64 code of a raster #' @export #' @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) #' } raster_str <- function(x, width = 480, height = 480, interpolate = FALSE) { stopifnot(is.raster(x)) value <- base64_raster_encode(x, w = ncol(x), h = nrow(x), width = width, height = height, interpolate = interpolate) value } #' @export #' @rdname raster_str raster_view <- function(code) { img <- paste0("") htmltools::browsable(htmltools::HTML(img)) } #' Draw/preview a raster to a png file #' #' @param x A raster object #' @param path name of the file to create #' @param width,height Width and height in pixels. #' @param interpolate A logical value indicating whether to linearly #' interpolate the image. #' @export #' @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) raster_write <- function(x, path, width = 480, height = 480, interpolate = FALSE) { stopifnot(is.raster(x)) raster_png_(raster_ = x, w = ncol(x), h = nrow(x), width = as.double(width), height = as.double(height), interpolate = interpolate, filename = path) invisible(path) } gdtools/R/fontconfig.R0000644000176200001440000000252614663053573014426 0ustar liggesusers#' Find best family match with systemfonts #' #' \code{match_family()} returns the best font family match. #' #' @param font family or face to match. #' @param bold Wheter to match a font featuring a \code{bold} face. #' @param italic Wheter to match a font featuring an \code{italic} face. #' @param debug deprecated #' @export #' @examples #' match_family("sans") #' match_family("serif") #' @importFrom systemfonts match_fonts system_fonts match_family <- function(font = "sans", bold = TRUE, italic = TRUE, debug = NULL) { if (bold) { weight <- "bold" } else { weight <- "normal" } font <- match_fonts(font, weight = weight, italic = italic) sysfonts <- sys_fonts() match <- which(sysfonts$path %in% font$path) sysfonts$family[match[1]] } #' Set and unset a minimalistic Fontconfig configuration #' #' @note #' Fontconfig is not used anymore and these functions will be deprecated #' in the next release. #' @export set_dummy_conf <- function() { } #' @rdname set_dummy_conf #' @export unset_dummy_conf <- function() { } #' @export #' @title reload Fontconfig configuration #' @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 fontconfig_reinit <- function() { } gdtools/R/gdtools.R0000644000176200001440000000077214571177307013746 0ustar liggesusers#' @useDynLib gdtools #' @importFrom Rcpp sourceCpp #' @importFrom grDevices is.raster NULL #' Version numbers of C libraries #' #' \code{version_cairo()} and \code{version_freetype()} return the #' runtime version. These helpers return version objects as with #' \code{\link[utils]{packageVersion}()}. #' @export version_cairo <- function() { ver <- version_cairo_() ver <- strsplit(ver, "\\.")[[1]] ver <- as.integer(ver) structure(list(ver), class = c("package_version", "numeric_version")) } gdtools/R/str-metrics.R0000644000176200001440000000650214373640554014543 0ustar liggesusers#' @title Compute string extents. #' #' @description Determines the width and height of a bounding box that's big enough #' to (just) enclose the provided text. #' #' @param x Character vector of strings to measure #' @param bold,italic Is text bold/italic? #' @param fontname Font name #' @param fontsize Font size #' @param fontfile Font file #' @examples #' str_extents(letters) #' str_extents("Hello World!", bold = TRUE, italic = FALSE, #' fontname = "sans", fontsize = 12) #' @export str_extents <- function(x, fontname = "sans", fontsize = 12, bold = FALSE, italic = FALSE, fontfile = "") { str_extents_(x = x, fontname = fontname, fontsize = fontsize, bold = bold, italic = italic, fontfile = fontfile) } #' Get font metrics for a string. #' #' @return A named numeric vector #' @inheritParams str_extents #' @examples #' str_metrics("Hello World!") #' @export str_metrics <- function(x, fontname = "sans", fontsize = 12, bold = FALSE, italic = FALSE, fontfile = "") { str_metrics_(x = x, fontname = fontname, fontsize = fontsize, bold = bold, italic = italic, fontfile = fontfile) } #' Validate glyph entries #' #' Determines if strings contain glyphs not part of a font. #' #' @param x Character vector of strings #' @param bold,italic Is text bold/italic? #' @param fontname Font name #' @param fontfile Font file #' @return 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. #' #' @examples #' glyphs_match(letters) #' glyphs_match("\u265E", bold = TRUE) #' @export glyphs_match <- function(x, fontname = "sans", bold = FALSE, italic = FALSE, fontfile = "") { glyphs_match_(x = x, fontname = fontname, bold = bold, italic = italic, fontfile = fontfile) } #' Compute string extents for a vector of string. #' #' 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. #' @param x Character vector of strings to measure #' @param bold,italic Is text bold/italic?. A vector of logical to match with x. #' @param fontname Font name. A vector of character to match with x. #' @param fontsize Font size. A vector of numeric to match with x. #' @param fontfile Font file. A vector of character to match with x. #' @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") ) #' } #' @export m_str_extents <- function(x, fontname = "sans", fontsize=10, bold = FALSE, italic = FALSE, fontfile = NULL) { stopifnot(is.character(x), is.character(fontname), is.numeric(fontsize), is.logical(bold), is.logical(italic), is.character(fontfile) || is.null(fontfile)) max_length <- length(x) fontname <- rep(fontname, length.out = max_length) fontsize <- rep(fontsize, length.out = max_length) bold <- rep(bold, length.out = max_length) italic <- rep(italic, length.out = max_length) if( is.null(fontfile) ) fontfile <- rep("", length.out = max_length) else fontfile <- rep(fontfile, length.out = max_length) m_str_extents_(x, fontname, fontsize, bold, italic, fontfile) } gdtools/R/sysdata.rda0000644000176200001440000007050614662442630014305 0ustar liggesusersBZh91AY&SYPhq>ҢoP||yt c֢w=#pX6yW!upvx! @7prl]z2ɝpÐux=$AE%$!@ M 492I[z^4AJӠH *NCĢ8PUŜYPsCBvͼXi瑸X2RY,H >,~_W|~?_?7\k6ݳ7nø.;v/^?^_^޿߳o}~/~oO/4UUH d{}RIR>@ @ LT01JU *"JQrIRUB(+"b&N aX¸0ŀaZk/c0ʒTT8+ b.-r...aZK""r%T0CQrV*JT%..""\kт.HP~$E4t0@t04M00M044NtDM1CL4@)uKK)uQp]HKȸ)tZ UK.I!rRJT"$rKqrRRꪗK\0EU~$R{f??&f+Rv-o|B{@ 4PAe)Y̱1UH3]hkPhNœCdq64פUBk0 &oJST&&!2 yݠLM wjg OJ kK˳"HȅkӲq7Wj uFЉ<fTrr<꣺b@: auoﵭʊLA5^[d5U(ؙd5aK ooUE5q,A4PL“*Ջc i&6ŀ.AM$0quv9EMLEG%ni*Z[QQE9Hduy$(e%h:i[Pfiݫnw@#.S-QlֶJmڵUͬ[knАR@IZ@^WxݷvjW'ֲv? xI-hPfaק0b ȕkU{́ex,vw]poL^X00dR,Q7dC&zz46vJ^QW]óh 1kz0ܟa봮M IHmbS]>|O9-fp 3aY]MaRch҆$j5Z(Ɠ:CY8\:N9q̜,8I&iufhŽ)5F = $/Cք4DS uX(dT$A4AT55*PS^.L}|[ӽ\PMh;6৿0h2K%3m\9: =y{М ԜOXx7~;}oO+8I>>,+nm>7^9Й!Rk|33P*VR>hЂug_I[ {5g}yww׎%6rW< I22O,`;C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I$I$I$I$I$I$I$I$I$I$I$I$I$I$I IrE8PPhqgdtools/R/liberation-sans.R0000644000176200001440000000413014663046622015352 0ustar liggesusersliberationsans_to_cache <- function() { font_id <- "liberation-sans" font_dir_ <- font_dir(id = font_id) font_css_ <- css_dir(id = font_id) if (!dir.exists(font_dir_) || !dir.exists(font_css_)) { dir.create(font_dir_, showWarnings = FALSE, recursive = TRUE) file.copy( from = list.files( system.file(package = "fontLiberation", "fonts/liberation-fonts"), full.names = TRUE), to = font_dir_, overwrite = TRUE) dir.create(font_css_, showWarnings = FALSE, recursive = TRUE) file.copy( from = system.file(package = "gdtools", "css/liberation-sans.css"), to = font_css_, overwrite = TRUE) } } #' @importFrom fontquiver font_faces #' @export #' @title Register font 'Liberation Sans' #' @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. #' @return TRUE if the operation went ok. #' @family functions for font management register_liberationsans <- function() { if (!font_family_exists("Liberation Sans")) { liberation_lst <- font_faces("Liberation", family = "sans") register_font( name = "Liberation Sans", plain = liberation_lst$plain$ttf, bold = liberation_lst$bold$ttf, italic = liberation_lst$italic$ttf, bolditalic = liberation_lst$bolditalic$ttf ) } font_family_exists("Liberation Sans") } #' @export #' @title 'Liberation Sans' Font HTML dependency #' @description Create an HTML dependency ready #' to be used in 'Shiny' or 'R Markdown' with #' 'Liberation Sans' Font. #' @seealso [gfontHtmlDependency()] #' @family functions for font management liberationsansHtmlDependency <- function() { pkg_version <- packageVersion("gdtools") pkg_version_str <- format(pkg_version) font_id <- "liberation-sans" liberationsans_to_cache() htmlDependency( all_files = TRUE, name = font_id, version = pkg_version_str, src = file.path(fonts_cache_dir(), font_id), stylesheet = paste0("css/", font_id, ".css") ) } gdtools/cleanup0000755000176200001440000000005314712103265013301 0ustar liggesusers#!/bin/sh rm -f src/Makevars configure.log gdtools/src/0000755000176200001440000000000014712103265012515 5ustar liggesusersgdtools/src/tests/0000755000176200001440000000000014360611071013655 5ustar liggesusersgdtools/src/tests/sysdeps.c0000644000176200001440000000011014360611071015503 0ustar liggesusers#include #include int main () { return 0; } gdtools/src/RcppExports.cpp0000644000176200001440000005476214663061151015532 0ustar liggesusers// Generated by using Rcpp::compileAttributes() -> do not edit by hand // Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 #include "../inst/include/gdtools.h" #include "../inst/include/gdtools_types.h" #include #include #include using namespace Rcpp; #ifdef RCPP_USE_GLOBAL_ROSTREAM Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); #endif // str_extents_ NumericMatrix str_extents_(CharacterVector x, std::string fontname, double fontsize, int bold, int italic, std::string fontfile); RcppExport SEXP _gdtools_str_extents_(SEXP xSEXP, SEXP fontnameSEXP, SEXP fontsizeSEXP, SEXP boldSEXP, SEXP italicSEXP, SEXP fontfileSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< CharacterVector >::type x(xSEXP); Rcpp::traits::input_parameter< std::string >::type fontname(fontnameSEXP); Rcpp::traits::input_parameter< double >::type fontsize(fontsizeSEXP); Rcpp::traits::input_parameter< int >::type bold(boldSEXP); Rcpp::traits::input_parameter< int >::type italic(italicSEXP); Rcpp::traits::input_parameter< std::string >::type fontfile(fontfileSEXP); rcpp_result_gen = Rcpp::wrap(str_extents_(x, fontname, fontsize, bold, italic, fontfile)); return rcpp_result_gen; END_RCPP } // str_metrics_ NumericVector str_metrics_(CharacterVector x, std::string fontname, double fontsize, int bold, int italic, std::string fontfile); RcppExport SEXP _gdtools_str_metrics_(SEXP xSEXP, SEXP fontnameSEXP, SEXP fontsizeSEXP, SEXP boldSEXP, SEXP italicSEXP, SEXP fontfileSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< CharacterVector >::type x(xSEXP); Rcpp::traits::input_parameter< std::string >::type fontname(fontnameSEXP); Rcpp::traits::input_parameter< double >::type fontsize(fontsizeSEXP); Rcpp::traits::input_parameter< int >::type bold(boldSEXP); Rcpp::traits::input_parameter< int >::type italic(italicSEXP); Rcpp::traits::input_parameter< std::string >::type fontfile(fontfileSEXP); rcpp_result_gen = Rcpp::wrap(str_metrics_(x, fontname, fontsize, bold, italic, fontfile)); return rcpp_result_gen; END_RCPP } // m_str_extents_ NumericMatrix m_str_extents_(CharacterVector x, std::vector fontname, std::vector fontsize, std::vector bold, std::vector italic, std::vector fontfile); RcppExport SEXP _gdtools_m_str_extents_(SEXP xSEXP, SEXP fontnameSEXP, SEXP fontsizeSEXP, SEXP boldSEXP, SEXP italicSEXP, SEXP fontfileSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< CharacterVector >::type x(xSEXP); Rcpp::traits::input_parameter< std::vector >::type fontname(fontnameSEXP); Rcpp::traits::input_parameter< std::vector >::type fontsize(fontsizeSEXP); Rcpp::traits::input_parameter< std::vector >::type bold(boldSEXP); Rcpp::traits::input_parameter< std::vector >::type italic(italicSEXP); Rcpp::traits::input_parameter< std::vector >::type fontfile(fontfileSEXP); rcpp_result_gen = Rcpp::wrap(m_str_extents_(x, fontname, fontsize, bold, italic, fontfile)); return rcpp_result_gen; END_RCPP } // glyphs_match_ LogicalVector glyphs_match_(CharacterVector x, std::string fontname, int bold, int italic, std::string fontfile); RcppExport SEXP _gdtools_glyphs_match_(SEXP xSEXP, SEXP fontnameSEXP, SEXP boldSEXP, SEXP italicSEXP, SEXP fontfileSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< CharacterVector >::type x(xSEXP); Rcpp::traits::input_parameter< std::string >::type fontname(fontnameSEXP); Rcpp::traits::input_parameter< int >::type bold(boldSEXP); Rcpp::traits::input_parameter< int >::type italic(italicSEXP); Rcpp::traits::input_parameter< std::string >::type fontfile(fontfileSEXP); rcpp_result_gen = Rcpp::wrap(glyphs_match_(x, fontname, bold, italic, fontfile)); return rcpp_result_gen; END_RCPP } // context_create XPtrCairoContext context_create(); static SEXP _gdtools_context_create_try() { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; rcpp_result_gen = Rcpp::wrap(context_create()); return rcpp_result_gen; END_RCPP_RETURN_ERROR } RcppExport SEXP _gdtools_context_create() { SEXP rcpp_result_gen; { Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = PROTECT(_gdtools_context_create_try()); } Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); if (rcpp_isInterrupt_gen) { UNPROTECT(1); Rf_onintr(); } bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); if (rcpp_isLongjump_gen) { Rcpp::internal::resumeJump(rcpp_result_gen); } Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; } // context_set_font bool context_set_font(XPtrCairoContext cc, std::string fontname, double fontsize, bool bold, bool italic, std::string fontfile); static SEXP _gdtools_context_set_font_try(SEXP ccSEXP, SEXP fontnameSEXP, SEXP fontsizeSEXP, SEXP boldSEXP, SEXP italicSEXP, SEXP fontfileSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< XPtrCairoContext >::type cc(ccSEXP); Rcpp::traits::input_parameter< std::string >::type fontname(fontnameSEXP); Rcpp::traits::input_parameter< double >::type fontsize(fontsizeSEXP); Rcpp::traits::input_parameter< bool >::type bold(boldSEXP); Rcpp::traits::input_parameter< bool >::type italic(italicSEXP); Rcpp::traits::input_parameter< std::string >::type fontfile(fontfileSEXP); rcpp_result_gen = Rcpp::wrap(context_set_font(cc, fontname, fontsize, bold, italic, fontfile)); return rcpp_result_gen; END_RCPP_RETURN_ERROR } RcppExport SEXP _gdtools_context_set_font(SEXP ccSEXP, SEXP fontnameSEXP, SEXP fontsizeSEXP, SEXP boldSEXP, SEXP italicSEXP, SEXP fontfileSEXP) { SEXP rcpp_result_gen; { Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = PROTECT(_gdtools_context_set_font_try(ccSEXP, fontnameSEXP, fontsizeSEXP, boldSEXP, italicSEXP, fontfileSEXP)); } Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); if (rcpp_isInterrupt_gen) { UNPROTECT(1); Rf_onintr(); } bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); if (rcpp_isLongjump_gen) { Rcpp::internal::resumeJump(rcpp_result_gen); } Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; } // context_extents FontMetric context_extents(XPtrCairoContext cc, std::string x); static SEXP _gdtools_context_extents_try(SEXP ccSEXP, SEXP xSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< XPtrCairoContext >::type cc(ccSEXP); Rcpp::traits::input_parameter< std::string >::type x(xSEXP); rcpp_result_gen = Rcpp::wrap(context_extents(cc, x)); return rcpp_result_gen; END_RCPP_RETURN_ERROR } RcppExport SEXP _gdtools_context_extents(SEXP ccSEXP, SEXP xSEXP) { SEXP rcpp_result_gen; { Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = PROTECT(_gdtools_context_extents_try(ccSEXP, xSEXP)); } Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); if (rcpp_isInterrupt_gen) { UNPROTECT(1); Rf_onintr(); } bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); if (rcpp_isLongjump_gen) { Rcpp::internal::resumeJump(rcpp_result_gen); } Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; } // raster_to_str std::string raster_to_str(std::vector raster, int w, int h, double width, double height, int interpolate); static SEXP _gdtools_raster_to_str_try(SEXP rasterSEXP, SEXP wSEXP, SEXP hSEXP, SEXP widthSEXP, SEXP heightSEXP, SEXP interpolateSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< std::vector >::type raster(rasterSEXP); Rcpp::traits::input_parameter< int >::type w(wSEXP); Rcpp::traits::input_parameter< int >::type h(hSEXP); Rcpp::traits::input_parameter< double >::type width(widthSEXP); Rcpp::traits::input_parameter< double >::type height(heightSEXP); Rcpp::traits::input_parameter< int >::type interpolate(interpolateSEXP); rcpp_result_gen = Rcpp::wrap(raster_to_str(raster, w, h, width, height, interpolate)); return rcpp_result_gen; END_RCPP_RETURN_ERROR } RcppExport SEXP _gdtools_raster_to_str(SEXP rasterSEXP, SEXP wSEXP, SEXP hSEXP, SEXP widthSEXP, SEXP heightSEXP, SEXP interpolateSEXP) { SEXP rcpp_result_gen; { Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = PROTECT(_gdtools_raster_to_str_try(rasterSEXP, wSEXP, hSEXP, widthSEXP, heightSEXP, interpolateSEXP)); } Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); if (rcpp_isInterrupt_gen) { UNPROTECT(1); Rf_onintr(); } bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); if (rcpp_isLongjump_gen) { Rcpp::internal::resumeJump(rcpp_result_gen); } Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; } // raster_to_file int raster_to_file(std::vector raster, int w, int h, double width, double height, int interpolate, std::string filename); static SEXP _gdtools_raster_to_file_try(SEXP rasterSEXP, SEXP wSEXP, SEXP hSEXP, SEXP widthSEXP, SEXP heightSEXP, SEXP interpolateSEXP, SEXP filenameSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< std::vector >::type raster(rasterSEXP); Rcpp::traits::input_parameter< int >::type w(wSEXP); Rcpp::traits::input_parameter< int >::type h(hSEXP); Rcpp::traits::input_parameter< double >::type width(widthSEXP); Rcpp::traits::input_parameter< double >::type height(heightSEXP); Rcpp::traits::input_parameter< int >::type interpolate(interpolateSEXP); Rcpp::traits::input_parameter< std::string >::type filename(filenameSEXP); rcpp_result_gen = Rcpp::wrap(raster_to_file(raster, w, h, width, height, interpolate, filename)); return rcpp_result_gen; END_RCPP_RETURN_ERROR } RcppExport SEXP _gdtools_raster_to_file(SEXP rasterSEXP, SEXP wSEXP, SEXP hSEXP, SEXP widthSEXP, SEXP heightSEXP, SEXP interpolateSEXP, SEXP filenameSEXP) { SEXP rcpp_result_gen; { Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = PROTECT(_gdtools_raster_to_file_try(rasterSEXP, wSEXP, hSEXP, widthSEXP, heightSEXP, interpolateSEXP, filenameSEXP)); } Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); if (rcpp_isInterrupt_gen) { UNPROTECT(1); Rf_onintr(); } bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); if (rcpp_isLongjump_gen) { Rcpp::internal::resumeJump(rcpp_result_gen); } Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; } // raster_png_ bool raster_png_(CharacterVector raster_, int w, int h, double width, double height, int interpolate, std::string filename); static SEXP _gdtools_raster_png__try(SEXP raster_SEXP, SEXP wSEXP, SEXP hSEXP, SEXP widthSEXP, SEXP heightSEXP, SEXP interpolateSEXP, SEXP filenameSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< CharacterVector >::type raster_(raster_SEXP); Rcpp::traits::input_parameter< int >::type w(wSEXP); Rcpp::traits::input_parameter< int >::type h(hSEXP); Rcpp::traits::input_parameter< double >::type width(widthSEXP); Rcpp::traits::input_parameter< double >::type height(heightSEXP); Rcpp::traits::input_parameter< int >::type interpolate(interpolateSEXP); Rcpp::traits::input_parameter< std::string >::type filename(filenameSEXP); rcpp_result_gen = Rcpp::wrap(raster_png_(raster_, w, h, width, height, interpolate, filename)); return rcpp_result_gen; END_RCPP_RETURN_ERROR } RcppExport SEXP _gdtools_raster_png_(SEXP raster_SEXP, SEXP wSEXP, SEXP hSEXP, SEXP widthSEXP, SEXP heightSEXP, SEXP interpolateSEXP, SEXP filenameSEXP) { SEXP rcpp_result_gen; { Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = PROTECT(_gdtools_raster_png__try(raster_SEXP, wSEXP, hSEXP, widthSEXP, heightSEXP, interpolateSEXP, filenameSEXP)); } Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); if (rcpp_isInterrupt_gen) { UNPROTECT(1); Rf_onintr(); } bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); if (rcpp_isLongjump_gen) { Rcpp::internal::resumeJump(rcpp_result_gen); } Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; } // base64_raster_encode std::string base64_raster_encode(CharacterVector raster_, int w, int h, double width, double height, int interpolate); static SEXP _gdtools_base64_raster_encode_try(SEXP raster_SEXP, SEXP wSEXP, SEXP hSEXP, SEXP widthSEXP, SEXP heightSEXP, SEXP interpolateSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< CharacterVector >::type raster_(raster_SEXP); Rcpp::traits::input_parameter< int >::type w(wSEXP); Rcpp::traits::input_parameter< int >::type h(hSEXP); Rcpp::traits::input_parameter< double >::type width(widthSEXP); Rcpp::traits::input_parameter< double >::type height(heightSEXP); Rcpp::traits::input_parameter< int >::type interpolate(interpolateSEXP); rcpp_result_gen = Rcpp::wrap(base64_raster_encode(raster_, w, h, width, height, interpolate)); return rcpp_result_gen; END_RCPP_RETURN_ERROR } RcppExport SEXP _gdtools_base64_raster_encode(SEXP raster_SEXP, SEXP wSEXP, SEXP hSEXP, SEXP widthSEXP, SEXP heightSEXP, SEXP interpolateSEXP) { SEXP rcpp_result_gen; { Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = PROTECT(_gdtools_base64_raster_encode_try(raster_SEXP, wSEXP, hSEXP, widthSEXP, heightSEXP, interpolateSEXP)); } Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); if (rcpp_isInterrupt_gen) { UNPROTECT(1); Rf_onintr(); } bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); if (rcpp_isLongjump_gen) { Rcpp::internal::resumeJump(rcpp_result_gen); } Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; } // base64_file_encode std::string base64_file_encode(std::string filename); static SEXP _gdtools_base64_file_encode_try(SEXP filenameSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< std::string >::type filename(filenameSEXP); rcpp_result_gen = Rcpp::wrap(base64_file_encode(filename)); return rcpp_result_gen; END_RCPP_RETURN_ERROR } RcppExport SEXP _gdtools_base64_file_encode(SEXP filenameSEXP) { SEXP rcpp_result_gen; { Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = PROTECT(_gdtools_base64_file_encode_try(filenameSEXP)); } Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); if (rcpp_isInterrupt_gen) { UNPROTECT(1); Rf_onintr(); } bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); if (rcpp_isLongjump_gen) { Rcpp::internal::resumeJump(rcpp_result_gen); } Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; } // base64_string_encode std::string base64_string_encode(std::string string); static SEXP _gdtools_base64_string_encode_try(SEXP stringSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< std::string >::type string(stringSEXP); rcpp_result_gen = Rcpp::wrap(base64_string_encode(string)); return rcpp_result_gen; END_RCPP_RETURN_ERROR } RcppExport SEXP _gdtools_base64_string_encode(SEXP stringSEXP) { SEXP rcpp_result_gen; { Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = PROTECT(_gdtools_base64_string_encode_try(stringSEXP)); } Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); if (rcpp_isInterrupt_gen) { UNPROTECT(1); Rf_onintr(); } bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); if (rcpp_isLongjump_gen) { Rcpp::internal::resumeJump(rcpp_result_gen); } Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; } // version_freetype Rcpp::List version_freetype(); RcppExport SEXP _gdtools_version_freetype() { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = Rcpp::wrap(version_freetype()); return rcpp_result_gen; END_RCPP } // version_cairo_ Rcpp::CharacterVector version_cairo_(); RcppExport SEXP _gdtools_version_cairo_() { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = Rcpp::wrap(version_cairo_()); return rcpp_result_gen; END_RCPP } // validate (ensure exported C++ functions exist before calling them) static int _gdtools_RcppExport_validate(const char* sig) { static std::set signatures; if (signatures.empty()) { signatures.insert("XPtrCairoContext(*context_create)()"); signatures.insert("bool(*context_set_font)(XPtrCairoContext,std::string,double,bool,bool,std::string)"); signatures.insert("FontMetric(*context_extents)(XPtrCairoContext,std::string)"); signatures.insert("std::string(*raster_to_str)(std::vector,int,int,double,double,int)"); signatures.insert("int(*raster_to_file)(std::vector,int,int,double,double,int,std::string)"); signatures.insert("bool(*raster_png_)(CharacterVector,int,int,double,double,int,std::string)"); signatures.insert("std::string(*base64_raster_encode)(CharacterVector,int,int,double,double,int)"); signatures.insert("std::string(*base64_file_encode)(std::string)"); signatures.insert("std::string(*base64_string_encode)(std::string)"); } return signatures.find(sig) != signatures.end(); } // registerCCallable (register entry points for exported C++ functions) RcppExport SEXP _gdtools_RcppExport_registerCCallable() { R_RegisterCCallable("gdtools", "_gdtools_context_create", (DL_FUNC)_gdtools_context_create_try); R_RegisterCCallable("gdtools", "_gdtools_context_set_font", (DL_FUNC)_gdtools_context_set_font_try); R_RegisterCCallable("gdtools", "_gdtools_context_extents", (DL_FUNC)_gdtools_context_extents_try); R_RegisterCCallable("gdtools", "_gdtools_raster_to_str", (DL_FUNC)_gdtools_raster_to_str_try); R_RegisterCCallable("gdtools", "_gdtools_raster_to_file", (DL_FUNC)_gdtools_raster_to_file_try); R_RegisterCCallable("gdtools", "_gdtools_raster_png_", (DL_FUNC)_gdtools_raster_png__try); R_RegisterCCallable("gdtools", "_gdtools_base64_raster_encode", (DL_FUNC)_gdtools_base64_raster_encode_try); R_RegisterCCallable("gdtools", "_gdtools_base64_file_encode", (DL_FUNC)_gdtools_base64_file_encode_try); R_RegisterCCallable("gdtools", "_gdtools_base64_string_encode", (DL_FUNC)_gdtools_base64_string_encode_try); R_RegisterCCallable("gdtools", "_gdtools_RcppExport_validate", (DL_FUNC)_gdtools_RcppExport_validate); return R_NilValue; } static const R_CallMethodDef CallEntries[] = { {"_gdtools_str_extents_", (DL_FUNC) &_gdtools_str_extents_, 6}, {"_gdtools_str_metrics_", (DL_FUNC) &_gdtools_str_metrics_, 6}, {"_gdtools_m_str_extents_", (DL_FUNC) &_gdtools_m_str_extents_, 6}, {"_gdtools_glyphs_match_", (DL_FUNC) &_gdtools_glyphs_match_, 5}, {"_gdtools_context_create", (DL_FUNC) &_gdtools_context_create, 0}, {"_gdtools_context_set_font", (DL_FUNC) &_gdtools_context_set_font, 6}, {"_gdtools_context_extents", (DL_FUNC) &_gdtools_context_extents, 2}, {"_gdtools_raster_to_str", (DL_FUNC) &_gdtools_raster_to_str, 6}, {"_gdtools_raster_to_file", (DL_FUNC) &_gdtools_raster_to_file, 7}, {"_gdtools_raster_png_", (DL_FUNC) &_gdtools_raster_png_, 7}, {"_gdtools_base64_raster_encode", (DL_FUNC) &_gdtools_base64_raster_encode, 6}, {"_gdtools_base64_file_encode", (DL_FUNC) &_gdtools_base64_file_encode, 1}, {"_gdtools_base64_string_encode", (DL_FUNC) &_gdtools_base64_string_encode, 1}, {"_gdtools_version_freetype", (DL_FUNC) &_gdtools_version_freetype, 0}, {"_gdtools_version_cairo_", (DL_FUNC) &_gdtools_version_cairo_, 0}, {"_gdtools_RcppExport_registerCCallable", (DL_FUNC) &_gdtools_RcppExport_registerCCallable, 0}, {NULL, NULL, 0} }; RcppExport void R_init_gdtools(DllInfo *dll) { R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); R_useDynamicSymbols(dll, FALSE); } gdtools/src/CairoContext.cpp0000644000176200001440000001117114360611071015622 0ustar liggesusers#include #include #include #include #include #include #include #include #include FT_FREETYPE_H #include "gdtools_types.h" using namespace Rcpp; struct CairoContext::CairoContext_ { cairo_surface_t* surface; cairo_t* context; FT_Library library; fontCache fonts; }; CairoContext::CairoContext() { cairo_ = new CairoContext_(); cairo_->surface = cairo_pdf_surface_create(NULL, 720, 720); cairo_->context = cairo_create(cairo_->surface); if (FT_Init_FreeType(&(cairo_->library))) Rcpp::stop("FreeType error: unable to initialize FreeType library object"); } CairoContext::~CairoContext() { fontCache::iterator it = cairo_->fonts.begin(); while (it != cairo_->fonts.end()) { cairo_font_face_destroy(it->second); ++it; } cairo_surface_destroy(cairo_->surface); cairo_destroy(cairo_->context); delete cairo_; } void CairoContext::cacheFont(fontCache& cache, std::string& key, std::string fontfile, int fontindex) { FT_Face face; if (0 != FT_New_Face(cairo_->library, fontfile.c_str(), fontindex, &face)) Rcpp::stop("FreeType error: unable to open %s", fontfile.c_str()); cairo_font_face_t* cairo_face = cairo_ft_font_face_create_for_ft_face(face, 0); cairo_user_data_key_t font_key; cairo_status_t status = cairo_font_face_set_user_data( cairo_face, &font_key, face, (cairo_destroy_func_t) FT_Done_Face ); if (status) { cairo_font_face_destroy(cairo_face); FT_Done_Face(face); Rcpp::stop("Cairo error: unable to handle %s", fontfile.c_str()); } cache[key] = cairo_face; } struct font_file_t { std::string file; int index; }; static int locate_font(const char *family, int italic, int bold, char *path, int max_path_length) { static int (*p_locate_font)(const char *family, int italic, int bold, char *path, int max_path_length) = NULL; if (p_locate_font == NULL) { p_locate_font = (int(*)(const char *, int, int, char *, int)) R_GetCCallable("systemfonts", "locate_font"); } return p_locate_font(family, italic, bold, path, max_path_length); } font_file_t findFontFile(const char* fontname, int bold, int italic) { char *path = new char[PATH_MAX+1]; path[PATH_MAX] = '\0'; font_file_t output; output.index = locate_font(fontname, italic, bold, path, PATH_MAX); output.file = path; delete[] path; if (output.file.size()) return output; else Rcpp::stop("error: unable to match font pattern"); } void CairoContext::setFont(std::string fontname, double fontsize, bool bold, bool italic, std::string fontfile) { std::string key; if (fontfile.size()) { // Use file path as key to cached elements key = fontfile; if (cairo_->fonts.find(key) == cairo_->fonts.end()) { cacheFont(cairo_->fonts, key, fontfile, 0); } } else { // Use font name and bold/italic properties as key char props[20]; snprintf(props, sizeof(props), " %d %d", (int) bold, (int) italic); key = fontname + props; if (cairo_->fonts.find(key) == cairo_->fonts.end()) { // Add font to cache font_file_t fontfile = findFontFile(fontname.c_str(), bold, italic); cacheFont(cairo_->fonts, key, fontfile.file, fontfile.index); } } cairo_set_font_size(cairo_->context, fontsize); cairo_set_font_face(cairo_->context, cairo_->fonts[key]); } FontMetric CairoContext::getExtents(std::string x) { cairo_text_extents_t te; cairo_text_extents(cairo_->context, x.c_str(), &te); FontMetric fm; fm.height = te.height; fm.width = te.x_advance; fm.ascent = -te.y_bearing; fm.descent = te.height + te.y_bearing; return fm; } bool CairoContext::validateGlyphs(std::string x) { cairo_glyph_t* glyphs = NULL; int glyph_count; cairo_text_cluster_t* clusters = NULL; int cluster_count; cairo_text_cluster_flags_t clusterflags; bool out = true; cairo_status_t status = cairo_scaled_font_text_to_glyphs(cairo_get_scaled_font(cairo_->context), 0, 0, x.c_str(), x.size(), &glyphs, &glyph_count, &clusters, &cluster_count, &clusterflags); if (status == CAIRO_STATUS_SUCCESS) { // for each cluster int glyph_index = 0; for (int i = 0; i < cluster_count; i++) { cairo_text_cluster_t* cluster = &clusters[i]; cairo_glyph_t* clusterglyphs = &glyphs[glyph_index]; if( clusterglyphs[0].index < 1 ){ out = false; break; } glyph_index += cluster->num_glyphs; } } else stop("Could not get table of glyphs"); cairo_glyph_free(glyphs); cairo_text_cluster_free(clusters); return out; } gdtools/src/Makevars.win0000644000176200001440000000066714512740476015027 0ustar liggesusersRWINLIB = ../windows/cairo PKG_CPPFLAGS = -I$(RWINLIB)/include/cairo -I$(RWINLIB)/include \ -I$(RWINLIB)/include/freetype2 -I../inst/include -DCAIRO_WIN32_STATIC_BUILD PKG_LIBS = -L$(RWINLIB)/lib$(R_ARCH) -L$(RWINLIB)/lib -lcairo -lfreetype -lpng -lpixman-1 \ -lharfbuzz -lbz2 -lz -liconv -lgdi32 -lrpcrt4 all: clean winlibs winlibs: "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" "../tools/winlibs.R" clean: rm -f $(SHLIB) $(OBJECTS) gdtools/src/gdtools.cpp0000644000176200001440000000125114360611071014671 0ustar liggesusers#include "gdtools_types.h" #include using namespace Rcpp; // [[Rcpp::interfaces(r, cpp)]] // [[Rcpp::export]] XPtrCairoContext context_create() { return XPtrCairoContext(new CairoContext()); } // [[Rcpp::export]] bool context_set_font(XPtrCairoContext cc, std::string fontname, double fontsize, bool bold, bool italic, std::string fontfile = "") { cc->setFont(fontname, fontsize, bold, italic, fontfile); // should return void, but doesn't seem to be supported for cpp // interface return true; } // [[Rcpp::export]] FontMetric context_extents(XPtrCairoContext cc, std::string x) { return cc->getExtents(x); } gdtools/src/font_metrics.cpp0000644000176200001440000000513314360611071015715 0ustar liggesusers#include "gdtools_types.h" #include #include using namespace Rcpp; // [[Rcpp::export]] NumericMatrix str_extents_(CharacterVector x, std::string fontname = "sans", double fontsize = 12, int bold = false, int italic = false, std::string fontfile = "") { int n = x.size(); CairoContext cc; cc.setFont(fontname, fontsize, bold, italic, fontfile); NumericMatrix out(n, 2); for (int i = 0; i < n; ++i) { if (x[i] == NA_STRING) { out(i, 0) = NA_REAL; out(i, 1) = NA_REAL; } else { std::string str(Rf_translateCharUTF8(x[i])); FontMetric fm = cc.getExtents(str); out(i, 0) = fm.width; out(i, 1) = fm.height; } } return out; } // [[Rcpp::export]] NumericVector str_metrics_(CharacterVector x, std::string fontname = "sans", double fontsize = 12, int bold = false, int italic = false, std::string fontfile = "") { CairoContext cc; cc.setFont(fontname, fontsize, bold, italic, fontfile); std::string str(Rf_translateCharUTF8(x[0])); FontMetric fm = cc.getExtents(str); return NumericVector::create( _["width"] = fm.width, _["ascent"] = fm.ascent, _["descent"] = fm.descent ); } // [[Rcpp::export]] NumericMatrix m_str_extents_(CharacterVector x, std::vector fontname, std::vector fontsize, std::vector bold, std::vector italic, std::vector fontfile) { int n = x.size(); CairoContext cc; NumericMatrix out(n, 2); for (int i = 0; i < n; ++i) { cc.setFont(fontname[i], fontsize[i], bold[i], italic[i], fontfile[i]); if (x[i] == NA_STRING) { out(i, 0) = NA_REAL; out(i, 1) = NA_REAL; } else { std::string str(Rf_translateCharUTF8(x[i])); FontMetric fm = cc.getExtents(str); out(i, 0) = fm.width; out(i, 1) = fm.height; } } return out; } // [[Rcpp::export]] LogicalVector glyphs_match_(CharacterVector x, std::string fontname = "sans", int bold = false, int italic = false, std::string fontfile = "") { int n = x.size(); CairoContext cc; cc.setFont(fontname, 10.0, bold, italic, fontfile); LogicalVector out(n); for (int i = 0; i < n; ++i) { if (x[i] == NA_STRING) { out(i) = NA_LOGICAL; } else { std::string str(Rf_translateCharUTF8(x[i])); out(i) = cc.validateGlyphs(str); } } return out; } gdtools/src/Makevars.in0000644000176200001440000000020514360611071014611 0ustar liggesusersPKG_CPPFLAGS=@cflags@ -I../inst/include/ PKG_CXXFLAGS=$(C_VISIBILITY) PKG_LIBS=@libs@ all: clean clean: rm -f $(SHLIB) $(OBJECTS) gdtools/src/versions.cpp0000644000176200001440000000165314360611071015074 0ustar liggesusers#include #include #include FT_FREETYPE_H #include Rcpp::List version_make(int major, int minor, int patch) { Rcpp::IntegerVector version; Rcpp::CharacterVector s3_class; version = Rcpp::IntegerVector::create(major, minor, patch); s3_class = Rcpp::CharacterVector::create("package_version", "numeric_version"); Rcpp::List output; output = Rcpp::List::create(version); output.attr("class") = s3_class; return output; } //' @rdname version_cairo //' @export // [[Rcpp::export]] Rcpp::List version_freetype() { FT_Library library; if (FT_Init_FreeType(&library)) Rcpp::stop("FreeType error: unable to initialise library"); int major, minor, patch = 0; FT_Library_Version(library, &major, &minor, &patch); FT_Done_FreeType(library); return version_make(major, minor, patch); } // [[Rcpp::export]] Rcpp::CharacterVector version_cairo_() { return cairo_version_string(); } gdtools/src/raster_to_base64.cpp0000644000176200001440000001507614360611071016376 0ustar liggesusers#include #include #include #include #include #include "cairo.h" using namespace Rcpp; using namespace std; // [[Rcpp::interfaces(r, cpp)]] #define R_RED(col) (((col) )&255) #define R_GREEN(col) (((col)>> 8)&255) #define R_BLUE(col) (((col)>>16)&255) #define R_ALPHA(col) (((col)>>24)&255) static const std::string base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789+/"; std::string base64_encode(std::vector data) { unsigned int in_len = data.size(); unsigned char* bytes_to_encode = reinterpret_cast(data.data()); std::string ret; int i = 0; int j = 0; unsigned char char_array_3[3]; unsigned char char_array_4[4]; while (in_len--) { char_array_3[i++] = *(bytes_to_encode++); if (i == 3) { char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); char_array_4[3] = char_array_3[2] & 0x3f; for (i = 0; (i < 4); i++) ret += base64_chars[char_array_4[i]]; i = 0; } } if (i) { for (j = i; j < 3; j++) char_array_3[j] = '\0'; char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); char_array_4[3] = char_array_3[2] & 0x3f; for (j = 0; (j < i + 1); j++) ret += base64_chars[char_array_4[j]]; while ((i++ < 3)) ret += '='; } return ret; } static cairo_status_t stream_data(void* closure, const unsigned char* data, unsigned int length) { vector* in = reinterpret_cast*>(closure); for (unsigned int i = 0; i < length; ++i) in->push_back(data[i]); return CAIRO_STATUS_SUCCESS; } /* The Cairo raster code is adapted from R's X11 device (c) 2010 R Development Core Team, GPL 2+ */ cairo_surface_t* raster_paint_surface(std::vector& raster, int w, int h, double width, double height, int interpolate) { int img_width = static_cast (std::ceil(width)); int img_height = static_cast (std::ceil(height)); cairo_surface_t* base_surface = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, img_width, img_height ); cairo_t* cc = cairo_create(base_surface); double w_factor = width / w; double h_factor = height / h; if (std::isnan(w_factor)) w_factor = 1; if (std::isnan(h_factor)) h_factor = 1; cairo_scale(cc, w_factor, h_factor); std::vector imageData(4 * w * h); for (int i = 0; i < w * h; i++) { int alpha = R_ALPHA(raster[i]); imageData[i*4 + 3] = alpha; if (alpha < 255) { imageData[i*4 + 2] = R_RED(raster[i]) * alpha / 255; imageData[i*4 + 1] = R_GREEN(raster[i]) * alpha / 255; imageData[i*4 + 0] = R_BLUE(raster[i]) * alpha / 255; } else { imageData[i*4 + 2] = R_RED(raster[i]); imageData[i*4 + 1] = R_GREEN(raster[i]); imageData[i*4 + 0] = R_BLUE(raster[i]); } } int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, w); cairo_surface_t* image = cairo_image_surface_create_for_data( &imageData[0], CAIRO_FORMAT_ARGB32, w, h, stride ); cairo_set_source_surface(cc, image, 0, 0); if (interpolate > 0) { cairo_pattern_set_filter(cairo_get_source(cc), CAIRO_FILTER_BILINEAR); cairo_pattern_set_extend(cairo_get_source(cc), CAIRO_EXTEND_PAD); } else cairo_pattern_set_filter(cairo_get_source(cc), CAIRO_FILTER_NEAREST); cairo_new_path(cc); cairo_rectangle(cc, 0, 0, w, h); cairo_clip(cc); cairo_paint(cc); cairo_destroy(cc); cairo_surface_destroy(image); return base_surface; } // [[Rcpp::export]] std::string raster_to_str(std::vector raster, int w, int h, double width, double height, int interpolate) { cairo_surface_t* surface = raster_paint_surface( raster, w, h, width, height, interpolate ); std::vector in; cairo_surface_write_to_png_stream(surface, stream_data, &in); cairo_surface_destroy(surface); return base64_encode(in); } // [[Rcpp::export]] int raster_to_file(std::vector raster, int w, int h, double width, double height, int interpolate, std::string filename) { cairo_surface_t* surface = raster_paint_surface( raster, w, h, width, height, interpolate ); cairo_surface_write_to_png(surface, filename.c_str()); cairo_surface_destroy(surface); return 1; } vector convert_hex(vector hcode) { vector bit_coded_colors(hcode.size()); for( size_t i = 0 ; i < hcode.size() ; i++ ){ std::stringstream str_abgr; unsigned int bit_coded_color; string in = "0x"; if( hcode[i].size() == 9 ) { in += hcode[i].substr(7, 2 ); } else in += "FF"; in += hcode[i].substr(5, 2 ); in += hcode[i].substr(3, 2 ); in += hcode[i].substr(1, 2 ); str_abgr << std::hex << in; str_abgr >> bit_coded_color; bit_coded_colors[i] = bit_coded_color; } return bit_coded_colors; } // [[Rcpp::export]] bool raster_png_(CharacterVector raster_, int w, int h, double width, double height, int interpolate, std::string filename) { vector raster = Rcpp::as >(raster_); vector out = convert_hex(raster); raster_to_file(out, w, h, width, height, interpolate, filename); return true; } // [[Rcpp::export]] std::string base64_raster_encode(CharacterVector raster_, int w, int h, double width, double height, int interpolate) { vector raster = Rcpp::as >(raster_); vector out = convert_hex(raster); return raster_to_str(out, w, h, width, height, interpolate); } // Encode a file into base64. // [[Rcpp::export]] std::string base64_file_encode(std::string filename) { ifstream ifs(filename.c_str(), ios::binary | ios::ate); if (!ifs.good()) stop("Failed to open %s", filename); ifstream::pos_type pos = ifs.tellg(); std::vector result(pos); ifs.seekg(0, ios::beg); ifs.read(&result[0], pos); ifs.close(); return base64_encode(result); } // [[Rcpp::export]] std::string base64_string_encode(std::string string) { std::vector chars(string.begin(), string.end()); return base64_encode(chars); } gdtools/NAMESPACE0000644000176200001440000000214314663047117013155 0ustar liggesusers# Generated by roxygen2: do not edit by hand export(addGFontHtmlDependency) export(check_gfonts) export(dummy_setup) export(font_family_exists) export(fontconfig_reinit) export(fonts_cache_dir) export(gfontHtmlDependency) export(glyphs_match) export(init_fonts_cache) export(install_gfont_script) export(installed_gfonts) export(liberationsansHtmlDependency) export(m_str_extents) export(match_family) export(raster_str) export(raster_view) export(raster_write) export(register_gfont) export(register_liberationsans) export(rm_fonts_cache) export(set_dummy_conf) export(str_extents) export(str_metrics) export(sys_fonts) export(unset_dummy_conf) export(version_cairo) export(version_freetype) importFrom(Rcpp,sourceCpp) importFrom(fontquiver,font_faces) importFrom(grDevices,is.raster) importFrom(htmltools,attachDependencies) importFrom(htmltools,htmlDependency) importFrom(htmltools,tags) importFrom(systemfonts,match_fonts) importFrom(systemfonts,register_font) importFrom(systemfonts,registry_fonts) importFrom(systemfonts,system_fonts) importFrom(tools,R_user_dir) importFrom(utils,packageVersion) useDynLib(gdtools) gdtools/LICENSE0000644000176200001440000010451314360611071012735 0ustar liggesusers GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . gdtools/NEWS.md0000644000176200001440000001002514711763523013032 0ustar liggesusers# gdtools 0.4.1 - specify systemfonts version shoud be 1.1.0 (#71) # gdtools 0.4.0 ## Changes - Move 'gfonts' and 'curl' in 'Suggests' dependencies so that it can be used with 'webR'. # gdtools 0.3.7 ## Issues - fix htmlDependancy for Liberation Sans # gdtools 0.3.6 ## Changes - update 'Google Fonts' font database # gdtools 0.3.5 ## Issues - fix -Wformat-security issue under r-devel ## New features - `install_gfont_script()` can now directly generate a script file ready to be executed to install a 'Google Font', use argument `file`. # gdtools 0.3.4 ## Changes - update to libcairo 1.18 - use dontrun macro to avoid CRAN errors # gdtools 0.3.3 ## Issues - no more calls to `gfonts::get_all_fonts()`. This should enable usage for those with no access to website used by 'gfonts'. # gdtools 0.3.2 ## New features - new function `installed_gfonts()` to list installed font from 'Google' # gdtools 0.3.1 ## New features - add 'liberation-sans' for having a fallback when off-line # gdtools 0.3.0 ## New features - The package now allows to download and work with Google Fonts thanks to the 'gfonts' and 'systemfonts' package. This is very useful for managing fonts with graphics produced with 'ragg', 'svglite' and 'ggiraph' but also with 'flextable' tables. Finally, it is possible to easily embed these fonts in HTML documents. # gdtools 0.2.4 * Windows: add support for ucrt toolchains # gdtools 0.2.3 * fixes for configure script for M1 mac and solaris # gdtools 0.2.2 * Small tweaks for configure script # gdtools 0.2.1 ## issues * Change font_family_exists so that it only check a family exists in family column returned by systemfonts::system_fonts() * fix a memory leak # gdtools 0.2.0 * refactor - package is now using package systemfonts instead of using fontconfig to locate fonts file # gdtools 0.1.9 * keep locale intact when using various gdtools functions (fix #51) * Reuse magick FONTCONFIG_PATH if exists # gdtools 0.1.8 * Windows: update cairo stack to rwinlib/cairo v1.15.10 # gdtools 0.1.6 * update with Rcpp 0.12.12 * new function `glyphs_match` to test whether glyphs in strings are all existing in a font table or not. # gdtools 0.1.5 * increase tolerance in font metrics unit-tests as new version of freetype is slightly changing returned extents. # gdtools 0.1.4 * New file src/registerDynamicSymbol.c to correctly register provided routines * a cleanup file to delete src/Makevars when package has been built # gdtools 0.1.3 * Add set_dummy_conf() and unset_dummy_conf() to set a minimalistic Fontconfig configuration. Useful to speed up cache building on Appveyor or CRAN. * skip tests that need fontquiver when not installed. # gdtools 0.1.2 * Fix a crash on some Linux platforms (hadley/svglite#80) # gdtools 0.1.1 ## updates * examples from sys_fonts and match_family are marked as donttest as their first run can be slow if no font caches are existing. # gdtools 0.1.0 ## new functions * sys_fonts: get system fonts details. * font_family_exists: test if a given font family name can be matched exactly * match_family: find best family match for a given Fontconfig pattern * match_font: returns font information for a given Fontconfig pattern * base64_string_export: encode a string in base64 * version_cairo: runtime version of the Cairo library * version_freetype: runtime version of the FreeType library * version_fontconfig: compile-time version of the Fontconfig library ## updates * CONFIGURE file has been updated with Homebrew new repo (Jeroen Ooms) * GPL-3 license file has been added * CairoContext now uses Fontconfig to find system fonts * CairoContext now supports user-defined font files # gdtools 0.0.7 * Fix to let OS X Snow Leopard produce binaries (Jeroen Ooms) # gdtools 0.0.6 * Fix to prevent OSX CRAN builder from linking against old libs in /usr/local/lib (Jeroen Ooms) # gdtools 0.0.5 * new function raster_write to write raster object to a png file * usage of testthat # gdtools 0.0.4 * Fix for Mavericks CRAN builder (Jeroen Ooms) * Fix for solaris CRAN builder (Jeroen Ooms) gdtools/inst/0000755000176200001440000000000014712103265012703 5ustar liggesusersgdtools/inst/include/0000755000176200001440000000000014360611071014324 5ustar liggesusersgdtools/inst/include/gdtools.h0000644000176200001440000000037214360611071016152 0ustar liggesusers// Generated by using Rcpp::compileAttributes() -> do not edit by hand // Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 #ifndef RCPP_gdtools_H_GEN_ #define RCPP_gdtools_H_GEN_ #include "gdtools_RcppExports.h" #endif // RCPP_gdtools_H_GEN_ gdtools/inst/include/gdtools_types.cpp0000644000176200001440000000000014360611071017715 0ustar liggesusersgdtools/inst/include/gdtools_types.h0000644000176200001440000000302414360611071017373 0ustar liggesusers#ifndef __GDTOOLS_TYPES__ #define __GDTOOLS_TYPES__ #include class FontMetric { public: double height, width, ascent, descent; FontMetric(); FontMetric(SEXP); operator SEXP() const ; }; #include using namespace Rcpp; inline FontMetric::FontMetric() {} inline FontMetric::FontMetric(SEXP x_) { Rcpp::NumericVector x(x_); if (x.size() != 4) Rcpp::stop("Invalid size"); width = x[0]; height = x[1]; ascent = x[2]; descent = x[3]; } inline FontMetric::operator SEXP() const { return Rcpp::NumericVector::create(width, height, ascent, descent); } typedef struct _cairo_font_face cairo_font_face_t; class CairoContext { struct CairoContext_; CairoContext_* cairo_; typedef std::map fontCache; public: CairoContext(); ~CairoContext(); void cacheFont(fontCache& cache, std::string& key, std::string fontfile, int fontindex); void cacheSystemFont(std::string& key, std::string& fontname, bool bold, bool italic); void setFont(std::string fontname = "sans", double fontsize = 12, bool bold = false, bool italic = false, std::string fontfile = ""); void setUserFont(std::string& fontname, double fontsize, bool bold, bool italic, std::string& fontfile); void setSystemFont(std::string& fontname, double fontsize, bool bold, bool italic); FontMetric getExtents(std::string x); bool validateGlyphs(std::string x); }; typedef Rcpp::XPtr XPtrCairoContext; #endif gdtools/inst/include/gdtools_RcppExports.h0000644000176200001440000002707414360611071020533 0ustar liggesusers// Generated by using Rcpp::compileAttributes() -> do not edit by hand // Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 #ifndef RCPP_gdtools_RCPPEXPORTS_H_GEN_ #define RCPP_gdtools_RCPPEXPORTS_H_GEN_ #include "gdtools_types.h" #include namespace gdtools { using namespace Rcpp; namespace { void validateSignature(const char* sig) { Rcpp::Function require = Rcpp::Environment::base_env()["require"]; require("gdtools", Rcpp::Named("quietly") = true); typedef int(*Ptr_validate)(const char*); static Ptr_validate p_validate = (Ptr_validate) R_GetCCallable("gdtools", "_gdtools_RcppExport_validate"); if (!p_validate(sig)) { throw Rcpp::function_not_exported( "C++ function with signature '" + std::string(sig) + "' not found in gdtools"); } } } inline XPtrCairoContext context_create() { typedef SEXP(*Ptr_context_create)(); static Ptr_context_create p_context_create = NULL; if (p_context_create == NULL) { validateSignature("XPtrCairoContext(*context_create)()"); p_context_create = (Ptr_context_create)R_GetCCallable("gdtools", "_gdtools_context_create"); } RObject rcpp_result_gen; { RNGScope RCPP_rngScope_gen; rcpp_result_gen = p_context_create(); } if (rcpp_result_gen.inherits("interrupted-error")) throw Rcpp::internal::InterruptedException(); if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) throw Rcpp::LongjumpException(rcpp_result_gen); if (rcpp_result_gen.inherits("try-error")) throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); return Rcpp::as(rcpp_result_gen); } inline bool context_set_font(XPtrCairoContext cc, std::string fontname, double fontsize, bool bold, bool italic, std::string fontfile = "") { typedef SEXP(*Ptr_context_set_font)(SEXP,SEXP,SEXP,SEXP,SEXP,SEXP); static Ptr_context_set_font p_context_set_font = NULL; if (p_context_set_font == NULL) { validateSignature("bool(*context_set_font)(XPtrCairoContext,std::string,double,bool,bool,std::string)"); p_context_set_font = (Ptr_context_set_font)R_GetCCallable("gdtools", "_gdtools_context_set_font"); } RObject rcpp_result_gen; { RNGScope RCPP_rngScope_gen; rcpp_result_gen = p_context_set_font(Shield(Rcpp::wrap(cc)), Shield(Rcpp::wrap(fontname)), Shield(Rcpp::wrap(fontsize)), Shield(Rcpp::wrap(bold)), Shield(Rcpp::wrap(italic)), Shield(Rcpp::wrap(fontfile))); } if (rcpp_result_gen.inherits("interrupted-error")) throw Rcpp::internal::InterruptedException(); if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) throw Rcpp::LongjumpException(rcpp_result_gen); if (rcpp_result_gen.inherits("try-error")) throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); return Rcpp::as(rcpp_result_gen); } inline FontMetric context_extents(XPtrCairoContext cc, std::string x) { typedef SEXP(*Ptr_context_extents)(SEXP,SEXP); static Ptr_context_extents p_context_extents = NULL; if (p_context_extents == NULL) { validateSignature("FontMetric(*context_extents)(XPtrCairoContext,std::string)"); p_context_extents = (Ptr_context_extents)R_GetCCallable("gdtools", "_gdtools_context_extents"); } RObject rcpp_result_gen; { RNGScope RCPP_rngScope_gen; rcpp_result_gen = p_context_extents(Shield(Rcpp::wrap(cc)), Shield(Rcpp::wrap(x))); } if (rcpp_result_gen.inherits("interrupted-error")) throw Rcpp::internal::InterruptedException(); if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) throw Rcpp::LongjumpException(rcpp_result_gen); if (rcpp_result_gen.inherits("try-error")) throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); return Rcpp::as(rcpp_result_gen); } inline std::string raster_to_str(std::vector raster, int w, int h, double width, double height, int interpolate) { typedef SEXP(*Ptr_raster_to_str)(SEXP,SEXP,SEXP,SEXP,SEXP,SEXP); static Ptr_raster_to_str p_raster_to_str = NULL; if (p_raster_to_str == NULL) { validateSignature("std::string(*raster_to_str)(std::vector,int,int,double,double,int)"); p_raster_to_str = (Ptr_raster_to_str)R_GetCCallable("gdtools", "_gdtools_raster_to_str"); } RObject rcpp_result_gen; { RNGScope RCPP_rngScope_gen; rcpp_result_gen = p_raster_to_str(Shield(Rcpp::wrap(raster)), Shield(Rcpp::wrap(w)), Shield(Rcpp::wrap(h)), Shield(Rcpp::wrap(width)), Shield(Rcpp::wrap(height)), Shield(Rcpp::wrap(interpolate))); } if (rcpp_result_gen.inherits("interrupted-error")) throw Rcpp::internal::InterruptedException(); if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) throw Rcpp::LongjumpException(rcpp_result_gen); if (rcpp_result_gen.inherits("try-error")) throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); return Rcpp::as(rcpp_result_gen); } inline int raster_to_file(std::vector raster, int w, int h, double width, double height, int interpolate, std::string filename) { typedef SEXP(*Ptr_raster_to_file)(SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP); static Ptr_raster_to_file p_raster_to_file = NULL; if (p_raster_to_file == NULL) { validateSignature("int(*raster_to_file)(std::vector,int,int,double,double,int,std::string)"); p_raster_to_file = (Ptr_raster_to_file)R_GetCCallable("gdtools", "_gdtools_raster_to_file"); } RObject rcpp_result_gen; { RNGScope RCPP_rngScope_gen; rcpp_result_gen = p_raster_to_file(Shield(Rcpp::wrap(raster)), Shield(Rcpp::wrap(w)), Shield(Rcpp::wrap(h)), Shield(Rcpp::wrap(width)), Shield(Rcpp::wrap(height)), Shield(Rcpp::wrap(interpolate)), Shield(Rcpp::wrap(filename))); } if (rcpp_result_gen.inherits("interrupted-error")) throw Rcpp::internal::InterruptedException(); if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) throw Rcpp::LongjumpException(rcpp_result_gen); if (rcpp_result_gen.inherits("try-error")) throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); return Rcpp::as(rcpp_result_gen); } inline bool raster_png_(CharacterVector raster_, int w, int h, double width, double height, int interpolate, std::string filename) { typedef SEXP(*Ptr_raster_png_)(SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP); static Ptr_raster_png_ p_raster_png_ = NULL; if (p_raster_png_ == NULL) { validateSignature("bool(*raster_png_)(CharacterVector,int,int,double,double,int,std::string)"); p_raster_png_ = (Ptr_raster_png_)R_GetCCallable("gdtools", "_gdtools_raster_png_"); } RObject rcpp_result_gen; { RNGScope RCPP_rngScope_gen; rcpp_result_gen = p_raster_png_(Shield(Rcpp::wrap(raster_)), Shield(Rcpp::wrap(w)), Shield(Rcpp::wrap(h)), Shield(Rcpp::wrap(width)), Shield(Rcpp::wrap(height)), Shield(Rcpp::wrap(interpolate)), Shield(Rcpp::wrap(filename))); } if (rcpp_result_gen.inherits("interrupted-error")) throw Rcpp::internal::InterruptedException(); if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) throw Rcpp::LongjumpException(rcpp_result_gen); if (rcpp_result_gen.inherits("try-error")) throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); return Rcpp::as(rcpp_result_gen); } inline std::string base64_raster_encode(CharacterVector raster_, int w, int h, double width, double height, int interpolate) { typedef SEXP(*Ptr_base64_raster_encode)(SEXP,SEXP,SEXP,SEXP,SEXP,SEXP); static Ptr_base64_raster_encode p_base64_raster_encode = NULL; if (p_base64_raster_encode == NULL) { validateSignature("std::string(*base64_raster_encode)(CharacterVector,int,int,double,double,int)"); p_base64_raster_encode = (Ptr_base64_raster_encode)R_GetCCallable("gdtools", "_gdtools_base64_raster_encode"); } RObject rcpp_result_gen; { RNGScope RCPP_rngScope_gen; rcpp_result_gen = p_base64_raster_encode(Shield(Rcpp::wrap(raster_)), Shield(Rcpp::wrap(w)), Shield(Rcpp::wrap(h)), Shield(Rcpp::wrap(width)), Shield(Rcpp::wrap(height)), Shield(Rcpp::wrap(interpolate))); } if (rcpp_result_gen.inherits("interrupted-error")) throw Rcpp::internal::InterruptedException(); if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) throw Rcpp::LongjumpException(rcpp_result_gen); if (rcpp_result_gen.inherits("try-error")) throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); return Rcpp::as(rcpp_result_gen); } inline std::string base64_file_encode(std::string filename) { typedef SEXP(*Ptr_base64_file_encode)(SEXP); static Ptr_base64_file_encode p_base64_file_encode = NULL; if (p_base64_file_encode == NULL) { validateSignature("std::string(*base64_file_encode)(std::string)"); p_base64_file_encode = (Ptr_base64_file_encode)R_GetCCallable("gdtools", "_gdtools_base64_file_encode"); } RObject rcpp_result_gen; { RNGScope RCPP_rngScope_gen; rcpp_result_gen = p_base64_file_encode(Shield(Rcpp::wrap(filename))); } if (rcpp_result_gen.inherits("interrupted-error")) throw Rcpp::internal::InterruptedException(); if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) throw Rcpp::LongjumpException(rcpp_result_gen); if (rcpp_result_gen.inherits("try-error")) throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); return Rcpp::as(rcpp_result_gen); } inline std::string base64_string_encode(std::string string) { typedef SEXP(*Ptr_base64_string_encode)(SEXP); static Ptr_base64_string_encode p_base64_string_encode = NULL; if (p_base64_string_encode == NULL) { validateSignature("std::string(*base64_string_encode)(std::string)"); p_base64_string_encode = (Ptr_base64_string_encode)R_GetCCallable("gdtools", "_gdtools_base64_string_encode"); } RObject rcpp_result_gen; { RNGScope RCPP_rngScope_gen; rcpp_result_gen = p_base64_string_encode(Shield(Rcpp::wrap(string))); } if (rcpp_result_gen.inherits("interrupted-error")) throw Rcpp::internal::InterruptedException(); if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) throw Rcpp::LongjumpException(rcpp_result_gen); if (rcpp_result_gen.inherits("try-error")) throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); return Rcpp::as(rcpp_result_gen); } } #endif // RCPP_gdtools_RCPPEXPORTS_H_GEN_ gdtools/inst/css/0000755000176200001440000000000014712103265013473 5ustar liggesusersgdtools/inst/css/liberation-sans.css0000644000176200001440000000200114373537446017307 0ustar liggesusers@font-face { font-family: 'Liberation Sans'; font-style: normal; font-weight: 400; src: url('../fonts/LiberationSans-Regular.ttf') format('truetype'), /* Safari, Android, iOS */ url('../fonts/LiberationSans-Regular.woff') format('woff'); } @font-face { font-family: 'Liberation Sans'; font-style: italic; font-weight: 400; src: url('../fonts/LiberationSans-Italic.ttf') format('truetype'), /* Safari, Android, iOS */ url('../fonts/LiberationSans-Italic.woff') format('woff'); } @font-face { font-family: 'Liberation Sans'; font-style: normal; font-weight: 700; src: url('../fonts/LiberationSans-Bold.ttf') format('truetype'), /* Safari, Android, iOS */ url('../fonts/LiberationSans-Bold.woff') format('woff'); } @font-face { font-family: 'Liberation Sans'; font-style: italic; font-weight: 700; src: url('../fonts/LiberationSans-BoldItalic.ttf') format('truetype'), /* Safari, Android, iOS */ url('../fonts/LiberationSans-BoldItalic.woff') format('woff'); } gdtools/tools/0000755000176200001440000000000014512740476013077 5ustar liggesusersgdtools/tools/winlibs.R0000644000176200001440000000157414512740476014700 0ustar liggesusersif(!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.md0000644000176200001440000000400714535106106013206 0ustar liggesusers # gdtools [![CRAN status](https://www.r-pkg.org/badges/version/gdtools)](https://CRAN.R-project.org/package=gdtools) [![R build status](https://github.com/davidgohel/gdtools/workflows/R-CMD-check/badge.svg)](https://github.com/davidgohel/gdtools/actions) [![codecov test coverage](https://codecov.io/gh/davidgohel/gdtools/branch/master/graph/badge.svg)](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/configure0000755000176200001440000000621714712103265013643 0ustar liggesusers# Anticonf script by Jeroen Ooms (2020) # The script will try 'pkg-config' to find required cflags and ldflags. # Make sure this executable is in PATH when installing the package. # Alternatively, you can set INCLUDE_DIR and LIB_DIR manually: # R CMD INSTALL --configure-vars='INCLUDE_DIR=/.../include LIB_DIR=/.../lib' # Library settings PKG_CONFIG_NAME="cairo freetype2" PKG_DEB_NAME="libcairo2-dev" PKG_RPM_NAME="cairo-devel" PKG_CSW_NAME="libcairo_dev" PKG_BREW_NAME="cairo" PKG_LIBS="-lcairo -lfreetype" PKG_TEST_FILE="src/tests/sysdeps.c" # Prefer static linking on MacOS if [ `uname` = "Darwin" ]; then PKG_CONFIG_NAME="--static $PKG_CONFIG_NAME" if [ `arch` = "i386" ]; then export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/opt/libffi/lib/pkgconfig" fi fi # Use pkg-config if available if [ `command -v pkg-config` ]; then PKGCONFIG_CFLAGS=`pkg-config --cflags ${PKG_CONFIG_NAME}` PKGCONFIG_LIBS=`pkg-config --libs ${PKG_CONFIG_NAME}` fi # On CRAN do not use pkgconfig cairo (which depends on XQuartz) if [ -d "/Builds/CRAN-QA-Simon" ] || [ -d "/Volumes/Builds" ]; then unset PKGCONFIG_CFLAGS unset PKGCONFIG_LIBS fi # Note that cflags may be empty in case of success if [ "$INCLUDE_DIR" ] || [ "$LIB_DIR" ]; then echo "Found INCLUDE_DIR and/or LIB_DIR!" PKG_CFLAGS="-I$INCLUDE_DIR $PKG_CFLAGS" PKG_LIBS="-L$LIB_DIR $PKG_LIBS" elif [ "$PKGCONFIG_CFLAGS" ] || [ "$PKGCONFIG_LIBS" ]; then echo "Found pkg-config cflags and libs!" PKG_CFLAGS=${PKGCONFIG_CFLAGS} PKG_LIBS=${PKGCONFIG_LIBS} elif [ `uname` = "Darwin" ]; then brew --version 2>/dev/null if [ $? -eq 0 ]; then BREWDIR=`brew --prefix` PKG_CFLAGS="-I$BREWDIR/include/cairo -I$BREWDIR/include/fontconfig -I$BREWDIR/include/freetype2" PKG_LIBS="-L$BREWDIR/lib $PKG_LIBS" else curl -sfL "https://autobrew.github.io/scripts/cairo" > autobrew . ./autobrew fi fi # Find compiler CC=`${R_HOME}/bin/R CMD config CC` CFLAGS=`${R_HOME}/bin/R CMD config CFLAGS` CPPFLAGS=`${R_HOME}/bin/R CMD config CPPFLAGS` # For debugging echo "Using PKG_CFLAGS=$PKG_CFLAGS" echo "Using PKG_LIBS=$PKG_LIBS" # Test configuration ${CC} ${CPPFLAGS} ${PKG_CFLAGS} ${CFLAGS} -E ${PKG_TEST_FILE} >/dev/null 2>configure.log if [ $? -ne 0 ]; then echo "-----------------------------[ ANTICONF ]-------------------------------" echo "Configuration failed to find libraries. Try installing:" echo " * deb: $PKG_DEB_NAME (Debian, Ubuntu)" echo " * rpm: $PKG_RPM_NAME (Fedora, CentOS, RHEL)" echo " * csw: $PKG_CSW_NAME (Solaris)" echo " * brew: $PKG_BREW_NAME (OSX)" echo "If $PKG_CONFIG_NAME are already installed, check that 'pkg-config' is in your" echo "PATH and PKG_CONFIG_PATH contains a $PKG_CONFIG_NAME.pc file. If pkg-config" echo "is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:" echo "R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'" echo "---------------------------[ ERROR MESSAGE ]----------------------------" cat configure.log echo "------------------------------------------------------------------------" exit 1 fi # Write to Makevars sed -e "s|@cflags@|$PKG_CFLAGS|" -e "s|@libs@|$PKG_LIBS|" src/Makevars.in > src/Makevars # Success exit 0 gdtools/man/0000755000176200001440000000000014663046572012515 5ustar liggesusersgdtools/man/fonts_cache_dir.Rd0000644000176200001440000000265514663046563016126 0ustar liggesusers% 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/m_str_extents.Rd0000644000176200001440000000217014373642552015700 0ustar liggesusers% 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/dummy_setup.Rd0000644000176200001440000000042014360635440015343 0ustar liggesusers% 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/installed_gfonts.Rd0000644000176200001440000000146414663046563016350 0ustar liggesusers% 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 (check_gfonts()) { 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/str_metrics.Rd0000644000176200001440000000112714373642552015341 0ustar liggesusers% 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_write.Rd0000644000176200001440000000131014360611071015473 0ustar liggesusers% 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/version_cairo.Rd0000644000176200001440000000067214360611071015635 0ustar liggesusers% 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/fontconfig_reinit.Rd0000644000176200001440000000065414360611071016501 0ustar liggesusers% 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/set_dummy_conf.Rd0000644000176200001440000000067014360611071016004 0ustar liggesusers% 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/register_gfont.Rd0000644000176200001440000000446614663046563016037 0ustar liggesusers% 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 (check_gfonts()) { 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/liberationsansHtmlDependency.Rd0000644000176200001440000000140714663046563020647 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/liberation-sans.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/register_liberationsans.Rd0000644000176200001440000000152414663046563017727 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/liberation-sans.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/check_gfonts.Rd0000644000176200001440000000077514662453766015460 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/fonts.R \name{check_gfonts} \alias{check_gfonts} \title{Checks the operability of 'gfonts'} \usage{ check_gfonts(errors = FALSE) } \arguments{ \item{errors}{if TRUE, function is triggering errors if a condition is not satisfied.} } \value{ TRUE or FALSE } \description{ Checks that 'gfonts' is installed and can be used. Packages 'curl' and 'gfonts' must be installed and internet connectivity must be active. } \keyword{internal} gdtools/man/str_extents.Rd0000644000176200001440000000131714373642552015366 0ustar liggesusers% 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/raster_str.Rd0000644000176200001440000000153414360611071015161 0ustar liggesusers% 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/glyphs_match.Rd0000644000176200001440000000126514373642552015470 0ustar liggesusers% 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/install_gfont_script.Rd0000644000176200001440000000530614663046563017237 0ustar liggesusers% 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 (check_gfonts()) { 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/addGFontHtmlDependency.Rd0000644000176200001440000000461214663046563017321 0ustar liggesusers% 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 (check_gfonts()) { 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.Rd0000644000176200001440000000113714360611071015425 0ustar liggesusers% 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/font_family_exists.Rd0000644000176200001440000000075714360611071016705 0ustar liggesusers% 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/sys_fonts.Rd0000644000176200001440000000053714373655307015040 0ustar liggesusers% 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/gfontHtmlDependency.Rd0000644000176200001440000000437114663046563016752 0ustar liggesusers% 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[htmltools:htmlDependency]{htmltools::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 (check_gfonts()) { 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/DESCRIPTION0000644000176200001440000000363114712112032013427 0ustar liggesusersPackage: gdtools Title: Utilities for Graphical Rendering and Fonts Management Version: 0.4.1 Authors@R: c( person("David", "Gohel", , "david.gohel@ardata.fr", role = c("aut", "cre")), person("Hadley", "Wickham", , "hadley@rstudio.com", role = "aut"), person("Lionel", "Henry", , "lionel@rstudio.com", role = "aut"), person("Jeroen", "Ooms", , "jeroen@berkeley.edu", role = "aut", 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("ArData", role = "cph"), person("RStudio", role = "cph") ) 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. License: GPL-3 | file LICENSE URL: https://davidgohel.github.io/gdtools/ BugReports: https://github.com/davidgohel/gdtools/issues Depends: R (>= 4.0.0) Imports: fontquiver (>= 0.2.0), htmltools, Rcpp (>= 0.12.12), systemfonts (>= 1.1.0), tools Suggests: curl, gfonts, methods, testthat LinkingTo: Rcpp Encoding: UTF-8 RoxygenNote: 7.3.2 SystemRequirements: cairo, freetype2, fontconfig NeedsCompilation: yes Packaged: 2024-11-04 08:32:53 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: 2024-11-04 09:30:02 UTC