aboutsummaryrefslogtreecommitdiffstats
path: root/src/render
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-01-26 22:15:00 +0100
committerbptato <nincsnevem662@gmail.com>2022-01-26 22:16:15 +0100
commit876f5e9c64992ffef8630cd2bafa8c5ba9431f01 (patch)
tree33f318fd1f7f5371d08182a3c99536906f380a37 /src/render
parent402f7595b6c63e668ae09c040410bfa13de5b588 (diff)
downloadchawan-876f5e9c64992ffef8630cd2bafa8c5ba9431f01.tar.gz
Implement padding
Diffstat (limited to 'src/render')
-rw-r--r--src/render/renderdocument.nim46
-rw-r--r--src/render/rendertext.nim4
2 files changed, 27 insertions, 23 deletions
diff --git a/src/render/renderdocument.nim b/src/render/renderdocument.nim
index 89ce4ae6..13cd7b0c 100644
--- a/src/render/renderdocument.nim
+++ b/src/render/renderdocument.nim
@@ -11,24 +11,24 @@ import layout/box
import layout/engine
import utils/twtstr
-func formatFromWord(word: InlineWord): Formatting =
- result.fgcolor = word.color.cellColor()
- if word.fontstyle in { FONT_STYLE_ITALIC, FONT_STYLE_OBLIQUE }:
+func formatFromWord(computed: ComputedFormat): Format =
+ result.fgcolor = computed.color.cellColor()
+ if computed.fontstyle in { FONT_STYLE_ITALIC, FONT_STYLE_OBLIQUE }:
result.italic = true
- if word.fontweight > 500:
+ if computed.fontweight > 500:
result.bold = true
- if word.textdecoration == TEXT_DECORATION_UNDERLINE:
+ if computed.textdecoration == TEXT_DECORATION_UNDERLINE:
result.underline = true
- if word.textdecoration == TEXT_DECORATION_OVERLINE:
+ if computed.textdecoration == TEXT_DECORATION_OVERLINE:
result.overline = true
- if word.textdecoration == TEXT_DECORATION_LINE_THROUGH:
+ if computed.textdecoration == TEXT_DECORATION_LINE_THROUGH:
result.strike = true
proc setRowWord(lines: var FlexibleGrid, word: InlineWord, x, y: int, term: TermAttributes) =
var r: Rune
let y = y div term.ppl
- var x = x div term.ppc
+ var x = (x + word.relx) div term.ppc
var i = 0
while x < 0:
fastRuneAt(word.str, i, r)
@@ -48,13 +48,15 @@ proc setRowWord(lines: var FlexibleGrid, word: InlineWord, x, y: int, term: Term
let oformats = lines[y].formats.subformats(i)
lines[y].setLen(i)
- lines.addFormat(y, i, word.formatFromWord(), word.node)
-
var nx = cx
if nx < x:
+ lines.addFormat(y, i, newFormat())
lines[y].str &= ' '.repeat(x - nx)
+ i += x - nx
nx = x
+ lines.addFormat(y, i, word.format.formatFromWord(), word.format, word.format.node)
+
lines[y].str &= linestr
nx += linestr.width()
@@ -71,7 +73,7 @@ proc setSpacing(lines: var FlexibleGrid, spacing: InlineSpacing, x, y: int, term
var r: Rune
let y = y div term.ppl
- var x = x div term.ppc
+ var x = (x + spacing.relx) div term.ppc
let width = spacing.width div term.ppc
var i = 0
@@ -94,16 +96,16 @@ proc setSpacing(lines: var FlexibleGrid, spacing: InlineSpacing, x, y: int, term
let oformats = lines[y].formats.subformats(i)
lines[y].setLen(i)
- if spacing.word != nil:
- lines.addFormat(y, i, spacing.word.formatFromWord(), spacing.word.node)
-
var nx = cx
if nx < x:
+ lines.addFormat(y, i, newFormat())
lines[y].str &= ' '.repeat(x - nx)
nx = x
lines[y].str &= linestr
nx += linestr.len
+ if spacing.format != nil:
+ lines.addFormat(y, i, spacing.format.formatFromWord(), spacing.format, spacing.format.node)
i = 0
while cx < nx and i < ostr.len:
@@ -117,6 +119,8 @@ proc setSpacing(lines: var FlexibleGrid, spacing: InlineSpacing, x, y: int, term
proc renderBlockContext(grid: var FlexibleGrid, ctx: BlockContext, x, y: int, term: TermAttributes)
proc renderInlineContext(grid: var FlexibleGrid, ctx: InlineContext, x, y: int, term: TermAttributes) =
+ let x = x + ctx.relx
+ let y = y + ctx.rely
for row in ctx.rows:
let x = x + row.relx
let y = y + row.rely + row.height
@@ -126,23 +130,23 @@ proc renderInlineContext(grid: var FlexibleGrid, ctx: InlineContext, x, y: int,
let y = y - atom.height
if atom of BlockContext:
let ctx = BlockContext(atom)
- grid.renderBlockContext(ctx, x + ctx.relx, y + ctx.rely, term)
+ grid.renderBlockContext(ctx, x, y, term)
elif atom of InlineWord:
let word = InlineWord(atom)
- grid.setRowWord(word, x + word.relx, y, term)
+ grid.setRowWord(word, x, y, term)
elif atom of InlineSpacing:
let spacing = InlineSpacing(atom)
- grid.setSpacing(spacing, x + spacing.relx, y, term)
+ grid.setSpacing(spacing, x, y, term)
proc renderBlockContext(grid: var FlexibleGrid, ctx: BlockContext, x, y: int, term: TermAttributes) =
- var x = x
- var y = y
+ let x = x + ctx.relx
+ let y = y + ctx.rely
if ctx.inline != nil:
assert ctx.nested.len == 0
- grid.renderInlineContext(ctx.inline, x + ctx.inline.relx, y, term)
+ grid.renderInlineContext(ctx.inline, x, y, term)
else:
for ctx in ctx.nested:
- grid.renderBlockContext(ctx, x + ctx.relx, y + ctx.rely, term)
+ grid.renderBlockContext(ctx, x, y, term)
const css = staticRead"res/ua.css"
let uastyle = css.parseStylesheet()
diff --git a/src/render/rendertext.nim b/src/render/rendertext.nim
index b5054e7b..15a58c4c 100644
--- a/src/render/rendertext.nim
+++ b/src/render/rendertext.nim
@@ -4,7 +4,7 @@ import io/cell
import utils/twtstr
proc renderPlainText*(text: string): FlexibleGrid =
- var format = newFormatting()
+ var format = newFormat()
template add_format() =
if af:
af = false
@@ -38,7 +38,7 @@ proc renderPlainText*(text: string): FlexibleGrid =
discard result.pop()
proc renderStream*(stream: Stream): FlexibleGrid =
- var format = newFormatting()
+ var format = newFormat()
template add_format() =
if af:
af = false