textUber
This commit is contained in:
parent
f45bb70ed7
commit
350d01cda7
1 changed files with 59 additions and 69 deletions
|
@ -425,12 +425,17 @@ proc parseSvgFont*(buf: string): Font =
|
||||||
result.lineHeight = AutoLineHeight
|
result.lineHeight = AutoLineHeight
|
||||||
result.paint = Paint(kind: pkSolid, color: rgbx(0, 0, 0, 255))
|
result.paint = Paint(kind: pkSolid, color: rgbx(0, 0, 0, 255))
|
||||||
|
|
||||||
proc fillText*(
|
proc textUber(
|
||||||
target: Image | Mask,
|
target: Image | Mask,
|
||||||
arrangement: Arrangement,
|
arrangement: Arrangement,
|
||||||
transform: Vec2 | Mat3 = vec2(0, 0)
|
transform: Vec2 | Mat3 = vec2(0, 0),
|
||||||
|
strokeWidth = 1.0,
|
||||||
|
lineCap = lcButt,
|
||||||
|
lineJoin = ljMiter,
|
||||||
|
miterLimit = defaultMiterLimit,
|
||||||
|
dashes: seq[float32] = @[],
|
||||||
|
stroke: static[bool] = false
|
||||||
) =
|
) =
|
||||||
## Fills the text arrangement.
|
|
||||||
var line: int
|
var line: int
|
||||||
for spanIndex, (start, stop) in arrangement.spans:
|
for spanIndex, (start, stop) in arrangement.spans:
|
||||||
let
|
let
|
||||||
|
@ -471,10 +476,45 @@ proc fillText*(
|
||||||
strikeoutThickness
|
strikeoutThickness
|
||||||
)
|
)
|
||||||
|
|
||||||
when type(target) is Image:
|
when stroke:
|
||||||
target.fillPath(path, font.paint, transform)
|
when type(target) is Image:
|
||||||
else: # target is Mask
|
target.strokePath(
|
||||||
target.fillPath(path, transform)
|
path,
|
||||||
|
font.paint,
|
||||||
|
transform,
|
||||||
|
strokeWidth,
|
||||||
|
lineCap,
|
||||||
|
lineJoin,
|
||||||
|
miterLimit,
|
||||||
|
dashes
|
||||||
|
)
|
||||||
|
else: # target is Mask
|
||||||
|
target.strokePath(
|
||||||
|
path,
|
||||||
|
transform,
|
||||||
|
strokeWidth,
|
||||||
|
lineCap,
|
||||||
|
lineJoin,
|
||||||
|
miterLimit,
|
||||||
|
dashes
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
when type(target) is Image:
|
||||||
|
target.fillPath(path, font.paint, transform)
|
||||||
|
else: # target is Mask
|
||||||
|
target.fillPath(path, transform)
|
||||||
|
|
||||||
|
proc fillText*(
|
||||||
|
target: Image | Mask,
|
||||||
|
arrangement: Arrangement,
|
||||||
|
transform: Vec2 | Mat3 = vec2(0, 0)
|
||||||
|
) {.inline.} =
|
||||||
|
## Fills the text arrangement.
|
||||||
|
textUber(
|
||||||
|
target,
|
||||||
|
arrangement,
|
||||||
|
transform
|
||||||
|
)
|
||||||
|
|
||||||
proc fillText*(
|
proc fillText*(
|
||||||
target: Image | Mask,
|
target: Image | Mask,
|
||||||
|
@ -501,69 +541,19 @@ proc strokeText*(
|
||||||
lineJoin = ljMiter,
|
lineJoin = ljMiter,
|
||||||
miterLimit = defaultMiterLimit,
|
miterLimit = defaultMiterLimit,
|
||||||
dashes: seq[float32] = @[]
|
dashes: seq[float32] = @[]
|
||||||
) =
|
) {.inline.} =
|
||||||
## Strokes the text arrangement.
|
## Strokes the text arrangement.
|
||||||
var line: int
|
textUber(
|
||||||
for spanIndex, (start, stop) in arrangement.spans:
|
target,
|
||||||
let
|
arrangement,
|
||||||
font = arrangement.fonts[spanIndex]
|
transform,
|
||||||
underlineThickness = font.typeface.underlineThickness * font.scale
|
strokeWidth,
|
||||||
underlinePosition = font.typeface.underlinePosition * font.scale
|
lineCap,
|
||||||
strikeoutThickness = font.typeface.strikeoutThickness * font.scale
|
lineJoin,
|
||||||
strikeoutPosition = font.typeface.strikeoutPosition * font.scale
|
miterLimit,
|
||||||
for runeIndex in start .. stop:
|
dashes,
|
||||||
let position = arrangement.positions[runeIndex]
|
true
|
||||||
|
)
|
||||||
var path = font.typeface.getGlyphPath(arrangement.runes[runeIndex])
|
|
||||||
path.transform(
|
|
||||||
translate(position) *
|
|
||||||
scale(vec2(font.scale))
|
|
||||||
)
|
|
||||||
|
|
||||||
var applyDecoration = true
|
|
||||||
if runeIndex == arrangement.lines[line][1]:
|
|
||||||
inc line
|
|
||||||
if arrangement.runes[runeIndex] == SP:
|
|
||||||
# Do not apply decoration to the space at end of lines
|
|
||||||
applyDecoration = false
|
|
||||||
|
|
||||||
if applyDecoration:
|
|
||||||
if font.underline:
|
|
||||||
path.rect(
|
|
||||||
arrangement.selectionRects[runeIndex].x,
|
|
||||||
position.y - underlinePosition + underlineThickness / 2,
|
|
||||||
arrangement.selectionRects[runeIndex].w,
|
|
||||||
underlineThickness
|
|
||||||
)
|
|
||||||
if font.strikethrough:
|
|
||||||
path.rect(
|
|
||||||
arrangement.selectionRects[runeIndex].x,
|
|
||||||
position.y - strikeoutPosition,
|
|
||||||
arrangement.selectionRects[runeIndex].w,
|
|
||||||
strikeoutThickness
|
|
||||||
)
|
|
||||||
|
|
||||||
when type(target) is Image:
|
|
||||||
target.strokePath(
|
|
||||||
path,
|
|
||||||
font.paint,
|
|
||||||
transform,
|
|
||||||
strokeWidth,
|
|
||||||
lineCap,
|
|
||||||
lineJoin,
|
|
||||||
miterLimit,
|
|
||||||
dashes
|
|
||||||
)
|
|
||||||
else: # target is Mask
|
|
||||||
target.strokePath(
|
|
||||||
path,
|
|
||||||
transform,
|
|
||||||
strokeWidth,
|
|
||||||
lineCap,
|
|
||||||
lineJoin,
|
|
||||||
miterLimit,
|
|
||||||
dashes
|
|
||||||
)
|
|
||||||
|
|
||||||
proc strokeText*(
|
proc strokeText*(
|
||||||
target: Image | Mask,
|
target: Image | Mask,
|
||||||
|
|
Loading…
Reference in a new issue