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

Fix ruby alignment, fix one possible crash, ignore empty non-linear flows #565

Merged
merged 4 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cr3gui/data/html5.css
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ sup {
ruby {
display: ruby;
text-align: center;
text-align-last: initial;
text-indent: 0;
}
rb, rubyBox[T=rb] {
Expand Down
4 changes: 4 additions & 0 deletions crengine/include/lvdocview.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ class LVDocView : public CacheLoadingCallback
ldomXPointer m_cursorPos;

lString32 m_pageHeaderOverride;
/// custom page info (curpage / nbpages %) can be set by frontend
lString32 m_pageInfoOverride;

int m_drawBufferBits;

Expand Down Expand Up @@ -422,6 +424,8 @@ class LVDocView : public CacheLoadingCallback
void setDrawBufferBits( int bits ) { m_drawBufferBits = bits; }
/// substitute page header with custom text (e.g. to be used while loading)
void setPageHeaderOverride( lString32 s );
/// substitute page info (curpage / nbpages %) with custom text
void setPageInfoOverride( lString32 s );
/// get screen rectangle for current cursor position, returns false if not visible
bool getCursorRect( lvRect & rc, bool scrollToCursor = false )
{
Expand Down
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
11 changes: 10 additions & 1 deletion crengine/src/lvdocview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,12 @@ void LVDocView::setPageHeaderOverride(lString32 s) {
clearImageCache();
}

/// substitute page info (curpage / nbpages %) with custom text
void LVDocView::setPageInfoOverride(lString32 s) {
m_pageInfoOverride = s;
clearImageCache();
}

/// draw page header to buffer
void LVDocView::drawPageHeader(LVDrawBuf * drawbuf, const lvRect & headerRc,
int pageIndex, int phi, int pageCount) {
Expand Down Expand Up @@ -1872,7 +1878,10 @@ void LVDocView::drawPageHeader(LVDrawBuf * drawbuf, const lvRect & headerRc,
}
}
lString32 pageinfo;
if (pageCount > 0) {
if (!m_pageInfoOverride.empty()) {
pageinfo = m_pageInfoOverride;
}
else if (pageCount > 0) {
if (phi & PGHDR_PAGE_NUMBER)
pageinfo += fmt::decimal( getExternalPageNumber(pageIndex) + 1 );
if (phi & PGHDR_PAGE_COUNT) {
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
10 changes: 6 additions & 4 deletions crengine/src/lvrend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11565,10 +11565,12 @@ void getRenderedWidths(ldomNode * node, int &maxWidth, int &minWidth, int direct
lastSpaceWidth = 0;
int _maxw = 0;
int _minw = 0;
if ( is_img && img_width > 0) {
// Inline img with a fixed width
_maxw = img_width;
_minw = img_width;
if ( is_img ) {
if ( img_width > 0) {
// Inline img with a fixed width
_maxw = img_width;
_minw = img_width;
}
}
else {
// Get the rendered width of the inlineBox
Expand Down
Loading