initialize_global_viewport = function()
local minx, miny, maxx, maxy = surface_bounds(Definitions)
-- ensure 1px of white background all around
-- just in case the viewport ever goes
-- outside canvas bounds while animating
minx,miny, maxx,maxy = minx-1,miny-1, maxx+2,maxy+1
local zoomx = App.screen.width/(maxx-minx)
local zoomy = App.screen.height/(maxy-miny)
local zoom, globalw, globalh
if zoomx < zoomy then
zoom = zoomx
globalw = maxx-minx
globalh = globalw*App.screen.height/App.screen.width
else
zoom = zoomy
globalh = maxy-miny
globalw = globalh*App.screen.width/App.screen.height
end
zoom = math.max(zoom, --[[disallow font size of 0; not sure why 1 doesn't work]] 2 / --[[baseline font size at zoom 1]] 20)
local global_viewport = {x=minx, y=miny, zoom=zoom}
return global_viewport, globalw, globalh
end