Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

EscherTextboxWrapper.java 3.7KB

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