mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
RTF images support: finished
This commit is contained in:
parent
cbcfe14f18
commit
4d90732a37
3 changed files with 31 additions and 15 deletions
|
@ -38,6 +38,9 @@ RtfReader::~RtfReader() {
|
||||||
RtfCommand::~RtfCommand() {
|
RtfCommand::~RtfCommand() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RtfDummyCommand::run(RtfReader&, int*) const {
|
||||||
|
}
|
||||||
|
|
||||||
void RtfNewParagraphCommand::run(RtfReader &reader, int*) const {
|
void RtfNewParagraphCommand::run(RtfReader &reader, int*) const {
|
||||||
reader.newParagraph();
|
reader.newParagraph();
|
||||||
}
|
}
|
||||||
|
@ -96,6 +99,7 @@ void RtfDestinationCommand::run(RtfReader &reader, int*) const {
|
||||||
reader.myState.Destination = myDestination;
|
reader.myState.Destination = myDestination;
|
||||||
if (myDestination == RtfReader::DESTINATION_PICTURE) {
|
if (myDestination == RtfReader::DESTINATION_PICTURE) {
|
||||||
reader.myState.ReadDataAsHex = true;
|
reader.myState.ReadDataAsHex = true;
|
||||||
|
reader.myNextImageMimeType.clear();
|
||||||
}
|
}
|
||||||
reader.switchDestination(myDestination, true);
|
reader.switchDestination(myDestination, true);
|
||||||
}
|
}
|
||||||
|
@ -158,6 +162,7 @@ void RtfReader::fillKeywordMap() {
|
||||||
for (const char **i = keywordsToSkip; *i != 0; ++i) {
|
for (const char **i = keywordsToSkip; *i != 0; ++i) {
|
||||||
addAction(*i, skipCommand);
|
addAction(*i, skipCommand);
|
||||||
}
|
}
|
||||||
|
addAction("shppict", new RtfDummyCommand());
|
||||||
addAction("info", new RtfDestinationCommand(RtfReader::DESTINATION_INFO));
|
addAction("info", new RtfDestinationCommand(RtfReader::DESTINATION_INFO));
|
||||||
addAction("title", new RtfDestinationCommand(RtfReader::DESTINATION_TITLE));
|
addAction("title", new RtfDestinationCommand(RtfReader::DESTINATION_TITLE));
|
||||||
addAction("author", new RtfDestinationCommand(RtfReader::DESTINATION_AUTHOR));
|
addAction("author", new RtfDestinationCommand(RtfReader::DESTINATION_AUTHOR));
|
||||||
|
@ -260,8 +265,10 @@ bool RtfReader::parseDocument() {
|
||||||
dataStart = ptr + 1;
|
dataStart = ptr + 1;
|
||||||
|
|
||||||
if (imageStartOffset >= 0) {
|
if (imageStartOffset >= 0) {
|
||||||
int imageSize = myStream->offset() + (ptr - end) - imageStartOffset;
|
if (!myNextImageMimeType.empty()) {
|
||||||
insertImage(myNextImageMimeType, myFileName, imageStartOffset, imageSize);
|
const int imageSize = myStream->offset() + (ptr - end) - imageStartOffset;
|
||||||
|
insertImage(myNextImageMimeType, myFileName, imageStartOffset, imageSize);
|
||||||
|
}
|
||||||
imageStartOffset = -1;
|
imageStartOffset = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,7 +406,7 @@ bool RtfReader::parseDocument() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RtfReader::processKeyword(const std::string &keyword, int *parameter) {
|
void RtfReader::processKeyword(const std::string &keyword, int *parameter) {
|
||||||
bool wasSpecialMode = mySpecialMode;
|
const bool wasSpecialMode = mySpecialMode;
|
||||||
mySpecialMode = false;
|
mySpecialMode = false;
|
||||||
if (myState.Destination == RtfReader::DESTINATION_SKIP) {
|
if (myState.Destination == RtfReader::DESTINATION_SKIP) {
|
||||||
return;
|
return;
|
||||||
|
@ -408,15 +415,15 @@ void RtfReader::processKeyword(const std::string &keyword, int *parameter) {
|
||||||
std::map<std::string, RtfCommand*>::const_iterator it = ourKeywordMap.find(keyword);
|
std::map<std::string, RtfCommand*>::const_iterator it = ourKeywordMap.find(keyword);
|
||||||
|
|
||||||
if (it == ourKeywordMap.end()) {
|
if (it == ourKeywordMap.end()) {
|
||||||
if (wasSpecialMode)
|
if (wasSpecialMode) {
|
||||||
myState.Destination = RtfReader::DESTINATION_SKIP;
|
myState.Destination = RtfReader::DESTINATION_SKIP;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
it->second->run(*this, parameter);
|
it->second->run(*this, parameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void RtfReader::processCharData(const char *data, size_t len, bool convert) {
|
void RtfReader::processCharData(const char *data, size_t len, bool convert) {
|
||||||
if (myState.Destination != RtfReader::DESTINATION_SKIP) {
|
if (myState.Destination != RtfReader::DESTINATION_SKIP) {
|
||||||
addCharData(data, len, convert);
|
addCharData(data, len, convert);
|
||||||
|
|
|
@ -130,6 +130,11 @@ public:
|
||||||
virtual void run(RtfReader &reader, int *parameter) const = 0;
|
virtual void run(RtfReader &reader, int *parameter) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class RtfDummyCommand : public RtfCommand {
|
||||||
|
public:
|
||||||
|
void run(RtfReader &reader, int *parameter) const;
|
||||||
|
};
|
||||||
|
|
||||||
class RtfNewParagraphCommand : public RtfCommand {
|
class RtfNewParagraphCommand : public RtfCommand {
|
||||||
public:
|
public:
|
||||||
void run(RtfReader &reader, int *parameter) const;
|
void run(RtfReader &reader, int *parameter) const;
|
||||||
|
|
|
@ -50,12 +50,14 @@ public class HexInputStream extends InputStream {
|
||||||
++skipped;
|
++skipped;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fillBuffer();
|
if (skipped < 2 * n) {
|
||||||
available = myBufferLength;
|
fillBuffer();
|
||||||
if (available == -1) {
|
available = myBufferLength;
|
||||||
return skipped / 2;
|
if (available == -1) {
|
||||||
|
return skipped / 2;
|
||||||
|
}
|
||||||
|
offset = 0;
|
||||||
}
|
}
|
||||||
offset = 0;
|
|
||||||
}
|
}
|
||||||
myBufferLength = available;
|
myBufferLength = available;
|
||||||
myBufferOffset = offset;
|
myBufferOffset = offset;
|
||||||
|
@ -103,12 +105,14 @@ public class HexInputStream extends InputStream {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fillBuffer();
|
if (ready < len) {
|
||||||
available = myBufferLength;
|
fillBuffer();
|
||||||
if (available == -1) {
|
available = myBufferLength;
|
||||||
return ready == 0 ? -1 : ready;
|
if (available == -1) {
|
||||||
|
return ready == 0 ? -1 : ready;
|
||||||
|
}
|
||||||
|
offset = 0;
|
||||||
}
|
}
|
||||||
offset = 0;
|
|
||||||
}
|
}
|
||||||
myBufferLength = available;
|
myBufferLength = available;
|
||||||
myBufferOffset = offset;
|
myBufferOffset = offset;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue