Skip to content

Commit 3dee4c5

Browse files
Respect Transform-Shape on Standalone Marks (#903)
* mark: Allow optional third argument * mark: Fix `transform-shape` for standalone marks Fixes #893 * mark: Add tests * mark: Update custom mark test
1 parent 061e8ab commit 3dee4c5

File tree

5 files changed

+42
-11
lines changed

5 files changed

+42
-11
lines changed

src/draw/shapes.typ

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -436,18 +436,24 @@
436436
///
437437
/// - from (coordinate): The position to place the mark.
438438
/// - to (coordinate,angle): The position or angle the mark should point towards.
439-
/// - ..style (style):
439+
/// - ..style (str,style): If the third positional argument is of type string, it is treated as mark name (e.g. `">"`) and overrules style keys such as `mark.symbol` or `mark.end`
440440
///
441441
/// ## Styling
442442
/// *Root*: `mark`
443443
///
444444
/// You can directly use the styling from [Mark Styling](/docs/basics/marks).
445445
#let mark(from, to, ..style) = {
446-
assert.eq(
447-
style.pos(),
448-
(),
449-
message: "Unexpected positional arguments: " + repr(style.pos()),
450-
)
446+
let symbol = if style.pos() != () {
447+
assert.eq(type(style.pos().at(0)), str,
448+
message: "Mark name must be of type string")
449+
style.pos().at(0)
450+
} else {
451+
none
452+
}
453+
454+
assert(
455+
style.pos().len() <= 1,
456+
message: "Unexpected positional arguments: " + repr(style.pos()))
451457

452458
let style = style.named()
453459

@@ -461,20 +467,28 @@
461467
let (ctx, ..pts) = coordinate.resolve(ctx, from, to)
462468
let style = styles.resolve(ctx.style, merge: style, root: "mark")
463469

464-
if style.end == none {
465-
style.end = style.symbol
470+
style.end = if symbol != none {
471+
symbol
472+
} else {
473+
style.symbol
466474
}
467475
style.start = none
468476
style.symbol = none
469477

470478
let (to, from) = (..pts)
471479
from = vector.sub(to, vector.sub(from, to))
472480

481+
// Place marks and adjust segments
473482
let drawables = drawable.line-strip((from, to))
474-
drawables = mark_.place-marks-along-path(ctx, style, none, drawables, add-path: false)
483+
if mark_.check-mark(style) {
484+
drawables = mark_.place-marks-along-path(ctx, style, ctx.transform, drawables, add-path: false)
485+
} else {
486+
drawables = drawable.apply-transform(ctx.transform, drawables)
487+
}
488+
475489
return (
476490
ctx: ctx,
477-
drawables: drawable.apply-transform(ctx.transform, drawables)
491+
drawables: drawables,
478492
)
479493
},)
480494
}

tests/custom-mark/test.typ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
line((0,-1), (0,1), stroke: green)
3232

3333
register-face()
34-
mark((0,0), (+1,0), symbol: ":)", slant: 50%, anchor: "center")
34+
mark((0,0), 0deg, ":)", slant: 50%, anchor: "center", flip: true)
3535
})
3636

3737
#test-case({

tests/mark-anchors/ref/1.png

146 Bytes
Loading

tests/mark-single/ref/1.png

908 Bytes
Loading

tests/mark-single/test.typ

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,20 @@
2828
mark((0,0), 180deg, symbol: ">", scale: 3, fill: red)
2929
mark((0,0), 270deg, symbol: ">", scale: 3, fill: yellow)
3030
})
31+
32+
// Positional mark name
33+
#test-case({
34+
import draw: *
35+
36+
// The positional symbol must override the `symbol` key.
37+
mark((0,0), 0deg, ">", symbol: "|", scale: 3)
38+
})
39+
40+
// Transform mark shape
41+
#test-case({
42+
import draw: *
43+
44+
scale(x: 2)
45+
mark((0,0), 0deg, ">", scale: 3)
46+
mark((0,0), 0deg, ">", scale: 3, transform-shape: true)
47+
})

0 commit comments

Comments
 (0)