about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/layout/box.nim10
-rw-r--r--src/layout/engine.nim29
-rw-r--r--src/render/renderdocument.nim16
3 files changed, 39 insertions, 16 deletions
diff --git a/src/layout/box.nim b/src/layout/box.nim
index f9bd2697..4ee7db70 100644
--- a/src/layout/box.nim
+++ b/src/layout/box.nim
@@ -39,6 +39,9 @@ type
     str*: string
     format*: ComputedFormat
 
+  InlineBlock* = ref object of InlineAtom
+    bctx*: BlockContext
+
   InlineRow* = ref object
     atoms*: seq[InlineAtom]
     relx*: int
@@ -61,11 +64,15 @@ type
     shrink*: bool
     format*: ComputedFormat
 
-  BlockContext* = ref object of InlineAtom
+  BlockContext* = ref object
     inline*: InlineContext
     nested*: seq[BlockContext]
     specified*: CSSSpecifiedValues
     viewport*: Viewport
+    relx*: int
+    rely*: int
+    width*: int
+    height*: int
     margin_top*: int
     margin_bottom*: int
     margin_left*: int
@@ -94,6 +101,7 @@ type
     bctx*: BlockContext
 
   InlineBlockBox* = ref object of BlockBox
+    iblock*: InlineBlock # iblock.bctx is equivalent to box.bctx
     ictx*: InlineContext
 
   ListItemBox* = ref object of BlockBox
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index 5d3d2fba..f235b606 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -320,6 +320,10 @@ proc newInlineBlockContext(parent: BlockContext, box: InlineBlockBox): BlockCont
   result = newBlockContext_common(parent, box)
   result.shrink = result.specified{"width"}.auto
 
+proc newInlineBlock(parent: BlockContext, box: InlineBlockBox): InlineBlock =
+  new(result)
+  result.bctx = parent.newInlineBlockContext(box)
+
 # Anonymous block box.
 proc newBlockContext(parent: BlockContext): BlockContext =
   new(result)
@@ -437,15 +441,16 @@ proc arrangeInlines(bctx: BlockContext, selfcontained: bool) =
 proc alignBlock(box: BlockBox, selfcontained = false)
 
 proc alignInlineBlock(bctx: BlockContext, box: InlineBlockBox) =
-  if box.bctx.done:
+  if box.iblock.bctx.done:
     return
   alignBlock(box, true)
 
-  box.bctx.relx += box.bctx.margin_left
-  box.bctx.width += box.bctx.margin_left
-  box.bctx.width += box.bctx.margin_right
+  let iblock = box.iblock
+  iblock.relx = iblock.bctx.relx + iblock.bctx.margin_left
+  iblock.width = iblock.bctx.width + iblock.bctx.margin_left + iblock.bctx.margin_right
+  iblock.height = iblock.bctx.height
 
-  box.ictx.addAtom(box.bctx, bctx.compwidth, box.specified)
+  box.ictx.addAtom(box.iblock, bctx.compwidth, box.specified)
   box.ictx.whitespacenum = 0
 
 # ew.
@@ -637,7 +642,8 @@ proc getPseudoBox(bctx: BlockContext, specified: CSSSpecifiedValues): CSSBox =
     box.bctx = bctx.newBlockContext(box)
   of DISPLAY_INLINE_BLOCK:
     let box = InlineBlockBox(box)
-    box.bctx = bctx.newInlineBlockContext(box)
+    box.iblock = bctx.newInlineBlock(box)
+    box.bctx = box.iblock.bctx
   else:
     discard
 
@@ -669,11 +675,9 @@ proc generateBox(elem: Element, viewport: Viewport, bctx: BlockContext = nil): C
       bctx = box.bctx
     of DISPLAY_INLINE_BLOCK:
       let box = InlineBlockBox(box)
-      if bctx == nil:
-        assert false
-        box.bctx = viewport.newBlockContext()
-      else:
-        box.bctx = bctx.newInlineBlockContext(box)
+      assert bctx != nil
+      box.iblock = bctx.newInlineBlock(box)
+      box.bctx = box.iblock.bctx
       bctx = box.bctx
     else:
       discard
@@ -708,7 +712,8 @@ proc generateBox(elem: Element, viewport: Viewport, bctx: BlockContext = nil): C
     bctx = box.bctx
   of DISPLAY_INLINE_BLOCK:
     let box = InlineBlockBox(box)
-    box.bctx = bctx.newInlineBlockContext(box)
+    box.iblock = bctx.newInlineBlock(box)
+    box.bctx = box.iblock.bctx
     bctx = box.bctx
   else: discard
 
diff --git a/src/render/renderdocument.nim b/src/render/renderdocument.nim
index f2b8d9f8..983999a9 100644
--- a/src/render/renderdocument.nim
+++ b/src/render/renderdocument.nim
@@ -27,6 +27,8 @@ func formatFromWord(computed: ComputedFormat): Format =
   if computed.textdecoration == TEXT_DECORATION_BLINK:
     result.blink = true
 
+#TODO format.pos signifying byte instead of actual position was a huge
+# mistake...
 proc setFormats(lines: var FlexibleGrid, y, ox, i: int, nx, cx: var int,
                 newformat: Format, oformats: seq[FormatCell],
                 str, ostr: string, computed: ComputedFormat = nil) {.inline.} =
@@ -46,8 +48,13 @@ proc setFormats(lines: var FlexibleGrid, y, ox, i: int, nx, cx: var int,
     if cx > newstrwidth + ox:
       # last oformat starts after newformat ends
       nx = ox + newstrwidth
+      eprint "ret"
       return
 
+    if osi >= ostr.len:
+      # I don't even know anymore
+      break
+
     # move nx to cx
     while nsi < str.len and nx < cx:
       var r: Rune
@@ -56,12 +63,14 @@ proc setFormats(lines: var FlexibleGrid, y, ox, i: int, nx, cx: var int,
 
     if format.format.bgcolor != newformat.bgcolor:
       newformat.bgcolor = format.format.bgcolor
+      eprint "odd", i + nsi, newformat.bgcolor, ox, nx
       if computed == nil:
         lines.addFormat(y, i + nsi, newformat)
       else:
         # have to pass nil to force new format... TODO?
         lines.addFormat(y, i + nsi, newformat, nil, computed.node)
 
+  eprint "end", ostr, "->", str, obg, nsi
   # last oformat starts before newformat ends
 
   # move cx to last old char
@@ -78,6 +87,7 @@ proc setFormats(lines: var FlexibleGrid, y, ox, i: int, nx, cx: var int,
 
   if nsi < str.len:
     newformat.bgcolor = obg
+    eprint "add", str, ":", i + nsi
     if computed == nil:
       lines.addFormat(y, i + nsi, newformat)
     else:
@@ -265,9 +275,9 @@ proc renderInlineContext(grid: var FlexibleGrid, ctx: InlineContext, x, y: int,
       grid.addLine()
 
     for atom in row.atoms:
-      if atom of BlockContext:
-        let ctx = BlockContext(atom)
-        grid.renderBlockContext(ctx, x, y, term)
+      if atom of InlineBlock:
+        let iblock = InlineBlock(atom)
+        grid.renderBlockContext(iblock.bctx, x + iblock.relx, y + iblock.rely, term)
       elif atom of InlineWord:
         let word = InlineWord(atom)
         grid.setRowWord(word, x, y, term)