[READ-ONLY] Mirror of https://github.com/thoda-dev/svg-lua. svg lua library
0

Configure Feed

Select the types of activity you want to include in your feed.

v1.5 preparation text and Rect done

Thomas (Mar 11, 2019, 12:08 PM +0100) 463c1ac5 aa0970d0

+52 -32
+1 -1
package.json
··· 1 1 { 2 2 "name": "svg-lua", 3 - "version": "1.0.6", 3 + "version": "1.5.0", 4 4 "description": "lua lib to create svg content", 5 5 "main": "svg-min.lua", 6 6 "repository": {
+42 -22
svg.lua
··· 77 77 -- style: string => style of the text (css with svg params) 78 78 -- tranform: string => transformation options (eg: rotation) 79 79 function svg:Text(text, x, y, anchor, style, transform) 80 - return self.Element:create("text", { 81 - x = x or 10, 82 - y = y or 50, 83 - ["text-anchor"] = anchor or "start", 84 - style = style or ("font-family: Verdana; font-size: 10; stroke: " .. self.stroke .. "; fill: " .. self.fill .. ";"), 85 - transform = transform or "" 86 - }, text) 80 + local options = { 81 + x = x or 0, 82 + y = y or 0 83 + } 84 + if not (anchor == nil) and not (anchor == "") then 85 + options["text-anchor"] = anchor 86 + end 87 + if not (style == nil) and not (style == "") then 88 + options.style = style 89 + end 90 + if not (transform == nil) and not (transform == "") then 91 + options.transform = transform 92 + end 93 + return self.Element:create("text", options, text) 87 94 end 88 - function svg:addText(text, x, y, style, transform) 89 - self:add(self:Text(text, x, y, style, transform)) 95 + function svg:addText(text, x, y, anchor, style, transform) 96 + self:add(self:Text(text, x, y, anchor, style, transform)) 90 97 end 91 98 92 99 -- function to create a rectangle ··· 99 106 -- fill: string => fill color 100 107 -- rx: number => Rayon x des coins du rectangle 101 108 -- ry: number => Rayon y des coins du rectangle 102 - -- tranform: string => transformation options (eg: rotation) 109 + -- transform: string => transformation options (eg: rotation) 103 110 function svg:Rect(x, y, width, height, stroke, strokeWidth, fill, rx, ry, transform) 104 - return self.Element:create("rect", { 105 - x = x or 10, 106 - y = y or 10, 107 - width = width or 10, 108 - height = height or 10, 109 - stroke = stroke or self.stroke, 110 - fill = fill or self.fill, 111 - ["stroke-width"] = strokeWidth or 1, 112 - rx = rx or 0, 113 - ry = ry or 0, 114 - transform = transform or "" 115 - }) 111 + local options = { 112 + x = x or 0, 113 + y = y or 0, 114 + width = width or 20, 115 + height = height or 10 116 + } 117 + if not (stroke == nil) and not (stroke == "") then 118 + options.stroke = stroke 119 + end 120 + if not (fill == nil) and not (fill == "") then 121 + options.fill = fill 122 + end 123 + if not (strokeWidth == nil) and not (strokeWidth == "") then 124 + options["stroke-width"] = strokeWidth 125 + end 126 + if not (rx == nil) and not (rx == "") then 127 + options.rx = rx 128 + end 129 + if not (ry == nil) and not (ry == "") then 130 + options.ry = ry 131 + end 132 + if not (transform == nil) and not (transform == "") then 133 + options.transform = transform 134 + end 135 + return self.Element:create("rect", options) 116 136 end 117 137 function svg:addRect(x, y, width, height, stroke, strokeWidth, fill, rx, ry, transform) 118 138 self:add(self:Rect(x, y, width, height, stroke, strokeWidth, fill, rx, ry, transform))
+9 -9
test.lua
··· 1 1 -- INCLUDE THE CURRENT PATH FOR LUA AND REQUIRE THE LIB -- 2 2 -- DO NOT CHANGE THAT PART -- 3 3 package.path = package.path .. ";" .. "..\\?.lua" 4 - require "svg-min" 4 + require "svg" 5 5 -- END OF LIBRARY IMPORT -- 6 6 7 7 -- TEST IS STARTING HERE -- YOU CAN MODIFY IT -- 8 8 9 9 mon_dessin = svg:create() 10 - mon_dessin:addText("Hello World !!") 11 - mon_dessin:addRect() 12 - mon_dessin:addCircle() 13 - mon_dessin:addEllipse() 14 - mon_dessin:addLine() 15 - mon_dessin:addPolyline() 16 - mon_dessin:addPath() 17 - print(mon_dessin:draw()) 10 + -- mon_dessin:addText("Hello World !!") 11 + -- mon_dessin:addRect() 12 + -- mon_dessin:addCircle() 13 + -- mon_dessin:addEllipse() 14 + -- mon_dessin:addLine() 15 + -- mon_dessin:addPolyline() 16 + -- mon_dessin:addPath() 17 + print(mon_dessin:innerdraw())