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.

EscherTextboxWrapper.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.Map;
  19. import java.util.function.Supplier;
  20. import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
  21. import org.apache.poi.ddf.EscherTextboxRecord;
  22. import org.apache.poi.util.GenericRecordUtil;
  23. /**
  24. * A wrapper around a DDF (Escher) EscherTextbox Record. Causes the DDF
  25. * Record to be accessible as if it were a HSLF record.
  26. * Note: when asked to write out, will simply put any child records correctly
  27. * into the Escher layer. A call to the escher layer to write out (by the
  28. * parent PPDrawing) will do the actual write out
  29. */
  30. public final class EscherTextboxWrapper extends RecordContainer {
  31. private final EscherTextboxRecord _escherRecord;
  32. private long _type;
  33. private int shapeId;
  34. private StyleTextPropAtom styleTextPropAtom;
  35. private StyleTextProp9Atom styleTextProp9Atom;
  36. /**
  37. * Returns the underlying DDF Escher Record
  38. */
  39. public EscherTextboxRecord getEscherRecord() { return _escherRecord; }
  40. /**
  41. * Creates the wrapper for the given DDF Escher Record and children
  42. */
  43. public EscherTextboxWrapper(EscherTextboxRecord textbox) {
  44. _escherRecord = textbox;
  45. _type = _escherRecord.getRecordId();
  46. // Find the child records in the escher data
  47. byte[] data = _escherRecord.getData();
  48. _children = Record.findChildRecords(data,0,data.length);
  49. for (org.apache.poi.hslf.record.Record r : this._children) {
  50. if (r instanceof StyleTextPropAtom) { this.styleTextPropAtom = (StyleTextPropAtom) r; }
  51. }
  52. }
  53. /**
  54. * Creates a new, empty wrapper for DDF Escher Records and their children
  55. */
  56. public EscherTextboxWrapper() {
  57. _escherRecord = new EscherTextboxRecord();
  58. _escherRecord.setRecordId(EscherTextboxRecord.RECORD_ID);
  59. _escherRecord.setOptions((short)15);
  60. _children = new org.apache.poi.hslf.record.Record[0];
  61. }
  62. /**
  63. * Return the type of the escher record (normally in the 0xFnnn range)
  64. */
  65. @Override
  66. public long getRecordType() { return _type; }
  67. /**
  68. * Stores the data for the child records back into the Escher layer.
  69. * Doesn't actually do the writing out, that's left to the Escher
  70. * layer to do. Must be called before writeOut/serialize is called
  71. * on the underlying Escher object!
  72. */
  73. @Override
  74. public void writeOut(OutputStream out) throws IOException {
  75. // Write out our children, and stuff them into the Escher layer
  76. // Grab the children's data
  77. try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
  78. for (org.apache.poi.hslf.record.Record r : _children) {
  79. r.writeOut(baos);
  80. }
  81. // Save in the escher layer
  82. _escherRecord.setData(baos.toByteArray());
  83. }
  84. }
  85. /**
  86. * @return Shape ID
  87. */
  88. public int getShapeId(){
  89. return shapeId;
  90. }
  91. /**
  92. * @param id Shape ID
  93. */
  94. public void setShapeId(int id){
  95. shapeId = id;
  96. }
  97. public StyleTextPropAtom getStyleTextPropAtom() {
  98. return styleTextPropAtom;
  99. }
  100. public void setStyleTextProp9Atom(final StyleTextProp9Atom nineAtom) {
  101. this.styleTextProp9Atom = nineAtom;
  102. }
  103. public StyleTextProp9Atom getStyleTextProp9Atom() {
  104. return this.styleTextProp9Atom;
  105. }
  106. @Override
  107. public Map<String, Supplier<?>> getGenericProperties() {
  108. return GenericRecordUtil.getGenericProperties(
  109. "shapeId", this::getShapeId,
  110. "escherRecord", this::getEscherRecord
  111. );
  112. }
  113. }