1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-06 03:50:19 +02:00

rtf: \u command support, code cleanup

This commit is contained in:
Nikolay Pultsin 2013-10-03 16:53:03 +01:00
parent 7090f55b9f
commit 223117f595
3 changed files with 16 additions and 3 deletions

View file

@ -6,6 +6,7 @@
* mobi: added support for <div> & <mbp:pagebreak> tags
* ePub: fixed reading of files generated from LibreOffice
* ePub: no empty paragraphs before/after the cover
* RTF: added unicode symbols (\u command) support
* Danish localization done by Jens Kaestel, sponsored by Panacea Supplies
* Danish hyphenation patterns imported by Dennis Sheil of Panacea Supplies
* Added Persian localization by HYIPEDU Team

View file

@ -22,6 +22,7 @@
#include <ZLFile.h>
#include <ZLInputStream.h>
#include <ZLUnicodeUtil.h>
#include "RtfReader.h"
@ -340,7 +341,7 @@ bool RtfReader::parseDocument() {
break;
case READ_KEYWORD:
if (!isalpha(*ptr)) {
if ((ptr == dataStart) && (keyword.empty())) {
if (ptr == dataStart && keyword.empty()) {
if (*ptr == '\'') {
parserState = READ_HEX_SYMBOL;
} else {
@ -351,7 +352,7 @@ bool RtfReader::parseDocument() {
dataStart = ptr + 1;
} else {
keyword.append(dataStart, ptr - dataStart);
if ((*ptr == '-') || isdigit(*ptr)) {
if (*ptr == '-' || isdigit(*ptr)) {
dataStart = ptr;
parserState = READ_KEYWORD_PARAMETER;
} else {
@ -369,9 +370,13 @@ bool RtfReader::parseDocument() {
int parameter = atoi(parameterString.c_str());
parameterString.erase();
readNextChar = *ptr == ' ';
if ((keyword == "bin") && (parameter > 0)) {
if (keyword == "bin" && parameter > 0) {
myBinaryDataSize = parameter;
parserState = READ_BINARY_DATA;
} else if (keyword == "u") {
processUnicodeCharacter(parameter);
readNextChar = true;
parserState = READ_NORMAL_DATA;
} else {
processKeyword(keyword, &parameter);
parserState = READ_NORMAL_DATA;
@ -424,6 +429,12 @@ void RtfReader::processKeyword(const std::string &keyword, int *parameter) {
it->second->run(*this, parameter);
}
void RtfReader::processUnicodeCharacter(int character) {
static char buffer[8];
const int len = ZLUnicodeUtil::ucs4ToUtf8(buffer, character);
processCharData(buffer, len, false);
}
void RtfReader::processCharData(const char *data, std::size_t len, bool convert) {
if (myState.Destination != RtfReader::DESTINATION_SKIP) {
addCharData(data, len, convert);

View file

@ -82,6 +82,7 @@ private:
bool parseDocument();
void processKeyword(const std::string &keyword, int *parameter = 0);
void processCharData(const char *data, std::size_t len, bool convert = true);
void processUnicodeCharacter(int character);
protected:
struct RtfReaderState {