PageRenderTime 65ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java

https://github.com/minstrelsy/SimpleAndroidDocView
Java | 759 lines | 519 code | 29 blank | 211 comment | 51 complexity | ad7ef563bd5c85239b2ca09f401501f5 MD5 | raw file
Possible License(s): Apache-2.0
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hwpf.sprm;
  16. import org.apache.poi.hwpf.usermodel.ShadingDescriptor80;
  17. import org.apache.poi.hwpf.model.Colorref;
  18. import org.apache.poi.hwpf.model.Hyphenation;
  19. import org.apache.poi.hwpf.model.StyleSheet;
  20. import org.apache.poi.hwpf.usermodel.BorderCode;
  21. import org.apache.poi.hwpf.usermodel.CharacterProperties;
  22. import org.apache.poi.hwpf.usermodel.DateAndTime;
  23. import org.apache.poi.hwpf.usermodel.ShadingDescriptor;
  24. import org.apache.poi.util.Internal;
  25. import org.apache.poi.util.LittleEndian;
  26. import org.apache.poi.util.POILogFactory;
  27. import org.apache.poi.util.POILogger;
  28. @Internal
  29. public final class CharacterSprmUncompressor extends SprmUncompressor
  30. {
  31. private static final POILogger logger = POILogFactory
  32. .getLogger( CharacterSprmUncompressor.class );
  33. public CharacterSprmUncompressor()
  34. {
  35. }
  36. @Deprecated
  37. public static CharacterProperties uncompressCHP(
  38. CharacterProperties parent, byte[] grpprl, int offset )
  39. {
  40. CharacterProperties newProperties = parent.clone();
  41. applySprms( parent, grpprl, offset, true, newProperties );
  42. return newProperties;
  43. }
  44. public static CharacterProperties uncompressCHP( StyleSheet styleSheet,
  45. CharacterProperties parStyle, byte[] grpprl, int offset )
  46. {
  47. CharacterProperties newProperties;
  48. if ( parStyle == null )
  49. {
  50. parStyle = new CharacterProperties();
  51. newProperties = new CharacterProperties();
  52. }
  53. else
  54. {
  55. newProperties = parStyle.clone();
  56. }
  57. /*
  58. * not fully conform to specification, but the fastest way to make it
  59. * work. Shall be rewritten if any errors would be found -- vlsergey
  60. */
  61. Integer style = getIstd( grpprl, offset );
  62. if ( style != null )
  63. {
  64. try
  65. {
  66. applySprms( parStyle, styleSheet.getCHPX( style ), 0, false,
  67. newProperties );
  68. }
  69. catch ( Exception exc )
  70. {
  71. logger.log( POILogger.ERROR, "Unable to apply all style ",
  72. style, " CHP SPRMs to CHP: ", exc, exc );
  73. }
  74. }
  75. CharacterProperties styleProperties = newProperties;
  76. newProperties = styleProperties.clone();
  77. try
  78. {
  79. applySprms( styleProperties, grpprl, offset, true, newProperties );
  80. }
  81. catch ( Exception exc )
  82. {
  83. logger.log( POILogger.ERROR,
  84. "Unable to process all direct CHP SPRMs: ", exc, exc );
  85. }
  86. return newProperties;
  87. }
  88. private static void applySprms( CharacterProperties parentProperties,
  89. byte[] grpprl, int offset, boolean warnAboutNonChpSprms,
  90. CharacterProperties targetProperties )
  91. {
  92. SprmIterator sprmIt = new SprmIterator( grpprl, offset );
  93. while ( sprmIt.hasNext() )
  94. {
  95. SprmOperation sprm = sprmIt.next();
  96. if ( sprm.getType() != 2 )
  97. {
  98. if ( warnAboutNonChpSprms )
  99. {
  100. logger.log( POILogger.WARN,
  101. "Non-CHP SPRM returned by SprmIterator: " + sprm );
  102. }
  103. continue;
  104. }
  105. unCompressCHPOperation( parentProperties, targetProperties, sprm );
  106. }
  107. }
  108. private static Integer getIstd( byte[] grpprl, int offset )
  109. {
  110. Integer style = null;
  111. try
  112. {
  113. SprmIterator sprmIt = new SprmIterator( grpprl, offset );
  114. while ( sprmIt.hasNext() )
  115. {
  116. SprmOperation sprm = sprmIt.next();
  117. if ( sprm.getType() == 2 && sprm.getOperation() == 0x30 )
  118. {
  119. // sprmCIstd (0x4A30)
  120. style = Integer.valueOf( sprm.getOperand() );
  121. }
  122. }
  123. }
  124. catch ( Exception exc )
  125. {
  126. logger.log( POILogger.ERROR,
  127. "Unable to extract istd from direct CHP SPRM: ", exc, exc );
  128. }
  129. return style;
  130. }
  131. /**
  132. * Used in decompression of a chpx. This performs an operation defined by
  133. * a single sprm.
  134. *
  135. * @param oldCHP The base CharacterProperties.
  136. * @param newCHP The current CharacterProperties.
  137. * @param operand The operand defined by the sprm (See Word file format spec)
  138. * @param param The parameter defined by the sprm (See Word file format spec)
  139. * @param varParam The variable length parameter defined by the sprm. (See
  140. * Word file format spec)
  141. * @param grpprl The entire chpx that this operation is a part of.
  142. * @param offset The offset in the grpprl of the next sprm
  143. * @param styleSheet The StyleSheet for this document.
  144. */
  145. static void unCompressCHPOperation (CharacterProperties oldCHP,
  146. CharacterProperties newCHP,
  147. SprmOperation sprm)
  148. {
  149. switch (sprm.getOperation())
  150. {
  151. case 0:
  152. newCHP.setFRMarkDel (getFlag (sprm.getOperand()));
  153. break;
  154. case 0x1:
  155. newCHP.setFRMark (getFlag (sprm.getOperand()));
  156. break;
  157. case 0x2:
  158. newCHP.setFFldVanish (getFlag (sprm.getOperand()));
  159. break;
  160. case 0x3:
  161. // sprmCPicLocation -- 0x6A03
  162. /*
  163. * [MS-DOC]
  164. *
  165. * Page 104 of 622
  166. *
  167. * A signed 32-bit integer that specifies either the position in the
  168. * Data Stream of a picture or binary data or the name of an OLE
  169. * object storage.
  170. */
  171. newCHP.setFcPic( sprm.getOperand() );
  172. newCHP.setFSpec( true );
  173. break;
  174. case 0x4:
  175. newCHP.setIbstRMark ((short) sprm.getOperand());
  176. break;
  177. case 0x5:
  178. newCHP.setDttmRMark (new DateAndTime(sprm.getGrpprl(), sprm.getGrpprlOffset()));
  179. break;
  180. case 0x6:
  181. newCHP.setFData (getFlag (sprm.getOperand()));
  182. break;
  183. case 0x7:
  184. //don't care about this
  185. break;
  186. case 0x8:
  187. //short chsDiff = (short)((param & 0xff0000) >>> 16);
  188. int operand =sprm.getOperand();
  189. short chsDiff = (short) (operand & 0x0000ff);
  190. newCHP.setFChsDiff (getFlag (chsDiff));
  191. newCHP.setChse ((short) (operand & 0xffff00));
  192. break;
  193. case 0x9:
  194. newCHP.setFSpec (true);
  195. newCHP.setFtcSym (LittleEndian.getShort (sprm.getGrpprl(), sprm.getGrpprlOffset()));
  196. newCHP.setXchSym (LittleEndian.getShort (sprm.getGrpprl(), sprm.getGrpprlOffset() + 2));
  197. break;
  198. case 0xa:
  199. newCHP.setFOle2 (getFlag (sprm.getOperand()));
  200. break;
  201. case 0xb:
  202. // Obsolete
  203. break;
  204. case 0xc:
  205. newCHP.setIcoHighlight ((byte) sprm.getOperand());
  206. newCHP.setFHighlight (getFlag (sprm.getOperand()));
  207. break;
  208. case 0xd:
  209. // undocumented
  210. break;
  211. case 0xe:
  212. newCHP.setFcObj (sprm.getOperand());
  213. break;
  214. case 0xf:
  215. // undocumented
  216. break;
  217. case 0x10:
  218. // undocumented
  219. break;
  220. // undocumented till 0x30
  221. case 0x11:
  222. // sprmCFWebHidden
  223. break;
  224. case 0x12:
  225. break;
  226. case 0x13:
  227. break;
  228. case 0x14:
  229. break;
  230. case 0x15:
  231. // sprmCRsidProp
  232. break;
  233. case 0x16:
  234. // sprmCRsidText
  235. break;
  236. case 0x17:
  237. // sprmCRsidRMDel
  238. break;
  239. case 0x18:
  240. // sprmCFSpecVanish
  241. break;
  242. case 0x19:
  243. break;
  244. case 0x1a:
  245. // sprmCFMathPr
  246. break;
  247. case 0x1b:
  248. break;
  249. case 0x1c:
  250. break;
  251. case 0x1d:
  252. break;
  253. case 0x1e:
  254. break;
  255. case 0x1f:
  256. break;
  257. case 0x20:
  258. break;
  259. case 0x21:
  260. break;
  261. case 0x22:
  262. break;
  263. case 0x23:
  264. break;
  265. case 0x24:
  266. break;
  267. case 0x25:
  268. break;
  269. case 0x26:
  270. break;
  271. case 0x27:
  272. break;
  273. case 0x28:
  274. break;
  275. case 0x29:
  276. break;
  277. case 0x2a:
  278. break;
  279. case 0x2b:
  280. break;
  281. case 0x2c:
  282. break;
  283. case 0x2d:
  284. break;
  285. case 0x2e:
  286. break;
  287. case 0x2f:
  288. break;
  289. case 0x30:
  290. newCHP.setIstd( sprm.getOperand() );
  291. // 0x30 is supported by uncompressCHP(...)
  292. break;
  293. case 0x31:
  294. //permutation vector for fast saves, who cares!
  295. break;
  296. case 0x32:
  297. newCHP.setFBold (false);
  298. newCHP.setFItalic (false);
  299. newCHP.setFOutline (false);
  300. newCHP.setFStrike (false);
  301. newCHP.setFShadow (false);
  302. newCHP.setFSmallCaps (false);
  303. newCHP.setFCaps (false);
  304. newCHP.setFVanish (false);
  305. newCHP.setKul ((byte) 0);
  306. newCHP.setIco ((byte) 0);
  307. break;
  308. case 0x33:
  309. // preserve the fSpec setting from the original CHP
  310. boolean fSpec = newCHP.isFSpec();
  311. newCHP = oldCHP.clone();
  312. newCHP.setFSpec( fSpec );
  313. return;
  314. case 0x34:
  315. // sprmCKcd
  316. break;
  317. case 0x35:
  318. newCHP.setFBold (getCHPFlag ((byte) sprm.getOperand(), oldCHP.isFBold ()));
  319. break;
  320. case 0x36:
  321. newCHP.setFItalic (getCHPFlag ((byte) sprm.getOperand(), oldCHP.isFItalic ()));
  322. break;
  323. case 0x37:
  324. newCHP.setFStrike (getCHPFlag ((byte) sprm.getOperand(), oldCHP.isFStrike ()));
  325. break;
  326. case 0x38:
  327. newCHP.setFOutline (getCHPFlag ((byte) sprm.getOperand(), oldCHP.isFOutline ()));
  328. break;
  329. case 0x39:
  330. newCHP.setFShadow (getCHPFlag ((byte) sprm.getOperand(), oldCHP.isFShadow ()));
  331. break;
  332. case 0x3a:
  333. newCHP.setFSmallCaps (getCHPFlag ((byte) sprm.getOperand(), oldCHP.isFSmallCaps ()));
  334. break;
  335. case 0x3b:
  336. newCHP.setFCaps (getCHPFlag ((byte) sprm.getOperand(), oldCHP.isFCaps ()));
  337. break;
  338. case 0x3c:
  339. newCHP.setFVanish (getCHPFlag ((byte) sprm.getOperand(), oldCHP.isFVanish ()));
  340. break;
  341. case 0x3d:
  342. newCHP.setFtcAscii ((short) sprm.getOperand());
  343. break;
  344. case 0x3e:
  345. newCHP.setKul ((byte) sprm.getOperand());
  346. break;
  347. case 0x3f:
  348. operand = sprm.getOperand();
  349. int hps = operand & 0xff;
  350. if (hps != 0)
  351. {
  352. newCHP.setHps (hps);
  353. }
  354. //byte cInc = (byte)(((byte)(param & 0xfe00) >>> 4) >> 1);
  355. byte cInc = (byte) ((operand & 0xff00) >>> 8);
  356. cInc = (byte) (cInc >>> 1);
  357. if (cInc != 0)
  358. {
  359. newCHP.setHps (Math.max (newCHP.getHps () + (cInc * 2), 2));
  360. }
  361. //byte hpsPos = (byte)((param & 0xff0000) >>> 8);
  362. byte hpsPos = (byte) ((operand & 0xff0000) >>> 16);
  363. if (hpsPos != 0x80)
  364. {
  365. newCHP.setHpsPos (hpsPos);
  366. }
  367. boolean fAdjust = (operand & 0x0100) > 0;
  368. if (fAdjust && hpsPos != 128 && hpsPos != 0 && oldCHP.getHpsPos () == 0)
  369. {
  370. newCHP.setHps (Math.max (newCHP.getHps () + ( -2), 2));
  371. }
  372. if (fAdjust && hpsPos == 0 && oldCHP.getHpsPos () != 0)
  373. {
  374. newCHP.setHps (Math.max (newCHP.getHps () + 2, 2));
  375. }
  376. break;
  377. case 0x40:
  378. newCHP.setDxaSpace (sprm.getOperand());
  379. break;
  380. case 0x41:
  381. newCHP.setLidDefault ((short) sprm.getOperand());
  382. break;
  383. case 0x42:
  384. newCHP.setIco ((byte) sprm.getOperand());
  385. break;
  386. case 0x43:
  387. newCHP.setHps (sprm.getOperand());
  388. break;
  389. case 0x44:
  390. byte hpsLvl = (byte) sprm.getOperand();
  391. newCHP.setHps (Math.max (newCHP.getHps () + (hpsLvl * 2), 2));
  392. break;
  393. case 0x45:
  394. newCHP.setHpsPos ((short) sprm.getOperand());
  395. break;
  396. case 0x46:
  397. if (sprm.getOperand() != 0)
  398. {
  399. if (oldCHP.getHpsPos () == 0)
  400. {
  401. newCHP.setHps (Math.max (newCHP.getHps () + ( -2), 2));
  402. }
  403. }
  404. else
  405. {
  406. if (oldCHP.getHpsPos () != 0)
  407. {
  408. newCHP.setHps (Math.max (newCHP.getHps () + 2, 2));
  409. }
  410. }
  411. break;
  412. case 0x47:
  413. /*CharacterProperties genCHP = new CharacterProperties ();
  414. genCHP.setFtcAscii (4);
  415. genCHP = (CharacterProperties) unCompressProperty (varParam, genCHP,
  416. styleSheet);
  417. CharacterProperties styleCHP = styleSheet.getStyleDescription (oldCHP.
  418. getBaseIstd ()).getCHP ();
  419. if (genCHP.isFBold () == newCHP.isFBold ())
  420. {
  421. newCHP.setFBold (styleCHP.isFBold ());
  422. }
  423. if (genCHP.isFItalic () == newCHP.isFItalic ())
  424. {
  425. newCHP.setFItalic (styleCHP.isFItalic ());
  426. }
  427. if (genCHP.isFSmallCaps () == newCHP.isFSmallCaps ())
  428. {
  429. newCHP.setFSmallCaps (styleCHP.isFSmallCaps ());
  430. }
  431. if (genCHP.isFVanish () == newCHP.isFVanish ())
  432. {
  433. newCHP.setFVanish (styleCHP.isFVanish ());
  434. }
  435. if (genCHP.isFStrike () == newCHP.isFStrike ())
  436. {
  437. newCHP.setFStrike (styleCHP.isFStrike ());
  438. }
  439. if (genCHP.isFCaps () == newCHP.isFCaps ())
  440. {
  441. newCHP.setFCaps (styleCHP.isFCaps ());
  442. }
  443. if (genCHP.getFtcAscii () == newCHP.getFtcAscii ())
  444. {
  445. newCHP.setFtcAscii (styleCHP.getFtcAscii ());
  446. }
  447. if (genCHP.getFtcFE () == newCHP.getFtcFE ())
  448. {
  449. newCHP.setFtcFE (styleCHP.getFtcFE ());
  450. }
  451. if (genCHP.getFtcOther () == newCHP.getFtcOther ())
  452. {
  453. newCHP.setFtcOther (styleCHP.getFtcOther ());
  454. }
  455. if (genCHP.getHps () == newCHP.getHps ())
  456. {
  457. newCHP.setHps (styleCHP.getHps ());
  458. }
  459. if (genCHP.getHpsPos () == newCHP.getHpsPos ())
  460. {
  461. newCHP.setHpsPos (styleCHP.getHpsPos ());
  462. }
  463. if (genCHP.getKul () == newCHP.getKul ())
  464. {
  465. newCHP.setKul (styleCHP.getKul ());
  466. }
  467. if (genCHP.getDxaSpace () == newCHP.getDxaSpace ())
  468. {
  469. newCHP.setDxaSpace (styleCHP.getDxaSpace ());
  470. }
  471. if (genCHP.getIco () == newCHP.getIco ())
  472. {
  473. newCHP.setIco (styleCHP.getIco ());
  474. }
  475. if (genCHP.getLidDefault () == newCHP.getLidDefault ())
  476. {
  477. newCHP.setLidDefault (styleCHP.getLidDefault ());
  478. }
  479. if (genCHP.getLidFE () == newCHP.getLidFE ())
  480. {
  481. newCHP.setLidFE (styleCHP.getLidFE ());
  482. }*/
  483. break;
  484. case 0x48:
  485. newCHP.setIss ((byte) sprm.getOperand());
  486. break;
  487. case 0x49:
  488. newCHP.setHps (LittleEndian.getShort (sprm.getGrpprl(), sprm.getGrpprlOffset()));
  489. break;
  490. case 0x4a:
  491. int increment = LittleEndian.getShort (sprm.getGrpprl(), sprm.getGrpprlOffset());
  492. newCHP.setHps (Math.max (newCHP.getHps () + increment, 8));
  493. break;
  494. case 0x4b:
  495. newCHP.setHpsKern (sprm.getOperand());
  496. break;
  497. // Microsoft Office Word 97-2007 Binary File Format (.doc) Specification
  498. // Page 59 of 210
  499. case 0x4c:
  500. // sprmCMajority50 -- 0xCA4C
  501. // unCompressCHPOperation (oldCHP, newCHP, 0x47, param, varParam,
  502. // styleSheet, opSize);
  503. break;
  504. case 0x4d:
  505. // sprmCHpsMul -- 0x4A4D
  506. float percentage = sprm.getOperand() / 100.0f;
  507. int add = (int) ( percentage * newCHP.getHps() );
  508. newCHP.setHps( newCHP.getHps() + add );
  509. break;
  510. case 0x4e:
  511. // sprmCHresi -- 0x484e
  512. Hyphenation hyphenation = new Hyphenation(
  513. (short) sprm.getOperand() );
  514. newCHP.setHresi( hyphenation );
  515. break;
  516. case 0x4f:
  517. newCHP.setFtcAscii ((short) sprm.getOperand());
  518. break;
  519. case 0x50:
  520. newCHP.setFtcFE ((short) sprm.getOperand());
  521. break;
  522. case 0x51:
  523. newCHP.setFtcOther ((short) sprm.getOperand());
  524. break;
  525. case 0x52:
  526. // sprmCCharScale
  527. break;
  528. case 0x53:
  529. newCHP.setFDStrike (getFlag (sprm.getOperand()));
  530. break;
  531. case 0x54:
  532. newCHP.setFImprint (getFlag (sprm.getOperand()));
  533. break;
  534. case 0x55:
  535. // sprmCFSpec -- 0x0855
  536. newCHP.setFSpec( getFlag( sprm.getOperand() ) );
  537. break;
  538. case 0x56:
  539. newCHP.setFObj (getFlag (sprm.getOperand()));
  540. break;
  541. case 0x57:
  542. // sprmCPropRMark -- 0xCA57
  543. /*
  544. * Microsoft Office Word 97-2007 Binary File Format (.doc)
  545. * Specification
  546. *
  547. * Page 78 of 210
  548. *
  549. * sprmCPropRMark (opcode 0xCA57) is interpreted by moving the first
  550. * parameter byte to chp.fPropRMark, the next two bytes to
  551. * chp.ibstPropRMark, and the remaining four bytes to
  552. * chp.dttmPropRMark.
  553. */
  554. byte[] buf = sprm.getGrpprl();
  555. int offset = sprm.getGrpprlOffset();
  556. newCHP.setFPropRMark( buf[offset] != 0 );
  557. newCHP.setIbstPropRMark( LittleEndian.getShort( buf, offset + 1 ) );
  558. newCHP.setDttmPropRMark( new DateAndTime( buf, offset + 3 ) );
  559. break;
  560. case 0x58:
  561. newCHP.setFEmboss (getFlag (sprm.getOperand()));
  562. break;
  563. case 0x59:
  564. newCHP.setSfxtText ((byte) sprm.getOperand());
  565. break;
  566. case 0x5a:
  567. // sprmCFBiDi
  568. break;
  569. case 0x5b:
  570. break;
  571. case 0x5c:
  572. // sprmCFBoldBi
  573. break;
  574. case 0x5d:
  575. // sprmCFItalicBi
  576. break;
  577. case 0x5e:
  578. // sprmCFtcBi
  579. break;
  580. case 0x5f:
  581. // sprmCLidBi
  582. break;
  583. case 0x60:
  584. // sprmCIcoBi
  585. break;
  586. case 0x61:
  587. // sprmCHpsBi
  588. break;
  589. case 0x62:
  590. // sprmCDispFldRMark -- 0xCA62
  591. /*
  592. * Microsoft Office Word 97-2007 Binary File Format (.doc)
  593. * Specification
  594. *
  595. * Page 78 of 210
  596. *
  597. * sprmCDispFldRMark (opcode 0xCA62) is interpreted by moving the
  598. * first parameter byte to chp.fDispFldRMark, the next two bytes to
  599. * chp.ibstDispFldRMark, the next four bytes to
  600. * chp.dttmDispFldRMark, and the remaining 32 bytes to
  601. * chp.xstDispFldRMark.
  602. */
  603. byte[] xstDispFldRMark = new byte[32];
  604. buf = sprm.getGrpprl();
  605. offset = sprm.getGrpprlOffset();
  606. newCHP.setFDispFldRMark( 0 != buf[offset] );
  607. newCHP.setIbstDispFldRMark( LittleEndian.getShort( buf, offset + 1 ) );
  608. newCHP.setDttmDispFldRMark( new DateAndTime( buf, offset + 3 ) );
  609. System.arraycopy( buf, offset + 7, xstDispFldRMark, 0, 32 );
  610. newCHP.setXstDispFldRMark( xstDispFldRMark );
  611. break;
  612. case 0x63:
  613. newCHP.setIbstRMarkDel ((short) sprm.getOperand());
  614. break;
  615. case 0x64:
  616. newCHP.setDttmRMarkDel (new DateAndTime(sprm.getGrpprl(), sprm.getGrpprlOffset()));
  617. break;
  618. case 0x65:
  619. newCHP.setBrc (new BorderCode(sprm.getGrpprl(), sprm.getGrpprlOffset()));
  620. break;
  621. case 0x66:
  622. // sprmCShd80
  623. /*
  624. * "A Shd80 structure that specifies the background shading for the text. By default, text is not shaded."
  625. *
  626. * Word (.doc) Binary File Format. Copyright (c) 2011 Microsoft
  627. * Corporation. Release: Tuesday, March 15, 2011
  628. */
  629. ShadingDescriptor80 oldDescriptor = new ShadingDescriptor80(
  630. sprm.getGrpprl(), sprm.getGrpprlOffset() );
  631. ShadingDescriptor newDescriptor = oldDescriptor
  632. .toShadingDescriptor();
  633. newCHP.setShd( newDescriptor );
  634. break;
  635. case 0x67:
  636. // Obsolete
  637. break;
  638. case 0x68:
  639. // sprmCFUsePgsuSettings
  640. break;
  641. case 0x69:
  642. break;
  643. case 0x6a:
  644. break;
  645. case 0x6b:
  646. break;
  647. case 0x6c:
  648. break;
  649. case 0x6d:
  650. newCHP.setLidDefault ((short) sprm.getOperand());
  651. break;
  652. case 0x6e:
  653. newCHP.setLidFE ((short) sprm.getOperand());
  654. break;
  655. case 0x6f:
  656. newCHP.setIdctHint ((byte) sprm.getOperand());
  657. break;
  658. case 0x70:
  659. // sprmCCv -- 0x6870
  660. newCHP.setCv( new Colorref( sprm.getOperand() ) );
  661. break;
  662. case 0x71:
  663. // sprmCShd
  664. break;
  665. case 0x72:
  666. // sprmCBrc
  667. break;
  668. case 0x73:
  669. // sprmCRgLid0
  670. break;
  671. case 0x74:
  672. // sprmCRgLid1
  673. break;
  674. case 0x75:
  675. // sprmCFNoProof -- 0x875
  676. /*
  677. * "A ToggleOperand value that specifies whether the text is excluded from the proofing analysis. By default, text is not excluded from the proofing analysis."
  678. *
  679. * Word (.doc) Binary File Format. Copyright (c) 2012 Microsoft
  680. * Corporation. Released: October 8, 2012
  681. */
  682. newCHP.setFNoProof(getCHPFlag((byte) sprm.getOperand(),
  683. oldCHP.isFNoProof()));
  684. break;
  685. default:
  686. logger.log( POILogger.DEBUG, "Unknown CHP sprm ignored: " + sprm );
  687. break;
  688. }
  689. }
  690. private static boolean getCHPFlag (byte x, boolean oldVal)
  691. {
  692. /*
  693. switch(x)
  694. {
  695. case 0:
  696. return false;
  697. case 1:
  698. return true;
  699. case (byte)0x80:
  700. return oldVal;
  701. case (byte)0x81:
  702. return !oldVal;
  703. default:
  704. return false;
  705. }
  706. */
  707. if (x == 0)
  708. {
  709. return false;
  710. }
  711. else if (x == 1)
  712. {
  713. return true;
  714. }
  715. else if ((x & 0x81) == 0x80)
  716. {
  717. return oldVal;
  718. }
  719. else if ((x & 0x81) == 0x81)
  720. {
  721. return!oldVal;
  722. }
  723. else
  724. {
  725. return false;
  726. }
  727. }
  728. }