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.

HSLFSimpleShape.java 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  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.hslf.usermodel;
  16. import java.awt.Color;
  17. import org.apache.poi.ddf.AbstractEscherOptRecord;
  18. import org.apache.poi.ddf.EscherChildAnchorRecord;
  19. import org.apache.poi.ddf.EscherClientAnchorRecord;
  20. import org.apache.poi.ddf.EscherContainerRecord;
  21. import org.apache.poi.ddf.EscherOptRecord;
  22. import org.apache.poi.ddf.EscherProperty;
  23. import org.apache.poi.ddf.EscherPropertyTypes;
  24. import org.apache.poi.ddf.EscherRecord;
  25. import org.apache.poi.ddf.EscherSimpleProperty;
  26. import org.apache.poi.ddf.EscherSpRecord;
  27. import org.apache.poi.hslf.exceptions.HSLFException;
  28. import org.apache.poi.sl.draw.DrawPaint;
  29. import org.apache.poi.sl.draw.geom.CustomGeometry;
  30. import org.apache.poi.sl.draw.geom.Guide;
  31. import org.apache.poi.sl.draw.geom.PresetGeometries;
  32. import org.apache.poi.sl.usermodel.LineDecoration;
  33. import org.apache.poi.sl.usermodel.LineDecoration.DecorationShape;
  34. import org.apache.poi.sl.usermodel.LineDecoration.DecorationSize;
  35. import org.apache.poi.sl.usermodel.PaintStyle;
  36. import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
  37. import org.apache.poi.sl.usermodel.Placeholder;
  38. import org.apache.poi.sl.usermodel.Shadow;
  39. import org.apache.poi.sl.usermodel.ShapeContainer;
  40. import org.apache.poi.sl.usermodel.ShapeType;
  41. import org.apache.poi.sl.usermodel.SimpleShape;
  42. import org.apache.poi.sl.usermodel.StrokeStyle;
  43. import org.apache.poi.sl.usermodel.StrokeStyle.LineCap;
  44. import org.apache.poi.sl.usermodel.StrokeStyle.LineCompound;
  45. import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;
  46. import org.apache.poi.util.LittleEndian;
  47. import org.apache.poi.util.POILogFactory;
  48. import org.apache.poi.util.POILogger;
  49. import org.apache.poi.util.Units;
  50. /**
  51. * An abstract simple (non-group) shape.
  52. * This is the parent class for all primitive shapes like Line, Rectangle, etc.
  53. */
  54. public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape<HSLFShape,HSLFTextParagraph> {
  55. private static final POILogger LOG = POILogFactory.getLogger(HSLFSimpleShape.class);
  56. public final static double DEFAULT_LINE_WIDTH = 0.75;
  57. protected static final EscherPropertyTypes[] ADJUST_VALUES = {
  58. EscherPropertyTypes.GEOMETRY__ADJUSTVALUE,
  59. EscherPropertyTypes.GEOMETRY__ADJUST2VALUE,
  60. EscherPropertyTypes.GEOMETRY__ADJUST3VALUE,
  61. EscherPropertyTypes.GEOMETRY__ADJUST4VALUE,
  62. EscherPropertyTypes.GEOMETRY__ADJUST5VALUE,
  63. EscherPropertyTypes.GEOMETRY__ADJUST6VALUE,
  64. EscherPropertyTypes.GEOMETRY__ADJUST7VALUE,
  65. EscherPropertyTypes.GEOMETRY__ADJUST8VALUE,
  66. EscherPropertyTypes.GEOMETRY__ADJUST9VALUE,
  67. EscherPropertyTypes.GEOMETRY__ADJUST10VALUE
  68. };
  69. /**
  70. * Hyperlink
  71. */
  72. protected HSLFHyperlink _hyperlink;
  73. /**
  74. * Create a SimpleShape object and initialize it from the supplied Record container.
  75. *
  76. * @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
  77. * @param parent the parent of the shape
  78. */
  79. protected HSLFSimpleShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
  80. super(escherRecord, parent);
  81. }
  82. /**
  83. * Create a new Shape
  84. *
  85. * @param isChild <code>true</code> if the Line is inside a group, <code>false</code> otherwise
  86. * @return the record container which holds this shape
  87. */
  88. @Override
  89. protected EscherContainerRecord createSpContainer(boolean isChild) {
  90. EscherContainerRecord ecr = super.createSpContainer(isChild);
  91. ecr.setRecordId( EscherContainerRecord.SP_CONTAINER );
  92. EscherSpRecord sp = new EscherSpRecord();
  93. int flags = EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE;
  94. if (isChild) {
  95. flags |= EscherSpRecord.FLAG_CHILD;
  96. }
  97. sp.setFlags(flags);
  98. ecr.addChildRecord(sp);
  99. AbstractEscherOptRecord opt = new EscherOptRecord();
  100. opt.setRecordId(EscherOptRecord.RECORD_ID);
  101. ecr.addChildRecord(opt);
  102. EscherRecord anchor;
  103. if(isChild) {
  104. anchor = new EscherChildAnchorRecord();
  105. } else {
  106. anchor = new EscherClientAnchorRecord();
  107. //hack. internal variable EscherClientAnchorRecord.shortRecord can be
  108. //initialized only in fillFields(). We need to set shortRecord=false;
  109. byte[] header = new byte[16];
  110. LittleEndian.putUShort(header, 0, 0);
  111. LittleEndian.putUShort(header, 2, 0);
  112. LittleEndian.putInt(header, 4, 8);
  113. anchor.fillFields(header, 0, null);
  114. }
  115. ecr.addChildRecord(anchor);
  116. return ecr;
  117. }
  118. /**
  119. * Returns width of the line in in points
  120. */
  121. public double getLineWidth(){
  122. AbstractEscherOptRecord opt = getEscherOptRecord();
  123. EscherSimpleProperty prop = getEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINEWIDTH);
  124. return (prop == null) ? DEFAULT_LINE_WIDTH : Units.toPoints(prop.getPropertyValue());
  125. }
  126. /**
  127. * Sets the width of line in in points
  128. * @param width the width of line in in points
  129. */
  130. public void setLineWidth(double width){
  131. AbstractEscherOptRecord opt = getEscherOptRecord();
  132. setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINEWIDTH, Units.toEMU(width));
  133. }
  134. /**
  135. * Sets the color of line
  136. *
  137. * @param color new color of the line
  138. */
  139. public void setLineColor(Color color){
  140. AbstractEscherOptRecord opt = getEscherOptRecord();
  141. if (color == null) {
  142. setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__NOLINEDRAWDASH, 0x80000);
  143. } else {
  144. int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
  145. setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__COLOR, rgb);
  146. setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__NOLINEDRAWDASH, 0x180018);
  147. }
  148. }
  149. /**
  150. * @return color of the line. If color is not set returns {@code null}
  151. */
  152. public Color getLineColor(){
  153. AbstractEscherOptRecord opt = getEscherOptRecord();
  154. EscherSimpleProperty p = getEscherProperty(opt, EscherPropertyTypes.LINESTYLE__NOLINEDRAWDASH);
  155. if(p != null && (p.getPropertyValue() & 0x8) == 0) {
  156. return null;
  157. }
  158. return getColor(EscherPropertyTypes.LINESTYLE__COLOR, EscherPropertyTypes.LINESTYLE__OPACITY);
  159. }
  160. /**
  161. * @return background color of the line. If color is not set returns {@code null}
  162. */
  163. public Color getLineBackgroundColor(){
  164. AbstractEscherOptRecord opt = getEscherOptRecord();
  165. EscherSimpleProperty p = getEscherProperty(opt, EscherPropertyTypes.LINESTYLE__NOLINEDRAWDASH);
  166. if(p != null && (p.getPropertyValue() & 0x8) == 0) {
  167. return null;
  168. }
  169. return getColor(EscherPropertyTypes.LINESTYLE__BACKCOLOR, EscherPropertyTypes.LINESTYLE__OPACITY);
  170. }
  171. /**
  172. * Sets the background color of line
  173. *
  174. * @param color new background color of the line
  175. */
  176. public void setLineBackgroundColor(Color color){
  177. AbstractEscherOptRecord opt = getEscherOptRecord();
  178. if (color == null) {
  179. setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__NOLINEDRAWDASH, 0x80000);
  180. opt.removeEscherProperty(EscherPropertyTypes.LINESTYLE__BACKCOLOR);
  181. } else {
  182. int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
  183. setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__BACKCOLOR, rgb);
  184. setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__NOLINEDRAWDASH, 0x180018);
  185. }
  186. }
  187. /**
  188. * Gets line cap.
  189. *
  190. * @return cap of the line.
  191. */
  192. public LineCap getLineCap(){
  193. AbstractEscherOptRecord opt = getEscherOptRecord();
  194. EscherSimpleProperty prop = getEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINEENDCAPSTYLE);
  195. return (prop == null) ? LineCap.FLAT : LineCap.fromNativeId(prop.getPropertyValue());
  196. }
  197. /**
  198. * Sets line cap.
  199. *
  200. * @param pen new style of the line.
  201. */
  202. public void setLineCap(LineCap pen){
  203. AbstractEscherOptRecord opt = getEscherOptRecord();
  204. setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINEENDCAPSTYLE, pen == LineCap.FLAT ? -1 : pen.nativeId);
  205. }
  206. /**
  207. * Gets line dashing.
  208. *
  209. * @return dashing of the line.
  210. */
  211. public LineDash getLineDash(){
  212. AbstractEscherOptRecord opt = getEscherOptRecord();
  213. EscherSimpleProperty prop = getEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINEDASHING);
  214. return (prop == null) ? LineDash.SOLID : LineDash.fromNativeId(prop.getPropertyValue());
  215. }
  216. /**
  217. * Sets line dashing.
  218. *
  219. * @param pen new style of the line.
  220. */
  221. public void setLineDash(LineDash pen){
  222. AbstractEscherOptRecord opt = getEscherOptRecord();
  223. setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINEDASHING, pen == LineDash.SOLID ? -1 : pen.nativeId);
  224. }
  225. /**
  226. * Gets the line compound style
  227. *
  228. * @return the compound style of the line.
  229. */
  230. public LineCompound getLineCompound() {
  231. AbstractEscherOptRecord opt = getEscherOptRecord();
  232. EscherSimpleProperty prop = getEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINESTYLE);
  233. return (prop == null) ? LineCompound.SINGLE : LineCompound.fromNativeId(prop.getPropertyValue());
  234. }
  235. /**
  236. * Sets the line compound style
  237. *
  238. * @param style new compound style of the line.
  239. */
  240. public void setLineCompound(LineCompound style){
  241. AbstractEscherOptRecord opt = getEscherOptRecord();
  242. setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINESTYLE, style == LineCompound.SINGLE ? -1 : style.nativeId);
  243. }
  244. /**
  245. * Returns line style. One of the constants defined in this class.
  246. *
  247. * @return style of the line.
  248. */
  249. @Override
  250. public StrokeStyle getStrokeStyle(){
  251. return new StrokeStyle() {
  252. @Override
  253. public PaintStyle getPaint() {
  254. return DrawPaint.createSolidPaint(HSLFSimpleShape.this.getLineColor());
  255. }
  256. @Override
  257. public LineCap getLineCap() {
  258. return null;
  259. }
  260. @Override
  261. public LineDash getLineDash() {
  262. return HSLFSimpleShape.this.getLineDash();
  263. }
  264. @Override
  265. public LineCompound getLineCompound() {
  266. return HSLFSimpleShape.this.getLineCompound();
  267. }
  268. @Override
  269. public double getLineWidth() {
  270. return HSLFSimpleShape.this.getLineWidth();
  271. }
  272. };
  273. }
  274. @Override
  275. public Color getFillColor() {
  276. return getFill().getForegroundColor();
  277. }
  278. @Override
  279. public void setFillColor(Color color) {
  280. getFill().setForegroundColor(color);
  281. }
  282. @Override
  283. public Guide getAdjustValue(String name) {
  284. if (name == null || !name.matches("adj([1-9]|10)?")) {
  285. LOG.log(POILogger.INFO, "Adjust value '"+name+"' not supported. Using default value.");
  286. return null;
  287. }
  288. name = name.replace("adj", "");
  289. if (name.isEmpty()) {
  290. name = "1";
  291. }
  292. final int adjInt = Integer.parseInt(name);
  293. if (adjInt < 1 || adjInt > 10) {
  294. throw new HSLFException("invalid adjust value: "+adjInt);
  295. }
  296. EscherPropertyTypes escherProp = ADJUST_VALUES[adjInt-1];
  297. int adjval = getEscherProperty(escherProp, -1);
  298. if (adjval == -1) {
  299. return null;
  300. }
  301. // Bug 59004
  302. // the adjust value are format dependent, we scale them up so they match the OOXML ones.
  303. // see https://social.msdn.microsoft.com/Forums/en-US/33e458e6-58df-48fe-9a10-e303ab08991d/preset-shapes-for-ppt?forum=os_binaryfile
  304. // usually we deal with length units and only very few degree units:
  305. boolean isDegreeUnit = false;
  306. switch (getShapeType()) {
  307. case ARC:
  308. case BLOCK_ARC:
  309. case CHORD:
  310. case PIE:
  311. isDegreeUnit = (adjInt == 1 || adjInt == 2);
  312. break;
  313. case CIRCULAR_ARROW:
  314. case LEFT_CIRCULAR_ARROW:
  315. case LEFT_RIGHT_CIRCULAR_ARROW:
  316. isDegreeUnit = (adjInt == 2 || adjInt == 3 || adjInt == 4);
  317. break;
  318. case MATH_NOT_EQUAL:
  319. isDegreeUnit = (adjInt == 2);
  320. break;
  321. }
  322. return new Guide(name, "val "+Math.rint(adjval * (isDegreeUnit ? 65536. : 100000./21000.)));
  323. }
  324. @Override
  325. public CustomGeometry getGeometry() {
  326. PresetGeometries dict = PresetGeometries.getInstance();
  327. ShapeType st = getShapeType();
  328. String name = (st != null) ? st.getOoxmlName() : null;
  329. CustomGeometry geom = dict.get(name);
  330. if (geom == null) {
  331. if (name == null) {
  332. name = (st != null) ? st.toString() : "<unknown>";
  333. }
  334. LOG.log(POILogger.WARN, "No preset shape definition for shapeType: "+name);
  335. }
  336. return geom;
  337. }
  338. public double getShadowAngle() {
  339. AbstractEscherOptRecord opt = getEscherOptRecord();
  340. EscherSimpleProperty prop = getEscherProperty(opt, EscherPropertyTypes.SHADOWSTYLE__OFFSETX);
  341. int offX = (prop == null) ? 0 : prop.getPropertyValue();
  342. prop = getEscherProperty(opt, EscherPropertyTypes.SHADOWSTYLE__OFFSETY);
  343. int offY = (prop == null) ? 0 : prop.getPropertyValue();
  344. return Math.toDegrees(Math.atan2(offY, offX));
  345. }
  346. public double getShadowDistance() {
  347. AbstractEscherOptRecord opt = getEscherOptRecord();
  348. EscherSimpleProperty prop = getEscherProperty(opt, EscherPropertyTypes.SHADOWSTYLE__OFFSETX);
  349. int offX = (prop == null) ? 0 : prop.getPropertyValue();
  350. prop = getEscherProperty(opt, EscherPropertyTypes.SHADOWSTYLE__OFFSETY);
  351. int offY = (prop == null) ? 0 : prop.getPropertyValue();
  352. return Units.toPoints((long)Math.hypot(offX, offY));
  353. }
  354. /**
  355. * @return color of the line. If color is not set returns <code>java.awt.Color.black</code>
  356. */
  357. public Color getShadowColor(){
  358. Color clr = getColor(EscherPropertyTypes.SHADOWSTYLE__COLOR, EscherPropertyTypes.SHADOWSTYLE__OPACITY);
  359. return clr == null ? Color.black : clr;
  360. }
  361. @Override
  362. public Shadow<HSLFShape,HSLFTextParagraph> getShadow() {
  363. AbstractEscherOptRecord opt = getEscherOptRecord();
  364. if (opt == null) {
  365. return null;
  366. }
  367. EscherProperty shadowType = opt.lookup(EscherPropertyTypes.SHADOWSTYLE__TYPE);
  368. if (shadowType == null) {
  369. return null;
  370. }
  371. return new Shadow<HSLFShape,HSLFTextParagraph>(){
  372. @Override
  373. public SimpleShape<HSLFShape,HSLFTextParagraph> getShadowParent() {
  374. return HSLFSimpleShape.this;
  375. }
  376. @Override
  377. public double getDistance() {
  378. return getShadowDistance();
  379. }
  380. @Override
  381. public double getAngle() {
  382. return getShadowAngle();
  383. }
  384. @Override
  385. public double getBlur() {
  386. // TODO Auto-generated method stub
  387. return 0;
  388. }
  389. @Override
  390. public SolidPaint getFillStyle() {
  391. return DrawPaint.createSolidPaint(getShadowColor());
  392. }
  393. };
  394. }
  395. public DecorationShape getLineHeadDecoration(){
  396. AbstractEscherOptRecord opt = getEscherOptRecord();
  397. EscherSimpleProperty prop = getEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINESTARTARROWHEAD);
  398. return (prop == null) ? null : DecorationShape.fromNativeId(prop.getPropertyValue());
  399. }
  400. public void setLineHeadDecoration(DecorationShape decoShape){
  401. AbstractEscherOptRecord opt = getEscherOptRecord();
  402. setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINESTARTARROWHEAD, decoShape == null ? -1 : decoShape.nativeId);
  403. }
  404. public DecorationSize getLineHeadWidth(){
  405. AbstractEscherOptRecord opt = getEscherOptRecord();
  406. EscherSimpleProperty prop = getEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINESTARTARROWWIDTH);
  407. return (prop == null) ? null : DecorationSize.fromNativeId(prop.getPropertyValue());
  408. }
  409. public void setLineHeadWidth(DecorationSize decoSize){
  410. AbstractEscherOptRecord opt = getEscherOptRecord();
  411. setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINESTARTARROWWIDTH, decoSize == null ? -1 : decoSize.nativeId);
  412. }
  413. public DecorationSize getLineHeadLength(){
  414. AbstractEscherOptRecord opt = getEscherOptRecord();
  415. EscherSimpleProperty prop = getEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINESTARTARROWLENGTH);
  416. return (prop == null) ? null : DecorationSize.fromNativeId(prop.getPropertyValue());
  417. }
  418. public void setLineHeadLength(DecorationSize decoSize){
  419. AbstractEscherOptRecord opt = getEscherOptRecord();
  420. setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINESTARTARROWLENGTH, decoSize == null ? -1 : decoSize.nativeId);
  421. }
  422. public DecorationShape getLineTailDecoration(){
  423. AbstractEscherOptRecord opt = getEscherOptRecord();
  424. EscherSimpleProperty prop = getEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINEENDARROWHEAD);
  425. return (prop == null) ? null : DecorationShape.fromNativeId(prop.getPropertyValue());
  426. }
  427. public void setLineTailDecoration(DecorationShape decoShape){
  428. AbstractEscherOptRecord opt = getEscherOptRecord();
  429. setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINEENDARROWHEAD, decoShape == null ? -1 : decoShape.nativeId);
  430. }
  431. public DecorationSize getLineTailWidth(){
  432. AbstractEscherOptRecord opt = getEscherOptRecord();
  433. EscherSimpleProperty prop = getEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINEENDARROWWIDTH);
  434. return (prop == null) ? null : DecorationSize.fromNativeId(prop.getPropertyValue());
  435. }
  436. public void setLineTailWidth(DecorationSize decoSize){
  437. AbstractEscherOptRecord opt = getEscherOptRecord();
  438. setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINEENDARROWWIDTH, decoSize == null ? -1 : decoSize.nativeId);
  439. }
  440. public DecorationSize getLineTailLength(){
  441. AbstractEscherOptRecord opt = getEscherOptRecord();
  442. EscherSimpleProperty prop = getEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINEENDARROWLENGTH);
  443. return (prop == null) ? null : DecorationSize.fromNativeId(prop.getPropertyValue());
  444. }
  445. public void setLineTailLength(DecorationSize decoSize){
  446. AbstractEscherOptRecord opt = getEscherOptRecord();
  447. setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINEENDARROWLENGTH, decoSize == null ? -1 : decoSize.nativeId);
  448. }
  449. @Override
  450. public LineDecoration getLineDecoration() {
  451. return new LineDecoration() {
  452. @Override
  453. public DecorationShape getHeadShape() {
  454. return HSLFSimpleShape.this.getLineHeadDecoration();
  455. }
  456. @Override
  457. public DecorationSize getHeadWidth() {
  458. return HSLFSimpleShape.this.getLineHeadWidth();
  459. }
  460. @Override
  461. public DecorationSize getHeadLength() {
  462. return HSLFSimpleShape.this.getLineHeadLength();
  463. }
  464. @Override
  465. public DecorationShape getTailShape() {
  466. return HSLFSimpleShape.this.getLineTailDecoration();
  467. }
  468. @Override
  469. public DecorationSize getTailWidth() {
  470. return HSLFSimpleShape.this.getLineTailWidth();
  471. }
  472. @Override
  473. public DecorationSize getTailLength() {
  474. return HSLFSimpleShape.this.getLineTailLength();
  475. }
  476. };
  477. }
  478. @Override
  479. public HSLFShapePlaceholderDetails getPlaceholderDetails() {
  480. return new HSLFShapePlaceholderDetails(this);
  481. }
  482. @Override
  483. public Placeholder getPlaceholder() {
  484. return getPlaceholderDetails().getPlaceholder();
  485. }
  486. @Override
  487. public void setPlaceholder(Placeholder placeholder) {
  488. getPlaceholderDetails().setPlaceholder(placeholder);
  489. }
  490. @Override
  491. public void setStrokeStyle(Object... styles) {
  492. if (styles.length == 0) {
  493. // remove stroke
  494. setLineColor(null);
  495. return;
  496. }
  497. // TODO: handle PaintStyle
  498. for (Object st : styles) {
  499. if (st instanceof Number) {
  500. setLineWidth(((Number)st).doubleValue());
  501. } else if (st instanceof LineCap) {
  502. setLineCap((LineCap)st);
  503. } else if (st instanceof LineDash) {
  504. setLineDash((LineDash)st);
  505. } else if (st instanceof LineCompound) {
  506. setLineCompound((LineCompound)st);
  507. } else if (st instanceof Color) {
  508. setLineColor((Color)st);
  509. }
  510. }
  511. }
  512. @Override
  513. public HSLFHyperlink getHyperlink(){
  514. return _hyperlink;
  515. }
  516. @Override
  517. public HSLFHyperlink createHyperlink() {
  518. if (_hyperlink == null) {
  519. _hyperlink = HSLFHyperlink.createHyperlink(this);
  520. }
  521. return _hyperlink;
  522. }
  523. /**
  524. * Sets the hyperlink - used when the document is parsed
  525. *
  526. * @param link the hyperlink
  527. */
  528. protected void setHyperlink(HSLFHyperlink link) {
  529. _hyperlink = link;
  530. }
  531. @Override
  532. public boolean isPlaceholder() {
  533. // currently we only identify TextShapes as placeholders
  534. return false;
  535. }
  536. }