From 626f18fb5f354037158553a3210ecd424903572a Mon Sep 17 00:00:00 2001 From: David Gohel Date: Wed, 14 Aug 2024 12:59:41 +0200 Subject: [PATCH] feat: add `unit` (in, cm, mm) argument in function `page_size()` fix #579 --- DESCRIPTION | 2 +- NEWS.md | 2 +- R/ooxml_run_objects.R | 7 ++++++- man/page_size.Rd | 9 ++++++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c6810f1a..80aad386 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: officer Title: Manipulation of Microsoft Word and PowerPoint Documents -Version: 0.6.7.003 +Version: 0.6.7.004 Authors@R: c( person("David", "Gohel", , "david.gohel@ardata.fr", role = c("aut", "cre")), person("Stefan", "Moog", , "moogs@gmx.de", role = "aut"), diff --git a/NEWS.md b/NEWS.md index 24a0e876..b282dd4d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,7 +9,7 @@ - new convenience functions `body_replace_gg_at_bkm()` and `body_replace_plot_at_bkm()` to replace text content enclosed in a bookmark with a ggplot or a base plot. - +- add `unit` (in, cm, mm) argument in function `page_size()`. # officer 0.6.6 diff --git a/R/ooxml_run_objects.R b/R/ooxml_run_objects.R index 3f6b5d89..b153bb28 100644 --- a/R/ooxml_run_objects.R +++ b/R/ooxml_run_objects.R @@ -643,10 +643,15 @@ inch_to_tweep <- function(x) round(x * 72 * 20, digits = 0) #' in landscape mode then the length becomes the width and the width becomes the length. #' @param width,height page width, page height (in inches). #' @param orient page orientation, either 'landscape', either 'portrait'. +#' @param unit unit for width and height, one of "in", "cm", "mm". #' @examples #' page_size(orient = "landscape") #' @family functions for section definition -page_size <- function(width = 21 / 2.54, height = 29.7 / 2.54, orient = "portrait") { +page_size <- function(width = 21 / 2.54, height = 29.7 / 2.54, orient = "portrait", unit = "in") { + + width <- convin(unit = unit, x = width) + height <- convin(unit = unit, x = height) + if (orient %in% "portrait") { h <- max(c(height, width)) w <- min(c(height, width)) diff --git a/man/page_size.Rd b/man/page_size.Rd index 16f3e2d3..cfcb9aa4 100644 --- a/man/page_size.Rd +++ b/man/page_size.Rd @@ -4,12 +4,19 @@ \alias{page_size} \title{Page size object} \usage{ -page_size(width = 21/2.54, height = 29.7/2.54, orient = "portrait") +page_size( + width = 21/2.54, + height = 29.7/2.54, + orient = "portrait", + unit = "in" +) } \arguments{ \item{width, height}{page width, page height (in inches).} \item{orient}{page orientation, either 'landscape', either 'portrait'.} + +\item{unit}{unit for width and height, one of "in", "cm", "mm".} } \description{ The function creates a representation of the dimensions of a page. The