Skip to content

Commit

Permalink
typst lines getting closer
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Jan 28, 2024
1 parent 6dd2175 commit 3d250e1
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions R/style_typst.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ style_typst <- function(x,
ival <- c(-1 * rev(seq_len(meta(x)$nhead) - 1), ival)
}

if (isTRUE(grepl("^#", color))) color <- sprintf("rgb(%s)", color)
if (isTRUE(grepl("^#", background))) background <- sprintf("rgb(%s)", background)
if (isTRUE(grepl("^#", line_color))) line_color <- sprintf("rgb(%s)", line_color)

style <- ""

if (!is.null(fontsize)) {
Expand Down Expand Up @@ -88,6 +92,53 @@ let j = (%s,);",
style <- paste0(idx, "\n", style)
}


# Lines are not part of cellspec/rowspec/columnspec. Do this separately.
if (!is.null(line)) {
iline <- jline <- NULL
if (grepl("t", line)) iline <- c(iline, ival + meta(x, "nhead"))
if (grepl("b", line)) iline <- c(iline, ival + meta(x, "nhead"))
if (grepl("l", line)) jline <- c(jline, jval)
if (grepl("r", line)) jline <- c(jline, jval)
iline <- unique(iline)
jline <- unique(jline)
line_width <- paste0(line_width, "em")
if (!is.null(iline)) {
for (i in iline) {
if (!is.null(jline)) {
tmp <- sprintf(
"hlinex(y: %s, start = %s, end = %s, stroke: %s + %s),",
i,
min(jval) - 1,
max(jval),
line_width,
line_color)
} else {
tmp <- sprintf(
"hlinex(y: %s, stroke: %s + %s),",
i,
line_width,
line_color)
}
out <- typst_insert(out, content = tmp, type = "lines")
}
}
# if (!is.null(jline)) {
# tmp <- sprintf(
# "vline{%s}={%s}{solid, %s, %s},",
# paste(jline, collapse = ","),
# paste(ival + meta(x, "nhead"), collapse = ","),
# line_width,
# sub("^#", "c", line_color)
# )
# out <- typst_insert(out, content = tmp, type = "lines")
# }
}
if (!is.null(line)) {
# hlinex(y: 0, stroke: black + .1em),
# hlinex(y: nhead, stroke: black + .05em),
}

out <- typst_insert(out, style, type = "style")

return(out)
Expand Down

0 comments on commit 3d250e1

Please sign in to comment.