span fixes, more tests
This commit is contained in:
parent
a34831e52c
commit
666746d82e
8 changed files with 103 additions and 6 deletions
|
@ -199,11 +199,9 @@ proc typeset*(
|
||||||
at.y += 1
|
at.y += 1
|
||||||
prevCanWrap = 0
|
prevCanWrap = 0
|
||||||
lines[^1][1] = runeIndex
|
lines[^1][1] = runeIndex
|
||||||
lines.add((runeIndex + 1, 0))
|
if runeIndex + 1 < result.runes.len:
|
||||||
|
lines.add((runeIndex + 1, 0))
|
||||||
else:
|
else:
|
||||||
if rune.canWrap():
|
|
||||||
prevCanWrap = runeIndex
|
|
||||||
|
|
||||||
let advance = advance(font, result.runes, runeIndex)
|
let advance = advance(font, result.runes, runeIndex)
|
||||||
if wrap and rune != SP and bounds.x > 0 and at.x + advance > bounds.x:
|
if wrap and rune != SP and bounds.x > 0 and at.x + advance > bounds.x:
|
||||||
# Wrap to new line
|
# Wrap to new line
|
||||||
|
@ -223,6 +221,9 @@ proc typeset*(
|
||||||
lines[^1][1] = lineStart - 1
|
lines[^1][1] = lineStart - 1
|
||||||
lines.add((lineStart, 0))
|
lines.add((lineStart, 0))
|
||||||
|
|
||||||
|
if rune.canWrap():
|
||||||
|
prevCanWrap = runeIndex
|
||||||
|
|
||||||
result.positions[runeIndex] = at
|
result.positions[runeIndex] = at
|
||||||
result.selectionRects[runeIndex] = rect(at.x, at.y, advance, 0)
|
result.selectionRects[runeIndex] = rect(at.x, at.y, advance, 0)
|
||||||
at.x += advance
|
at.x += advance
|
||||||
|
@ -302,13 +303,12 @@ proc typeset*(
|
||||||
font.defaultLineHeight
|
font.defaultLineHeight
|
||||||
lineHeights[line] = max(lineHeights[line], fontLineHeight)
|
lineHeights[line] = max(lineHeights[line], fontLineHeight)
|
||||||
for runeIndex in start .. stop:
|
for runeIndex in start .. stop:
|
||||||
if line + 1 < lines.len and runeIndex == lines[line][1]:
|
if line + 1 < lines.len and runeIndex == lines[line + 1][0]:
|
||||||
inc line
|
inc line
|
||||||
lineHeights[line] = max(lineHeights[line], fontLineHeight)
|
lineHeights[line] = max(lineHeights[line], fontLineHeight)
|
||||||
# Handle when span and line endings coincide
|
# Handle when span and line endings coincide
|
||||||
if line + 1 < lines.len and stop == lines[line][1]:
|
if line + 1 < lines.len and stop == lines[line][1]:
|
||||||
inc line
|
inc line
|
||||||
lineHeights[line] = max(lineHeights[line], fontLineHeight)
|
|
||||||
|
|
||||||
block: # Vertically position the glyphs
|
block: # Vertically position the glyphs
|
||||||
var
|
var
|
||||||
|
|
BIN
tests/fonts/diffs/spans4.png
Normal file
BIN
tests/fonts/diffs/spans4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 73 KiB |
BIN
tests/fonts/diffs/spans5.png
Normal file
BIN
tests/fonts/diffs/spans5.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 29 KiB |
BIN
tests/fonts/masters/spans4.png
Normal file
BIN
tests/fonts/masters/spans4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 33 KiB |
BIN
tests/fonts/masters/spans5.png
Normal file
BIN
tests/fonts/masters/spans5.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
BIN
tests/fonts/rendered/spans4.png
Normal file
BIN
tests/fonts/rendered/spans4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 81 KiB |
BIN
tests/fonts/rendered/spans5.png
Normal file
BIN
tests/fonts/rendered/spans5.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 33 KiB |
|
@ -707,3 +707,100 @@ block:
|
||||||
image.fillRect(rect, rgba(128, 128, 128, 128))
|
image.fillRect(rect, rgba(128, 128, 128, 128))
|
||||||
|
|
||||||
doDiff(image, "selection_rects3")
|
doDiff(image, "selection_rects3")
|
||||||
|
|
||||||
|
block:
|
||||||
|
let
|
||||||
|
roboto = readFont("tests/fonts/Roboto-Regular_1.ttf")
|
||||||
|
aclonica = readFont("tests/fonts/Aclonica-Regular_1.ttf")
|
||||||
|
ubuntu = readFont("tests/fonts/Ubuntu-Regular_1.ttf")
|
||||||
|
ibm = readFont("tests/fonts/IBMPlexSans-Regular_2.ttf")
|
||||||
|
noto = readFont("tests/fonts/NotoSans-Regular_4.ttf")
|
||||||
|
|
||||||
|
|
||||||
|
var font1 = roboto
|
||||||
|
font1.size = 64
|
||||||
|
|
||||||
|
var font2 = aclonica
|
||||||
|
font2.size = 80
|
||||||
|
|
||||||
|
var font3 = ibm
|
||||||
|
font3.size = 40
|
||||||
|
|
||||||
|
var font4 = ubuntu
|
||||||
|
font4.size = 56
|
||||||
|
|
||||||
|
var font5 = noto
|
||||||
|
font5.size = 72
|
||||||
|
|
||||||
|
var font6 = roboto
|
||||||
|
font6.size = 48
|
||||||
|
|
||||||
|
var font7 = noto
|
||||||
|
font7.size = 64
|
||||||
|
|
||||||
|
var font8 = ubuntu
|
||||||
|
font8.size = 54
|
||||||
|
font8.paint.color = rgba(255, 0 ,0, 255)
|
||||||
|
|
||||||
|
var font9 = roboto
|
||||||
|
font9.size = 48
|
||||||
|
|
||||||
|
var font10 = aclonica
|
||||||
|
font10.size = 48
|
||||||
|
font10.lineHeight = 120
|
||||||
|
|
||||||
|
let spans = @[
|
||||||
|
newSpan("Using spans, ", font1),
|
||||||
|
newSpan("Pixie ", font2),
|
||||||
|
newSpan("can arrange and rasterize ", font3),
|
||||||
|
newSpan("very complex text layouts. ", font4),
|
||||||
|
newSpan("Spans", font5),
|
||||||
|
newSpan(" can have different ", font6),
|
||||||
|
newSpan("font sizes,", font7),
|
||||||
|
newSpan(" colors", font8),
|
||||||
|
newSpan(" and ", font9),
|
||||||
|
newSpan("line heights.", font10)
|
||||||
|
]
|
||||||
|
|
||||||
|
let image = newImage(600, 600)
|
||||||
|
image.fill(rgba(255, 255, 255, 255))
|
||||||
|
|
||||||
|
let arrangement = typeset(spans, bounds = image.wh)
|
||||||
|
|
||||||
|
image.fillText(arrangement)
|
||||||
|
|
||||||
|
doDiff(image, "spans4")
|
||||||
|
|
||||||
|
block:
|
||||||
|
let ubuntu = readFont("tests/fonts/Ubuntu-Regular_1.ttf")
|
||||||
|
|
||||||
|
var font1 = ubuntu
|
||||||
|
font1.size = 15
|
||||||
|
font1.paint.color = parseHtmlColor("#CACACA").rgba()
|
||||||
|
|
||||||
|
var font2 = ubuntu
|
||||||
|
font2.size = 84
|
||||||
|
|
||||||
|
var font3 = ubuntu
|
||||||
|
font3.size = 18
|
||||||
|
font3.paint.color = parseHtmlColor("#007FF4").rgba()
|
||||||
|
|
||||||
|
var font4 = ubuntu
|
||||||
|
font4.size = 20
|
||||||
|
font4.paint.color = parseHtmlColor("#4F4F4F").rgba()
|
||||||
|
|
||||||
|
let spans = @[
|
||||||
|
newSpan("verb [with object] ", font1),
|
||||||
|
newSpan("strallow\n", font2),
|
||||||
|
newSpan("\nstral·low\n", font3),
|
||||||
|
newSpan("\n1. free (something) from restrictive restrictions \"the regulations are intended to strallow changes in public policy\" ", font4)
|
||||||
|
]
|
||||||
|
|
||||||
|
let image = newImage(400, 400)
|
||||||
|
image.fill(rgba(255, 255, 255, 255))
|
||||||
|
|
||||||
|
let arrangement = typeset(spans, bounds = vec2(360, 360))
|
||||||
|
|
||||||
|
image.fillText(arrangement, vec2(20, 20))
|
||||||
|
|
||||||
|
doDiff(image, "spans5")
|
||||||
|
|
Loading…
Reference in a new issue