您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

FtPioGrbitSubRecord.java 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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.record;
  16. import static org.apache.poi.util.GenericRecordUtil.getBitsAsString;
  17. import java.util.Map;
  18. import java.util.function.Supplier;
  19. import org.apache.poi.util.GenericRecordUtil;
  20. import org.apache.poi.util.LittleEndianInput;
  21. import org.apache.poi.util.LittleEndianOutput;
  22. import org.apache.poi.util.RecordFormatException;
  23. /**
  24. * This structure appears as part of an Obj record that represents image display properties.
  25. */
  26. public final class FtPioGrbitSubRecord extends SubRecord {
  27. public static final short sid = 0x08;
  28. public static final short length = 0x02;
  29. /**
  30. * A bit that specifies whether the picture's aspect ratio is preserved when rendered in
  31. * different views (Normal view, Page Break Preview view, Page Layout view and printing).
  32. */
  33. public static final int AUTO_PICT_BIT = 1 << 0;
  34. /**
  35. * A bit that specifies whether the pictFmla field of the Obj record that contains
  36. * this FtPioGrbit specifies a DDE reference.
  37. */
  38. public static final int DDE_BIT = 1 << 1;
  39. /**
  40. * A bit that specifies whether this object is expected to be updated on print to
  41. * reflect the values in the cell associated with the object.
  42. */
  43. public static final int PRINT_CALC_BIT = 1 << 2;
  44. /**
  45. * A bit that specifies whether the picture is displayed as an icon.
  46. */
  47. public static final int ICON_BIT = 1 << 3;
  48. /**
  49. * A bit that specifies whether this object is an ActiveX control.
  50. * It MUST NOT be the case that both fCtl and fDde are equal to 1.
  51. */
  52. public static final int CTL_BIT = 1 << 4;
  53. /**
  54. * A bit that specifies whether the object data are stored in an
  55. * embedding storage (= 0) or in the controls stream (ctls) (= 1).
  56. */
  57. public static final int PRSTM_BIT = 1 << 5;
  58. /**
  59. * A bit that specifies whether this is a camera picture.
  60. */
  61. public static final int CAMERA_BIT = 1 << 7;
  62. /**
  63. * A bit that specifies whether this picture's size has been explicitly set.
  64. * 0 = picture size has been explicitly set, 1 = has not been set
  65. */
  66. public static final int DEFAULT_SIZE_BIT = 1 << 8;
  67. /**
  68. * A bit that specifies whether the OLE server for the object is called
  69. * to load the object's data automatically when the parent workbook is opened.
  70. */
  71. public static final int AUTO_LOAD_BIT = 1 << 9;
  72. private short flags;
  73. /**
  74. * Construct a new <code>FtPioGrbitSubRecord</code> and
  75. * fill its data with the default values
  76. */
  77. public FtPioGrbitSubRecord() {}
  78. public FtPioGrbitSubRecord(FtPioGrbitSubRecord other) {
  79. super(other);
  80. flags = other.flags;
  81. }
  82. public FtPioGrbitSubRecord(LittleEndianInput in, int size) {
  83. this(in,size,-1);
  84. }
  85. FtPioGrbitSubRecord(LittleEndianInput in, int size, int cmoOt) {
  86. if (size != length) {
  87. throw new RecordFormatException("Unexpected size (" + size + ")");
  88. }
  89. flags = in.readShort();
  90. }
  91. /**
  92. * Use one of the bitmasks MANUAL_ADVANCE_BIT ... CURSOR_VISIBLE_BIT
  93. * @param bitmask the bitmask to apply
  94. * @param enabled if true, the bitmask will be or-ed, otherwise the bits set in the mask will be removed from the flags
  95. */
  96. public void setFlagByBit(int bitmask, boolean enabled) {
  97. if (enabled) {
  98. flags |= bitmask;
  99. } else {
  100. flags &= (0xFFFF ^ bitmask);
  101. }
  102. }
  103. public boolean getFlagByBit(int bitmask) {
  104. return ((flags & bitmask) != 0);
  105. }
  106. /**
  107. * Serialize the record data into the supplied array of bytes
  108. *
  109. * @param out the stream to serialize into
  110. */
  111. public void serialize(LittleEndianOutput out) {
  112. out.writeShort(sid);
  113. out.writeShort(length);
  114. out.writeShort(flags);
  115. }
  116. protected int getDataSize() {
  117. return length;
  118. }
  119. /**
  120. * @return id of this record.
  121. */
  122. public short getSid()
  123. {
  124. return sid;
  125. }
  126. @Override
  127. public FtPioGrbitSubRecord copy() {
  128. return new FtPioGrbitSubRecord(this);
  129. }
  130. public short getFlags() {
  131. return flags;
  132. }
  133. public void setFlags(short flags) {
  134. this.flags = flags;
  135. }
  136. @Override
  137. public SubRecordTypes getGenericRecordType() {
  138. return SubRecordTypes.FT_PIO_GRBIT;
  139. }
  140. @Override
  141. public Map<String, Supplier<?>> getGenericProperties() {
  142. return GenericRecordUtil.getGenericProperties(
  143. "flags", getBitsAsString(this::getFlags,
  144. new int[]{AUTO_PICT_BIT, DDE_BIT, PRINT_CALC_BIT, ICON_BIT, CTL_BIT, PRSTM_BIT, CAMERA_BIT, DEFAULT_SIZE_BIT, AUTO_LOAD_BIT},
  145. new String[]{"AUTO_PICT", "DDE", "PRINT_CALC", "ICON", "CTL", "PRSTM", "CAMERA", "DEFAULT_SIZE", "AUTO_LOAD"})
  146. );
  147. }
  148. }