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.

ParagraphHeight.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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.hwpf.model;
  16. import java.io.IOException;
  17. import java.io.OutputStream;
  18. import org.apache.poi.common.Duplicatable;
  19. import org.apache.poi.util.BitField;
  20. import org.apache.poi.util.BitFieldFactory;
  21. import org.apache.poi.util.Internal;
  22. import org.apache.poi.util.LittleEndian;
  23. import org.apache.poi.util.LittleEndianConsts;
  24. @Internal
  25. public final class ParagraphHeight implements Duplicatable {
  26. private static final BitField fSpare = BitFieldFactory.getInstance(0x0001);
  27. private static final BitField fUnk = BitFieldFactory.getInstance(0x0002);
  28. private static final BitField fDiffLines = BitFieldFactory.getInstance(0x0004);
  29. private static final BitField clMac = BitFieldFactory.getInstance(0xff00);
  30. private short infoField;
  31. private short reserved;
  32. private int dxaCol;
  33. private int dymLineOrHeight;
  34. public ParagraphHeight() {}
  35. public ParagraphHeight(ParagraphHeight other) {
  36. infoField = other.infoField;
  37. reserved = other.reserved;
  38. dxaCol = other.dxaCol;
  39. dymLineOrHeight = other.dymLineOrHeight;
  40. }
  41. public ParagraphHeight(byte[] buf, int offset) {
  42. infoField = LittleEndian.getShort(buf, offset);
  43. offset += LittleEndianConsts.SHORT_SIZE;
  44. reserved = LittleEndian.getShort(buf, offset);
  45. offset += LittleEndianConsts.SHORT_SIZE;
  46. dxaCol = LittleEndian.getInt(buf, offset);
  47. offset += LittleEndianConsts.INT_SIZE;
  48. dymLineOrHeight = LittleEndian.getInt(buf, offset);
  49. }
  50. public void write(OutputStream out)
  51. throws IOException
  52. {
  53. out.write(toByteArray());
  54. }
  55. protected byte[] toByteArray()
  56. {
  57. byte[] buf = new byte[12];
  58. int offset = 0;
  59. LittleEndian.putShort(buf, offset, infoField);
  60. offset += LittleEndianConsts.SHORT_SIZE;
  61. LittleEndian.putShort(buf, offset, reserved);
  62. offset += LittleEndianConsts.SHORT_SIZE;
  63. LittleEndian.putInt(buf, offset, dxaCol);
  64. offset += LittleEndianConsts.INT_SIZE;
  65. LittleEndian.putInt(buf, offset, dymLineOrHeight);
  66. return buf;
  67. }
  68. public boolean equals(Object o)
  69. {
  70. if (!(o instanceof ParagraphHeight)) return false;
  71. ParagraphHeight ph = (ParagraphHeight)o;
  72. return infoField == ph.infoField && reserved == ph.reserved &&
  73. dxaCol == ph.dxaCol && dymLineOrHeight == ph.dymLineOrHeight;
  74. }
  75. @Override
  76. public int hashCode() {
  77. assert false : "hashCode not designed";
  78. return 42; // any arbitrary constant will do
  79. }
  80. @Override
  81. public ParagraphHeight copy() {
  82. return new ParagraphHeight(this);
  83. }
  84. }