From 4e18c888b159af48bed5ef5f1ebef80e48cd494a Mon Sep 17 00:00:00 2001 From: "Felix (xq) Queißner" Date: Mon, 8 Mar 2021 00:46:03 +0100 Subject: New HTML rendering via HTML code generation. --- src/renderers/htmlrenderer.cpp | 311 +++++++++++++---------------------------- 1 file changed, 100 insertions(+), 211 deletions(-) (limited to 'src/renderers/htmlrenderer.cpp') diff --git a/src/renderers/htmlrenderer.cpp b/src/renderers/htmlrenderer.cpp index 48f4709..351b0e1 100644 --- a/src/renderers/htmlrenderer.cpp +++ b/src/renderers/htmlrenderer.cpp @@ -6,6 +6,7 @@ #include #include +#include #include static void* malloc_wrapper(void*, size_t size) { return malloc(size); } @@ -62,11 +63,15 @@ static const char* find_title(const GumboNode* root) { struct RenderState { - QTextCursor cursor; - TextStyleInstance text_style; + QString & stream; QUrl root_url; - DocumentStyle const * style; - DocumentOutlineModel * outline; + DocumentOutlineModel & outline; + + //! when non-null, we're inside a header element and accumulate the text to + //! compute the outline. + QString * header_text; + + int header_count; }; static char const * getAttribute(GumboElement const & element, char const * attrib_name) @@ -80,32 +85,6 @@ static char const * getAttribute(GumboElement const & element, char const * attr return nullptr; } -struct TextFormatReset -{ - QTextCursor * cursor; - - QTextCharFormat char_format; - QTextBlockFormat block_format; - - TextFormatReset(QTextCursor * cursor) : - cursor(cursor), - char_format(cursor->charFormat()), - block_format(cursor->blockFormat()) - { - - } - - TextFormatReset(TextFormatReset const &) = delete; - TextFormatReset(TextFormatReset &&) = delete; - - ~TextFormatReset() - { - this->cursor->setCharFormat(this->char_format); - this->cursor->setBlockFormat(this->block_format); - } - -}; - // Problems: // Style/theme elements must use a push/pop // use instead of "replacing" styles @@ -114,8 +93,8 @@ struct TextFormatReset static void renderRecursive(RenderState & state, GumboNode const & node, int nesting = 0) { - auto & cursor = state.cursor; - auto & text_style = state.text_style; + auto & stream = state.stream; + auto & outline = state.outline; switch(node.type) { /** Document node. v will be a GumboDocument. */ @@ -123,154 +102,82 @@ static void renderRecursive(RenderState & state, GumboNode const & node, int nes qWarning() << "Detected embedded document"; } - /** Element node. v will be a GumboElement. */ + /** Element node.v will be a GumboElement. */ case GUMBO_NODE_ELEMENT: { auto const & element = node.v.element; - TextFormatReset format_reset { &cursor }; - // qDebug() << "begin node(" << gumbo_normalized_tagname(element.tag) << ")"; + bool process_header = false; + QString header_text; + switch(element.tag) { // Stripped tags case GUMBO_TAG_STYLE: case GUMBO_TAG_SCRIPT: + case GUMBO_TAG_UNKNOWN: + return; + + case GUMBO_TAG_BR: + stream += "
"; + return; + + case GUMBO_TAG_HR: + // HACK: stream += "

                                                                                                                                                        
 

"; + stream += "
"; return; case GUMBO_TAG_NAV: { // TODO: Optionally strip navigation from sites - if(true) - return; + //if(true) + // return; + stream += "