Skip to content

css_tweaks: Add generic setting for smaller inpage footnotes #13613

Merged
poire-z merged 14 commits into
koreader:masterfrom
moben:refactor-smaller-footnotes
Jun 1, 2025
Merged

css_tweaks: Add generic setting for smaller inpage footnotes #13613
poire-z merged 14 commits into
koreader:masterfrom
moben:refactor-smaller-footnotes

Conversation

@moben

@moben moben commented Apr 16, 2025

Copy link
Copy Markdown
Contributor

When fixing the "smaller" versions of in-page footnotes for #13554 I got annoyed by the duplication. Also, the in-page footnote menu is getting quite big.

I couldn't find any context for why it's set up this way but here is an alternative. css_tweaks: Generalize smaller inpage footnotes introduces a single Smaller in-page footnotes tweak that affects all enabled footnotes.

I believe a possible downside of this is that it has to be -cr-hint: late and needs to be manually sorted by priority relative to other tweaks. But if that were a problem then it would also apply to all the fixup tweaks?

Screenshot

(also has the changes from #13554 but that is unrelated, I'll just rebase if one of them is merged)
Reader_Jonathan Strange and Mr Norrell epub_p1_2025-04-17_015652


This change is Reviewable

@moben moben force-pushed the refactor-smaller-footnotes branch 2 times, most recently from 8f31e29 to 4c2ab7e Compare April 17, 2025 00:00
Comment thread frontend/ui/data/onetime_migration.lua Outdated
@moben moben force-pushed the refactor-smaller-footnotes branch from 4c2ab7e to 2379025 Compare April 17, 2025 06:45
@Commodore64user

Copy link
Copy Markdown
Member

very happy with the removal of all the duplicate settings, although the extension stuff could go inside fix-up easily. Just add a separator and whack 'em at the bottom.

I do find the names extend footnotes until next footnote and extend footnotes until next header or footnote a bit too overwhelming. I would suggest something more like extend footnote selection/content up to next footnote and extend footnote selection up to next header.

unrelated to this PR but, shouldn't that font size stuff be a SpinWidget?

@moben moben force-pushed the refactor-smaller-footnotes branch from 2379025 to 09f0dc6 Compare April 17, 2025 15:12
@moben moben marked this pull request as ready for review April 17, 2025 15:12
@moben

moben commented Apr 17, 2025

Copy link
Copy Markdown
Contributor Author

I've rebased out the footnote extension changes, let's keep that discussion in #13554. Just means I'll need to rebase whichever one of these is merged first.

@moben moben mentioned this pull request Apr 17, 2025
2 tasks
@poire-z

poire-z commented Apr 17, 2025

Copy link
Copy Markdown
Contributor

If we can, I'd be all for getting rid of the "smaller" stuff, as it is redundant with choosing a font size (80%) in the "In-page footnote font size" submenu.

But please have a look at (no time myself to re-read all that - and this PR - this evening):
#5863 (comment) (where I removed them)
#5863 (comment) (where I put them back)
and see if how you manage and migrate that solves all my worries.

unrelated to this PR but, shouldn't that font size stuff be a SpinWidget?

These font size items works with each their own id - styletweaks are not dynamic, they are just stored as IDs to static bits of CSS. Having a SpinWidget would need a lot more work to pick the right ID or need some more dynamic CSS spitting, not worth the effort (and I like these menu items, easier that having to play with a SpinWidget).

@moben

moben commented Apr 20, 2025

Copy link
Copy Markdown
Contributor Author

Pushed an alternative that allows getting rid of "smaller" while keeping all current behavior/combinations in #13639. Not sure if it's worth it though or if this simplification is enough.

Comment thread frontend/ui/data/css_tweaks.lua Outdated
conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_") end,
global_conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_classic_classnames") end,
title = _("In-page classic classname footnotes (smaller)"),
id = "smaller_footnote-inpage",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may sort all the settings in settings.reader.lua, so it would be nice if this one started the same as the other.
I think we start with footnote_inpage_ when targetting elements to be a footnote, and inpage_footnote_ when adjusting a matched element, so this one could be named inpage_footnote_smaller.

@poire-z

poire-z commented Apr 21, 2025

Copy link
Copy Markdown
Contributor

Looks like you'd be migrating only global tweaks.
What about tweaks set specifically for an already opened book ? The won't be there when that book is reopened ?

@moben

moben commented Apr 22, 2025

Copy link
Copy Markdown
Contributor Author

Good point, will look into migrating per-book settings as well. (and fix the hint name)


In the mean time, thoughts on either of these menu placements? (and of course hint names, I'm bad at those)

"Smaller footnotes" is just the current 80% setting on top-level footnote blocks, the various sizes would be the same hint with different values. (whereas the "Force" variants are the hint with inside-inpage-footnote that applies to all blocks inside a footnote).

Everything in the submenu would conflict to reduce confusion.

Annoyingly, sometimes "small" footnotes are bigger if the body text sets a font smaller than 0.8rem... I guess the only way to fix that would be a -cr-scale-font: 0.x that scales the font after regular font-size computation, but I don't want to bloat this PR further.

@Commodore64user

Copy link
Copy Markdown
Member

I personally hate both those screenshots, but hate the left one a lot less, does it really need to use word “force”?

@Frenzie

Frenzie commented Apr 23, 2025

Copy link
Copy Markdown
Member

All the style tweaks are about forcing things, so indeed that seems redundant at best.

@Frenzie

Frenzie commented Apr 23, 2025

Copy link
Copy Markdown
Member

I personally hate both those screenshots, but hate the left one a lot less

Forget about how it looks. But what does it do? ;-)

I'm not quite sure what this is trying to say. What's the same hint with different values?

"Smaller footnotes" is just the current 80% setting on top-level footnote blocks, the various sizes would be the same hint with different values. (whereas the "Force" variants are the hint with inside-inpage-footnote that applies to all blocks inside a footnote).

@moben

moben commented Apr 24, 2025

Copy link
Copy Markdown
Contributor Author

Sorry, I should have elaborated a bit more. I pushed the left version without the wording change.

I just moved the "smaller footnotes" hint, which is

*, autoBoxing {
    -cr-hint: late;
    -cr-only-if: inpage-footnote;
        font-size: 0.8rem !important;
}

Into the footnote size submenu. This keeps the same behavior that's in master right now if you select one of the duplicated "smaller" in-page footnote options. (i.e. within footnotes, relative font-sizes work)

I wanted to find some wording that distinguishes this from the footnote font-size tweaks, which override the size of each (block) element in the footnote to e.g. 0.8rem. (i.e. almost everything in the footnote is forced to the same size)

This has always been confusing in my opinion. If you select the smaller footnotes, what do the footnote font-size hints do? Maybe "override" would be a wording that's more consistent with other tweaks?

In any case, I just split out the duplicated "smaller" part from the footnotes and moved it to the submenu for now (and specified that it's 80%, because all the other size options also specify the size).

@poire-z

If we can, I'd be all for getting rid of the "smaller" stuff, as it is redundant with choosing a font size (80%) in the "In-page footnote font size" submenu.
But please have a look at (no time myself to re-read all that - and this PR - this evening):
#5863 (comment) (where I removed them)
#5863 (comment) (where I put them back)
and see if how you manage and migrate that solves all my worries.

This doesn't quite get rid of it. I don't think it's possible without fundamentally changing behavior as you were worried about and I think it's valuable to have a tweak that just changes the size at the top level of the footnote (or some way to scale the font-size of a whole block in crengine).

This should at least be less cluttered than the duplicated "smaller" footnote hints and correctly does conflicts to make it clear that the font-size tweaks override the "smaller" variant.


Comment on lines -37 to -43
-- Global settings, https://github.com/koreader/koreader/pull/4945 & https://github.com/koreader/koreader/pull/5655
-- Limit the check to the most recent update. ReaderUI calls this one unconditionally to update docsettings, too.
if last_migration_date < 20191129 then
logger.info("Performing one-time migration for 20191129")

local SettingsMigration = require("ui/data/settings_migration")
SettingsMigration:migrateSettings(G_reader_settings)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one has not been used since 2019 - not sure why. May be it existed before we introduced onetimemigration, which is where migration stuff has been happening :) @NiLuJe ?
So, dunno if it's a good idea to ressurect/reuse that one, which did/would do other stuff.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong feeling about it, but it probably couldn't hurt to keep the old one as-is, and just add another specific method in SettingsMigration for that one ;).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onetimemigration also handles global settings. It was introduced by you in April 2021.
settings_migration has had minor stuff added after 2019, but given that it's driven since Apr 2021 by your PR with a last_migration_date < 2019 condition, it has had no effect and use.
I'd be for keeping everything in onetime_migration.

Comment thread frontend/ui/data/settings_migration.lua
Comment thread frontend/ui/data/settings_migration.lua Outdated
Comment on lines +52 to +58
-- base hint
--
-- | n | t | f |
-- ---+---+---+---+
-- small n | n | t | f |
-- hint t | t | t | t |
-- f | f | t | f |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do n, t and f stand for ? I really can't say :/ so it needs a comment.

Some minutes later: Oh, nil, true and false ! you may as well write them fully :)

Some minutes later: what does hint means ? What's the last unamed line, the resut ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope it's clearer now. The two input dimensions are the tweak setting for e.g. classname footnotes and smaller classname footnotes, the fields are the result after the migration.

I found it helpful to write down all the cases especially because the meaning differs a bit between global and per-book settings.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, "base hint" written on 2 lines :)
"hint" feels like not the best word, I would just use "note".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to hopefully be unambiguous and also make it clear that this is per footnote type. (diff above is outdated though)

For some reason my brain keeps replacing "tweak" with "hint", but I think I fixed that in all comments (probably because of -cr-hint)...

Comment on lines +960 to +981
id = "inpage_footnote_font-size_smaller",
conflicts_with = function(id) return util.stringStartsWith(id, "inpage_footnote_font-size_") end,
title = _("Smaller footnotes (80%)"),
description = _([[
Decrease size of in-page footnotes.]]),
css = [[
body[name="notes"] > section {
-cr-only-if: fb2-document;
font-size: 0.75rem;
}
body[name="comments"] > section {
-cr-only-if: fb2-document;
font-size: 0.85rem;
}
*, autoBoxing {
-cr-hint: late;
-cr-only-if: -fb2-document inpage-footnote;
font-size: 0.8rem !important;
}
]],
separator = true,
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, what I disliked in the other PR, I'm ok with having it only in this "somehow legacy" tweak.
May be it could have a more verbose description, mentionning it's limited (no inheritance, so possibly no effect - the reasong why you qualitied the others with "force" all along).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm honestly not 100% sure if I like this better or if it's better to keep the fb2 footnote size tweak separate. My main concern was cleaning up the top-level footnote menu and I got a bit carried away.

As you noted, it prevents some combinations like having larger epub and smaller fb2.
Any preference on your side for reducing menu items vs keeping fb2 size separate? (as in master, or also moving it inside font size)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dunno, not sure I get what the options are :).
I don't mint not reducing menu stuff for FB2 and having them separated (FB2 is useful to user from a few countries only, 98% of users won't ever hear about FB2).
I'd rather not have the font size % duplicated in the FB2 submenu.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted the changes to fb2, incorporating that into the migration would have been tricky anyway.

It now just removes the "smaller" top-level variants and moves them to the footnote font-size submenu.

@poire-z

poire-z commented Apr 25, 2025

Copy link
Copy Markdown
Contributor

Ok, I prefer this one.

I couldn't find any context for why it's set up this way

Initially, we only had the pairs "normal" and "smaller", which were not "forcing": no inheritance to sub elements (because otherwise it would have killed any superscript in the footnote), so possibly having no effect if there's nested block elements and the publisher sets a font size on the sub element.

Later, I added support for -cr-only-if: -inline, which allowed me to target all nested block elements (with inside-inpage-footnote), while preserving inline (superscripts) relative font size.

The 2nd behaviour is probably the best, and could be the only one.
I would have been ok killing the 1st one, and just forcing the 2nd to users, they would probably not notice - and those who do can make their own book style tweak when it has unwanted effect.

But as you are keeping this 1st behaviour (that I'm willing to call legacy) buried inside the "Footnote font size" submenu, I'm quite fine with this PR.

No idea if the migration will handle all cases, or prevent some combinations (smaller FB2 but normal EPUB ? probably rarely used), so trusting you.

id = "footnote-inpage_epub",
conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_") end,
global_conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_epub") end,
global_conflicts_with = false,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by the way, is it intentional that this lets you set multiple of these footnote tweaks as global defaults, even if they conflict? You can do that on master and I've preserved the behavior, but I always found it strange. As soon as you then adjust them in book-specific settings you can only keep one, so it's very inconsistent.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember.
But I guess one could set EPUB + Wikipedia to have inpage footnotes whenever he opens a publisher EPUB and a Wikipedia Saved as EPUB - there may be no need to prevent that.

(Not using that myself, I have my own patch which sets tweaks depending on some condition - mostly just because I don't like having a black star in my menu items :))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, the question is what you mean by conflict exactly. Setting all the footnote classes as default is very reasonable for example.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean conflicts as in conflicts_with in css_tweaks.lua. I find it weird that I can set all inpage footnote tweaks as default, so once I open a book they are all enabled at the same time. But if I only have one of them as default then I can't enable multiple of them for a single book.

I agree it's fine in practice because each book probably only uses one of the types and having the others on doesn't hurt (and if it does you can adjust from there). I just found it weird when testing this stuff that there are some configurations that you can only reach through global defaults and not by adjusting per-book settings.

@moben

moben commented May 4, 2025

Copy link
Copy Markdown
Contributor Author

No idea if the migration will handle all cases, or prevent some combinations (smaller FB2 but normal EPUB ? probably rarely used), so trusting you.

I tested many different combinations, but this obviously limits possibilities compared to what's in master. e.g. you can't have regular size EPUB footnotes and smaller classname footnotes as default. (or in a single book if such a book exists)

As you say, probably rarely used though and the newer footnote font-size tweaks already work the same way and affect all footnotes, so this is probably better anyway.

@poire-z

poire-z commented May 5, 2025

Copy link
Copy Markdown
Contributor

Fine with the latest comments and changes.

Remaining, from my previous review comments:

#13613 (comment)

Looks like you'd be migrating only global tweaks.
What about tweaks set specifically for an already opened book ? The won't be there when that book is reopened ?

#13613 (comment)

onetimemigration also handles global settings. It was introduced by you in April 2021.
settings_migration has had minor stuff added after 2019, but given that it's driven since Apr 2021 by your PR with a last_migration_date < 2019 condition, it has had no effect and use.
I'd be for keeping everything in onetime_migration.

#13613 (comment)

May be it could have a more verbose description, mentionning it's limited (no inheritance, so possibly no effect - the reasong why you qualitied the others with "force" all along).

@moben

moben commented May 5, 2025

Copy link
Copy Markdown
Contributor Author

settings_migration handles global and per-book settings. I switched to using that and this branch now handles both correctly (that's where the false cases in the migration table come from, global tweaks are only true or nil as far as I understand)

since Apr 2021 by your PR with a last_migration_date < 2019 condition, [settings_migration] has had no effect and use.

I don't think that's quite correct. settings_migration is also called in readerui.lua each time any book is opened and actually re-runs the same migration each time even if it was already applied. I didn't want to touch the whole migration here because it would be a bigger change, but I'm happy to merge them into one place that handles both global and per-book (and actually also respects/sets last_migration_date for per-book settings)

@poire-z

poire-z commented May 5, 2025

Copy link
Copy Markdown
Contributor

Oh, you mean it's alright, and the correct place, to have per-book (docsettings) settings migration ?
And that if we hadn't touched that file for years, it's because we just haven't had the need to migrate past opened book settings ? Strange that we haven't had the need, but ok.
Ok then.

Comment thread frontend/ui/data/css_tweaks.lua Outdated
conflicts_with = function(id) return util.stringStartsWith(id, "inpage_footnote_font-size_") end,
title = _("Smaller footnotes (80%)"),
description = _([[
Decrease size of in-page footnotes. This may have limited/no effect, e.g. if it's overwritten by publisher styles.]]),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Decrease size of in-page footnotes. This may have limited/no effect, e.g. if it's overwritten by publisher styles.]]),
Decrease size of in-page footnotes. This may have no effect if it's overwritten by publisher styles.]]),

But how can !important have no effect? Do you mean something like 'may have no apparent effect'?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will find the footnote container and apply it.
But if the publisher has set a font-size on a sub-block of that container, this font-size will not be overridden by ours (set on the parent, not inherited).
So, may have no apparent effect.

The other (added at a later date) tweaks use * { -cr-only-if: inside-inpage-footnote } and will match ALL children and will override their font-size.
That's why I mentionned previously this one could be considered legacy and this could be mentionned - but @moben seems to want to be soft about it :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not trying to be soft about it, I'm just bad at writing these descriptions 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the wording stronger, maybe it's better now?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with me :)

DEFAULT_GLOBAL_STYLE_TWEAKS["footnote-inpage_epub_smaller"] = true
DEFAULT_GLOBAL_STYLE_TWEAKS["footnote-inpage_epub"] = true
DEFAULT_GLOBAL_STYLE_TWEAKS["footnote-inpage_fb2"] = true
DEFAULT_GLOBAL_STYLE_TWEAKS["inpage_footnote_font-size_smaller"] = true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing that could be done is switching this default to inpage_footnote_font-size_80.

That would apply to new installs, whereas existing users get the "legacy" tweak inpage_footnote_font-size_smaller via the migration.

Maybe a good idea if it's strongly recommended to use the newer tweaks as @poire-z suggests. Then we'd also be more likely to get reports if these newer tweaks are worse in some situation. After some time one could migrate everyone from the legacy tweak (if wanted).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you feel.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there might be enough changes here to maybe wait for a release and see if there's any feedback before also changing the default.

Comment thread frontend/ui/data/css_tweaks.lua Outdated
conflicts_with = function(id) return util.stringStartsWith(id, "inpage_footnote_font-size_") end,
title = _("Smaller footnotes (80%, legacy)"),
description = _([[
Decrease size of in-page footnotes. This may have limited/no apparent effect, e.g. if it's overwritten by publisher styles. The "footnote font size" style tweaks are recommended instead.]]),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Decrease size of in-page footnotes. This may have limited/no apparent effect, e.g. if it's overwritten by publisher styles. The "footnote font size" style tweaks are recommended instead.]]),
Decrease size of in-page footnotes. This may have no effect if it's overwritten by publisher styles. The "footnote font size" style tweaks are recommended instead.]]),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied

@poire-z

poire-z commented May 25, 2025

Copy link
Copy Markdown
Contributor

"This branch has conflicts that must be resolved". Letting you handle this.

@moben moben force-pushed the refactor-smaller-footnotes branch from d2e0a68 to 6ed2ee6 Compare May 25, 2025 21:17
Comment thread frontend/ui/data/onetime_migration.lua Outdated

-- Date at which the last migration snippet was added
local CURRENT_MIGRATION_DATE = 20250405
local CURRENT_MIGRATION_DATE = 20250417

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update this date to the day you'll do it :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to today

@poire-z poire-z merged commit cfc6779 into koreader:master Jun 1, 2025
2 of 4 checks passed
@Frenzie Frenzie added this to the 2025.05 milestone Jun 1, 2025
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants