⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 docdecoder.cpp

📁 此文件为Word 格式文件.DOC转换为TXT文件的源代码。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		iNextVal = iValue / *q;
		if (*q == 2)		/* magic */
			iNextVal /= *(q += 2);
		if (iNumber + iNextVal >= iValue) {
			*outp++ = *++q;
			iNumber += iNextVal;
		} else {
			p++;
			iValue /= *p++;
		}
	}
} /* end of iInteger2Roman */


int
CDocDecoder::iInteger2Alpha(int iNumber, bool bUpperCase,
			   unsigned short *szOutput)
{
	unsigned short	*outp;
	char	cTmp;


	outp = szOutput;
	cTmp = bUpperCase ? 'A': 'a';
	if (iNumber <= 26) {
		iNumber -= 1;
		*outp++ = cTmp + iNumber;
	} else if (iNumber <= 26 + 26*26) {
		iNumber -= 26 + 1;
		*outp++ = cTmp + iNumber / 26;
		*outp++ = cTmp + iNumber % 26;
	} else if (iNumber <= 26 + 26*26 + 26*26*26) {
		iNumber -= 26 + 26*26 + 1;
		*outp++ = cTmp + iNumber / (26*26);
		*outp++ = cTmp + iNumber / 26 % 26;
		*outp++ = cTmp + iNumber % 26;
	}
	*outp = '\0';
	return (int)(outp - szOutput);
} /* end of iInteger2Alpha */


void
CDocDecoder::vDestroyNotesInfoLists(void)
{
	/* Free the lists and reset all control variables */
	aiEndnoteList = (int *)xfree(aiEndnoteList);
	aiFootnoteList = (int *)xfree(aiFootnoteList);
	iEndnoteListLength = 0;
	iFootnoteListLength = 0;
} /* end of vDestroyNotesInfoLists */


void
CDocDecoder::vGet6FootnotesInfo(unsigned char *pFile, int iStartBlock,
				   const int *aiBBD, int iBBDLen,
				   const unsigned char *aucHeader)
{
	unsigned char	*aucBuffer;
	int	iBeginOfText, iBeginFootnoteInfo, iFootnoteInfoLen;
	int	iIndex, iOffset, iFileOffset;


	iBeginOfText = (int)ulGetLong(0x18, aucHeader);
	iBeginFootnoteInfo = (int)ulGetLong(0x68, aucHeader);
	iFootnoteInfoLen = (int)ulGetLong(0x6c, aucHeader);

	if (iFootnoteInfoLen < 10) {
		return;
	}

	aucBuffer = (unsigned char *)xmalloc(iFootnoteInfoLen);
	if (!bReadBuffer(pFile, iStartBlock,
		aiBBD, iBBDLen, BIG_BLOCK_SIZE,
		aucBuffer, iBeginFootnoteInfo, iFootnoteInfoLen)) {
			aucBuffer = (unsigned char *)xfree(aucBuffer);
			return;
		}

		iFootnoteListLength = (iFootnoteInfoLen - 4) / 6;

		aiFootnoteList = (int *)xmalloc(sizeof(int) * iFootnoteListLength);

		for (iIndex = 0; iIndex < iFootnoteListLength; iIndex++) {
			iOffset = (int)ulGetLong(iIndex * 4, aucBuffer);
			iFileOffset = iTextOffset2FileOffset(iOffset + iBeginOfText);
			aiFootnoteList[iIndex] = iFileOffset;
		}
		aucBuffer = (unsigned char *)xfree(aucBuffer);
} /* end of vGet6FootnotesInfo */


void
CDocDecoder::vGet6EndnotesInfo(unsigned char *pFile, int iStartBlock,
				  const int *aiBBD, int iBBDLen,
				  const unsigned char *aucHeader)
{
	unsigned char	*aucBuffer;
	int	iBeginOfText, iBeginEndnoteInfo, iEndnoteInfoLen;
	int	iIndex, iOffset, iFileOffset;


	iBeginOfText = (int)ulGetLong(0x18, aucHeader);
	iBeginEndnoteInfo = (int)ulGetLong(0x1d2, aucHeader);
	iEndnoteInfoLen = (int)ulGetLong(0x1d6, aucHeader);

	if (iEndnoteInfoLen < 10) {
		return;
	}

	aucBuffer = (unsigned char *)xmalloc(iEndnoteInfoLen);
	if (!bReadBuffer(pFile, iStartBlock,
		aiBBD, iBBDLen, BIG_BLOCK_SIZE,
		aucBuffer, iBeginEndnoteInfo, iEndnoteInfoLen)) {
			aucBuffer = (unsigned char *)xfree(aucBuffer);
			return;
		}

		iEndnoteListLength = (iEndnoteInfoLen - 4) / 6;

		aiEndnoteList = (int *)xmalloc(sizeof(int) * iEndnoteListLength);

		for (iIndex = 0; iIndex < iEndnoteListLength; iIndex++) {
			iOffset = (int)ulGetLong(iIndex * 4, aucBuffer);
			iFileOffset = iTextOffset2FileOffset(iOffset + iBeginOfText);
			aiEndnoteList[iIndex] = iFileOffset;
		}
		aucBuffer = (unsigned char *)xfree(aucBuffer);
} /* end of vGet6EndnotesInfo */


void
CDocDecoder::vGet6NotesInfo(unsigned char *pFile, int iStartBlock,
			   const int *aiBBD, int iBBDLen,
			   const unsigned char *aucHeader)
{
	vGet6FootnotesInfo(pFile, iStartBlock,
		aiBBD, iBBDLen, aucHeader);
	vGet6EndnotesInfo(pFile, iStartBlock,
		aiBBD, iBBDLen, aucHeader);
} /* end of vGet6NotesInfo */


void
CDocDecoder::vGet8FootnotesInfo(unsigned char *pFile, const pps_info_type *pPPS,
				   const int *aiBBD, int iBBDLen, const int *aiSBD, int iSBDLen,
				   const unsigned char *aucHeader)
{
	const int	*aiBlockDepot;
	unsigned char	*aucBuffer;
	int	iTableStartBlock, iTableSize, iBlockDepotLen, iBlockSize;
	int	iBeginOfText, iBeginFootnoteInfo, iFootnoteInfoLen;
	int	iIndex, iOffset, iFileOffset;
	unsigned short	usDocStatus;

	iBeginOfText = (int)ulGetLong(0x18, aucHeader);
	iBeginFootnoteInfo = (int)ulGetLong(0xaa, aucHeader);
	iFootnoteInfoLen = (int)ulGetLong(0xae, aucHeader);

	if (iFootnoteInfoLen < 10) {
		return;
	}

	/* Use 0Table or 1Table? */
	usDocStatus = usGetWord(0x0a, aucHeader);
	if (usDocStatus & BIT(9)) {
		iTableStartBlock = pPPS->t1Table.iSb;
		iTableSize = pPPS->t1Table.iSize;
	} else {
		iTableStartBlock = pPPS->t0Table.iSb;
		iTableSize = pPPS->t0Table.iSize;
	}
	if (iTableStartBlock < 0) {
		return;
	}
	if (iTableSize < MIN_SIZE_FOR_BBD_USE) {
		/* Use the Small Block Depot */
		aiBlockDepot = aiSBD;
		iBlockDepotLen = iSBDLen;
		iBlockSize = SMALL_BLOCK_SIZE;
	} else {
		/* Use the Big Block Depot */
		aiBlockDepot = aiBBD;
		iBlockDepotLen = iBBDLen;
		iBlockSize = BIG_BLOCK_SIZE;
	}
	aucBuffer = (unsigned char *)xmalloc(iFootnoteInfoLen);
	if (!bReadBuffer(pFile, iTableStartBlock,
		aiBlockDepot, iBlockDepotLen, iBlockSize,
		aucBuffer, iBeginFootnoteInfo, iFootnoteInfoLen)) {
			aucBuffer = (unsigned char *)xfree(aucBuffer);
			return;
		}
		iFootnoteListLength = (iFootnoteInfoLen - 4) / 6;

		aiFootnoteList = (int *)xmalloc(sizeof(int) * iFootnoteListLength);

		for (iIndex = 0; iIndex < iFootnoteListLength; iIndex++) {
			iOffset = (int)ulGetLong(iIndex * 4, aucBuffer);
			iFileOffset = iTextOffset2FileOffset(iOffset + iBeginOfText);
			aiFootnoteList[iIndex] = iFileOffset;
		}
		aucBuffer = (unsigned char *)xfree(aucBuffer);
} /* end of vGet8FootnotesInfo */


void
CDocDecoder::vGet8EndnotesInfo(unsigned char *pFile, const pps_info_type *pPPS,
				  const int *aiBBD, int iBBDLen, const int *aiSBD, int iSBDLen,
				  const unsigned char *aucHeader)
{
	const int	*aiBlockDepot;
	unsigned char	*aucBuffer;
	int	iTableStartBlock, iTableSize, iBlockDepotLen, iBlockSize;
	int	iBeginOfText, iBeginEndnoteInfo, iEndnoteInfoLen;
	int	iIndex, iOffset, iFileOffset;
	unsigned short	usDocStatus;

	iBeginOfText = (int)ulGetLong(0x18, aucHeader);
	iBeginEndnoteInfo = (int)ulGetLong(0x20a, aucHeader);
	iEndnoteInfoLen = (int)ulGetLong(0x20e, aucHeader);

	if (iEndnoteInfoLen < 10) {
		return;
	}

	/* Use 0Table or 1Table? */
	usDocStatus = usGetWord(0x0a, aucHeader);
	if (usDocStatus & BIT(9)) {
		iTableStartBlock = pPPS->t1Table.iSb;
		iTableSize = pPPS->t1Table.iSize;
	} else {
		iTableStartBlock = pPPS->t0Table.iSb;
		iTableSize = pPPS->t0Table.iSize;
	}
	if (iTableStartBlock < 0) {
		return;
	}
	if (iTableSize < MIN_SIZE_FOR_BBD_USE) {
		/* Use the Small Block Depot */
		aiBlockDepot = aiSBD;
		iBlockDepotLen = iSBDLen;
		iBlockSize = SMALL_BLOCK_SIZE;
	} else {
		/* Use the Big Block Depot */
		aiBlockDepot = aiBBD;
		iBlockDepotLen = iBBDLen;
		iBlockSize = BIG_BLOCK_SIZE;
	}
	aucBuffer = (unsigned char *)xmalloc(iEndnoteInfoLen);
	if (!bReadBuffer(pFile, iTableStartBlock,
		aiBlockDepot, iBlockDepotLen, iBlockSize,
		aucBuffer, iBeginEndnoteInfo, iEndnoteInfoLen)) {
			aucBuffer = (unsigned char *)xfree(aucBuffer);
			return;
		}
		iEndnoteListLength = (iEndnoteInfoLen - 4) / 6;

		aiEndnoteList = (int *)xmalloc(sizeof(int) * iEndnoteListLength);

		for (iIndex = 0; iIndex < iEndnoteListLength; iIndex++) {
			iOffset = (int)ulGetLong(iIndex * 4, aucBuffer);
			iFileOffset = iTextOffset2FileOffset(iOffset + iBeginOfText);
			aiEndnoteList[iIndex] = iFileOffset;
		}
		aucBuffer = (unsigned char *)xfree(aucBuffer);
} /* end of vGet8EndnotesInfo */


void
CDocDecoder::vGet8NotesInfo(unsigned char *pFile, const pps_info_type *pPPS,
			   const int *aiBBD, int iBBDLen, const int *aiSBD, int iSBDLen,
			   const unsigned char *aucHeader)
{
	vGet8FootnotesInfo(pFile, pPPS,
		aiBBD, iBBDLen, aiSBD, iSBDLen, aucHeader);
	vGet8EndnotesInfo(pFile, pPPS,
		aiBBD, iBBDLen, aiSBD, iSBDLen, aucHeader);
} /* end of vGet8NotesInfo */


void
CDocDecoder::vGetNotesInfo(unsigned char *pFile, const pps_info_type *pPPS,
			  const int *aiBBD, int iBBDLen, const int *aiSBD, int iSBDLen,
			  const unsigned char *aucHeader, int iWordVersion)
{

	switch (iWordVersion) {
	case 6:
	case 7:
		vGet6NotesInfo(pFile, pPPS->tWordDocument.iSb,
			aiBBD, iBBDLen, aucHeader);
		break;
	case 8:
		vGet8NotesInfo(pFile, pPPS,
			aiBBD, iBBDLen, aiSBD, iSBDLen, aucHeader);
		break;
	default:
//		werr(0, "Sorry, no notes information");
		break;
	}
} /* end of vGetNotesInfo */


notetype_enum
CDocDecoder::eGetNotetype(int iFileOffset)
{
	int	iIndex;


	/* Go for the easy answer first */
	if (iFootnoteListLength <= 0 && iEndnoteListLength <= 0) {
		return notetype_is_unknown;
	}
	if (iEndnoteListLength <= 0) {
		return notetype_is_footnote;
	}
	if (iFootnoteListLength <= 0) {
		return notetype_is_endnote;
	}
	/* No easy answer, so we search */
	for (iIndex = 0; iIndex < iFootnoteListLength; iIndex++) {
		if (aiFootnoteList[iIndex] == iFileOffset) {
			return notetype_is_footnote;
		}
	}
	for (iIndex = 0; iIndex < iEndnoteListLength; iIndex++) {
		if (aiEndnoteList[iIndex] == iFileOffset) {
			return notetype_is_endnote;
		}
	}
	/* Not found */
	return notetype_is_unknown;
} /* end of eGetNotetype */


void
CDocDecoder::vString2Diagram(diagram_type *pDiag, output_type *pAnchor)
{
	output_type	*pOutput;
	int		iWidth;
	unsigned char	ucMaxFontsize;


	/* Compute the maximum fontsize in this string */
	ucMaxFontsize = MIN_FONT_SIZE;
	for (pOutput = pAnchor; pOutput != NULL; pOutput = pOutput->pNext) {
		if (pOutput->ucFontsize > ucMaxFontsize) {
			ucMaxFontsize = pOutput->ucFontsize;
		}
	}
	/* Output all substrings */
	for (pOutput = pAnchor; pOutput != NULL; pOutput = pOutput->pNext) {
		iWidth = iMilliPoints2DrawUnits(pOutput->iStringWidth);
		vSubstring2Diagram(pDiag, pOutput->szStorage,
			pOutput->iNextFree, iWidth, pOutput->iColour,
			pOutput->ucFontstyle, pOutput->tFontRef,
			pOutput->ucFontsize, ucMaxFontsize);
	}
	/* Goto the start of the next line */
//cjg remove	vMove2NextLine(pDiag, pAnchor->tFontRef, ucMaxFontsize);
} /* end of vString2Diagram */


void
CDocDecoder::vResetStyles(void)
{
	memset(aiHdrCounter, 0, sizeof(aiHdrCounter));
} /* end of vResetStyles */


int
CDocDecoder::iStyle2Window(unsigned short *szLine, 
			  const style_block_type *pStyleInfo)
{
	unsigned short	*pcTxt;
	int	iIndex, iStyleIndex;
	char cs[64];


	pcTxt = szLine;
	if ((int)pStyleInfo->ucStyle >= 1 && (int)pStyleInfo->ucStyle <= 9) {
		iStyleIndex = (int)pStyleInfo->ucStyle - 1;
		for (iIndex = 0; iIndex < 9; iIndex++) {
			if (iIndex == iStyleIndex) {
				aiHdrCounter[iIndex]++;
			} else if (iIndex > iStyleIndex) {
				aiHdrCounter[iIndex] = 0;
			} else if (aiHdrCounter[iIndex] < 1) {
				aiHdrCounter[iIndex] = 1;
			}
			if (iIndex <= iStyleIndex) {
				sprintf(cs,"%d",aiHdrCounter[iIndex]);
				pcTxt += toUnicodeStr(pcTxt,(unsigned char *)cs);

				if (iIndex < iStyleIndex) {
					*pcTxt++ = '.';
				}
			}
		}
		*pcTxt++ = ' ';
	}
	*pcTxt = '\0';
	return (int)(pcTxt - szLine);
} /* end of iStyle2Window */

int 
CDocDecoder::shortncpy(unsigned short *d,unsigned short *s,int n)
{
	int i;
	for(i=0;i<n && s[i]!=0;i++)
		d[i]=s[i];
	return i;
}

int 
CDocDecoder::shortlen(unsigned short *s)
{
	int i;
	for(i=0;s[i];i++)NULL;
	return i;
}

unsigned short* 
CDocDecoder::shortrchr(unsigned short* s,unsigned short c)
{
	int i;
	int lastpos=-1;
	for(i=0;s[i]!=0;i++)
		if(s[i]==c)lastpos=i;
	if(lastpos==-1)	return NULL;
	return s+lastpos;
}

unsigned short* 
CDocDecoder::shortchr(unsigned short* s,unsigned short c)
{
	int i;
	for(i=0;s[i]!=0;i++)
		if(s[i]==c)return s+i;
	return NULL;
}

bool 
CDocDecoder::testspace(unsigned short c)
{
	if(c==0x20 )return 1;
	return 0;
}


int
CDocDecoder::iGet6InfoLength(int iByteNbr, const unsigned char *aucFpage)
{
	int	iTmp, iDel, iAdd;

	switch (ucGetByte(iByteNbr, aucFpage)) {
	case 0x02: case 0x10: case 0x11: case 0x13:
	case 0x15: case 0x16: case 0x1b: case 0x1c:
	case 0x26: case 0x27: case 0x28: case 0x29:
	case 0x2a: case 0x2b: case 0x2d: case 0x2e:
	case 0x2f: case 0x30: case 0x31: case 0x50:
	case 0x5d: case 0x60: case 0x61: case 0x63:
	case 0x65: case 0x69: case 0x6a: case 0x6b:
	case 0x90: case 0xa4: case 0xa5: case 0xb6:
	case 0xb8: case 0xbd: case 0xc3: case 0xc5:
	case 0xc6:
		return 3;
	case 0x03: case 0x0c: case 0x0f: case 0x51:
	case 0x67: case 0x6c: case 0xbc: case 0xbe:
	case 0xbf:
		return 2 + (int)ucGetByte(iByteNbr + 1, aucFpage);
	case 0x14: case 0x49: case 0x4a: case 0xc0:
	case 0xc2: case 0xc4: case 0xc8:
		return 5;
	case 0x17:
		iTmp = (int)ucGetByte(iByteNbr + 1, aucFpage);
		if (iTmp == 255) {
			iDel = (int)ucGetByte(iByteNbr + 2, aucFpage);
			iAdd = (int)ucGetByte(
					iByteNbr + 3 + iDel * 4, aucFpage);
			iTmp = 2 + iDel * 4 + iAdd * 3;
		}
		return 2 + iTmp;
	case 0x44: case 0xc1: case 0xc7:
		return 6;
	case 0x5f: case 0x88: case 0x89:
		return 4;
	case 0x78:
		return 14;
	case 0xbb:
		return 13;
	default:
		return 2;
	}
} /* end of iGet6InfoLength */


row_info_enum
CDocDecoder::eGet6RowInfo(int iFodo, const unsigned char *aucFpage, row_block_type *pRow)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -