PageRenderTime 101ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/openmicroscopy/bioformats
Java | 191 lines | 100 code | 23 blank | 68 comment | 0 complexity | caf9b32bdd1d6052248a6d5f8cf5c345 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 an textbox shape and converts between the highlevel records
  43. * and lowlevel records for an oval.
  44. *
  45. * @author Glen Stampoultzis (glens at apache.org)
  46. */
  47. public class TextboxShape
  48. extends AbstractShape
  49. {
  50. private EscherContainerRecord spContainer;
  51. private TextObjectRecord textObjectRecord;
  52. private ObjRecord objRecord;
  53. private EscherTextboxRecord escherTextbox;
  54. /**
  55. * Creates the low evel records for an textbox.
  56. *
  57. * @param hssfShape The highlevel shape.
  58. * @param shapeId The shape id to use for this shape.
  59. */
  60. TextboxShape( HSSFTextbox hssfShape, int shapeId )
  61. {
  62. spContainer = createSpContainer( hssfShape, shapeId );
  63. objRecord = createObjRecord( hssfShape, shapeId );
  64. textObjectRecord = createTextObjectRecord( hssfShape, shapeId );
  65. }
  66. /**
  67. * Creates the low level OBJ record for this shape.
  68. */
  69. private ObjRecord createObjRecord( HSSFTextbox hssfShape, int shapeId )
  70. {
  71. HSSFShape shape = hssfShape;
  72. ObjRecord obj = new ObjRecord();
  73. CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
  74. c.setObjectType( (short) ( (HSSFSimpleShape) shape ).getShapeType() );
  75. c.setObjectId( (short) ( shapeId ) );
  76. c.setLocked( true );
  77. c.setPrintable( true );
  78. c.setAutofill( true );
  79. c.setAutoline( true );
  80. EndSubRecord e = new EndSubRecord();
  81. obj.addSubRecord( c );
  82. obj.addSubRecord( e );
  83. return obj;
  84. }
  85. /**
  86. * Generates the escher shape records for this shape.
  87. *
  88. * @param hssfShape
  89. * @param shapeId
  90. */
  91. private EscherContainerRecord createSpContainer( HSSFTextbox hssfShape, int shapeId )
  92. {
  93. HSSFTextbox shape = hssfShape;
  94. EscherContainerRecord spContainer = new EscherContainerRecord();
  95. EscherSpRecord sp = new EscherSpRecord();
  96. EscherOptRecord opt = new EscherOptRecord();
  97. EscherRecord anchor = new EscherClientAnchorRecord();
  98. EscherClientDataRecord clientData = new EscherClientDataRecord();
  99. escherTextbox = new EscherTextboxRecord();
  100. spContainer.setRecordId( EscherContainerRecord.SP_CONTAINER );
  101. spContainer.setOptions( (short) 0x000F );
  102. sp.setRecordId( EscherSpRecord.RECORD_ID );
  103. sp.setOptions( (short) ( ( EscherAggregate.ST_TEXTBOX << 4 ) | 0x2 ) );
  104. sp.setShapeId( shapeId );
  105. sp.setFlags( EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE );
  106. opt.setRecordId( EscherOptRecord.RECORD_ID );
  107. // opt.addEscherProperty( new EscherBoolProperty( EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 262144 ) );
  108. opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.TEXT__TEXTID, 0 ) );
  109. opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.TEXT__TEXTLEFT, shape.getMarginLeft() ) );
  110. opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.TEXT__TEXTRIGHT, shape.getMarginRight() ) );
  111. opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.TEXT__TEXTBOTTOM, shape.getMarginBottom() ) );
  112. opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.TEXT__TEXTTOP, shape.getMarginTop() ) );
  113. addStandardOptions( shape, opt );
  114. HSSFAnchor userAnchor = shape.getAnchor();
  115. // if (userAnchor.isHorizontallyFlipped())
  116. // sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ);
  117. // if (userAnchor.isVerticallyFlipped())
  118. // sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPVERT);
  119. anchor = createAnchor( userAnchor );
  120. clientData.setRecordId( EscherClientDataRecord.RECORD_ID );
  121. clientData.setOptions( (short) 0x0000 );
  122. escherTextbox.setRecordId( EscherTextboxRecord.RECORD_ID );
  123. escherTextbox.setOptions( (short) 0x0000 );
  124. spContainer.addChildRecord( sp );
  125. spContainer.addChildRecord( opt );
  126. spContainer.addChildRecord( anchor );
  127. spContainer.addChildRecord( clientData );
  128. spContainer.addChildRecord( escherTextbox );
  129. return spContainer;
  130. }
  131. /**
  132. * Textboxes also have an extra TXO record associated with them that most
  133. * other shapes dont have.
  134. */
  135. private TextObjectRecord createTextObjectRecord( HSSFTextbox hssfShape, int shapeId )
  136. {
  137. HSSFTextbox shape = hssfShape;
  138. TextObjectRecord obj = new TextObjectRecord();
  139. obj.setHorizontalTextAlignment( TextObjectRecord.HORIZONTAL_TEXT_ALIGNMENT_LEFT_ALIGNED );
  140. obj.setVerticalTextAlignment( TextObjectRecord.VERTICAL_TEXT_ALIGNMENT_TOP );
  141. obj.setTextLocked( true );
  142. obj.setTextOrientation( TextObjectRecord.TEXT_ORIENTATION_NONE );
  143. int frLength = ( shape.getString().numFormattingRuns() + 1 ) * 8;
  144. obj.setFormattingRunLength( (short) frLength );
  145. obj.setTextLength( (short) shape.getString().length() );
  146. obj.setStr( shape.getString() );
  147. obj.setReserved7( 0 );
  148. return obj;
  149. }
  150. public EscherContainerRecord getSpContainer()
  151. {
  152. return spContainer;
  153. }
  154. public ObjRecord getObjRecord()
  155. {
  156. return objRecord;
  157. }
  158. public TextObjectRecord getTextObjectRecord()
  159. {
  160. return textObjectRecord;
  161. }
  162. public EscherRecord getEscherTextbox()
  163. {
  164. return escherTextbox;
  165. }
  166. }