diff --git a/README.md b/README.md
index 78b5406..1794ceb 100644
--- a/README.md
+++ b/README.md
@@ -119,11 +119,12 @@ If you installed luamin, you can use the script `minify.bat` included to minify
- stroke: string => lines color, default to "#000000"
- fill: string => fill color, default to "transparent"
-**svg:addText(text, x, y, style, transform)** *add text*
+**svg:addText(text, x, y, anchor, style, transform)** *add text*
- text: string => the text to write
- x: number => Horizontal position, default to 10
- y: number => Vertical position, default to 50
+ - anchor: string => the text-anchor attribute (start, middle or end)
- style: string => style of the text (css with svg params), default to:
* `font-family: Verdana`
* `font-size: 10`
@@ -201,11 +202,12 @@ If you installed luamin, you can use the script `minify.bat` included to minify
### Elements for svg:add(element) or elements rendering only
-**svg:Text(text, x, y, style, transform)** *add text*
+**svg:Text(text, x, y, anchor, style, transform)** *add text*
- text: string => the text to write
- x: number => Horizontal position, default to 10
- y: number => Vertical position, default to 50
+ - anchor: string => the text-anchor attribute (start, middle or end)
- style: string => style of the text (css with svg params), default to:
* `font-family: Verdana`
* `font-size: 10`
diff --git a/package.json b/package.json
index 08b3573..c58a9aa 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "svg-lua",
- "version": "1.0.4",
+ "version": "1.0.5",
"description": "lua lib to create svg content",
"main": "svg-min.lua",
"repository": {
diff --git a/svg-min.lua b/svg-min.lua
index 373b9fb..608fb89 100644
--- a/svg-min.lua
+++ b/svg-min.lua
@@ -1 +1 @@
-svg={}svg.__index=svg;function svg:create(a,b,c,d)local e={}setmetatable(e,svg)e.width=a or 100;e.height=height or 100;e.stroke=c or"#000000"e.fill=d or"transparent"e.elements={}e.Element={}e.Element.__index=svg.Element;function e.Element:create(f,g,h)local i={}setmetatable(i,e.Element)i.name=f;i.strElement="<"..f.." "for j,k in pairs(g)do i[j]=k;i.strElement=i.strElement..j.."=\""..k.."\" "end;if h~=nil then i.strElement=i.strElement..">"..h..""..f..">"else i.strElement=i.strElement.."/>"end;return i end;return e end;function svg:add(l)table.insert(self.elements,l)end;function svg:draw()local m=""return m end;function svg:innerdraw()local m=""for n,o in pairs(self.elements)do m=m..o.strElement end;return m end;function svg:Text(p,q,s,t,u)return self.Element:create("text",{x=q or 10,y=s or 50,style=t or"font-family: Verdana; font-size: 10; stroke: "..self.stroke.."; fill: "..self.fill..";",transform=u or""},p)end;function svg:addText(p,q,s,t,u)self:add(self:Text(p,q,s,t,u))end;function svg:Rect(q,s,a,height,c,v,d,w,x,u)return self.Element:create("rect",{x=q or 10,y=s or 10,width=a or 10,height=height or 10,stroke=c or self.stroke,fill=d or self.fill,["stroke-width"]=v or 1,rx=w or 0,ry=x or 0,transform=u or""})end;function svg:addRect(q,s,a,height,c,v,d,w,x,u)self:add(self:Rect(q,s,a,height,c,v,d,w,x,u))end;function svg:Circle(r,cx,cy,c,v,d,u)return self.Element:create("circle",{r=r or 25,cx=cx or 30,cy=cy or 30,stroke=c or self.stroke,["stroke-width"]=v or 1,fill=d or self.fill,transform=u or""})end;function svg:addCircle(r,cx,cy,c,v,d,u)self:add(self:Circle(r,cx,cy,c,v,d,u))end;function svg:Ellipse(cx,cy,w,x,c,v,d,u)return self.Element:create("ellipse",{rx=r or 25,ry=r or 15,cx=cx or 30,cy=cy or 30,stroke=c or self.stroke,["stroke-width"]=v or 1,fill=d or self.fill,transform=u or""})end;function svg:addEllipse(cx,cy,w,x,c,v,d,u)self:add(self:Ellipse(cx,cy,w,x,c,v,d,u))end;function svg:Line(y,z,A,B,c,v,d)return self.Element:create("line",{x1=r or 15,y1=r or 15,x2=cx or 50,y2=cy or 45,stroke=c or self.stroke,["stroke-width"]=v or 1,fill=d or self.fill})end;function svg:addLine(y,z,A,B,c,v,d)self:add(self:Line(y,z,A,B,c,v,d))end;function svg:Polyline(C,c,v,d,u)return self.Element:create("polyline",{points=C or"10,10 50,50 50,25 75,25",stroke=c or self.stroke,["stroke-width"]=v or 1,fill=d or self.fill,transform=u or""})end;function svg:addPolyline(C,c,v,d,u)self:add(self:Polyline(C,c,v,d,u))end;function svg:Path(D,c,v,d,u)return self.Element:create("path",{d=D or"M50 0 L75 100 L25 100 Z",stroke=c or self.stroke,["stroke-width"]=v or 1,fill=d or self.fill,transform=u or""})end;function svg:addPath(D,c,v,d,u)self:add(self:Path(D,c,v,d,u))end
+svg={}svg.__index=svg;function svg:create(a,b,c,d)local e={}setmetatable(e,svg)e.width=a or 100;e.height=b or 100;e.stroke=c or"#000000"e.fill=d or"transparent"e.elements={}e.Element={}e.Element.__index=svg.Element;function e.Element:create(f,g,h)local i={}setmetatable(i,e.Element)i.name=f;i.strElement="<"..f.." "for j,k in pairs(g)do i[j]=k;i.strElement=i.strElement..j.."=\""..k.."\" "end;if h~=nil then i.strElement=i.strElement..">"..h..""..f..">"else i.strElement=i.strElement.."/>"end;return i end;return e end;function svg:add(l)table.insert(self.elements,l)end;function svg:draw()local m=""return m end;function svg:innerdraw()local m=""for n,o in pairs(self.elements)do m=m..o.strElement end;return m end;function svg:Text(p,q,s,t,u,v)return self.Element:create("text",{x=q or 10,y=s or 50,["text-anchor"]=t or"start",style=u or"font-family: Verdana; font-size: 10; stroke: "..self.stroke.."; fill: "..self.fill..";",transform=v or""},p)end;function svg:addText(p,q,s,u,v)self:add(self:Text(p,q,s,u,v))end;function svg:Rect(q,s,a,b,c,w,d,x,y,v)return self.Element:create("rect",{x=q or 10,y=s or 10,width=a or 10,height=b or 10,stroke=c or self.stroke,fill=d or self.fill,["stroke-width"]=w or 1,rx=x or 0,ry=y or 0,transform=v or""})end;function svg:addRect(q,s,a,b,c,w,d,x,y,v)self:add(self:Rect(q,s,a,b,c,w,d,x,y,v))end;function svg:Circle(r,cx,cy,c,w,d,v)return self.Element:create("circle",{r=r or 25,cx=cx or 30,cy=cy or 30,stroke=c or self.stroke,["stroke-width"]=w or 1,fill=d or self.fill,transform=v or""})end;function svg:addCircle(r,cx,cy,c,w,d,v)self:add(self:Circle(r,cx,cy,c,w,d,v))end;function svg:Ellipse(cx,cy,x,y,c,w,d,v)return self.Element:create("ellipse",{rx=r or 25,ry=r or 15,cx=cx or 30,cy=cy or 30,stroke=c or self.stroke,["stroke-width"]=w or 1,fill=d or self.fill,transform=v or""})end;function svg:addEllipse(cx,cy,x,y,c,w,d,v)self:add(self:Ellipse(cx,cy,x,y,c,w,d,v))end;function svg:Line(z,A,B,C,c,w,d)return self.Element:create("line",{x1=r or 15,y1=r or 15,x2=cx or 50,y2=cy or 45,stroke=c or self.stroke,["stroke-width"]=w or 1,fill=d or self.fill})end;function svg:addLine(z,A,B,C,c,w,d)self:add(self:Line(z,A,B,C,c,w,d))end;function svg:Polyline(D,c,w,d,v)return self.Element:create("polyline",{points=D or"10,10 50,50 50,25 75,25",stroke=c or self.stroke,["stroke-width"]=w or 1,fill=d or self.fill,transform=v or""})end;function svg:addPolyline(D,c,w,d,v)self:add(self:Polyline(D,c,w,d,v))end;function svg:Path(E,c,w,d,v)return self.Element:create("path",{d=E or"M50 0 L75 100 L25 100 Z",stroke=c or self.stroke,["stroke-width"]=w or 1,fill=d or self.fill,transform=v or""})end;function svg:addPath(E,c,w,d,v)self:add(self:Path(E,c,w,d,v))end
diff --git a/svg.lua b/svg.lua
index 5957b1d..566e769 100644
--- a/svg.lua
+++ b/svg.lua
@@ -7,7 +7,7 @@ svg.__index = svg;
-- height: number => height of the drawing
-- stroke: string => lines color
-- fill: string => fill color
-function svg:create(width, heigth, stroke, fill)
+function svg:create(width, height, stroke, fill)
local s = {}
setmetatable(s,svg)
s.width = width or 100
@@ -73,12 +73,14 @@ end
-- text: string => the text to write
-- x: number => Horizontal position
-- y: number => Vertical position
+-- anchor: string => the text-anchor attribute (start, middle or end)
-- style: string => style of the text (css with svg params)
-- tranform: string => transformation options (eg: rotation)
-function svg:Text(text, x, y, style, transform)
+function svg:Text(text, x, y, anchor, style, transform)
return self.Element:create("text", {
x = x or 10,
y = y or 50,
+ ["text-anchor"] = anchor or "start",
style = style or ("font-family: Verdana; font-size: 10; stroke: " .. self.stroke .. "; fill: " .. self.fill .. ";"),
transform = transform or ""
}, text)