From def15ede4fbd686b0ee9b193f41b2a47190aa43a Mon Sep 17 00:00:00 2001 From: bptato Date: Thu, 22 Feb 2024 03:00:48 +0100 Subject: layout: remove justify The way `justify' was implemented just made text annoying to read. (The algorithm of distributing spacing evenly does not really work on a cell-based screen because of rounding errors.) CSS 2.1 says: > Conforming user agents may interpret the value 'justify' as 'left' or > 'right', depending on whether the element's default writing direction > is left-to-right or right-to-left, respectively. Since we have no bidi yet, just interpret it as `left'. Maybe in the future we could add an implementation that tries to align line box lengths instead of their contents, but this will probably be difficult to get right. --- src/layout/engine.nim | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) (limited to 'src') diff --git a/src/layout/engine.nim b/src/layout/engine.nim index 170e6443..06e95cdc 100644 --- a/src/layout/engine.nim +++ b/src/layout/engine.nim @@ -319,7 +319,7 @@ proc horizontalAlignLine(ictx: var InlineContext, state: InlineState, max(ictx.size.w, ictx.space.w.u) # we don't support directions for now so left = start and right = end case state.computed{"text-align"} - of TEXT_ALIGN_START, TEXT_ALIGN_LEFT, TEXT_ALIGN_CHA_LEFT: + of TEXT_ALIGN_START, TEXT_ALIGN_LEFT, TEXT_ALIGN_CHA_LEFT, TEXT_ALIGN_JUSTIFY: discard of TEXT_ALIGN_END, TEXT_ALIGN_RIGHT, TEXT_ALIGN_CHA_RIGHT: # move everything @@ -334,25 +334,6 @@ proc horizontalAlignLine(ictx: var InlineContext, state: InlineState, for atom in line.atoms.mitems: atom.offset.x += x ictx.size.w = max(atom.offset.x + atom.size.w, ictx.size.w) - of TEXT_ALIGN_JUSTIFY: - if not state.computed.whitespacepre and not last: - var sumwidth: LayoutUnit = 0 - var spaces = 0 - for atom in line.atoms.mitems: - if atom.t == INLINE_SPACING: - discard - else: - inc spaces - sumwidth += atom.size.w - dec spaces - if spaces > 0: - let spacingwidth = (width - sumwidth) div spaces - line.size.w = 0 - for atom in line.atoms.mitems: - atom.offset.x = line.size.w - if atom.t == INLINE_SPACING: - atom.size.w = spacingwidth - line.size.w += atom.size.w # If necessary, update ictx's width. ictx.size.w = max(line.size.w, ictx.size.w) -- cgit