add two extra fields for graphical text items
[mplib] / src / texk / web2c / mpdir / tests / test.lua
1
2 -- There are two interfaces:
3 -- new * run
4 -- or
5 -- new * execute^1 * finish
6
7 if false then 
8   mpx = mp.new({ini_version = true, command_line = "plain \\dump"})
9   print (mpx:run());
10   mpx = nil;
11 end
12
13 dofile("/opt/tex/texmf-local/tex/context/base/l-table.lua");
14
15 function dorun (m, s) 
16   local v = m:execute(s)
17 --  print ('<<term:'..v.term..'>>')
18   print ('<<log:'..v.log..'>>')
19   if v.fig then
20      for _,gs in ipairs(v.fig) do
21            local b = gs:objects()
22        for _,vv in ipairs(b) do
23                   print(vv, vv.type, table.serialize(vv.path), table.serialize(vv.color))
24           if vv.type == "text" then
25                     print(vv.text, vv.font, vv.dsize, table.serialize(vv.transform))
26           end
27        end
28 --       print(gs:postscript())
29      end
30   end
31 end
32
33 -- chunks have to have 'complete file' nesting state
34 local lines = {
35  "prologues:=3;",
36  "path p,q;",
37  "p = (0,0){right}..(20,100)..(50,60)..(75,50)...(25,25)..cycle;",
38  "q = (0,0){right}..(20,100)..(50,60)..(75,50)...(25,25);",
39  "pickup pencircle scaled 2;",
40  "beginfig(1); fill p withcolor (1,0,0); draw p dashed evenly; endfig;",
41  [[beginfig(2); fill p withcolor (1,0,1); endfig; 
42    beginfig(3); draw q withcolor (0,1,1); endfig;]],
43  "beginfig(4); label(\"stuff\", (0,0)); endfig;",
44 }
45
46 function finder (a,b,c)
47    print(a,b,c)
48    if a == "mpost.map" then
49      return "/opt/tex/texmf-local/fonts/map/pdftex/pdftex.map"
50    end
51    if a =="cmr10.tfm" then
52      return "/opt/tex/texmf/fonts/tfm/public/cm/cmr10.tfm"
53    end
54    return a
55 end
56
57 mpx = mp.new({mem_name = "plain.mem", 
58               command_line = "\\relax ", 
59               find_file = finder})
60
61 for _,l in ipairs(lines) do
62    dorun (mpx, l)
63 end
64
65 v = mpx:finish();
66