From 223e67e503c0b5633ec5e8aa86692268ad22ea5b Mon Sep 17 00:00:00 2001 From: shenleban tongying Date: Sat, 15 Apr 2023 04:45:57 -0400 Subject: [PATCH] feat(stardict): Display images from `img:` in resource file list See Type identifiers -> 'r' at http://www.huzheng .org/stardict/StarDictFileFormat --- stardict.cc | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/stardict.cc b/stardict.cc index d12faef7..961cbeca 100644 --- a/stardict.cc +++ b/stardict.cc @@ -445,6 +445,8 @@ private: string StardictDictionary::handleResource( char type, char const * resource, size_t size ) { QString text; + + // See "Type identifiers" at http://www.huzheng.org/stardict/StarDictFileFormat switch( type ) { case 'x': // Xdxf content @@ -590,8 +592,24 @@ string StardictDictionary::handleResource( char type, char const * resource, siz case 'n': // WordNet data. We don't know anything about it. return "
" + Html::escape( string( resource, size ) ) + "
"; - case 'r': // Resource file list. For now, resources aren't handled. - return "
" + Html::escape( string( resource, size ) ) + "
"; + case 'r': // Resource file list. For now, only img: is handled. + { + string result = R"(
)"; + + // Handle img:example.jpg + QString imgTemplate( R"()" ); + + for ( const auto & file : QString::fromUtf8( resource, size ).simplified().split( " " ) ) { + if ( file.startsWith( "img:" ) ) { + result += imgTemplate.arg( file.right( file.size() - file.indexOf( ":" ) - 1 ) ).toStdString(); + } + else { + result += Html::escape( file.toStdString() ); + } + } + + return result + "
"; + } case 'W': // An embedded Wav file. Unhandled yet. return "
(an embedded .wav file)
";