From c1b9c6fa86f14598f3d35d070ee66235584aba67 Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Fri, 20 Sep 2024 22:42:28 -0400 Subject: [PATCH] typst lines --- R/build_tt.R | 9 +++++++-- R/style_typst.R | 7 +++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/R/build_tt.R b/R/build_tt.R index 91753b2d..d4cbb9b9 100644 --- a/R/build_tt.R +++ b/R/build_tt.R @@ -90,9 +90,14 @@ build_tt <- function(x, output = NULL) { if (is.null(x@theme[[1]]) || is.function(x@theme[[1]]) || isTRUE(x@theme[[1]] %in% c("default", "striped"))) { # reverse the order of the lines to allow overwriting defaults ls <- x@lazy_style - x <- style_tt(x, i = -x@nhead + 1, line = "t", line_width = 0.1) - x <- style_tt(x, i = 1, line = "t", line_width = 0.05) x <- style_tt(x, i = nrow(x), line = "b", line_width = 0.1) + if (x@nhead > 0) { + x <- style_tt(x, i = -x@nhead + 1, line = "t", line_width = 0.1) + x <- style_tt(x, i = 1, line = "t", line_width = 0.05) + } else { + x <- style_tt(x, i = 1, line = "t", line_width = 0.1) + } + x@lazy_style <- c(x@lazy_style[(length(x@lazy_style) - 3):length(x@lazy_style)], ls) } } diff --git a/R/style_typst.R b/R/style_typst.R index fc4edc22..e872a072 100644 --- a/R/style_typst.R +++ b/R/style_typst.R @@ -155,19 +155,22 @@ style_apply_typst <- function(x) { } lin$i <- lin$i + x@nhead + # not sure why, but seems necessary + if (x@nhead == 0) lin$i <- lin$i + 1 + lin_split <- split(lin, lin[, 3:ncol(lin)]) for (ls in lin_split) { line_h <- "table.hline(y: %s, start: %s, end: %s, stroke: %sem + %s)," line_v <- "table.vline(x: %s, start: %s, end: %s, stroke: %sem + %s)," if (any(grepl("b", ls$line))) { for (h in unique(ls$i)) { - template <- sprintf(line_h, h, min(ls$j) - 1, max(ls$j) + 1, ls$line_width[1], ls$line_color[1]) + template <- sprintf(line_h, h, min(ls$j) - 1, max(ls$j), ls$line_width[1], ls$line_color[1]) x@table_string <- lines_insert(x@table_string, template, "tinytable lines before", "before") } } if (any(grepl("t", ls$line))) { for (h in unique(ls$i)) { - template <- sprintf(line_h, h - 1, min(ls$j) - 1, max(ls$j) + 1, ls$line_width[1], ls$line_color[1]) + template <- sprintf(line_h, h - 1, min(ls$j) - 1, max(ls$j), ls$line_width[1], ls$line_color[1]) x@table_string <- lines_insert(x@table_string, template, "tinytable lines before", "before") } }