aboutsummaryrefslogtreecommitdiffstats
path: root/src/render
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-01-23 13:42:24 +0100
committerbptato <nincsnevem662@gmail.com>2022-01-23 13:42:24 +0100
commitd97776fb627720bc4bd5841ffffcd8c9af712f3c (patch)
treefde0f696f78fa4cb197edcee7308403d1d6d22b6 /src/render
parent0b19885b33c53e2250a3a91326e5f146ccfa1492 (diff)
downloadchawan-d97776fb627720bc4bd5841ffffcd8c9af712f3c.tar.gz
Use pixels as the base unit for the layout
Diffstat (limited to 'src/render')
-rw-r--r--src/render/renderdocument.nim78
1 files changed, 11 insertions, 67 deletions
diff --git a/src/render/renderdocument.nim b/src/render/renderdocument.nim
index 9d5e0dcd..8d0b53b1 100644
--- a/src/render/renderdocument.nim
+++ b/src/render/renderdocument.nim
@@ -11,63 +11,6 @@ import layout/box
import layout/engine
import utils/twtstr
-func formatFromLine(line: RowBox): Formatting =
- result.fgcolor = line.color.cellColor()
- if line.fontstyle in { FONT_STYLE_ITALIC, FONT_STYLE_OBLIQUE }:
- result.italic = true
- if line.fontweight > 500:
- result.bold = true
- if line.textdecoration == TEXT_DECORATION_UNDERLINE:
- result.underline = true
- if line.textdecoration == TEXT_DECORATION_OVERLINE:
- result.overline = true
- if line.textdecoration == TEXT_DECORATION_LINE_THROUGH:
- result.strike = true
-
-proc setRowBox(lines: var FlexibleGrid, line: RowBox) =
- var r: Rune
-
- var x = line.x
- var i = 0
- while x < 0:
- fastRuneAt(line.str, i, r)
- x += r.width()
- let linestr = line.str.substr(i)
- i = 0
-
- let y = line.y
-
- while lines.len <= y:
- lines.addLine()
-
- var cx = 0
- while cx < x and i < lines[y].str.len:
- fastRuneAt(lines[y].str, i, r)
- cx += r.width()
-
- let ostr = lines[y].str.substr(i)
- let oformats = lines[y].formats.subformats(i)
- lines[y].setLen(i)
-
- lines.addFormat(y, i, line.formatFromLine(), line.nodes)
-
- var nx = cx
- if nx < x:
- lines[y].str &= ' '.repeat(x - nx)
- nx = x
-
- lines[y].str &= linestr
- nx += linestr.width()
-
- i = 0
- while cx < nx and i < ostr.len:
- fastRuneAt(ostr, i, r)
- cx += r.width()
-
- if i < ostr.len:
- let oline = FlexibleLine(str: ostr.substr(i), formats: oformats.subformats(i))
- lines[y].add(oline)
-
func formatFromWord(word: InlineWord): Formatting =
result.fgcolor = word.color.cellColor()
if word.fontstyle in { FONT_STYLE_ITALIC, FONT_STYLE_OBLIQUE }:
@@ -81,10 +24,11 @@ func formatFromWord(word: InlineWord): Formatting =
if word.textdecoration == TEXT_DECORATION_LINE_THROUGH:
result.strike = true
-proc setRowWord(lines: var FlexibleGrid, word: InlineWord, x, y: int) =
+proc setRowWord(lines: var FlexibleGrid, word: InlineWord, x, y: int, term: TermAttributes) =
var r: Rune
- var x = x
+ let y = y div term.ppl
+ var x = x div term.ppc
var i = 0
while x < 0:
fastRuneAt(word.str, i, r)
@@ -123,9 +67,9 @@ proc setRowWord(lines: var FlexibleGrid, word: InlineWord, x, y: int) =
let oline = FlexibleLine(str: ostr.substr(i), formats: oformats.subformats(i))
lines[y].add(oline)
-proc renderBlockContext(grid: var FlexibleGrid, ctx: BlockContext, x, y: int)
+proc renderBlockContext(grid: var FlexibleGrid, ctx: BlockContext, x, y: int, term: TermAttributes)
-proc renderInlineContext(grid: var FlexibleGrid, ctx: InlineContext, x, y: int) =
+proc renderInlineContext(grid: var FlexibleGrid, ctx: InlineContext, x, y: int, term: TermAttributes) =
for row in ctx.rows:
let x = x + row.relx
let y = y + row.rely + row.height
@@ -135,20 +79,20 @@ 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)
+ grid.renderBlockContext(ctx, x + ctx.relx, y + ctx.rely, term)
elif atom of InlineWord:
let word = InlineWord(atom)
- grid.setRowWord(word, x + word.relx, y)
+ grid.setRowWord(word, x + word.relx, y, term)
-proc renderBlockContext(grid: var FlexibleGrid, ctx: BlockContext, x, y: int) =
+proc renderBlockContext(grid: var FlexibleGrid, ctx: BlockContext, x, y: int, term: TermAttributes) =
var x = x
var y = y
if ctx.inline != nil:
assert ctx.nested.len == 0
- grid.renderInlineContext(ctx.inline, x + ctx.inline.relx, y)
+ grid.renderInlineContext(ctx.inline, x + ctx.inline.relx, y, term)
else:
for ctx in ctx.nested:
- grid.renderBlockContext(ctx, x + ctx.relx, y + ctx.rely)
+ grid.renderBlockContext(ctx, x + ctx.relx, y + ctx.rely, term)
const css = staticRead"res/ua.css"
let uastyle = css.parseStylesheet()
@@ -156,6 +100,6 @@ proc renderDocument*(document: Document, attrs: TermAttributes, userstyle: CSSSt
document.applyStylesheets(uastyle, userstyle)
layout.renderLayout(document)
result.setLen(0)
- result.renderBlockContext(layout.root.bctx, 0, 0)
+ result.renderBlockContext(layout.root.bctx, 0, 0, layout.term)
if result.len == 0:
result.addLine()