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.

SimpleFilledShape.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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.hssf.model;
  16. import org.apache.poi.ddf.*;
  17. import org.apache.poi.hssf.record.ObjRecord;
  18. import org.apache.poi.hssf.record.EscherAggregate;
  19. import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
  20. import org.apache.poi.hssf.record.EndSubRecord;
  21. import org.apache.poi.hssf.usermodel.HSSFSimpleShape;
  22. import org.apache.poi.hssf.usermodel.HSSFShape;
  23. @Deprecated
  24. public class SimpleFilledShape
  25. extends AbstractShape
  26. {
  27. private EscherContainerRecord spContainer;
  28. private ObjRecord objRecord;
  29. /**
  30. * Creates the low evel records for an oval.
  31. *
  32. * @param hssfShape The highlevel shape.
  33. * @param shapeId The shape id to use for this shape.
  34. */
  35. SimpleFilledShape( HSSFSimpleShape hssfShape, int shapeId )
  36. {
  37. spContainer = createSpContainer( hssfShape, shapeId );
  38. objRecord = createObjRecord( hssfShape, shapeId );
  39. }
  40. /**
  41. * Generates the shape records for this shape.
  42. *
  43. * @param hssfShape
  44. * @param shapeId
  45. */
  46. private EscherContainerRecord createSpContainer( HSSFSimpleShape hssfShape, int shapeId )
  47. {
  48. HSSFShape shape = hssfShape;
  49. EscherContainerRecord spContainer = new EscherContainerRecord();
  50. EscherSpRecord sp = new EscherSpRecord();
  51. EscherOptRecord opt = new EscherOptRecord();
  52. EscherClientDataRecord clientData = new EscherClientDataRecord();
  53. spContainer.setRecordId( EscherContainerRecord.SP_CONTAINER );
  54. spContainer.setOptions( (short) 0x000F );
  55. sp.setRecordId( EscherSpRecord.RECORD_ID );
  56. short shapeType = objTypeToShapeType( hssfShape.getShapeType() );
  57. sp.setOptions( (short) ( ( shapeType << 4 ) | 0x2 ) );
  58. sp.setShapeId( shapeId );
  59. sp.setFlags( EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE );
  60. opt.setRecordId( EscherOptRecord.RECORD_ID );
  61. addStandardOptions(shape, opt);
  62. EscherRecord anchor = createAnchor( shape.getAnchor() );
  63. clientData.setRecordId( EscherClientDataRecord.RECORD_ID );
  64. clientData.setOptions( (short) 0x0000 );
  65. spContainer.addChildRecord( sp );
  66. spContainer.addChildRecord( opt );
  67. spContainer.addChildRecord( anchor );
  68. spContainer.addChildRecord( clientData );
  69. return spContainer;
  70. }
  71. private short objTypeToShapeType( int objType )
  72. {
  73. short shapeType;
  74. if (objType == HSSFSimpleShape.OBJECT_TYPE_OVAL)
  75. shapeType = EscherAggregate.ST_ELLIPSE;
  76. else if (objType == HSSFSimpleShape.OBJECT_TYPE_RECTANGLE)
  77. shapeType = EscherAggregate.ST_RECTANGLE;
  78. else
  79. throw new IllegalArgumentException("Unable to handle an object of this type");
  80. return shapeType;
  81. }
  82. /**
  83. * Creates the low level OBJ record for this shape.
  84. */
  85. private ObjRecord createObjRecord( HSSFShape hssfShape, int shapeId )
  86. {
  87. HSSFShape shape = hssfShape;
  88. ObjRecord obj = new ObjRecord();
  89. CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
  90. c.setObjectType( (short) ( (HSSFSimpleShape) shape ).getShapeType() );
  91. c.setObjectId( getCmoObjectId(shapeId) );
  92. c.setLocked( true );
  93. c.setPrintable( true );
  94. c.setAutofill( true );
  95. c.setAutoline( true );
  96. EndSubRecord e = new EndSubRecord();
  97. obj.addSubRecord( c );
  98. obj.addSubRecord( e );
  99. return obj;
  100. }
  101. public EscherContainerRecord getSpContainer()
  102. {
  103. return spContainer;
  104. }
  105. public ObjRecord getObjRecord()
  106. {
  107. return objRecord;
  108. }
  109. }