1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
|
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hslf.usermodel;
import java.awt.Color;
import org.apache.logging.log4j.Logger;
import org.apache.poi.hslf.record.HSLFEscherClientDataRecord;
import org.apache.poi.hslf.record.OEPlaceholderAtom;
import org.apache.poi.hslf.record.RoundTripHFPlaceholder12;
import org.apache.poi.logging.PoiLogManager;
import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherChildAnchorRecord;
import org.apache.poi.ddf.EscherClientAnchorRecord;
import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperty;
import org.apache.poi.ddf.EscherPropertyTypes;
import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.ddf.EscherSimpleProperty;
import org.apache.poi.ddf.EscherSpRecord;
import org.apache.poi.hslf.exceptions.HSLFException;
import org.apache.poi.sl.draw.DrawPaint;
import org.apache.poi.sl.draw.geom.CustomGeometry;
import org.apache.poi.sl.draw.geom.Guide;
import org.apache.poi.sl.draw.geom.PresetGeometries;
import org.apache.poi.sl.usermodel.LineDecoration;
import org.apache.poi.sl.usermodel.LineDecoration.DecorationShape;
import org.apache.poi.sl.usermodel.LineDecoration.DecorationSize;
import org.apache.poi.sl.usermodel.PaintStyle;
import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
import org.apache.poi.sl.usermodel.Placeholder;
import org.apache.poi.sl.usermodel.Shadow;
import org.apache.poi.sl.usermodel.ShapeContainer;
import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.sl.usermodel.SimpleShape;
import org.apache.poi.sl.usermodel.StrokeStyle;
import org.apache.poi.sl.usermodel.StrokeStyle.LineCap;
import org.apache.poi.sl.usermodel.StrokeStyle.LineCompound;
import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.Units;
import static org.apache.poi.hslf.usermodel.HSLFShapePlaceholderDetails.createOEPlaceholderAtom;
import static org.apache.poi.hslf.usermodel.HSLFShapePlaceholderDetails.getPlaceholderId;
import static org.apache.poi.hslf.usermodel.HSLFShapePlaceholderDetails.removePlaceholder;
import static org.apache.poi.hslf.usermodel.HSLFShapePlaceholderDetails.updateSPRecord;
/**
* An abstract simple (non-group) shape.
* This is the parent class for all primitive shapes like Line, Rectangle, etc.
*/
public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape<HSLFShape,HSLFTextParagraph> {
private static final Logger LOG = PoiLogManager.getLogger(HSLFSimpleShape.class);
public static final double DEFAULT_LINE_WIDTH = 0.75;
protected static final EscherPropertyTypes[] ADJUST_VALUES = {
EscherPropertyTypes.GEOMETRY__ADJUSTVALUE,
EscherPropertyTypes.GEOMETRY__ADJUST2VALUE,
EscherPropertyTypes.GEOMETRY__ADJUST3VALUE,
EscherPropertyTypes.GEOMETRY__ADJUST4VALUE,
EscherPropertyTypes.GEOMETRY__ADJUST5VALUE,
EscherPropertyTypes.GEOMETRY__ADJUST6VALUE,
EscherPropertyTypes.GEOMETRY__ADJUST7VALUE,
EscherPropertyTypes.GEOMETRY__ADJUST8VALUE,
EscherPropertyTypes.GEOMETRY__ADJUST9VALUE,
EscherPropertyTypes.GEOMETRY__ADJUST10VALUE
};
/**
* Hyperlink
*/
protected HSLFHyperlink _hyperlink;
protected HSLFShapePlaceholderDetails _placeholderDetails;
/**
* Create a SimpleShape object and initialize it from the supplied Record container.
*
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
* @param parent the parent of the shape
*/
protected HSLFSimpleShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent);
}
/**
* Create a new Shape
*
* @param isChild <code>true</code> if the Line is inside a group, <code>false</code> otherwise
* @return the record container which holds this shape
*/
@Override
protected EscherContainerRecord createSpContainer(boolean isChild) {
EscherContainerRecord ecr = super.createSpContainer(isChild);
ecr.setRecordId( EscherContainerRecord.SP_CONTAINER );
EscherSpRecord sp = new EscherSpRecord();
int flags = EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE;
if (isChild) {
flags |= EscherSpRecord.FLAG_CHILD;
}
sp.setFlags(flags);
ecr.addChildRecord(sp);
AbstractEscherOptRecord opt = new EscherOptRecord();
opt.setRecordId(EscherOptRecord.RECORD_ID);
ecr.addChildRecord(opt);
EscherRecord anchor;
if(isChild) {
anchor = new EscherChildAnchorRecord();
} else {
anchor = new EscherClientAnchorRecord();
//hack. internal variable EscherClientAnchorRecord.shortRecord can be
//initialized only in fillFields(). We need to set shortRecord=false;
byte[] header = new byte[16];
LittleEndian.putUShort(header, 0, 0);
LittleEndian.putUShort(header, 2, 0);
LittleEndian.putInt(header, 4, 8);
anchor.fillFields(header, 0, null);
}
ecr.addChildRecord(anchor);
return ecr;
}
/**
* Returns width of the line in in points
*/
public double getLineWidth(){
AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINEWIDTH);
return (prop == null) ? DEFAULT_LINE_WIDTH : Units.toPoints(prop.getPropertyValue());
}
/**
* Sets the width of line in in points
* @param width the width of line in in points
*/
public void setLineWidth(double width){
AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINEWIDTH, Units.toEMU(width));
}
/**
* Sets the color of line
*
* @param color new color of the line
*/
public void setLineColor(Color color){
AbstractEscherOptRecord opt = getEscherOptRecord();
if (color == null) {
setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__NOLINEDRAWDASH, 0x80000);
} else {
int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__COLOR, rgb);
setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__NOLINEDRAWDASH, 0x180018);
}
}
/**
* @return color of the line. If color is not set returns {@code null}
*/
public Color getLineColor(){
AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty p = getEscherProperty(opt, EscherPropertyTypes.LINESTYLE__NOLINEDRAWDASH);
if(p != null && (p.getPropertyValue() & 0x8) == 0) {
return null;
}
return getColor(EscherPropertyTypes.LINESTYLE__COLOR, EscherPropertyTypes.LINESTYLE__OPACITY);
}
/**
* @return background color of the line. If color is not set returns {@code null}
*/
public Color getLineBackgroundColor(){
AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty p = getEscherProperty(opt, EscherPropertyTypes.LINESTYLE__NOLINEDRAWDASH);
if(p != null && (p.getPropertyValue() & 0x8) == 0) {
return null;
}
return getColor(EscherPropertyTypes.LINESTYLE__BACKCOLOR, EscherPropertyTypes.LINESTYLE__OPACITY);
}
/**
* Sets the background color of line
*
* @param color new background color of the line
*/
public void setLineBackgroundColor(Color color){
AbstractEscherOptRecord opt = getEscherOptRecord();
if (color == null) {
setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__NOLINEDRAWDASH, 0x80000);
opt.removeEscherProperty(EscherPropertyTypes.LINESTYLE__BACKCOLOR);
} else {
int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__BACKCOLOR, rgb);
setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__NOLINEDRAWDASH, 0x180018);
}
}
/**
* Gets line cap.
*
* @return cap of the line.
*/
public LineCap getLineCap(){
AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINEENDCAPSTYLE);
return (prop == null) ? LineCap.FLAT : LineCap.fromNativeId(prop.getPropertyValue());
}
/**
* Sets line cap.
*
* @param pen new style of the line.
*/
public void setLineCap(LineCap pen){
AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINEENDCAPSTYLE, pen == LineCap.FLAT ? -1 : pen.nativeId);
}
/**
* Gets line dashing.
*
* @return dashing of the line.
*/
public LineDash getLineDash(){
AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINEDASHING);
return (prop == null) ? LineDash.SOLID : LineDash.fromNativeId(prop.getPropertyValue());
}
/**
* Sets line dashing.
*
* @param pen new style of the line.
*/
public void setLineDash(LineDash pen){
AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINEDASHING, pen == LineDash.SOLID ? -1 : pen.nativeId);
}
/**
* Gets the line compound style
*
* @return the compound style of the line.
*/
public LineCompound getLineCompound() {
AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINESTYLE);
return (prop == null) ? LineCompound.SINGLE : LineCompound.fromNativeId(prop.getPropertyValue());
}
/**
* Sets the line compound style
*
* @param style new compound style of the line.
*/
public void setLineCompound(LineCompound style){
AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINESTYLE, style == LineCompound.SINGLE ? -1 : style.nativeId);
}
/**
* Returns line style. One of the constants defined in this class.
*
* @return style of the line.
*/
@Override
public StrokeStyle getStrokeStyle(){
return new StrokeStyle() {
@Override
public PaintStyle getPaint() {
return DrawPaint.createSolidPaint(HSLFSimpleShape.this.getLineColor());
}
@Override
public LineCap getLineCap() {
return null;
}
@Override
public LineDash getLineDash() {
return HSLFSimpleShape.this.getLineDash();
}
@Override
public LineCompound getLineCompound() {
return HSLFSimpleShape.this.getLineCompound();
}
@Override
public double getLineWidth() {
return HSLFSimpleShape.this.getLineWidth();
}
};
}
@Override
public Color getFillColor() {
return getFill().getForegroundColor();
}
@Override
public void setFillColor(Color color) {
getFill().setForegroundColor(color);
}
@Override
public Guide getAdjustValue(String name) {
if (name == null || !name.matches("adj([1-9]|10)?")) {
LOG.atInfo().log("Adjust value '{}' not supported. Using default value.", name);
return null;
}
name = name.replace("adj", "");
if (name.isEmpty()) {
name = "1";
}
final int adjInt = Integer.parseInt(name);
if (adjInt < 1 || adjInt > 10) {
throw new HSLFException("invalid adjust value: "+adjInt);
}
EscherPropertyTypes escherProp = ADJUST_VALUES[adjInt-1];
int adjval = getEscherProperty(escherProp, -1);
if (adjval == -1) {
return null;
}
// Bug 59004
// the adjust value are format dependent, we scale them up so they match the OOXML ones.
// see https://social.msdn.microsoft.com/Forums/en-US/33e458e6-58df-48fe-9a10-e303ab08991d/preset-shapes-for-ppt?forum=os_binaryfile
// usually we deal with length units and only very few degree units:
boolean isDegreeUnit = false;
switch (getShapeType()) {
case ARC:
case BLOCK_ARC:
case CHORD:
case PIE:
isDegreeUnit = (adjInt == 1 || adjInt == 2);
break;
case CIRCULAR_ARROW:
case LEFT_CIRCULAR_ARROW:
case LEFT_RIGHT_CIRCULAR_ARROW:
isDegreeUnit = (adjInt == 2 || adjInt == 3 || adjInt == 4);
break;
case MATH_NOT_EQUAL:
isDegreeUnit = (adjInt == 2);
break;
}
Guide gd = new Guide();
gd.setName(name);
gd.setFmla("val "+Math.rint(adjval * (isDegreeUnit ? 65536. : 100000./21000.)));
return gd;
}
@Override
public CustomGeometry getGeometry() {
PresetGeometries dict = PresetGeometries.getInstance();
ShapeType st = getShapeType();
String name = (st != null) ? st.getOoxmlName() : null;
CustomGeometry geom = dict.get(name);
if (geom == null) {
if (name == null) {
name = (st != null) ? st.toString() : "<unknown>";
}
LOG.atWarn().log("No preset shape definition for shapeType: {}", name);
}
return geom;
}
public double getShadowAngle() {
AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherPropertyTypes.SHADOWSTYLE__OFFSETX);
int offX = (prop == null) ? 0 : prop.getPropertyValue();
prop = getEscherProperty(opt, EscherPropertyTypes.SHADOWSTYLE__OFFSETY);
int offY = (prop == null) ? 0 : prop.getPropertyValue();
return Math.toDegrees(Math.atan2(offY, offX));
}
public double getShadowDistance() {
AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherPropertyTypes.SHADOWSTYLE__OFFSETX);
int offX = (prop == null) ? 0 : prop.getPropertyValue();
prop = getEscherProperty(opt, EscherPropertyTypes.SHADOWSTYLE__OFFSETY);
int offY = (prop == null) ? 0 : prop.getPropertyValue();
return Units.toPoints((long)Math.hypot(offX, offY));
}
/**
* @return color of the line. If color is not set returns <code>java.awt.Color.black</code>
*/
public Color getShadowColor(){
Color clr = getColor(EscherPropertyTypes.SHADOWSTYLE__COLOR, EscherPropertyTypes.SHADOWSTYLE__OPACITY);
return clr == null ? Color.black : clr;
}
@Override
public Shadow<HSLFShape,HSLFTextParagraph> getShadow() {
AbstractEscherOptRecord opt = getEscherOptRecord();
if (opt == null) {
return null;
}
EscherProperty shadowType = opt.lookup(EscherPropertyTypes.SHADOWSTYLE__TYPE);
if (shadowType == null) {
return null;
}
return new Shadow<HSLFShape,HSLFTextParagraph>(){
@Override
public SimpleShape<HSLFShape,HSLFTextParagraph> getShadowParent() {
return HSLFSimpleShape.this;
}
@Override
public double getDistance() {
return getShadowDistance();
}
@Override
public double getAngle() {
return getShadowAngle();
}
@Override
public double getBlur() {
// TODO Auto-generated method stub
return 0;
}
@Override
public SolidPaint getFillStyle() {
return DrawPaint.createSolidPaint(getShadowColor());
}
};
}
public DecorationShape getLineHeadDecoration(){
AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINESTARTARROWHEAD);
return (prop == null) ? null : DecorationShape.fromNativeId(prop.getPropertyValue());
}
public void setLineHeadDecoration(DecorationShape decoShape){
AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINESTARTARROWHEAD, decoShape == null ? -1 : decoShape.nativeId);
}
public DecorationSize getLineHeadWidth(){
AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINESTARTARROWWIDTH);
return (prop == null) ? null : DecorationSize.fromNativeId(prop.getPropertyValue());
}
public void setLineHeadWidth(DecorationSize decoSize){
AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINESTARTARROWWIDTH, decoSize == null ? -1 : decoSize.nativeId);
}
public DecorationSize getLineHeadLength(){
AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINESTARTARROWLENGTH);
return (prop == null) ? null : DecorationSize.fromNativeId(prop.getPropertyValue());
}
public void setLineHeadLength(DecorationSize decoSize){
AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINESTARTARROWLENGTH, decoSize == null ? -1 : decoSize.nativeId);
}
public DecorationShape getLineTailDecoration(){
AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINEENDARROWHEAD);
return (prop == null) ? null : DecorationShape.fromNativeId(prop.getPropertyValue());
}
public void setLineTailDecoration(DecorationShape decoShape){
AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINEENDARROWHEAD, decoShape == null ? -1 : decoShape.nativeId);
}
public DecorationSize getLineTailWidth(){
AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINEENDARROWWIDTH);
return (prop == null) ? null : DecorationSize.fromNativeId(prop.getPropertyValue());
}
public void setLineTailWidth(DecorationSize decoSize){
AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINEENDARROWWIDTH, decoSize == null ? -1 : decoSize.nativeId);
}
public DecorationSize getLineTailLength(){
AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINEENDARROWLENGTH);
return (prop == null) ? null : DecorationSize.fromNativeId(prop.getPropertyValue());
}
public void setLineTailLength(DecorationSize decoSize){
AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, EscherPropertyTypes.LINESTYLE__LINEENDARROWLENGTH, decoSize == null ? -1 : decoSize.nativeId);
}
@Override
public LineDecoration getLineDecoration() {
return new LineDecoration() {
@Override
public DecorationShape getHeadShape() {
return HSLFSimpleShape.this.getLineHeadDecoration();
}
@Override
public DecorationSize getHeadWidth() {
return HSLFSimpleShape.this.getLineHeadWidth();
}
@Override
public DecorationSize getHeadLength() {
return HSLFSimpleShape.this.getLineHeadLength();
}
@Override
public DecorationShape getTailShape() {
return HSLFSimpleShape.this.getLineTailDecoration();
}
@Override
public DecorationSize getTailWidth() {
return HSLFSimpleShape.this.getLineTailWidth();
}
@Override
public DecorationSize getTailLength() {
return HSLFSimpleShape.this.getLineTailLength();
}
};
}
@Override
public HSLFShapePlaceholderDetails getPlaceholderDetails() {
if (_placeholderDetails == null) {
_placeholderDetails = new HSLFShapePlaceholderDetails(this);
}
return _placeholderDetails;
}
@Override
public Placeholder getPlaceholder() {
return getPlaceholderDetails().getPlaceholder();
}
@Override
public void setPlaceholder(Placeholder placeholder) {
// reset the placeholder details so that the next call to getPlaceholderDetails() will reinitialize it
_placeholderDetails = null;
updateSPRecord(this, placeholder);
if (placeholder == null) {
removePlaceholder(this);
return;
}
HSLFEscherClientDataRecord clientData = getClientData(true);
// OEPlaceholderAtom tells powerpoint that this shape is a placeholder
OEPlaceholderAtom oep = null;
RoundTripHFPlaceholder12 rtp = null;
for (org.apache.poi.hslf.record.Record r : clientData.getHSLFChildRecords()) {
if (r instanceof OEPlaceholderAtom) {
oep = (OEPlaceholderAtom) r;
break;
}
if (r instanceof RoundTripHFPlaceholder12) {
rtp = (RoundTripHFPlaceholder12) r;
break;
}
}
/**
* Extract from MSDN:
*
* There is a special case when the placeholder does not have a position in the layout.
* This occurs when the user has moved the placeholder from its original position.
* In this case the placeholder ID is -1.
*/
final byte phId = getPlaceholderId(getSheet(), placeholder);
switch (placeholder) {
case HEADER:
case FOOTER:
if (rtp == null) {
rtp = new RoundTripHFPlaceholder12();
rtp.setPlaceholderId(phId);
clientData.addChild(rtp);
}
if (oep != null) {
clientData.removeChild(OEPlaceholderAtom.class);
}
break;
default:
if (rtp != null) {
clientData.removeChild(RoundTripHFPlaceholder12.class);
}
if (oep == null) {
oep = createOEPlaceholderAtom(clientData, phId);
}
break;
}
}
@Override
public void setStrokeStyle(Object... styles) {
if (styles.length == 0) {
// remove stroke
setLineColor(null);
return;
}
// TODO: handle PaintStyle
for (Object st : styles) {
if (st instanceof Number) {
setLineWidth(((Number)st).doubleValue());
} else if (st instanceof LineCap) {
setLineCap((LineCap)st);
} else if (st instanceof LineDash) {
setLineDash((LineDash)st);
} else if (st instanceof LineCompound) {
setLineCompound((LineCompound)st);
} else if (st instanceof Color) {
setLineColor((Color)st);
}
}
}
@Override
public HSLFHyperlink getHyperlink(){
return _hyperlink;
}
@Override
public HSLFHyperlink createHyperlink() {
if (_hyperlink == null) {
_hyperlink = HSLFHyperlink.createHyperlink(this);
}
return _hyperlink;
}
/**
* Sets the hyperlink - used when the document is parsed
*
* @param link the hyperlink
*/
protected void setHyperlink(HSLFHyperlink link) {
_hyperlink = link;
}
@Override
public boolean isPlaceholder() {
// currently we only identify TextShapes as placeholders
return false;
}
}
|