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.

EscherPlaceholder.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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.hslf.record;
  16. import java.util.Map;
  17. import java.util.function.Supplier;
  18. import org.apache.logging.log4j.LogManager;
  19. import org.apache.logging.log4j.Logger;
  20. import org.apache.poi.ddf.EscherRecord;
  21. import org.apache.poi.ddf.EscherRecordFactory;
  22. import org.apache.poi.ddf.EscherSerializationListener;
  23. import org.apache.poi.util.GenericRecordUtil;
  24. import org.apache.poi.util.LittleEndian;
  25. /**
  26. * An atom record that specifies whether a shape is a placeholder shape.
  27. * The number, position, and type of placeholder shapes are determined by
  28. * the slide layout as specified in the SlideAtom record.
  29. */
  30. public class EscherPlaceholder extends EscherRecord {
  31. private static final Logger LOG = LogManager.getLogger(EscherPlaceholder.class);
  32. public static final short RECORD_ID = RecordTypes.OEPlaceholderAtom.typeID;
  33. public static final String RECORD_DESCRIPTION = "msofbtClientTextboxPlaceholder";
  34. private int position = -1;
  35. private byte placementId;
  36. private byte size;
  37. private short unused;
  38. public EscherPlaceholder() {}
  39. public EscherPlaceholder(EscherPlaceholder other) {
  40. super(other);
  41. position = other.position;
  42. placementId = other.placementId;
  43. size = other.size;
  44. unused = other.unused;
  45. }
  46. @Override
  47. public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
  48. int bytesRemaining = readHeader( data, offset );
  49. position = LittleEndian.getInt(data, offset+8);
  50. placementId = data[offset+12];
  51. size = data[offset+13];
  52. unused = LittleEndian.getShort(data, offset+14);
  53. if (bytesRemaining + 8 != 16) {
  54. LOG.warn("Invalid header-data received, should have 8 bytes left, but had: {}", bytesRemaining);
  55. }
  56. return bytesRemaining + 8;
  57. }
  58. @Override
  59. public int serialize(int offset, byte[] data, EscherSerializationListener listener) {
  60. listener.beforeRecordSerialize( offset, getRecordId(), this );
  61. LittleEndian.putShort(data, offset, getOptions());
  62. LittleEndian.putShort(data, offset+2, getRecordId());
  63. LittleEndian.putInt(data, offset+4, 8);
  64. LittleEndian.putInt(data, offset+8, position);
  65. LittleEndian.putByte(data, offset+12, placementId);
  66. LittleEndian.putByte(data, offset+13, size);
  67. LittleEndian.putShort(data, offset+14, unused);
  68. listener.afterRecordSerialize( offset+getRecordSize(), getRecordId(), getRecordSize(), this );
  69. return getRecordSize();
  70. }
  71. @Override
  72. public int getRecordSize() {
  73. return 8 + 8;
  74. }
  75. @Override
  76. public String getRecordName() {
  77. return "ClientTextboxPlaceholder";
  78. }
  79. public int getPosition() {
  80. return position;
  81. }
  82. public byte getPlacementId() {
  83. return placementId;
  84. }
  85. public byte getSize() {
  86. return size;
  87. }
  88. @Override
  89. public Map<String, Supplier<?>> getGenericProperties() {
  90. return GenericRecordUtil.getGenericProperties(
  91. "base", super::getGenericProperties,
  92. "position", this::getPosition,
  93. "placementId", this::getPlacementId,
  94. "size", this::getSize
  95. );
  96. }
  97. @Override
  98. public Enum getGenericRecordType() {
  99. return RecordTypes.OEPlaceholderAtom;
  100. }
  101. @Override
  102. public EscherPlaceholder copy() {
  103. return new EscherPlaceholder(this);
  104. }
  105. }