You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

87 lines
2.9 KiB

-- Register all Toolbar actions and intialize all UI stuff
function initUi()
app.registerUi({["menu"] = "Migrate font sizes with factor displayDPI / 72", ["callback"] = "migrate"});
app.registerUi({["menu"] = "Show font size migration dialog", ["callback"] = "showDialog"});
lgiInstallPaths = "/usr/share/lua/5.3/?.lua; /usr/local/share/lua/5.3/?.lua" -- change this if your lgi.lua file is located in a different directory
package.path = package.path .. ";../?.lua;" .. lgiInstallPaths
sourcePath = debug.getinfo(1).source:match("@?(.*/)")
end
function migrate()
local displayDpi = app.getDisplayDpi()
local dpiNormalizationFactor = 72
local factor = displayDpi / dpiNormalizationFactor
-- print("Display DPI is " .. displayDpi .. " => scaling by factor " .. displayDpi .. "/72 = " .. factor)
local result = app.msgbox("Display DPI is " .. displayDpi .. ". By proceeding the font sizes of all text elements will be scaled by the factor " .. displayDpi .. "/72 = " .. factor, {[1]="Cancel", [2]="OK"})
if result == 2 then
resize(factor)
end
end
local currDpi
function showDialog()
local hasLgi, lgi = pcall(require, "lgi")
if not hasLgi then
app.msgbox("You need to have the Lua lgi-module installed in order to use the GUI for migrating font sizes. \n\n Also check the lgi module install paths in the file \n\n " .. sourcePath .. "main.lua \n\n Currently \n\n" .. lgiInstallPaths .. "\n\n is specified", {[1]="OK"})
return
end
--lgi module has been found
local Gtk = lgi.Gtk
local Gdk = lgi.Gdk
local assert = lgi.assert
local builder = Gtk.Builder()
assert(builder:add_from_file(sourcePath .. "dialog.glade"))
local ui = builder.objects
local dialog = ui.dlgMigrateFontSizes
if not currDpi then
currDpi = app.getDisplayDpi()
end
ui.spbtOldDpi:set_value(currDpi)
ui.lblCurrentDpi:set_text(app.getDisplayDpi())
-- Connect actions
function ui.btApply.on_clicked()
local factor = ui.spbtScaleFactor:get_value()
resize(factor)
end
function ui.btCancel.on_clicked()
dialog:destroy()
end
function ui.spbtScaleFactor.on_value_changed()
factor = ui.spbtScaleFactor:get_value()
currDpi = math.floor(factor*72+0.5)
ui.spbtOldDpi:set_value(currDpi)
end
function ui.spbtOldDpi.on_value_changed()
oldDpi = ui.spbtOldDpi:get_value()
ui.spbtScaleFactor:set_value(oldDpi/72)
end
dialog:show_all()
end
function resize(factor)
local docStructure = app.getDocumentStructure()
local numPages = #docStructure["pages"]
local page = docStructure["currentPage"]
local layer = docStructure["pages"][page]["currentLayer"]
for i=1, numPages do
app.setCurrentPage(i)
local numLayers = #docStructure["pages"][page]["layers"]
for j=1, numLayers do
app.setCurrentLayer(j)
app.scaleTextElements(factor)
end
end
app.setCurrentPage(page)
app.setCurrentLayer(layer)
end