ADG Lua 

ADG Lua Commit Details

Date:2013-03-28 16:16:22 (6 years 6 months ago)
Author:Nicola Fontana
Branch:master
Commit:decbbe7db360d92be4671fb5a8277e87d22ca735
Parents: 93b795acee8ee45a07cf031efc4d8622816d5ab9
Message:piston: allow exporting with custom suffix

Changes:
Mpiston.lua (2 diffs)

File differences

piston.lua
295295
296296
297297
298
299
300
298
299
300
301
301302
302303
303304
304305
305306
306307
307
308
308309
309
310
310311
311
312
312313
313
314
314315
315316
316317
......
319320
320321
321322
323
324
325
326
327
322328
323
324329
325330
326331
generator.view = {}
-- Inject the export method into Adg.Canvas
rawset(Adg.Canvas, 'export', function (canvas, file)
-- The export format is guessed from the file suffix
local suffix = file:match('%..*$')
rawset(Adg.Canvas, 'export', function (canvas, file, format)
-- The not explicitely set, the export format is guessed from the file suffix
if not format then format = file:match('%.(.*)$') end
local size = canvas:get_size()
size.x = size.x + canvas:get_left_margin() + canvas:get_right_margin()
size.y = size.y + canvas:get_top_margin() + canvas:get_bottom_margin()
-- Create the cairo surface
local surface
if suffix == '.png' and cairo.ImageSurface then
if format == 'png' and cairo.ImageSurface then
surface = cairo.ImageSurface.create(cairo.Format.RGB24, size.x, size.y)
elseif suffix == '.svg' and cairo.SvgSurface then
elseif format == 'svg' and cairo.SvgSurface then
surface = cairo.SvgSurface.create(file, size.x, size.y)
elseif suffix == '.pdf' and cairo.PdfSurface then
elseif format == 'pdf' and cairo.PdfSurface then
surface = cairo.PdfSurface.create(file, size.x, size.y)
elseif suffix == '.ps' and cairo.PsSurface then
elseif format == 'ps' and cairo.PsSurface then
-- Pull request: http://github.com/pavouk/lgi/pull/46
surface = cairo.PsSurface.create(file, size.x, size.y)
surface:dsc_comment('%%Title: adg-lua demonstration program')
surface:dsc_begin_setup()
surface:dsc_begin_page_setup()
surface:dsc_comment('%%IncludeFeature: *PageSize A4')
elseif not format then
format = '<nil>'
end
if not surface then
return nil, 'Requested format not supported (' .. format .. ')'
end
if not surface then return nil, 'Requested format not supported' end
-- Render the canvas content
local cr = cairo.Context.create(surface)

Archive Download the corresponding diff file

Branches

Tags