2016-07-09 19:03:49 +02:00
|
|
|
local file_path, image_path = ...
|
|
|
|
require("_common_template")(...)
|
2016-03-19 09:58:02 +01:00
|
|
|
|
|
|
|
local wibox = require( "wibox" )
|
|
|
|
local surface = require( "gears.surface" )
|
2021-11-13 09:20:21 +01:00
|
|
|
local cairo = require("lgi").cairo
|
|
|
|
|
|
|
|
--- Create a copy of the widget frozen in time.
|
|
|
|
-- This is useful whe the global state is modified between the time this is
|
|
|
|
-- called and the time the final output is rendered.
|
|
|
|
function _memento(wdg, width, height, context, force) -- luacheck: globals _memento
|
|
|
|
context = context or {dpi=96}
|
|
|
|
|
|
|
|
local w, h = wdg:fit(context, width or 9999, height or 9999)
|
|
|
|
|
|
|
|
w, h = math.min(force and width or w, width or 9999), math.min(force and height or h, height or 9999)
|
|
|
|
|
|
|
|
local memento = cairo.RecordingSurface(
|
|
|
|
cairo.Content.CAIRO_FORMAT_ARGB32,
|
|
|
|
cairo.Rectangle { x = 0, y = 0, width = w, height = h }
|
|
|
|
)
|
|
|
|
|
|
|
|
local cr = cairo.Context(memento)
|
|
|
|
|
|
|
|
wibox.widget.draw_to_cairo_context(wdg, cr, w, h, context)
|
|
|
|
|
|
|
|
return wibox.widget {
|
|
|
|
fit = function()
|
|
|
|
return w, h
|
|
|
|
end,
|
|
|
|
draw = function(_, _, cr2)
|
|
|
|
cr2:set_source_surface(memento)
|
|
|
|
cr2:paint()
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
2016-03-19 09:58:02 +01:00
|
|
|
|
|
|
|
-- This is the main widget the tests will use as top level
|
|
|
|
local container = wibox.layout.fixed.vertical()
|
|
|
|
|
|
|
|
-- Let the test request a size and file format
|
|
|
|
local w, h, image_type = loadfile(file_path)(container)
|
|
|
|
image_type = image_type or "svg"
|
|
|
|
|
|
|
|
-- Emulate the event loop for 10 iterations
|
|
|
|
for _ = 1, 10 do
|
2019-02-15 17:04:19 +01:00
|
|
|
require("gears.timer").run_delayed_calls_now()
|
2016-03-19 09:58:02 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Get the example fallback size (the tests can return a size if the want)
|
|
|
|
local f_w, f_h = container:fit({dpi=96}, 9999, 9999)
|
|
|
|
|
|
|
|
-- There is an overhead that cause testbox "...", add 10 until someone
|
|
|
|
-- figures out the real equation
|
|
|
|
f_w, f_h = f_w+10, f_h+10
|
|
|
|
|
|
|
|
-- Save to the output file
|
|
|
|
local img = surface["widget_to_"..image_type](container, image_path.."."..image_type, w or f_w, h or f_h)
|
|
|
|
img:finish()
|
|
|
|
|
2016-12-31 13:59:38 +01:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|