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 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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.EscherProperties;
  23. import org.apache.poi.ddf.EscherProperty;
  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. /**
  58. * Hyperlink
  59. */
  60. protected HSLFHyperlink _hyperlink;
  61. /**
  62. * Create a SimpleShape object and initialize it from the supplied Record container.
  63. *
  64. * @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
  65. * @param parent the parent of the shape
  66. */
  67. protected HSLFSimpleShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
  68. super(escherRecord, parent);
  69. }
  70. /**
  71. * Create a new Shape
  72. *
  73. * @param isChild <code>true</code> if the Line is inside a group, <code>false</code> otherwise
  74. * @return the record container which holds this shape
  75. */
  76. @Override
  77. protected EscherContainerRecord createSpContainer(boolean isChild) {
  78. EscherContainerRecord ecr = super.createSpContainer(isChild);
  79. ecr.setRecordId( EscherContainerRecord.SP_CONTAINER );
  80. EscherSpRecord sp = new EscherSpRecord();
  81. int flags = EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE;
  82. if (isChild) {
  83. flags |= EscherSpRecord.FLAG_CHILD;
  84. }
  85. sp.setFlags(flags);
  86. ecr.addChildRecord(sp);
  87. AbstractEscherOptRecord opt = new EscherOptRecord();
  88. opt.setRecordId(EscherOptRecord.RECORD_ID);
  89. ecr.addChildRecord(opt);
  90. EscherRecord anchor;
  91. if(isChild) {
  92. anchor = new EscherChildAnchorRecord();
  93. } else {
  94. anchor = new EscherClientAnchorRecord();
  95. //hack. internal variable EscherClientAnchorRecord.shortRecord can be
  96. //initialized only in fillFields(). We need to set shortRecord=false;
  97. byte[] header = new byte[16];
  98. LittleEndian.putUShort(header, 0, 0);
  99. LittleEndian.putUShort(header, 2, 0);
  100. LittleEndian.putInt(header, 4, 8);
  101. anchor.fillFields(header, 0, null);
  102. }
  103. ecr.addChildRecord(anchor);
  104. return ecr;
  105. }
  106. /**
  107. * Returns width of the line in in points
  108. */
  109. public double getLineWidth(){
  110. AbstractEscherOptRecord opt = getEscherOptRecord();
  111. EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH);
  112. return (prop == null) ? DEFAULT_LINE_WIDTH : Units.toPoints(prop.getPropertyValue());
  113. }
  114. /**
  115. * Sets the width of line in in points
  116. * @param width the width of line in in points
  117. */
  118. public void setLineWidth(double width){
  119. AbstractEscherOptRecord opt = getEscherOptRecord();
  120. setEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH, Units.toEMU(width));
  121. }
  122. /**
  123. * Sets the color of line
  124. *
  125. * @param color new color of the line
  126. */
  127. public void setLineColor(Color color){
  128. AbstractEscherOptRecord opt = getEscherOptRecord();
  129. if (color == null) {
  130. setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80000);
  131. } else {
  132. int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
  133. setEscherProperty(opt, EscherProperties.LINESTYLE__COLOR, rgb);
  134. setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x180018);
  135. }
  136. }
  137. /**
  138. * @return color of the line. If color is not set returns {@code null}
  139. */
  140. public Color getLineColor(){
  141. AbstractEscherOptRecord opt = getEscherOptRecord();
  142. EscherSimpleProperty p = getEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH);
  143. if(p != null && (p.getPropertyValue() & 0x8) == 0) {
  144. return null;
  145. }
  146. Color clr = getColor(EscherProperties.LINESTYLE__COLOR, EscherProperties.LINESTYLE__OPACITY);
  147. return clr == null ? null : clr;
  148. }
  149. /**
  150. * @return background color of the line. If color is not set returns {@code null}
  151. */
  152. public Color getLineBackgroundColor(){
  153. AbstractEscherOptRecord opt = getEscherOptRecord();
  154. EscherSimpleProperty p = getEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH);
  155. if(p != null && (p.getPropertyValue() & 0x8) == 0) {
  156. return null;
  157. }
  158. Color clr = getColor(EscherProperties.LINESTYLE__BACKCOLOR, EscherProperties.LINESTYLE__OPACITY);
  159. return clr == null ? null : clr;
  160. }
  161. /**
  162. * Sets the background color of line
  163. *
  164. * @param color new background color of the line
  165. */
  166. public void setLineBackgroundColor(Color color){
  167. AbstractEscherOptRecord opt = getEscherOptRecord();
  168. if (color == null) {
  169. setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80000);
  170. opt.removeEscherProperty(EscherProperties.LINESTYLE__BACKCOLOR);
  171. } else {
  172. int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
  173. setEscherProperty(opt, EscherProperties.LINESTYLE__BACKCOLOR, rgb);
  174. setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x180018);
  175. }
  176. }
  177. /**
  178. * Gets line cap.
  179. *
  180. * @return cap of the line.
  181. */
  182. public LineCap getLineCap(){
  183. AbstractEscherOptRecord opt = getEscherOptRecord();
  184. EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINEENDCAPSTYLE);
  185. return (prop == null) ? LineCap.FLAT : LineCap.fromNativeId(prop.getPropertyValue());
  186. }
  187. /**
  188. * Sets line cap.
  189. *
  190. * @param pen new style of the line.
  191. */
  192. public void setLineCap(LineCap pen){
  193. AbstractEscherOptRecord opt = getEscherOptRecord();
  194. setEscherProperty(opt, EscherProperties.LINESTYLE__LINEENDCAPSTYLE, pen == LineCap.FLAT ? -1 : pen.nativeId);
  195. }
  196. /**
  197. * Gets line dashing.
  198. *
  199. * @return dashing of the line.
  200. */
  201. public LineDash getLineDash(){
  202. AbstractEscherOptRecord opt = getEscherOptRecord();
  203. EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING);
  204. return (prop == null) ? LineDash.SOLID : LineDash.fromNativeId(prop.getPropertyValue());
  205. }
  206. /**
  207. * Sets line dashing.
  208. *
  209. * @param pen new style of the line.
  210. */
  211. public void setLineDash(LineDash pen){
  212. AbstractEscherOptRecord opt = getEscherOptRecord();
  213. setEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING, pen == LineDash.SOLID ? -1 : pen.nativeId);
  214. }
  215. /**
  216. * Gets the line compound style
  217. *
  218. * @return the compound style of the line.
  219. */
  220. public LineCompound getLineCompound() {
  221. AbstractEscherOptRecord opt = getEscherOptRecord();
  222. EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE);
  223. return (prop == null) ? LineCompound.SINGLE : LineCompound.fromNativeId(prop.getPropertyValue());
  224. }
  225. /**
  226. * Sets the line compound style
  227. *
  228. * @param style new compound style of the line.
  229. */
  230. public void setLineCompound(LineCompound style){
  231. AbstractEscherOptRecord opt = getEscherOptRecord();
  232. setEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE, style == LineCompound.SINGLE ? -1 : style.nativeId);
  233. }
  234. /**
  235. * Returns line style. One of the constants defined in this class.
  236. *
  237. * @return style of the line.
  238. */
  239. @Override
  240. public StrokeStyle getStrokeStyle(){
  241. return new StrokeStyle() {
  242. @Override
  243. public PaintStyle getPaint() {
  244. return DrawPaint.createSolidPaint(HSLFSimpleShape.this.getLineColor());
  245. }
  246. @Override
  247. public LineCap getLineCap() {
  248. return null;
  249. }
  250. @Override
  251. public LineDash getLineDash() {
  252. return HSLFSimpleShape.this.getLineDash();
  253. }
  254. @Override
  255. public LineCompound getLineCompound() {
  256. return HSLFSimpleShape.this.getLineCompound();
  257. }
  258. @Override
  259. public double getLineWidth() {
  260. return HSLFSimpleShape.this.getLineWidth();
  261. }
  262. };
  263. }
  264. @Override
  265. public Color getFillColor() {
  266. return getFill().getForegroundColor();
  267. }
  268. @Override
  269. public void setFillColor(Color color) {
  270. getFill().setForegroundColor(color);
  271. }
  272. @Override
  273. public Guide getAdjustValue(String name) {
  274. if (name == null || !name.matches("adj([1-9]|10)?")) {
  275. LOG.log(POILogger.INFO, "Adjust value '"+name+"' not supported. Using default value.");
  276. return null;
  277. }
  278. name = name.replace("adj", "");
  279. if (name.isEmpty()) {
  280. name = "1";
  281. }
  282. final int adjInt = Integer.parseInt(name);
  283. short escherProp;
  284. switch (adjInt) {
  285. case 1: escherProp = EscherProperties.GEOMETRY__ADJUSTVALUE; break;
  286. case 2: escherProp = EscherProperties.GEOMETRY__ADJUST2VALUE; break;
  287. case 3: escherProp = EscherProperties.GEOMETRY__ADJUST3VALUE; break;
  288. case 4: escherProp = EscherProperties.GEOMETRY__ADJUST4VALUE; break;
  289. case 5: escherProp = EscherProperties.GEOMETRY__ADJUST5VALUE; break;
  290. case 6: escherProp = EscherProperties.GEOMETRY__ADJUST6VALUE; break;
  291. case 7: escherProp = EscherProperties.GEOMETRY__ADJUST7VALUE; break;
  292. case 8: escherProp = EscherProperties.GEOMETRY__ADJUST8VALUE; break;
  293. case 9: escherProp = EscherProperties.GEOMETRY__ADJUST9VALUE; break;
  294. case 10: escherProp = EscherProperties.GEOMETRY__ADJUST10VALUE; break;
  295. default: throw new HSLFException();
  296. }
  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, EscherProperties.SHADOWSTYLE__OFFSETX);
  341. int offX = (prop == null) ? 0 : prop.getPropertyValue();
  342. prop = getEscherProperty(opt, EscherProperties.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, EscherProperties.SHADOWSTYLE__OFFSETX);
  349. int offX = (prop == null) ? 0 : prop.getPropertyValue();
  350. prop = getEscherProperty(opt, EscherProperties.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(EscherProperties.SHADOWSTYLE__COLOR, EscherProperties.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(EscherProperties.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, EscherProperties.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, EscherProperties.LINESTYLE__LINESTARTARROWHEAD, decoShape == null ? -1 : decoShape.nativeId);
  403. }
  404. public DecorationSize getLineHeadWidth(){
  405. AbstractEscherOptRecord opt = getEscherOptRecord();
  406. EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.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, EscherProperties.LINESTYLE__LINESTARTARROWWIDTH, decoSize == null ? -1 : decoSize.nativeId);
  412. }
  413. public DecorationSize getLineHeadLength(){
  414. AbstractEscherOptRecord opt = getEscherOptRecord();
  415. EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.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, EscherProperties.LINESTYLE__LINESTARTARROWLENGTH, decoSize == null ? -1 : decoSize.nativeId);
  421. }
  422. public DecorationShape getLineTailDecoration(){
  423. AbstractEscherOptRecord opt = getEscherOptRecord();
  424. EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.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, EscherProperties.LINESTYLE__LINEENDARROWHEAD, decoShape == null ? -1 : decoShape.nativeId);
  430. }
  431. public DecorationSize getLineTailWidth(){
  432. AbstractEscherOptRecord opt = getEscherOptRecord();
  433. EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.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, EscherProperties.LINESTYLE__LINEENDARROWWIDTH, decoSize == null ? -1 : decoSize.nativeId);
  439. }
  440. public DecorationSize getLineTailLength(){
  441. AbstractEscherOptRecord opt = getEscherOptRecord();
  442. EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.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, EscherProperties.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. }