diff --git a/src/mark.typ b/src/mark.typ index e9d1899c..59c231f8 100644 --- a/src/mark.typ +++ b/src/mark.typ @@ -24,6 +24,7 @@ scale: auto, length: auto, sep: auto, + pos: auto, offset: auto, flex: auto, xy-up: auto, @@ -74,10 +75,15 @@ } // Path length relative attributes - style.offset = if type(style.offset) == ratio { - style.offset * path-length / 100% - } else { - util.resolve-number(ctx, style.offset) + for k in ("offset", "pos",) { + let v = style.at(k) + if v != none and v != auto { + style.insert(k, if type(v) == ratio { + v * path-length / 100% + } else { + util.resolve-number(ctx, v) + }) + } } out.push(style) @@ -151,6 +157,11 @@ continue } + // Override position, if set + if style.pos != none { + distance = style.pos + } + // Apply mark offset distance += style.offset diff --git a/src/styles.typ b/src/styles.typ index 249e41ab..6b03227c 100644 --- a/src/styles.typ +++ b/src/styles.typ @@ -21,7 +21,8 @@ width: 0.15cm, // The size of the mark along the normal of its direction inset: .05cm, // The inner length of some mark shapes, like triangles and brackets sep: .1cm, // The distance between multiple marks along their path - offset: 0cm, + pos: none, // Position override on the path (none, number or path-length ratio) + offset: 0, // Mark extra offset (number or path-length ratio) start: none, // Mark start symbol(s) end: none, // Mark end symbol(s) symbol: none, // Mark symbol diff --git a/tests/mark/pos/ref.png b/tests/mark/pos/ref.png new file mode 100644 index 00000000..347125d6 Binary files /dev/null and b/tests/mark/pos/ref.png differ diff --git a/tests/mark/pos/test.typ b/tests/mark/pos/test.typ new file mode 100644 index 00000000..ea54eef4 --- /dev/null +++ b/tests/mark/pos/test.typ @@ -0,0 +1,28 @@ +#set page(width: auto, height: auto) +#import "/src/lib.typ": * +#import "/tests/helper.typ": * + +// No Position +#test-case({ + import draw: * + set-style(mark: (fill: white)) + line((-1,0), (1,0), mark: (start: ">", end: ">")) +}) + +// Absolute Position +#test-case({ + import draw: * + set-style(mark: (fill: white)) + line((-1,1), (1,1), mark: (start: ">", end: ">", pos: .25, shorten-to: none)) +}) + + +// Relative Offset +#test-case({ + import draw: * + set-style(mark: (fill: white)) + line((-1,0), (1,0), mark: (start: ">", end: ">", pos: 25%, shorten-to: none)) + line((-1,1), (1,1), mark: (end: ">", pos: 50%, shorten-to: none)) + line((-1,2), (1,2), mark: (start: ">", pos: 50%, shorten-to: none)) + line((-1,3), (1,3), mark: (start: (">", (symbol: "|", pos: 50%)), end: ">", shorten-to: 0)) +})