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.4KB

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