vec: vector/svg (parse to Vector: paths/arcs, shapes, transforms, groups, use/symbol/nested svg, CSS subset, gradients, opacity groups, clip paths, units; rasterize via codecs/Raster + codecs/Blend; write SVG back). Tests vs resvg (PSNR) incl. resvg rendering our written SVG

This commit is contained in:
4DBug committed 2026-10-31 09:06:01 -05:00
1 parent 84e5d2e4c9
commit 6c54b0c6d5
11 files changed
+2632 -3

No files matched your search

+16 -3
View File
@@ -13,6 +13,12 @@ local function hex(b: buffer): string
return table.concat(t)
end
local function jstr(s: string): string
return '"' .. string.gsub(s, '[%c"\\]', function(c: string): string
return string.format("\\u%04x", string.byte(c))
end) .. '"'
end
local function json(v: any): string
if type(v) == "table" then
if #v > 0 or next(v) == nil then
@@ -24,11 +30,11 @@ local function json(v: any): string
end
local t = {}
for k, x in v do
table.insert(t, string.format("%q", k) .. ":" .. json(x))
table.insert(t, jstr(k) .. ":" .. json(x))
end
return "{" .. table.concat(t, ",") .. "}"
elseif type(v) == "string" then
return string.format("%q", v)
return jstr(v)
elseif type(v) == "boolean" then
return if v then "true" else "false"
end
@@ -137,7 +143,7 @@ local function tiledMap(): Types.TileMap
return m
end
local which = ...
local which, arg = ...
if which == "psd" then
local Psd = require("@formats/layered/psd")
local doc = psdDoc()
@@ -164,4 +170,11 @@ elseif which == "tiled" then
local tmx = Tiled.encode(m, { format = "tmx" }) :: buffer
local tmj = Tiled.encode(m, { format = "tmj" }) :: buffer
print(json({ tmx = hex(tmx), tmj = hex(tmj) }))
elseif which == "svg" then
-- the SVG text given on the command line, decoded and written back by our encoder
local Svg = require("@formats/vector/svg")
local Bytes = require("@formats/core/Bytes")
local v = Svg.decode(Bytes.reader(buffer.fromstring(arg)))
local out = if v then Svg.encode(v) else nil
print(json({ svg = if out then buffer.tostring(out) else "" }))
end