You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CharacterRun.java 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. /* ====================================================================
  2. Copyright 2002-2004 Apache Software Foundation
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ==================================================================== */
  13. package org.apache.poi.hwpf.usermodel;
  14. import org.apache.poi.hwpf.model.CHPX;
  15. import org.apache.poi.hwpf.model.StyleSheet;
  16. import org.apache.poi.hwpf.sprm.SprmBuffer;
  17. /**
  18. * This class represents a run of text that share common properties.
  19. *
  20. * @author Ryan Ackley
  21. */
  22. public class CharacterRun
  23. extends Range
  24. implements Cloneable
  25. {
  26. public final static short SPRM_FRMARKDEL = (short)0x0800;
  27. public final static short SPRM_FRMARK = 0x0801;
  28. public final static short SPRM_FFLDVANISH = 0x0802;
  29. public final static short SPRM_PICLOCATION = 0x6A03;
  30. public final static short SPRM_IBSTRMARK = 0x4804;
  31. public final static short SPRM_DTTMRMARK = 0x6805;
  32. public final static short SPRM_FDATA = 0x0806;
  33. public final static short SPRM_SYMBOL = 0x6A09;
  34. public final static short SPRM_FOLE2 = 0x080A;
  35. public final static short SPRM_HIGHLIGHT = 0x2A0C;
  36. public final static short SPRM_OBJLOCATION = 0x680E;
  37. public final static short SPRM_ISTD = 0x4A30;
  38. public final static short SPRM_FBOLD = 0x0835;
  39. public final static short SPRM_FITALIC = 0x0836;
  40. public final static short SPRM_FSTRIKE = 0x0837;
  41. public final static short SPRM_FOUTLINE = 0x0838;
  42. public final static short SPRM_FSHADOW = 0x0839;
  43. public final static short SPRM_FSMALLCAPS = 0x083A;
  44. public final static short SPRM_FCAPS = 0x083B;
  45. public final static short SPRM_FVANISH = 0x083C;
  46. public final static short SPRM_KUL = 0x2A3E;
  47. public final static short SPRM_DXASPACE = (short)0x8840;
  48. public final static short SPRM_LID = 0x4A41;
  49. public final static short SPRM_ICO = 0x2A42;
  50. public final static short SPRM_HPS = 0x4A43;
  51. public final static short SPRM_HPSPOS = 0x4845;
  52. public final static short SPRM_ISS = 0x2A48;
  53. public final static short SPRM_HPSKERN = 0x484B;
  54. public final static short SPRM_YSRI = 0x484E;
  55. public final static short SPRM_RGFTCASCII = 0x4A4F;
  56. public final static short SPRM_RGFTCFAREAST = 0x4A50;
  57. public final static short SPRM_RGFTCNOTFAREAST = 0x4A51;
  58. public final static short SPRM_CHARSCALE = 0x4852;
  59. public final static short SPRM_FDSTRIKE = 0x2A53;
  60. public final static short SPRM_FIMPRINT = 0x0854;
  61. public final static short SPRM_FSPEC = 0x0855;
  62. public final static short SPRM_FOBJ = 0x0856;
  63. public final static short SPRM_PROPRMARK = (short)0xCA57;
  64. public final static short SPRM_FEMBOSS = 0x0858;
  65. public final static short SPRM_SFXTEXT = 0x2859;
  66. public final static short SPRM_DISPFLDRMARK = (short)0xCA62;
  67. public final static short SPRM_IBSTRMARKDEL = 0x4863;
  68. public final static short SPRM_DTTMRMARKDEL = 0x6864;
  69. public final static short SPRM_BRC = 0x6865;
  70. public final static short SPRM_SHD = 0x4866;
  71. public final static short SPRM_IDSIRMARKDEL = 0x4867;
  72. public final static short SPRM_CPG = 0x486B;
  73. public final static short SPRM_NONFELID = 0x486D;
  74. public final static short SPRM_FELID = 0x486E;
  75. public final static short SPRM_IDCTHINT = 0x286F;
  76. SprmBuffer _chpx;
  77. CharacterProperties _props;
  78. /**
  79. *
  80. * @param chpx The chpx this object is based on.
  81. * @param ss The stylesheet for the document this run belongs to.
  82. * @param istd The style index if this run's base style.
  83. * @param parent The parent range of this character run (usually a paragraph).
  84. */
  85. CharacterRun(CHPX chpx, StyleSheet ss, short istd, Range parent)
  86. {
  87. super(Math.max(parent._start, chpx.getStart()), Math.min(parent._end, chpx.getEnd()), parent);
  88. _props = chpx.getCharacterProperties(ss, istd);
  89. _chpx = chpx.getSprmBuf();
  90. }
  91. /**
  92. * Here for runtime type determination using a switch statement convenient.
  93. *
  94. * @return TYPE_CHARACTER
  95. */
  96. public int type()
  97. {
  98. return TYPE_CHARACTER;
  99. }
  100. public boolean isMarkedDeleted()
  101. {
  102. return _props.isFRMarkDel();
  103. }
  104. public void markDeleted(boolean mark)
  105. {
  106. _props.setFRMarkDel(mark);
  107. byte newVal = (byte)(mark ? 1 : 0);
  108. _chpx.updateSprm(SPRM_FRMARKDEL, newVal);
  109. }
  110. public boolean isBold()
  111. {
  112. return _props.isFBold();
  113. }
  114. public void setBold(boolean bold)
  115. {
  116. _props.setFBold(bold);
  117. byte newVal = (byte)(bold ? 1 : 0);
  118. _chpx.updateSprm(SPRM_FBOLD, newVal);
  119. }
  120. public boolean isItalic()
  121. {
  122. return _props.isFItalic();
  123. }
  124. public void setItalic(boolean italic)
  125. {
  126. _props.setFItalic(italic);
  127. byte newVal = (byte)(italic ? 1 : 0);
  128. _chpx.updateSprm(SPRM_FITALIC, newVal);
  129. }
  130. public boolean isOutlined()
  131. {
  132. return _props.isFOutline();
  133. }
  134. public void setOutline(boolean outlined)
  135. {
  136. _props.setFOutline(outlined);
  137. byte newVal = (byte)(outlined ? 1 : 0);
  138. _chpx.updateSprm(SPRM_FOUTLINE, newVal);
  139. }
  140. public boolean isFldVanished()
  141. {
  142. return _props.isFFldVanish();
  143. }
  144. public void setFldVanish(boolean fldVanish)
  145. {
  146. _props.setFFldVanish(fldVanish);
  147. byte newVal = (byte)(fldVanish ? 1 : 0);
  148. _chpx.updateSprm(SPRM_FFLDVANISH, newVal);
  149. }
  150. public boolean isSmallCaps()
  151. {
  152. return _props.isFSmallCaps();
  153. }
  154. public void setSmallCaps(boolean smallCaps)
  155. {
  156. _props.setFSmallCaps(smallCaps);
  157. byte newVal = (byte)(smallCaps ? 1 : 0);
  158. _chpx.updateSprm(SPRM_FSMALLCAPS, newVal);
  159. }
  160. public boolean isCapitalized()
  161. {
  162. return _props.isFCaps();
  163. }
  164. public void setCapitalized(boolean caps)
  165. {
  166. _props.setFCaps(caps);
  167. byte newVal = (byte)(caps ? 1 : 0);
  168. _chpx.updateSprm(SPRM_FCAPS, newVal);
  169. }
  170. public boolean isVanished()
  171. {
  172. return _props.isFVanish();
  173. }
  174. public void setVanished(boolean vanish)
  175. {
  176. _props.setFVanish(vanish);
  177. byte newVal = (byte)(vanish ? 1 : 0);
  178. _chpx.updateSprm(SPRM_FVANISH, newVal);
  179. }
  180. public boolean isMarkedInserted()
  181. {
  182. return _props.isFRMark();
  183. }
  184. public void markInserted(boolean mark)
  185. {
  186. _props.setFRMark(mark);
  187. byte newVal = (byte)(mark ? 1 : 0);
  188. _chpx.updateSprm(SPRM_FRMARK, newVal);
  189. }
  190. public boolean isStrikeThrough()
  191. {
  192. return _props.isFStrike();
  193. }
  194. public void strikeThrough(boolean strike)
  195. {
  196. _props.setFStrike(strike);
  197. byte newVal = (byte)(strike ? 1 : 0);
  198. _chpx.updateSprm(SPRM_FSTRIKE, newVal);
  199. }
  200. public boolean isShadowed()
  201. {
  202. return _props.isFShadow();
  203. }
  204. public void setShadow(boolean shadow)
  205. {
  206. _props.setFShadow(shadow);
  207. byte newVal = (byte)(shadow ? 1 : 0);
  208. _chpx.updateSprm(SPRM_FSHADOW, newVal);
  209. }
  210. public boolean isEmbossed()
  211. {
  212. return _props.isFEmboss();
  213. }
  214. public void setEmbossed(boolean emboss)
  215. {
  216. _props.setFEmboss(emboss);
  217. byte newVal = (byte)(emboss ? 1 : 0);
  218. _chpx.updateSprm(SPRM_FEMBOSS, newVal);
  219. }
  220. public boolean isImprinted()
  221. {
  222. return _props.isFImprint();
  223. }
  224. public void setImprinted(boolean imprint)
  225. {
  226. _props.setFImprint(imprint);
  227. byte newVal = (byte)(imprint ? 1 : 0);
  228. _chpx.updateSprm(SPRM_FIMPRINT, newVal);
  229. }
  230. public boolean isDoubleStrikeThrough()
  231. {
  232. return _props.isFDStrike();
  233. }
  234. public void setDoubleStrikethrough(boolean dstrike)
  235. {
  236. _props.setFDStrike(dstrike);
  237. byte newVal = (byte)(dstrike ? 1 : 0);
  238. _chpx.updateSprm(SPRM_FDSTRIKE, newVal);
  239. }
  240. public void setFtcAscii(int ftcAscii)
  241. {
  242. _props.setFtcAscii(ftcAscii);
  243. _chpx.updateSprm(SPRM_RGFTCASCII, (short)ftcAscii);
  244. }
  245. public void setFtcFE(int ftcFE)
  246. {
  247. _props.setFtcFE(ftcFE);
  248. _chpx.updateSprm(SPRM_RGFTCFAREAST, (short)ftcFE);
  249. }
  250. public void setFtcOther(int ftcOther)
  251. {
  252. _props.setFtcOther(ftcOther);
  253. _chpx.updateSprm(SPRM_RGFTCNOTFAREAST, (short)ftcOther);
  254. }
  255. public int getFontSize()
  256. {
  257. return _props.getHps();
  258. }
  259. public void setFontSize(int halfPoints)
  260. {
  261. _props.setHps(halfPoints);
  262. _chpx.updateSprm(SPRM_HPS, (short)halfPoints);
  263. }
  264. public int getCharacterSpacing()
  265. {
  266. return _props.getDxaSpace();
  267. }
  268. public void setCharacterSpacing(int twips)
  269. {
  270. _props.setDxaSpace(twips);
  271. _chpx.updateSprm(SPRM_DXASPACE, twips);
  272. }
  273. public short getSubSuperScriptIndex()
  274. {
  275. return _props.getIss();
  276. }
  277. public void setSubSuperScriptIndex(short iss)
  278. {
  279. _props.setDxaSpace(iss);
  280. _chpx.updateSprm(SPRM_DXASPACE, iss);
  281. }
  282. public int getUnderlineCode()
  283. {
  284. return _props.getKul();
  285. }
  286. public void setUnderlineCode(int kul)
  287. {
  288. _props.setKul((byte)kul);
  289. _chpx.updateSprm(SPRM_KUL, (byte)kul);
  290. }
  291. public int getColor()
  292. {
  293. return _props.getIco();
  294. }
  295. public void setColor(int color)
  296. {
  297. _props.setIco((byte)color);
  298. _chpx.updateSprm(SPRM_ICO, (byte)color);
  299. }
  300. public int getVerticalOffset()
  301. {
  302. return _props.getHpsPos();
  303. }
  304. public void setVerticalOffset(int hpsPos)
  305. {
  306. _props.setHpsPos(hpsPos);
  307. _chpx.updateSprm(SPRM_HPSPOS, (byte)hpsPos);
  308. }
  309. public int getKerning()
  310. {
  311. return _props.getHpsKern();
  312. }
  313. public void setKerning(int kern)
  314. {
  315. _props.setHpsKern(kern);
  316. _chpx.updateSprm(SPRM_HPSKERN, (short)kern);
  317. }
  318. public boolean isHighlighted()
  319. {
  320. return _props.isFHighlight();
  321. }
  322. public void setHighlighted(byte color)
  323. {
  324. _props.setFHighlight(true);
  325. _props.setIcoHighlight(color);
  326. _chpx.updateSprm(SPRM_HIGHLIGHT, color);
  327. }
  328. public String getFontName()
  329. {
  330. return _doc.getFontTable().getMainFont(_props.getFtcAscii());
  331. }
  332. public boolean isSpecialCharacter()
  333. {
  334. return _props.isFSpec();
  335. }
  336. public void setSpecialCharacter(boolean spec)
  337. {
  338. _props.setFSpec(spec);
  339. byte newVal = (byte)(spec ? 1 : 0);
  340. _chpx.updateSprm(SPRM_FSPEC, newVal);
  341. }
  342. public boolean isObj()
  343. {
  344. return _props.isFObj();
  345. }
  346. public void setObj(boolean obj)
  347. {
  348. _props.setFObj(obj);
  349. byte newVal = (byte)(obj ? 1 : 0);
  350. _chpx.updateSprm(SPRM_FOBJ, newVal);
  351. }
  352. public int getPicOffset()
  353. {
  354. return _props.getFcPic();
  355. }
  356. public void setPicOffset(int offset)
  357. {
  358. _props.setFcPic(offset);
  359. _chpx.updateSprm(SPRM_PICLOCATION, offset);
  360. }
  361. public boolean isData()
  362. {
  363. return _props.isFData();
  364. }
  365. public void setData(boolean data)
  366. {
  367. _props.setFData(data);
  368. byte newVal = (byte)(data ? 1 : 0);
  369. _chpx.updateSprm(SPRM_FOBJ, newVal);
  370. }
  371. public boolean isOle2()
  372. {
  373. return _props.isFOle2();
  374. }
  375. public void setOle2(boolean ole)
  376. {
  377. _props.setFOle2(ole);
  378. byte newVal = (byte)(ole ? 1 : 0);
  379. _chpx.updateSprm(SPRM_FOBJ, newVal);
  380. }
  381. public int getObjOffset()
  382. {
  383. return _props.getFcObj();
  384. }
  385. public void setObjOffset(int obj)
  386. {
  387. _props.setFcObj(obj);
  388. _chpx.updateSprm(SPRM_OBJLOCATION, obj);
  389. }
  390. /**
  391. * Get the ico24 field for the CHP record.
  392. */
  393. public int getIco24()
  394. {
  395. return _props.getIco24();
  396. }
  397. /**
  398. * Set the ico24 field for the CHP record.
  399. */
  400. public void setIco24(int colour24)
  401. {
  402. _props.setIco24(colour24);
  403. }
  404. /**
  405. * Used to create a deep copy of this object.
  406. *
  407. * @return A deep copy.
  408. * @throws CloneNotSupportedException never
  409. */
  410. public Object clone()
  411. throws CloneNotSupportedException
  412. {
  413. CharacterRun cp = (CharacterRun)super.clone();
  414. cp._props.setDttmRMark((DateAndTime)_props.getDttmRMark().clone());
  415. cp._props.setDttmRMarkDel((DateAndTime)_props.getDttmRMarkDel().clone());
  416. cp._props.setDttmPropRMark((DateAndTime)_props.getDttmPropRMark().clone());
  417. cp._props.setDttmDispFldRMark((DateAndTime)_props.getDttmDispFldRMark().
  418. clone());
  419. cp._props.setXstDispFldRMark((byte[])_props.getXstDispFldRMark().clone());
  420. cp._props.setShd((ShadingDescriptor)_props.getShd().clone());
  421. return cp;
  422. }
  423. }