08-25-2024, 05:24 PM | #16 |
Grand Sorcerer
Posts: 28,045
Karma: 199464182
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Me too. I was hoping the coding solution would work. We could still do something with fonts. We'd just have to make sure the fonts we started with were license free (and Linux folk would just be on their own getting them installed/configured).
|
08-26-2024, 02:19 PM | #17 |
Sigil Developer
Posts: 8,160
Karma: 5450818
Join Date: Nov 2009
Device: many
|
FWIW,
I used FontForge on Linux and was able to take the LiberationMono.ttf font from its github release site, and eventually found a way to edit the OS2 tables Win Ascent and Win Descent values and generated a MyLibMono font with increased line spacing. It took quite a bit of trial and error but it was doable. To install it I just copied it to ~/.fonts folder. Then I launched Sigil and opened Preferences and used Appearance CodeView to select the MyLibMono font and it all worked. Even with FontForge the process involved a lot of trial and error. And according to their docs, the same changes may not work on other platforms. So not easy but doable. |
Advert | |
|
08-27-2024, 10:36 AM | #18 |
Grand Sorcerer
Posts: 28,045
Karma: 199464182
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Just a thought--I've not looked into the code at all--but I'm wondering if it would be possible to come at this thing through the line-numbering widget? If we give it a Qt objectName, could we not change that widget's spacing or padding via qss (or perhaps come at it programmatically).
Then again, it's entirely likely that this is a "tail wagging the dog" situation (where the metrics of the font used in the QPlainTextWidget dictate the line-height of the LineNumbering area). Just a thought. |
08-27-2024, 10:44 AM | #19 |
Sigil Developer
Posts: 8,160
Karma: 5450818
Join Date: Nov 2009
Device: many
|
I think it is the latter case. The QPlaintextEdit document layout code is simply ignoring the QTextBlockFormat set and so always just uses the font bounding rectangle to determine spacing. The code just adds a left margin and a block number count, I think.
Last edited by KevinH; 08-27-2024 at 10:59 AM. |
08-27-2024, 12:07 PM | #20 |
Sigil Developer
Posts: 8,160
Karma: 5450818
Join Date: Nov 2009
Device: many
|
I will at least look into what it would take to move to QTextEdit. It is just that QPlainTextEdit is supposedly optimized to work with much much larger text files than QTextEdit can handle.
So we would be trading off speed and size just to get line spacing. I am not sure that is a good tradeoff given interested users could edit a font to make that change themselves. |
Advert | |
|
08-27-2024, 12:15 PM | #21 |
Grand Sorcerer
Posts: 28,045
Karma: 199464182
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Agreed. I think the line-height issue warrants some looking into. But I don't think moving to QTextEdit would be the best tradeoff to get it.
|
08-27-2024, 02:15 PM | #22 |
Sigil Developer
Posts: 8,160
Karma: 5450818
Join Date: Nov 2009
Device: many
|
QPlainTextEdit uses QTextLine in its text layout code. I took a look at QTextLine and it completely bases its height on the specific font's ascent, descent, and leading (line gap) metrics. I have no idea if we could subclass QTextLine and override its height routine to max that value against a user settable value or not.
Not sure if that is even possible. |
08-27-2024, 03:24 PM | #23 |
Grand Sorcerer
Posts: 28,045
Karma: 199464182
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Weird that Qt would make something like this so difficult. Seems like something that more people would wish for.
|
08-27-2024, 04:20 PM | #24 |
Sigil Developer
Posts: 8,160
Karma: 5450818
Join Date: Nov 2009
Device: many
|
It is strange. It would not slow down QPlainTextEdit at all to add a user settable but fixed amount to the lineHeight to create better text spacing.
That said, from the qfontengine code we now know the exact values to change in a font to make the line gap (leading value) larger. Perhaps a python program could allow a user to select a monospaced font and then update the type linegap, and leading value (hhea table leading value on mac) to created a modified font for them. There are some nice font tools in python. That might be an avenue to consider. Last edited by KevinH; 08-27-2024 at 04:39 PM. |
08-27-2024, 04:49 PM | #25 |
Guru
Posts: 783
Karma: 2298438
Join Date: Jan 2017
Location: Poland
Device: Various
|
Works!
scale=1.1 means increasing the offset by 10%. Before: pip install fonttools |
08-27-2024, 05:19 PM | #26 |
Sigil Developer
Posts: 8,160
Karma: 5450818
Join Date: Nov 2009
Device: many
|
Hi BeckyEbook,
Very nice! But instead of scaling up the ascent and descent values there is a typo line gap (and similar line gap values for hhea) value that does not actually scale the drawn glyphs but instead just grows the gap between lines. So I just add the current ascent plus descent (as a positive value) and and take 50% of it and make that the typo line gap value stead of 0 (for 1.5 line spacing). That keeps font size exactly the same in QT QFonts but increases line spacing. Does that python fontlib make it easy to try that? Thanks! Kevin Update, checking the ttflib code the values I want to play with are: Code:
ttLib.getTableClass("hhea"), ( "ascent", "descent", "lineGap", ... Code:
ttLib.getTableClass("OS/2"), ( ... "sTypoAscender", "sTypoDescender", "sTypoLineGap", "usWinAscent", "usWinDescent", "sxHeight", "sCapHeight", ), I am away from my Desktop so if you have a free moment would you try that. Based on my reading of the qfontengine code, this should work on all platforms under Qt6. Last edited by KevinH; 08-27-2024 at 05:42 PM. |
08-27-2024, 06:43 PM | #27 |
Guru
Posts: 783
Karma: 2298438
Join Date: Jan 2017
Location: Poland
Device: Various
|
I don't know if I understood correctly that you want to scale all these shown values. Because just changing those two (sTypoLineGap in the OS2 table and lineGap in the hhea table) is unlikely to work, or at least I haven't seen any difference.
In addition, the code now changes the internal name of the font by adding a scale to it, which is very useful for choosing your favorite spacing. The attached code scales all the elements you mentioned. |
08-27-2024, 07:50 PM | #28 |
Sigil Developer
Posts: 8,160
Karma: 5450818
Join Date: Nov 2009
Device: many
|
Not quite. The line gaps are typically 0 so scaling them in any way will not help.
So *instead* of scaling the ascent and descent values (ie. leave them alone) and just change the lineGap values as follows: new_line_gap = int(0.5 * (ascent + descent)) (assuming of course descent is positive). The 0.5 comes from (1.5 line spacing - 1). That sets the leading value in the font metrics to be half the font original height. Either way I will try it tomorrow when I get back home. Thanks! |
08-27-2024, 08:58 PM | #29 |
Sigil Developer
Posts: 8,160
Karma: 5450818
Join Date: Nov 2009
Device: many
|
But I just read that there is a flag value in a ttf file that tells it to use its Typo Metrics over Win Ascent and Descent values. I can set it easily in FontForge but I have no idea how to set it in python fontTool.
So my way may never work except with FontForge Update: in the OS2 table is the field fsSelection in bit 7 (128) is the USE_TYPO_METRICS flag which is not directly supported in fontTools. Also it is clear that hhea , usWinAscent, usWinDescent, and the OS2 table values are really inconsistent in some shipping fonts and they do not fit with the em_square value which must be a power of 2. So what the spec says and what is actually out there in the wild is very inconsistent. Last edited by KevinH; 08-27-2024 at 09:51 PM. |
08-28-2024, 03:43 AM | #30 |
Guru
Posts: 783
Karma: 2298438
Join Date: Jan 2017
Location: Poland
Device: Various
|
I agree with the inconsistency and total arbitrariness of the values, but I checked on a few fonts and it worked. I'm not saying to add this code to Sigil, but it could be a sure workaround for the few people who would have the need. People have different eyesight and wider spacing can certainly be counted as an Accessibility option.
Version 7 does exactly what you described (I hope): * Adds spacing (gap) based on Ascend and Descend values. * Resets the USE_TYPO_METRICS bit. |
Tags |
code view, qt_styles.qss |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to change background color in Code View window | philja | Sigil | 13 | 10-06-2022 12:27 PM |
replace in book view changes view to code view | cybmole | Sigil | 4 | 10-28-2012 02:20 PM |
Sigil highlight Book View No Longer Shows in Code View | Themus | Sigil | 4 | 10-04-2012 08:54 PM |
How do I change the syntax colouring and increase the font size in the Code View? | nicciglen | Sigil | 5 | 02-08-2012 10:34 AM |
lock book view & code view windows into synch | cybmole | Sigil | 5 | 01-19-2011 11:30 PM |