diff options
-rw-r--r-- | res/default.css | 21 | ||||
-rw-r--r-- | src/css/style.nim | 24 | ||||
-rw-r--r-- | src/io/buffer.nim | 15 | ||||
-rw-r--r-- | src/io/cell.nim | 2 | ||||
-rw-r--r-- | src/layout/box.nim | 1 | ||||
-rw-r--r-- | src/layout/engine.nim | 1 | ||||
-rw-r--r-- | src/types/enums.nim | 15 |
7 files changed, 59 insertions, 20 deletions
diff --git a/res/default.css b/res/default.css index 113b7ba5..2c154e9f 100644 --- a/res/default.css +++ b/res/default.css @@ -8,16 +8,6 @@ menu, noframes, body { display: block; } -pre { - margin-top: 1em; - margin-bottom: 1em; - white-space: pre; -} - -a { - color: yellow; -} - a, abbr, b, bdo, button, cite, code, del, dfn, em, font, i, img, ins, iframe, kbd, label, map, object, q, samp, select, small, span, strong { @@ -38,6 +28,7 @@ b, strong { u, ins { text-decoration: underline; +} col { display: table-column; @@ -50,3 +41,13 @@ img { li { display: list-item; } + +pre { + margin-top: 1em; + margin-bottom: 1em; + white-space: pre; +} + +a { + color: yellow; +} diff --git a/src/css/style.nim b/src/css/style.nim index 025f6fbc..9f0a0c7c 100644 --- a/src/css/style.nim +++ b/src/css/style.nim @@ -33,6 +33,8 @@ type whitespace*: WhitespaceType of VALUE_INTEGER: integer*: int + of VALUE_TEXT_DECORATION: + textdecoration*: CSSTextDecoration of VALUE_NONE: discard CSSSpecifiedValue* = object of CSSComputedValue @@ -54,6 +56,7 @@ const PropertyNames = { "content": PROPERTY_CONTENT, "white-space": PROPERTY_WHITE_SPACE, "font-weight": PROPERTY_FONT_WEIGHT, + "text-decoration": PROPERTY_TEXT_DECORATION, }.toTable() const ValueTypes = { @@ -70,10 +73,12 @@ const ValueTypes = { PROPERTY_CONTENT: VALUE_CONTENT, PROPERTY_WHITE_SPACE: VALUE_WHITE_SPACE, PROPERTY_FONT_WEIGHT: VALUE_INTEGER, + PROPERTY_TEXT_DECORATION: VALUE_TEXT_DECORATION, }.toTable() const InheritedProperties = { - PROPERTY_COLOR, PROPERTY_FONT_STYLE, PROPERTY_WHITE_SPACE, PROPERTY_FONT_WEIGHT + PROPERTY_COLOR, PROPERTY_FONT_STYLE, PROPERTY_WHITE_SPACE, + PROPERTY_FONT_WEIGHT, PROPERTY_TEXT_DECORATION } func getPropInheritedArray(): array[low(CSSPropertyType)..high(CSSPropertyType), bool] = @@ -300,14 +305,24 @@ func cssFontWeight(d: CSSDeclaration): int = of "bold": return 700 of "lighter": return 400 of "bolder": return 700 - else: return 400 elif tok.tokenType == CSS_NUMBER_TOKEN: return int(tok.nvalue) raise newException(CSSValueError, "Invalid font weight") -proc cssGlobal(d: CSSDeclaration): CSSGlobalValueType = +func cssTextDecoration(d: CSSDeclaration): CSSTextDecoration = + if isToken(d): + let tok = getToken(d) + if tok.tokenType == CSS_IDENT_TOKEN: + case $tok.value + of "underline": return TEXT_DECORATION_UNDERLINE + of "overline": return TEXT_DECORATION_OVERLINE + of "line-through": return TEXT_DECORATION_LINE_THROUGH + of "blink": return TEXT_DECORATION_BLINK + raise newException(CSSValueError, "Invalid text decoration") + +func cssGlobal(d: CSSDeclaration): CSSGlobalValueType = if isToken(d): let tok = getToken(d) if tok.tokenType == CSS_IDENT_TOKEN: @@ -336,6 +351,7 @@ func getSpecifiedValue*(d: CSSDeclaration): CSSSpecifiedValue = of PROPERTY_FONT_WEIGHT: result.integer = cssFontWeight(d) else: discard #??? + of VALUE_TEXT_DECORATION: result.textdecoration = cssTextDecoration(d) of VALUE_NONE: discard except CSSValueError: result.globalValue = VALUE_UNSET @@ -393,6 +409,8 @@ func getComputedValue*(prop: CSSSpecifiedValue, current: CSSComputedValues): CSS return CSSComputedValue(t: prop.t, v: VALUE_WHITESPACE, whitespace: prop.whitespace) of VALUE_INTEGER: return CSSComputedValue(t: prop.t, v: VALUE_INTEGER, integer: prop.integer) + of VALUE_TEXT_DECORATION: + return CSSComputedValue(t: prop.t, v: VALUE_TEXT_DECORATION, textdecoration: prop.textdecoration) of VALUE_NONE: return CSSComputedValue(t: prop.t, v: VALUE_NONE) func getComputedValue*(d: CSSDeclaration, current: CSSComputedValues): CSSComputedValue = diff --git a/src/io/buffer.nim b/src/io/buffer.nim index 47148363..79f8415b 100644 --- a/src/io/buffer.nim +++ b/src/io/buffer.nim @@ -76,8 +76,7 @@ func generateFullOutput*(buffer: Buffer): seq[string] = result.add(s) x = 0 s = "" - - s &= "\e[0m" + s &= "\e[m" if cell.fgcolor != defaultColor: var color = cell.fgcolor if color.rgb: @@ -100,6 +99,10 @@ func generateFullOutput*(buffer: Buffer): seq[string] = s &= "\e[3m" if cell.underline: s &= "\e[4m" + if cell.strike: + s &= "\e[9m" + if cell.overline: + s &= "\e[53m" s &= $cell.runes inc x @@ -556,6 +559,12 @@ func cellFromLine(line: CSSRowBox, i: int): FlexibleCell = result.italic = true if line.fontweight > 500: result.bold = true + if line.textdecoration == TEXT_DECORATION_UNDERLINE: + result.underline = true + if line.textdecoration == TEXT_DECORATION_OVERLINE: + result.overline = true + if line.textdecoration == TEXT_DECORATION_LINE_THROUGH: + result.strike = true proc setRowBox(buffer: Buffer, line: CSSRowBox) = let x = line.x @@ -639,6 +648,8 @@ proc refreshDisplay*(buffer: Buffer) = buffer.display[dls + j - n].italic = line[i].italic buffer.display[dls + j - n].bold = line[i].bold buffer.display[dls + j - n].underline = line[i].underline + buffer.display[dls + j - n].strike = line[i].strike + buffer.display[dls + j - n].overline = line[i].overline j += line[i].rune.width() inc i diff --git a/src/io/cell.nim b/src/io/cell.nim index 6ea887e3..50094e88 100644 --- a/src/io/cell.nim +++ b/src/io/cell.nim @@ -10,6 +10,8 @@ type italic*: bool bold*: bool underline*: bool + strike*: bool + overline*: bool FlexibleCell* = object of Cell rune*: Rune diff --git a/src/layout/box.nim b/src/layout/box.nim index 0dce03e0..60da87f7 100644 --- a/src/layout/box.nim +++ b/src/layout/box.nim @@ -46,6 +46,7 @@ type color*: CSSColor fontstyle*: CSSFontStyle fontweight*: int + textdecoration*: CSSTextDecoration runes*: seq[Rune] CSSInlineBox* = ref CSSInlineBoxObj diff --git a/src/layout/engine.nim b/src/layout/engine.nim index 2ef4b43e..a8519c3f 100644 --- a/src/layout/engine.nim +++ b/src/layout/engine.nim @@ -52,6 +52,7 @@ proc setup(rowbox: var CSSRowBox, cssvalues: CSSComputedValues) = rowbox.color = cssvalues[PROPERTY_COLOR].color rowbox.fontstyle = cssvalues[PROPERTY_FONT_STYLE].fontstyle rowbox.fontweight = cssvalues[PROPERTY_FONT_WEIGHT].integer + rowbox.textdecoration = cssvalues[PROPERTY_TEXT_DECORATION].textdecoration proc inlineWrap(ibox: var CSSInlineBox, rowi: var int, fromx: var int, rowbox: var CSSRowBox) = ibox.content.add(rowbox) diff --git a/src/types/enums.nim b/src/types/enums.nim index 09adb5ca..db7a87e7 100644 --- a/src/types/enums.nim +++ b/src/types/enums.nim @@ -67,21 +67,26 @@ type POSITION_STATIC, POSITION_RELATIVE, POSITION_ABSOLUTE, POSITION_FIXED, POSITION_INHERIT - CSSFontStyle* = enum - FONTSTYLE_NORMAL, FONTSTYLE_ITALIC, FONTSTYLE_OBLIQUE - CSSPropertyType* = enum PROPERTY_NONE, PROPERTY_ALL, PROPERTY_COLOR, PROPERTY_MARGIN, PROPERTY_MARGIN_TOP, PROPERTY_MARGIN_LEFT, PROPERTY_MARGIN_RIGHT, PROPERTY_MARGIN_BOTTOM, PROPERTY_FONT_STYLE, PROPERTY_DISPLAY, - PROPERTY_CONTENT, PROPERTY_WHITE_SPACE, PROPERTY_FONT_WEIGHT + PROPERTY_CONTENT, PROPERTY_WHITE_SPACE, PROPERTY_FONT_WEIGHT, + PROPERTY_TEXT_DECORATION + + CSSFontStyle* = enum + FONTSTYLE_NORMAL, FONTSTYLE_ITALIC, FONTSTYLE_OBLIQUE + + CSSTextDecoration* = enum + TEXT_DECORATION_NONE, TEXT_DECORATION_UNDERLINE, TEXT_DECORATION_OVERLINE, + TEXT_DECORATION_LINE_THROUGH, TEXT_DECORATION_BLINK CSSGlobalValueType* = enum VALUE_NOGLOBAL, VALUE_INITIAL, VALUE_INHERIT, VALUE_REVERT, VALUE_UNSET CSSValueType* = enum VALUE_NONE, VALUE_LENGTH, VALUE_COLOR, VALUE_CONTENT, VALUE_DISPLAY, - VALUE_FONT_STYLE, VALUE_WHITE_SPACE, VALUE_INTEGER + VALUE_FONT_STYLE, VALUE_WHITE_SPACE, VALUE_INTEGER, VALUE_TEXT_DECORATION DrawInstructionType* = enum DRAW_TEXT, DRAW_GOTO, DRAW_FGCOLOR, DRAW_BGCOLOR, DRAW_STYLE, DRAW_RESET |