diff options
author | rumpf_a@web.de <> | 2010-02-14 09:59:01 +0100 |
---|---|---|
committer | rumpf_a@web.de <> | 2010-02-14 09:59:01 +0100 |
commit | 01fb99bc804ecc38bc2b7e36aefeba338d5604e4 (patch) | |
tree | 0d5b29c935017263e1fae78a3c87cc784ed25ac5 | |
parent | 597d98e7ee9cf60ec1ed601a311975384d65cba8 (diff) | |
download | Nim-01fb99bc804ecc38bc2b7e36aefeba338d5604e4.tar.gz |
further improvements for the HTML parser
-rw-r--r-- | lib/devel/graphics.nim | 67 | ||||
-rw-r--r-- | lib/pure/htmlparser.nim | 8 |
2 files changed, 73 insertions, 2 deletions
diff --git a/lib/devel/graphics.nim b/lib/devel/graphics.nim new file mode 100644 index 000000000..6e4d83187 --- /dev/null +++ b/lib/devel/graphics.nim @@ -0,0 +1,67 @@ +# +# +# Nimrod's Runtime Library +# (c) Copyright 2010 Andreas Rumpf +# +# See the file "copying.txt", included in this +# distribution, for details about the copyright. +# + +## This module implements graphical output for Nimrod; the current +## implementation uses Cairo under the surface. + +type + PSurface* = ref TSurface + TSurface {.pure, final.} = object + ... # internal data + + + TRect* = tuple[x, y, width, height: int] + TPoint* = tuple[x, y: int] + + TColor* = distinct int ## a color stored as RGB + +proc `==` (a, b: TColor): bool {.borrow.} +# XXX maybe other operations for colors? What about saturated artithmetic? + + +const + colRed* = TColor(0x00ff0000) # RGB + colGreen* = ... + colBlue* = ... + colOrange* = ... + +proc newSurface*(width, height: int): PSurface + +proc color*(name: string): TColor +proc isColor*(name: string): bool + +proc rgb*(r, g, b: range[0..255]): TColor + + +proc drawRect*(sur: PSurface, r: TRect, col: TColor) +proc fillRect*(sur: PSurface, r: TRect, col: TColor) + +proc drawCircle*(sur: PSurface, mid: TPoint, radius: int) +proc drawCircle*(sur: PSurface, r: TRect) + +proc fillCircle*(sur: PSurface, mid: TPoint, radius: int) +proc fillCircle*(sur: PSurface, r: TRect) + +proc drawElipse*(sur: PSurface, r: TRect) +proc fillElipse*(sur: PSurface, r: TRect) + + +proc textBounds*(text: string): tuple[len, height: int] +proc drawText*(sur: PSurface, p: TPoint, text: string) + +proc drawLine*(sur: PSurface, a, b: TPoint) + +proc `[]`*(sur: PSurface, p: TPoint): TColor +proc `[,]`*(sur: PSurface, x, y: int): TColor +proc `[]=`*(sur: PSurface, p: TPoint, col: TColor) +proc `[,]=`*(sur: PSurface, x, y: int, col: TColor) + +proc writeToPNG*(sur: PSurface, filename: string) + + diff --git a/lib/pure/htmlparser.nim b/lib/pure/htmlparser.nim index 4e4af0e4b..81a3a8cb4 100644 --- a/lib/pure/htmlparser.nim +++ b/lib/pure/htmlparser.nim @@ -152,7 +152,7 @@ const tagOl, tagP, tagPre, tagTable, tagUl, tagCenter, tagDir, tagIsindex, tagMenu, tagNoframes} SingleTags* = {tagArea, tagBase, tagBasefont, - tagBr, tagCol, tagFrame, tagHr, tagImg, tagInput, tagIsindex, + tagBr, tagCol, tagFrame, tagHr, tagImg, tagIsindex, tagLink, tagMeta, tagParam} Entities = [ @@ -276,7 +276,7 @@ proc untilElementEnd(x: var TXmlParser, result: PXmlNode, case x.kind of xmlElementStart, xmlElementOpen: case result.htmlTag - of tagLi, tagP, tagDt, tagDd, tagOption: + of tagLi, tagP, tagDt, tagDd, tagInput, tagOption: if htmlTag(x.elementName) notin InlineTags: # some tags are common to have no ``</end>``, like ``<li>``: errors.add(expected(x, result)) @@ -285,6 +285,10 @@ proc untilElementEnd(x: var TXmlParser, result: PXmlNode, if htmlTag(x.elementName) in {tagTr, tagTd, tagTh}: errors.add(expected(x, result)) break + of tagOptgroup: + if htmlTag(x.elementName) in {tagOption, tagOptgroup}: + errors.add(expected(x, result)) + break else: nil result.addNode(parse(x, errors)) of xmlElementEnd: |