Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

StyleDescription.java 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /* ====================================================================
  2. * The Apache Software License, Version 1.1
  3. *
  4. * Copyright (c) 2003 The Apache Software Foundation. All rights
  5. * reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution,
  20. * if any, must include the following acknowledgment:
  21. * "This product includes software developed by the
  22. * Apache Software Foundation (http://www.apache.org/)."
  23. * Alternately, this acknowledgment may appear in the software itself,
  24. * if and wherever such third-party acknowledgments normally appear.
  25. *
  26. * 4. The names "Apache" and "Apache Software Foundation" and
  27. * "Apache POI" must not be used to endorse or promote products
  28. * derived from this software without prior written permission. For
  29. * written permission, please contact apache@apache.org.
  30. *
  31. * 5. Products derived from this software may not be called "Apache",
  32. * "Apache POI", nor may "Apache" appear in their name, without
  33. * prior written permission of the Apache Software Foundation.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46. * SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This software consists of voluntary contributions made by many
  50. * individuals on behalf of the Apache Software Foundation. For more
  51. * information on the Apache Software Foundation, please see
  52. * <http://www.apache.org/>.
  53. */
  54. package org.apache.poi.hwpf.model.hdftypes;
  55. import java.io.UnsupportedEncodingException;
  56. import org.apache.poi.util.LittleEndian;
  57. import org.apache.poi.util.BitField;
  58. /**
  59. * Comment me
  60. *
  61. * @author Ryan Ackley
  62. */
  63. public class StyleDescription implements HDFType
  64. {
  65. private static int PARAGRAPH_STYLE = 1;
  66. private static int CHARACTER_STYLE = 2;
  67. private short _infoShort;
  68. private static BitField _sti = new BitField(0xfff);
  69. private static BitField _fScratch = new BitField(0x1000);
  70. private static BitField _fInvalHeight = new BitField(0x2000);
  71. private static BitField _fHasUpe = new BitField(0x4000);
  72. private static BitField _fMassCopy = new BitField(0x8000);
  73. private short _infoShort2;
  74. private static BitField _styleTypeCode = new BitField(0xf);
  75. private static BitField _baseStyle = new BitField(0xfff0);
  76. private static BitField _numUPX = new BitField(0xf);
  77. private static BitField _nextStyle = new BitField(0xfff0);
  78. private short _bchUpe;
  79. private short _infoShort3;
  80. private static BitField _fAutoRedef = new BitField(0x1);
  81. private static BitField _fHidden = new BitField(0x2);
  82. byte[] _papx;
  83. byte[] _chpx;
  84. String _name;
  85. // ParagraphProperties _pap;
  86. // CharacterProperties _chp;
  87. public StyleDescription()
  88. {
  89. // _pap = new ParagraphProperties();
  90. // _chp = new CharacterProperties();
  91. }
  92. public StyleDescription(byte[] std, int baseLength, int offset, boolean word9)
  93. {
  94. int nameStart = offset + baseLength;
  95. _infoShort = LittleEndian.getShort(std, offset);
  96. offset += LittleEndian.SHORT_SIZE;
  97. _infoShort2 = LittleEndian.getShort(std, offset);
  98. offset += LittleEndian.SHORT_SIZE;
  99. _bchUpe = LittleEndian.getShort(std, offset);
  100. offset += LittleEndian.SHORT_SIZE;
  101. _infoShort3 = LittleEndian.getShort(std, offset);
  102. offset += LittleEndian.SHORT_SIZE;
  103. //first byte(s) of variable length section of std is the length of the
  104. //style name and aliases string
  105. int nameLength = 0;
  106. int multiplier = 1;
  107. if(word9)
  108. {
  109. nameLength = LittleEndian.getShort(std, nameStart);
  110. multiplier = 2;
  111. nameStart += LittleEndian.SHORT_SIZE;
  112. }
  113. else
  114. {
  115. nameLength = std[nameStart];
  116. }
  117. try
  118. {
  119. _name = new String(std, nameStart, nameLength * multiplier, "UTF-16LE");
  120. }
  121. catch (UnsupportedEncodingException ignore)
  122. {
  123. // ignore
  124. }
  125. //2 bytes for length, length then null terminator.
  126. int grupxStart = multiplier + ((nameLength + 1) * multiplier) + nameStart;
  127. // the spec only refers to two possible upxs but it mentions
  128. // that more may be added in the future
  129. int add = 0;
  130. int numUPX = _numUPX.getValue(_infoShort2);
  131. for(int x = 0; x < numUPX; x++)
  132. {
  133. int upxSize = LittleEndian.getShort(std, grupxStart + add);
  134. if(_styleTypeCode.getValue(_infoShort2) == PARAGRAPH_STYLE)
  135. {
  136. if(x == 0)
  137. {
  138. _papx = new byte[upxSize];
  139. System.arraycopy(std, grupxStart + add + 2, _papx, 0, upxSize);
  140. }
  141. else if(x == 1)
  142. {
  143. _chpx = new byte[upxSize];
  144. System.arraycopy(std, grupxStart + add + 2, _chpx, 0, upxSize);
  145. }
  146. }
  147. else if(_styleTypeCode.getValue(_infoShort2) == CHARACTER_STYLE && x == 0)
  148. {
  149. _chpx = new byte[upxSize];
  150. System.arraycopy(std, grupxStart + add + 2, _chpx, 0, upxSize);
  151. }
  152. // the upx will always start on a word boundary.
  153. if(upxSize % 2 == 1)
  154. {
  155. ++upxSize;
  156. }
  157. add += 2 + upxSize;
  158. }
  159. }
  160. public int getBaseStyle()
  161. {
  162. return _baseStyle.getValue(_infoShort2);
  163. }
  164. public byte[] getCHPX()
  165. {
  166. return _chpx;
  167. }
  168. public byte[] getPAPX()
  169. {
  170. return _papx;
  171. }
  172. // public ParagraphProperties getPAP()
  173. // {
  174. // return _pap;
  175. // }
  176. // public CharacterProperties getCHP()
  177. // {
  178. // return _chp;
  179. // }
  180. // public void setPAP(ParagraphProperties pap)
  181. // {
  182. // _pap = pap;
  183. // }
  184. // public void setCHP(CharacterProperties chp)
  185. // {
  186. // _chp = chp;
  187. // }
  188. }