mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
better RTF encoding detection; don't fail on RTF files with .doc extension; fixed XML serialisation
This commit is contained in:
parent
a6c8ead2bf
commit
7e9d47bba9
5 changed files with 84 additions and 33 deletions
|
@ -34,23 +34,16 @@ bool RtfPlugin::providesMetainfo() const {
|
|||
}
|
||||
|
||||
const std::string RtfPlugin::supportedFileType() const {
|
||||
return "rtf";
|
||||
return "RTF";
|
||||
}
|
||||
|
||||
bool RtfPlugin::readMetainfo(Book &book) const {
|
||||
readLanguageAndEncoding(book);
|
||||
|
||||
if (!RtfDescriptionReader(book).readDocument(book.file())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (book.encoding().empty()) {
|
||||
book.setEncoding(ZLEncodingConverter::UTF8);
|
||||
} else if (book.language().empty()) {
|
||||
shared_ptr<ZLInputStream> stream = new RtfReaderStream(book.file(), 50000);
|
||||
if (!stream.isNull()) {
|
||||
detectLanguage(book, *stream, book.encoding());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -64,5 +57,19 @@ bool RtfPlugin::readModel(BookModel &model) const {
|
|||
}
|
||||
|
||||
bool RtfPlugin::readLanguageAndEncoding(Book &book) const {
|
||||
if (book.encoding().empty()) {
|
||||
shared_ptr<ZLInputStream> stream = new RtfReaderStream(book.file(), 50000);
|
||||
if (!stream.isNull()) {
|
||||
detectEncodingAndLanguage(book, *stream);
|
||||
}
|
||||
if (book.encoding().empty()) {
|
||||
book.setEncoding(ZLEncodingConverter::UTF8);
|
||||
}
|
||||
} else if (book.language().empty()) {
|
||||
shared_ptr<ZLInputStream> stream = new RtfReaderStream(book.file(), 50000);
|
||||
if (!stream.isNull()) {
|
||||
detectLanguage(book, *stream, book.encoding());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue