Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion mpl_typst/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ def draw_text(self, gc: GraphicsContextBase, x: float, y: float, s: str,
alignment = f'{halign} + {valign}'
fontsize = mtext.get_fontsize()
angle = mtext.get_rotation()
rgbText = tuple(gc.get_rgb())[:3]
tcolor = Call('rgb', *[Scalar(c * 100, '%') for c in rgbText])
else:
x = x / self.figure.dpi
y = self.height + y / self.figure.dpi
Expand All @@ -362,7 +364,8 @@ def draw_text(self, gc: GraphicsContextBase, x: float, y: float, s: str,
size=Scalar(fontsize, 'pt'),
alignment=alignment,
baseline=baseline,
angle=Scalar(360 - angle, 'deg'))
angle=Scalar(360 - angle, 'deg'),
tcolor=tcolor)
self.main.append(elem)

def flipy(self):
Expand Down
4 changes: 2 additions & 2 deletions mpl_typst/prologue.typ
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

{{ preamble }}

#let draw-text(dx: 0pt, dy: 0pt, size: 10pt, alignment: center + horizon, baseline: false, angle: 0deg, body) = context {
#let draw-text(dx: 0pt, dy: 0pt, size: 10pt, alignment: center + horizon, baseline: false, angle: 0deg, tcolor: black, body) = context {
// In order to align a text properly, we need to configure bounding box of a
// text.
let top-edge = "cap-height"
Expand All @@ -23,7 +23,7 @@
}

// Measure shape of text block.
let content = text(size: size, top-edge: top-edge, bottom-edge: bot-edge, body)
let content = text(size: size, top-edge: top-edge, bottom-edge: bot-edge, fill: tcolor, body)
let shape = measure(content)

// Adjust horizontal position.
Expand Down
Loading