diff options
author | bptato <nincsnevem662@gmail.com> | 2024-07-29 18:42:20 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-07-29 18:45:22 +0200 |
commit | 1e719997eda085e998d38a90134f26489e50188e (patch) | |
tree | b645f55129bb7749ae4a830a57699794d120a3f1 /src/layout/engine.nim | |
parent | 9653c35fb9a4398942ecb305835a95fbd87c433a (diff) | |
download | chawan-1e719997eda085e998d38a90134f26489e50188e.tar.gz |
buffer, layout: small refactoring
Diffstat (limited to 'src/layout/engine.nim')
-rw-r--r-- | src/layout/engine.nim | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/src/layout/engine.nim b/src/layout/engine.nim index b92676dc..0a92c185 100644 --- a/src/layout/engine.nim +++ b/src/layout/engine.nim @@ -250,7 +250,6 @@ type whitespaceIsLF: bool whitespaceFragment: InlineFragment word: InlineAtom - wordstate: InlineAtomState wrappos: int # position of last wrapping opportunity, or -1 textFragmentSeen: bool lastTextFragment: InlineFragment @@ -325,15 +324,11 @@ proc applyLineHeight(ictx: InlineContext; state: var LineBoxState; state.paddingBottom = max(paddingBottom, state.paddingBottom) state.lineHeight = max(lineHeight, state.lineHeight) -proc newWord(ictx: var InlineContext; state: var InlineState) = +proc newWord(ictx: var InlineContext) = ictx.word = InlineAtom( t: iatWord, size: size(w = 0, h = ictx.cellHeight) ) - ictx.wordstate = InlineAtomState( - vertalign: state.fragment.computed{"vertical-align"}, - baseline: ictx.cellHeight - ) ictx.wrappos = -1 ictx.hasshy = false @@ -528,16 +523,16 @@ proc putAtom(state: var LineBoxState; atom: InlineAtom; state.atoms.add(atom) fragment.state.atoms.add(atom) -proc addSpacing(ictx: var InlineContext; width, height: LayoutUnit; - state: InlineState; hang = false) = +proc addSpacing(ictx: var InlineContext; width: LayoutUnit; state: InlineState; + hang = false) = let fragment = ictx.whitespaceFragment if fragment.state.atoms.len == 0 or fragment.state.atoms[^1].t != iatWord: let atom = InlineAtom( t: iatWord, - size: size(w = 0, h = height), - offset: offset(x = ictx.lbstate.size.w, y = height) + size: size(w = 0, h = ictx.cellHeight), + offset: offset(x = ictx.lbstate.size.w, y = ictx.cellHeight) ) - let iastate = InlineAtomState(baseline: height) + let iastate = InlineAtomState(baseline: atom.size.h) ictx.lbstate.putAtom(atom, iastate, fragment) let atom = fragment.state.atoms[^1] let n = (width div ictx.cellWidth).toInt #TODO @@ -555,7 +550,7 @@ proc flushWhitespace(ictx: var InlineContext; state: InlineState; ictx.lbstate.charwidth += ictx.whitespacenum ictx.whitespacenum = 0 if shift > 0: - ictx.addSpacing(shift, ictx.cellHeight, state, hang) + ictx.addSpacing(shift, state, hang) # Prepare the next line's initial width and available width. # (If space on the left is excluded by floats, set the initial width to @@ -669,7 +664,7 @@ proc addAtom(ictx: var InlineContext; state: var InlineState; shift = ictx.computeShift(state) if atom.size.w > 0 and atom.size.h > 0: if shift > 0: - ictx.addSpacing(shift, ictx.cellHeight, state) + ictx.addSpacing(shift, state) ictx.root.state.xminwidth = max(ictx.root.state.xminwidth, atom.xminwidth) ictx.applyLineHeight(ictx.lbstate, state.fragment.computed) if atom.t == iatWord: @@ -703,8 +698,12 @@ proc addWord(ictx: var InlineContext; state: var InlineState): bool = result = false if ictx.word.str != "": ictx.word.str.mnormalize() #TODO this may break on EOL. - result = ictx.addAtom(state, ictx.wordstate, ictx.word) - ictx.newWord(state) + let iastate = InlineAtomState( + vertalign: state.fragment.computed{"vertical-align"}, + baseline: ictx.word.size.h + ) + result = ictx.addAtom(state, iastate, ictx.word) + ictx.newWord() proc addWordEOL(ictx: var InlineContext; state: var InlineState): bool = result = false @@ -841,7 +840,7 @@ proc layoutTextLoop(ictx: var InlineContext; state: var InlineState; proc layoutText(ictx: var InlineContext; state: var InlineState; s: string) = ictx.flushWhitespace(state) - ictx.newWord(state) + ictx.newWord() let transform = state.fragment.computed{"text-transform"} if transform == TextTransformNone: ictx.layoutTextLoop(state, s) |