diff --git a/generators/chm/generator_chm.cpp b/generators/chm/generator_chm.cpp index 4913f46..ed0ff1e 100644 --- a/generators/chm/generator_chm.cpp +++ b/generators/chm/generator_chm.cpp @@ -185,6 +185,13 @@ void CHMGenerator::slotCompleted() if (!m_request) return; + if( m_syncGen->encoding() == QStringLiteral("ISO-8859-1") ) { + const QTextCodec *txt_codec = m_file->currentTextCodec(); + if( txt_codec ) { + m_syncGen->setEncoding(QLatin1String(txt_codec->name()), true); + } + } + QImage image(m_request->width(), m_request->height(), QImage::Format_ARGB32); image.fill(Qt::white); --- a/generators/chm/lib/ebook.h +++ b/generators/chm/lib/ebook.h @@ -211,6 +211,14 @@ public: virtual bool setCurrentEncoding(const char *encoding) = 0; /*! + * \brief Gets the current text codec or 0 if absent + * \return The current text codec. + * + * \ingroup encoding + */ + virtual const QTextCodec * currentTextCodec() const = 0; + + /*! * \brief Checks if this kind of URL is supported by the ebook format (i.e. could be passed to ebook functions) * \param url The url to check */ diff --git a/generators/chm/lib/ebook_chm.cpp b/generators/chm/lib/ebook_chm.cpp index 732d29f..65f438f 100644 --- a/generators/chm/lib/ebook_chm.cpp +++ b/generators/chm/lib/ebook_chm.cpp @@ -817,6 +817,11 @@ bool EBook_CHM::setCurrentEncoding( const char * encoding ) return changeFileEncoding( encoding ); } +const QTextCodec * EBook_CHM::currentTextCodec( ) const +{ + return m_textCodec; +} + bool EBook_CHM::isSupportedUrl(const QUrl &url) { return url.scheme() == URL_SCHEME_CHM; --- a/generators/chm/lib/ebook_chm.h +++ b/generators/chm/lib/ebook_chm.h @@ -173,6 +173,14 @@ public: bool setCurrentEncoding(const char *encoding) override; /*! + * \brief Gets the current CHM archive text codec or 0 if absent + * \return The current text codec. + * + * \ingroup encoding + */ + const QTextCodec * currentTextCodec() const; + + /*! * \brief Checks if this kind of URL is supported by the ebook format (i.e. could be passed to ebook functions) * \param url The url to check */ diff --git a/generators/chm/lib/ebook_epub.cpp b/generators/chm/lib/ebook_epub.cpp index 83a7773..3a4339a 100644 --- a/generators/chm/lib/ebook_epub.cpp +++ b/generators/chm/lib/ebook_epub.cpp @@ -169,6 +169,12 @@ bool EBook_EPUB::setCurrentEncoding(const char *) abort(); } +const QTextCodec * EBook_EPUB::currentTextCodec( ) const +{ + return nullptr; +} + + bool EBook_EPUB::isSupportedUrl(const QUrl &url) { return url.scheme() == URL_SCHEME_EPUB; --- a/generators/chm/lib/ebook_epub.h +++ b/generators/chm/lib/ebook_epub.h @@ -162,6 +162,14 @@ public: bool setCurrentEncoding(const char *encoding) override; /*! + * \brief Gets the current text codec or 0 if absent + * \return The current text codec. + * + * \ingroup encoding + */ + virtual const QTextCodec * currentTextCodec() const; + + /*! * \brief Checks if this kind of URL is supported by the ebook format (i.e. could be passed to ebook functions) * \param url The url to check */