Skip to content

Commit

Permalink
lvtext: add LTEXT_OBJECT_IS_EMBEDDED_BLOCK
Browse files Browse the repository at this point in the history
To keep things clearer and avoid some function calls.
  • Loading branch information
poire-z committed Apr 23, 2022
1 parent 6fe1411 commit e72540d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 32 deletions.
6 changes: 4 additions & 2 deletions crengine/include/lvtextfm.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ extern "C" {
// Object flags (used when LTEXT_SRC_IS_OBJECT is set)
#define LTEXT_OBJECT_IS_IMAGE 0x0001 // image
#define LTEXT_OBJECT_IS_INLINE_BOX 0x0002 // inlineBox wrapping node
#define LTEXT_OBJECT_IS_FLOAT 0x0004 // float:'ing node
#define LTEXT_OBJECT_IS_FLOAT_DONE 0x0008 // float:'ing node (already dealt with)
#define LTEXT_OBJECT_IS_EMBEDDED_BLOCK 0x0004 // block element among inlines (should also have previous bit LTEXT_OBJECT_IS_INLINE_BOX
// as it is also an inlineBox wrapping node)
#define LTEXT_OBJECT_IS_FLOAT 0x0010 // float:'ing node
#define LTEXT_OBJECT_IS_FLOAT_DONE 0x0020 // float:'ing node (already dealt with)

// Extra LTEXT properties we can request (via these values) and fetch from the node style,
// mostly used for rare inherited CSS properties that don't need us to waste a bit for
Expand Down
22 changes: 9 additions & 13 deletions crengine/src/lvrend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3710,8 +3710,7 @@ void renderFinalBlock( ldomNode * enode, LFormattedText * txform, RenderRectAcce
#ifdef DEBUG_DUMP_ENABLED
logfile << "+INLINEBOX ";
#endif
bool is_embedded_block = enode->isEmbeddedBlockBoxingInlineBox();
if ( is_embedded_block ) {
if ( enode->isEmbeddedBlockBoxingInlineBox() ) {
// If embedded-block wrapper: it should not be part of the lines
// made by the surrounding text/elements: we should ensure a new
// line before and after it.
Expand Down Expand Up @@ -3745,25 +3744,22 @@ void renderFinalBlock( ldomNode * enode, LFormattedText * txform, RenderRectAcce
// These might have no effect, but let's explicitely drop them.
valign_dy = 0;
indent = 0;
txform->AddSourceObject(flags, LTEXT_OBJECT_IS_INLINE_BOX|LTEXT_OBJECT_IS_EMBEDDED_BLOCK, line_h, valign_dy, indent, enode, lang_cfg );
// Let flags unchanged, with their newline/alignment flag as if it
// hadn't been consumed, so it is reported back into baseflags below
// so that the next sibling (or upper followup inline node) starts
// on a new line.
// Note: a space just before or just after (because of a newline in
// the HTML source) should have been removed or included in the
// boxing element - so we shouldn't have any spurious empty line
// in this final block (except it that space is included in some
// other inline element (<span> </span>) in which case, it is
// explicitely expected to generate an empty line.
// We also use LTEXT_OBJECT_IS_INLINE_BOX (no need to waste a bit in
// the lUInt16 for LTEXT_OBJECT_IS_EMBEDDED_BLOCK).
}
// We use the flags computed previously (and not baseflags) as they
// carry vertical alignment
txform->AddSourceObject(flags, LTEXT_OBJECT_IS_INLINE_BOX, line_h, valign_dy, indent, enode, lang_cfg );
if ( is_embedded_block ) {
// Let flags unchanged, with their newline/alignment flag as if it
// hadn't been consumed, so it is reported back into baseflags below
// so that the next sibling (or upper followup inline node) starts
// on a new line.
}
else {
// We use the flags computed previously (and not baseflags) as they
// carry vertical alignment
txform->AddSourceObject(flags, LTEXT_OBJECT_IS_INLINE_BOX, line_h, valign_dy, indent, enode, lang_cfg );
flags &= ~LTEXT_FLAG_NEWLINE & ~LTEXT_SRC_IS_CLEAR_BOTH; // clear newline flag
}
}
Expand Down
23 changes: 6 additions & 17 deletions crengine/src/lvtextfm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4627,26 +4627,15 @@ class LVFormatter {
// We do not need to go thru processParagraph() to handle an embedded block
// (bogus block element children of an inline element): we have a dedicated
// handler for it.
bool isEmbeddedBlock = false;
if ( i == start + 1 ) {
if ( i == start + 1 && m_pbuffer->srctext[start].flags & LTEXT_SRC_IS_OBJECT
&& m_pbuffer->srctext[start].o.objflags & LTEXT_OBJECT_IS_EMBEDDED_BLOCK ) {
// Embedded block among inlines had been surrounded by LTEXT_FLAG_NEWLINE,
// so we'll get one standalone here.
if ( m_pbuffer->srctext[start].flags & LTEXT_SRC_IS_OBJECT
&& m_pbuffer->srctext[start].o.objflags & LTEXT_OBJECT_IS_INLINE_BOX ) {
// We used LTEXT_OBJECT_IS_INLINE_BOX for embedded blocks too (to not
// waste a bit in the lUInt16 for LTEXT_OBJECT_IS_EMBEDDED_BLOCK that
// we would only be using here), so do this check to see if it
// really is an embedded block.
ldomNode * node = (ldomNode *) m_pbuffer->srctext[start].object;
if ( node->isEmbeddedBlockBoxingInlineBox() ) {
isEmbeddedBlock = true;
}
}
}
if ( isEmbeddedBlock )
processEmbeddedBlock( start );
else
}
else {
processParagraph( start, i, isLastPara );
}
start = i;
}
}
Expand Down Expand Up @@ -5173,7 +5162,7 @@ void LFormattedText::Draw( LVDrawBuf * buf, int x, int y, ldomMarkedRangeList *
getAbsMarksFromMarks(marks, absmarks, node);
absmarks_update_needed = false;
}
if ( node->isEmbeddedBlockBoxingInlineBox() ) {
if ( srcline->o.objflags & LTEXT_OBJECT_IS_EMBEDDED_BLOCK ) {
// With embedded blocks, we shouldn't drop the clip (as we do next
// for regular inline-block boxes)
DrawDocument( *buf, node, x0, y0, dx, dy, doc_x, doc_y, page_height, absmarks, bookmarks );
Expand Down

0 comments on commit e72540d

Please sign in to comment.