parent
3af0aab36d
commit
a2e69336c7
6 changed files with 497 additions and 4 deletions
@ -0,0 +1,341 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<!-- Generated with glade 3.22.2 --> |
||||||
|
<interface> |
||||||
|
<requires lib="gtk+" version="3.20"/> |
||||||
|
<object class="GtkAdjustment" id="adjOldDpi"> |
||||||
|
<property name="lower">13</property> |
||||||
|
<property name="upper">400</property> |
||||||
|
<property name="value">223</property> |
||||||
|
<property name="step_increment">1</property> |
||||||
|
<property name="page_increment">10</property> |
||||||
|
</object> |
||||||
|
<object class="GtkAdjustment" id="adjScaleFactor"> |
||||||
|
<property name="lower">0.17999999999999999</property> |
||||||
|
<property name="upper">5.5499999999999998</property> |
||||||
|
<property name="value">3.0899999999999999</property> |
||||||
|
<property name="step_increment">0.01</property> |
||||||
|
<property name="page_increment">1</property> |
||||||
|
</object> |
||||||
|
<object class="GtkDialog" id="dlgMigrateFontSizes"> |
||||||
|
<property name="can_focus">False</property> |
||||||
|
<property name="resizable">False</property> |
||||||
|
<property name="type_hint">dialog</property> |
||||||
|
<child type="titlebar"> |
||||||
|
<placeholder/> |
||||||
|
</child> |
||||||
|
<child internal-child="vbox"> |
||||||
|
<object class="GtkBox" id="vboxInternal"> |
||||||
|
<property name="can_focus">False</property> |
||||||
|
<property name="margin_left">12</property> |
||||||
|
<property name="margin_right">12</property> |
||||||
|
<property name="margin_top">12</property> |
||||||
|
<property name="margin_bottom">12</property> |
||||||
|
<property name="orientation">vertical</property> |
||||||
|
<property name="spacing">2</property> |
||||||
|
<child internal-child="action_area"> |
||||||
|
<object class="GtkButtonBox" id="btBox"> |
||||||
|
<property name="can_focus">False</property> |
||||||
|
<property name="layout_style">end</property> |
||||||
|
<child> |
||||||
|
<object class="GtkButton" id="btCancel"> |
||||||
|
<property name="label">gtk-cancel</property> |
||||||
|
<property name="visible">True</property> |
||||||
|
<property name="can_focus">True</property> |
||||||
|
<property name="receives_default">True</property> |
||||||
|
<property name="use_stock">True</property> |
||||||
|
</object> |
||||||
|
<packing> |
||||||
|
<property name="expand">True</property> |
||||||
|
<property name="fill">True</property> |
||||||
|
<property name="position">0</property> |
||||||
|
</packing> |
||||||
|
</child> |
||||||
|
<child> |
||||||
|
<object class="GtkButton" id="btApply"> |
||||||
|
<property name="label">gtk-apply</property> |
||||||
|
<property name="visible">True</property> |
||||||
|
<property name="can_focus">True</property> |
||||||
|
<property name="receives_default">True</property> |
||||||
|
<property name="use_stock">True</property> |
||||||
|
</object> |
||||||
|
<packing> |
||||||
|
<property name="expand">True</property> |
||||||
|
<property name="fill">True</property> |
||||||
|
<property name="position">1</property> |
||||||
|
</packing> |
||||||
|
</child> |
||||||
|
</object> |
||||||
|
<packing> |
||||||
|
<property name="expand">False</property> |
||||||
|
<property name="fill">False</property> |
||||||
|
<property name="position">0</property> |
||||||
|
</packing> |
||||||
|
</child> |
||||||
|
<child> |
||||||
|
<object class="GtkBox" id="vbox1"> |
||||||
|
<property name="visible">True</property> |
||||||
|
<property name="can_focus">False</property> |
||||||
|
<property name="margin_bottom">12</property> |
||||||
|
<property name="orientation">vertical</property> |
||||||
|
<property name="spacing">12</property> |
||||||
|
<child> |
||||||
|
<object class="GtkLabel" id="lblTitle"> |
||||||
|
<property name="visible">True</property> |
||||||
|
<property name="can_focus">False</property> |
||||||
|
<property name="label" translatable="yes">Migrate font sizes</property> |
||||||
|
<attributes> |
||||||
|
<attribute name="weight" value="bold"/> |
||||||
|
</attributes> |
||||||
|
</object> |
||||||
|
<packing> |
||||||
|
<property name="expand">False</property> |
||||||
|
<property name="fill">True</property> |
||||||
|
<property name="position">0</property> |
||||||
|
</packing> |
||||||
|
</child> |
||||||
|
<child> |
||||||
|
<object class="GtkExpander" id="expHelp"> |
||||||
|
<property name="visible">True</property> |
||||||
|
<property name="can_focus">True</property> |
||||||
|
<child> |
||||||
|
<object class="GtkLabel" id="lblExplanation"> |
||||||
|
<property name="visible">True</property> |
||||||
|
<property name="can_focus">False</property> |
||||||
|
<property name="label" translatable="yes">In Xournal++ versions 1.0.x and earlier version of 1.1.0+dev font sizes were relative |
||||||
|
to the display DPI setting from the preferences (slider in the zoom panel). Only |
||||||
|
with the standard setting of 72 DPI the fonts were saved with their true size. With a |
||||||
|
20 pt Sans Regular font, two subsequent lines of text should be separated exactly |
||||||
|
by the distance between two subsequent lines of the ruled paper background. |
||||||
|
With 144 DPI (i.e. the doubled value) you however needed a font size of 10 pt |
||||||
|
(the half value) for that purpose. This was confusing. |
||||||
|
|
||||||
|
We have changed that so that 20 pt Sans Regular will always fit to the ruled paper |
||||||
|
background lines regardless of the display DPI setting. |
||||||
|
|
||||||
|
If you have created documents with a different display DPI setting than 72, you will |
||||||
|
now see font sizes that are of different size then they looked like when you created |
||||||
|
them. This plugin allows to correct that in the current document for once and |
||||||
|
forever. For that purpose we need to scale all font sizes of the document with the |
||||||
|
factor f = OldDPI / 72, where OldDPI is the display DPI value with which the |
||||||
|
document was created.</property> |
||||||
|
<property name="wrap">True</property> |
||||||
|
<property name="width_chars">55</property> |
||||||
|
</object> |
||||||
|
</child> |
||||||
|
<child type="label"> |
||||||
|
<object class="GtkLabel" id="lblHelp"> |
||||||
|
<property name="visible">True</property> |
||||||
|
<property name="can_focus">False</property> |
||||||
|
<property name="label" translatable="yes">Show help</property> |
||||||
|
<attributes> |
||||||
|
<attribute name="weight" value="bold"/> |
||||||
|
</attributes> |
||||||
|
</object> |
||||||
|
</child> |
||||||
|
</object> |
||||||
|
<packing> |
||||||
|
<property name="expand">False</property> |
||||||
|
<property name="fill">True</property> |
||||||
|
<property name="position">1</property> |
||||||
|
</packing> |
||||||
|
</child> |
||||||
|
<child> |
||||||
|
<object class="GtkBox"> |
||||||
|
<property name="visible">True</property> |
||||||
|
<property name="can_focus">False</property> |
||||||
|
<property name="margin_bottom">12</property> |
||||||
|
<child> |
||||||
|
<object class="GtkLabel" id="lblCurrentDpiHeading"> |
||||||
|
<property name="visible">True</property> |
||||||
|
<property name="can_focus">False</property> |
||||||
|
<property name="label" translatable="yes">Current Display DPI</property> |
||||||
|
<attributes> |
||||||
|
<attribute name="weight" value="bold"/> |
||||||
|
</attributes> |
||||||
|
</object> |
||||||
|
<packing> |
||||||
|
<property name="expand">False</property> |
||||||
|
<property name="fill">True</property> |
||||||
|
<property name="position">0</property> |
||||||
|
</packing> |
||||||
|
</child> |
||||||
|
<child> |
||||||
|
<object class="GtkLabel" id="lblCurrentDpi"> |
||||||
|
<property name="visible">True</property> |
||||||
|
<property name="can_focus">False</property> |
||||||
|
<property name="margin_left">24</property> |
||||||
|
<property name="label" translatable="yes">223</property> |
||||||
|
<property name="width_chars">5</property> |
||||||
|
<property name="max_width_chars">5</property> |
||||||
|
</object> |
||||||
|
<packing> |
||||||
|
<property name="expand">False</property> |
||||||
|
<property name="fill">True</property> |
||||||
|
<property name="position">1</property> |
||||||
|
</packing> |
||||||
|
</child> |
||||||
|
</object> |
||||||
|
<packing> |
||||||
|
<property name="expand">False</property> |
||||||
|
<property name="fill">True</property> |
||||||
|
<property name="position">2</property> |
||||||
|
</packing> |
||||||
|
</child> |
||||||
|
<child> |
||||||
|
<object class="GtkGrid" id="gridFactorSettings"> |
||||||
|
<property name="visible">True</property> |
||||||
|
<property name="can_focus">False</property> |
||||||
|
<property name="row_spacing">12</property> |
||||||
|
<property name="column_spacing">6</property> |
||||||
|
<child> |
||||||
|
<object class="GtkLabel" id="lblScaleFactor"> |
||||||
|
<property name="visible">True</property> |
||||||
|
<property name="can_focus">False</property> |
||||||
|
<property name="halign">start</property> |
||||||
|
<property name="label" translatable="yes">Scale Factor</property> |
||||||
|
<attributes> |
||||||
|
<attribute name="weight" value="bold"/> |
||||||
|
</attributes> |
||||||
|
</object> |
||||||
|
<packing> |
||||||
|
<property name="left_attach">4</property> |
||||||
|
<property name="top_attach">0</property> |
||||||
|
</packing> |
||||||
|
</child> |
||||||
|
<child> |
||||||
|
<object class="GtkLabel" id="lblDpiNormalization"> |
||||||
|
<property name="visible">True</property> |
||||||
|
<property name="can_focus">False</property> |
||||||
|
<property name="halign">start</property> |
||||||
|
<property name="label" translatable="yes">DPI Normalization</property> |
||||||
|
<attributes> |
||||||
|
<attribute name="weight" value="bold"/> |
||||||
|
</attributes> |
||||||
|
</object> |
||||||
|
<packing> |
||||||
|
<property name="left_attach">2</property> |
||||||
|
<property name="top_attach">0</property> |
||||||
|
</packing> |
||||||
|
</child> |
||||||
|
<child> |
||||||
|
<object class="GtkLabel" id="lblOldDPI"> |
||||||
|
<property name="visible">True</property> |
||||||
|
<property name="can_focus">False</property> |
||||||
|
<property name="halign">start</property> |
||||||
|
<property name="label" translatable="yes">Old DPI</property> |
||||||
|
<attributes> |
||||||
|
<attribute name="weight" value="bold"/> |
||||||
|
</attributes> |
||||||
|
</object> |
||||||
|
<packing> |
||||||
|
<property name="left_attach">0</property> |
||||||
|
<property name="top_attach">0</property> |
||||||
|
</packing> |
||||||
|
</child> |
||||||
|
<child> |
||||||
|
<object class="GtkSpinButton" id="spbtOldDpi"> |
||||||
|
<property name="visible">True</property> |
||||||
|
<property name="can_focus">True</property> |
||||||
|
<property name="max_length">6</property> |
||||||
|
<property name="width_chars">5</property> |
||||||
|
<property name="text" translatable="yes">223</property> |
||||||
|
<property name="adjustment">adjOldDpi</property> |
||||||
|
<property name="numeric">True</property> |
||||||
|
<property name="value">232</property> |
||||||
|
</object> |
||||||
|
<packing> |
||||||
|
<property name="left_attach">0</property> |
||||||
|
<property name="top_attach">1</property> |
||||||
|
</packing> |
||||||
|
</child> |
||||||
|
<child> |
||||||
|
<object class="GtkLabel" id="lblDivisionSign"> |
||||||
|
<property name="visible">True</property> |
||||||
|
<property name="can_focus">False</property> |
||||||
|
<property name="margin_left">24</property> |
||||||
|
<property name="label" translatable="yes">/</property> |
||||||
|
</object> |
||||||
|
<packing> |
||||||
|
<property name="left_attach">1</property> |
||||||
|
<property name="top_attach">1</property> |
||||||
|
</packing> |
||||||
|
</child> |
||||||
|
<child> |
||||||
|
<object class="GtkLabel" id="lblEqualSign"> |
||||||
|
<property name="visible">True</property> |
||||||
|
<property name="can_focus">False</property> |
||||||
|
<property name="margin_right">24</property> |
||||||
|
<property name="label" translatable="yes">=</property> |
||||||
|
</object> |
||||||
|
<packing> |
||||||
|
<property name="left_attach">3</property> |
||||||
|
<property name="top_attach">1</property> |
||||||
|
</packing> |
||||||
|
</child> |
||||||
|
<child> |
||||||
|
<object class="GtkSpinButton" id="spbtScaleFactor"> |
||||||
|
<property name="visible">True</property> |
||||||
|
<property name="can_focus">True</property> |
||||||
|
<property name="max_length">10</property> |
||||||
|
<property name="width_chars">8</property> |
||||||
|
<property name="progress_fraction">0.01</property> |
||||||
|
<property name="adjustment">adjScaleFactor</property> |
||||||
|
<property name="digits">4</property> |
||||||
|
<property name="numeric">True</property> |
||||||
|
<property name="value">3.0899999999999999</property> |
||||||
|
</object> |
||||||
|
<packing> |
||||||
|
<property name="left_attach">4</property> |
||||||
|
<property name="top_attach">1</property> |
||||||
|
</packing> |
||||||
|
</child> |
||||||
|
<child> |
||||||
|
<object class="GtkLabel" id="lblConstant"> |
||||||
|
<property name="visible">True</property> |
||||||
|
<property name="can_focus">False</property> |
||||||
|
<property name="label" translatable="yes">72</property> |
||||||
|
</object> |
||||||
|
<packing> |
||||||
|
<property name="left_attach">2</property> |
||||||
|
<property name="top_attach">1</property> |
||||||
|
</packing> |
||||||
|
</child> |
||||||
|
<child> |
||||||
|
<placeholder/> |
||||||
|
</child> |
||||||
|
<child> |
||||||
|
<placeholder/> |
||||||
|
</child> |
||||||
|
</object> |
||||||
|
<packing> |
||||||
|
<property name="expand">False</property> |
||||||
|
<property name="fill">True</property> |
||||||
|
<property name="position">3</property> |
||||||
|
</packing> |
||||||
|
</child> |
||||||
|
<child> |
||||||
|
<object class="GtkLabel" id="lblDialog"> |
||||||
|
<property name="visible">True</property> |
||||||
|
<property name="can_focus">False</property> |
||||||
|
<property name="halign">start</property> |
||||||
|
<property name="margin_top">12</property> |
||||||
|
<property name="label" translatable="yes">Click "Apply" to scale font sizes of all elements of the document by the scale factor. |
||||||
|
Save the document, when you are done.</property> |
||||||
|
</object> |
||||||
|
<packing> |
||||||
|
<property name="expand">False</property> |
||||||
|
<property name="fill">True</property> |
||||||
|
<property name="position">4</property> |
||||||
|
</packing> |
||||||
|
</child> |
||||||
|
</object> |
||||||
|
<packing> |
||||||
|
<property name="expand">False</property> |
||||||
|
<property name="fill">True</property> |
||||||
|
<property name="position">1</property> |
||||||
|
</packing> |
||||||
|
</child> |
||||||
|
</object> |
||||||
|
</child> |
||||||
|
</object> |
||||||
|
</interface> |
||||||
@ -0,0 +1,87 @@ |
|||||||
|
-- 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 |
||||||
@ -0,0 +1,15 @@ |
|||||||
|
[about] |
||||||
|
## Author / Copyright notice |
||||||
|
author=Roland Lötscher |
||||||
|
|
||||||
|
description=Migrate font sizes to Display DPI independent font size handling since Feb 2021 |
||||||
|
|
||||||
|
## If the plugin is packed with Xournal++, use |
||||||
|
## <xournalpp> then it gets the same version number |
||||||
|
version=<xournalpp> |
||||||
|
|
||||||
|
[default] |
||||||
|
enabled=true |
||||||
|
|
||||||
|
[plugin] |
||||||
|
mainfile=main.lua |
||||||
Loading…
Reference in new issue