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.

SlideAtomLayout.java 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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.io.IOException;
  17. import java.io.OutputStream;
  18. import java.util.Arrays;
  19. import java.util.Map;
  20. import java.util.function.Supplier;
  21. import org.apache.poi.common.usermodel.GenericRecord;
  22. import org.apache.poi.hslf.exceptions.HSLFException;
  23. import org.apache.poi.util.GenericRecordUtil;
  24. import org.apache.poi.util.Internal;
  25. import org.apache.poi.util.LittleEndian;
  26. /**
  27. * Holds the geometry of the Slide, and the ID of the placeholders on the slide.
  28. * Embedded inside a SlideAtom is a SlideAtomLayout, without the usual record header.
  29. * Since it's a fixed size and tied to the SlideAtom, we'll hold it here.<p>
  30. *
  31. * This might eventually merged with the XSLF counterpart
  32. */
  33. @Internal
  34. public class SlideAtomLayout implements GenericRecord {
  35. // The different kinds of geometry
  36. public enum SlideLayoutType {
  37. /** One title and one subtitle placeholder shapes. */
  38. TITLE_SLIDE(0x0000),
  39. /** Presentation slide or main master slide layout with one title and one body placeholder shape. */
  40. TITLE_BODY(0x0001),
  41. /** Title master slide layout with one title and one subtitle placeholder shape. */
  42. MASTER_TITLE(0x0002),
  43. /** ??? (not documented in spec) */
  44. MASTER_SLIDE(0x0003),
  45. /** ??? (not documented in spec) */
  46. MASTER_NOTES(0x0004),
  47. /** ??? (not documented in spec) */
  48. NOTES_TITLE_BODY(0x0005),
  49. /** Only header, footer and date placeholders */
  50. HANDOUT(0x0006),
  51. /** Presentation slide layout with one title placeholder shape. */
  52. TITLE_ONLY(0x0007),
  53. /** Presentation slide layout with one title and two body placeholder shapes stacked horizontally. */
  54. TWO_COLUMNS(0x0008),
  55. /** Presentation slide layout with one title and two body placeholder shapes stacked vertically. */
  56. TWO_ROWS(0x0009),
  57. /** Presentation slide layout with one title and three body placeholder shapes split into two columns. The right column has two rows. */
  58. COLUMN_TWO_ROWS(0x000A),
  59. /** Presentation slide layout with one title and three body placeholder shapes split into two columns. The left column has two rows. */
  60. TWO_ROWS_COLUMN(0x000B),
  61. /** ??? (not documented in spec) */
  62. TITLE_2_ROW_BOTTOM_2_COLUMN_BODY(0x000C),
  63. /** Presentation slide layout with one title and three body placeholder shapes split into two rows. The top row has two columns. */
  64. TWO_COLUMNS_ROW(0x000D),
  65. /** Presentation slide layout with one title and four body placeholder shapes. */
  66. FOUR_OBJECTS(0x000E),
  67. /** Presentation slide layout with one body placeholder shape. */
  68. BIG_OBJECT(0x000F),
  69. /** Presentation slide layout with no placeholder shape. */
  70. BLANK_SLIDE(0x0010),
  71. /** Presentation slide layout with a vertical title placeholder shape on the right and a body placeholder shape on the left. */
  72. VERTICAL_TITLE_BODY(0x0011),
  73. /** Presentation slide layout with a vertical title placeholder shape on the right and two body placeholder shapes in two columns on the left. */
  74. VERTICAL_TWO_ROWS(0x0012);
  75. private int nativeId;
  76. SlideLayoutType(int nativeId) {
  77. this.nativeId = nativeId;
  78. }
  79. public int getNativeId() {
  80. return nativeId;
  81. }
  82. public static SlideLayoutType forNativeID(int nativeId) {
  83. for (SlideLayoutType ans : values()) {
  84. if (ans.nativeId == nativeId) {
  85. return ans;
  86. }
  87. }
  88. return null;
  89. }
  90. }
  91. /** What geometry type we are */
  92. private SlideLayoutType geometry;
  93. /** What placeholder IDs we have */
  94. private byte[] placeholderIDs;
  95. /** Retrieve the geometry type */
  96. public SlideLayoutType getGeometryType() { return geometry; }
  97. /** Set the geometry type */
  98. public void setGeometryType(SlideLayoutType geom) { geometry = geom; }
  99. /**
  100. * Create a new Embedded SSlideLayoutAtom, from 12 bytes of data
  101. */
  102. public SlideAtomLayout(byte[] data) {
  103. if(data.length != 12) {
  104. throw new HSLFException("SSlideLayoutAtom created with byte array not 12 bytes long - was " + data.length + " bytes in size");
  105. }
  106. // Grab out our data
  107. geometry = SlideLayoutType.forNativeID(LittleEndian.getInt(data,0));
  108. placeholderIDs = Arrays.copyOfRange(data,4, 4+8);
  109. }
  110. /**
  111. * Write the contents of the record back, so it can be written
  112. * to disk. Skips the record header
  113. */
  114. public void writeOut(OutputStream out) throws IOException {
  115. // Write the geometry
  116. byte[] buf = new byte[4];
  117. LittleEndian.putInt(buf, 0, geometry == null ? 0 : geometry.getNativeId());
  118. out.write(buf);
  119. // Write the placeholder IDs
  120. out.write(placeholderIDs);
  121. }
  122. @Override
  123. public Map<String, Supplier<?>> getGenericProperties() {
  124. return GenericRecordUtil.getGenericProperties(
  125. "geometry", this::getGeometryType,
  126. "placeholderIDs", () -> placeholderIDs
  127. );
  128. }
  129. }