Skip to content

Commit

Permalink
Page splitting: ignore empty non-linear flows
Browse files Browse the repository at this point in the history
If a non-linear flow was created, but we never got
any "line" associated to it, just ignore it and reset
the counter.
(Otherwise, frontend would get holes/nil in the array
of flows, and would get confused.)
  • Loading branch information
poire-z committed May 19, 2024
1 parent aecd39d commit 1d3041e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
4 changes: 3 additions & 1 deletion crengine/include/lvpagesplitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class LVRendPageList : public LVPtrVector<LVRendPageInfo>
public:
LVRendPageList() : has_nonlinear_flows(false) {}
int FindNearestPage( int y, int direction );
void setHasNonLinearFlows() { has_nonlinear_flows=true; }
void setHasNonLinearFlows( bool hasnonlinearflows ) { has_nonlinear_flows = hasnonlinearflows; }
bool hasNonLinearFlows() { return has_nonlinear_flows; }
bool serialize( SerialBuf & buf );
bool deserialize( SerialBuf & buf );
Expand Down Expand Up @@ -412,6 +412,8 @@ class LVRendPageContext
int current_flow;
// maximum flow encountered so far
int max_flow;
// to know if current flow got some lines
bool current_flow_empty;

LVHashTable<lString32, LVFootNoteRef> footNotes;

Expand Down
21 changes: 15 additions & 6 deletions crengine/src/lvpagesplitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static LVRendPageContext * main_context = NULL;
LVRendPageContext::LVRendPageContext(LVRendPageList * pageList, int pageHeight, int docFontSize, bool gatherLines)
: callback(NULL), totalFinalBlocks(0)
, renderedFinalBlocks(0), lastPercent(-1), page_list(pageList), page_h(pageHeight)
, doc_font_size(docFontSize), gather_lines(gatherLines), current_flow(0), max_flow(0)
, doc_font_size(docFontSize), gather_lines(gatherLines), current_flow(0), max_flow(0), current_flow_empty(false)
, footNotes(64), curr_note(NULL)
{
if ( callback ) {
Expand Down Expand Up @@ -157,13 +157,21 @@ void LVRendPageContext::newFlow( bool nonlinear )
{
/// A new non-linear flow gets the next number
/// A new linear flow simply gets appended to flow 0
if ( current_flow > 0 && current_flow_empty ) {
// We created a flow but didn't fill it: have it like it never happened
max_flow--;
if ( page_list )
page_list->setHasNonLinearFlows(max_flow > 0);
current_flow_empty = false;
}
if (nonlinear) {
max_flow++;
current_flow = max_flow;
if ( page_list )
page_list->setHasNonLinearFlows();
max_flow++;
current_flow = max_flow;
current_flow_empty = true;
if ( page_list )
page_list->setHasNonLinearFlows(max_flow > 0);
} else {
current_flow = 0;
current_flow = 0;
}
}

Expand All @@ -177,6 +185,7 @@ void LVRendPageContext::AddLine( int starty, int endy, int flags )
flags |= RN_SPLIT_FOOT_NOTE;
LVRendLineInfo * line = new LVRendLineInfo(starty, endy, flags, current_flow);
lines.add( line );
current_flow_empty = false;
if ( curr_note != NULL ) {
//CRLog::trace("adding line to note (%d)", line->start);
curr_note->addLine( line );
Expand Down

0 comments on commit 1d3041e

Please sign in to comment.