about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2021-11-15 20:18:29 +0100
committerbptato <nincsnevem662@gmail.com>2021-11-15 20:18:29 +0100
commit9b95435ae6a859f5da69d2fc473099df5102e243 (patch)
tree65b9d25fef0064fa9401543b15e5fda83b58df7a /src
parent0dc4172725322bdfd66353051cae1b929be52679 (diff)
downloadchawan-9b95435ae6a859f5da69d2fc473099df5102e243.tar.gz
Profiling and more CSS compatibility
Diffstat (limited to 'src')
-rw-r--r--src/io/buffer.nim26
-rw-r--r--src/layout/engine.nim3
-rw-r--r--src/main.nim2
3 files changed, 21 insertions, 10 deletions
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