about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-06-30 20:33:52 +0200
committerbptato <nincsnevem662@gmail.com>2024-06-30 20:39:12 +0200
commit7a2a70e672b4ce16890b39af277d94aa5a51ad5a (patch)
tree77f8d2db3302368bb035e7939f4557e54d29feee /src
parente11b25aa7e29a690dd34bb48dd14642f0b7fad62 (diff)
downloadchawan-7a2a70e672b4ce16890b39af277d94aa5a51ad5a.tar.gz
renderdocument: avoid recursion
Diffstat (limited to 'src')
-rw-r--r--src/layout/renderdocument.nim21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/layout/renderdocument.nim b/src/layout/renderdocument.nim
index 89afde32..c247a7fe 100644
--- a/src/layout/renderdocument.nim
+++ b/src/layout/renderdocument.nim
@@ -354,19 +354,21 @@ proc paintInlineFragment(grid: var FlexibleGrid; state: var RenderState;
     let x2 = toInt(offset.x + area.offset.x + area.size.w)
     let y2 = toInt(offset.y + area.offset.y + area.size.h)
     grid.paintBackground(state, bgcolor, x1, y1, x2, y2, fragment.node)
-  if fragment.t == iftParent:
-    for child in fragment.children:
-      grid.paintInlineFragment(state, child, offset, bgcolor)
 
 proc renderInlineFragment(grid: var FlexibleGrid; state: var RenderState;
-    fragment: InlineFragment; offset: Offset) =
+    fragment: InlineFragment; offset: Offset; bgcolor0: ARGBColor) =
   let bgcolor = fragment.computed{"background-color"}
-  if bgcolor.t == ctANSI or bgcolor.t == ctRGB and bgcolor.argbcolor.a > 0:
-    #TODO color blending
-    grid.paintInlineFragment(state, fragment, offset, bgcolor)
+  var bgcolor0 = bgcolor0
+  case bgcolor.t
+  of ctNone: discard
+  of ctANSI: grid.paintInlineFragment(state, fragment, offset, bgcolor)
+  of ctRGB:
+    bgcolor0 = bgcolor0.blend(bgcolor.argbcolor)
+    if bgcolor0.a > 0:
+      grid.paintInlineFragment(state, fragment, offset, cellColor(bgcolor0))
   if fragment.t == iftParent:
     for child in fragment.children:
-      grid.renderInlineFragment(state, child, offset)
+      grid.renderInlineFragment(state, child, offset, bgcolor0)
   else:
     let format = fragment.computed.toFormat()
     for atom in fragment.state.atoms:
@@ -394,7 +396,8 @@ proc renderInlineFragment(grid: var FlexibleGrid; state: var RenderState;
 
 proc renderRootInlineFragment(grid: var FlexibleGrid; state: var RenderState;
     root: RootInlineFragment; offset: Offset) =
-  grid.renderInlineFragment(state, root.fragment, root.state.offset + offset)
+  grid.renderInlineFragment(state, root.fragment, root.state.offset + offset,
+    rgba(0, 0, 0, 0))
 
 proc renderBlockBox(grid: var FlexibleGrid; state: var RenderState;
     box: BlockBox; offset: Offset) =