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