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.

EscherChildAnchorRecord.java 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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.ddf;
  16. import org.apache.poi.util.HexDump;
  17. import org.apache.poi.util.LittleEndian;
  18. /**
  19. * The escher child achor record is used to specify the position of a shape under an
  20. * existing group. The first level of shape records use a EscherClientAnchor record instead.
  21. *
  22. * @author Glen Stampoultzis
  23. * @see EscherChildAnchorRecord
  24. */
  25. public class EscherChildAnchorRecord
  26. extends EscherRecord
  27. {
  28. public static final short RECORD_ID = (short) 0xF00F;
  29. public static final String RECORD_DESCRIPTION = "MsofbtChildAnchor";
  30. private int field_1_dx1;
  31. private int field_2_dy1;
  32. private int field_3_dx2;
  33. private int field_4_dy2;
  34. public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
  35. int bytesRemaining = readHeader( data, offset );
  36. int pos = offset + 8;
  37. int size = 0;
  38. switch (bytesRemaining) {
  39. case 16: // RectStruct
  40. field_1_dx1 = LittleEndian.getInt( data, pos + size );size+=4;
  41. field_2_dy1 = LittleEndian.getInt( data, pos + size );size+=4;
  42. field_3_dx2 = LittleEndian.getInt( data, pos + size );size+=4;
  43. field_4_dy2 = LittleEndian.getInt( data, pos + size );size+=4;
  44. break;
  45. case 8: // SmallRectStruct
  46. field_1_dx1 = LittleEndian.getShort( data, pos + size );size+=2;
  47. field_2_dy1 = LittleEndian.getShort( data, pos + size );size+=2;
  48. field_3_dx2 = LittleEndian.getShort( data, pos + size );size+=2;
  49. field_4_dy2 = LittleEndian.getShort( data, pos + size );size+=2;
  50. break;
  51. default:
  52. throw new RuntimeException("Invalid EscherChildAnchorRecord - neither 8 nor 16 bytes.");
  53. }
  54. return 8 + size;
  55. }
  56. public int serialize(int offset, byte[] data, EscherSerializationListener listener) {
  57. listener.beforeRecordSerialize( offset, getRecordId(), this );
  58. int pos = offset;
  59. LittleEndian.putShort( data, pos, getOptions() ); pos += 2;
  60. LittleEndian.putShort( data, pos, getRecordId() ); pos += 2;
  61. LittleEndian.putInt( data, pos, getRecordSize()-8 ); pos += 4;
  62. LittleEndian.putInt( data, pos, field_1_dx1 ); pos += 4;
  63. LittleEndian.putInt( data, pos, field_2_dy1 ); pos += 4;
  64. LittleEndian.putInt( data, pos, field_3_dx2 ); pos += 4;
  65. LittleEndian.putInt( data, pos, field_4_dy2 ); pos += 4;
  66. listener.afterRecordSerialize( pos, getRecordId(), pos - offset, this );
  67. return pos - offset;
  68. }
  69. public int getRecordSize()
  70. {
  71. return 8 + 4 * 4;
  72. }
  73. public short getRecordId() {
  74. return RECORD_ID;
  75. }
  76. public String getRecordName() {
  77. return "ChildAnchor";
  78. }
  79. /**
  80. * The string representation of this record
  81. */
  82. public String toString()
  83. {
  84. String nl = System.getProperty("line.separator");
  85. return getClass().getName() + ":" + nl +
  86. " RecordId: 0x" + HexDump.toHex(RECORD_ID) + nl +
  87. " Version: 0x" + HexDump.toHex(getVersion()) + nl +
  88. " Instance: 0x" + HexDump.toHex(getInstance()) + nl +
  89. " X1: " + field_1_dx1 + nl +
  90. " Y1: " + field_2_dy1 + nl +
  91. " X2: " + field_3_dx2 + nl +
  92. " Y2: " + field_4_dy2 + nl ;
  93. }
  94. @Override
  95. public String toXml(String tab) {
  96. StringBuilder builder = new StringBuilder();
  97. builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
  98. .append(tab).append("\t").append("<X1>").append(field_1_dx1).append("</X1>\n")
  99. .append(tab).append("\t").append("<Y1>").append(field_2_dy1).append("</Y1>\n")
  100. .append(tab).append("\t").append("<X2>").append(field_3_dx2).append("</X2>\n")
  101. .append(tab).append("\t").append("<Y2>").append(field_4_dy2).append("</Y2>\n");
  102. builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
  103. return builder.toString();
  104. }
  105. /**
  106. * Retrieves offset within the parent coordinate space for the top left point.
  107. */
  108. public int getDx1()
  109. {
  110. return field_1_dx1;
  111. }
  112. /**
  113. * Sets offset within the parent coordinate space for the top left point.
  114. */
  115. public void setDx1( int field_1_dx1 )
  116. {
  117. this.field_1_dx1 = field_1_dx1;
  118. }
  119. /**
  120. * Gets offset within the parent coordinate space for the top left point.
  121. */
  122. public int getDy1()
  123. {
  124. return field_2_dy1;
  125. }
  126. /**
  127. * Sets offset within the parent coordinate space for the top left point.
  128. */
  129. public void setDy1( int field_2_dy1 )
  130. {
  131. this.field_2_dy1 = field_2_dy1;
  132. }
  133. /**
  134. * Retrieves offset within the parent coordinate space for the bottom right point.
  135. */
  136. public int getDx2()
  137. {
  138. return field_3_dx2;
  139. }
  140. /**
  141. * Sets offset within the parent coordinate space for the bottom right point.
  142. */
  143. public void setDx2( int field_3_dx2 )
  144. {
  145. this.field_3_dx2 = field_3_dx2;
  146. }
  147. /**
  148. * Gets the offset within the parent coordinate space for the bottom right point.
  149. */
  150. public int getDy2()
  151. {
  152. return field_4_dy2;
  153. }
  154. /**
  155. * Sets the offset within the parent coordinate space for the bottom right point.
  156. */
  157. public void setDy2( int field_4_dy2 )
  158. {
  159. this.field_4_dy2 = field_4_dy2;
  160. }
  161. }