blob: 87a6e05cef657b06cb469be57f258379ef0e99a6 [file] [log] [blame]
Marc Kupietzd2be7362023-06-14 07:17:27 +02001#' Posterdown IDS-CD based on HTML format (using pagedown::poster_relaxed)
2#'
3#' @inheritParams pagedown::poster_relaxed
4#' @param ... Additional arguments to `rmarkdown::html_document`
5#'
6#' @return R Markdown output format to pass to
7#' [rmarkdown::render()]
8#'
9#'@examples
10#'\donttest{
11#'file <- file.path(tempdir(),"foo.rmd")
Marc Kupietza39d0cc2024-05-31 12:45:45 +020012#'rmarkdown::draft(file, template="posterdown_ids", package="posterdown.ids")
Marc Kupietzd2be7362023-06-14 07:17:27 +020013#'}
14#'
Marc Kupietza39d0cc2024-05-31 12:45:45 +020015#' @description The output format `posterdown_ids()` mimics the IDS Mannheim
Marc Kupietzd2be7362023-06-14 07:17:27 +020016#' corporate design posters.
Marc Kupietza39d0cc2024-05-31 12:45:45 +020017#' @rdname posterdown_ids
Marc Kupietzd2be7362023-06-14 07:17:27 +020018#' @export
19posterdown_ids <- function(...,
20 template = find_resource("posterdown_ids", "template.html"),
21 css = NULL) {
22 pagedown::poster_relaxed(..., css = css, template = template)
23}
24
Marc Kupietzcbe8b142023-06-24 17:48:20 +020025
Marc Kupietz60a299b2026-08-05 17:45:56 +020026#' @param url Target URL for the QR code
27#' @param logo Optional path to a logo image to place in the center of the QR code
28#' @param text Optional text/caption to display below the QR code (alias: \code{caption})
29#' @param caption Alias for \code{text}
Marc Kupietzcbe8b142023-06-24 17:48:20 +020030#' @description Print html code for a linked qr code to the given url
31#' @importFrom qrcode add_logo qr_code generate_svg
32#' @export
Marc Kupietz60a299b2026-08-05 17:45:56 +020033qrlink <- function(url, logo = NULL, text = NULL, caption = text) {
Marc Kupietzcbe8b142023-06-24 17:48:20 +020034 tmp <- tempfile(fileext = ".svg")
35 qrcode <- qrcode::qr_code(url, ecl = if(is.null(logo)) "L" else "H")
36 if(!is.null(logo)) {
37 qrcode <- qrcode::add_logo(qrcode, logo, ecl = "L")
38 }
39 qrcode::generate_svg(qrcode, tmp, show = FALSE)
Marc Kupietz60a299b2026-08-05 17:45:56 +020040
41 cap_html <- if (!is.null(caption) && nchar(trimws(caption)) > 0) {
42 sprintf('<span class="qrcode-caption">%s</span>', caption)
43 } else {
44 ""
45 }
46
47 if (nchar(cap_html) > 0) {
48 return(paste0( '<div class="qrcode-container"><a class="qrcode" href="', url, '"><img class="qrcode">',
49 gsub("\r?\n|\r", "", readChar(tmp, 1e7)),
50 '</img></a>',
51 cap_html,
52 '</div>'
53 ))
54 } else {
55 return(paste0( sprintf('<a class="qrcode" href="%s"><img class="qrcode">', url),
56 gsub("\r?\n|\r", "", readChar(tmp, 1e7)),
57 '</img></a>'
58 ))
59 }
Marc Kupietzcbe8b142023-06-24 17:48:20 +020060}
61