Skip to content

Commit

Permalink
mark: Support mnemonics
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-wolf committed Dec 20, 2023
1 parent d04cd26 commit 82cd1db
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/mark-shapes.typ
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,18 @@
tip-offset: calculate-tip-offset(style)
)
)

// Mark mnemonics
#let mnemonics = (
">": "triangle",
)

// Get a mark shape for a mark name
#let get-mark(ctx, symbol) = {
// TODO: Support user supplied marks by looking them up in the ctx style

if not symbol in marks {
symbol = mnemonics.at(symbol)
}
return marks.at(symbol)
}
8 changes: 4 additions & 4 deletions src/mark.typ
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#import "util.typ"
#import "path-util.typ"
#import "styles.typ"
#import "mark-shapes.typ"
#import "mark-shapes.typ": get-mark

#let check-mark(style) = (style.start, style.end, style.symbol).any(v => v != none)

Expand Down Expand Up @@ -107,8 +107,8 @@
/// -> A dictionary with the keys:
/// - drawables (drawables): The transformed drawables of the mark.
/// - distance: The distance between the tip of the mark and the end.
#let place-mark(style, pos, angle) = {
let (drawables, distance, tip-offset) = (mark-shapes.marks.at(style.symbol))(style)
#let place-mark(ctx, style, pos, angle) = {
let (drawables, distance, tip-offset) = (get-mark(ctx, style.symbol))(style)

return (
drawables: drawable.apply-transform(
Expand All @@ -133,7 +133,7 @@
if style.symbol == none {
continue
}
let mark = (mark-shapes.marks.at(style.symbol))(style)
let mark = (get-mark(ctx, style.symbol))(style)
mark.length = mark.distance + mark.tip-offset

let pos = path-util.point-on-path(
Expand Down

0 comments on commit 82cd1db

Please sign in to comment.