Skip to content

Commit

Permalink
CSS: add support for "-cr-only-if: line-height-normal" (#603)
Browse files Browse the repository at this point in the history
This allows overriding "line-height: normal" (which uses the
font authors' designed value from the the font metrics)
with a specific line-height based on the CSS font size.
  • Loading branch information
moben authored Nov 2, 2024
1 parent f9e9c3f commit 3131eb1
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions crengine/src/lvstsheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3074,6 +3074,8 @@ static const char * css_cr_only_if_names[]={
"not-inpage-footnote",
"inside-inpage-footnote",
"not-inside-inpage-footnote",
"line-height-normal",
"not-line-height-normal",
NULL
};
enum cr_only_if_t {
Expand Down Expand Up @@ -3111,6 +3113,8 @@ enum cr_only_if_t {
cr_only_if_not_inpage_footnote,
cr_only_if_inside_inpage_footnote,
cr_only_if_not_inside_inpage_footnote,
cr_only_if_line_height_normal,
cr_only_if_not_line_height_normal,
};

static const char * css_cr_apply_func_names[]={
Expand Down Expand Up @@ -5328,6 +5332,27 @@ void LVCssDeclaration::apply( css_style_rec_t * style, const ldomNode * node ) c
return; // don't apply anything more of this declaration to this style
}
}
else if ( only_if == cr_only_if_line_height_normal || only_if == cr_only_if_not_line_height_normal ) {
if ( const ldomNode * parent_node = node->getParentNode(); style->line_height == css_length_t(css_val_inherited, 0) && parent_node ) {
const css_style_ref_t parent_style = node->getParentNode()->getStyle();
if ( !parent_style.isNull() && parent_style->line_height == css_length_t(css_val_unspecified, css_generic_normal) ) {
if ( only_if == cr_only_if_not_line_height_normal )
return; // don't apply anything more of this declaration to this style
}
else {
if ( only_if == cr_only_if_line_height_normal )
return; // don't apply anything more of this declaration to this style
}
}
else if ( style->line_height == css_length_t(css_val_unspecified, css_generic_normal) ) {
if ( only_if == cr_only_if_not_line_height_normal )
return; // don't apply anything more of this declaration to this style
}
else {
if ( only_if == cr_only_if_line_height_normal )
return; // don't apply anything more of this declaration to this style
}
}
}
break;
case cssd_cr_apply_func:
Expand Down

0 comments on commit 3131eb1

Please sign in to comment.