From dd9cd51310d7ba0fba0272f1ab07291a2a5013ef Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Sun, 18 Jul 2021 15:41:00 -0500 Subject: [PATCH] font can have mulitple paints but still has simple paint api for 99% case --- src/pixie/fonts.nim | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/pixie/fonts.nim b/src/pixie/fonts.nim index b7cfe73..79ed21e 100644 --- a/src/pixie/fonts.nim +++ b/src/pixie/fonts.nim @@ -16,7 +16,7 @@ type typeface*: Typeface size*: float32 ## Font size in pixels. lineHeight*: float32 ## The line height in pixels or AutoLineHeight for the font's default line height. - paint*: Paint + paints*: seq[Paint] textCase*: TextCase underline*: bool ## Apply an underline. strikethrough*: bool ## Apply a strikethrough. @@ -128,6 +128,15 @@ proc defaultLineHeight*(font: Font): float32 {.inline.} = font.typeface.ascent - font.typeface.descent + font.typeface.lineGap round(fontUnits * font.scale) +proc paint*(font: var Font): var Paint = + font.paints[0] + +proc paint*(font: Font): lent Paint = + font.paints[0] + +proc `paint=`*(font: var Font, paint: Paint) = + font.paints = @[paint] + proc newSpan*(text: string, font: Font): Span = ## Creates a span, associating a font with the text. result = Span() @@ -478,16 +487,17 @@ proc textUber( when stroke: when type(target) is Image: - target.strokePath( - path, - font.paint, - transform, - strokeWidth, - lineCap, - lineJoin, - miterLimit, - dashes - ) + for paint in font.paints: + target.strokePath( + path, + paint, + transform, + strokeWidth, + lineCap, + lineJoin, + miterLimit, + dashes + ) else: # target is Mask target.strokePath( path, @@ -500,7 +510,8 @@ proc textUber( ) else: when type(target) is Image: - target.fillPath(path, font.paint, transform) + for paint in font.paints: + target.fillPath(path, paint, transform) else: # target is Mask target.fillPath(path, transform)