context.nim -> contexts.nim, pixieDebugSvg
This commit is contained in:
parent
c93726dd86
commit
7dfea4dc39
6 changed files with 55 additions and 15 deletions
|
@ -1,9 +1,9 @@
|
||||||
import bumpy, chroma, flatty/binny, os, pixie/blends, pixie/common,
|
import bumpy, chroma, flatty/binny, os, pixie/blends, pixie/common,
|
||||||
pixie/context, pixie/fileformats/bmp, pixie/fileformats/gif,
|
pixie/contexts, pixie/fileformats/bmp, pixie/fileformats/gif,
|
||||||
pixie/fileformats/jpg, pixie/fileformats/png, pixie/fileformats/svg,
|
pixie/fileformats/jpg, pixie/fileformats/png, pixie/fileformats/svg,
|
||||||
pixie/fonts, pixie/images, pixie/masks, pixie/paints, pixie/paths, strutils, vmath
|
pixie/fonts, pixie/images, pixie/masks, pixie/paints, pixie/paths, strutils, vmath
|
||||||
|
|
||||||
export blends, bumpy, chroma, common, context, fonts, images, masks, paints,
|
export blends, bumpy, chroma, common, contexts, fonts, images, masks, paints,
|
||||||
paths, vmath
|
paths, vmath
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
|
@ -8,6 +8,7 @@ const
|
||||||
svgSignature* = "<svg"
|
svgSignature* = "<svg"
|
||||||
|
|
||||||
type Ctx = object
|
type Ctx = object
|
||||||
|
display: bool
|
||||||
fillRule: WindingRule
|
fillRule: WindingRule
|
||||||
fill, stroke: ColorRGBX
|
fill, stroke: ColorRGBX
|
||||||
strokeWidth: float32
|
strokeWidth: float32
|
||||||
|
@ -27,6 +28,7 @@ proc attrOrDefault(node: XmlNode, name, default: string): string =
|
||||||
result = default
|
result = default
|
||||||
|
|
||||||
proc initCtx(): Ctx =
|
proc initCtx(): Ctx =
|
||||||
|
result.display = true
|
||||||
result.fill = parseHtmlColor("black").rgbx
|
result.fill = parseHtmlColor("black").rgbx
|
||||||
result.stroke = parseHtmlColor("black").rgbx
|
result.stroke = parseHtmlColor("black").rgbx
|
||||||
result.strokeWidth = 1
|
result.strokeWidth = 1
|
||||||
|
@ -54,6 +56,23 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx =
|
||||||
strokeDashArray = node.attr("stroke-dasharray")
|
strokeDashArray = node.attr("stroke-dasharray")
|
||||||
transform = node.attr("transform")
|
transform = node.attr("transform")
|
||||||
style = node.attr("style")
|
style = node.attr("style")
|
||||||
|
display = node.attr("display")
|
||||||
|
|
||||||
|
when defined(pixieDebugSvg):
|
||||||
|
proc maybeLogPair(k, v: string) =
|
||||||
|
if k notin [ # Handled, never need to log
|
||||||
|
"fill-rule", "fill", "stroke", "stroke-width", "stroke-linecap",
|
||||||
|
"stroke-linejoin", "stroke-miterlimit", "stroke-dasharray",
|
||||||
|
"transform", "style", "version", "viewBox", "width", "height",
|
||||||
|
"xmlns", "x", "y", "x1", "x2", "y1", "y2", "id", "d", "cx", "cy",
|
||||||
|
"r", "points", "rx", "ry", "enable-background", "xml:space",
|
||||||
|
"xmlns:xlink", "data-name", "role", "class"
|
||||||
|
]:
|
||||||
|
echo k, ": ", v
|
||||||
|
|
||||||
|
if node.attrs() != nil:
|
||||||
|
for k, v in node.attrs():
|
||||||
|
maybeLogPair(k, v)
|
||||||
|
|
||||||
let pairs = style.split(';')
|
let pairs = style.split(';')
|
||||||
for pair in pairs:
|
for pair in pairs:
|
||||||
|
@ -61,6 +80,9 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx =
|
||||||
if parts.len == 2:
|
if parts.len == 2:
|
||||||
# Do not override element properties
|
# Do not override element properties
|
||||||
case parts[0].strip():
|
case parts[0].strip():
|
||||||
|
of "fill-rule":
|
||||||
|
if fillRule.len == 0:
|
||||||
|
fillRule = parts[1].strip()
|
||||||
of "fill":
|
of "fill":
|
||||||
if fill.len == 0:
|
if fill.len == 0:
|
||||||
fill = parts[1].strip()
|
fill = parts[1].strip()
|
||||||
|
@ -82,6 +104,18 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx =
|
||||||
of "stroke-dasharray":
|
of "stroke-dasharray":
|
||||||
if strokeDashArray.len == 0:
|
if strokeDashArray.len == 0:
|
||||||
strokeDashArray = parts[1].strip()
|
strokeDashArray = parts[1].strip()
|
||||||
|
of "display":
|
||||||
|
if display.len == 0:
|
||||||
|
display = parts[1].strip()
|
||||||
|
else:
|
||||||
|
when defined(pixieDebugSvg):
|
||||||
|
maybeLogPair(parts[0], parts[1])
|
||||||
|
elif pair.len > 0:
|
||||||
|
when defined(pixieDebugSvg):
|
||||||
|
echo "Invalid style pair: ", pair
|
||||||
|
|
||||||
|
if display.len > 0:
|
||||||
|
result.display = display.strip() != "none"
|
||||||
|
|
||||||
if fillRule == "":
|
if fillRule == "":
|
||||||
discard # Inherit
|
discard # Inherit
|
||||||
|
@ -232,9 +266,11 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx =
|
||||||
failInvalidTransform(transform)
|
failInvalidTransform(transform)
|
||||||
|
|
||||||
proc fill(img: Image, ctx: Ctx, path: Path) {.inline.} =
|
proc fill(img: Image, ctx: Ctx, path: Path) {.inline.} =
|
||||||
|
if ctx.display:
|
||||||
img.fillPath(path, ctx.fill, ctx.transform, ctx.fillRule)
|
img.fillPath(path, ctx.fill, ctx.transform, ctx.fillRule)
|
||||||
|
|
||||||
proc stroke(img: Image, ctx: Ctx, path: Path) {.inline.} =
|
proc stroke(img: Image, ctx: Ctx, path: Path) {.inline.} =
|
||||||
|
if ctx.display:
|
||||||
img.strokePath(
|
img.strokePath(
|
||||||
path,
|
path,
|
||||||
ctx.stroke,
|
ctx.stroke,
|
||||||
|
@ -252,9 +288,13 @@ proc draw(img: Image, node: XmlNode, ctxStack: var seq[Ctx]) =
|
||||||
return
|
return
|
||||||
|
|
||||||
case node.tag:
|
case node.tag:
|
||||||
of "title", "desc", "defs":
|
of "title", "desc":
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
of "defs":
|
||||||
|
when defined(pixieDebugSvg):
|
||||||
|
echo node
|
||||||
|
|
||||||
of "g":
|
of "g":
|
||||||
let ctx = decodeCtx(ctxStack[^1], node)
|
let ctx = decodeCtx(ctxStack[^1], node)
|
||||||
ctxStack.add(ctx)
|
ctxStack.add(ctx)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import
|
import
|
||||||
test_bmp,
|
test_bmp,
|
||||||
test_context,
|
test_contexts,
|
||||||
test_fonts,
|
test_fonts,
|
||||||
test_gif,
|
test_gif,
|
||||||
test_images,
|
test_images,
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Loading…
Reference in a new issue