3 This file is part of adg-lua.
4 Copyright (C) 2012-2013 Nicola Fontana <ntd at entidi.it>
6 adg-lua is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License, or (at your option) any later version.
11 adg-lua is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General
17 Public License along with adg-lua; if not, write to the Free
18 Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
24 -- Convenient function to load scripts from the same directory
25 -- of this very same file
26 local function local_require(filename
)
28 local basedir
= FILE
and FILE
:match('^(.*/).*$') or './'
29 local filename
= basedir
.. filename
.. '.lua'
30 return assert(loadfile(filename
)())
34 local lgi
= require
'lgi'
35 local cairo
= lgi
.require
'cairo'
36 local Adg
= lgi
.require
'Adg'
37 local Piston
= local_require
'piston'
41 -- Command line parsing
42 -----------------------------------------------------------------
46 for n
, s
in ipairs(arg
) do
47 -- Arguments are expected in k=v tuples
48 local k
, v
= s
:match('(.-)=(.*)')
49 if not k
then error('Invalid argument ' .. n
) end
53 -- Provide fallback values
81 TITLE
= 'SAMPLE DRAWING',
84 DATE
= os
.date('%d/%m/%Y'),
86 if not request
[k
] then request
[k
] = v
end
91 -----------------------------------------------------------------
93 local piston
= Piston
.new(request
)
97 -----------------------------------------------------------------
100 local canvas
= piston
.view
.detailed
101 canvas
:set_margins(10, 10, 10, 10)
102 canvas
:set_paddings(0, 0, 0, 0)
103 canvas
:set_size_explicit(800, 600)
105 -- Adjust the zoom factor based on the (optional) requested size
107 if request
.width
then
108 local x_zoom
= request
.width
/ 800
109 if x_zoom
< zoom
then zoom
= x_zoom
end
111 if request
.height
then
112 local y_zoom
= request
.height
/ 600
113 if y_zoom
< zoom
then zoom
= y_zoom
end
115 canvas
:set_global_map(cairo
.Matrix
{ xx
= zoom
, yy
= zoom
})
122 -----------------------------------------------------------------
124 local _
, err
= canvas
:export('/dev/stdout', 'png')
125 if err
then error(err
) end