Skip to content

Commit

Permalink
lvtext: tweak object flags implementation
Browse files Browse the repository at this point in the history
We have room in src_text_fragment_t in the union struct
used for objects, so put object-only flags in there,
leaving more bits available in the 'flags' field shared
by object (image, inline-block, floats) and text fragments.
(This is just reorganisation, no rendering change.)
  • Loading branch information
poire-z committed Apr 23, 2022
1 parent e6de204 commit d6564c3
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 105 deletions.
17 changes: 12 additions & 5 deletions crengine/include/lvtextfm.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,10 @@ extern "C" {
#define LTEXT_LOCKED_SPACING 0x00040000 // regular spaces should not change width with text justification
#define LTEXT_HYPHENATE 0x00080000 // allow hyphenation

// Source object type (when source is not a text node)
#define LTEXT_SRC_IS_OBJECT 0x00100000 // object (image)
#define LTEXT_SRC_IS_INLINE_BOX 0x00200000 // inlineBox wrapping node
#define LTEXT_SRC_IS_FLOAT 0x00400000 // float:'ing node
#define LTEXT_SRC_IS_FLOAT_DONE 0x00800000 // float:'ing node (already dealt with)
#define LTEXT_SRC_IS_OBJECT 0x00100000 // Source is not a text node
#define LTEXT__AVAILABLE_BIT_22__ 0x00200000
#define LTEXT__AVAILABLE_BIT_23__ 0x00400000
#define LTEXT__AVAILABLE_BIT_24__ 0x00800000
// "clear" handling
#define LTEXT_SRC_IS_CLEAR_RIGHT 0x01000000 // text follows <BR style="clear: right">
#define LTEXT_SRC_IS_CLEAR_LEFT 0x02000000 // text follows <BR style="clear: left">
Expand All @@ -86,6 +85,11 @@ extern "C" {
#define LTEXT__AVAILABLE_BIT_31__ 0x40000000
#define LTEXT_LEGACY_RENDERING 0x80000000 // Legacy text rendering tweaks

// 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)

// 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 Expand Up @@ -129,6 +133,7 @@ typedef struct
} t;
struct {
// (Note: width & height will be stored negative when they are in % unit)
lUInt16 objflags; /**< \brief object flags */
lInt16 width; /**< \brief width of image or inline-block-box */
lInt16 height; /**< \brief height of image or inline-block box */
lUInt16 baseline; /**< \brief baseline of inline-block box */
Expand Down Expand Up @@ -361,6 +366,7 @@ void lvtextAddSourceObject(
lInt16 width,
lInt16 height,
lUInt32 flags, /* flags */
lUInt16 objflags, /* object flags */
lInt16 interval, /* line height in screen pixels */
lInt16 valign_dy, /* drift y from baseline */
lInt16 indent, /* first line indent (or all but first, when negative) */
Expand Down Expand Up @@ -421,6 +427,7 @@ class LFormattedText

void AddSourceObject(
lUInt32 flags, /* flags */
lUInt16 objflags, /* object flags */
lInt16 interval, /* line height in screen pixels */
lInt16 valign_dy, /* drift y from baseline */
lInt16 indent, /* first line indent (or all but first, when negative) */
Expand Down
12 changes: 6 additions & 6 deletions crengine/src/lvrend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3118,7 +3118,7 @@ void renderFinalBlock( ldomNode * enode, LFormattedText * txform, RenderRectAcce
// be guessed and renderBlockElement() called to render it
// and get is height, so LFormattedText knows how to render
// this erm_final text around it.
txform->AddSourceObject(baseflags|LTEXT_SRC_IS_FLOAT, line_h, valign_dy, indent, enode, lang_cfg );
txform->AddSourceObject(baseflags, LTEXT_OBJECT_IS_FLOAT, line_h, valign_dy, indent, enode, lang_cfg );
baseflags &= ~LTEXT_FLAG_NEWLINE & ~LTEXT_SRC_IS_CLEAR_BOTH; // clear newline flag
return;
}
Expand Down Expand Up @@ -3684,7 +3684,7 @@ void renderFinalBlock( ldomNode * enode, LFormattedText * txform, RenderRectAcce
for ( int i=0; i<lines.length(); i++ )
txform->AddSourceLine( lines[i].c_str(), lines[i].length(), cl, bgcl, font.get(), lang_cfg, flags|LTEXT_FLAG_OWNTEXT, line_h, valign_dy, 0, enode );
}
txform->AddSourceObject(flags, line_h, valign_dy, indent, enode, lang_cfg );
txform->AddSourceObject(flags, LTEXT_OBJECT_IS_IMAGE, line_h, valign_dy, indent, enode, lang_cfg );
title = enode->getAttributeValue(attr_subtitle);
if ( !title.empty() ) {
lString32Collection lines;
Expand All @@ -3702,7 +3702,7 @@ void renderFinalBlock( ldomNode * enode, LFormattedText * txform, RenderRectAcce
} else { // inline image
// We use the flags computed previously (and not baseflags) as they
// carry vertical alignment
txform->AddSourceObject(flags, line_h, valign_dy, indent, enode, lang_cfg );
txform->AddSourceObject(flags, LTEXT_OBJECT_IS_IMAGE, line_h, valign_dy, indent, enode, lang_cfg );
flags &= ~LTEXT_FLAG_NEWLINE & ~LTEXT_SRC_IS_CLEAR_BOTH; // clear newline flag
}
}
Expand Down Expand Up @@ -3751,12 +3751,12 @@ void renderFinalBlock( ldomNode * enode, LFormattedText * txform, RenderRectAcce
// 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_SRC_IS_INLINE_BOX (no need to waste a bit in
// the lUInt32 for LTEXT_SRC_IS_EMBEDDED_BLOCK).
// 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_SRC_IS_INLINE_BOX, line_h, valign_dy, indent, enode, lang_cfg );
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
Expand Down
Loading

0 comments on commit d6564c3

Please sign in to comment.