📄 docdecoder.cpp
字号:
{
int iBytes, iFodoOff, iInfoLen;
int iIndex, iSize, iCol;
int iPosCurr, iPosPrev;
bool bFound18, bFound19, bFoundBE;
iBytes = 2 * (int)ucGetByte(iFodo, aucFpage);
iFodoOff = 3;
bFound18 = false;
bFound19 = false;
bFoundBE = false;
while (iBytes >= iFodoOff + 1) {
iInfoLen = 0;
switch (ucGetByte(iFodo + iFodoOff, aucFpage)) {
case 0x18:
if (ucGetByte(iFodo + iFodoOff + 1,
aucFpage) == 0x01) {
bFound18 = true;
}
break;
case 0x19:
if (ucGetByte(iFodo + iFodoOff + 1,
aucFpage) == 0x01) {
bFound19 = true;
}
break;
case 0xbe:
iSize = (int)ucGetByte(iFodo + iFodoOff + 1, aucFpage);
if (iSize < 6 || iBytes < iFodoOff + 7) {
iInfoLen = 1;
break;
}
iCol = (int)ucGetByte(iFodo + iFodoOff + 3, aucFpage);
if (iCol < 1 ||
iBytes < iFodoOff + 3 + (iCol + 1) * 2) {
iInfoLen = 1;
break;
}
if (iCol >= elementsof(pRow->asColumnWidth)) {
return found_nothing;
// werr(1, "The number of columns is corrupt");
}
pRow->ucNumberOfColumns = iCol;
pRow->iColumnWidthSum = 0;
iPosPrev = (int)(short)usGetWord(
iFodo + iFodoOff + 4,
aucFpage);
for (iIndex = 0; iIndex < iCol; iIndex++) {
iPosCurr = (int)(short)usGetWord(
iFodo + iFodoOff + 6 + iIndex * 2,
aucFpage);
pRow->asColumnWidth[iIndex] =
iPosCurr - iPosPrev;
pRow->iColumnWidthSum +=
pRow->asColumnWidth[iIndex];
iPosPrev = iPosCurr;
}
bFoundBE = true;
break;
default:
break;
}
if (iInfoLen <= 0) {
iInfoLen =
iGet6InfoLength(iFodo + iFodoOff, aucFpage);
}
iFodoOff += iInfoLen;
}
if (bFound18 && bFound19 && bFoundBE) {
return found_end_of_row;
}
if (bFound18) {
return found_a_cell;
}
return found_nothing;
} /* end of eGet6RowInfo */
bool
CDocDecoder::bGet6StyleInfo(int iFodo, const unsigned char *aucFpage,
style_block_type *pStyle)
{
int iBytes, iFodoOff, iInfoLen;
int iTmp, iDel, iAdd;
iBytes = 2 * (int)ucGetByte(iFodo, aucFpage);
iFodoOff = 3;
if (iBytes < 1) {
return false;
}
(void)memset(pStyle, 0, sizeof(*pStyle));
pStyle->ucStyle = ucGetByte(iFodo + 1, aucFpage);
while (iBytes >= iFodoOff + 1) {
iInfoLen = 0;
switch (ucGetByte(iFodo + iFodoOff, aucFpage)) {
case 0x05:
pStyle->ucAlignment = ucGetByte(
iFodo + iFodoOff + 1, aucFpage);
break;
case 0x0c:
iTmp = (int)ucGetByte(
iFodo + iFodoOff + 1, aucFpage);
if (iTmp >= 1) {
pStyle->ucListType = ucGetByte(
iFodo + iFodoOff + 2, aucFpage);
pStyle->bInList = true;
}
if (iTmp >= 21) {
pStyle->ucListCharacter = ucGetByte(
iFodo + iFodoOff + 22, aucFpage);
}
break;
case 0x0d:
iTmp = (int)ucGetByte(
iFodo + iFodoOff + 1, aucFpage);
switch (iTmp) {
case 0x0c:
pStyle->bUnmarked = true;
/* No break or return */
case 0x0a:
case 0x0b:
pStyle->bInList = true;
break;
default:
break;
}
break;
case 0x0f:
iTmp = (int)ucGetByte(iFodo + iFodoOff + 1, aucFpage);
if (iTmp < 2) {
iInfoLen = 1;
break;
}
iDel = (int)ucGetByte(iFodo + iFodoOff + 2, aucFpage);
if (iTmp < 2 + 2 * iDel) {
iInfoLen = 1;
break;
}
iAdd = (int)ucGetByte(
iFodo + iFodoOff + 3 + 2 * iDel, aucFpage);
if (iTmp < 2 + 2 * iDel + 2 * iAdd) {
iInfoLen = 1;
break;
}
break;
case 0x10:
pStyle->sRightIndent = (short)usGetWord(
iFodo + iFodoOff + 1, aucFpage);
break;
case 0x11:
pStyle->sLeftIndent = (short)usGetWord(
iFodo + iFodoOff + 1, aucFpage);
break;
case 0x12:
iTmp = (short)usGetWord(iFodo + iFodoOff + 1, aucFpage);
pStyle->sLeftIndent += iTmp;
if (pStyle->sLeftIndent < 0) {
pStyle->sLeftIndent = 0;
}
break;
default:
break;
}
if (iInfoLen <= 0) {
iInfoLen =
iGet6InfoLength(iFodo + iFodoOff, aucFpage);
}
iFodoOff += iInfoLen;
}
return true;
} /* end of bGet6StyleInfo */
void
CDocDecoder::vGet6ParInfo(unsigned char *pFile, int iStartBlock,
const int *aiBBD, int iBBDLen,
const unsigned char *aucHeader)
{
row_block_type tRow;
style_block_type tStyle;
unsigned short *ausParfPage;
unsigned char *aucBuffer;
size_t tSize;
int iLenOld, iLen;
int iParmOffset, iParmOffsetFirst, iParmOffsetLast;
int iIndex, iIndex2, iCount, iOffset, iNbr, iFodo;
int iParfFirstPage, iBeginParfInfo,iParfInfoLen, iParfPageNum;
unsigned char aucFpage[BIG_BLOCK_SIZE];
iBeginParfInfo = (int)ulGetLong(0xc0, aucHeader);
iParfInfoLen = (int)ulGetLong(0xc4, aucHeader);
aucBuffer = (unsigned char *)xmalloc(iParfInfoLen);
if (!bReadBuffer(pFile, iStartBlock,
aiBBD, iBBDLen, BIG_BLOCK_SIZE,
aucBuffer, iBeginParfInfo, iParfInfoLen)) {
aucBuffer = (unsigned char *)xfree(aucBuffer);
return;
}
iLen = (iParfInfoLen - 4) / 6;
tSize = iLen * sizeof(unsigned short);
ausParfPage = (unsigned short *)xmalloc(tSize);
for (iIndex = 0, iOffset = (iLen + 1) * 4;
iIndex < iLen;
iIndex++, iOffset += 2) {
ausParfPage[iIndex] = usGetWord(iOffset, aucBuffer);
}
aucBuffer = (unsigned char *)xfree(aucBuffer);
aucBuffer = NULL;
iParfPageNum = (int)usGetWord(0x190, aucHeader);
if (iLen < iParfPageNum) {
/* Replace ParfPage by a longer version */
iLenOld = iLen;
iParfFirstPage = (int)usGetWord(0x18c, aucHeader);
iLen += iParfPageNum - 1;
tSize = iLen * sizeof(unsigned short);
ausParfPage = (unsigned short *)xrealloc(ausParfPage, tSize);
/* Add new values */
iCount = iParfFirstPage + 1;
for (iIndex = iLenOld; iIndex < iLen; iIndex++) {
ausParfPage[iIndex] = iCount;
iCount++;
}
}
(void)memset(&tStyle, 0, sizeof(tStyle));
(void)memset(&tRow, 0, sizeof(tRow));
iParmOffsetFirst = -1;
for (iIndex = 0; iIndex < iLen; iIndex++) {
if (!bReadBuffer(pFile, iStartBlock,
aiBBD, iBBDLen, BIG_BLOCK_SIZE,
aucFpage,
(int)ausParfPage[iIndex] * BIG_BLOCK_SIZE,
BIG_BLOCK_SIZE)) {
break;
}
iNbr = (int)ucGetByte(0x1ff, aucFpage);
for (iIndex2 = 0; iIndex2 < iNbr; iIndex2++) {
iFodo = 2 * (int)ucGetByte(
(iNbr + 1) * 4 + iIndex2 * 7, aucFpage);
if (iFodo <= 0) {
continue;
}
if (bGet6StyleInfo(iFodo, aucFpage, &tStyle)) {
iParmOffset = (int)ulGetLong(
iIndex2 * 4, aucFpage);
tStyle.iOffset = iTextOffset2FileOffset(
iParmOffset);
vAdd2StyleInfoList(&tStyle);
(void)memset(&tStyle, 0, sizeof(tStyle));
}
switch (eGet6RowInfo(iFodo, aucFpage, &tRow)) {
case found_a_cell:
if (iParmOffsetFirst >= 0) {
break;
}
iParmOffsetFirst = (int)ulGetLong(
iIndex2 * 4, aucFpage);
tRow.iOffsetStart = iTextOffset2FileOffset(
iParmOffsetFirst);
break;
case found_end_of_row:
iParmOffsetLast = (int)ulGetLong(
iIndex2 * 4, aucFpage);
tRow.iOffsetEnd = iTextOffset2FileOffset(
iParmOffsetLast);
vAdd2RowInfoList(&tRow);
(void)memset(&tRow, 0, sizeof(tRow));
iParmOffsetFirst = -1;
break;
default:
break;
}
}
}
ausParfPage = (unsigned short *)xfree(ausParfPage);
} /* end of vGet6ParInfo */
int
CDocDecoder::iGet8InfoLength(int iByteNbr, const unsigned char *aucFpage)
{
int iTmp, iDel, iAdd;
unsigned short usOpCode;
usOpCode = usGetWord(iByteNbr, aucFpage);
switch (usOpCode & 0xe000) {
case 0x0000: case 0x2000:
return 3;
case 0x4000: case 0x8000: case 0xa000:
return 4;
case 0xe000:
return 5;
case 0x6000:
return 6;
case 0xc000:
iTmp = (int)ucGetByte(iByteNbr + 2, aucFpage);
if (usOpCode == 0xc615 && iTmp == 255) {
iDel = (int)ucGetByte(iByteNbr + 3, aucFpage);
iAdd = (int)ucGetByte(
iByteNbr + 4 + iDel * 4, aucFpage);
iTmp = 2 + iDel * 4 + iAdd * 3;
}
return 3 + iTmp;
default:
return 1;
}
} /* end of iGet8InfoLength */
row_info_enum
CDocDecoder::eGet8RowInfo(int iFodo, const unsigned char *aucFpage, row_block_type *pRow)
{
int iBytes, iFodoOff, iInfoLen;
int iIndex, iSize, iCol;
int iPosCurr, iPosPrev;
bool bFound2416, bFound2417, bFoundd608;
iBytes = 2 * (int)ucGetByte(iFodo, aucFpage);
iFodoOff = 3;
if (iBytes == 0) {
iFodo++;
iBytes = 2 * (int)ucGetByte(iFodo, aucFpage);
}
bFound2416 = false;
bFound2417 = false;
bFoundd608 = false;
while (iBytes >= iFodoOff + 2) {
iInfoLen = 0;
switch (usGetWord(iFodo + iFodoOff, aucFpage)) {
case 0x2416:
if (ucGetByte(iFodo + iFodoOff + 2,
aucFpage) == 0x01) {
bFound2416 = true;
}
break;
case 0x2417:
if (ucGetByte(iFodo + iFodoOff + 2,
aucFpage) == 0x01) {
bFound2417 = true;
}
break;
case 0xd608:
iSize = (int)ucGetByte(iFodo + iFodoOff + 2, aucFpage);
if (iSize < 6 || iBytes < iFodoOff + 8) {
iInfoLen = 2;
break;
}
iCol = (int)ucGetByte(iFodo + iFodoOff + 4, aucFpage);
if (iCol < 1 ||
iBytes < iFodoOff + 4 + (iCol + 1) * 2) {
iInfoLen = 2;
break;
}
if (iCol >= elementsof(pRow->asColumnWidth)) {
return found_nothing;
// werr(1, "The number of columns is corrupt");
}
pRow->ucNumberOfColumns = iCol;
pRow->iColumnWidthSum = 0;
iPosPrev = (int)(short)usGetWord(
iFodo + iFodoOff + 5,
aucFpage);
for (iIndex = 0; iIndex < iCol; iIndex++) {
iPosCurr = (int)(short)usGetWord(
iFodo + iFodoOff + 7 + iIndex * 2,
aucFpage);
pRow->asColumnWidth[iIndex] =
iPosCurr - iPosPrev;
pRow->iColumnWidthSum +=
pRow->asColumnWidth[iIndex];
iPosPrev = iPosCurr;
}
bFoundd608 = true;
break;
default:
break;
}
if (iInfoLen <= 0) {
iInfoLen =
iGet8InfoLength(iFodo + iFodoOff, aucFpage);
}
iFodoOff += iInfoLen;
}
if (bFound2416 && bFound2417 && bFoundd608) {
return found_end_of_row;
}
if (bFound2416) {
return found_a_cell;
}
return found_nothing;
} /* end of eGet8RowInfo */
bool
CDocDecoder::bGet8StyleInfo(int iFodo, const unsigned char *aucFpage,
style_block_type *pStyle)
{
int iBytes, iFodoOff, iInfoLen;
int iTmp, iDel, iAdd;
iBytes = 2 * (int)ucGetByte(iFodo, aucFpage);
iFodoOff = 3;
if (iBytes == 0) {
iFodo++;
iBytes = 2 * (int)ucGetByte(iFodo, aucFpage);
}
if (iBytes < 2) {
return false;
}
(void)memset(pStyle, 0, sizeof(*pStyle));
iTmp = usGetWord(iFodo + 1, aucFpage);
if (iTmp >= 0 && iTmp <= UCHAR_MAX) {
pStyle->ucStyle = (unsigned char)iTmp;
}
while (iBytes >= iFodoOff + 2) {
iInfoLen = 0;
switch (usGetWord(iFodo + iFodoOff, aucFpage)) {
case 0x2403:
pStyle->ucAlignment = ucGetByte(
iFodo + iFodoOff + 2, aucFpage);
break;
case 0x260a:
pStyle->bInList = true;
pStyle->ucListLevel =
ucGetByte(iFodo + iFodoOff + 2, aucFpage);
break;
case 0x460b:
break;
case 0x4610:
iTmp = (short)usGetWord(iFodo + iFodoOff + 2, aucFpage);
pStyle->sLeftIndent += iTmp;
if (pStyle->sLeftIndent < 0) {
pStyle->sLeftIndent = 0;
}
break;
case 0x6c0d:
iTmp = (int)ucGetByte(iFodo + iFodoOff + 2, aucFpage);
if (iTmp < 2) {
iInfoLen = 1;
break;
}
iDel = (int)ucGetByte(iFodo + iFodoOff + 3, aucFpage);
if (iTmp < 2 + 2 * iDel) {
iInfoLen = 1;
break;
}
iAdd = (int)ucGetByte(
iFodo + iFodoOff + 4 + 2 * iDel, aucFpage);
if (iTmp < 2 + 2 * iDel + 2 * iAdd) {
iInfoLen = 1;
break;
}
break;
case 0x840e:
pStyle->sRightIndent = (short)usGetWord(
iFodo + iFodoOff + 2, aucFpage);
break;
case 0x840f:
pStyle->sLeftIndent = (short)usGetWord(
iFodo + iFodoOff + 2, aucFpage);
break;
default:
break;
}
if (iInfoLen <= 0) {
iInfoLen =
iGet8InfoLength(iFodo + iFodoOff, aucFpage);
}
iFodoOff += iInfoLen;
}
return true;
} /* end of bGet8StyleInfo */
void
CDocDecoder::vGet8ParInfo(unsigned char *pFile, const pps_info_type *pPPS,
const int *aiBBD, int iBBDLen, const int *aiSBD, int iSBDLen,
const unsigned char *aucHeader)
{
row_block_type tRow;
style_block_type tStyle;
const int *aiBlockDepot;
int *aiParfPage;
unsigned char *aucBuffer;
size_t tSize;
int iTableStartBlock, iTableSize, iBlockDepotLen, iBlockSize;
int iLen, iOffset;
int iParmOffset, iParmOffsetFirst, iParmOffsetLast;
int iIndex, iIndex2, iNbr, iFodo;
int iBeginParfInfo, iParfInfoLen;
unsigned short usDocStatus;
unsigned char aucFpage[BIG_BLOCK_SI
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -