Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding font-based normal line-height #603

Merged
merged 7 commits into from
Nov 2, 2024

Conversation

moben
Copy link
Contributor

@moben moben commented Sep 7, 2024

For koreader/koreader#12483, see description there


This change is Reviewable

@moben moben marked this pull request as draft September 7, 2024 13:29
@moben moben force-pushed the normal-line-height branch from ab4cf26 to d68e84e Compare September 8, 2024 17:52
@poire-z
Copy link
Contributor

poire-z commented Sep 9, 2024

image

May want to rebase just to be clean and sure.

crengine/src/lvrend.cpp Outdated Show resolved Hide resolved
crengine/include/lvdocviewprops.h Outdated Show resolved Hide resolved
crengine/src/lvrend.cpp Outdated Show resolved Hide resolved
@moben moben force-pushed the normal-line-height branch from d68e84e to de21aad Compare September 13, 2024 23:10
crengine/src/lvrend.cpp Outdated Show resolved Hide resolved
crengine/src/lvrend.cpp Outdated Show resolved Hide resolved
@moben moben force-pushed the normal-line-height branch from de21aad to 166ed03 Compare October 5, 2024 23:47
@moben moben marked this pull request as ready for review October 5, 2024 23:48
@moben
Copy link
Contributor Author

moben commented Oct 5, 2024

Moved to -cr-only-if: line-height-normal, as suggested in koreader/koreader#12483.

It's a bit annoying that the parent style needs to be passed through everywhere, but it's all coming from lvrend's setNodeStyle, which does know the parent style. But if I understand things correctly that's not really avoidable unless most of what setNodeStyle does (i.e. computing/inheriting the actual values) is moved to LVCssDeclaration::parse. Otherwise -cr-only-if can always have trouble matching if the actual value is only computed later.

@poire-z
Copy link
Contributor

poire-z commented Oct 6, 2024

I'll read your posts and review better tomorrow.

unless most of what setNodeStyle does (i.e. computing/inheriting the actual values) is moved to LVCssDeclaration::parse.

These are really 2 different things: LVCssDeclaration::parse parses a stylesheet way earlier before we get to act on nodes. Which is what setNodeStyle does: applying.

Otherwise -cr-only-if can always have trouble matching if the actual value is only computed later.

I suggested using -cr-hint: late;, which you did use. It's supposed to get that declaration applied (by setNodeStyle) after all others, so normally after all those that set line-height:.
But I'm not sure (haven't looked) if it applies after line-height:inherit in case the node inherits normal.

@moben
Copy link
Contributor Author

moben commented Oct 6, 2024

These are really 2 different things: LVCssDeclaration::parse parses a stylesheet way earlier before we get to act on nodes. Which is what setNodeStyle does: applying.

Sorry, I got that wrong when writing the comment, I meant LVCssDeclaration::apply of course, which is where the condition for -cr-only-if is checked. There you still have line-height: inherit when that is checked because setNodeStyle calls apply and then does all the inheritance.

I'm open to suggestions for a better way to do this, but I don't see how. -cr-hint: late declarations could set something to inherit again, so you need to run inheritance after them. I guess the whole inheritance / computed value part of setNodeStyle could be it's own function, so it can be re-used when checking -cr-only-if instead of open coding it, which would be a slight improvement?

@poire-z
Copy link
Contributor

poire-z commented Oct 6, 2024

I'm open to suggestions for a better way to do this, but I don't see how. -cr-hint: late declarations could set something to inherit again, so you need to run inheritance after them.

-cr-hint: late is our custom stuff, we don't need to allow line-height: inherit to work, we can limit its feature anyway we want, to keep the code simpler.

I guess the whole inheritance / computed value part of setNodeStyle could be it's own function, so it can be re-used when checking -cr-only-if instead of open coding it, which would be a slight improvement?

All the style stuff/setNodeStyle and the rendering methods stuff is quite fragile, there are 2 different code paths using it (initial loading with style computer as we build the dom, vs later rerendering where the dom is already present) and there had been many issues keeping that consistent and the various hashs that detects that identical. So, the less stuff we change the better.

If there is any change we get a parent node with computed style line-height: normal, and its child node gets a computed style of line-height: inherit at the time your -cr-hint:late are checked, I would just add a check in the function to get the parent style and see if it is "normal".
Oh, just looking at the code, that's what you already do :)

But you don't need to pass parent_style alll along, as you're nearly the only user of that. Please limit the changes to the minimum.
You can get to it from the node itself, with getParentNode()->getStyle().
cssd_cr_apply_func (just below what you added) / apply_cr_apply_func / cr_apply_func_css_text_align_center_if_parent_text_align_initial already do that.

@moben moben changed the title Allow calculating a nicer normal line-height Allow overriding font-based normal line-height Nov 1, 2024
@poire-z poire-z merged commit 3131eb1 into koreader:master Nov 2, 2024
1 check passed
@poire-z
Copy link
Contributor

poire-z commented Nov 2, 2024

We'll wait for this to reach koreader frontend to merge koreader/koreader#12483.

benoit-pierre added a commit to benoit-pierre/koreader-base that referenced this pull request Nov 22, 2024
Frenzie pushed a commit to koreader/koreader-base that referenced this pull request Nov 23, 2024
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.

2 participants