···7777-- style: string => style of the text (css with svg params)
7878-- tranform: string => transformation options (eg: rotation)
7979function svg:Text(text, x, y, anchor, style, transform)
8080- return self.Element:create("text", {
8181- x = x or 10,
8282- y = y or 50,
8383- ["text-anchor"] = anchor or "start",
8484- style = style or ("font-family: Verdana; font-size: 10; stroke: " .. self.stroke .. "; fill: " .. self.fill .. ";"),
8585- transform = transform or ""
8686- }, text)
8080+ local options = {
8181+ x = x or 0,
8282+ y = y or 0
8383+ }
8484+ if not (anchor == nil) and not (anchor == "") then
8585+ options["text-anchor"] = anchor
8686+ end
8787+ if not (style == nil) and not (style == "") then
8888+ options.style = style
8989+ end
9090+ if not (transform == nil) and not (transform == "") then
9191+ options.transform = transform
9292+ end
9393+ return self.Element:create("text", options, text)
8794end
8888-function svg:addText(text, x, y, style, transform)
8989- self:add(self:Text(text, x, y, style, transform))
9595+function svg:addText(text, x, y, anchor, style, transform)
9696+ self:add(self:Text(text, x, y, anchor, style, transform))
9097end
91989299-- function to create a rectangle
···99106-- fill: string => fill color
100107-- rx: number => Rayon x des coins du rectangle
101108-- ry: number => Rayon y des coins du rectangle
102102--- tranform: string => transformation options (eg: rotation)
109109+-- transform: string => transformation options (eg: rotation)
103110function svg:Rect(x, y, width, height, stroke, strokeWidth, fill, rx, ry, transform)
104104- return self.Element:create("rect", {
105105- x = x or 10,
106106- y = y or 10,
107107- width = width or 10,
108108- height = height or 10,
109109- stroke = stroke or self.stroke,
110110- fill = fill or self.fill,
111111- ["stroke-width"] = strokeWidth or 1,
112112- rx = rx or 0,
113113- ry = ry or 0,
114114- transform = transform or ""
115115- })
111111+ local options = {
112112+ x = x or 0,
113113+ y = y or 0,
114114+ width = width or 20,
115115+ height = height or 10
116116+ }
117117+ if not (stroke == nil) and not (stroke == "") then
118118+ options.stroke = stroke
119119+ end
120120+ if not (fill == nil) and not (fill == "") then
121121+ options.fill = fill
122122+ end
123123+ if not (strokeWidth == nil) and not (strokeWidth == "") then
124124+ options["stroke-width"] = strokeWidth
125125+ end
126126+ if not (rx == nil) and not (rx == "") then
127127+ options.rx = rx
128128+ end
129129+ if not (ry == nil) and not (ry == "") then
130130+ options.ry = ry
131131+ end
132132+ if not (transform == nil) and not (transform == "") then
133133+ options.transform = transform
134134+ end
135135+ return self.Element:create("rect", options)
116136end
117137function svg:addRect(x, y, width, height, stroke, strokeWidth, fill, rx, ry, transform)
118138 self:add(self:Rect(x, y, width, height, stroke, strokeWidth, fill, rx, ry, transform))
+9-9
test.lua
···11-- INCLUDE THE CURRENT PATH FOR LUA AND REQUIRE THE LIB --
22-- DO NOT CHANGE THAT PART --
33package.path = package.path .. ";" .. "..\\?.lua"
44-require "svg-min"
44+require "svg"
55-- END OF LIBRARY IMPORT --
6677-- TEST IS STARTING HERE -- YOU CAN MODIFY IT --
8899mon_dessin = svg:create()
1010-mon_dessin:addText("Hello World !!")
1111-mon_dessin:addRect()
1212-mon_dessin:addCircle()
1313-mon_dessin:addEllipse()
1414-mon_dessin:addLine()
1515-mon_dessin:addPolyline()
1616-mon_dessin:addPath()
1717-print(mon_dessin:draw())1010+-- mon_dessin:addText("Hello World !!")
1111+-- mon_dessin:addRect()
1212+-- mon_dessin:addCircle()
1313+-- mon_dessin:addEllipse()
1414+-- mon_dessin:addLine()
1515+-- mon_dessin:addPolyline()
1616+-- mon_dessin:addPath()
1717+print(mon_dessin:innerdraw())