diff options
author | bptato <nincsnevem662@gmail.com> | 2023-12-11 01:12:26 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-12-11 01:18:22 +0100 |
commit | 6b9db7e8d77c3ce68558f45f9162121a13a96a2b (patch) | |
tree | 9620c5c2266cf0eac24b233024fdecbc49d69e06 /src/layout | |
parent | b787ab592f582fc4e6c9feb7dbec2820aa2f2c7b (diff) | |
download | chawan-6b9db7e8d77c3ce68558f45f9162121a13a96a2b.tar.gz |
css: add text-transform
Probably not fully correct, but it's a good start. Includes proprietary extension -cha-half-width, which converts full-width characters to half-width ones.
Diffstat (limited to 'src/layout')
-rw-r--r-- | src/layout/engine.nim | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/layout/engine.nim b/src/layout/engine.nim index 92a1e251..0f2aba6f 100644 --- a/src/layout/engine.nim +++ b/src/layout/engine.nim @@ -697,9 +697,7 @@ func newInlineContext(bctx: var BlockContext, space: AvailableSpace, ictx.initLine() return ictx -proc layoutText(ictx: var InlineContext, state: var InlineState, str: string) = - ictx.flushWhitespace(state) - ictx.newWord(state) +proc layoutTextLoop(ictx: var InlineContext, state: var InlineState, str: string) = var i = 0 while i < str.len: let c = str[i] @@ -733,6 +731,26 @@ proc layoutText(ictx: var InlineContext, state: var InlineState, str: string) = let shift = ictx.computeShift(state) ictx.currentLine.widthAfterWhitespace = ictx.currentLine.size.w + shift +proc layoutText(ictx: var InlineContext, state: var InlineState, str: string) = + ictx.flushWhitespace(state) + ictx.newWord(state) + case state.computed{"text-transform"} + of TEXT_TRANSFORM_NONE: + ictx.layoutTextLoop(state, str) + {.linearScanEnd.} + of TEXT_TRANSFORM_CAPITALIZE: + ictx.layoutTextLoop(state, str.capitalize()) + of TEXT_TRANSFORM_UPPERCASE: + ictx.layoutTextLoop(state, str.toUpper()) + of TEXT_TRANSFORM_LOWERCASE: + ictx.layoutTextLoop(state, str.toLower()) + of TEXT_TRANSFORM_FULL_WIDTH: + ictx.layoutTextLoop(state, str.fullwidth()) + of TEXT_TRANSFORM_FULL_SIZE_KANA: + ictx.layoutTextLoop(state, str.fullsize()) + of TEXT_TRANSFORM_CHA_HALF_WIDTH: + ictx.layoutTextLoop(state, str.halfwidth()) + func spx(l: CSSLength, lctx: LayoutState, p: SizeConstraint, computed: CSSComputedValues, padding: LayoutUnit): LayoutUnit = let u = l.px(lctx, p) |