Skip to content

Commit

Permalink
typst lines
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Sep 21, 2024
1 parent 3660ffc commit c1b9c6f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 7 additions & 2 deletions R/build_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
7 changes: 5 additions & 2 deletions R/style_typst.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down

0 comments on commit c1b9c6f

Please sign in to comment.