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 calculating a nicer normal line-height #603

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

moben
Copy link

@moben moben commented Sep 7, 2024

For koreader#, see description there


This change is Reviewable

@poire-z
Copy link
Contributor

poire-z commented Sep 9, 2024

image

May want to rebase just to be clean and sure.

Comment on lines 3416 to 3413
if (gRenderNormalLineHeight > 0) {
int rem = enode->getDocument()->getDefaultFont()->getSize();
// Scale slightly to font size. Line height is partially a fixed offset and
// partially relative to font size, so scale half of the offset.
// Larger font sizes need less line height
line_h = em + (gRenderNormalLineHeight - rem) * (em + rem) / (2 * em);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Was wondering if all this and your comment could end up in a static inline int getFancyLineHeight(node, font_size).
But it's just one line of maths.
Anyway, keep the documentative comment here only (in renderFinalBlock), and for the 2 others (rather anecdotical : list item and <empty-line> , just mention // See renderFinalBlock() to avoid triplicating the comment.

@@ -90,6 +90,7 @@
// use 0 for old crengine behaviour (no support for absolute units and 1css px = 1 screen px)
#define PROP_RENDER_DPI "crengine.render.dpi"
#define PROP_RENDER_SCALE_FONT_WITH_DPI "crengine.render.scale.font.with.dpi"
#define PROP_RENDER_NORMAL_LINE_HEIGHT "crengine.render.normal.line.height"
Copy link
Contributor

Choose a reason for hiding this comment

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

I know these settings name are all rather odd and some reads as sentnce rather than as a tree :)
May be "crengine.render.line.height.normal" (so it reads like the CSS name:value, rather than a sentence) ?

Comment on lines 3135 to 3136
int em = font->getSize();
if (gRenderNormalLineHeight > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

int em... can be put inside the if ... { }.

Comment on lines 11227 to +11231
}
}
if (pstyle->cr_normal_line_height.type == css_val_inherited) {
pstyle->cr_normal_line_height = parent_style->cr_normal_line_height; // inherit as-is
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just asking in case you did wonder and your brain worked better than mine:
No need to do as in the previous if (pstyle->line_height.type == css_val_inherited) { just above, in case one uses line-height: normal; -cr-normal-line-height: 120% or 1.2em on the parent and line-height: inherit; -cr-normal-line-height: inherit on the child? (or some other kind of combination like that... my brain hurts trying to think about that :/)

Comment on lines +3132 to +3139
int em = font->getSize();
if ( style->cr_normal_line_height.type == css_val_unspecified &&
style->cr_normal_line_height.value == css_generic_normal ) {
line_h = font->getHeight(); // line-height: normal
}
else {
line_h = lengthToPx(enode, style->cr_normal_line_height, em, em, true);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You can shove the int em = font->getSize(); in the else {} branch.

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