T = Graphics.ToTable(pl) returns the Graphics object pl as a Lua table: the size of the page and every line, curve, arc, text, bitmap and layer on it, with all their properties. The table can be read and changed, and Graphics.New(T) turns it into a Graphics object again.
Points are given as {x, y}, fractions of the width and the height of the page, and lists of points as { {x1, y1}, {x2, y2}, …}. Widths, radii and the sizes of texts are fractions of $\sqrt{\mathrm{width} \cdot \mathrm{height}}$ of the page, angles are in radians, and colors are 32 bit integers 0xAARRGGBB (see colors).
Graphics.New(T) accepts such a table with any of the fields left out; they then take their default values (black, a width of 0.001, a text size of 0.05, a circle of radius 1). It refuses fields it does not know. A Graphics object can also be saved to a file with io.put and read back with io.get.
A page with a line, a circle and a text as a table. The circle is then made red and twice as large in the table, and the table is turned into a new Graphics object.
-- a page of 100 mm by 60 mm with a line, a circle and a text pl = Graphics.New({{"Canvas.Size.X",100}, {"Canvas.Size.Y",60}}) pl.Add({ {0.1,0.1}, {0.9,0.1} }, {{"Color",0x0000FF}}) pl.Add({"Arc", {0.5,0.5}, 0.2}, {{"Line Width",0.01}}) pl.Add("Quanty", 0.5, 0.45, {{"Alignment","c"}}) T = Graphics.ToTable(pl) -- the page and the elements print("CanvasSize ", T.CanvasSize[1], T.CanvasSize[2]) print("CanvasOrigin", T.CanvasOrigin[1], T.CanvasOrigin[2]) for _, Kind in ipairs({"Line", "Curve", "Arc", "Text", "BitMap", "Layer"}) do print(string.format("%-6s %d", Kind, T[Kind] and #T[Kind] or 0)) end -- the fields of the line, sorted by name Names = {} for Name in pairs(T.Line[1]) do Names[#Names+1] = Name end table.sort(Names) for _, Name in ipairs(Names) do local v = T.Line[1][Name] if Name == "Point" then print(Name, "{ {"..v[1][1]..", "..v[1][2].."}, {"..v[2][1]..", "..v[2][2].."} }") elseif Name == "Color" or Name == "FillColor" then print(Name, string.format("0x%08X", v)) else print(Name, v) end end -- change the table and make a new Graphics object of it: the circle red and twice as large T.Arc[1].Color = 0xFF0000 T.Arc[1].R = 2*T.Arc[1].R pl2 = Graphics.New(T) print("radius", Graphics.ToTable(pl).Arc[1].R, Graphics.ToTable(pl2).Arc[1].R)
CanvasSize 100 60
CanvasOrigin 0 0
Line 1
Curve 0
Arc 1
Text 1
BitMap 0
Layer 0
CloseAndFill false
Color 0x000000FF
FillColor 0x00000000
Point { {0.1, 0.1}, {0.9, 0.1} }
Width 0.001
radius 0.2 0.4
The page has no curves, bitmaps or layers, so these fields are left out of the table. The original pl is not changed by changing the table.