Skip to content

Commit

Permalink
mark: Support position override
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-wolf committed Dec 30, 2023
1 parent 5d2dcce commit 84d7020
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
19 changes: 15 additions & 4 deletions src/mark.typ
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
scale: auto,
length: auto,
sep: auto,
pos: auto,
offset: auto,
flex: auto,
xy-up: auto,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -151,6 +157,11 @@
continue
}

// Override position, if set
if style.pos != none {
distance = style.pos
}

// Apply mark offset
distance += style.offset

Expand Down
3 changes: 2 additions & 1 deletion src/styles.typ
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added tests/mark/pos/ref.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions tests/mark/pos/test.typ
Original file line number Diff line number Diff line change
@@ -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))
})

0 comments on commit 84d7020

Please sign in to comment.