diff --git a/crengine/include/lvtinydom.h b/crengine/include/lvtinydom.h index 6d1ae1b95..6f6ebd1cd 100755 --- a/crengine/include/lvtinydom.h +++ b/crengine/include/lvtinydom.h @@ -2456,6 +2456,10 @@ class ldomDocumentFragmentWriter : public LVXMLParserCallback lString8 headStyleText; int headStyleState; + lString16 htmlDir; + lString16 htmlLang; + bool insideHtmlTag; + public: /// return content of html/head/style element @@ -2486,6 +2490,9 @@ class ldomDocumentFragmentWriter : public LVXMLParserCallback insideTag = false; headStyleText.clear(); headStyleState = 0; + insideHtmlTag = false; + htmlDir.clear(); + htmlLang.clear(); } /// called on parsing end virtual void OnStop() @@ -2525,7 +2532,8 @@ class ldomDocumentFragmentWriter : public LVXMLParserCallback /// constructor ldomDocumentFragmentWriter( LVXMLParserCallback * parentWriter, lString16 baseTagName, lString16 baseTagReplacementName, lString16 fragmentFilePath ) : parent(parentWriter), baseTag(baseTagName), baseTagReplacement(baseTagReplacementName), - insideTag(false), styleDetectionState(0), pathSubstitutions(100), baseElement(NULL), lastBaseElement(NULL), headStyleState(0) + insideTag(false), styleDetectionState(0), pathSubstitutions(100), baseElement(NULL), lastBaseElement(NULL), + headStyleState(0), insideHtmlTag(false) { setCodeBase( fragmentFilePath ); } diff --git a/crengine/src/lvtinydom.cpp b/crengine/src/lvtinydom.cpp index 705bf2e74..c5119beb5 100644 --- a/crengine/src/lvtinydom.cpp +++ b/crengine/src/lvtinydom.cpp @@ -10043,7 +10043,15 @@ void ldomDocumentFragmentWriter::OnAttribute( const lChar16 * nsname, const lCha parent->OnAttribute(nsname, attrname, attrvalue); } } else { - if ( styleDetectionState ) { + if (insideHtmlTag) { + // Grab attributes from (not included in the DOM) + // to reinject them in + if ( !lStr_cmp(attrname, "dir") ) + htmlDir = attrvalue; + else if ( !lStr_cmp(attrname, "lang") ) + htmlLang = attrvalue; + } + else if ( styleDetectionState ) { if ( !lStr_cmp(attrname, "rel") && lString16(attrvalue).lowercase() == L"stylesheet" ) styleDetectionState |= 2; else if ( !lStr_cmp(attrname, "type") ) { @@ -10079,8 +10087,13 @@ ldomNode * ldomDocumentFragmentWriter::OnTagOpen( const lChar16 * nsname, const } else { if ( !lStr_cmp(tagname, "link") ) styleDetectionState = 1; - if ( !lStr_cmp(tagname, "style") ) + else if ( !lStr_cmp(tagname, "style") ) headStyleState = 1; + else if ( !lStr_cmp(tagname, "html") ) { + insideHtmlTag = true; + htmlDir.clear(); + htmlLang.clear(); + } } // When meeting the of each of an EPUB's embedded HTML files, @@ -10115,6 +10128,11 @@ ldomNode * ldomDocumentFragmentWriter::OnTagOpen( const lChar16 * nsname, const } if ( !codeBasePrefix.empty() ) // add attribute OnAttribute(L"", L"id", codeBasePrefix.c_str() ); + if ( !htmlDir.empty() ) // add attribute tag + parent->OnAttribute(L"", L"dir", htmlDir.c_str() ); + if ( !htmlLang.empty() ) // add attribute tag + parent->OnAttribute(L"", L"lang", htmlLang.c_str() ); + parent->OnTagBody(); // inside if ( !headStyleText.empty() || stylesheetLinks.length() > 0 ) { // add stylesheet element as child of : @@ -10178,6 +10196,9 @@ void ldomDocumentFragmentWriter::OnTagBody() if ( insideTag ) { parent->OnTagBody(); } + else if ( insideHtmlTag ) { + insideHtmlTag = false; + } if ( styleDetectionState == 11 ) { // incomplete ; assuming type="text/css" if ( !stylesheetFile.empty() )