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.

OFDirTabEntry.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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.truetype;
  19. import java.io.IOException;
  20. import java.io.UnsupportedEncodingException;
  21. import java.util.Arrays;
  22. /**
  23. * This class represents an entry to a TrueType font's Dir Tab.
  24. */
  25. public class OFDirTabEntry {
  26. private byte[] tag = new byte[4];
  27. private long checksum;
  28. private long offset;
  29. private long length;
  30. public OFDirTabEntry() {
  31. }
  32. public OFDirTabEntry(long offset, long length) {
  33. this.offset = offset;
  34. this.length = length;
  35. }
  36. /**
  37. * Read Dir Tab.
  38. * @param in font file reader
  39. * @return tag name
  40. * @throws IOException upon I/O exception
  41. */
  42. public String read(FontFileReader in) throws IOException {
  43. tag[0] = in.readTTFByte();
  44. tag[1] = in.readTTFByte();
  45. tag[2] = in.readTTFByte();
  46. tag[3] = in.readTTFByte();
  47. checksum = in.readTTFLong();
  48. offset = in.readTTFULong();
  49. length = in.readTTFULong();
  50. return getTagString();
  51. }
  52. @Override
  53. public String toString() {
  54. return "Read dir tab [" + Arrays.toString(tag) + "]"
  55. + " offset: " + offset
  56. + " length: " + length
  57. + " name: " + getTagString();
  58. }
  59. /**
  60. * Returns the checksum.
  61. * @return int
  62. */
  63. public long getChecksum() {
  64. return checksum;
  65. }
  66. /**
  67. * Returns the length.
  68. * @return long
  69. */
  70. public long getLength() {
  71. return length;
  72. }
  73. /**
  74. * Returns the offset.
  75. * @return long
  76. */
  77. public long getOffset() {
  78. return offset;
  79. }
  80. /**
  81. * Returns the tag bytes.
  82. * @return byte[]
  83. */
  84. public byte[] getTag() {
  85. return tag;
  86. }
  87. /**
  88. * Returns the tag bytes.
  89. * @return byte[]
  90. */
  91. public String getTagString() {
  92. try {
  93. return new String(tag, "ISO-8859-1");
  94. } catch (UnsupportedEncodingException e) {
  95. return this.toString(); // Should never happen.
  96. }
  97. }
  98. }