aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2025-01-02 18:00:36 +0100
committerbptato <nincsnevem662@gmail.com>2025-01-02 18:00:36 +0100
commitfa8db221388eaca1ffac1d47e61722563999e278 (patch)
treee3aa1d67871730f94e1b06aae80ee86831926fdd
parent6ac50899d942db740797c9d3277d04b7a535159e (diff)
downloadchawan-fa8db221388eaca1ffac1d47e61722563999e278.tar.gz
layout: ignore general category Me, Mn
I'm not sure if this is the best way. On one hand, it probably breaks text in some languages that cannot be represented in normal form. On the other hand, some terminals may crash on such strange sequences (or worse). I'll just skip them for now, because it's marginally faster than returning 0 from width. We'll see if somebody complains.
-rw-r--r--src/css/layout.nim7
-rw-r--r--src/utils/luwrap.nim10
2 files changed, 16 insertions, 1 deletions
diff --git a/src/css/layout.nim b/src/css/layout.nim
index bb5f5f42..67177b7f 100644
--- a/src/css/layout.nim
+++ b/src/css/layout.nim
@@ -46,6 +46,7 @@ type
imgText: StyledNode
audioText: StyledNode
videoText: StyledNode
+ luctx: LUContext
# min-content: box width is longest word's width
# max-content: box width is content width without wrapping
@@ -843,6 +844,7 @@ func initInlineContext(bctx: var BlockContext; space: AvailableSpace;
proc layoutTextLoop(ictx: var InlineContext; state: var InlineState;
str: string) =
+ let luctx = ictx.lctx.luctx
var i = 0
while i < str.len:
let c = str[i]
@@ -862,6 +864,8 @@ proc layoutTextLoop(ictx: var InlineContext; state: var InlineState;
else:
let pi = i
let u = str.nextUTF8(i)
+ if luctx.isEnclosingMark(u) or luctx.isNonspacingMark(u):
+ continue
let w = u.width()
ictx.checkWrap(state, u, w)
if u == 0xAD: # soft hyphen
@@ -3502,7 +3506,8 @@ proc layout*(root: StyledNode; attrsp: ptr WindowAttributes): BlockBox =
myRootProperties: rootProperties(),
imgText: newStyledText("[img]"),
videoText: newStyledText("[video]"),
- audioText: newStyledText("[audio]")
+ audioText: newStyledText("[audio]"),
+ luctx: LUContext()
)
let box = BlockBox(computed: root.computed, node: root)
var ctx = newInnerBlockContext(root, box, lctx, nil)
diff --git a/src/utils/luwrap.nim b/src/utils/luwrap.nim
index 06057d8d..e2748958 100644
--- a/src/utils/luwrap.nim
+++ b/src/utils/luwrap.nim
@@ -85,6 +85,8 @@ type
lurHiragana = "Hiragana"
lurKatakana = "Katakana"
lurHangul = "Hangul"
+ lurEnclosingMark = "Me"
+ lurNonspacingMark = "Mn"
LUContextObj = object
crs: array[LURangeType, CharRange]
@@ -139,3 +141,11 @@ proc isKatakana*(ctx: LUContext; u: uint32): bool =
proc isHangul*(ctx: LUContext; u: uint32): bool =
ctx.initScript(lurHangul)
return u in ctx.crs[lurHangul]
+
+proc isEnclosingMark*(ctx: LUContext; u: uint32): bool =
+ ctx.initGeneralCategory(lurEnclosingMark)
+ return u in ctx.crs[lurEnclosingMark]
+
+proc isNonspacingMark*(ctx: LUContext; u: uint32): bool =
+ ctx.initGeneralCategory(lurNonspacingMark)
+ return u in ctx.crs[lurNonspacingMark]