pixie/examples/text_spans.nim

24 lines
877 B
Nim
Raw Normal View History

2021-05-11 21:35:44 +00:00
import pixie
let image = newImage(200, 200)
image.fill(rgba(255, 255, 255, 255))
2021-09-07 23:46:55 +00:00
let typeface = readTypeface("examples/data/Ubuntu-Regular_1.ttf")
2021-05-11 21:35:44 +00:00
2021-08-12 03:54:55 +00:00
proc newFont(typeface: Typeface, size: float32, color: Color): Font =
2021-08-06 19:05:37 +00:00
result = newFont(typeface)
2021-05-11 21:59:53 +00:00
result.size = size
result.paint.color = color
2021-05-11 21:35:44 +00:00
let spans = @[
2021-08-06 19:05:37 +00:00
newSpan("verb [with object] ",
2021-08-12 03:54:55 +00:00
newFont(typeface, 12, color(0.78125, 0.78125, 0.78125, 1))),
newSpan("strallow\n", newFont(typeface, 36, color(0, 0, 0, 1))),
newSpan("\nstral·low\n", newFont(typeface, 13, color(0, 0.5, 0.953125, 1))),
2021-05-11 22:38:05 +00:00
newSpan("\n1. free (something) from restrictive restrictions \"the regulations are intended to strallow changes in public policy\" ",
2021-08-12 03:54:55 +00:00
newFont(typeface, 14, color(0.3125, 0.3125, 0.3125, 1)))
2021-05-11 21:35:44 +00:00
]
2021-08-17 20:23:01 +00:00
image.fillText(typeset(spans, vec2(180, 180)), translate(vec2(10, 10)))
2021-05-11 21:35:44 +00:00
image.writeFile("examples/text_spans.png")