Skip to content

Commit

Permalink
Strut confining: don't when there is no strut
Browse files Browse the repository at this point in the history
List item markers with "list-style-position: outside" don't
have any strut set: the arithmetic with a strut height of 0
could cause clipping issues with in-page footnotes.
  • Loading branch information
poire-z committed Jul 19, 2020
1 parent a61773e commit c9faa83
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions crengine/src/lvtextfm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ class LVFormatter {
bool m_has_float_to_position;
bool m_has_ongoing_float;
bool m_no_clear_own_floats;
bool m_allow_strut_confinning;
bool m_allow_strut_confining;
bool m_has_multiple_scripts;
bool m_indent_first_line_done;
int m_indent_after_first_line;
Expand Down Expand Up @@ -960,10 +960,7 @@ class LVFormatter {
}
#endif

// Whether any "-cr-hint: strut-confined" should be applied: only when
// we have non-space-only text in the paragraph - standalone images
// possibly separated by spaces don't need to be reduced in size.
m_allow_strut_confinning = false;
bool has_non_space = false; // If we have non-empty text, we can do strut confining

int pos = 0;
int i;
Expand Down Expand Up @@ -1242,8 +1239,7 @@ class LVFormatter {
last_non_collapsed_space_pos = -1;
is_locked_spacing = false;
if ( !is_space ) {
// Non empty text, we can do strut confinning
m_allow_strut_confinning = true;
has_non_space = true;
}
}
prev_was_space = is_space || (c == '\n');
Expand Down Expand Up @@ -1425,6 +1421,13 @@ class LVFormatter {
}
TR("%s", LCSTR(lString16(m_text, m_length)));

// Whether any "-cr-hint: strut-confined" should be applied: only when
// we have non-space-only text in the paragraph - standalone images
// possibly separated by spaces don't need to be reduced in size.
// And only when we actually have a strut set (list item markers
// with "list-style-position: outside" don't have any set).
m_allow_strut_confining = has_non_space && m_pbuffer->strut_height > 0;

#if (USE_FRIBIDI==1)
if ( has_rtl ) {
// Trust the direction determined by renderBlockElementEnhanced() from the
Expand Down Expand Up @@ -2000,7 +2003,7 @@ class LVFormatter {
UnicodeToLocal(ldomXPointer((ldomNode*)m_srcs[start]->object, 0).toString()).c_str());
*/
resizeImage(width, height, m_pbuffer->width, m_max_img_height, m_length>1);
if ( (m_srcs[start]->flags & LTEXT_STRUT_CONFINED) && m_allow_strut_confinning ) {
if ( (m_srcs[start]->flags & LTEXT_STRUT_CONFINED) && m_allow_strut_confining ) {
// Text with "-cr-hint: strut-confined" might just be vertically shifted,
// but won't change widths. But images who will change height must also
// have their width reduced to keep their aspect ratio.
Expand Down Expand Up @@ -2807,7 +2810,7 @@ class LVFormatter {
bool adjust_line_box = true;
// We will make sure elements with "-cr-hint: strut-confined"
// do not change the strut baseline and height
bool strut_confined = (srcline->flags & LTEXT_STRUT_CONFINED) && m_allow_strut_confinning;
bool strut_confined = (srcline->flags & LTEXT_STRUT_CONFINED) && m_allow_strut_confining;

if ( srcline->flags & LTEXT_SRC_IS_OBJECT ) {
// object: image or inline-block box (floats have been skipped above)
Expand All @@ -2830,7 +2833,7 @@ class LVFormatter {
else { // image
word->flags = LTEXT_WORD_IS_OBJECT;
// The image dimensions have already been resized to fit
// into m_pbuffer->width (and strut confinning if requested.
// into m_pbuffer->width (and strut confining if requested.
// Note: it can happen when there is some text-indent than
// the image width exceeds the available width: it might be
// shown overflowing or overrideing other content.
Expand Down

0 comments on commit c9faa83

Please sign in to comment.