Skip to content

Commit

Permalink
decorations: Port decorcations to 0.2.0 (#259)
Browse files Browse the repository at this point in the history
Fixes `brace` and `flat-brace` to use the new 0.2.0 API.
  • Loading branch information
johannes-wolf committed Oct 20, 2023
1 parent 080df38 commit 58924ab
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/draw/shapes.typ
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@
let r = process.element(ctx, element)
if r != none {
ctx = r.ctx
if segments != () {
if segments != () and r.drawables != () {
assert.eq(r.drawables.first().type, "path")
let start = path-util.segment-end(segments.last())
let end = path-util.segment-start(r.drawables.first().segments.first())
Expand Down Expand Up @@ -696,4 +696,4 @@
drawables: drawables
)
},)
}
}
2 changes: 1 addition & 1 deletion src/drawable.typ
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,4 @@
} else if symbol == "o" {
circle()
}
}
}
5 changes: 3 additions & 2 deletions src/lib/decorations.typ
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#import "../matrix.typ"
#import "../util.typ"
#import "../draw.typ": *
#import "../coordinate.typ"
#import "../styles.typ"

/// Rotates the vector 'ab' around 'a' and scales it to 'len', returns the absolute point 'c'.
#let _rotate-around(a, b, angle: 90deg, len: auto) = {
Expand Down Expand Up @@ -276,8 +278,7 @@

// all the following code assumes the brace to start at (0, 0), growing to the right,
// pointing upwards, so we set the origin and rotate the entire group accordingly
let start = coordinate.resolve(ctx, start)
let end = coordinate.resolve(ctx, end)
let (_, start, end) = coordinate.resolve(ctx, start, end)
set-origin(start)
rotate(vector.angle2(start, end))

Expand Down
11 changes: 1 addition & 10 deletions src/util.typ
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,8 @@
// Measure content in canvas coordinates
#let measure(ctx, cnt) = {
let size = typst-measure(cnt, ctx.typst-style)

// Transformation matrix:
// sx .. .. .
// .. sy .. .
// .. .. sz .
// .. .. .. 1
// let sx = ctx.transform.at(0).at(0)
// let sy = ctx.transform.at(1).at(1)

return (
calc.abs(size.width / ctx.length),
calc.abs(size.height / ctx.length)
)
}
}
2 changes: 1 addition & 1 deletion tests/decorations/test.typ
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#set page(width: auto, height: auto)
#import "../../src/lib.typ": *
#import "/src/lib.typ": *

#box(stroke: 2pt + red, canvas({
decorations.brace((0, -0), (3, -0))
Expand Down

0 comments on commit 58924ab

Please sign in to comment.