prop8.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496
  1. /*
  2. * prop8.c
  3. * Copyright (C) 1998-2005 A.J. van Os; Released under GNU GPL
  4. *
  5. * Description:
  6. * Read the property information from a MS Word 8, 9,10 or 11 file
  7. *
  8. * Word 8 is better known as Word 97 or as Word 98 for Mac
  9. * Word 9 is better known as Word 2000 or as Word 2001 for Mac
  10. * Word 10 is better known as Word 2002 or as Word XP
  11. * Word 11 is better known as Word 2003
  12. */
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include "antiword.h"
  16. #define DEFAULT_LISTCHAR 0x002e /* A full stop */
  17. /*
  18. * iGet8InfoLength - the length of the information for Word 8/9/10/11 files
  19. */
  20. static int
  21. iGet8InfoLength(int iByteNbr, const UCHAR *aucGrpprl)
  22. {
  23. int iTmp, iDel, iAdd;
  24. USHORT usOpCode;
  25. usOpCode = usGetWord(iByteNbr, aucGrpprl);
  26. switch (usOpCode & 0xe000) {
  27. case 0x0000: case 0x2000:
  28. return 3;
  29. case 0x4000: case 0x8000: case 0xa000:
  30. return 4;
  31. case 0xe000:
  32. return 5;
  33. case 0x6000:
  34. return 6;
  35. case 0xc000:
  36. iTmp = (int)ucGetByte(iByteNbr + 2, aucGrpprl);
  37. if (usOpCode == 0xc615 && iTmp == 255) {
  38. iDel = (int)ucGetByte(iByteNbr + 3, aucGrpprl);
  39. iAdd = (int)ucGetByte(
  40. iByteNbr + 4 + iDel * 4, aucGrpprl);
  41. iTmp = 2 + iDel * 4 + iAdd * 3;
  42. }
  43. return 3 + iTmp;
  44. default:
  45. DBG_HEX(usOpCode);
  46. DBG_FIXME();
  47. return 1;
  48. }
  49. } /* end of iGet8InfoLength */
  50. /*
  51. * aucFillInfoBuffer - fill the information buffer
  52. *
  53. * Returns the information buffer when successful, otherwise NULL
  54. */
  55. static UCHAR *
  56. aucFillInfoBuffer(FILE *pFile, const pps_type *pTable,
  57. const ULONG *aulBBD, size_t tBBDLen,
  58. const ULONG *aulSBD, size_t tSBDLen,
  59. ULONG ulBeginInfo, size_t tInfoLen)
  60. {
  61. const ULONG *aulBlockDepot;
  62. UCHAR *aucBuffer;
  63. size_t tBlockDepotLen, tBlockSize;
  64. fail(pFile == NULL || pTable == NULL);
  65. fail(aulBBD == NULL || aulSBD == NULL);
  66. fail(tInfoLen == 0);
  67. NO_DBG_DEC(pTable->ulSB);
  68. NO_DBG_HEX(pTable->ulSize);
  69. if (pTable->ulSize == 0) {
  70. DBG_MSG("No information");
  71. return NULL;
  72. }
  73. if (pTable->ulSize < MIN_SIZE_FOR_BBD_USE) {
  74. /* Use the Small Block Depot */
  75. aulBlockDepot = aulSBD;
  76. tBlockDepotLen = tSBDLen;
  77. tBlockSize = SMALL_BLOCK_SIZE;
  78. } else {
  79. /* Use the Big Block Depot */
  80. aulBlockDepot = aulBBD;
  81. tBlockDepotLen = tBBDLen;
  82. tBlockSize = BIG_BLOCK_SIZE;
  83. }
  84. aucBuffer = xmalloc(tInfoLen);
  85. if (!bReadBuffer(pFile, pTable->ulSB,
  86. aulBlockDepot, tBlockDepotLen, tBlockSize,
  87. aucBuffer, ulBeginInfo, tInfoLen)) {
  88. aucBuffer = xfree(aucBuffer);
  89. return NULL;
  90. }
  91. return aucBuffer;
  92. } /* end of aucFillInfoBuffer */
  93. /*
  94. * Build the lists with Document Property Information for Word 8/9/10/11 files
  95. */
  96. void
  97. vGet8DopInfo(FILE *pFile, const pps_type *pTable,
  98. const ULONG *aulBBD, size_t tBBDLen,
  99. const ULONG *aulSBD, size_t tSBDLen,
  100. const UCHAR *aucHeader)
  101. {
  102. document_block_type tDocument;
  103. UCHAR *aucBuffer;
  104. ULONG ulBeginDocpInfo, ulTmp;
  105. size_t tDocpInfoLen;
  106. USHORT usTmp;
  107. fail(pFile == NULL || pTable == NULL || aucHeader == NULL);
  108. fail(aulBBD == NULL || aulSBD == NULL);
  109. ulBeginDocpInfo = ulGetLong(0x192, aucHeader); /* fcDop */
  110. NO_DBG_HEX(ulBeginSectInfo);
  111. tDocpInfoLen = (size_t)ulGetLong(0x196, aucHeader); /* lcbDop */
  112. NO_DBG_DEC(tSectInfoLen);
  113. if (tDocpInfoLen < 28) {
  114. DBG_MSG("No Document information");
  115. return;
  116. }
  117. aucBuffer = aucFillInfoBuffer(pFile, pTable,
  118. aulBBD, tBBDLen, aulSBD, tSBDLen,
  119. ulBeginDocpInfo, tDocpInfoLen);
  120. if (aucBuffer == NULL) {
  121. return;
  122. }
  123. usTmp = usGetWord(0x00, aucBuffer);
  124. tDocument.ucHdrFtrSpecification = (UCHAR)(usTmp >> 8); /* grpfIhdt */
  125. tDocument.usDefaultTabWidth = usGetWord(0x0a, aucBuffer); /* dxaTab */
  126. ulTmp = ulGetLong(0x14, aucBuffer); /* dttmCreated */
  127. tDocument.tCreateDate = tConvertDTTM(ulTmp);
  128. ulTmp = ulGetLong(0x18, aucBuffer); /* dttmRevised */
  129. tDocument.tRevisedDate = tConvertDTTM(ulTmp);
  130. vCreateDocumentInfoList(&tDocument);
  131. aucBuffer = xfree(aucBuffer);
  132. } /* end of vGet8DopInfo */
  133. /*
  134. * Fill the section information block with information
  135. * from a Word 8/9/10/11 file.
  136. */
  137. static void
  138. vGet8SectionInfo(const UCHAR *aucGrpprl, size_t tBytes,
  139. section_block_type *pSection)
  140. {
  141. UINT uiIndex;
  142. int iFodoOff, iInfoLen, iSize, iTmp;
  143. USHORT usCcol;
  144. UCHAR ucTmp;
  145. fail(aucGrpprl == NULL || pSection == NULL);
  146. iFodoOff = 0;
  147. while (tBytes >= (size_t)iFodoOff + 2) {
  148. iInfoLen = 0;
  149. switch (usGetWord(iFodoOff, aucGrpprl)) {
  150. case 0x3009: /* bkc */
  151. ucTmp = ucGetByte(iFodoOff + 2, aucGrpprl);
  152. DBG_DEC(ucTmp);
  153. pSection->bNewPage = ucTmp != 0 && ucTmp != 1;
  154. break;
  155. case 0x3014: /* grpfIhdt */
  156. pSection->ucHdrFtrSpecification =
  157. ucGetByte(iFodoOff + 2, aucGrpprl);
  158. break;
  159. case 0x500b: /* ccolM1 */
  160. usCcol = 1 + usGetWord(iFodoOff + 2, aucGrpprl);
  161. DBG_DEC(usCcol);
  162. break;
  163. case 0xd202: /* olstAnm */
  164. iSize = (int)ucGetByte(iFodoOff + 2, aucGrpprl);
  165. DBG_DEC_C(iSize != 212, iSize);
  166. for (uiIndex = 0, iTmp = iFodoOff + 3;
  167. uiIndex < 9 && iTmp < iFodoOff + 3 + iSize - 15;
  168. uiIndex++, iTmp += 16) {
  169. pSection->aucNFC[uiIndex] =
  170. ucGetByte(iTmp, aucGrpprl);
  171. DBG_DEC(pSection->aucNFC[uiIndex]);
  172. ucTmp = ucGetByte(iTmp + 3, aucGrpprl);
  173. DBG_HEX(ucTmp);
  174. if ((ucTmp & BIT(2)) != 0) {
  175. pSection->usNeedPrevLvl |=
  176. (USHORT)BIT(uiIndex);
  177. }
  178. if ((ucTmp & BIT(3)) != 0) {
  179. pSection->usHangingIndent |=
  180. (USHORT)BIT(uiIndex);
  181. }
  182. }
  183. DBG_HEX(pSection->usNeedPrevLvl);
  184. DBG_HEX(pSection->usHangingIndent);
  185. break;
  186. default:
  187. break;
  188. }
  189. if (iInfoLen <= 0) {
  190. iInfoLen = iGet8InfoLength(iFodoOff, aucGrpprl);
  191. fail(iInfoLen <= 0);
  192. }
  193. iFodoOff += iInfoLen;
  194. }
  195. } /* end of vGet8SectionInfo */
  196. /*
  197. * Build the lists with Section Property Information for Word 8/9/10/11 files
  198. */
  199. void
  200. vGet8SepInfo(FILE *pFile, const pps_info_type *pPPS,
  201. const ULONG *aulBBD, size_t tBBDLen,
  202. const ULONG *aulSBD, size_t tSBDLen,
  203. const UCHAR *aucHeader)
  204. {
  205. section_block_type tSection;
  206. ULONG *aulSectPage, *aulCharPos;
  207. UCHAR *aucBuffer, *aucFpage;
  208. ULONG ulBeginOfText, ulTextOffset, ulBeginSectInfo;
  209. size_t tSectInfoLen, tIndex, tOffset, tLen, tBytes;
  210. UCHAR aucTmp[2];
  211. fail(pFile == NULL || pPPS == NULL || aucHeader == NULL);
  212. fail(aulBBD == NULL || aulSBD == NULL);
  213. ulBeginOfText = ulGetLong(0x18, aucHeader); /* fcMin */
  214. NO_DBG_HEX(ulBeginOfText);
  215. ulBeginSectInfo = ulGetLong(0xca, aucHeader); /* fcPlcfsed */
  216. NO_DBG_HEX(ulBeginSectInfo);
  217. tSectInfoLen = (size_t)ulGetLong(0xce, aucHeader); /* lcbPlcfsed */
  218. NO_DBG_DEC(tSectInfoLen);
  219. if (tSectInfoLen < 4) {
  220. DBG_DEC(tSectInfoLen);
  221. return;
  222. }
  223. aucBuffer = aucFillInfoBuffer(pFile, &pPPS->tTable,
  224. aulBBD, tBBDLen, aulSBD, tSBDLen,
  225. ulBeginSectInfo, tSectInfoLen);
  226. if (aucBuffer == NULL) {
  227. return;
  228. }
  229. NO_DBG_PRINT_BLOCK(aucBuffer, tSectInfoLen);
  230. /* Read the Section Descriptors */
  231. tLen = (tSectInfoLen - 4) / 16;
  232. /* Save the section offsets */
  233. aulCharPos = xcalloc(tLen, sizeof(ULONG));
  234. for (tIndex = 0, tOffset = 0;
  235. tIndex < tLen;
  236. tIndex++, tOffset += 4) {
  237. ulTextOffset = ulGetLong(tOffset, aucBuffer);
  238. NO_DBG_HEX(ulTextOffset);
  239. aulCharPos[tIndex] = ulBeginOfText + ulTextOffset;
  240. NO_DBG_HEX(aulCharPos[tIndex]);
  241. }
  242. /* Save the Sepx offsets */
  243. aulSectPage = xcalloc(tLen, sizeof(ULONG));
  244. for (tIndex = 0, tOffset = (tLen + 1) * 4;
  245. tIndex < tLen;
  246. tIndex++, tOffset += 12) {
  247. aulSectPage[tIndex] = ulGetLong(tOffset + 2, aucBuffer);
  248. NO_DBG_HEX(aulSectPage[tIndex]); /* fcSepx */
  249. }
  250. aucBuffer = xfree(aucBuffer);
  251. /* Read the Section Properties */
  252. for (tIndex = 0; tIndex < tLen; tIndex++) {
  253. if (aulSectPage[tIndex] == FC_INVALID) {
  254. vDefault2SectionInfoList(aulCharPos[tIndex]);
  255. continue;
  256. }
  257. /* Get the number of bytes to read */
  258. if (!bReadBuffer(pFile, pPPS->tWordDocument.ulSB,
  259. aulBBD, tBBDLen, BIG_BLOCK_SIZE,
  260. aucTmp, aulSectPage[tIndex], 2)) {
  261. continue;
  262. }
  263. tBytes = 2 + (size_t)usGetWord(0, aucTmp);
  264. NO_DBG_DEC(tBytes);
  265. /* Read the bytes */
  266. aucFpage = xmalloc(tBytes);
  267. if (!bReadBuffer(pFile, pPPS->tWordDocument.ulSB,
  268. aulBBD, tBBDLen, BIG_BLOCK_SIZE,
  269. aucFpage, aulSectPage[tIndex], tBytes)) {
  270. aucFpage = xfree(aucFpage);
  271. continue;
  272. }
  273. NO_DBG_PRINT_BLOCK(aucFpage, tBytes);
  274. /* Process the bytes */
  275. vGetDefaultSection(&tSection);
  276. vGet8SectionInfo(aucFpage + 2, tBytes - 2, &tSection);
  277. vAdd2SectionInfoList(&tSection, aulCharPos[tIndex]);
  278. aucFpage = xfree(aucFpage);
  279. }
  280. aulCharPos = xfree(aulCharPos);
  281. aulSectPage = xfree(aulSectPage);
  282. } /* end of vGet8SepInfo */
  283. /*
  284. * Build the list with Header/Footer Information for Word 8/9/10/11 files
  285. */
  286. void
  287. vGet8HdrFtrInfo(FILE *pFile, const pps_type *pTable,
  288. const ULONG *aulBBD, size_t tBBDLen,
  289. const ULONG *aulSBD, size_t tSBDLen,
  290. const UCHAR *aucHeader)
  291. {
  292. ULONG *aulCharPos;
  293. UCHAR *aucBuffer;
  294. ULONG ulHdrFtrOffset, ulBeginHdrFtrInfo;
  295. size_t tHdrFtrInfoLen, tIndex, tOffset, tLen;
  296. fail(pFile == NULL || pTable == NULL || aucHeader == NULL);
  297. fail(aulBBD == NULL || aulSBD == NULL);
  298. ulBeginHdrFtrInfo = ulGetLong(0xf2, aucHeader); /* fcPlcfhdd */
  299. NO_DBG_HEX(ulBeginHdrFtrInfo);
  300. tHdrFtrInfoLen = (size_t)ulGetLong(0xf6, aucHeader); /* lcbPlcfhdd */
  301. NO_DBG_DEC(tHdrFtrInfoLen);
  302. if (tHdrFtrInfoLen < 8) {
  303. DBG_DEC_C(tHdrFtrInfoLen != 0, tHdrFtrInfoLen);
  304. return;
  305. }
  306. aucBuffer = aucFillInfoBuffer(pFile, pTable,
  307. aulBBD, tBBDLen, aulSBD, tSBDLen,
  308. ulBeginHdrFtrInfo, tHdrFtrInfoLen);
  309. if (aucBuffer == NULL) {
  310. return;
  311. }
  312. NO_DBG_PRINT_BLOCK(aucBuffer, tHdrFtrInfoLen);
  313. tLen = tHdrFtrInfoLen / 4 - 1;
  314. DBG_DEC_C(tLen % 12 != 1 && tLen % 12 != 7, tLen);
  315. /* Save the header/footer offsets */
  316. aulCharPos = xcalloc(tLen, sizeof(ULONG));
  317. for (tIndex = 0, tOffset = 0;
  318. tIndex < tLen;
  319. tIndex++, tOffset += 4) {
  320. ulHdrFtrOffset = ulGetLong(tOffset, aucBuffer);
  321. NO_DBG_HEX(ulHdrFtrOffset);
  322. aulCharPos[tIndex] = ulHdrFtrOffset2CharPos(ulHdrFtrOffset);
  323. NO_DBG_HEX(aulCharPos[tIndex]);
  324. }
  325. vCreat8HdrFtrInfoList(aulCharPos, tLen);
  326. /* Clean up and leave */
  327. aulCharPos = xfree(aulCharPos);
  328. aucBuffer = xfree(aucBuffer);
  329. } /* end of vGet8HdrFtrInfo */
  330. /*
  331. * Translate the rowinfo to a member of the row_info enumeration
  332. */
  333. row_info_enum
  334. eGet8RowInfo(int iFodo,
  335. const UCHAR *aucGrpprl, int iBytes, row_block_type *pRow)
  336. {
  337. int iFodoOff, iInfoLen;
  338. int iIndex, iSize, iCol;
  339. int iPosCurr, iPosPrev;
  340. USHORT usTmp;
  341. BOOL bFound2416_0, bFound2416_1, bFound2417_0, bFound2417_1;
  342. BOOL bFound244b_0, bFound244b_1, bFound244c_0, bFound244c_1;
  343. BOOL bFoundd608;
  344. fail(iFodo < 0 || aucGrpprl == NULL || pRow == NULL);
  345. iFodoOff = 0;
  346. bFound2416_0 = FALSE;
  347. bFound2416_1 = FALSE;
  348. bFound2417_0 = FALSE;
  349. bFound2417_1 = FALSE;
  350. bFound244b_0 = FALSE;
  351. bFound244b_1 = FALSE;
  352. bFound244c_0 = FALSE;
  353. bFound244c_1 = FALSE;
  354. bFoundd608 = FALSE;
  355. while (iBytes >= iFodoOff + 2) {
  356. iInfoLen = 0;
  357. switch (usGetWord(iFodo + iFodoOff, aucGrpprl)) {
  358. case 0x2416: /* fInTable */
  359. if (odd(ucGetByte(iFodo + iFodoOff + 2, aucGrpprl))) {
  360. bFound2416_1 = TRUE;
  361. } else {
  362. bFound2416_0 = TRUE;
  363. }
  364. break;
  365. case 0x2417: /* fTtp */
  366. if (odd(ucGetByte(iFodo + iFodoOff + 2, aucGrpprl))) {
  367. bFound2417_1 = TRUE;
  368. } else {
  369. bFound2417_0 = TRUE;
  370. }
  371. break;
  372. case 0x244b: /* sub-table fInTable */
  373. if (odd(ucGetByte(iFodo + iFodoOff + 2, aucGrpprl))) {
  374. bFound244b_1 = TRUE;
  375. } else {
  376. bFound244b_0 = TRUE;
  377. }
  378. break;
  379. case 0x244c: /* sub-table fTtp */
  380. if (odd(ucGetByte(iFodo + iFodoOff + 2, aucGrpprl))) {
  381. bFound244c_1 = TRUE;
  382. } else {
  383. bFound244c_0 = TRUE;
  384. }
  385. break;
  386. case 0x6424: /* brcTop */
  387. usTmp = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
  388. usTmp &= 0xff00;
  389. NO_DBG_DEC(usTmp >> 8);
  390. if (usTmp == 0) {
  391. pRow->ucBorderInfo &= ~TABLE_BORDER_TOP;
  392. } else {
  393. pRow->ucBorderInfo |= TABLE_BORDER_TOP;
  394. }
  395. break;
  396. case 0x6425: /* brcLeft */
  397. usTmp = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
  398. usTmp &= 0xff00;
  399. NO_DBG_DEC(usTmp >> 8);
  400. if (usTmp == 0) {
  401. pRow->ucBorderInfo &= ~TABLE_BORDER_LEFT;
  402. } else {
  403. pRow->ucBorderInfo |= TABLE_BORDER_LEFT;
  404. }
  405. break;
  406. case 0x6426: /* brcBottom */
  407. usTmp = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
  408. usTmp &= 0xff00;
  409. NO_DBG_DEC(usTmp >> 8);
  410. if (usTmp == 0) {
  411. pRow->ucBorderInfo &= ~TABLE_BORDER_BOTTOM;
  412. } else {
  413. pRow->ucBorderInfo |= TABLE_BORDER_BOTTOM;
  414. }
  415. break;
  416. case 0x6427: /* brcRight */
  417. usTmp = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
  418. usTmp &= 0xff00;
  419. NO_DBG_DEC(usTmp >> 8);
  420. if (usTmp == 0) {
  421. pRow->ucBorderInfo &= ~TABLE_BORDER_RIGHT;
  422. } else {
  423. pRow->ucBorderInfo |= TABLE_BORDER_RIGHT;
  424. }
  425. break;
  426. case 0xd606: /* cDefTable10 */
  427. DBG_MSG("0xd606: sprmTDefTable10");
  428. iSize = (int)usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
  429. DBG_DEC(iSize);
  430. break;
  431. case 0xd608: /* cDefTable */
  432. iSize = (int)usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
  433. if (iSize < 6 || iBytes < iFodoOff + 8) {
  434. DBG_DEC(iSize);
  435. DBG_DEC(iFodoOff);
  436. iInfoLen = 2;
  437. break;
  438. }
  439. iCol = (int)ucGetByte(iFodo + iFodoOff + 4, aucGrpprl);
  440. if (iCol < 1 ||
  441. iBytes < iFodoOff + 4 + (iCol + 1) * 2) {
  442. DBG_DEC(iCol);
  443. DBG_DEC(iFodoOff);
  444. iInfoLen = 2;
  445. break;
  446. }
  447. if (iCol >= (int)elementsof(pRow->asColumnWidth)) {
  448. DBG_DEC(iCol);
  449. werr(1, "The number of columns is corrupt");
  450. }
  451. pRow->ucNumberOfColumns = (UCHAR)iCol;
  452. iPosPrev = (int)(short)usGetWord(
  453. iFodo + iFodoOff + 5,
  454. aucGrpprl);
  455. for (iIndex = 0; iIndex < iCol; iIndex++) {
  456. iPosCurr = (int)(short)usGetWord(
  457. iFodo + iFodoOff + 7 + iIndex * 2,
  458. aucGrpprl);
  459. pRow->asColumnWidth[iIndex] =
  460. (short)(iPosCurr - iPosPrev);
  461. iPosPrev = iPosCurr;
  462. }
  463. bFoundd608 = TRUE;
  464. break;
  465. default:
  466. break;
  467. }
  468. if (iInfoLen <= 0) {
  469. iInfoLen =
  470. iGet8InfoLength(iFodo + iFodoOff, aucGrpprl);
  471. fail(iInfoLen <= 0);
  472. }
  473. iFodoOff += iInfoLen;
  474. }
  475. if (bFound2417_1 && bFoundd608) {
  476. return found_end_of_row;
  477. }
  478. if (bFound2417_0 && !bFoundd608) {
  479. return found_not_end_of_row;
  480. }
  481. if (bFound2416_1 || bFound244b_1) {
  482. return found_a_cell;
  483. }
  484. if (bFound2416_0 || bFound244b_0) {
  485. return found_not_a_cell;
  486. }
  487. return found_nothing;
  488. } /* end of eGet8RowInfo */
  489. /*
  490. * Fill the style information block with information
  491. * from a Word 8/9/10/11 file.
  492. */
  493. void
  494. vGet8StyleInfo(int iFodo,
  495. const UCHAR *aucGrpprl, int iBytes, style_block_type *pStyle)
  496. {
  497. list_block_type tList6;
  498. const list_block_type *pList;
  499. int iFodoOff, iInfoLen;
  500. int iTmp, iDel, iAdd, iBefore;
  501. USHORT usOpCode, usTmp;
  502. short sTmp;
  503. fail(iFodo < 0 || aucGrpprl == NULL || pStyle == NULL);
  504. NO_DBG_DEC_C(pStyle->usListIndex != 0, pStyle->usIstd);
  505. NO_DBG_DEC_C(pStyle->usListIndex != 0, pStyle->usListIndex);
  506. (void)memset(&tList6, 0, sizeof(tList6));
  507. iFodoOff = 0;
  508. while (iBytes >= iFodoOff + 2) {
  509. iInfoLen = 0;
  510. usOpCode = usGetWord(iFodo + iFodoOff, aucGrpprl);
  511. switch (usOpCode) {
  512. case 0x2403: /* jc */
  513. pStyle->ucAlignment = ucGetByte(
  514. iFodo + iFodoOff + 2, aucGrpprl);
  515. break;
  516. case 0x260a: /* ilvl */
  517. pStyle->ucListLevel =
  518. ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
  519. NO_DBG_DEC(pStyle->ucListLevel);
  520. pStyle->ucNumLevel = pStyle->ucListLevel;
  521. break;
  522. case 0x4600: /* istd */
  523. usTmp = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
  524. NO_DBG_DEC(usTmp);
  525. break;
  526. case 0x460b: /* ilfo */
  527. pStyle->usListIndex =
  528. usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
  529. NO_DBG_DEC(pStyle->usListIndex);
  530. break;
  531. case 0x4610: /* Nest dxaLeft */
  532. sTmp = (short)usGetWord(
  533. iFodo + iFodoOff + 2, aucGrpprl);
  534. pStyle->sLeftIndent += sTmp;
  535. if (pStyle->sLeftIndent < 0) {
  536. pStyle->sLeftIndent = 0;
  537. }
  538. DBG_DEC(sTmp);
  539. DBG_DEC(pStyle->sLeftIndent);
  540. break;
  541. case 0xc60d: /* ChgTabsPapx */
  542. case 0xc615: /* ChgTabs */
  543. iTmp = (int)ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
  544. if (iTmp < 2) {
  545. iInfoLen = 1;
  546. break;
  547. }
  548. NO_DBG_DEC(iTmp);
  549. iDel = (int)ucGetByte(iFodo + iFodoOff + 3, aucGrpprl);
  550. if (iTmp < 2 + 2 * iDel) {
  551. iInfoLen = 1;
  552. break;
  553. }
  554. NO_DBG_DEC(iDel);
  555. iAdd = (int)ucGetByte(
  556. iFodo + iFodoOff + 4 + 2 * iDel, aucGrpprl);
  557. if (iTmp < 2 + 2 * iDel + 2 * iAdd) {
  558. iInfoLen = 1;
  559. break;
  560. }
  561. NO_DBG_DEC(iAdd);
  562. break;
  563. case 0x840e: /* dxaRight */
  564. pStyle->sRightIndent = (short)usGetWord(
  565. iFodo + iFodoOff + 2, aucGrpprl);
  566. NO_DBG_DEC(pStyle->sRightIndent);
  567. break;
  568. case 0x840f: /* dxaLeft */
  569. pStyle->sLeftIndent = (short)usGetWord(
  570. iFodo + iFodoOff + 2, aucGrpprl);
  571. NO_DBG_DEC(pStyle->sLeftIndent);
  572. break;
  573. case 0x8411: /* dxaLeft1 */
  574. pStyle->sLeftIndent1 = (short)usGetWord(
  575. iFodo + iFodoOff + 2, aucGrpprl);
  576. NO_DBG_DEC(pStyle->sLeftIndent1);
  577. break;
  578. case 0xa413: /* dyaBefore */
  579. pStyle->usBeforeIndent = usGetWord(
  580. iFodo + iFodoOff + 2, aucGrpprl);
  581. NO_DBG_DEC(pStyle->usBeforeIndent);
  582. break;
  583. case 0xa414: /* dyaAfter */
  584. pStyle->usAfterIndent = usGetWord(
  585. iFodo + iFodoOff + 2, aucGrpprl);
  586. NO_DBG_DEC(pStyle->usAfterIndent);
  587. break;
  588. case 0xc63e: /* anld */
  589. iTmp = (int)ucGetByte(
  590. iFodo + iFodoOff + 2, aucGrpprl);
  591. DBG_DEC_C(iTmp < 84, iTmp);
  592. if (iTmp >= 1) {
  593. tList6.ucNFC = ucGetByte(
  594. iFodo + iFodoOff + 3, aucGrpprl);
  595. }
  596. if (tList6.ucNFC != LIST_BULLETS && iTmp >= 2) {
  597. iBefore = (int)ucGetByte(
  598. iFodo + iFodoOff + 4, aucGrpprl);
  599. } else {
  600. iBefore = 0;
  601. }
  602. if (iTmp >= 12) {
  603. tList6.ulStartAt = (ULONG)usGetWord(
  604. iFodo + iFodoOff + 13, aucGrpprl);
  605. }
  606. if (iTmp >= iBefore + 22) {
  607. tList6.usListChar = usGetWord(
  608. iFodo + iFodoOff + iBefore + 23,
  609. aucGrpprl);
  610. DBG_HEX(tList6.usListChar);
  611. }
  612. break;
  613. default:
  614. NO_DBG_HEX(usOpCode);
  615. break;
  616. }
  617. if (iInfoLen <= 0) {
  618. iInfoLen =
  619. iGet8InfoLength(iFodo + iFodoOff, aucGrpprl);
  620. fail(iInfoLen <= 0);
  621. }
  622. iFodoOff += iInfoLen;
  623. }
  624. if (pStyle->usListIndex == 2047) {
  625. /* Old style list */
  626. pStyle->usStartAt = (USHORT)tList6.ulStartAt;
  627. pStyle->usListChar = tList6.usListChar;
  628. pStyle->ucNFC = tList6.ucNFC;
  629. } else {
  630. /* New style list */
  631. pList = pGetListInfo(pStyle->usListIndex, pStyle->ucListLevel);
  632. if (pList != NULL) {
  633. pStyle->bNoRestart = pList->bNoRestart;
  634. fail(pList->ulStartAt > (ULONG)USHRT_MAX);
  635. pStyle->usStartAt = (USHORT)pList->ulStartAt;
  636. pStyle->usListChar = pList->usListChar;
  637. pStyle->ucNFC = pList->ucNFC;
  638. if (pStyle->sLeftIndent <= 0) {
  639. pStyle->sLeftIndent = pList->sLeftIndent;
  640. }
  641. }
  642. }
  643. } /* end of vGet8StyleInfo */
  644. /*
  645. * Get the left indentation value from the style information block
  646. *
  647. * Returns the value when found, otherwise 0
  648. */
  649. static short
  650. sGetLeftIndent(const UCHAR *aucGrpprl, size_t tBytes)
  651. {
  652. int iOffset, iInfoLen;
  653. USHORT usOpCode, usTmp;
  654. fail(aucGrpprl == NULL);
  655. iOffset = 0;
  656. while (tBytes >= (size_t)iOffset + 4) {
  657. usOpCode = usGetWord(iOffset, aucGrpprl);
  658. if (usOpCode == 0x840f) { /* dxaLeft */
  659. usTmp = usGetWord(iOffset + 2, aucGrpprl);
  660. if (usTmp <= 0x7fff) {
  661. NO_DBG_DEC(usTmp);
  662. return (short)usTmp;
  663. }
  664. }
  665. iInfoLen = iGet8InfoLength(iOffset, aucGrpprl);
  666. fail(iInfoLen <= 0);
  667. iOffset += iInfoLen;
  668. }
  669. return 0;
  670. } /* end of sGetLeftIndent */
  671. /*
  672. * Build the list with List Information for Word 8/9/10/11 files
  673. */
  674. void
  675. vGet8LstInfo(FILE *pFile, const pps_info_type *pPPS,
  676. const ULONG *aulBBD, size_t tBBDLen,
  677. const ULONG *aulSBD, size_t tSBDLen,
  678. const UCHAR *aucHeader)
  679. {
  680. list_block_type tList;
  681. const ULONG *aulBlockDepot;
  682. UCHAR *aucLfoInfo, *aucLstfInfo, *aucPapx, *aucXString;
  683. ULONG ulBeginLfoInfo, ulBeginLstfInfo, ulBeginLvlfInfo;
  684. ULONG ulListID, ulStart;
  685. size_t tBlockDepotLen, tBlockSize;
  686. size_t tLfoInfoLen, tLstfInfoLen, tPapxLen, tXstLen, tOff;
  687. size_t tLstfRecords, tStart, tIndex;
  688. int iNums;
  689. USHORT usIstd;
  690. UCHAR ucTmp, ucListLevel, ucMaxLevel, ucChpxLen;
  691. UCHAR aucLvlfInfo[28], aucXst[2];
  692. fail(pFile == NULL || pPPS == NULL || aucHeader == NULL);
  693. fail(aulBBD == NULL || aulSBD == NULL);
  694. NO_DBG_DEC(pPPS->tTable.ulSB);
  695. NO_DBG_HEX(pPPS->tTable.ulSize);
  696. if (pPPS->tTable.ulSize == 0) {
  697. DBG_MSG("No list information");
  698. return;
  699. }
  700. if (pPPS->tTable.ulSize < MIN_SIZE_FOR_BBD_USE) {
  701. /* Use the Small Block Depot */
  702. aulBlockDepot = aulSBD;
  703. tBlockDepotLen = tSBDLen;
  704. tBlockSize = SMALL_BLOCK_SIZE;
  705. } else {
  706. /* Use the Big Block Depot */
  707. aulBlockDepot = aulBBD;
  708. tBlockDepotLen = tBBDLen;
  709. tBlockSize = BIG_BLOCK_SIZE;
  710. }
  711. /* LFO (List Format Override) */
  712. ulBeginLfoInfo = ulGetLong(0x2ea, aucHeader); /* fcPlfLfo */
  713. DBG_HEX(ulBeginLfoInfo);
  714. tLfoInfoLen = (size_t)ulGetLong(0x2ee, aucHeader); /* lcbPlfLfo */
  715. DBG_DEC(tLfoInfoLen);
  716. if (tLfoInfoLen == 0) {
  717. DBG_MSG("No lists in this document");
  718. return;
  719. }
  720. aucLfoInfo = xmalloc(tLfoInfoLen);
  721. if (!bReadBuffer(pFile, pPPS->tTable.ulSB,
  722. aulBlockDepot, tBlockDepotLen, tBlockSize,
  723. aucLfoInfo, ulBeginLfoInfo, tLfoInfoLen)) {
  724. aucLfoInfo = xfree(aucLfoInfo);
  725. return;
  726. }
  727. NO_DBG_PRINT_BLOCK(aucLfoInfo, tLfoInfoLen);
  728. vBuildLfoList(aucLfoInfo, tLfoInfoLen);
  729. aucLfoInfo = xfree(aucLfoInfo);
  730. /* LSTF (LiST data on File) */
  731. ulBeginLstfInfo = ulGetLong(0x2e2, aucHeader); /* fcPlcfLst */
  732. DBG_HEX(ulBeginLstfInfo);
  733. tLstfInfoLen = (size_t)ulGetLong(0x2e6, aucHeader); /* lcbPlcfLst */
  734. DBG_DEC(tLstfInfoLen);
  735. if (tLstfInfoLen == 0) {
  736. DBG_MSG("No list data on file");
  737. return;
  738. }
  739. aucLstfInfo = xmalloc(tLstfInfoLen);
  740. if (!bReadBuffer(pFile, pPPS->tTable.ulSB,
  741. aulBlockDepot, tBlockDepotLen, tBlockSize,
  742. aucLstfInfo, ulBeginLstfInfo, tLstfInfoLen)) {
  743. aucLstfInfo = xfree(aucLstfInfo);
  744. return;
  745. }
  746. NO_DBG_PRINT_BLOCK(aucLstfInfo, tLstfInfoLen);
  747. tLstfRecords = (size_t)usGetWord(0, aucLstfInfo);
  748. if (2 + tLstfRecords * 28 < tLstfInfoLen) {
  749. DBG_DEC(2 + tLstfRecords * 28);
  750. DBG_DEC(tLstfInfoLen);
  751. aucLstfInfo = xfree(aucLstfInfo);
  752. return;
  753. }
  754. /* LVLF (List leVeL on File) */
  755. ulBeginLvlfInfo = ulBeginLstfInfo + tLstfInfoLen;
  756. DBG_HEX(ulBeginLvlfInfo);
  757. aucXString = NULL;
  758. ulStart = ulBeginLvlfInfo;
  759. for (tIndex = 0, tStart = 2;
  760. tIndex < tLstfRecords;
  761. tIndex++, tStart += 28) {
  762. ulListID = ulGetLong(tStart, aucLstfInfo);
  763. NO_DBG_HEX(ulListID);
  764. ucTmp = ucGetByte(tStart + 26, aucLstfInfo);
  765. ucMaxLevel = odd(ucTmp) ? 1 : 9;
  766. for (ucListLevel = 0; ucListLevel < ucMaxLevel; ucListLevel++) {
  767. fail(aucXString != NULL);
  768. usIstd = usGetWord(
  769. tStart + 8 + 2 * (size_t)ucListLevel,
  770. aucLstfInfo);
  771. DBG_DEC_C(usIstd != STI_NIL, usIstd);
  772. NO_DBG_HEX(ulStart);
  773. (void)memset(&tList, 0, sizeof(tList));
  774. /* Read the lvlf (List leVeL on File) */
  775. if (!bReadBuffer(pFile, pPPS->tTable.ulSB,
  776. aulBlockDepot, tBlockDepotLen,
  777. tBlockSize, aucLvlfInfo,
  778. ulStart, sizeof(aucLvlfInfo))) {
  779. aucLstfInfo = xfree(aucLstfInfo);
  780. return;
  781. }
  782. NO_DBG_PRINT_BLOCK(aucLvlfInfo, sizeof(aucLvlfInfo));
  783. if (bAllZero(aucLvlfInfo, sizeof(aucLvlfInfo))) {
  784. tList.ulStartAt = 1;
  785. tList.ucNFC = 0x00;
  786. tList.bNoRestart = FALSE;
  787. } else {
  788. tList.ulStartAt = ulGetLong(0, aucLvlfInfo);
  789. tList.ucNFC = ucGetByte(4, aucLvlfInfo);
  790. ucTmp = ucGetByte(5, aucLvlfInfo);
  791. tList.bNoRestart = (ucTmp & BIT(3)) != 0;
  792. DBG_MSG_C((ucTmp & BIT(4)) != 0 &&
  793. (ucTmp & BIT(6)) != 0, "Found one");
  794. }
  795. ulStart += sizeof(aucLvlfInfo);
  796. tPapxLen = (size_t)ucGetByte(25, aucLvlfInfo);
  797. if (tPapxLen != 0) {
  798. aucPapx = xmalloc(tPapxLen);
  799. /* Read the Papx */
  800. if (!bReadBuffer(pFile, pPPS->tTable.ulSB,
  801. aulBlockDepot, tBlockDepotLen,
  802. tBlockSize, aucPapx,
  803. ulStart, tPapxLen)) {
  804. aucPapx = xfree(aucPapx);
  805. aucLstfInfo = xfree(aucLstfInfo);
  806. return;
  807. }
  808. NO_DBG_PRINT_BLOCK(aucPapx, tPapxLen);
  809. tList.sLeftIndent =
  810. sGetLeftIndent(aucPapx, tPapxLen);
  811. aucPapx = xfree(aucPapx);
  812. }
  813. ulStart += tPapxLen;
  814. ucChpxLen = ucGetByte(24, aucLvlfInfo);
  815. ulStart += (ULONG)ucChpxLen;
  816. /* Read the length of the XString */
  817. if (!bReadBuffer(pFile, pPPS->tTable.ulSB,
  818. aulBlockDepot, tBlockDepotLen,
  819. tBlockSize, aucXst,
  820. ulStart, sizeof(aucXst))) {
  821. aucLstfInfo = xfree(aucLstfInfo);
  822. return;
  823. }
  824. NO_DBG_PRINT_BLOCK(aucXst, sizeof(aucXst));
  825. tXstLen = (size_t)usGetWord(0, aucXst);
  826. ulStart += sizeof(aucXst);
  827. if (tXstLen == 0) {
  828. tList.usListChar = DEFAULT_LISTCHAR;
  829. vAdd2ListInfoList(ulListID,
  830. usIstd,
  831. ucListLevel,
  832. &tList);
  833. continue;
  834. }
  835. tXstLen *= 2; /* Length in chars to length in bytes */
  836. aucXString = xmalloc(tXstLen);
  837. /* Read the XString */
  838. if (!bReadBuffer(pFile, pPPS->tTable.ulSB,
  839. aulBlockDepot, tBlockDepotLen,
  840. tBlockSize, aucXString,
  841. ulStart, tXstLen)) {
  842. aucXString = xfree(aucXString);
  843. aucLstfInfo = xfree(aucLstfInfo);
  844. return;
  845. }
  846. NO_DBG_PRINT_BLOCK(aucXString, tXstLen);
  847. tOff = 0;
  848. for (iNums = 6; iNums < 15; iNums++) {
  849. ucTmp = ucGetByte(iNums, aucLvlfInfo);
  850. if (ucTmp == 0) {
  851. break;
  852. }
  853. tOff = (size_t)ucTmp;
  854. }
  855. tOff *= 2; /* Offset in chars to offset in bytes */
  856. NO_DBG_DEC(tOff);
  857. if (tList.ucNFC == LIST_SPECIAL ||
  858. tList.ucNFC == LIST_SPECIAL2 ||
  859. tList.ucNFC == LIST_BULLETS) {
  860. tList.usListChar = usGetWord(0, aucXString);
  861. } else if (tOff != 0 && tOff < tXstLen) {
  862. tList.usListChar = usGetWord(tOff, aucXString);
  863. } else {
  864. tList.usListChar = DEFAULT_LISTCHAR;
  865. }
  866. vAdd2ListInfoList(ulListID,
  867. usIstd,
  868. ucListLevel,
  869. &tList);
  870. ulStart += tXstLen;
  871. aucXString = xfree(aucXString);
  872. }
  873. }
  874. aucLstfInfo = xfree(aucLstfInfo);
  875. } /* end of vGet8LstInfo */
  876. /*
  877. * Build the lists with Paragraph Information for Word 8/9/10/11 files
  878. */
  879. void
  880. vGet8PapInfo(FILE *pFile, const pps_info_type *pPPS,
  881. const ULONG *aulBBD, size_t tBBDLen,
  882. const ULONG *aulSBD, size_t tSBDLen,
  883. const UCHAR *aucHeader)
  884. {
  885. row_block_type tRow;
  886. style_block_type tStyle;
  887. ULONG *aulParfPage;
  888. UCHAR *aucBuffer;
  889. ULONG ulCharPos, ulCharPosFirst, ulCharPosLast;
  890. ULONG ulBeginParfInfo;
  891. size_t tParfInfoLen, tOffset, tLen;
  892. int iIndex, iIndex2, iRun, iFodo, iLen;
  893. row_info_enum eRowInfo;
  894. USHORT usIstd;
  895. UCHAR aucFpage[BIG_BLOCK_SIZE];
  896. fail(pFile == NULL || pPPS == NULL || aucHeader == NULL);
  897. fail(aulBBD == NULL || aulSBD == NULL);
  898. ulBeginParfInfo = ulGetLong(0x102, aucHeader); /* fcPlcfbtePapx */
  899. NO_DBG_HEX(ulBeginParfInfo);
  900. tParfInfoLen = (size_t)ulGetLong(0x106, aucHeader); /* lcbPlcfbtePapx */
  901. NO_DBG_DEC(tParfInfoLen);
  902. if (tParfInfoLen < 4) {
  903. DBG_DEC(tParfInfoLen);
  904. return;
  905. }
  906. aucBuffer = aucFillInfoBuffer(pFile, &pPPS->tTable,
  907. aulBBD, tBBDLen, aulSBD, tSBDLen,
  908. ulBeginParfInfo, tParfInfoLen);
  909. if (aucBuffer == NULL) {
  910. return;
  911. }
  912. NO_DBG_PRINT_BLOCK(aucBuffer, tParfInfoLen);
  913. tLen = (tParfInfoLen / 4 - 1) / 2;
  914. aulParfPage = xcalloc(tLen, sizeof(ULONG));
  915. for (iIndex = 0, tOffset = (tLen + 1) * 4;
  916. iIndex < (int)tLen;
  917. iIndex++, tOffset += 4) {
  918. aulParfPage[iIndex] = ulGetLong(tOffset, aucBuffer);
  919. NO_DBG_DEC(aulParfPage[iIndex]);
  920. }
  921. DBG_HEX(ulGetLong(0, aucBuffer));
  922. aucBuffer = xfree(aucBuffer);
  923. NO_DBG_PRINT_BLOCK(aucHeader, HEADER_SIZE);
  924. (void)memset(&tRow, 0, sizeof(tRow));
  925. ulCharPosFirst = CP_INVALID;
  926. for (iIndex = 0; iIndex < (int)tLen; iIndex++) {
  927. fail(aulParfPage[iIndex] > ULONG_MAX / BIG_BLOCK_SIZE);
  928. if (!bReadBuffer(pFile, pPPS->tWordDocument.ulSB,
  929. aulBBD, tBBDLen, BIG_BLOCK_SIZE,
  930. aucFpage,
  931. aulParfPage[iIndex] * BIG_BLOCK_SIZE,
  932. BIG_BLOCK_SIZE)) {
  933. break;
  934. }
  935. NO_DBG_PRINT_BLOCK(aucFpage, BIG_BLOCK_SIZE);
  936. iRun = (int)ucGetByte(0x1ff, aucFpage);
  937. NO_DBG_DEC(iRun);
  938. for (iIndex2 = 0; iIndex2 < iRun; iIndex2++) {
  939. NO_DBG_HEX(ulGetLong(iIndex2 * 4, aucFpage));
  940. iFodo = 2 * (int)ucGetByte(
  941. (iRun + 1) * 4 + iIndex2 * 13, aucFpage);
  942. if (iFodo <= 0) {
  943. continue;
  944. }
  945. iLen = 2 * (int)ucGetByte(iFodo, aucFpage);
  946. if (iLen == 0) {
  947. iFodo++;
  948. iLen = 2 * (int)ucGetByte(iFodo, aucFpage);
  949. }
  950. usIstd = usGetWord(iFodo + 1, aucFpage);
  951. vFillStyleFromStylesheet(usIstd, &tStyle);
  952. vGet8StyleInfo(iFodo, aucFpage + 3, iLen - 3, &tStyle);
  953. ulCharPos = ulGetLong(iIndex2 * 4, aucFpage);
  954. NO_DBG_HEX(ulCharPos);
  955. tStyle.ulFileOffset = ulCharPos2FileOffsetX(
  956. ulCharPos, &tStyle.eListID);
  957. vAdd2StyleInfoList(&tStyle);
  958. eRowInfo = eGet8RowInfo(iFodo,
  959. aucFpage + 3, iLen - 3, &tRow);
  960. switch (eRowInfo) {
  961. case found_a_cell:
  962. if (ulCharPosFirst != CP_INVALID) {
  963. break;
  964. }
  965. ulCharPosFirst = ulGetLong(
  966. iIndex2 * 4, aucFpage);
  967. NO_DBG_HEX(ulCharPosFirst);
  968. tRow.ulCharPosStart = ulCharPosFirst;
  969. tRow.ulFileOffsetStart =
  970. ulCharPos2FileOffset(ulCharPosFirst);
  971. NO_DBG_HEX_C(
  972. tRow.ulFileOffsetStart == FC_INVALID,
  973. ulCharPosFirst);
  974. break;
  975. case found_end_of_row:
  976. ulCharPosLast = ulGetLong(
  977. iIndex2 * 4, aucFpage);
  978. NO_DBG_HEX(ulCharPosLast);
  979. tRow.ulCharPosEnd = ulCharPosLast;
  980. tRow.ulFileOffsetEnd =
  981. ulCharPos2FileOffset(ulCharPosLast);
  982. NO_DBG_HEX_C(tRow.ulFileOffsetEnd == FC_INVALID,
  983. ulCharPosLast);
  984. vAdd2RowInfoList(&tRow);
  985. (void)memset(&tRow, 0, sizeof(tRow));
  986. ulCharPosFirst = CP_INVALID;
  987. break;
  988. case found_nothing:
  989. break;
  990. default:
  991. DBG_DEC(eRowInfo);
  992. break;
  993. }
  994. }
  995. }
  996. aulParfPage = xfree(aulParfPage);
  997. } /* end of vGet8PapInfo */
  998. /*
  999. * Fill the font information block with information
  1000. * from a Word 8/9/10/11 file.
  1001. */
  1002. void
  1003. vGet8FontInfo(int iFodo, USHORT usIstd,
  1004. const UCHAR *aucGrpprl, int iBytes, font_block_type *pFont)
  1005. {
  1006. long lTmp;
  1007. int iFodoOff, iInfoLen;
  1008. USHORT usFtc0, usFtc1, usFtc2, usTmp;
  1009. UCHAR ucTmp;
  1010. fail(iFodo < 0 || aucGrpprl == NULL || pFont == NULL);
  1011. usFtc0 = USHRT_MAX;
  1012. usFtc1 = USHRT_MAX;
  1013. usFtc2 = USHRT_MAX;
  1014. iFodoOff = 0;
  1015. while (iBytes >= iFodoOff + 2) {
  1016. switch (usGetWord(iFodo + iFodoOff, aucGrpprl)) {
  1017. case 0x0800: /* fRMarkDel */
  1018. ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
  1019. if (ucTmp == 0) {
  1020. pFont->usFontStyle &= ~FONT_MARKDEL;
  1021. } else {
  1022. pFont->usFontStyle |= FONT_MARKDEL;
  1023. }
  1024. break;
  1025. case 0x0835: /* fBold */
  1026. ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
  1027. switch (ucTmp) {
  1028. case 0: /* Unset */
  1029. pFont->usFontStyle &= ~FONT_BOLD;
  1030. break;
  1031. case 1: /* Set */
  1032. pFont->usFontStyle |= FONT_BOLD;
  1033. break;
  1034. case 128: /* Unchanged */
  1035. break;
  1036. case 129: /* Negation */
  1037. pFont->usFontStyle ^= FONT_BOLD;
  1038. break;
  1039. default:
  1040. DBG_DEC(ucTmp);
  1041. DBG_FIXME();
  1042. break;
  1043. }
  1044. break;
  1045. case 0x0836: /* fItalic */
  1046. ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
  1047. switch (ucTmp) {
  1048. case 0: /* Unset */
  1049. pFont->usFontStyle &= ~FONT_ITALIC;
  1050. break;
  1051. case 1: /* Set */
  1052. pFont->usFontStyle |= FONT_ITALIC;
  1053. break;
  1054. case 128: /* Unchanged */
  1055. break;
  1056. case 129: /* Negation */
  1057. pFont->usFontStyle ^= FONT_ITALIC;
  1058. break;
  1059. default:
  1060. DBG_DEC(ucTmp);
  1061. DBG_FIXME();
  1062. break;
  1063. }
  1064. break;
  1065. case 0x0837: /* fStrike */
  1066. ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
  1067. switch (ucTmp) {
  1068. case 0: /* Unset */
  1069. pFont->usFontStyle &= ~FONT_STRIKE;
  1070. break;
  1071. case 1: /* Set */
  1072. pFont->usFontStyle |= FONT_STRIKE;
  1073. break;
  1074. case 128: /* Unchanged */
  1075. break;
  1076. case 129: /* Negation */
  1077. pFont->usFontStyle ^= FONT_STRIKE;
  1078. break;
  1079. default:
  1080. DBG_DEC(ucTmp);
  1081. DBG_FIXME();
  1082. break;
  1083. }
  1084. break;
  1085. case 0x083a: /* fSmallCaps */
  1086. ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
  1087. switch (ucTmp) {
  1088. case 0: /* Unset */
  1089. pFont->usFontStyle &= ~FONT_SMALL_CAPITALS;
  1090. break;
  1091. case 1: /* Set */
  1092. pFont->usFontStyle |= FONT_SMALL_CAPITALS;
  1093. break;
  1094. case 128: /* Unchanged */
  1095. break;
  1096. case 129: /* Negation */
  1097. pFont->usFontStyle ^= FONT_SMALL_CAPITALS;
  1098. break;
  1099. default:
  1100. DBG_DEC(ucTmp);
  1101. DBG_FIXME();
  1102. break;
  1103. }
  1104. break;
  1105. case 0x083b: /* fCaps */
  1106. ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
  1107. switch (ucTmp) {
  1108. case 0: /* Unset */
  1109. pFont->usFontStyle &= ~FONT_CAPITALS;
  1110. break;
  1111. case 1: /* Set */
  1112. pFont->usFontStyle |= FONT_CAPITALS;
  1113. break;
  1114. case 128: /* Unchanged */
  1115. break;
  1116. case 129: /* Negation */
  1117. pFont->usFontStyle ^= FONT_CAPITALS;
  1118. break;
  1119. default:
  1120. DBG_DEC(ucTmp);
  1121. DBG_FIXME();
  1122. break;
  1123. }
  1124. break;
  1125. case 0x083c: /* fVanish */
  1126. ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
  1127. switch (ucTmp) {
  1128. case 0: /* Unset */
  1129. pFont->usFontStyle &= ~FONT_HIDDEN;
  1130. break;
  1131. case 1: /* Set */
  1132. pFont->usFontStyle |= FONT_HIDDEN;
  1133. break;
  1134. case 128: /* Unchanged */
  1135. break;
  1136. case 129: /* Negation */
  1137. pFont->usFontStyle ^= FONT_HIDDEN;
  1138. break;
  1139. default:
  1140. DBG_DEC(ucTmp);
  1141. DBG_FIXME();
  1142. break;
  1143. }
  1144. break;
  1145. case 0x2a32: /* cDefault */
  1146. pFont->usFontStyle &= FONT_HIDDEN;
  1147. pFont->ucFontColor = FONT_COLOR_DEFAULT;
  1148. break;
  1149. case 0x2a33: /* cPlain */
  1150. DBG_MSG("2a33: cPlain");
  1151. vFillFontFromStylesheet(usIstd, pFont);
  1152. break;
  1153. case 0x2a3e: /* cKul */
  1154. ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
  1155. if (ucTmp == 0 || ucTmp == 5) {
  1156. pFont->usFontStyle &= ~FONT_UNDERLINE;
  1157. } else {
  1158. NO_DBG_MSG("Underline text");
  1159. pFont->usFontStyle |= FONT_UNDERLINE;
  1160. if (ucTmp == 6) {
  1161. DBG_MSG("Bold text");
  1162. pFont->usFontStyle |= FONT_BOLD;
  1163. }
  1164. }
  1165. break;
  1166. case 0x2a42: /* cIco */
  1167. pFont->ucFontColor =
  1168. ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
  1169. NO_DBG_DEC(pFont->ucFontColor);
  1170. break;
  1171. case 0x2a44: /* cHpsInc */
  1172. DBG_MSG("0x2a44: sprmCHpsInc");
  1173. ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
  1174. DBG_DEC(ucTmp);
  1175. break;
  1176. case 0x2a48: /* cIss */
  1177. ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
  1178. ucTmp &= 0x07;
  1179. if (ucTmp == 1) {
  1180. pFont->usFontStyle |= FONT_SUPERSCRIPT;
  1181. NO_DBG_MSG("Superscript");
  1182. } else if (ucTmp == 2) {
  1183. pFont->usFontStyle |= FONT_SUBSCRIPT;
  1184. NO_DBG_MSG("Subscript");
  1185. }
  1186. break;
  1187. case 0x4a30: /* cIstd */
  1188. usTmp = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
  1189. NO_DBG_DEC(usTmp);
  1190. break;
  1191. case 0x4a43: /* cHps */
  1192. pFont->usFontSize =
  1193. usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
  1194. NO_DBG_DEC(pFont->usFontSize);
  1195. break;
  1196. case 0x4a4d: /* cHpsMul */
  1197. DBG_MSG("0x4a4d: sprmCHpsMul");
  1198. usTmp = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
  1199. DBG_DEC(usTmp);
  1200. break;
  1201. case 0x4a4f: /* cFtc0 */
  1202. usFtc0 = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
  1203. break;
  1204. case 0x4a50: /* cFtc1 */
  1205. usFtc1 = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
  1206. break;
  1207. case 0x4a51: /* cFtc2 */
  1208. usFtc2 = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
  1209. break;
  1210. case 0xca47: /* cMajority */
  1211. DBG_MSG("0xca47: sprmCMajority");
  1212. break;
  1213. case 0xca4a: /* cHpsInc1 */
  1214. usTmp = usGetWord(iFodo + iFodoOff + 2, aucGrpprl);
  1215. lTmp = (long)pFont->usFontSize + (long)usTmp;
  1216. if (lTmp < 8) {
  1217. pFont->usFontSize = 8;
  1218. } else if (lTmp > 32766) {
  1219. pFont->usFontSize = 32766;
  1220. } else {
  1221. pFont->usFontSize = (USHORT)lTmp;
  1222. }
  1223. break;
  1224. case 0xca4c: /* cMajority50 */
  1225. DBG_MSG("0xca4c: sprmCMajority50");
  1226. break;
  1227. case 0xea3f: /* cHps, cHpsPos */
  1228. ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
  1229. DBG_DEC(ucTmp);
  1230. if (ucTmp != 0) {
  1231. pFont->usFontSize = (USHORT)ucTmp;
  1232. }
  1233. ucTmp = ucGetByte(iFodo + iFodoOff + 3, aucGrpprl);
  1234. DBG_DEC(ucTmp);
  1235. break;
  1236. default:
  1237. break;
  1238. }
  1239. iInfoLen = iGet8InfoLength(iFodo + iFodoOff, aucGrpprl);
  1240. fail(iInfoLen <= 0);
  1241. iFodoOff += iInfoLen;
  1242. }
  1243. /* Combine the Ftc's to a FontNumber */
  1244. NO_DBG_DEC_C(usFtc0 != USHRT_MAX, usFtc0);
  1245. NO_DBG_DEC_C(usFtc2 != USHRT_MAX, usFtc2);
  1246. NO_DBG_DEC_C(usFtc1 != USHRT_MAX, usFtc1);
  1247. if (usFtc0 <= 0x7fff) {
  1248. if (usFtc0 <= (USHORT)UCHAR_MAX) {
  1249. pFont->ucFontNumber = (UCHAR)usFtc0;
  1250. } else {
  1251. DBG_DEC(usFtc0);
  1252. DBG_FIXME();
  1253. pFont->ucFontNumber = 0;
  1254. }
  1255. } else if (usFtc2 <= 0x7fff) {
  1256. if (usFtc2 <= (USHORT)UCHAR_MAX) {
  1257. pFont->ucFontNumber = (UCHAR)usFtc2;
  1258. } else {
  1259. DBG_DEC(usFtc2);
  1260. DBG_FIXME();
  1261. pFont->ucFontNumber = 0;
  1262. }
  1263. } else if (usFtc1 <= 0x7fff) {
  1264. if (usFtc1 <= (USHORT)UCHAR_MAX) {
  1265. pFont->ucFontNumber = (UCHAR)usFtc1;
  1266. } else {
  1267. DBG_DEC(usFtc1);
  1268. DBG_FIXME();
  1269. pFont->ucFontNumber = 0;
  1270. }
  1271. }
  1272. } /* end of vGet8FontInfo */
  1273. /*
  1274. * Fill the picture information block with information
  1275. * from a Word 8/9/10/11 file.
  1276. * Returns TRUE when successful, otherwise FALSE
  1277. */
  1278. static BOOL
  1279. bGet8PicInfo(int iFodo,
  1280. const UCHAR *aucGrpprl, int iBytes, picture_block_type *pPicture)
  1281. {
  1282. ULONG ulTmp;
  1283. int iFodoOff, iInfoLen;
  1284. BOOL bFound;
  1285. UCHAR ucTmp;
  1286. fail(iFodo <= 0 || aucGrpprl == NULL || pPicture == NULL);
  1287. iFodoOff = 0;
  1288. bFound = FALSE;
  1289. while (iBytes >= iFodoOff + 2) {
  1290. switch (usGetWord(iFodo + iFodoOff, aucGrpprl)) {
  1291. #if 0
  1292. case 0x0806: /* fData */
  1293. ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
  1294. if (ucTmp == 0x01) {
  1295. /* Not a picture, but a form field */
  1296. return FALSE;
  1297. }
  1298. DBG_DEC_C(ucTmp != 0, ucTmp);
  1299. break;
  1300. #endif
  1301. case 0x080a: /* fOle2 */
  1302. ucTmp = ucGetByte(iFodo + iFodoOff + 2, aucGrpprl);
  1303. if (ucTmp == 0x01) {
  1304. /* Not a picture, but an OLE object */
  1305. return FALSE;
  1306. }
  1307. DBG_DEC_C(ucTmp != 0, ucTmp);
  1308. break;
  1309. case 0x680e: /* fcObj */
  1310. ulTmp = ulGetLong(iFodo + iFodoOff + 2, aucGrpprl);
  1311. DBG_HEX(ulTmp);
  1312. break;
  1313. case 0x6a03: /* fcPic */
  1314. pPicture->ulPictureOffset = ulGetLong(
  1315. iFodo + iFodoOff + 2, aucGrpprl);
  1316. bFound = TRUE;
  1317. break;
  1318. default:
  1319. break;
  1320. }
  1321. iInfoLen = iGet8InfoLength(iFodo + iFodoOff, aucGrpprl);
  1322. fail(iInfoLen <= 0);
  1323. iFodoOff += iInfoLen;
  1324. }
  1325. return bFound;
  1326. } /* end of bGet8PicInfo */
  1327. /*
  1328. * Build the lists with Character Information for Word 8/9/10/11 files
  1329. */
  1330. void
  1331. vGet8ChrInfo(FILE *pFile, const pps_info_type *pPPS,
  1332. const ULONG *aulBBD, size_t tBBDLen,
  1333. const ULONG *aulSBD, size_t tSBDLen,
  1334. const UCHAR *aucHeader)
  1335. {
  1336. font_block_type tFont;
  1337. picture_block_type tPicture;
  1338. ULONG *aulCharPage;
  1339. UCHAR *aucBuffer;
  1340. ULONG ulFileOffset, ulCharPos, ulBeginCharInfo;
  1341. size_t tCharInfoLen, tOffset, tLen;
  1342. int iIndex, iIndex2, iRun, iFodo, iLen;
  1343. USHORT usIstd;
  1344. UCHAR aucFpage[BIG_BLOCK_SIZE];
  1345. fail(pFile == NULL || pPPS == NULL || aucHeader == NULL);
  1346. fail(aulBBD == NULL || aulSBD == NULL);
  1347. ulBeginCharInfo = ulGetLong(0xfa, aucHeader); /* fcPlcfbteChpx */
  1348. NO_DBG_HEX(ulBeginCharInfo);
  1349. tCharInfoLen = (size_t)ulGetLong(0xfe, aucHeader); /* lcbPlcfbteChpx */
  1350. NO_DBG_DEC(tCharInfoLen);
  1351. if (tCharInfoLen < 4) {
  1352. DBG_DEC(tCharInfoLen);
  1353. return;
  1354. }
  1355. aucBuffer = aucFillInfoBuffer(pFile, &pPPS->tTable,
  1356. aulBBD, tBBDLen, aulSBD, tSBDLen,
  1357. ulBeginCharInfo, tCharInfoLen);
  1358. if (aucBuffer == NULL) {
  1359. return;
  1360. }
  1361. NO_DBG_PRINT_BLOCK(aucBuffer, tCharInfoLen);
  1362. tLen = (tCharInfoLen / 4 - 1) / 2;
  1363. aulCharPage = xcalloc(tLen, sizeof(ULONG));
  1364. for (iIndex = 0, tOffset = (tLen + 1) * 4;
  1365. iIndex < (int)tLen;
  1366. iIndex++, tOffset += 4) {
  1367. aulCharPage[iIndex] = ulGetLong(tOffset, aucBuffer);
  1368. NO_DBG_DEC(aulCharPage[iIndex]);
  1369. }
  1370. DBG_HEX(ulGetLong(0, aucBuffer));
  1371. aucBuffer = xfree(aucBuffer);
  1372. NO_DBG_PRINT_BLOCK(aucHeader, HEADER_SIZE);
  1373. for (iIndex = 0; iIndex < (int)tLen; iIndex++) {
  1374. fail(aulCharPage[iIndex] > ULONG_MAX / BIG_BLOCK_SIZE);
  1375. if (!bReadBuffer(pFile, pPPS->tWordDocument.ulSB,
  1376. aulBBD, tBBDLen, BIG_BLOCK_SIZE,
  1377. aucFpage,
  1378. aulCharPage[iIndex] * BIG_BLOCK_SIZE,
  1379. BIG_BLOCK_SIZE)) {
  1380. break;
  1381. }
  1382. NO_DBG_PRINT_BLOCK(aucFpage, BIG_BLOCK_SIZE);
  1383. iRun = (int)ucGetByte(0x1ff, aucFpage);
  1384. NO_DBG_DEC(iRun);
  1385. for (iIndex2 = 0; iIndex2 < iRun; iIndex2++) {
  1386. ulCharPos = ulGetLong(iIndex2 * 4, aucFpage);
  1387. ulFileOffset = ulCharPos2FileOffset(ulCharPos);
  1388. iFodo = 2 * (int)ucGetByte(
  1389. (iRun + 1) * 4 + iIndex2, aucFpage);
  1390. iLen = (int)ucGetByte(iFodo, aucFpage);
  1391. usIstd = usGetIstd(ulFileOffset);
  1392. vFillFontFromStylesheet(usIstd, &tFont);
  1393. if (iFodo != 0) {
  1394. vGet8FontInfo(iFodo, usIstd,
  1395. aucFpage + 1, iLen - 1, &tFont);
  1396. }
  1397. tFont.ulFileOffset = ulFileOffset;
  1398. vAdd2FontInfoList(&tFont);
  1399. if (iFodo <= 0) {
  1400. continue;
  1401. }
  1402. (void)memset(&tPicture, 0, sizeof(tPicture));
  1403. if (bGet8PicInfo(iFodo, aucFpage + 1,
  1404. iLen - 1, &tPicture)) {
  1405. tPicture.ulFileOffset = ulFileOffset;
  1406. tPicture.ulFileOffsetPicture =
  1407. ulDataPos2FileOffset(
  1408. tPicture.ulPictureOffset);
  1409. vAdd2PictInfoList(&tPicture);
  1410. }
  1411. }
  1412. }
  1413. aulCharPage = xfree(aulCharPage);
  1414. } /* end of vGet8ChrInfo */