diff options
author | bptato <nincsnevem662@gmail.com> | 2023-06-02 00:36:54 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-06-05 03:58:21 +0200 |
commit | 8027e52cb221c432bed64517015ebf3182e6166d (patch) | |
tree | 18991f9e74c8dcfc0ed7439f3bc78a0cfec9b2d6 /src/css | |
parent | b3b97465805b7367df461a4b7b830fabaccf3a89 (diff) | |
download | chawan-8027e52cb221c432bed64517015ebf3182e6166d.tar.gz |
Add support for canvas and multipart
Quite incomplete canvas implementation. Crucially, the layout engine can't do much with whatever is drawn because it doesn't support images yet. I've re-introduced multipart as well, with the FormData API. For the append function I've also introduced a hack to the JS binding generator that allows requesting the JSContext pointer in nim procs. Really I should just fix the union generator thing and add support for overloading. In conclusion, for now the only thing canvas can be used for is exporting it as PNG and uploading it somewhere. Also, we now have PNG encoding and decoding too. (Now if only we had sixels as well...)
Diffstat (limited to 'src/css')
-rw-r--r-- | src/css/cascade.nim | 12 | ||||
-rw-r--r-- | src/css/cssparser.nim | 8 | ||||
-rw-r--r-- | src/css/values.nim | 25 |
3 files changed, 20 insertions, 25 deletions
diff --git a/src/css/cascade.nim b/src/css/cascade.nim index 0cea87b7..7aac213f 100644 --- a/src/css/cascade.nim +++ b/src/css/cascade.nim @@ -127,17 +127,17 @@ func calcPresentationalHints(element: Element): CSSComputedValues = if c.isSome: set_cv "color", c.get template map_colspan = - let colspan = element.attrigz("colspan") + let colspan = element.attrulgz("colspan") if colspan.isSome: let i = colspan.get if i <= 1000: - set_cv "-cha-colspan", i + set_cv "-cha-colspan", int(i) template map_rowspan = - let rowspan = element.attrigez("rowspan") + let rowspan = element.attrul("rowspan") if rowspan.isSome: let i = rowspan.get if i <= 65534: - set_cv "-cha-rowspan", i + set_cv "-cha-rowspan", int(i) case element.tagType of TAG_DIV: @@ -170,8 +170,8 @@ func calcPresentationalHints(element: Element): CSSComputedValues = map_text of TAG_TEXTAREA: let textarea = HTMLTextAreaElement(element) - let cols = textarea.attri("cols").get(20) - let rows = textarea.attri("rows").get(1) + let cols = textarea.attrul("cols").get(20) + let rows = textarea.attrul("rows").get(1) set_cv "width", CSSLength(unit: UNIT_CH, num: float64(cols)) set_cv "height", CSSLength(unit: UNIT_EM, num: float64(rows)) of TAG_FONT: diff --git a/src/css/cssparser.nim b/src/css/cssparser.nim index 9c8328de..57cfc87e 100644 --- a/src/css/cssparser.nim +++ b/src/css/cssparser.nim @@ -867,10 +867,10 @@ proc parseAnB*(state: var CSSParseState): Option[CSSAnB] = return none(CSSAnB) template parse_sub_int(sub: string, skip: int): int = let s = sub.substr(skip) - for c in s: - if c notin AsciiDigit: - return none(CSSAnB) - parseInt32(s) + let x = parseInt32(s) + if x.isNone: + return none(CSSAnB) + x.get template fail_non_integer(tok: CSSToken, res: Option[CSSAnB]) = if tok.tokenType != CSS_NUMBER_TOKEN: state.reconsume() diff --git a/src/css/values.nim b/src/css/values.nim index c786e47e..dd3f2df4 100644 --- a/src/css/values.nim +++ b/src/css/values.nim @@ -493,7 +493,7 @@ func skipWhitespace(vals: seq[CSSComponentValue], i: var int) = break inc i -func cssColor(val: CSSComponentValue): RGBAColor = +func cssColor*(val: CSSComponentValue): RGBAColor = if val of CSSToken: let tok = CSSToken(val) case tok.tokenType @@ -525,23 +525,15 @@ func cssColor(val: CSSComponentValue): RGBAColor = commaMode = true elif commaMode: raise newException(CSSValueError, "Invalid color") - if slash: + elif slash: if f.value[i] != CSS_DELIM_TOKEN or CSSToken(f.value[i]).rvalue != Rune('/'): raise newException(CSSValueError, "Invalid color") inc i f.value.skipWhitespace(i) - check_err + if not slash: + check_err case f.name - of "rgb": - f.value.skipWhitespace(i) - check_err - let r = CSSToken(f.value[i]).nvalue - next_value true - let g = CSSToken(f.value[i]).nvalue - next_value - let b = CSSToken(f.value[i]).nvalue - return rgba(int(r), int(g), int(b), 255) - of "rgba": + of "rgb", "rgba": f.value.skipWhitespace(i) check_err let r = CSSToken(f.value[i]).nvalue @@ -550,8 +542,11 @@ func cssColor(val: CSSComponentValue): RGBAColor = next_value let b = CSSToken(f.value[i]).nvalue next_value false, true - let a = CSSToken(f.value[i]).nvalue - return rgba(int(r), int(g), int(b), int(a)) + let a = if i < f.value.len: + CSSToken(f.value[i]).nvalue + else: + 1 + return rgba(int(r), int(g), int(b), int(a * 255)) else: discard raise newException(CSSValueError, "Invalid color") |