diff --git a/pixie.nimble b/pixie.nimble index 1002a9a..57c4d10 100644 --- a/pixie.nimble +++ b/pixie.nimble @@ -8,7 +8,7 @@ srcDir = "src" requires "nim >= 1.2.6" requires "vmath >= 1.0.8" requires "chroma >= 0.2.5" -requires "zippy >= 0.3.5" +requires "zippy >= 0.5.12" requires "flatty >= 0.1.3" requires "nimsimd >= 1.0.0" requires "bumpy >= 1.0.3" diff --git a/src/pixie.nim b/src/pixie.nim index 822f11a..b0d21e0 100644 --- a/src/pixie.nim +++ b/src/pixie.nim @@ -1,9 +1,9 @@ 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/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 type diff --git a/src/pixie/context.nim b/src/pixie/contexts.nim similarity index 100% rename from src/pixie/context.nim rename to src/pixie/contexts.nim diff --git a/src/pixie/fileformats/gif.nim b/src/pixie/fileformats/gif.nim index 69ab40a..18cd1ad 100644 --- a/src/pixie/fileformats/gif.nim +++ b/src/pixie/fileformats/gif.nim @@ -113,7 +113,7 @@ proc decodeGif*(data: string): Image = if bs.pos + bitSize.int > bs.data.len * 8: failInvalid() var # Read variable bits out of the table. - codeId = bs.readBits(bitSize.int).int + codeId = bs.readBits(bitSize).int # Some time we need to carry over table information. carryOver: seq[int] diff --git a/src/pixie/fileformats/svg.nim b/src/pixie/fileformats/svg.nim index 0592938..3295158 100644 --- a/src/pixie/fileformats/svg.nim +++ b/src/pixie/fileformats/svg.nim @@ -8,6 +8,7 @@ const svgSignature* = "<svg" type Ctx = object + display: bool fillRule: WindingRule fill, stroke: ColorRGBX strokeWidth: float32 @@ -27,6 +28,7 @@ proc attrOrDefault(node: XmlNode, name, default: string): string = result = default proc initCtx(): Ctx = + result.display = true result.fill = parseHtmlColor("black").rgbx result.stroke = parseHtmlColor("black").rgbx result.strokeWidth = 1 @@ -54,6 +56,23 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx = strokeDashArray = node.attr("stroke-dasharray") transform = node.attr("transform") 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(';') for pair in pairs: @@ -61,6 +80,9 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx = if parts.len == 2: # Do not override element properties case parts[0].strip(): + of "fill-rule": + if fillRule.len == 0: + fillRule = parts[1].strip() of "fill": if fill.len == 0: fill = parts[1].strip() @@ -82,6 +104,18 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx = of "stroke-dasharray": if strokeDashArray.len == 0: 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 == "": discard # Inherit @@ -232,19 +266,21 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx = failInvalidTransform(transform) proc fill(img: Image, ctx: Ctx, path: Path) {.inline.} = - img.fillPath(path, ctx.fill, ctx.transform, ctx.fillRule) + if ctx.display: + img.fillPath(path, ctx.fill, ctx.transform, ctx.fillRule) proc stroke(img: Image, ctx: Ctx, path: Path) {.inline.} = - img.strokePath( - path, - ctx.stroke, - ctx.transform, - ctx.strokeWidth, - ctx.strokeLineCap, - ctx.strokeLineJoin, - miterLimit = ctx.strokeMiterLimit, - dashes = ctx.strokeDashArray - ) + if ctx.display: + img.strokePath( + path, + ctx.stroke, + ctx.transform, + ctx.strokeWidth, + ctx.strokeLineCap, + ctx.strokeLineJoin, + miterLimit = ctx.strokeMiterLimit, + dashes = ctx.strokeDashArray + ) proc draw(img: Image, node: XmlNode, ctxStack: var seq[Ctx]) = if node.kind != xnElement: @@ -252,9 +288,13 @@ proc draw(img: Image, node: XmlNode, ctxStack: var seq[Ctx]) = return case node.tag: - of "title", "desc", "defs": + of "title", "desc": discard + of "defs": + when defined(pixieDebugSvg): + echo node + of "g": let ctx = decodeCtx(ctxStack[^1], node) ctxStack.add(ctx) diff --git a/tests/all.nim b/tests/all.nim index 3b810b4..e0c13a0 100644 --- a/tests/all.nim +++ b/tests/all.nim @@ -1,6 +1,6 @@ import test_bmp, - test_context, + test_contexts, test_fonts, test_gif, test_images, diff --git a/tests/images/svg/emojitwo.png b/tests/images/svg/emojitwo.png index a5e0faa..e023fcd 100644 Binary files a/tests/images/svg/emojitwo.png and b/tests/images/svg/emojitwo.png differ diff --git a/tests/test_context.nim b/tests/test_contexts.nim similarity index 100% rename from tests/test_context.nim rename to tests/test_contexts.nim