Utility Method To Rescale Sizes In Stylesheets and Themes

15 views
Skip to first unread message

tbp1...@gmail.com

unread,
Mar 11, 2022, 12:10:44 AM3/11/22
to leo-editor
I have just submitted a PR for a new method to be added to Leo's Stylesheet Manager  (g.app.gui.styleSheetManagerClass).  The new method is named rescale_fonts() and it lets you easily rescale all the sizes in a CSS stylesheet  or a Leo theme outline.  It rescales logical sizes (like @string font-family-base = 10.6pt) and physical sizes (like font-size: 10.6pt;)

The background is that I have been struggling with coming up with a theme that works on a small tablet I have.  I couldn't get it to be usable, and I got tired of trying to hand-edit all those logical font-sizes, like @font-family-basic = 10.6pt.  Also, there are many other sizes that are not usually given logical names, like the various paddings and margins that also need to be changed.

At the same time, I was becoming aware that my two plugins, VR3 and Freewin, as well as a new thing I'm working on, don't adjust to changes in theme font size, and I was wondering how to make them adapt more automatically.  And I found that some of the standard plugins that I depend on all the time, like the Find and Nav tabs, also don't scale with the theme sizes.  How to fix all that?

So I wrote a script that uses a regular expression to find all the size instances in pt or px and resize them by a specified factor.  Non-integer sizes are allowed (since I use them in places). Qt and browsers honor point sizes to at least .5pt granularity, and possibly finer.  I'm not sure what will happen for a size in fractional px, like 1.5px.  Presumably  the nearest integer will be used, but it remains to be seen.  If necessary, I could adapt the method to avoid fractional px values - that would be easy.

Once I had this script, I thought that it could be useful to others, especially plugin developers, and that the obvious home for it would be as a new method on the style sheet manager. After all, the SSM already has a node for "Computations on stylesheets themselves".

Using the method to rescale a theme or stylesheet is this easy:

# Input "theme" is a theme or css string
SCALE = 1.25
ssm = g.app.gui.styleSheetManagerClass(c)
rescaled = ssm.rescale_sizes(theme, SCALE)
# Save to a new theme file if desired, or load the 
# changed stylesheet back into the master widget, etc.

Assuming that @Edward agrees, the new method should show up on the devel branch soon.  The PR is at Add new utility method to Qt styleSheetManager class: rescale

tbp1...@gmail.com

unread,
Mar 11, 2022, 7:53:14 AM3/11/22
to leo-editor
Oops, the new method is named rescale_sizes() - a last-minute change - as correctly shown in my code example.  The PR has just been approved, so it should be in the latest version of the devel branch.
Reply all
Reply to author
Forward
0 new messages