PageRenderTime 282ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/components/forks/poi/src/loci/poi/hssf/model/PictureShape.java

http://github.com/openmicroscopy/bioformats
Java | 154 lines | 71 code | 18 blank | 65 comment | 2 complexity | 3fac04b2d420f2a566cce5b6a652e8c5 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, BSD-2-Clause, MPL-2.0-no-copyleft-exception
  1. /*
  2. * #%L
  3. * Fork of Apache Jakarta POI.
  4. * %%
  5. * Copyright (C) 2008 - 2013 Open Microscopy Environment:
  6. * - Board of Regents of the University of Wisconsin-Madison
  7. * - Glencoe Software, Inc.
  8. * - University of Dundee
  9. * %%
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. * #L%
  22. */
  23. /* ====================================================================
  24. Licensed to the Apache Software Foundation (ASF) under one or more
  25. contributor license agreements. See the NOTICE file distributed with
  26. this work for additional information regarding copyright ownership.
  27. The ASF licenses this file to You under the Apache License, Version 2.0
  28. (the "License"); you may not use this file except in compliance with
  29. the License. You may obtain a copy of the License at
  30. http://www.apache.org/licenses/LICENSE-2.0
  31. Unless required by applicable law or agreed to in writing, software
  32. distributed under the License is distributed on an "AS IS" BASIS,
  33. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  34. See the License for the specific language governing permissions and
  35. limitations under the License.
  36. ==================================================================== */
  37. package loci.poi.hssf.model;
  38. import loci.poi.ddf.*;
  39. import loci.poi.hssf.record.*;
  40. import loci.poi.hssf.usermodel.*;
  41. /**
  42. * Represents a picture shape and creates all specific low level records.
  43. *
  44. * @author Glen Stampoultzis (glens at apache.org)
  45. */
  46. public class PictureShape
  47. extends AbstractShape
  48. {
  49. private EscherContainerRecord spContainer;
  50. private ObjRecord objRecord;
  51. /**
  52. * Creates the line shape from the highlevel user shape. All low level
  53. * records are created at this point.
  54. *
  55. * @param hssfShape The user model shape.
  56. * @param shapeId The identifier to use for this shape.
  57. */
  58. PictureShape( HSSFSimpleShape hssfShape, int shapeId )
  59. {
  60. spContainer = createSpContainer(hssfShape, shapeId);
  61. objRecord = createObjRecord(hssfShape, shapeId);
  62. }
  63. /**
  64. * Creates the lowerlevel escher records for this shape.
  65. */
  66. private EscherContainerRecord createSpContainer(HSSFSimpleShape hssfShape, int shapeId)
  67. {
  68. HSSFPicture shape = (HSSFPicture) hssfShape;
  69. EscherContainerRecord spContainer = new EscherContainerRecord();
  70. EscherSpRecord sp = new EscherSpRecord();
  71. EscherOptRecord opt = new EscherOptRecord();
  72. EscherRecord anchor;
  73. EscherClientDataRecord clientData = new EscherClientDataRecord();
  74. spContainer.setRecordId( EscherContainerRecord.SP_CONTAINER );
  75. spContainer.setOptions( (short) 0x000F );
  76. sp.setRecordId( EscherSpRecord.RECORD_ID );
  77. sp.setOptions( (short) ( (EscherAggregate.ST_PICTUREFRAME << 4) | 0x2 ) );
  78. sp.setShapeId( shapeId );
  79. sp.setFlags( EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE );
  80. opt.setRecordId( EscherOptRecord.RECORD_ID );
  81. // opt.addEscherProperty( new EscherBoolProperty( EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x00800080 ) );
  82. opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.BLIP__BLIPTODISPLAY, false, true, shape.getPictureIndex() ) );
  83. // opt.addEscherProperty( new EscherComplexProperty( EscherProperties.BLIP__BLIPFILENAME, true, new byte[] { (byte)0x74, (byte)0x00, (byte)0x65, (byte)0x00, (byte)0x73, (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x00, (byte)0x00 } ) );
  84. // opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.FILL__FILLTYPE, 0x00000003 ) );
  85. addStandardOptions(shape, opt);
  86. HSSFAnchor userAnchor = shape.getAnchor();
  87. if (userAnchor.isHorizontallyFlipped())
  88. sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ);
  89. if (userAnchor.isVerticallyFlipped())
  90. sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPVERT);
  91. anchor = createAnchor(userAnchor);
  92. clientData.setRecordId( EscherClientDataRecord.RECORD_ID );
  93. clientData.setOptions( (short) 0x0000 );
  94. spContainer.addChildRecord(sp);
  95. spContainer.addChildRecord(opt);
  96. spContainer.addChildRecord(anchor);
  97. spContainer.addChildRecord(clientData);
  98. return spContainer;
  99. }
  100. /**
  101. * Creates the low level OBJ record for this shape.
  102. */
  103. private ObjRecord createObjRecord(HSSFShape hssfShape, int shapeId)
  104. {
  105. HSSFShape shape = hssfShape;
  106. ObjRecord obj = new ObjRecord();
  107. CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
  108. c.setObjectType((short) ((HSSFSimpleShape)shape).getShapeType());
  109. // c.setObjectId((short) ( 1 ));
  110. c.setObjectId((short) ( shapeId ));
  111. c.setLocked(true);
  112. c.setPrintable(true);
  113. c.setAutofill(true);
  114. c.setAutoline(true);
  115. // c.setReserved2( 0x012C0A84 );
  116. c.setReserved2( 0x0 );
  117. // UnknownRecord sub1 = new UnknownRecord( (short)0x7, (short)0x2, new byte[] { 0x09, 0x00 } );
  118. // UnknownRecord sub2 = new UnknownRecord( (short)0x8, (short)0x2, new byte[] { 0x01, 0x00 } );
  119. EndSubRecord e = new EndSubRecord();
  120. obj.addSubRecord(c);
  121. // obj.addSubRecord( sub1 );
  122. // obj.addSubRecord( sub2 );
  123. obj.addSubRecord(e);
  124. return obj;
  125. }
  126. public EscherContainerRecord getSpContainer()
  127. {
  128. return spContainer;
  129. }
  130. public ObjRecord getObjRecord()
  131. {
  132. return objRecord;
  133. }
  134. }