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.

DropCapSpecifier.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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.usermodel;
  16. import org.apache.poi.common.Duplicatable;
  17. import org.apache.poi.util.BitField;
  18. import org.apache.poi.util.BitFieldFactory;
  19. import org.apache.poi.util.LittleEndian;
  20. import org.apache.poi.util.Removal;
  21. /**
  22. * This data structure is used by a paragraph to determine how it should drop
  23. * its first letter. I think its the visual effect that will show a giant first
  24. * letter to a paragraph. I've seen this used in the first paragraph of a book
  25. */
  26. public final class DropCapSpecifier implements Duplicatable {
  27. private static final BitField _lines = BitFieldFactory.getInstance( 0xf8 );
  28. private static final BitField _type = BitFieldFactory.getInstance( 0x07 );
  29. private short _fdct;
  30. public DropCapSpecifier() {
  31. _fdct = 0;
  32. }
  33. public DropCapSpecifier(DropCapSpecifier other) {
  34. _fdct = other._fdct;
  35. }
  36. public DropCapSpecifier( byte[] buf, int offset ) {
  37. this( LittleEndian.getShort( buf, offset ) );
  38. }
  39. public DropCapSpecifier( short fdct ) {
  40. this._fdct = fdct;
  41. }
  42. @Override
  43. @SuppressWarnings("squid:S2975")
  44. @Deprecated
  45. @Removal(version = "5.0.0")
  46. public DropCapSpecifier clone() {
  47. return copy();
  48. }
  49. @Override
  50. public DropCapSpecifier copy() {
  51. return new DropCapSpecifier(this);
  52. }
  53. @Override
  54. public boolean equals( Object obj )
  55. {
  56. if ( this == obj )
  57. return true;
  58. if ( obj == null )
  59. return false;
  60. if ( getClass() != obj.getClass() )
  61. return false;
  62. DropCapSpecifier other = (DropCapSpecifier) obj;
  63. if ( _fdct != other._fdct )
  64. return false;
  65. return true;
  66. }
  67. public byte getCountOfLinesToDrop()
  68. {
  69. return (byte) _lines.getValue( _fdct );
  70. }
  71. public byte getDropCapType()
  72. {
  73. return (byte) _type.getValue( _fdct );
  74. }
  75. @Override
  76. public int hashCode() {
  77. return _fdct;
  78. }
  79. public boolean isEmpty()
  80. {
  81. return _fdct == 0;
  82. }
  83. public void setCountOfLinesToDrop( byte value )
  84. {
  85. _fdct = (short) _lines.setValue( _fdct, value );
  86. }
  87. public void setDropCapType( byte value )
  88. {
  89. _fdct = (short) _type.setValue( _fdct, value );
  90. }
  91. public short toShort()
  92. {
  93. return _fdct;
  94. }
  95. @Override
  96. public String toString()
  97. {
  98. if ( isEmpty() )
  99. return "[DCS] EMPTY";
  100. return "[DCS] (type: " + getDropCapType() + "; count: "
  101. + getCountOfLinesToDrop() + ")";
  102. }
  103. }