diff --git a/aard.cc b/aard.cc index e33936f7..502e4298 100644 --- a/aard.cc +++ b/aard.cc @@ -287,7 +287,8 @@ private: /// Loads the article. void loadArticle( quint32 address, - string & articleText ); + string & articleText, + bool rawText = false ); string convert( string const & in_data ); friend class AardArticleRequest; @@ -411,7 +412,8 @@ string AardDictionary::convert( const string & in ) } void AardDictionary::loadArticle( quint32 address, - string & articleText ) + string & articleText, + bool rawText ) { quint32 articleOffset = address; quint32 articleSize; @@ -509,7 +511,12 @@ void AardDictionary::loadArticle( quint32 address, } if( !articleText.empty() ) + { + if( rawText ) + return; + articleText = convert( articleText ); + } else articleText = string( QObject::tr( "Article decoding error" ).toUtf8().constData() ); diff --git a/zim.cc b/zim.cc index 915a0c2a..ebe5b3a4 100644 --- a/zim.cc +++ b/zim.cc @@ -321,6 +321,8 @@ bool indexIsOldOrBad( string const & indexFile ) quint32 readArticle( ZimFile & file, ZIM_header & header, quint32 articleNumber, string & result, set< quint32 > * loadedArticles = NULL ) { + result.clear(); + while( 1 ) { if( articleNumber >= header.articleCount ) @@ -409,7 +411,6 @@ quint32 readArticle( ZimFile & file, ZIM_header & header, quint32 articleNumber, memcpy( offsets, decompressedData.data() + artEntry.blobNumber * 4, sizeof(offsets) ); quint32 size = offsets[ 1 ] - offsets[ 0 ]; - result.clear(); result.append( decompressedData, offsets[ 0 ], size ); return articleNumber; @@ -496,7 +497,8 @@ private: /// Loads the article. quint32 loadArticle( quint32 address, string & articleText, - set< quint32 > * loadedArticles ); + set< quint32 > * loadedArticles, + bool rawText = false ); string convert( string const & in_data ); friend class ZimArticleRequest; @@ -589,14 +591,16 @@ void ZimDictionary::loadIcon() throw() quint32 ZimDictionary::loadArticle( quint32 address, string & articleText, - set< quint32 > * loadedArticles ) + set< quint32 > * loadedArticles, + bool rawText ) { quint32 ret; { Mutex::Lock _( zimMutex ); ret = readArticle( df, zimHeader, address, articleText, loadedArticles ); } - articleText = convert( articleText ); + if( !rawText ) + articleText = convert( articleText ); return ret; } @@ -808,7 +812,7 @@ void ZimDictionary::getArticleText( uint32_t articleAddress, QString & headword, headword.clear(); string articleText; - loadArticle( articleAddress, articleText, 0 ); + loadArticle( articleAddress, articleText, 0, true ); text = Html::unescape( QString::fromUtf8( articleText.data(), articleText.size() ) ); } catch( std::exception &ex ) @@ -826,7 +830,7 @@ quint32 ZimDictionary::getArticleText( uint32_t articleAddress, QString & headwo headword.clear(); string articleText; - articleNumber = loadArticle( articleAddress, articleText, loadedArticles ); + articleNumber = loadArticle( articleAddress, articleText, loadedArticles, true ); text = Html::unescape( QString::fromUtf8( articleText.data(), articleText.size() ) ); } catch( std::exception &ex )