Skip to content

Commit

Permalink
[fonts] fallback to Aptos Narrow width if font not found
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed Jul 15, 2024
1 parent a3c2f1d commit 6ee1444
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions R/converters.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ calc_col_width <- function(base_font, col_width) {
font <- base_font$name$val
size <- as.integer(base_font$size$val)

if (!any(font %in% font_width_tab$FontFamilyName))
font <- "Aptos Narrow"

sel <- font_width_tab$FontFamilyName == font & font_width_tab$FontSize == size
# maximum digit width of selected font
mdw <- font_width_tab$Width[sel]
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-converters.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,10 @@ test_that("", {
expect_equal(got, 8)

})

test_that("unknown font works", {
wb <- wb_workbook()
wb$add_worksheet("Sheet 1")
wb$set_base_font(font_name = "Roboto")
expect_silent(wb$set_col_widths(cols = c(1, 4, 6, 7, 9), widths = c(16, 15, 12, 18, 33)))
})

0 comments on commit 6ee1444

Please sign in to comment.