This commit is contained in:
Ryan Oldenburg 2021-05-07 16:09:31 -05:00
parent 84dd01fd00
commit 43e80a70ab
2 changed files with 49 additions and 8 deletions

View file

@ -339,7 +339,15 @@ proc fillText*(
wrap = true,
kerning = true
) =
for _, path in font.typeset(
## Typesets and fills the text. Optional parameters:
## transform: translation or matrix to apply
## bounds: width determines wrapping and halign, height for valign
## hAlign: horizontal alignment of the text
## vAlign: vertical alignment of the text
## textCase: text character case
## wrap: enable/disable text wrapping
## kerning: enable/disable kerning adjustments to letter spacing
for path in font.typeset(
text,
bounds,
hAlign,
@ -362,7 +370,15 @@ proc fillText*(
wrap = true,
kerning = true
) =
for _, path in font.typeset(
## Typesets and fills the text. Optional parameters:
## transform: translation or matrix to apply
## bounds: width determines wrapping and halign, height for valign
## hAlign: horizontal alignment of the text
## vAlign: vertical alignment of the text
## textCase: text character case
## wrap: enable/disable text wrapping
## kerning: enable/disable kerning adjustments to letter spacing
for path in font.typeset(
text,
bounds,
hAlign,
@ -387,7 +403,15 @@ proc strokeText*(
wrap = true,
kerning = true
) =
for _, path in font.typeset(
## Typesets and strokes the text. Optional parameters:
## transform: translation or matrix to apply
## bounds: width determines wrapping and halign, height for valign
## hAlign: horizontal alignment of the text
## vAlign: vertical alignment of the text
## textCase: text character case
## wrap: enable/disable text wrapping
## kerning: enable/disable kerning adjustments to letter spacing
for path in font.typeset(
text,
bounds,
hAlign,
@ -411,7 +435,15 @@ proc strokeText*(
wrap = true,
kerning = true
) =
for _, path in font.typeset(
## Typesets and strokes the text. Optional parameters:
## transform: translation or matrix to apply
## bounds: width determines wrapping and halign, height for valign
## hAlign: horizontal alignment of the text
## vAlign: vertical alignment of the text
## textCase: text character case
## wrap: enable/disable text wrapping
## kerning: enable/disable kerning adjustments to letter spacing
for path in font.typeset(
text,
bounds,
hAlign,

View file

@ -126,6 +126,14 @@ proc typeset*(
wrap = true,
kerning = true
): Arrangement =
## Lays out the character glyphs and returns the arrangement.
## Optional parameters:
## bounds: width determines wrapping and halign, height for valign
## hAlign: horizontal alignment of the text
## vAlign: vertical alignment of the text
## textCase: text character case
## wrap: enable/disable text wrapping
## kerning: enable/disable kerning adjustments to letter spacing
result = Arrangement()
result.font = font
@ -255,16 +263,17 @@ proc typeset*(
result.positions[i].y += yAdjustment
result.selectionRects[i].y += yAdjustment
proc getPath*(arrangement: Arrangement, i: int): Path =
proc getPath*(arrangement: Arrangement, index: int): Path =
## Returns the path for index.
result = arrangement.font.typeface.getGlyphPath(arrangement.runes[i])
result.transform(
translate(arrangement.positions[i]) * scale(vec2(arrangement.font.scale))
)
iterator paths*(arrangement: Arrangement): (int, Path) =
iterator paths*(arrangement: Arrangement): Path =
## Iterates over the paths for the arrangement.
for i in 0 ..< arrangement.runes.len:
if arrangement.runes[i].uint32 > SP.uint32: # Don't draw control runes
yield (i, arrangement.getPath(i))
yield arrangement.getPath(i)
proc parseOtf*(buf: string): Font =
result.typeface = Typeface()