diff options
author | bptato <nincsnevem662@gmail.com> | 2021-11-15 20:18:29 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2021-11-15 20:18:29 +0100 |
commit | 9b95435ae6a859f5da69d2fc473099df5102e243 (patch) | |
tree | 65b9d25fef0064fa9401543b15e5fda83b58df7a | |
parent | 0dc4172725322bdfd66353051cae1b929be52679 (diff) | |
download | chawan-9b95435ae6a859f5da69d2fc473099df5102e243.tar.gz |
Profiling and more CSS compatibility
-rw-r--r-- | makefile | 2 | ||||
-rw-r--r-- | res/default.css | 11 | ||||
-rw-r--r-- | src/io/buffer.nim | 26 | ||||
-rw-r--r-- | src/layout/engine.nim | 3 | ||||
-rw-r--r-- | src/main.nim | 2 |
5 files changed, 31 insertions, 13 deletions
diff --git a/makefile b/makefile index 48382521..8c1e6cca 100644 --- a/makefile +++ b/makefile @@ -6,6 +6,8 @@ debug: $(NIMC) $(FLAGS) $(FILES) release: $(NIMC) $(FLAGS) -d:release -d:strip -d:lto $(FILES) +profile: + $(NIMC) $(FLAGS) --profiler:on --stacktrace:on -d:profile $(FILES) install: cp twt /usr/local/bin/ clean: diff --git a/res/default.css b/res/default.css index de8cf8a4..01228752 100644 --- a/res/default.css +++ b/res/default.css @@ -3,8 +3,7 @@ area, base, source, track, link, meta, param, wbr, head, style, script { } address, blockquote, center, del, dir, div, dl, fieldset, form, h1, h2, h3, h4, -h5, h6, hr, ins, menu, noframes, noscript, ol, p, pre, table, ul, center, dir, -menu, noframes, body { +h5, h6, hr, ins, menu, noframes, noscript, ol, p, pre, table, ul, body { display: block; } @@ -42,6 +41,12 @@ li { display: list-item; } +h1, h2, h3, h4, h5, h6 { + margin-top: 1em; + margin-bottom: 1em; + font-weight: bold; +} + pre { margin-top: 1em; margin-bottom: 1em; @@ -49,7 +54,7 @@ pre { } a { - color: yellow; + color: #c4a000; } a:hover { diff --git a/src/io/buffer.nim b/src/io/buffer.nim index bd37ef91..0dfbf379 100644 --- a/src/io/buffer.nim +++ b/src/io/buffer.nim @@ -548,24 +548,32 @@ proc setLine*(buffer: Buffer, x: int, y: int, line: FlexibleLine) = buffer.lines[y].add(line[i]) inc i -func cellFromLine(line: CSSRowBox, i: int): FlexibleCell = - result.rune = line.runes[i] - result.formatting.fgcolor = line.color.cellColor() +func formatFromLine(line: CSSRowBox): Formatting = + result.fgcolor = line.color.cellColor() if line.fontstyle in { FONT_STYLE_ITALIC, FONT_STYLE_OBLIQUE }: - result.formatting.italic = true + result.italic = true if line.fontweight > 500: - result.formatting.bold = true + result.bold = true if line.textdecoration == TEXT_DECORATION_UNDERLINE: - result.formatting.underline = true + result.underline = true if line.textdecoration == TEXT_DECORATION_OVERLINE: - result.formatting.overline = true + result.overline = true if line.textdecoration == TEXT_DECORATION_LINE_THROUGH: - result.formatting.strike = true + result.strike = true + +func cellFromLine(line: CSSRowBox, i: int, format: Formatting): FlexibleCell = + result.rune = line.runes[i] + result.formatting = format result.nodes = line.nodes proc setRowBox(buffer: Buffer, line: CSSRowBox) = + if line.runes.len == 0: + return + let x = line.x let y = line.y + + let format = line.formatFromLine() while buffer.lines.len <= y: buffer.addLine() @@ -586,7 +594,7 @@ proc setRowBox(buffer: Buffer, line: CSSRowBox) = inc nx while j < line.runes.len: - buffer.lines[y].add(line.cellFromLine(j)) + buffer.lines[y].add(line.cellFromLine(j, format)) nx += line.runes[j].width() inc j diff --git a/src/layout/engine.nim b/src/layout/engine.nim index 7d279b87..7b82cdf9 100644 --- a/src/layout/engine.nim +++ b/src/layout/engine.nim @@ -87,7 +87,8 @@ proc processInlineBox(parent: CSSBox, str: string): CSSBox = fastRuneAt(str, i, r) if rowbox.width + r.width() > ibox.width: inlineWrap(ibox, rowi, fromx, rowbox) - if r.isWhitespace(): + if r != Rune(0x00A0) and #NBSP + r.isWhitespace(): let wsr = ibox.cssvalues[PROPERTY_WHITESPACE].whitespace if ibox.context.whitespace: if ibox.context.ws_initial: diff --git a/src/main.nim b/src/main.nim index 873364b0..dc3db21c 100644 --- a/src/main.nim +++ b/src/main.nim @@ -3,6 +3,8 @@ import uri import os import streams import terminal +when defined(profile): + import nimprof import html/parser import io/buffer |