mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
DocPlugin: setting default paragraph alignment if it's not specified + little bit of refactoring
This commit is contained in:
parent
51ed7d79b5
commit
813ff0f64b
8 changed files with 277 additions and 258 deletions
|
@ -47,10 +47,10 @@ bool DocBookReader::readBook() {
|
||||||
if (stream.isNull()) {
|
if (stream.isNull()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return readDocument(stream, file.size());
|
return readDocument(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DocBookReader::readDocument(shared_ptr<ZLInputStream> inputStream, size_t streamSize) {
|
bool DocBookReader::readDocument(shared_ptr<ZLInputStream> inputStream) {
|
||||||
static const std::string WORD_DOCUMENT = "WordDocument";
|
static const std::string WORD_DOCUMENT = "WordDocument";
|
||||||
|
|
||||||
if (inputStream.isNull() || !inputStream->open()) {
|
if (inputStream.isNull() || !inputStream->open()) {
|
||||||
|
@ -62,7 +62,7 @@ bool DocBookReader::readDocument(shared_ptr<ZLInputStream> inputStream, size_t s
|
||||||
|
|
||||||
shared_ptr<OleStorage> storage = new OleStorage;
|
shared_ptr<OleStorage> storage = new OleStorage;
|
||||||
|
|
||||||
if (!storage->init(inputStream, streamSize)) {
|
if (!storage->init(inputStream, inputStream->sizeOfOpened())) {
|
||||||
ZLLogger::Instance().println("DocBookReader", "Broken OLE file!");
|
ZLLogger::Instance().println("DocBookReader", "Broken OLE file!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -112,8 +112,8 @@ void DocBookReader::handleHardLinebreak() {
|
||||||
myModelReader.endParagraph();
|
myModelReader.endParagraph();
|
||||||
}
|
}
|
||||||
myModelReader.beginParagraph();
|
myModelReader.beginParagraph();
|
||||||
if (!myCurStyleEntry.isNull()) {
|
if (!myCurrentStyleEntry.isNull()) {
|
||||||
myModelReader.addStyleEntry(*myCurStyleEntry);
|
myModelReader.addStyleEntry(*myCurrentStyleEntry);
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < myKindStack.size(); ++i) {
|
for (size_t i = 0; i < myKindStack.size(); ++i) {
|
||||||
myModelReader.addControl(myKindStack.at(i), true);
|
myModelReader.addControl(myKindStack.at(i), true);
|
||||||
|
@ -125,14 +125,14 @@ void DocBookReader::handleParagraphEnd() {
|
||||||
myModelReader.endParagraph();
|
myModelReader.endParagraph();
|
||||||
}
|
}
|
||||||
myModelReader.beginParagraph();
|
myModelReader.beginParagraph();
|
||||||
myCurStyleEntry = 0;
|
myCurrentStyleEntry = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DocBookReader::handlePageBreak() {
|
void DocBookReader::handlePageBreak() {
|
||||||
if (myModelReader.paragraphIsOpen()) {
|
if (myModelReader.paragraphIsOpen()) {
|
||||||
myModelReader.endParagraph();
|
myModelReader.endParagraph();
|
||||||
}
|
}
|
||||||
myCurStyleEntry = 0;
|
myCurrentStyleEntry = 0;
|
||||||
myModelReader.insertEndOfSectionParagraph();
|
myModelReader.insertEndOfSectionParagraph();
|
||||||
myModelReader.beginParagraph();
|
myModelReader.beginParagraph();
|
||||||
}
|
}
|
||||||
|
@ -259,10 +259,10 @@ void DocBookReader::handleFontStyle(unsigned int fontStyle) {
|
||||||
myModelReader.addControl(myKindStack.back(), false);
|
myModelReader.addControl(myKindStack.back(), false);
|
||||||
myKindStack.pop_back();
|
myKindStack.pop_back();
|
||||||
}
|
}
|
||||||
if (fontStyle & OleMainStream::CharInfo::BOLD) {
|
if (fontStyle & OleMainStream::CharInfo::FONT_BOLD) {
|
||||||
myKindStack.push_back(BOLD);
|
myKindStack.push_back(BOLD);
|
||||||
}
|
}
|
||||||
if (fontStyle & OleMainStream::CharInfo::ITALIC) {
|
if (fontStyle & OleMainStream::CharInfo::FONT_ITALIC) {
|
||||||
myKindStack.push_back(ITALIC);
|
myKindStack.push_back(ITALIC);
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < myKindStack.size(); ++i) {
|
for (size_t i = 0; i < myKindStack.size(); ++i) {
|
||||||
|
@ -271,44 +271,59 @@ void DocBookReader::handleFontStyle(unsigned int fontStyle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DocBookReader::handleParagraphStyle(const OleMainStream::Style &styleInfo) {
|
void DocBookReader::handleParagraphStyle(const OleMainStream::Style &styleInfo) {
|
||||||
if (styleInfo.hasPageBreakBefore) {
|
if (styleInfo.HasPageBreakBefore) {
|
||||||
handlePageBreak();
|
handlePageBreak();
|
||||||
}
|
}
|
||||||
shared_ptr<ZLTextStyleEntry> entry = new ZLTextStyleEntry();
|
shared_ptr<ZLTextStyleEntry> entry = new ZLTextStyleEntry();
|
||||||
|
|
||||||
if (styleInfo.alignment == OleMainStream::Style::LEFT) {
|
switch (styleInfo.Alignment) {
|
||||||
entry->setAlignmentType(ALIGN_JUSTIFY); //force justify align
|
default: // in that case, use default alignment type
|
||||||
} else if (styleInfo.alignment == OleMainStream::Style::CENTER) {
|
break;
|
||||||
entry->setAlignmentType(ALIGN_CENTER);
|
case OleMainStream::Style::ALIGNMENT_LEFT:
|
||||||
} else if (styleInfo.alignment == OleMainStream::Style::RIGHT) {
|
entry->setAlignmentType(ALIGN_LEFT);
|
||||||
entry->setAlignmentType(ALIGN_RIGHT);
|
break;
|
||||||
} else if (styleInfo.alignment == OleMainStream::Style::JUSTIFY) {
|
case OleMainStream::Style::ALIGNMENT_RIGHT:
|
||||||
entry->setAlignmentType(ALIGN_JUSTIFY);
|
entry->setAlignmentType(ALIGN_RIGHT);
|
||||||
|
break;
|
||||||
|
case OleMainStream::Style::ALIGNMENT_CENTER:
|
||||||
|
entry->setAlignmentType(ALIGN_CENTER);
|
||||||
|
break;
|
||||||
|
case OleMainStream::Style::ALIGNMENT_JUSTIFY:
|
||||||
|
entry->setAlignmentType(ALIGN_JUSTIFY);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO in case, where style is heading, but size is small it works wrong
|
//TODO in case, where style is heading, but size is small it works wrong
|
||||||
ZLTextStyleEntry::SizeUnit unit = ZLTextStyleEntry::SIZE_UNIT_PERCENT;
|
const ZLTextStyleEntry::SizeUnit unit = ZLTextStyleEntry::SIZE_UNIT_PERCENT;
|
||||||
if (styleInfo.istd == OleMainStream::H1) {
|
switch (styleInfo.StyleIdCurrent) {
|
||||||
entry->setLength(ZLTextStyleEntry::LENGTH_FONT_SIZE, 140, unit);
|
default:
|
||||||
} else if (styleInfo.istd == OleMainStream::H2) {
|
break;
|
||||||
entry->setLength(ZLTextStyleEntry::LENGTH_FONT_SIZE, 120, unit);
|
case OleMainStream::Style::STYLE_H1:
|
||||||
} else if (styleInfo.istd == OleMainStream::H3) {
|
entry->setLength(ZLTextStyleEntry::LENGTH_FONT_SIZE, 140, unit);
|
||||||
entry->setLength(ZLTextStyleEntry::LENGTH_FONT_SIZE, 110, unit);
|
break;
|
||||||
|
case OleMainStream::Style::STYLE_H2:
|
||||||
|
entry->setLength(ZLTextStyleEntry::LENGTH_FONT_SIZE, 120, unit);
|
||||||
|
break;
|
||||||
|
case OleMainStream::Style::STYLE_H3:
|
||||||
|
entry->setLength(ZLTextStyleEntry::LENGTH_FONT_SIZE, 110, unit);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
myCurrentStyleEntry = entry;
|
||||||
|
myModelReader.addStyleEntry(*myCurrentStyleEntry);
|
||||||
|
|
||||||
myCurStyleEntry = entry;
|
// we should have the same font style, as for the previous paragraph,
|
||||||
myModelReader.addStyleEntry(*myCurStyleEntry);
|
// if it has the same StyleIdCurrent
|
||||||
|
if (myCurrentStyleInfo.StyleIdCurrent != OleMainStream::Style::STYLE_INVALID &&
|
||||||
//we should have the same font style, as for the previous paragraph, if it has the same istd
|
myCurrentStyleInfo.StyleIdCurrent == styleInfo.StyleIdCurrent) {
|
||||||
if (myCurStyleInfo.istd != OleMainStream::ISTD_INVALID && myCurStyleInfo.istd == styleInfo.istd) {
|
|
||||||
for (size_t i = 0; i < myKindStack.size(); ++i) {
|
for (size_t i = 0; i < myKindStack.size(); ++i) {
|
||||||
myModelReader.addControl(myKindStack.at(i), true);
|
myModelReader.addControl(myKindStack.at(i), true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
myKindStack.clear();
|
myKindStack.clear();
|
||||||
handleFontStyle(styleInfo.charInfo.fontStyle); //fill by the fontstyle, that was got from Stylesheet
|
// fill by the fontstyle, that was got from Stylesheet
|
||||||
|
handleFontStyle(styleInfo.CurrentCharInfo.FontStyle);
|
||||||
}
|
}
|
||||||
myCurStyleInfo = styleInfo;
|
myCurrentStyleInfo = styleInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DocBookReader::handleBookmark(const std::string &name) {
|
void DocBookReader::handleBookmark(const std::string &name) {
|
||||||
|
|
|
@ -39,7 +39,7 @@ public:
|
||||||
bool readBook();
|
bool readBook();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool readDocument(shared_ptr<ZLInputStream> stream, size_t streamSize);
|
bool readDocument(shared_ptr<ZLInputStream> stream);
|
||||||
|
|
||||||
void handleChar(ZLUnicodeUtil::Ucs2Char ucs2char);
|
void handleChar(ZLUnicodeUtil::Ucs2Char ucs2char);
|
||||||
void handleHardLinebreak();
|
void handleHardLinebreak();
|
||||||
|
@ -87,8 +87,8 @@ private:
|
||||||
|
|
||||||
//formatting
|
//formatting
|
||||||
std::vector<FBTextKind> myKindStack;
|
std::vector<FBTextKind> myKindStack;
|
||||||
shared_ptr<ZLTextStyleEntry> myCurStyleEntry;
|
shared_ptr<ZLTextStyleEntry> myCurrentStyleEntry;
|
||||||
OleMainStream::Style myCurStyleInfo;
|
OleMainStream::Style myCurrentStyleInfo;
|
||||||
unsigned int myPictureCounter;
|
unsigned int myPictureCounter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -53,11 +53,11 @@ void DocFloatImageReader::readAll() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ZLFileImage::Blocks DocFloatImageReader::getBlocksForShapeID(unsigned int shapeID) const {
|
ZLFileImage::Blocks DocFloatImageReader::getBlocksForShapeId(unsigned int shapeId) const {
|
||||||
FSPContainer container;
|
FSPContainer container;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (size_t i = 0; !found && i < myItem.FSPs.size(); ++i) {
|
for (size_t i = 0; !found && i < myItem.FSPs.size(); ++i) {
|
||||||
if (myItem.FSPs.at(i).fsp.shapeID == shapeID) {
|
if (myItem.FSPs.at(i).fsp.shapeId == shapeId) {
|
||||||
found = true;
|
found = true;
|
||||||
container = myItem.FSPs.at(i);
|
container = myItem.FSPs.at(i);
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ ZLFileImage::Blocks DocFloatImageReader::getBlocksForShapeID(unsigned int shapeI
|
||||||
|
|
||||||
for (size_t i = 0; i < container.fopte.size(); ++i) {
|
for (size_t i = 0; i < container.fopte.size(); ++i) {
|
||||||
const FOPTE &fopte = container.fopte.at(i);
|
const FOPTE &fopte = container.fopte.at(i);
|
||||||
if (fopte.pID == 0x0104 && !fopte.isComplex) { //0x0104 specifies the BLIP, see p.420 [MS-ODRAW]
|
if (fopte.pId == 0x0104 && !fopte.isComplex) { //0x0104 specifies the BLIP, see p.420 [MS-ODRAW]
|
||||||
if (fopte.value <= myItem.blips.size() && fopte.value > 0) {
|
if (fopte.value <= myItem.blips.size() && fopte.value > 0) {
|
||||||
Blip blip = myItem.blips.at(fopte.value - 1);
|
Blip blip = myItem.blips.at(fopte.value - 1);
|
||||||
return blip.blocks;
|
return blip.blocks;
|
||||||
|
@ -150,15 +150,16 @@ unsigned int DocFloatImageReader::readBStoreContainerFileBlock(Blip &blip, share
|
||||||
RecordHeader header;
|
RecordHeader header;
|
||||||
unsigned int count2 = readRecordHeader(header, mainStream);
|
unsigned int count2 = readRecordHeader(header, mainStream);
|
||||||
switch (header.type) {
|
switch (header.type) {
|
||||||
case OleMainStream::WMF:
|
case OleMainStream::IMAGE_WMF:
|
||||||
case OleMainStream::EMF:
|
case OleMainStream::IMAGE_EMF:
|
||||||
case OleMainStream::PICT:
|
case OleMainStream::IMAGE_PICT:
|
||||||
count2 += skipRecord(header, mainStream);
|
count2 += skipRecord(header, mainStream);
|
||||||
break;
|
break;
|
||||||
case OleMainStream::JPEG: case OleMainStream::JPEG2:
|
case OleMainStream::IMAGE_JPEG:
|
||||||
case OleMainStream::PNG:
|
case OleMainStream::IMAGE_JPEG2:
|
||||||
case OleMainStream::DIB:
|
case OleMainStream::IMAGE_PNG:
|
||||||
case OleMainStream::TIFF:
|
case OleMainStream::IMAGE_DIB:
|
||||||
|
case OleMainStream::IMAGE_TIFF:
|
||||||
count2 += readBlip(blip, header, mainStream);
|
count2 += readBlip(blip, header, mainStream);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -173,21 +174,22 @@ unsigned int DocFloatImageReader::readBlip(Blip &blip, const RecordHeader &heade
|
||||||
|
|
||||||
bool addField = false;
|
bool addField = false;
|
||||||
switch (header.type) {
|
switch (header.type) {
|
||||||
case OleMainStream::PNG:
|
case OleMainStream::IMAGE_PNG:
|
||||||
if (header.instance == 0x6E1) {
|
if (header.instance == 0x6E1) {
|
||||||
addField = true;
|
addField = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case OleMainStream::JPEG: case OleMainStream::JPEG2:
|
case OleMainStream::IMAGE_JPEG:
|
||||||
|
case OleMainStream::IMAGE_JPEG2:
|
||||||
if (header.instance == 0x46B || header.instance == 0x6E3) {
|
if (header.instance == 0x46B || header.instance == 0x6E3) {
|
||||||
addField = true;
|
addField = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case OleMainStream::DIB:
|
case OleMainStream::IMAGE_DIB:
|
||||||
if (header.instance == 0x7A9) {
|
if (header.instance == 0x7A9) {
|
||||||
addField = true;
|
addField = true;
|
||||||
}
|
}
|
||||||
case OleMainStream::TIFF:
|
case OleMainStream::IMAGE_TIFF:
|
||||||
if (header.instance == 0x6E5) {
|
if (header.instance == 0x6E5) {
|
||||||
addField = true;
|
addField = true;
|
||||||
}
|
}
|
||||||
|
@ -315,7 +317,7 @@ unsigned int DocFloatImageReader::readSpContainter(FSPContainer &item, unsigned
|
||||||
|
|
||||||
unsigned int DocFloatImageReader::readFSP(FSP &fsp, shared_ptr<OleStream> stream) {
|
unsigned int DocFloatImageReader::readFSP(FSP &fsp, shared_ptr<OleStream> stream) {
|
||||||
//OfficeArtFSP structure is described at p.76 [MS-ODRAW]
|
//OfficeArtFSP structure is described at p.76 [MS-ODRAW]
|
||||||
fsp.shapeID = read4Bytes(stream);
|
fsp.shapeId = read4Bytes(stream);
|
||||||
stream->seek(4, false);
|
stream->seek(4, false);
|
||||||
return 8;
|
return 8;
|
||||||
}
|
}
|
||||||
|
@ -341,8 +343,8 @@ unsigned int DocFloatImageReader::readFOPTE(FOPTE &fopte, shared_ptr<OleStream>
|
||||||
//OfficeArtFOPTE structure is described at p.32 [MS-ODRAW]
|
//OfficeArtFOPTE structure is described at p.32 [MS-ODRAW]
|
||||||
unsigned int dtemp;
|
unsigned int dtemp;
|
||||||
dtemp = read2Bytes (stream);
|
dtemp = read2Bytes (stream);
|
||||||
fopte.pID = (dtemp & 0x3fff);
|
fopte.pId = (dtemp & 0x3fff);
|
||||||
fopte.isBlipID = ((dtemp & 0x4000) >> 14) == 0x1;
|
fopte.isBlipId = ((dtemp & 0x4000) >> 14) == 0x1;
|
||||||
fopte.isComplex = ((dtemp & 0x8000) >> 15) == 0x1;
|
fopte.isComplex = ((dtemp & 0x8000) >> 15) == 0x1;
|
||||||
fopte.value = read4Bytes (stream);
|
fopte.value = read4Bytes (stream);
|
||||||
return 6;
|
return 6;
|
||||||
|
|
|
@ -38,12 +38,12 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FSP { //see p.76-77 [MS-ODRAW]
|
struct FSP { //see p.76-77 [MS-ODRAW]
|
||||||
unsigned int shapeID; //spid
|
unsigned int shapeId; //spid
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FOPTE { //see p.98 and p.32 [MS-ODRAW]
|
struct FOPTE { //see p.98 and p.32 [MS-ODRAW]
|
||||||
unsigned int pID; //pid
|
unsigned int pId; //pid
|
||||||
bool isBlipID; //fBid
|
bool isBlipId; //fBid
|
||||||
bool isComplex; //fComplex
|
bool isComplex; //fComplex
|
||||||
unsigned int value; //op
|
unsigned int value; //op
|
||||||
};
|
};
|
||||||
|
@ -71,7 +71,7 @@ public:
|
||||||
public:
|
public:
|
||||||
void readAll();
|
void readAll();
|
||||||
|
|
||||||
ZLFileImage::Blocks getBlocksForShapeID(unsigned int shapeID) const;
|
ZLFileImage::Blocks getBlocksForShapeId(unsigned int shapeId) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static unsigned int readRecordHeader(RecordHeader &header, shared_ptr<OleStream> stream);
|
static unsigned int readRecordHeader(RecordHeader &header, shared_ptr<OleStream> stream);
|
||||||
|
|
|
@ -93,12 +93,13 @@ ZLFileImage::Blocks DocInlineImageReader::getImagePieceInfo(unsigned int dataPos
|
||||||
myDataStream->seek(recordLen, false);
|
myDataStream->seek(recordLen, false);
|
||||||
curOffset += recordLen;
|
curOffset += recordLen;
|
||||||
break;
|
break;
|
||||||
case OleMainStream::EMF: //EMF
|
case OleMainStream::IMAGE_EMF:
|
||||||
case OleMainStream::WMF: //WMF
|
case OleMainStream::IMAGE_WMF:
|
||||||
case OleMainStream::PICT: //PICT
|
case OleMainStream::IMAGE_PICT:
|
||||||
//TODO implement
|
//TODO implement
|
||||||
return ZLFileImage::Blocks();
|
return ZLFileImage::Blocks();
|
||||||
case OleMainStream::JPEG: case OleMainStream::JPEG2: //JPEG
|
case OleMainStream::IMAGE_JPEG:
|
||||||
|
case OleMainStream::IMAGE_JPEG2:
|
||||||
myDataStream->seek(17, false);
|
myDataStream->seek(17, false);
|
||||||
curOffset += 17;
|
curOffset += 17;
|
||||||
if (recordInstance == 0x46B || recordInstance == 0x6E3) {
|
if (recordInstance == 0x46B || recordInstance == 0x6E3) {
|
||||||
|
@ -107,7 +108,7 @@ ZLFileImage::Blocks DocInlineImageReader::getImagePieceInfo(unsigned int dataPos
|
||||||
}
|
}
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
case OleMainStream::PNG: //PNG
|
case OleMainStream::IMAGE_PNG:
|
||||||
myDataStream->seek(17, false);
|
myDataStream->seek(17, false);
|
||||||
curOffset += 17;
|
curOffset += 17;
|
||||||
if (recordInstance == 0x6E1) {
|
if (recordInstance == 0x6E1) {
|
||||||
|
@ -116,7 +117,7 @@ ZLFileImage::Blocks DocInlineImageReader::getImagePieceInfo(unsigned int dataPos
|
||||||
}
|
}
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
case OleMainStream::DIB: //DIB (BMP without 14-bytes header)
|
case OleMainStream::IMAGE_DIB: // DIB = BMP without 14-bytes header
|
||||||
myDataStream->seek(17, false);
|
myDataStream->seek(17, false);
|
||||||
curOffset += 17;
|
curOffset += 17;
|
||||||
if (recordInstance == 0x7A9) {
|
if (recordInstance == 0x7A9) {
|
||||||
|
@ -125,7 +126,7 @@ ZLFileImage::Blocks DocInlineImageReader::getImagePieceInfo(unsigned int dataPos
|
||||||
}
|
}
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
case OleMainStream::TIFF: //TIFF
|
case OleMainStream::IMAGE_TIFF:
|
||||||
myDataStream->seek(17, false);
|
myDataStream->seek(17, false);
|
||||||
curOffset += 17;
|
curOffset += 17;
|
||||||
if (recordInstance == 0x6E5) {
|
if (recordInstance == 0x6E5) {
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
* 02110-1301, USA.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cstring> //for memset
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <ZLLogger.h>
|
#include <ZLLogger.h>
|
||||||
|
@ -30,35 +29,31 @@
|
||||||
|
|
||||||
#include "OleMainStream.h"
|
#include "OleMainStream.h"
|
||||||
|
|
||||||
OleMainStream::Style::Style() {
|
OleMainStream::Style::Style() :
|
||||||
(void)memset(this, 0, sizeof(*this));
|
StyleIdCurrent(STYLE_INVALID),
|
||||||
istd = ISTD_INVALID;
|
StyleIdNext(STYLE_INVALID),
|
||||||
istdNext = ISTD_INVALID;
|
HasPageBreakBefore(false),
|
||||||
hasPageBreakBefore = false;
|
BeforeParagraphIndent(0),
|
||||||
charInfo.fontSize = 20;
|
AfterParagraphIndent(0),
|
||||||
|
LeftIndent(0),
|
||||||
|
FirstLineIndent(0),
|
||||||
|
RightIndent(0),
|
||||||
|
Alignment(ALIGNMENT_DEFAULT) {
|
||||||
}
|
}
|
||||||
|
|
||||||
OleMainStream::CharInfo::CharInfo():
|
OleMainStream::CharInfo::CharInfo() : FontStyle(FONT_REGULAR), FontSize(20) {
|
||||||
fontStyle(0),
|
|
||||||
fontSize(20) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OleMainStream::SectionInfo::SectionInfo() : CharPosition(0), IsNewPage(true) {
|
||||||
OleMainStream::SectionInfo::SectionInfo() :
|
|
||||||
charPos(0),
|
|
||||||
newPage(true) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OleMainStream::InlineImageInfo::InlineImageInfo() :
|
OleMainStream::InlineImageInfo::InlineImageInfo() : DataPosition(0) {
|
||||||
dataPos(0) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OleMainStream::FloatImageInfo::FloatImageInfo() :
|
OleMainStream::FloatImageInfo::FloatImageInfo() : ShapeId(0) {
|
||||||
shapeID(0) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OleMainStream::OleMainStream(shared_ptr<OleStorage> storage, OleEntry oleEntry, shared_ptr<ZLInputStream> stream) :
|
OleMainStream::OleMainStream(shared_ptr<OleStorage> storage, OleEntry oleEntry, shared_ptr<ZLInputStream> stream) : OleStream(storage, oleEntry, stream) {
|
||||||
OleStream(storage, oleEntry, stream) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OleMainStream::open() {
|
bool OleMainStream::open() {
|
||||||
|
@ -79,7 +74,7 @@ bool OleMainStream::open() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//determining table stream number
|
// determining table stream number
|
||||||
unsigned int tableNumber = (OleUtil::getU2Bytes(headerBuffer, 0xA) & 0x0200) ? 1 : 0;
|
unsigned int tableNumber = (OleUtil::getU2Bytes(headerBuffer, 0xA) & 0x0200) ? 1 : 0;
|
||||||
std::string tableName = tableNumber == 0 ? "0" : "1";
|
std::string tableName = tableNumber == 0 ? "0" : "1";
|
||||||
tableName += "Table";
|
tableName += "Table";
|
||||||
|
@ -87,8 +82,9 @@ bool OleMainStream::open() {
|
||||||
result = myStorage->getEntryByName(tableName, tableEntry);
|
result = myStorage->getEntryByName(tableName, tableEntry);
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
//cant't find table stream (that can be only in case if file format is below Word 7/8), so building simple table stream
|
// cant't find table stream (that can be only in case if file format is below Word 7/8), so building simple table stream
|
||||||
Piece piece = {myStartOfText, myEndOfText - myStartOfText, true, Piece::TEXT, 0}; //CHECK may be not all old documents have ANSI
|
// TODO: CHECK may be not all old documents have ANSI
|
||||||
|
Piece piece = {myStartOfText, myEndOfText - myStartOfText, true, Piece::PIECE_TEXT, 0};
|
||||||
myPieces.push_back(piece);
|
myPieces.push_back(piece);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -128,7 +124,7 @@ const OleMainStream::StyleInfoList &OleMainStream::getStyleInfoList() const {
|
||||||
return myStyleInfoList;
|
return myStyleInfoList;
|
||||||
}
|
}
|
||||||
|
|
||||||
const OleMainStream::Bookmarks &OleMainStream::getBookmarks() const {
|
const OleMainStream::BookmarksList &OleMainStream::getBookmarks() const {
|
||||||
return myBookmarks;
|
return myBookmarks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,19 +136,19 @@ const OleMainStream::FloatImageInfoList &OleMainStream::getFloatImageInfoList()
|
||||||
return myFloatImageInfoList;
|
return myFloatImageInfoList;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZLFileImage::Blocks OleMainStream::getFloatImage(unsigned int shapeID) const {
|
ZLFileImage::Blocks OleMainStream::getFloatImage(unsigned int shapeId) const {
|
||||||
if (myFLoatImageReader.isNull()) {
|
if (myFLoatImageReader.isNull()) {
|
||||||
return ZLFileImage::Blocks();
|
return ZLFileImage::Blocks();
|
||||||
}
|
}
|
||||||
return myFLoatImageReader->getBlocksForShapeID(shapeID);
|
return myFLoatImageReader->getBlocksForShapeId(shapeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZLFileImage::Blocks OleMainStream::getInlineImage(unsigned int dataPos) const {
|
ZLFileImage::Blocks OleMainStream::getInlineImage(unsigned int dataPosition) const {
|
||||||
if (myDataStream.isNull()) {
|
if (myDataStream.isNull()) {
|
||||||
return ZLFileImage::Blocks();
|
return ZLFileImage::Blocks();
|
||||||
}
|
}
|
||||||
DocInlineImageReader imageReader(myDataStream);
|
DocInlineImageReader imageReader(myDataStream);
|
||||||
return imageReader.getImagePieceInfo(dataPos);
|
return imageReader.getImagePieceInfo(dataPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OleMainStream::readFIB(const char *headerBuffer) {
|
bool OleMainStream::readFIB(const char *headerBuffer) {
|
||||||
|
@ -196,32 +192,32 @@ void OleMainStream::splitPieces(const Pieces &s, Pieces &dest1, Pieces &dest2, P
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (i = 0; i < source.size(); ++i) {
|
for (i = 0; i < source.size(); ++i) {
|
||||||
Piece piece = source.at(i);
|
Piece piece = source.at(i);
|
||||||
if (piece.length + sumLength >= boundary) {
|
if (piece.Length + sumLength >= boundary) {
|
||||||
Piece piece2 = piece;
|
Piece piece2 = piece;
|
||||||
|
|
||||||
piece.length = boundary - sumLength;
|
piece.Length = boundary - sumLength;
|
||||||
piece.type = type1;
|
piece.Type = type1;
|
||||||
|
|
||||||
piece2.type = type2;
|
piece2.Type = type2;
|
||||||
piece2.offset += piece.length * 2;
|
piece2.Offset += piece.Length * 2;
|
||||||
piece2.length -= piece.length;
|
piece2.Length -= piece.Length;
|
||||||
|
|
||||||
if (piece.length > 0) {
|
if (piece.Length > 0) {
|
||||||
dest1.push_back(piece);
|
dest1.push_back(piece);
|
||||||
}
|
}
|
||||||
if (piece2.length > 0) {
|
if (piece2.Length > 0) {
|
||||||
dest2.push_back(piece2);
|
dest2.push_back(piece2);
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sumLength += piece.length;
|
sumLength += piece.Length;
|
||||||
piece.type = type1;
|
piece.Type = type1;
|
||||||
dest1.push_back(piece);
|
dest1.push_back(piece);
|
||||||
}
|
}
|
||||||
for (; i < source.size(); ++i) {
|
for (; i < source.size(); ++i) {
|
||||||
Piece piece = source.at(i);
|
Piece piece = source.at(i);
|
||||||
piece.type = type2;
|
piece.Type = type2;
|
||||||
dest2.push_back(piece);
|
dest2.push_back(piece);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,16 +294,16 @@ bool OleMainStream::readPieceTable(const char *headerBuffer, const OleEntry &tab
|
||||||
//4byte integer with offset and ANSI flag
|
//4byte integer with offset and ANSI flag
|
||||||
int fcValue = OleUtil::get4Bytes(descriptors.at(i).c_str(), 0x2); //offset for piece structure
|
int fcValue = OleUtil::get4Bytes(descriptors.at(i).c_str(), 0x2); //offset for piece structure
|
||||||
Piece piece;
|
Piece piece;
|
||||||
piece.isANSI = (fcValue & 0x40000000) == 0x40000000; //ansi flag
|
piece.IsANSI = (fcValue & 0x40000000) == 0x40000000; //ansi flag
|
||||||
piece.offset = fcValue & 0x3FFFFFFF; //gettting offset for current piece
|
piece.Offset = fcValue & 0x3FFFFFFF; //gettting offset for current piece
|
||||||
piece.length = cp.at(i + 1) - cp.at(i);
|
piece.Length = cp.at(i + 1) - cp.at(i);
|
||||||
myPieces.push_back(piece);
|
myPieces.push_back(piece);
|
||||||
}
|
}
|
||||||
|
|
||||||
//split pieces into different types
|
//split pieces into different types
|
||||||
Pieces piecesText, piecesFootnote, piecesOther;
|
Pieces piecesText, piecesFootnote, piecesOther;
|
||||||
splitPieces(myPieces, piecesText, piecesFootnote, Piece::TEXT, Piece::FOOTNOTE, ccpText);
|
splitPieces(myPieces, piecesText, piecesFootnote, Piece::PIECE_TEXT, Piece::PIECE_FOOTNOTE, ccpText);
|
||||||
splitPieces(piecesFootnote, piecesFootnote, piecesOther, Piece::FOOTNOTE, Piece::OTHER, ccpFtn);
|
splitPieces(piecesFootnote, piecesFootnote, piecesOther, Piece::PIECE_FOOTNOTE, Piece::PIECE_OTHER, ccpFtn);
|
||||||
|
|
||||||
myPieces.clear();
|
myPieces.clear();
|
||||||
for (size_t i = 0; i < piecesText.size(); ++i) {
|
for (size_t i = 0; i < piecesText.size(); ++i) {
|
||||||
|
@ -323,10 +319,10 @@ bool OleMainStream::readPieceTable(const char *headerBuffer, const OleEntry &tab
|
||||||
//converting length and offset depending on isANSI
|
//converting length and offset depending on isANSI
|
||||||
for (size_t i = 0; i < myPieces.size(); ++i) {
|
for (size_t i = 0; i < myPieces.size(); ++i) {
|
||||||
Piece &piece = myPieces.at(i);
|
Piece &piece = myPieces.at(i);
|
||||||
if (!piece.isANSI) {
|
if (!piece.IsANSI) {
|
||||||
piece.length *= 2;
|
piece.Length *= 2;
|
||||||
} else {
|
} else {
|
||||||
piece.offset /= 2;
|
piece.Offset /= 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,10 +331,10 @@ bool OleMainStream::readPieceTable(const char *headerBuffer, const OleEntry &tab
|
||||||
for (size_t i = 0; i < myPieces.size(); ++i) {
|
for (size_t i = 0; i < myPieces.size(); ++i) {
|
||||||
Piece &piece = myPieces.at(i);
|
Piece &piece = myPieces.at(i);
|
||||||
piece.startCP = curStartCP;
|
piece.startCP = curStartCP;
|
||||||
if (piece.isANSI) {
|
if (piece.IsANSI) {
|
||||||
curStartCP += piece.length;
|
curStartCP += piece.Length;
|
||||||
} else {
|
} else {
|
||||||
curStartCP += piece.length / 2;
|
curStartCP += piece.Length / 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -402,8 +398,8 @@ bool OleMainStream::readBookmarks(const char *headerBuffer, const OleEntry &tabl
|
||||||
break; //for the case if something in these structures goes wrong, to not to lose all bookmarks
|
break; //for the case if something in these structures goes wrong, to not to lose all bookmarks
|
||||||
}
|
}
|
||||||
Bookmark bookmark;
|
Bookmark bookmark;
|
||||||
bookmark.charPos = charPage.at(i);
|
bookmark.CharPosition = charPage.at(i);
|
||||||
bookmark.name = names.at(i);
|
bookmark.Name = names.at(i);
|
||||||
myBookmarks.push_back(bookmark);
|
myBookmarks.push_back(bookmark);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,25 +443,25 @@ bool OleMainStream::readStylesheet(const char *headerBuffer, const OleEntry &tab
|
||||||
|
|
||||||
Style styleInfo = myStyleSheet.at(index);
|
Style styleInfo = myStyleSheet.at(index);
|
||||||
|
|
||||||
unsigned int styleAndBaseType = OleUtil::getU2Bytes(buffer, offset + 4);
|
const unsigned int styleAndBaseType = OleUtil::getU2Bytes(buffer, offset + 4);
|
||||||
unsigned int styleType = styleAndBaseType % 16;
|
const unsigned int styleType = styleAndBaseType % 16;
|
||||||
unsigned int baseStyle = styleAndBaseType / 16;
|
const unsigned int baseStyleId = styleAndBaseType / 16;
|
||||||
if (baseStyle == STI_NIL || baseStyle == STI_USER) {
|
if (baseStyleId == Style::STYLE_NIL || baseStyleId == Style::STYLE_USER) {
|
||||||
//if based on nil or user style, left defaukt
|
//if based on nil or user style, left default
|
||||||
} else {
|
} else {
|
||||||
int baseStyleIndex = getStyleIndex(baseStyle, isFilled, myStyleSheet);
|
int baseStyleIndex = getStyleIndex(baseStyleId, isFilled, myStyleSheet);
|
||||||
if (baseStyleIndex < 0) {
|
if (baseStyleIndex < 0) {
|
||||||
//this base style is not filled yet, sp pass it at some time
|
//this base style is not filled yet, so pass it at some time
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
styleInfo = myStyleSheet.at(baseStyleIndex);
|
styleInfo = myStyleSheet.at(baseStyleIndex);
|
||||||
styleInfo.istd = ISTD_INVALID;
|
styleInfo.StyleIdCurrent = Style::STYLE_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse STD structure
|
// parse STD structure
|
||||||
unsigned int tmp = OleUtil::getU2Bytes(buffer, offset + 6);
|
unsigned int tmp = OleUtil::getU2Bytes(buffer, offset + 6);
|
||||||
unsigned int upxCount = tmp % 16;
|
unsigned int upxCount = tmp % 16;
|
||||||
styleInfo.istdNext = tmp / 16;
|
styleInfo.StyleIdNext = tmp / 16;
|
||||||
|
|
||||||
//adding current style
|
//adding current style
|
||||||
myStyleSheet[index] = styleInfo;
|
myStyleSheet[index] = styleInfo;
|
||||||
|
@ -490,7 +486,7 @@ bool OleMainStream::readStylesheet(const char *headerBuffer, const OleEntry &tab
|
||||||
//for style info styleType must be equal 1
|
//for style info styleType must be equal 1
|
||||||
if (styleType == 1 && upxCount >= 1) {
|
if (styleType == 1 && upxCount >= 1) {
|
||||||
if (upxLen >= 2) {
|
if (upxLen >= 2) {
|
||||||
styleInfo.istd = OleUtil::getU2Bytes(buffer, offset + pos + 2);
|
styleInfo.StyleIdCurrent = OleUtil::getU2Bytes(buffer, offset + pos + 2);
|
||||||
getStyleInfo(0, buffer + offset + pos + 4, upxLen - 2, styleInfo);
|
getStyleInfo(0, buffer + offset + pos + 4, upxLen - 2, styleInfo);
|
||||||
myStyleSheet[index] = styleInfo;
|
myStyleSheet[index] = styleInfo;
|
||||||
}
|
}
|
||||||
|
@ -507,8 +503,8 @@ bool OleMainStream::readStylesheet(const char *headerBuffer, const OleEntry &tab
|
||||||
//for char info styleType can be equal 1 or 2
|
//for char info styleType can be equal 1 or 2
|
||||||
if ((styleType == 1 && upxCount >= 2) || (styleType == 2 && upxCount >= 1)) {
|
if ((styleType == 1 && upxCount >= 2) || (styleType == 2 && upxCount >= 1)) {
|
||||||
CharInfo charInfo;
|
CharInfo charInfo;
|
||||||
getCharInfo(0, ISTD_INVALID, buffer + offset + pos + 2, upxLen, charInfo);
|
getCharInfo(0, Style::STYLE_INVALID, buffer + offset + pos + 2, upxLen, charInfo);
|
||||||
styleInfo.charInfo = charInfo;
|
styleInfo.CurrentCharInfo = charInfo;
|
||||||
myStyleSheet[index] = styleInfo;
|
myStyleSheet[index] = styleInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -553,11 +549,11 @@ bool OleMainStream::readCharInfoTable(const char *headerBuffer, const OleEntry &
|
||||||
if (!offsetToCharPos(offset, charPos, myPieces)) {
|
if (!offsetToCharPos(offset, charPos, myPieces)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
unsigned int istd = getIstdByCharPos(charPos, myStyleInfoList);
|
unsigned int styleId = getStyleIdByCharPos(charPos, myStyleInfoList);
|
||||||
|
|
||||||
CharInfo charInfo = getStyleFromStylesheet(istd, myStyleSheet).charInfo;
|
CharInfo charInfo = getStyleFromStylesheet(styleId, myStyleSheet).CurrentCharInfo;
|
||||||
if (chpxOffset != 0) {
|
if (chpxOffset != 0) {
|
||||||
getCharInfo(chpxOffset, istd, formatPageBuffer + 1, len - 1, charInfo);
|
getCharInfo(chpxOffset, styleId, formatPageBuffer + 1, len - 1, charInfo);
|
||||||
}
|
}
|
||||||
myCharInfoList.push_back(CharPosToCharInfo(charPos, charInfo));
|
myCharInfoList.push_back(CharPosToCharInfo(charPos, charInfo));
|
||||||
|
|
||||||
|
@ -604,7 +600,7 @@ bool OleMainStream::readFloatingImages(const char *headerBuffer, const OleEntry
|
||||||
unsigned int spid = OleUtil::getU4Bytes(buffer.c_str(), tOffset);
|
unsigned int spid = OleUtil::getU4Bytes(buffer.c_str(), tOffset);
|
||||||
FloatImageInfo info;
|
FloatImageInfo info;
|
||||||
unsigned int charPos = picturesBlocks.at(index);
|
unsigned int charPos = picturesBlocks.at(index);
|
||||||
info.shapeID = spid;
|
info.ShapeId = spid;
|
||||||
myFloatImageInfoList.push_back(CharPosToFloatImageInfo(charPos, info));
|
myFloatImageInfoList.push_back(CharPosToFloatImageInfo(charPos, info));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -655,9 +651,9 @@ bool OleMainStream::readParagraphStyleTable(const char *headerBuffer, const OleE
|
||||||
if (read(formatPageBuffer, OleStorage::BBD_BLOCK_SIZE) != OleStorage::BBD_BLOCK_SIZE) {
|
if (read(formatPageBuffer, OleStorage::BBD_BLOCK_SIZE) != OleStorage::BBD_BLOCK_SIZE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
unsigned int paragraphsCount = OleUtil::getU1Byte(formatPageBuffer, 0x1ff); //offset with 'cpara' value (count of paragraphs)
|
const unsigned int paragraphsCount = OleUtil::getU1Byte(formatPageBuffer, 0x1ff); //offset with 'cpara' value (count of paragraphs)
|
||||||
for (unsigned int index2 = 0; index2 < paragraphsCount; ++index2) {
|
for (unsigned int index2 = 0; index2 < paragraphsCount; ++index2) {
|
||||||
unsigned int offset = OleUtil::getU4Bytes(formatPageBuffer, index2 * 4);
|
const unsigned int offset = OleUtil::getU4Bytes(formatPageBuffer, index2 * 4);
|
||||||
unsigned int papxOffset = OleUtil::getU1Byte(formatPageBuffer, (paragraphsCount + 1) * 4 + index2 * 13) * 2;
|
unsigned int papxOffset = OleUtil::getU1Byte(formatPageBuffer, (paragraphsCount + 1) * 4 + index2 * 13) * 2;
|
||||||
if (papxOffset <= 0) {
|
if (papxOffset <= 0) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -668,8 +664,8 @@ bool OleMainStream::readParagraphStyleTable(const char *headerBuffer, const OleE
|
||||||
len = OleUtil::getU1Byte(formatPageBuffer, papxOffset) * 2;
|
len = OleUtil::getU1Byte(formatPageBuffer, papxOffset) * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int istd = OleUtil::getU2Bytes(formatPageBuffer, papxOffset + 1);
|
const unsigned int styleId = OleUtil::getU2Bytes(formatPageBuffer, papxOffset + 1);
|
||||||
Style styleInfo = getStyleFromStylesheet(istd, myStyleSheet);
|
Style styleInfo = getStyleFromStylesheet(styleId, myStyleSheet);
|
||||||
|
|
||||||
if (len >= 3) {
|
if (len >= 3) {
|
||||||
getStyleInfo(papxOffset, formatPageBuffer + 3, len - 3, styleInfo);
|
getStyleInfo(papxOffset, formatPageBuffer + 3, len - 3, styleInfo);
|
||||||
|
@ -723,7 +719,7 @@ bool OleMainStream::readSectionsInfoTable(const char *headerBuffer, const OleEnt
|
||||||
for (size_t index = 0; index < sectPage.size(); ++index) {
|
for (size_t index = 0; index < sectPage.size(); ++index) {
|
||||||
if (sectPage.at(index) == 0xffffffffUL) { //check for invalid record, to make default section info
|
if (sectPage.at(index) == 0xffffffffUL) { //check for invalid record, to make default section info
|
||||||
SectionInfo sectionInfo;
|
SectionInfo sectionInfo;
|
||||||
sectionInfo.charPos = charPos.at(index);
|
sectionInfo.CharPosition = charPos.at(index);
|
||||||
mySectionInfoList.push_back(sectionInfo);
|
mySectionInfoList.push_back(sectionInfo);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -745,7 +741,7 @@ bool OleMainStream::readSectionsInfoTable(const char *headerBuffer, const OleEnt
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SectionInfo sectionInfo;
|
SectionInfo sectionInfo;
|
||||||
sectionInfo.charPos = charPos.at(index);
|
sectionInfo.CharPosition = charPos.at(index);
|
||||||
getSectionInfo(formatPageBuffer + 2, bytes - 2, sectionInfo);
|
getSectionInfo(formatPageBuffer + 2, bytes - 2, sectionInfo);
|
||||||
mySectionInfoList.push_back(sectionInfo);
|
mySectionInfoList.push_back(sectionInfo);
|
||||||
delete[] formatPageBuffer;
|
delete[] formatPageBuffer;
|
||||||
|
@ -760,12 +756,12 @@ void OleMainStream::getStyleInfo(unsigned int papxOffset, const char *grpprlBuff
|
||||||
unsigned int curPrlLength = 0;
|
unsigned int curPrlLength = 0;
|
||||||
switch (OleUtil::getU2Bytes(grpprlBuffer, papxOffset + offset)) {
|
switch (OleUtil::getU2Bytes(grpprlBuffer, papxOffset + offset)) {
|
||||||
case 0x2403:
|
case 0x2403:
|
||||||
styleInfo.alignment = OleUtil::getU1Byte(grpprlBuffer, papxOffset + offset + 2);
|
styleInfo.Alignment = (Style::AlignmentType)OleUtil::getU1Byte(grpprlBuffer, papxOffset + offset + 2);
|
||||||
break;
|
break;
|
||||||
case 0x4610:
|
case 0x4610:
|
||||||
styleInfo.leftIndent += OleUtil::getU2Bytes(grpprlBuffer, papxOffset + offset + 2);
|
styleInfo.LeftIndent += OleUtil::getU2Bytes(grpprlBuffer, papxOffset + offset + 2);
|
||||||
if (styleInfo.leftIndent < 0) {
|
if (styleInfo.LeftIndent < 0) {
|
||||||
styleInfo.leftIndent = 0;
|
styleInfo.LeftIndent = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0xc60d: // ChgTabsPapx
|
case 0xc60d: // ChgTabsPapx
|
||||||
|
@ -787,22 +783,22 @@ void OleMainStream::getStyleInfo(unsigned int papxOffset, const char *grpprlBuff
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0x840e:
|
case 0x840e:
|
||||||
styleInfo.rightIndent = (int)OleUtil::getU2Bytes(grpprlBuffer, papxOffset + offset + 2);
|
styleInfo.RightIndent = (int)OleUtil::getU2Bytes(grpprlBuffer, papxOffset + offset + 2);
|
||||||
break;
|
break;
|
||||||
case 0x840f:
|
case 0x840f:
|
||||||
styleInfo.leftIndent = (int)OleUtil::getU2Bytes(grpprlBuffer, papxOffset + offset + 2);
|
styleInfo.LeftIndent = (int)OleUtil::getU2Bytes(grpprlBuffer, papxOffset + offset + 2);
|
||||||
break;
|
break;
|
||||||
case 0x8411:
|
case 0x8411:
|
||||||
styleInfo.firstLineIndent = (int)OleUtil::getU2Bytes(grpprlBuffer, papxOffset + offset + 2);
|
styleInfo.FirstLineIndent = (int)OleUtil::getU2Bytes(grpprlBuffer, papxOffset + offset + 2);
|
||||||
break;
|
break;
|
||||||
case 0xa413:
|
case 0xa413:
|
||||||
styleInfo.beforeIndent = OleUtil::getU2Bytes(grpprlBuffer, papxOffset + offset + 2);
|
styleInfo.BeforeParagraphIndent = OleUtil::getU2Bytes(grpprlBuffer, papxOffset + offset + 2);
|
||||||
break;
|
break;
|
||||||
case 0xa414:
|
case 0xa414:
|
||||||
styleInfo.afterIndent = OleUtil::getU2Bytes(grpprlBuffer, papxOffset + offset + 2);
|
styleInfo.AfterParagraphIndent = OleUtil::getU2Bytes(grpprlBuffer, papxOffset + offset + 2);
|
||||||
break;
|
break;
|
||||||
case 0x2407:
|
case 0x2407:
|
||||||
styleInfo.hasPageBreakBefore = OleUtil::getU1Byte(grpprlBuffer, papxOffset + offset + 2) == 0x01;
|
styleInfo.HasPageBreakBefore = OleUtil::getU1Byte(grpprlBuffer, papxOffset + offset + 2) == 0x01;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -815,7 +811,7 @@ void OleMainStream::getStyleInfo(unsigned int papxOffset, const char *grpprlBuff
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OleMainStream::getCharInfo(unsigned int chpxOffset, unsigned int /*istd*/, const char *grpprlBuffer, unsigned int bytes, CharInfo &charInfo) {
|
void OleMainStream::getCharInfo(unsigned int chpxOffset, unsigned int /*styleId*/, const char *grpprlBuffer, unsigned int bytes, CharInfo &charInfo) {
|
||||||
unsigned int sprm = 0; //single propery modifier
|
unsigned int sprm = 0; //single propery modifier
|
||||||
unsigned int offset = 0;
|
unsigned int offset = 0;
|
||||||
while (bytes >= offset + 2) {
|
while (bytes >= offset + 2) {
|
||||||
|
@ -824,15 +820,15 @@ void OleMainStream::getCharInfo(unsigned int chpxOffset, unsigned int /*istd*/,
|
||||||
sprm = OleUtil::getU1Byte(grpprlBuffer, chpxOffset + offset + 2);
|
sprm = OleUtil::getU1Byte(grpprlBuffer, chpxOffset + offset + 2);
|
||||||
switch (sprm) {
|
switch (sprm) {
|
||||||
case UNSET:
|
case UNSET:
|
||||||
charInfo.fontStyle &= ~CharInfo::BOLD;
|
charInfo.FontStyle &= ~CharInfo::FONT_BOLD;
|
||||||
break;
|
break;
|
||||||
case SET:
|
case SET:
|
||||||
charInfo.fontStyle |= CharInfo::BOLD;
|
charInfo.FontStyle |= CharInfo::FONT_BOLD;
|
||||||
break;
|
break;
|
||||||
case UNCHANGED:
|
case UNCHANGED:
|
||||||
break;
|
break;
|
||||||
case NEGATION:
|
case NEGATION:
|
||||||
charInfo.fontStyle ^= CharInfo::BOLD;
|
charInfo.FontStyle ^= CharInfo::FONT_BOLD;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -842,22 +838,22 @@ void OleMainStream::getCharInfo(unsigned int chpxOffset, unsigned int /*istd*/,
|
||||||
sprm = OleUtil::getU1Byte(grpprlBuffer, chpxOffset + offset + 2);
|
sprm = OleUtil::getU1Byte(grpprlBuffer, chpxOffset + offset + 2);
|
||||||
switch (sprm) {
|
switch (sprm) {
|
||||||
case UNSET:
|
case UNSET:
|
||||||
charInfo.fontStyle &= ~CharInfo::ITALIC;
|
charInfo.FontStyle &= ~CharInfo::FONT_ITALIC;
|
||||||
break;
|
break;
|
||||||
case SET:
|
case SET:
|
||||||
charInfo.fontStyle |= CharInfo::ITALIC;
|
charInfo.FontStyle |= CharInfo::FONT_ITALIC;
|
||||||
break;
|
break;
|
||||||
case UNCHANGED:
|
case UNCHANGED:
|
||||||
break;
|
break;
|
||||||
case NEGATION:
|
case NEGATION:
|
||||||
charInfo.fontStyle ^= CharInfo::ITALIC;
|
charInfo.FontStyle ^= CharInfo::FONT_ITALIC;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0x4a43: //size of font
|
case 0x4a43: //size of font
|
||||||
charInfo.fontSize = OleUtil::getU2Bytes(grpprlBuffer, chpxOffset + offset + 2);
|
charInfo.FontSize = OleUtil::getU2Bytes(grpprlBuffer, chpxOffset + offset + 2);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -874,7 +870,7 @@ void OleMainStream::getSectionInfo(const char *grpprlBuffer, size_t bytes, Secti
|
||||||
switch (OleUtil::getU2Bytes(grpprlBuffer, offset)) {
|
switch (OleUtil::getU2Bytes(grpprlBuffer, offset)) {
|
||||||
case 0x3009: //new page
|
case 0x3009: //new page
|
||||||
tmp = OleUtil::getU1Byte(grpprlBuffer, offset + 2);
|
tmp = OleUtil::getU1Byte(grpprlBuffer, offset + 2);
|
||||||
sectionInfo.newPage = (tmp != 0 && tmp != 1);
|
sectionInfo.IsNewPage = (tmp != 0 && tmp != 1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -905,7 +901,7 @@ bool OleMainStream::getInlineImageInfo(unsigned int chpxOffset, const char *grpp
|
||||||
// }
|
// }
|
||||||
// break;
|
// break;
|
||||||
case 0x6a03: // location p.105 [MS-DOC]
|
case 0x6a03: // location p.105 [MS-DOC]
|
||||||
pictureInfo.dataPos = OleUtil::getU4Bytes(grpprlBuffer, chpxOffset + offset + 2);
|
pictureInfo.DataPosition = OleUtil::getU4Bytes(grpprlBuffer, chpxOffset + offset + 2);
|
||||||
isFound = true;
|
isFound = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -916,61 +912,61 @@ bool OleMainStream::getInlineImageInfo(unsigned int chpxOffset, const char *grpp
|
||||||
return isFound;
|
return isFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
OleMainStream::Style OleMainStream::getStyleFromStylesheet(unsigned int istd, const StyleSheet &stylesheet) {
|
OleMainStream::Style OleMainStream::getStyleFromStylesheet(unsigned int styleId, const StyleSheet &stylesheet) {
|
||||||
//TODO optimize it: StyleSheet can be map structure with istd key
|
//TODO optimize it: StyleSheet can be map structure with styleId key
|
||||||
Style style;
|
Style style;
|
||||||
if (istd != ISTD_INVALID && istd != STI_NIL && istd != STI_USER) {
|
if (styleId != Style::STYLE_INVALID && styleId != Style::STYLE_NIL && styleId != Style::STYLE_USER) {
|
||||||
for (size_t index = 0; index < stylesheet.size(); ++index) {
|
for (size_t index = 0; index < stylesheet.size(); ++index) {
|
||||||
if (stylesheet.at(index).istd == istd) {
|
if (stylesheet.at(index).StyleIdCurrent == styleId) {
|
||||||
return stylesheet.at(index);
|
return stylesheet.at(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
style.istd = istd;
|
style.StyleIdCurrent = styleId;
|
||||||
return style;
|
return style;
|
||||||
}
|
}
|
||||||
|
|
||||||
int OleMainStream::getStyleIndex(unsigned int istd, const std::vector<bool> &isFilled, const StyleSheet &stylesheet) {
|
int OleMainStream::getStyleIndex(unsigned int styleId, const std::vector<bool> &isFilled, const StyleSheet &stylesheet) {
|
||||||
//TODO optimize it: StyleSheet can be map structure with istd key
|
//TODO optimize it: StyleSheet can be map structure with styleId key
|
||||||
//in that case, this method will be excess
|
//in that case, this method will be excess
|
||||||
if (istd == ISTD_INVALID) {
|
if (styleId == Style::STYLE_INVALID) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
for (int index = 0; index < (int)stylesheet.size(); ++index) {
|
for (int index = 0; index < (int)stylesheet.size(); ++index) {
|
||||||
if (isFilled.at(index) && stylesheet.at(index).istd == istd) {
|
if (isFilled.at(index) && stylesheet.at(index).StyleIdCurrent == styleId) {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int OleMainStream::getIstdByCharPos(unsigned int charPos, const StyleInfoList &styleInfoList) {
|
unsigned int OleMainStream::getStyleIdByCharPos(unsigned int charPos, const StyleInfoList &styleInfoList) {
|
||||||
unsigned int istd = ISTD_INVALID;
|
unsigned int styleId = Style::STYLE_INVALID;
|
||||||
for (size_t i = 0; i < styleInfoList.size(); ++i) {
|
for (size_t i = 0; i < styleInfoList.size(); ++i) {
|
||||||
const Style &info = styleInfoList.at(i).second;
|
const Style &info = styleInfoList.at(i).second;
|
||||||
if (i == styleInfoList.size() - 1) { //if last
|
if (i == styleInfoList.size() - 1) { //if last
|
||||||
istd = info.istd;
|
styleId = info.StyleIdCurrent;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
unsigned int curOffset = styleInfoList.at(i).first;
|
unsigned int curOffset = styleInfoList.at(i).first;
|
||||||
unsigned int nextOffset = styleInfoList.at(i + 1).first;
|
unsigned int nextOffset = styleInfoList.at(i + 1).first;
|
||||||
if (charPos >= curOffset && charPos < nextOffset) {
|
if (charPos >= curOffset && charPos < nextOffset) {
|
||||||
istd = info.istd;
|
styleId = info.StyleIdCurrent;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return istd;
|
return styleId;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OleMainStream::offsetToCharPos(unsigned int offset, unsigned int &charPos, const Pieces &pieces) {
|
bool OleMainStream::offsetToCharPos(unsigned int offset, unsigned int &charPos, const Pieces &pieces) {
|
||||||
if (pieces.empty()) {
|
if (pieces.empty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ((unsigned int)pieces.front().offset > offset) {
|
if ((unsigned int)pieces.front().Offset > offset) {
|
||||||
charPos = 0;
|
charPos = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ((unsigned int)(pieces.back().offset + pieces.back().length) <= offset) {
|
if ((unsigned int)(pieces.back().Offset + pieces.back().Length) <= offset) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -980,8 +976,8 @@ bool OleMainStream::offsetToCharPos(unsigned int offset, unsigned int &charPos,
|
||||||
pieceNumber = i;
|
pieceNumber = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
unsigned int curOffset = pieces.at(i).offset;
|
unsigned int curOffset = pieces.at(i).Offset;
|
||||||
unsigned int nextOffset = pieces.at(i + 1).offset;
|
unsigned int nextOffset = pieces.at(i + 1).Offset;
|
||||||
if (offset >= curOffset && offset < nextOffset) {
|
if (offset >= curOffset && offset < nextOffset) {
|
||||||
pieceNumber = i;
|
pieceNumber = i;
|
||||||
break;
|
break;
|
||||||
|
@ -989,8 +985,8 @@ bool OleMainStream::offsetToCharPos(unsigned int offset, unsigned int &charPos,
|
||||||
}
|
}
|
||||||
|
|
||||||
const Piece &piece = pieces.at(pieceNumber);
|
const Piece &piece = pieces.at(pieceNumber);
|
||||||
unsigned int diffOffset = offset - piece.offset;
|
unsigned int diffOffset = offset - piece.Offset;
|
||||||
if (!piece.isANSI) {
|
if (!piece.IsANSI) {
|
||||||
diffOffset /= 2;
|
diffOffset /= 2;
|
||||||
}
|
}
|
||||||
charPos = piece.startCP + diffOffset;
|
charPos = piece.startCP + diffOffset;
|
||||||
|
|
|
@ -30,37 +30,36 @@ class OleMainStream : public OleStream {
|
||||||
public:
|
public:
|
||||||
struct Piece {
|
struct Piece {
|
||||||
enum PieceType {
|
enum PieceType {
|
||||||
TEXT,
|
PIECE_TEXT,
|
||||||
FOOTNOTE,
|
PIECE_FOOTNOTE,
|
||||||
OTHER
|
PIECE_OTHER
|
||||||
};
|
};
|
||||||
|
|
||||||
int offset; //maybe make it unsigned int
|
int Offset; // TODO: maybe make it unsigned int
|
||||||
int length; //maybe make it unsigned int
|
int Length; // TODO: maybe make it unsigned int
|
||||||
bool isANSI;
|
bool IsANSI;
|
||||||
PieceType type;
|
PieceType Type;
|
||||||
unsigned int startCP;
|
unsigned int startCP;
|
||||||
};
|
};
|
||||||
typedef std::vector<Piece> Pieces;
|
typedef std::vector<Piece> Pieces;
|
||||||
|
|
||||||
struct CharInfo {
|
struct CharInfo {
|
||||||
|
|
||||||
enum Font {
|
enum Font {
|
||||||
REGULAR = 0x0000,
|
FONT_REGULAR = 0,
|
||||||
BOLD = 0x0001,
|
FONT_BOLD = 1 << 0,
|
||||||
ITALIC = 0x0002,
|
FONT_ITALIC = 1 << 1,
|
||||||
UNDERLINE = 0x0004,
|
FONT_UNDERLINE = 1 << 2,
|
||||||
CAPITALS = 0x0008,
|
FONT_CAPITALS = 1 << 3,
|
||||||
SMALL_CAPITALS = 0x0010,
|
FONT_SMALL_CAPS = 1 << 4,
|
||||||
STRIKE = 0x0020,
|
FONT_STRIKE = 1 << 5,
|
||||||
HIDDEN = 0x0040,
|
FONT_HIDDEN = 1 << 6,
|
||||||
MARKDEL = 0x0080,
|
FONT_MARKDEL = 1 << 7,
|
||||||
SUPERSCRIPT = 0x0100,
|
FONT_SUPERSCRIPT = 1 << 8,
|
||||||
SUBSCRIPT = 0x0200
|
FONT_SUBSCRIPT = 1 << 9
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned int fontStyle;
|
unsigned int FontStyle;
|
||||||
unsigned int fontSize;
|
unsigned int FontSize;
|
||||||
|
|
||||||
CharInfo();
|
CharInfo();
|
||||||
};
|
};
|
||||||
|
@ -68,76 +67,82 @@ public:
|
||||||
typedef std::vector<CharPosToCharInfo > CharInfoList;
|
typedef std::vector<CharPosToCharInfo > CharInfoList;
|
||||||
|
|
||||||
struct Style {
|
struct Style {
|
||||||
|
enum AlignmentType {
|
||||||
enum Alignment {
|
ALIGNMENT_LEFT = 0x00,
|
||||||
LEFT = 0x00,
|
ALIGNMENT_CENTER = 0x01,
|
||||||
CENTER = 0x01,
|
ALIGNMENT_RIGHT = 0x02,
|
||||||
RIGHT = 0x02,
|
ALIGNMENT_JUSTIFY = 0x03,
|
||||||
JUSTIFY = 0x03
|
ALIGNMENT_DEFAULT // for case if alignment is not setted by word
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned int istd; //Current style
|
// style Ids:
|
||||||
unsigned int istdNext; //Next style unless overruled
|
// (this is not full list of possible style ids, enum is used for using in switch-case)
|
||||||
bool hasPageBreakBefore;
|
enum StyleID {
|
||||||
unsigned int beforeIndent; //Vertical indent before paragraph
|
STYLE_H1 = 0x1,
|
||||||
unsigned int afterIndent; //Vertical indent after paragraph
|
STYLE_H2 = 0x2,
|
||||||
int leftIndent; //Left indent
|
STYLE_H3 = 0x3,
|
||||||
int firstLineIndent; //First line left indent
|
STYLE_USER = 0xFFE,
|
||||||
int rightIndent; //Right indent
|
STYLE_NIL = 0xFFF,
|
||||||
unsigned int alignment;
|
STYLE_INVALID = 0xFFFF
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned int StyleIdCurrent;
|
||||||
|
unsigned int StyleIdNext; // Next style unless overruled
|
||||||
|
|
||||||
|
bool HasPageBreakBefore;
|
||||||
|
unsigned int BeforeParagraphIndent; // Vertical indent before paragraph, pixels
|
||||||
|
unsigned int AfterParagraphIndent; // Vertical indent after paragraph, pixels
|
||||||
|
int LeftIndent;
|
||||||
|
int FirstLineIndent;
|
||||||
|
int RightIndent;
|
||||||
|
AlignmentType Alignment;
|
||||||
|
CharInfo CurrentCharInfo;
|
||||||
|
|
||||||
CharInfo charInfo;
|
|
||||||
Style();
|
Style();
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::pair<unsigned int, Style> CharPosToStyle;
|
typedef std::pair<unsigned int, Style> CharPosToStyle;
|
||||||
typedef std::vector<CharPosToStyle> StyleInfoList;
|
typedef std::vector<CharPosToStyle> StyleInfoList;
|
||||||
typedef std::vector<Style> StyleSheet;
|
typedef std::vector<Style> StyleSheet;
|
||||||
|
|
||||||
enum StyleID {
|
|
||||||
H1 = 0x1,
|
|
||||||
H2 = 0x2,
|
|
||||||
H3 = 0x3,
|
|
||||||
STI_USER = 0xFFE,
|
|
||||||
STI_NIL = 0xFFF,
|
|
||||||
ISTD_INVALID = 0xFFFF
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SectionInfo {
|
struct SectionInfo {
|
||||||
unsigned int charPos;
|
unsigned int CharPosition;
|
||||||
bool newPage;
|
bool IsNewPage;
|
||||||
|
|
||||||
SectionInfo();
|
SectionInfo();
|
||||||
};
|
};
|
||||||
typedef std::vector<SectionInfo> SectionInfoList;
|
typedef std::vector<SectionInfo> SectionInfoList;
|
||||||
|
|
||||||
struct Bookmark {
|
struct Bookmark {
|
||||||
unsigned int charPos;
|
unsigned int CharPosition;
|
||||||
std::string name;
|
std::string Name;
|
||||||
};
|
};
|
||||||
typedef std::vector<Bookmark> Bookmarks;
|
typedef std::vector<Bookmark> BookmarksList;
|
||||||
|
|
||||||
struct InlineImageInfo {
|
struct InlineImageInfo {
|
||||||
unsigned int dataPos;
|
unsigned int DataPosition;
|
||||||
|
|
||||||
InlineImageInfo();
|
InlineImageInfo();
|
||||||
};
|
};
|
||||||
typedef std::pair<unsigned int, InlineImageInfo> CharPosToInlineImageInfo;
|
typedef std::pair<unsigned int, InlineImageInfo> CharPosToInlineImageInfo;
|
||||||
typedef std::vector<CharPosToInlineImageInfo> InlineImageInfoList;
|
typedef std::vector<CharPosToInlineImageInfo> InlineImageInfoList;
|
||||||
|
|
||||||
struct FloatImageInfo {
|
struct FloatImageInfo {
|
||||||
unsigned int shapeID;
|
unsigned int ShapeId;
|
||||||
FloatImageInfo();
|
FloatImageInfo();
|
||||||
};
|
};
|
||||||
typedef std::pair<unsigned int, FloatImageInfo> CharPosToFloatImageInfo;
|
typedef std::pair<unsigned int, FloatImageInfo> CharPosToFloatImageInfo;
|
||||||
typedef std::vector<CharPosToFloatImageInfo> FloatImageInfoList;
|
typedef std::vector<CharPosToFloatImageInfo> FloatImageInfoList;
|
||||||
|
|
||||||
enum ImageType { //see p. 60 [MS-ODRAW]
|
enum ImageType { //see p. 60 [MS-ODRAW]
|
||||||
EMF = 0xF01A,
|
IMAGE_EMF = 0xF01A,
|
||||||
WMF = 0xF01B,
|
IMAGE_WMF = 0xF01B,
|
||||||
PICT = 0xF01C,
|
IMAGE_PICT = 0xF01C,
|
||||||
JPEG = 0xF01D,
|
IMAGE_JPEG = 0xF01D,
|
||||||
PNG = 0xF01E,
|
IMAGE_PNG = 0xF01E,
|
||||||
DIB = 0xF01F,
|
IMAGE_DIB = 0xF01F,
|
||||||
TIFF = 0xF029,
|
IMAGE_TIFF = 0xF029,
|
||||||
JPEG2 = 0xF02A
|
IMAGE_JPEG2 = 0xF02A
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -148,11 +153,11 @@ public:
|
||||||
const Pieces &getPieces() const;
|
const Pieces &getPieces() const;
|
||||||
const CharInfoList &getCharInfoList() const;
|
const CharInfoList &getCharInfoList() const;
|
||||||
const StyleInfoList &getStyleInfoList() const;
|
const StyleInfoList &getStyleInfoList() const;
|
||||||
const Bookmarks &getBookmarks() const;
|
const BookmarksList &getBookmarks() const;
|
||||||
const InlineImageInfoList &getInlineImageInfoList() const;
|
const InlineImageInfoList &getInlineImageInfoList() const;
|
||||||
const FloatImageInfoList &getFloatImageInfoList() const;
|
const FloatImageInfoList &getFloatImageInfoList() const;
|
||||||
|
|
||||||
ZLFileImage::Blocks getFloatImage(unsigned int shapeID) const;
|
ZLFileImage::Blocks getFloatImage(unsigned int shapeId) const;
|
||||||
ZLFileImage::Blocks getInlineImage(unsigned int dataPos) const;
|
ZLFileImage::Blocks getInlineImage(unsigned int dataPos) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -171,14 +176,14 @@ private: //readPieceTable helpers methods
|
||||||
|
|
||||||
private: //formatting reader helpers methods
|
private: //formatting reader helpers methods
|
||||||
static unsigned int getPrlLength(const char *grpprlBuffer, unsigned int byteNumber);
|
static unsigned int getPrlLength(const char *grpprlBuffer, unsigned int byteNumber);
|
||||||
static void getCharInfo(unsigned int chpxOffset, unsigned int istd, const char *grpprlBuffer, unsigned int bytes, CharInfo &charInfo);
|
static void getCharInfo(unsigned int chpxOffset, unsigned int styleId, const char *grpprlBuffer, unsigned int bytes, CharInfo &charInfo);
|
||||||
static void getStyleInfo(unsigned int papxOffset, const char *grpprlBuffer, unsigned int bytes, Style &styleInfo);
|
static void getStyleInfo(unsigned int papxOffset, const char *grpprlBuffer, unsigned int bytes, Style &styleInfo);
|
||||||
static void getSectionInfo(const char *grpprlBuffer, size_t bytes, SectionInfo §ionInfo);
|
static void getSectionInfo(const char *grpprlBuffer, size_t bytes, SectionInfo §ionInfo);
|
||||||
static bool getInlineImageInfo(unsigned int chpxOffset, const char *grpprlBuffer, unsigned int bytes, InlineImageInfo &pictureInfo);
|
static bool getInlineImageInfo(unsigned int chpxOffset, const char *grpprlBuffer, unsigned int bytes, InlineImageInfo &pictureInfo);
|
||||||
|
|
||||||
static Style getStyleFromStylesheet(unsigned int istd, const StyleSheet &stylesheet);
|
static Style getStyleFromStylesheet(unsigned int styleId, const StyleSheet &stylesheet);
|
||||||
static int getStyleIndex(unsigned int istd, const std::vector<bool> &isFilled, const StyleSheet &stylesheet);
|
static int getStyleIndex(unsigned int styleId, const std::vector<bool> &isFilled, const StyleSheet &stylesheet);
|
||||||
static unsigned int getIstdByCharPos(unsigned int offset, const StyleInfoList &styleInfoList);
|
static unsigned int getStyleIdByCharPos(unsigned int offset, const StyleInfoList &styleInfoList);
|
||||||
|
|
||||||
static bool offsetToCharPos(unsigned int offset, unsigned int &charPos, const Pieces &pieces);
|
static bool offsetToCharPos(unsigned int offset, unsigned int &charPos, const Pieces &pieces);
|
||||||
static bool readToBuffer(std::string &result, unsigned int offset, size_t length, OleStream &stream);
|
static bool readToBuffer(std::string &result, unsigned int offset, size_t length, OleStream &stream);
|
||||||
|
@ -207,7 +212,7 @@ private:
|
||||||
InlineImageInfoList myInlineImageInfoList;
|
InlineImageInfoList myInlineImageInfoList;
|
||||||
FloatImageInfoList myFloatImageInfoList;
|
FloatImageInfoList myFloatImageInfoList;
|
||||||
|
|
||||||
Bookmarks myBookmarks;
|
BookmarksList myBookmarks;
|
||||||
|
|
||||||
shared_ptr<OleStream> myDataStream;
|
shared_ptr<OleStream> myDataStream;
|
||||||
|
|
||||||
|
|
|
@ -178,7 +178,7 @@ void OleStreamReader::processInlineImage(OleMainStream &stream) {
|
||||||
}
|
}
|
||||||
while (myNextInlineImageInfoIndex < imageInfoList.size() && imageInfoList.at(myNextInlineImageInfoIndex).first == myCurCharPos) {
|
while (myNextInlineImageInfoIndex < imageInfoList.size() && imageInfoList.at(myNextInlineImageInfoIndex).first == myCurCharPos) {
|
||||||
OleMainStream::InlineImageInfo info = imageInfoList.at(myNextInlineImageInfoIndex).second;
|
OleMainStream::InlineImageInfo info = imageInfoList.at(myNextInlineImageInfoIndex).second;
|
||||||
ZLFileImage::Blocks list = stream.getInlineImage(info.dataPos);
|
ZLFileImage::Blocks list = stream.getInlineImage(info.DataPosition);
|
||||||
if (!list.empty()) {
|
if (!list.empty()) {
|
||||||
handleImage(list);
|
handleImage(list);
|
||||||
}
|
}
|
||||||
|
@ -197,7 +197,7 @@ void OleStreamReader::processFloatImage(OleMainStream &stream) {
|
||||||
}
|
}
|
||||||
while (myNextFloatImageInfoIndex < imageInfoList.size() && imageInfoList.at(myNextFloatImageInfoIndex).first == myCurCharPos) {
|
while (myNextFloatImageInfoIndex < imageInfoList.size() && imageInfoList.at(myNextFloatImageInfoIndex).first == myCurCharPos) {
|
||||||
OleMainStream::FloatImageInfo info = imageInfoList.at(myNextFloatImageInfoIndex).second;
|
OleMainStream::FloatImageInfo info = imageInfoList.at(myNextFloatImageInfoIndex).second;
|
||||||
ZLFileImage::Blocks list = stream.getFloatImage(info.shapeID);
|
ZLFileImage::Blocks list = stream.getFloatImage(info.ShapeId);
|
||||||
if (!list.empty()) {
|
if (!list.empty()) {
|
||||||
handleImage(list);
|
handleImage(list);
|
||||||
}
|
}
|
||||||
|
@ -219,16 +219,16 @@ void OleStreamReader::processStyles(OleMainStream &stream) {
|
||||||
if (!charInfoList.empty()) {
|
if (!charInfoList.empty()) {
|
||||||
while (myNextCharInfoIndex < charInfoList.size() && charInfoList.at(myNextCharInfoIndex).first == myCurCharPos) {
|
while (myNextCharInfoIndex < charInfoList.size() && charInfoList.at(myNextCharInfoIndex).first == myCurCharPos) {
|
||||||
OleMainStream::CharInfo info = charInfoList.at(myNextCharInfoIndex).second;
|
OleMainStream::CharInfo info = charInfoList.at(myNextCharInfoIndex).second;
|
||||||
handleFontStyle(info.fontStyle);
|
handleFontStyle(info.FontStyle);
|
||||||
++myNextCharInfoIndex;
|
++myNextCharInfoIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const OleMainStream::Bookmarks &bookmarksList = stream.getBookmarks();
|
const OleMainStream::BookmarksList &bookmarksList = stream.getBookmarks();
|
||||||
if (!bookmarksList.empty()) {
|
if (!bookmarksList.empty()) {
|
||||||
while (myNextBookmarkIndex < bookmarksList.size() && bookmarksList.at(myNextBookmarkIndex).charPos == myCurCharPos) {
|
while (myNextBookmarkIndex < bookmarksList.size() && bookmarksList.at(myNextBookmarkIndex).CharPosition == myCurCharPos) {
|
||||||
OleMainStream::Bookmark bookmark = bookmarksList.at(myNextBookmarkIndex);
|
OleMainStream::Bookmark bookmark = bookmarksList.at(myNextBookmarkIndex);
|
||||||
handleBookmark(bookmark.name);
|
handleBookmark(bookmark.Name);
|
||||||
++myNextBookmarkIndex;
|
++myNextBookmarkIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -241,24 +241,24 @@ bool OleStreamReader::fillBuffer(OleMainStream &stream) {
|
||||||
}
|
}
|
||||||
const OleMainStream::Piece &piece = pieces.at(myNextPieceNumber);
|
const OleMainStream::Piece &piece = pieces.at(myNextPieceNumber);
|
||||||
|
|
||||||
if (piece.type == OleMainStream::Piece::FOOTNOTE) {
|
if (piece.Type == OleMainStream::Piece::PIECE_FOOTNOTE) {
|
||||||
handlePageBreak();
|
handlePageBreak();
|
||||||
} else if (piece.type == OleMainStream::Piece::OTHER) {
|
} else if (piece.Type == OleMainStream::Piece::PIECE_OTHER) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!stream.seek(piece.offset, true)) {
|
if (!stream.seek(piece.Offset, true)) {
|
||||||
//TODO maybe in that case we should take next piece?
|
//TODO maybe in that case we should take next piece?
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
char *textBuffer = new char[piece.length];
|
char *textBuffer = new char[piece.Length];
|
||||||
size_t readedBytes = stream.read(textBuffer, piece.length);
|
size_t readedBytes = stream.read(textBuffer, piece.Length);
|
||||||
if (readedBytes != (unsigned int)piece.length) {
|
if (readedBytes != (unsigned int)piece.Length) {
|
||||||
ZLLogger::Instance().println("OleStreamReader", "not all bytes has been readed from piece");
|
ZLLogger::Instance().println("OleStreamReader", "not all bytes has been readed from piece");
|
||||||
}
|
}
|
||||||
|
|
||||||
myBuffer.clear();
|
myBuffer.clear();
|
||||||
if (!piece.isANSI) {
|
if (!piece.IsANSI) {
|
||||||
for (unsigned int i = 0; i < readedBytes; i += 2) {
|
for (unsigned int i = 0; i < readedBytes; i += 2) {
|
||||||
ZLUnicodeUtil::Ucs2Char ch = OleUtil::getU2Bytes(textBuffer, i);
|
ZLUnicodeUtil::Ucs2Char ch = OleUtil::getU2Bytes(textBuffer, i);
|
||||||
myBuffer.push_back(ch);
|
myBuffer.push_back(ch);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue