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.

CMapSegment.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.fonts;
  19. /**
  20. * A segment in a cmap table of format 4. Unicode code points between
  21. * {@link #getUnicodeStart()} and {@link #getUnicodeEnd()} map to contiguous glyph indices
  22. * starting from {@link #getGlyphStartIndex()}.
  23. */
  24. public final class CMapSegment {
  25. private final int unicodeStart;
  26. private final int unicodeEnd;
  27. private final int glyphStartIndex;
  28. /**
  29. * Creates a new segment.
  30. *
  31. * @param unicodeStart Unicode start index
  32. * @param unicodeEnd Unicode end index
  33. * @param glyphStartIndex glyph start index
  34. */
  35. public CMapSegment(int unicodeStart, int unicodeEnd, int glyphStartIndex) {
  36. this.unicodeStart = unicodeStart;
  37. this.unicodeEnd = unicodeEnd;
  38. this.glyphStartIndex = glyphStartIndex;
  39. }
  40. @Override
  41. public int hashCode() {
  42. int hc = 17;
  43. hc = 31 * hc + unicodeStart;
  44. hc = 31 * hc + unicodeEnd;
  45. hc = 31 * hc + glyphStartIndex;
  46. return hc;
  47. }
  48. @Override
  49. public boolean equals(Object o) {
  50. if (o instanceof CMapSegment) {
  51. CMapSegment ce = (CMapSegment) o;
  52. return ce.unicodeStart == this.unicodeStart
  53. && ce.unicodeEnd == this.unicodeEnd
  54. && ce.glyphStartIndex == this.glyphStartIndex;
  55. }
  56. return false;
  57. }
  58. /**
  59. * Returns the unicodeStart.
  60. * @return the Unicode start index
  61. */
  62. public int getUnicodeStart() {
  63. return unicodeStart;
  64. }
  65. /**
  66. * Returns the unicodeEnd.
  67. * @return the Unicode end index
  68. */
  69. public int getUnicodeEnd() {
  70. return unicodeEnd;
  71. }
  72. /**
  73. * Returns the glyphStartIndex.
  74. * @return the glyph start index
  75. */
  76. public int getGlyphStartIndex() {
  77. return glyphStartIndex;
  78. }
  79. /** {@inheritDoc} */
  80. @Override
  81. public String toString() {
  82. StringBuilder sb = new StringBuilder("CMapSegment: ");
  83. sb.append ( "{ UC[" );
  84. sb.append ( unicodeStart );
  85. sb.append ( ',' );
  86. sb.append ( unicodeEnd );
  87. sb.append ( "]: GC[" );
  88. sb.append ( glyphStartIndex );
  89. sb.append ( ',' );
  90. sb.append ( glyphStartIndex + ( unicodeEnd - unicodeStart ) );
  91. sb.append ( "] }" );
  92. return sb.toString();
  93. }
  94. }