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.

StyleTextProp9Atom.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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.LinkedList;
  19. import java.util.List;
  20. import org.apache.poi.hslf.model.textproperties.TextPFException9;
  21. import org.apache.poi.util.LittleEndian;
  22. /**
  23. * The atom record that specifies additional text formatting.
  24. */
  25. public final class StyleTextProp9Atom extends RecordAtom {
  26. private final TextPFException9[] autoNumberSchemes;
  27. /** Record header. */
  28. private byte[] header;
  29. /** Record data. */
  30. private byte[] data;
  31. private short version;
  32. private short recordId;
  33. private int length;
  34. /**
  35. * Constructs the link related atom record from its
  36. * source data.
  37. *
  38. * @param source the source data as a byte array.
  39. * @param start the start offset into the byte array.
  40. * @param len the length of the slice in the byte array.
  41. */
  42. protected StyleTextProp9Atom(byte[] source, int start, int len) {
  43. // Get the header.
  44. final List<TextPFException9> schemes = new LinkedList<TextPFException9>();
  45. header = new byte[8];
  46. System.arraycopy(source,start, header,0,8);
  47. this.version = LittleEndian.getShort(header, 0);
  48. this.recordId = LittleEndian.getShort(header, 2);
  49. this.length = LittleEndian.getInt(header, 4);
  50. // Get the record data.
  51. data = new byte[len-8];
  52. System.arraycopy(source, start+8, data, 0, len-8);
  53. for (int i = 0; i < data.length; ) {
  54. final TextPFException9 item = new TextPFException9(data, i);
  55. schemes.add(item);
  56. i += item.getRecordLength();
  57. if (i >= data.length) {
  58. break;
  59. }
  60. int textCfException9 = LittleEndian.getInt(data, i );
  61. i += 4;
  62. //TODO analyze textCfException when have some test data
  63. if (i >= data.length) {
  64. break;
  65. }
  66. int textSiException = LittleEndian.getInt(data, i );
  67. i += 4;//TextCFException9 + SIException
  68. if (0 != (textSiException & 0x40)) {
  69. i += 2; //skip fBidi
  70. }
  71. if (i >= data.length) {
  72. break;
  73. }
  74. }
  75. this.autoNumberSchemes = (TextPFException9[]) schemes.toArray(new TextPFException9[schemes.size()]);
  76. }
  77. /**
  78. * Gets the record type.
  79. * @return the record type.
  80. */
  81. public long getRecordType() { return this.recordId; }
  82. public short getVersion() {
  83. return version;
  84. }
  85. public int getLength() {
  86. return length;
  87. }
  88. public TextPFException9[] getAutoNumberTypes() {
  89. return this.autoNumberSchemes;
  90. }
  91. /**
  92. * Write the contents of the record back, so it can be written
  93. * to disk
  94. *
  95. * @param out the output stream to write to.
  96. * @throws java.io.IOException if an error occurs.
  97. */
  98. public void writeOut(OutputStream out) throws IOException {
  99. out.write(header);
  100. out.write(data);
  101. }
  102. /**
  103. * Update the text length
  104. *
  105. * @param size the text length
  106. */
  107. public void setTextSize(int size){
  108. LittleEndian.putInt(data, 0, size);
  109. }
  110. /**
  111. * Reset the content to one info run with the default values
  112. * @param size the site of parent text
  113. */
  114. public void reset(int size){
  115. data = new byte[10];
  116. // 01 00 00 00
  117. LittleEndian.putInt(data, 0, size);
  118. // 01 00 00 00
  119. LittleEndian.putInt(data, 4, 1); //mask
  120. // 00 00
  121. LittleEndian.putShort(data, 8, (short)0); //langId
  122. // Update the size (header bytes 5-8)
  123. LittleEndian.putInt(header, 4, data.length);
  124. }
  125. }