summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-08-18 15:48:54 -0500
committersanine <sanine.not@pm.me>2023-08-18 15:48:54 -0500
commitc8f36f3df88c1a4064a9c73c95a165eb13beeb20 (patch)
treee18d7cfd9cac65f2f5b34fb710f8532a4c441805
parent83448304527d8a1dde233f2f33b98124bced5f88 (diff)
add demomain
-rwxr-xr-xdemo.lua18
-rw-r--r--marigold.lua9
-rw-r--r--output.svg5
3 files changed, 31 insertions, 1 deletions
diff --git a/demo.lua b/demo.lua
new file mode 100755
index 0000000..9c8dd34
--- /dev/null
+++ b/demo.lua
@@ -0,0 +1,18 @@
+#!/usr/bin/env lua5.1
+
+local svg = require 'marigold'
+
+
+local img = svg.svg{
+ style = 'fill=#bbbbbbff',
+ width = '100mm',
+ height = '100mm',
+
+ svg.rect{ x=0, y=0, width='100mm', height='100mm', style='fill: #ff0000ff' },
+ svg.text('hello c:', { x=10, y=10, style='font-family: Verdana' }),
+}
+
+
+local f = io.open('output.svg', 'w')
+f:write(svg.render(img))
+f:close()
diff --git a/marigold.lua b/marigold.lua
index 9daa808..a5b1c75 100644
--- a/marigold.lua
+++ b/marigold.lua
@@ -104,6 +104,7 @@ local function render_internal(tbl, indent_level)
children,
indent, close)
end
+marigold.prerender = render_internal
marigold.render = function(tbl)
local str = render_internal(tbl, 0)
@@ -171,7 +172,13 @@ marigold.rect = function(tbl)
end
-marigold.text = function(tbl)
+marigold.text = function(content, tbl)
+ local tag, err = maketag(
+ 'text', content, tbl,
+ { 'lengthAdjust', 'x', 'y', 'dx', 'dy', 'rotate', 'textLength' }
+ )
+ if err then error(err) end
+ return tag
end
diff --git a/output.svg b/output.svg
new file mode 100644
index 0000000..84c6fb0
--- /dev/null
+++ b/output.svg
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg height="100mm" width="100mm" style="fill=#bbbbbbff" xmlns="http://www.w3.org/2000/svg">
+ <rect y="0" x="0" style="fill: #ff0000ff" height="100mm" width="100mm"></rect>
+ <text y="10" x="10" style="font-family: Verdana">hello c:</text>
+</svg> \ No newline at end of file