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.

TTFDirTabEntry.java 2.8KB

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