/*
* hdrftrlist.c
* Copyright (C) 2004,2005 A.J. van Os; Released under GNU GPL
*
* Description:
* Build, read and destroy list(s) of Word Header/footer information
*/
/*
* Private structures to hide the way the information
* is stored from the rest of the program
*/
typedef struct hdrftr_local_tag {
hdrftr_block_type tInfo;
ULONG ulCharPosStart;
ULONG ulCharPosNext;
BOOL bUseful;
BOOL bTextOriginal;
} hdrftr_local_type;
typedef struct hdrftr_mem_tag {
hdrftr_local_type atElement[6];
} hdrftr_mem_type;
/* Variables needed to write the Header/footer Information List */
static hdrftr_mem_type *pHdrFtrList = NULL;
static size_t tHdrFtrLen = 0;
/*
* vDestroyHdrFtrInfoList - destroy the Header/footer Information List
*/
void
vDestroyHdrFtrInfoList(void)
{
hdrftr_mem_type *pRecord;
output_type *pCurr, *pNext;
size_t tHdrFtr, tIndex;
DBG_MSG("vDestroyHdrFtrInfoList");
/* Free the Header/footer Information List */
for (tHdrFtr = 0; tHdrFtr < tHdrFtrLen; tHdrFtr++) {
pRecord = pHdrFtrList + tHdrFtr;
for (tIndex = 0;
tIndex < elementsof(pRecord->atElement);
tIndex++) {
if (!pRecord->atElement[tIndex].bTextOriginal) {
continue;
}
pCurr = pRecord->atElement[tIndex].tInfo.pText;
while (pCurr != NULL) {
pCurr->szStorage = xfree(pCurr->szStorage);
pNext = pCurr->pNext;
pCurr = xfree(pCurr);
pCurr = pNext;
}
}
}
pHdrFtrList = xfree(pHdrFtrList);
/* Reset all control variables */
tHdrFtrLen = 0;
} /* end of vDestroyHdrFtrInfoList */
/*
* vCreat8HdrFtrInfoList - Create the Header/footer Information List
*/
void
vCreat8HdrFtrInfoList(const ULONG *aulCharPos, size_t tLength)
{
hdrftr_mem_type *pListMember;
size_t tHdrFtr, tIndex, tMainIndex;
/*
* vCreat2HdrFtrInfoList - Create the Header/footer Information List
*/
void
vCreat2HdrFtrInfoList(const ULONG *aulCharPos, size_t tLength)
{
vCreat6HdrFtrInfoList(aulCharPos, tLength);
} /* end of vCreat2HdrFtrInfoList */
/*
* pGetHdrFtrInfo - get the Header/footer information
*/
const hdrftr_block_type *
pGetHdrFtrInfo(int iSectionIndex,
BOOL bWantHeader, BOOL bOddPage, BOOL bFirstInSection)
{
hdrftr_mem_type *pCurr;
if (bFirstInSection) {
if (bWantHeader) {
return &pCurr->atElement[HDR_FIRST_PAGE].tInfo;
} else {
return &pCurr->atElement[FTR_FIRST_PAGE].tInfo;
}
} else {
if (bWantHeader) {
if (bOddPage) {
return &pCurr->atElement[HDR_ODD_PAGES].tInfo;
} else {
return &pCurr->atElement[HDR_EVEN_PAGES].tInfo;
}
} else {
if (bOddPage) {
return &pCurr->atElement[FTR_ODD_PAGES].tInfo;
} else {
return &pCurr->atElement[FTR_EVEN_PAGES].tInfo;
}
}
}
} /* end of pGetHdrFtrInfo */
/*
* lComputeHdrFtrHeight - compute the height of a header or footer
*
* Returns the height in DrawUnits
*/
static long
lComputeHdrFtrHeight(const output_type *pAnchor)
{
const output_type *pCurr;
long lTotal;
USHORT usFontSizeMax;
lTotal = 0;
usFontSizeMax = 0;
for (pCurr = pAnchor; pCurr != NULL; pCurr = pCurr->pNext) {
if (pCurr->tNextFree == 1) {
if (pCurr->szStorage[0] == PAR_END) {
/* End of a paragraph */
lTotal += lComputeLeading(usFontSizeMax);
lTotal += lMilliPoints2DrawUnits(
(long)pCurr->usFontSize * 200);
usFontSizeMax = 0;
continue;
}
if (pCurr->szStorage[0] == HARD_RETURN) {
/* End of a line */
lTotal += lComputeLeading(usFontSizeMax);
usFontSizeMax = 0;
continue;
}
}
if (pCurr->usFontSize > usFontSizeMax) {
usFontSizeMax = pCurr->usFontSize;
}
}
if (usFontSizeMax != 0) {
/* Height of the last paragraph */
lTotal += lComputeLeading(usFontSizeMax);
}
return lTotal;
} /* end of lComputeHdrFtrHeight */