{{indexmenu_n>999}} ====== ToTable ====== ### //T = Graphics.ToTable(pl)// returns the [[documentation:language_reference:objects:graphics:start|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 //[[documentation:language_reference:objects:graphics:functions:new|Graphics.New(T)]]// turns it into a Graphics object again. ### ===== Input ===== * //pl// : a Graphics object. ===== Output ===== * //T// : a table with the fields below. A list that would be empty is left out, so //T.Curve// is nil when //pl// has no curves. ### 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 [[documentation:language_reference:objects:graphics:start#colors|colors]]). ### * //CanvasSize// : //{width, height}// of the page in mm. * //CanvasOrigin// : //{x, y}// of the lower left corner of the page in mm. * //Line// : a list of lines, each a table with * //Point// : the list of points. * //Color//, //Width// : the color and the width of the line. * //CloseAndFill//, //FillColor// : Boolean, the line is closed and filled with //FillColor//. * //Curve// : a list of curves, each a table with * //Point// : the list of points. * //VL//, //VR// : the lists of control points before and after each point, see //[[documentation:language_reference:objects:graphics:functions:add|Graphics.Add()]]//. * //Color//, //Width//, //CloseAndFill//, //FillColor// : as for a line. * //Arc// : a list of arcs, each a table with * //Point//, //R// : the centre and the radius. * //ThetaR//, //ThetaL// : the angles where the arc starts and ends, counterclockwise. A full circle runs from 0 to $2\pi$. * //Color//, //Width//, //CloseAndFill//, //FillColor// : as for a line; a closed arc is closed through its centre. * //Text// : a list of texts, each a table with * //String// : the text. * //Point//, //Alignment// : the point of the text, and whether it is the left end (//"l"//), the middle (//"c"//) or the right end (//"r"//) of the text. * //Size//, //Angle//, //Color//, //Font// : the height, the angle, the color and the PostScript name of the font. * //BitMap// : a list of bitmaps, each a table with * //LB//, //RT// : the lower left and the upper right corner of the rectangle. * //NpointsX//, //NpointsY// : the number of pixels in a row and the number of rows. * //Pixels// : a string of hexadecimal digits, eight per pixel (its color 0xAARRGGBB), the rows one after the other from the top, closed by //">"//. Spaces and line breaks in it are ignored. * //Pixelated// : true when the bitmap is drawn with sharp pixels; left out otherwise. * //Angle// : the angle by which the rectangle is turned about its middle, see //[[documentation:language_reference:objects:graphics:functions:rotate|Graphics.Rotate()]]//; left out when it is 0. * //Layer// : a list of the layers, each a table of this same form. ### //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 //[[documentation:language_reference:functions:io.put|io.put]]// and read back with //[[documentation:language_reference:functions:io.get|io.get]]//. ### ===== Example ===== ### 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. ### ==== Input ==== -- 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) ==== Result ==== 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. ### ===== Table of contents ===== {{indexmenu>../#2|tsort}}