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.

HSLFShape.java 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  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 java.awt.Graphics2D;
  18. import java.awt.geom.Rectangle2D;
  19. import java.util.Iterator;
  20. import java.util.List;
  21. import org.apache.poi.ddf.AbstractEscherOptRecord;
  22. import org.apache.poi.ddf.EscherChildAnchorRecord;
  23. import org.apache.poi.ddf.EscherClientAnchorRecord;
  24. import org.apache.poi.ddf.EscherClientDataRecord;
  25. import org.apache.poi.ddf.EscherColorRef;
  26. import org.apache.poi.ddf.EscherColorRef.SysIndexProcedure;
  27. import org.apache.poi.ddf.EscherColorRef.SysIndexSource;
  28. import org.apache.poi.ddf.EscherComplexProperty;
  29. import org.apache.poi.ddf.EscherContainerRecord;
  30. import org.apache.poi.ddf.EscherProperties;
  31. import org.apache.poi.ddf.EscherProperty;
  32. import org.apache.poi.ddf.EscherRecord;
  33. import org.apache.poi.ddf.EscherSimpleProperty;
  34. import org.apache.poi.ddf.EscherSpRecord;
  35. import org.apache.poi.ddf.EscherTextboxRecord;
  36. import org.apache.poi.hslf.record.ColorSchemeAtom;
  37. import org.apache.poi.hslf.record.HSLFEscherClientDataRecord;
  38. import org.apache.poi.hslf.record.Record;
  39. import org.apache.poi.hslf.record.RecordTypes;
  40. import org.apache.poi.sl.draw.DrawFactory;
  41. import org.apache.poi.sl.usermodel.FillStyle;
  42. import org.apache.poi.sl.usermodel.PresetColor;
  43. import org.apache.poi.sl.usermodel.Shape;
  44. import org.apache.poi.sl.usermodel.ShapeContainer;
  45. import org.apache.poi.sl.usermodel.ShapeType;
  46. import org.apache.poi.util.POILogFactory;
  47. import org.apache.poi.util.POILogger;
  48. import org.apache.poi.util.StringUtil;
  49. import org.apache.poi.util.Units;
  50. /**
  51. * <p>
  52. * Represents a Shape which is the elemental object that composes a drawing.
  53. * This class is a wrapper around EscherSpContainer which holds all information
  54. * about a shape in PowerPoint document.
  55. * </p>
  56. * <p>
  57. * When you add a shape, you usually specify the dimensions of the shape and the position
  58. * of the upper'left corner of the bounding box for the shape relative to the upper'left
  59. * corner of the page, worksheet, or slide. Distances in the drawing layer are measured
  60. * in points (72 points = 1 inch).
  61. * </p>
  62. * <p>
  63. */
  64. public abstract class HSLFShape implements Shape<HSLFShape,HSLFTextParagraph> {
  65. private static final POILogger LOG = POILogFactory.getLogger(HSLFShape.class);
  66. /**
  67. * Either EscherSpContainer or EscheSpgrContainer record
  68. * which holds information about this shape.
  69. */
  70. private EscherContainerRecord _escherContainer;
  71. /**
  72. * Parent of this shape.
  73. * <code>null</code> for the topmost shapes.
  74. */
  75. private ShapeContainer<HSLFShape,HSLFTextParagraph> _parent;
  76. /**
  77. * The <code>Sheet</code> this shape belongs to
  78. */
  79. private HSLFSheet _sheet;
  80. /**
  81. * Fill
  82. */
  83. private HSLFFill _fill;
  84. /**
  85. * Create a Shape object. This constructor is used when an existing Shape is read from from a PowerPoint document.
  86. *
  87. * @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
  88. * @param parent the parent of this Shape
  89. */
  90. protected HSLFShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
  91. _escherContainer = escherRecord;
  92. _parent = parent;
  93. }
  94. /**
  95. * Create and assign the lower level escher record to this shape
  96. */
  97. protected EscherContainerRecord createSpContainer(boolean isChild) {
  98. if (_escherContainer == null) {
  99. _escherContainer = new EscherContainerRecord();
  100. _escherContainer.setOptions((short)15);
  101. }
  102. return _escherContainer;
  103. }
  104. /**
  105. * @return the parent of this shape
  106. */
  107. @Override
  108. public ShapeContainer<HSLFShape,HSLFTextParagraph> getParent(){
  109. return _parent;
  110. }
  111. /**
  112. * @return name of the shape.
  113. */
  114. @Override
  115. public String getShapeName(){
  116. final EscherComplexProperty ep = getEscherProperty(getEscherOptRecord(), EscherProperties.GROUPSHAPE__SHAPENAME);
  117. if (ep != null) {
  118. final byte[] cd = ep.getComplexData();
  119. return StringUtil.getFromUnicodeLE0Terminated(cd, 0, cd.length/2);
  120. } else {
  121. return getShapeType().nativeName+" "+getShapeId();
  122. }
  123. }
  124. public ShapeType getShapeType(){
  125. EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
  126. return ShapeType.forId(spRecord.getShapeType(), false);
  127. }
  128. public void setShapeType(ShapeType type){
  129. EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
  130. spRecord.setShapeType( (short) type.nativeId );
  131. spRecord.setVersion( (short) 0x2 );
  132. }
  133. /**
  134. * Returns the anchor (the bounding box rectangle) of this shape.
  135. * All coordinates are expressed in points (72 dpi).
  136. *
  137. * @return the anchor of this shape
  138. */
  139. @Override
  140. public Rectangle2D getAnchor() {
  141. EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
  142. int flags = spRecord.getFlags();
  143. int x1,y1,x2,y2;
  144. EscherChildAnchorRecord childRec = getEscherChild(EscherChildAnchorRecord.RECORD_ID);
  145. boolean useChildRec = ((flags & EscherSpRecord.FLAG_CHILD) != 0);
  146. if (useChildRec && childRec != null){
  147. x1 = childRec.getDx1();
  148. y1 = childRec.getDy1();
  149. x2 = childRec.getDx2();
  150. y2 = childRec.getDy2();
  151. } else {
  152. if (useChildRec) {
  153. LOG.log(POILogger.WARN, "EscherSpRecord.FLAG_CHILD is set but EscherChildAnchorRecord was not found");
  154. }
  155. EscherClientAnchorRecord clientRec = getEscherChild(EscherClientAnchorRecord.RECORD_ID);
  156. x1 = clientRec.getCol1();
  157. y1 = clientRec.getFlag();
  158. x2 = clientRec.getDx1();
  159. y2 = clientRec.getRow1();
  160. }
  161. // TODO: find out where this -1 value comes from at #57820 (link to ms docs?)
  162. return new Rectangle2D.Double(
  163. (x1 == -1 ? -1 : Units.masterToPoints(x1)),
  164. (y1 == -1 ? -1 : Units.masterToPoints(y1)),
  165. (x2 == -1 ? -1 : Units.masterToPoints(x2-x1)),
  166. (y2 == -1 ? -1 : Units.masterToPoints(y2-y1))
  167. );
  168. }
  169. /**
  170. * Sets the anchor (the bounding box rectangle) of this shape.
  171. * All coordinates should be expressed in points (72 dpi).
  172. *
  173. * @param anchor new anchor
  174. */
  175. public void setAnchor(Rectangle2D anchor){
  176. int x = Units.pointsToMaster(anchor.getX());
  177. int y = Units.pointsToMaster(anchor.getY());
  178. int w = Units.pointsToMaster(anchor.getWidth() + anchor.getX());
  179. int h = Units.pointsToMaster(anchor.getHeight() + anchor.getY());
  180. EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
  181. int flags = spRecord.getFlags();
  182. if ((flags & EscherSpRecord.FLAG_CHILD) != 0){
  183. EscherChildAnchorRecord rec = getEscherChild(EscherChildAnchorRecord.RECORD_ID);
  184. rec.setDx1(x);
  185. rec.setDy1(y);
  186. rec.setDx2(w);
  187. rec.setDy2(h);
  188. } else {
  189. EscherClientAnchorRecord rec = getEscherChild(EscherClientAnchorRecord.RECORD_ID);
  190. rec.setCol1((short)x);
  191. rec.setFlag((short)y);
  192. rec.setDx1((short)w);
  193. rec.setRow1((short)h);
  194. }
  195. }
  196. /**
  197. * Moves the top left corner of the shape to the specified point.
  198. *
  199. * @param x the x coordinate of the top left corner of the shape
  200. * @param y the y coordinate of the top left corner of the shape
  201. */
  202. public final void moveTo(double x, double y) {
  203. // This convenience method should be implemented via setAnchor in subclasses
  204. // see HSLFGroupShape.setAnchor() for a reference
  205. Rectangle2D anchor = getAnchor();
  206. anchor.setRect(x, y, anchor.getWidth(), anchor.getHeight());
  207. setAnchor(anchor);
  208. }
  209. /**
  210. * Helper method to return escher child by record ID
  211. *
  212. * @return escher record or <code>null</code> if not found.
  213. */
  214. public static <T extends EscherRecord> T getEscherChild(EscherContainerRecord owner, int recordId){
  215. return owner.getChildById((short)recordId);
  216. }
  217. /**
  218. * @since POI 3.14-Beta2
  219. */
  220. public static <T extends EscherRecord> T getEscherChild(EscherContainerRecord owner, RecordTypes recordId){
  221. return getEscherChild(owner, recordId.typeID);
  222. }
  223. public <T extends EscherRecord> T getEscherChild(int recordId){
  224. return _escherContainer.getChildById((short)recordId);
  225. }
  226. /**
  227. * @since POI 3.14-Beta2
  228. */
  229. public <T extends EscherRecord> T getEscherChild(RecordTypes recordId){
  230. return getEscherChild(recordId.typeID);
  231. }
  232. /**
  233. * Returns escher property by id.
  234. *
  235. * @return escher property or <code>null</code> if not found.
  236. */
  237. public static <T extends EscherProperty> T getEscherProperty(AbstractEscherOptRecord opt, int propId){
  238. return (opt == null) ? null : opt.lookup(propId);
  239. }
  240. /**
  241. * Set an escher property for this shape.
  242. *
  243. * @param opt The opt record to set the properties to.
  244. * @param propId The id of the property. One of the constants defined in EscherOptRecord.
  245. * @param value value of the property. If value = -1 then the property is removed.
  246. */
  247. public static void setEscherProperty(AbstractEscherOptRecord opt, short propId, int value){
  248. java.util.List<EscherProperty> props = opt.getEscherProperties();
  249. for ( Iterator<EscherProperty> iterator = props.iterator(); iterator.hasNext(); ) {
  250. if (iterator.next().getPropertyNumber() == propId){
  251. iterator.remove();
  252. break;
  253. }
  254. }
  255. if (value != -1) {
  256. opt.addEscherProperty(new EscherSimpleProperty(propId, value));
  257. opt.sortProperties();
  258. }
  259. }
  260. /**
  261. * Set an simple escher property for this shape.
  262. *
  263. * @param propId The id of the property. One of the constants defined in EscherOptRecord.
  264. * @param value value of the property. If value = -1 then the property is removed.
  265. */
  266. public void setEscherProperty(short propId, int value){
  267. AbstractEscherOptRecord opt = getEscherOptRecord();
  268. setEscherProperty(opt, propId, value);
  269. }
  270. /**
  271. * Get the value of a simple escher property for this shape.
  272. *
  273. * @param propId The id of the property. One of the constants defined in EscherOptRecord.
  274. */
  275. public int getEscherProperty(short propId){
  276. AbstractEscherOptRecord opt = getEscherOptRecord();
  277. EscherSimpleProperty prop = getEscherProperty(opt, propId);
  278. return prop == null ? 0 : prop.getPropertyValue();
  279. }
  280. /**
  281. * Get the value of a simple escher property for this shape.
  282. *
  283. * @param propId The id of the property. One of the constants defined in EscherOptRecord.
  284. */
  285. public int getEscherProperty(short propId, int defaultValue){
  286. AbstractEscherOptRecord opt = getEscherOptRecord();
  287. EscherSimpleProperty prop = getEscherProperty(opt, propId);
  288. return prop == null ? defaultValue : prop.getPropertyValue();
  289. }
  290. /**
  291. * @return The shape container and it's children that can represent this
  292. * shape.
  293. */
  294. public EscherContainerRecord getSpContainer(){
  295. return _escherContainer;
  296. }
  297. /**
  298. * Event which fires when a shape is inserted in the sheet.
  299. * In some cases we need to propagate changes to upper level containers.
  300. * <br>
  301. * Default implementation does nothing.
  302. *
  303. * @param sh - owning shape
  304. */
  305. protected void afterInsert(HSLFSheet sh){
  306. if(_fill != null) {
  307. _fill.afterInsert(sh);
  308. }
  309. }
  310. /**
  311. * @return the <code>SlideShow</code> this shape belongs to
  312. */
  313. @Override
  314. public HSLFSheet getSheet(){
  315. return _sheet;
  316. }
  317. /**
  318. * Assign the <code>SlideShow</code> this shape belongs to
  319. *
  320. * @param sheet owner of this shape
  321. */
  322. public void setSheet(HSLFSheet sheet){
  323. _sheet = sheet;
  324. }
  325. Color getColor(short colorProperty, short opacityProperty){
  326. final AbstractEscherOptRecord opt = getEscherOptRecord();
  327. final EscherSimpleProperty colProp = getEscherProperty(opt, colorProperty);
  328. final Color col;
  329. if (colProp == null) {
  330. col = Color.WHITE;
  331. } else {
  332. EscherColorRef ecr = new EscherColorRef(colProp.getPropertyValue());
  333. col = getColor(ecr);
  334. if (col == null) {
  335. return null;
  336. }
  337. }
  338. double alpha = getAlpha(opacityProperty);
  339. return new Color(col.getRed(), col.getGreen(), col.getBlue(), (int)(alpha*255.0));
  340. }
  341. Color getColor(EscherColorRef ecr) {
  342. boolean fPaletteIndex = ecr.hasPaletteIndexFlag();
  343. boolean fPaletteRGB = ecr.hasPaletteRGBFlag();
  344. boolean fSystemRGB = ecr.hasSystemRGBFlag();
  345. boolean fSchemeIndex = ecr.hasSchemeIndexFlag();
  346. boolean fSysIndex = ecr.hasSysIndexFlag();
  347. int rgb[] = ecr.getRGB();
  348. HSLFSheet sheet = getSheet();
  349. if (fSchemeIndex && sheet != null) {
  350. //red is the index to the color scheme
  351. ColorSchemeAtom ca = sheet.getColorScheme();
  352. int schemeColor = ca.getColor(ecr.getSchemeIndex());
  353. rgb[0] = (schemeColor >> 0) & 0xFF;
  354. rgb[1] = (schemeColor >> 8) & 0xFF;
  355. rgb[2] = (schemeColor >> 16) & 0xFF;
  356. } else if (fPaletteIndex) {
  357. //TODO
  358. } else if (fPaletteRGB) {
  359. //TODO
  360. } else if (fSystemRGB) {
  361. //TODO
  362. } else if (fSysIndex) {
  363. Color col = getSysIndexColor(ecr);
  364. col = applySysIndexProcedure(ecr, col);
  365. return col;
  366. }
  367. return new Color(rgb[0], rgb[1], rgb[2]);
  368. }
  369. private Color getSysIndexColor(EscherColorRef ecr) {
  370. SysIndexSource sis = ecr.getSysIndexSource();
  371. if (sis == null) {
  372. int sysIdx = ecr.getSysIndex();
  373. PresetColor pc = PresetColor.valueOfNativeId(sysIdx);
  374. return (pc != null) ? pc.color : null;
  375. }
  376. // TODO: check for recursive loops, when color getter also reference
  377. // a different color type
  378. switch (sis) {
  379. case FILL_COLOR: {
  380. return getFill().getForegroundColor();
  381. }
  382. case LINE_OR_FILL_COLOR: {
  383. Color col = null;
  384. if (this instanceof HSLFSimpleShape) {
  385. col = ((HSLFSimpleShape)this).getLineColor();
  386. }
  387. if (col == null) {
  388. col = getFill().getForegroundColor();
  389. }
  390. return col;
  391. }
  392. case LINE_COLOR: {
  393. if (this instanceof HSLFSimpleShape) {
  394. return ((HSLFSimpleShape)this).getLineColor();
  395. }
  396. break;
  397. }
  398. case SHADOW_COLOR: {
  399. if (this instanceof HSLFSimpleShape) {
  400. return ((HSLFSimpleShape)this).getShadowColor();
  401. }
  402. break;
  403. }
  404. case CURRENT_OR_LAST_COLOR: {
  405. // TODO ... read from graphics context???
  406. break;
  407. }
  408. case FILL_BACKGROUND_COLOR: {
  409. return getFill().getBackgroundColor();
  410. }
  411. case LINE_BACKGROUND_COLOR: {
  412. if (this instanceof HSLFSimpleShape) {
  413. return ((HSLFSimpleShape)this).getLineBackgroundColor();
  414. }
  415. break;
  416. }
  417. case FILL_OR_LINE_COLOR: {
  418. Color col = getFill().getForegroundColor();
  419. if (col == null && this instanceof HSLFSimpleShape) {
  420. col = ((HSLFSimpleShape)this).getLineColor();
  421. }
  422. return col;
  423. }
  424. default:
  425. break;
  426. }
  427. return null;
  428. }
  429. private Color applySysIndexProcedure(EscherColorRef ecr, Color col) {
  430. final SysIndexProcedure sip = ecr.getSysIndexProcedure();
  431. if (col == null || sip == null) {
  432. return col;
  433. }
  434. switch (sip) {
  435. case DARKEN_COLOR: {
  436. // see java.awt.Color#darken()
  437. double FACTOR = (ecr.getRGB()[2])/255.;
  438. int r = (int)Math.rint(col.getRed()*FACTOR);
  439. int g = (int)Math.rint(col.getGreen()*FACTOR);
  440. int b = (int)Math.rint(col.getBlue()*FACTOR);
  441. return new Color(r,g,b);
  442. }
  443. case LIGHTEN_COLOR: {
  444. double FACTOR = (0xFF-ecr.getRGB()[2])/255.;
  445. int r = col.getRed();
  446. int g = col.getGreen();
  447. int b = col.getBlue();
  448. r += Math.rint((0xFF-r)*FACTOR);
  449. g += Math.rint((0xFF-g)*FACTOR);
  450. b += Math.rint((0xFF-b)*FACTOR);
  451. return new Color(r,g,b);
  452. }
  453. default:
  454. // TODO ...
  455. break;
  456. }
  457. return col;
  458. }
  459. double getAlpha(short opacityProperty) {
  460. AbstractEscherOptRecord opt = getEscherOptRecord();
  461. EscherSimpleProperty op = getEscherProperty(opt, opacityProperty);
  462. int defaultOpacity = 0x00010000;
  463. int opacity = (op == null) ? defaultOpacity : op.getPropertyValue();
  464. return Units.fixedPointToDouble(opacity);
  465. }
  466. Color toRGB(int val){
  467. int a = (val >> 24) & 0xFF;
  468. int b = (val >> 16) & 0xFF;
  469. int g = (val >> 8) & 0xFF;
  470. int r = (val >> 0) & 0xFF;
  471. if(a == 0xFE){
  472. // Color is an sRGB value specified by red, green, and blue fields.
  473. } else if (a == 0xFF){
  474. // Color is undefined.
  475. } else {
  476. // index in the color scheme
  477. ColorSchemeAtom ca = getSheet().getColorScheme();
  478. int schemeColor = ca.getColor(a);
  479. r = (schemeColor >> 0) & 0xFF;
  480. g = (schemeColor >> 8) & 0xFF;
  481. b = (schemeColor >> 16) & 0xFF;
  482. }
  483. return new Color(r, g, b);
  484. }
  485. @Override
  486. public int getShapeId(){
  487. EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
  488. return spRecord == null ? 0 : spRecord.getShapeId();
  489. }
  490. /**
  491. * Sets shape ID
  492. *
  493. * @param id of the shape
  494. */
  495. public void setShapeId(int id){
  496. EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
  497. if(spRecord != null) spRecord.setShapeId(id);
  498. }
  499. /**
  500. * Fill properties of this shape
  501. *
  502. * @return fill properties of this shape
  503. */
  504. public HSLFFill getFill(){
  505. if(_fill == null) {
  506. _fill = new HSLFFill(this);
  507. }
  508. return _fill;
  509. }
  510. public FillStyle getFillStyle() {
  511. return getFill().getFillStyle();
  512. }
  513. @Override
  514. public void draw(Graphics2D graphics, Rectangle2D bounds){
  515. DrawFactory.getInstance(graphics).drawShape(graphics, this, bounds);
  516. }
  517. public AbstractEscherOptRecord getEscherOptRecord() {
  518. AbstractEscherOptRecord opt = getEscherChild(RecordTypes.EscherOPT);
  519. if (opt == null) {
  520. opt = getEscherChild(RecordTypes.EscherUserDefined);
  521. }
  522. return opt;
  523. }
  524. public boolean getFlipHorizontal(){
  525. EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
  526. return (spRecord.getFlags()& EscherSpRecord.FLAG_FLIPHORIZ) != 0;
  527. }
  528. public void setFlipHorizontal(boolean flip) {
  529. EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
  530. int flag = spRecord.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ;
  531. spRecord.setFlags(flag);
  532. }
  533. public boolean getFlipVertical(){
  534. EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
  535. return (spRecord.getFlags()& EscherSpRecord.FLAG_FLIPVERT) != 0;
  536. }
  537. public void setFlipVertical(boolean flip) {
  538. EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
  539. int flag = spRecord.getFlags() | EscherSpRecord.FLAG_FLIPVERT;
  540. spRecord.setFlags(flag);
  541. }
  542. public double getRotation(){
  543. int rot = getEscherProperty(EscherProperties.TRANSFORM__ROTATION);
  544. return Units.fixedPointToDouble(rot);
  545. }
  546. public void setRotation(double theta){
  547. int rot = Units.doubleToFixedPoint(theta % 360.0);
  548. setEscherProperty(EscherProperties.TRANSFORM__ROTATION, rot);
  549. }
  550. public boolean isPlaceholder() {
  551. return false;
  552. }
  553. /**
  554. * Find a record in the underlying EscherClientDataRecord
  555. *
  556. * @param recordType type of the record to search
  557. */
  558. @SuppressWarnings("unchecked")
  559. public <T extends Record> T getClientDataRecord(int recordType) {
  560. List<? extends Record> records = getClientRecords();
  561. if (records != null) for (Record r : records) {
  562. if (r.getRecordType() == recordType){
  563. return (T)r;
  564. }
  565. }
  566. return null;
  567. }
  568. /**
  569. * Search for EscherClientDataRecord, if found, convert its contents into an array of HSLF records
  570. *
  571. * @return an array of HSLF records contained in the shape's EscherClientDataRecord or <code>null</code>
  572. */
  573. protected List<? extends Record> getClientRecords() {
  574. HSLFEscherClientDataRecord clientData = getClientData(false);
  575. return (clientData == null) ? null : clientData.getHSLFChildRecords();
  576. }
  577. /**
  578. * Create a new HSLF-specific EscherClientDataRecord
  579. *
  580. * @param create if true, create the missing record
  581. * @return the client record or null if it was missing and create wasn't activated
  582. */
  583. protected HSLFEscherClientDataRecord getClientData(boolean create) {
  584. HSLFEscherClientDataRecord clientData = getEscherChild(EscherClientDataRecord.RECORD_ID);
  585. if (clientData == null && create) {
  586. clientData = new HSLFEscherClientDataRecord();
  587. clientData.setOptions((short)15);
  588. clientData.setRecordId(EscherClientDataRecord.RECORD_ID);
  589. getSpContainer().addChildBefore(clientData, EscherTextboxRecord.RECORD_ID);
  590. }
  591. return clientData;
  592. }
  593. }