Skip to content

Commit 825382e

Browse files
committed
feat: support for strikethrough decoration
1 parent f95472c commit 825382e

34 files changed

+189
-9
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: flextable
33
Title: Functions for Tabular Reporting
4-
Version: 0.9.11.006
4+
Version: 0.9.11.007
55
Authors@R: c(
66
person("David", "Gohel", , "[email protected]", role = c("aut", "cre")),
77
person("ArData", role = "cph"),

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export(as_i)
7474
export(as_image)
7575
export(as_paragraph)
7676
export(as_raster)
77+
export(as_strike)
7778
export(as_sub)
7879
export(as_sup)
7980
export(as_word_field)

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# flextable 0.9.11
22

3+
## new features
4+
5+
- support strikethrough formatting with `fp_text_default()`.
6+
- new function `as_strike()` to apply strikethrough formatting to text chunks.
7+
38
## Internals
49

510
- Strings metrics are now computed with `gdtools::strings_sizes()` instead of

R/01_fpstruct.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ add_rows_fpstruct <- function(x, nrows, first, default = x$default, ...) {
5757
text_struct <- function(nrow, keys,
5858
color = "black", font.size = 10,
5959
bold = FALSE, italic = FALSE, underlined = FALSE,
60+
strike = FALSE,
6061
font.family = "Arial",
6162
hansi.family = "Arial", eastasia.family = "Arial", cs.family = "Arial",
6263
vertical.align = "baseline",
@@ -67,6 +68,7 @@ text_struct <- function(nrow, keys,
6768
bold = fpstruct(nrow = nrow, keys = keys, default = bold),
6869
italic = fpstruct(nrow = nrow, keys = keys, default = italic),
6970
underlined = fpstruct(nrow = nrow, keys = keys, default = underlined),
71+
strike = fpstruct(nrow = nrow, keys = keys, default = strike),
7072
font.family = fpstruct(nrow = nrow, keys = keys, default = font.family),
7173
hansi.family = fpstruct(nrow = nrow, keys = keys, default = hansi.family),
7274
eastasia.family = fpstruct(nrow = nrow, keys = keys, default = eastasia.family),
@@ -329,7 +331,7 @@ as_chunkset_struct <- function(l_paragraph, keys, i = NULL) {
329331
}
330332

331333
is_paragraph <- function(x) {
332-
chunk_str_names <- c("txt", "font.size", "italic", "bold", "underlined", "color",
334+
chunk_str_names <- c("txt", "font.size", "italic", "bold", "underlined", "strike", "color",
333335
"shading.color", "font.family", "hansi.family", "eastasia.family",
334336
"cs.family", "vertical.align", "width", "height", "url", "eq_data",
335337
"word_field_data", "img_data",
@@ -354,7 +356,7 @@ set_chunkset_struct_element <- function(x, i, j, value) {
354356
}
355357

356358
append_chunkset_struct_element <- function(x, i, j, chunk_data, last = TRUE) {
357-
chunk_str_names <- c("txt", "font.size", "italic", "bold", "underlined", "color",
359+
chunk_str_names <- c("txt", "font.size", "italic", "bold", "underlined", "strike", "color",
358360
"shading.color", "font.family", "hansi.family", "eastasia.family",
359361
"cs.family", "vertical.align", "width", "height", "url", "eq_data",
360362
"word_field_data", "img_data")
@@ -419,7 +421,7 @@ get_chunkset_struct_element <- function(x, i, j) {
419421

420422
replace_missing_fptext_by_default <- function(x, default) {
421423
by_columns <- c(
422-
"font.size", "italic", "bold", "underlined", "color", "shading.color",
424+
"font.size", "italic", "bold", "underlined", "strike", "color", "shading.color",
423425
"font.family", "hansi.family", "eastasia.family", "cs.family",
424426
"vertical.align"
425427
)

R/05_content.R

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#' italic = c(FALSE, TRUE),
2626
#' bold = c(FALSE, TRUE),
2727
#' underlined = c(FALSE, TRUE),
28+
#' strike = c(FALSE, TRUE),
2829
#' color = c("black", "red"),
2930
#' shading.color = c("transparent", "yellow"),
3031
#' font.family = c("Arial", "Arial"),
@@ -42,6 +43,7 @@
4243
#' italic = c(FALSE, TRUE),
4344
#' bold = c(FALSE, TRUE),
4445
#' underlined = c(FALSE, TRUE),
46+
#' strike = c(FALSE, TRUE),
4547
#' color = c("black", "red"),
4648
#' shading.color = c("transparent", "yellow"),
4749
#' font.family = c("Arial", "Arial"),
@@ -73,6 +75,7 @@ chunk_dataframe <- function(...) {
7375
italic = def_lgl,
7476
bold = def_lgl,
7577
underlined = def_lgl,
78+
strike = def_lgl,
7679
color = def_chr,
7780
shading.color = def_chr,
7881
font.family = def_chr,
@@ -103,6 +106,7 @@ default_fptext_prop <- structure(
103106
bold = as.logical(NA_integer_),
104107
italic = as.logical(NA_integer_),
105108
underlined = as.logical(NA_integer_),
109+
strike = as.logical(NA_integer_),
106110
color = NA_character_,
107111
shading.color = NA_character_,
108112
font.family = NA_character_,
@@ -182,6 +186,7 @@ as_chunk <- function(x, props = NULL, formatter = format_fun, ...) {
182186
italic = sapply(props, function(x) x$italic),
183187
bold = sapply(props, function(x) x$bold),
184188
underlined = sapply(props, function(x) x$underlined),
189+
strike = sapply(props, function(x) x$strike),
185190
color = sapply(props, function(x) x$color),
186191
shading.color = sapply(props, function(x) x$shading.color),
187192
font.family = sapply(props, function(x) x$font.family),
@@ -294,6 +299,38 @@ as_b <- function(x) {
294299
x
295300
}
296301

302+
#' @export
303+
#' @title Strikethrough chunk
304+
#' @description The function is producing a chunk with
305+
#' strikethrough font.
306+
#'
307+
#' It is used to add it to the content of a cell of the
308+
#' flextable with the functions [compose()], [append_chunks()]
309+
#' or [prepend_chunks()].
310+
#'
311+
#' @inheritParams as_sub
312+
#' @family chunk elements for paragraph
313+
#' @examples
314+
#' ft <- flextable(head(iris),
315+
#' col_keys = c("Sepal.Length", "dummy")
316+
#' )
317+
#'
318+
#' ft <- compose(ft,
319+
#' j = "dummy",
320+
#' value = as_paragraph(
321+
#' as_strike(Sepal.Length)
322+
#' )
323+
#' )
324+
#'
325+
#' ft
326+
as_strike <- function(x) {
327+
if (!inherits(x, "chunk")) {
328+
x <- as_chunk(x, formatter = format_fun)
329+
}
330+
x$strike <- TRUE
331+
x
332+
}
333+
297334
#' @export
298335
#' @title Italic chunk
299336
#' @description The function is producing a chunk with
@@ -541,6 +578,7 @@ as_equation <- function(x, width = 1, height = .2, unit = "in", props = NULL) {
541578
italic = sapply(props, function(x) x$italic),
542579
bold = sapply(props, function(x) x$bold),
543580
underlined = sapply(props, function(x) x$underlined),
581+
strike = sapply(props, function(x) x$strike),
544582
color = sapply(props, function(x) x$color),
545583
shading.color = sapply(props, function(x) x$shading.color),
546584
font.family = sapply(props, function(x) x$font.family),
@@ -659,6 +697,7 @@ as_word_field <- function(x, props = NULL, width = .1, height = .15, unit = "in"
659697
italic = sapply(props, function(x) x$italic),
660698
bold = sapply(props, function(x) x$bold),
661699
underlined = sapply(props, function(x) x$underlined),
700+
strike = sapply(props, function(x) x$strike),
662701
color = sapply(props, function(x) x$color),
663702
shading.color = sapply(props, function(x) x$shading.color),
664703
font.family = sapply(props, function(x) x$font.family),

R/defaults.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ fp_text_default <- function(color = flextable_global$defaults$font.color,
421421
bold = FALSE,
422422
italic = FALSE,
423423
underlined = FALSE,
424+
strike = FALSE,
424425
font.family = flextable_global$defaults$font.family,
425426
cs.family = NULL, eastasia.family = NULL, hansi.family = NULL,
426427
vertical.align = "baseline",
@@ -434,7 +435,8 @@ fp_text_default <- function(color = flextable_global$defaults$font.color,
434435
font.family = font.family,
435436
cs.family = cs.family, eastasia.family = eastasia.family, hansi.family = hansi.family,
436437
vertical.align = vertical.align,
437-
shading.color = shading.color
438+
shading.color = shading.color,
439+
strike = strike
438440
)
439441
}
440442
#' @export

R/docx_str.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ default_fp_text_wml <- function(value) {
219219
setDT(default_chunks_properties)
220220
default_chunks_properties <- merge(
221221
default_chunks_properties, unique_text_props,
222-
by = c("color", "font.size", "bold", "italic", "underlined", "font.family",
222+
by = c("color", "font.size", "bold", "italic", "underlined", "strike", "font.family",
223223
"hansi.family", "eastasia.family", "cs.family", "vertical.align",
224224
"shading.color")
225225
)

R/flextable.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ set_caption <- function(x,
350350
caption_value <- caption[[1]]
351351

352352
by_columns <- c(
353-
"font.size", "italic", "bold", "underlined", "color", "shading.color",
353+
"font.size", "italic", "bold", "underlined", "strike", "color", "shading.color",
354354
"font.family", "hansi.family", "eastasia.family", "cs.family",
355355
"vertical.align"
356356
)

R/latex_chunks.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ as_table_latexstyle_lr <- function(x) {
6161
underlined_right <- rep("", nrow(x))
6262
underlined_left[x$underlined %in% TRUE] <- "\\underline{"
6363
underlined_right[x$underlined %in% TRUE] <- "}"
64+
underlined_left[x$strike %in% TRUE] <- "\\sout{"
65+
underlined_right[x$strike %in% TRUE] <- "}"
6466
left <- paste0(left, underlined_left)
6567
right <- paste0(underlined_right, right)
6668

R/latex_str.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ list_latex_dep <- function(float = FALSE, wrapfig = FALSE) {
4949
x$multirow <- latex_dependency("multirow")
5050
x$multicol <- latex_dependency("multicol")
5151
x$colortbl <- latex_dependency("colortbl")
52+
x$ulem <- latex_dependency("ulem")
5253
x$hhline <- latex_dependency(
5354
name = "hhline",
5455
extra_lines = c(

0 commit comments

Comments
 (0)