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.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. 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, return tag name
  37. */
  38. public String read(FontFileReader in) throws IOException {
  39. tag[0] = in.readTTFByte();
  40. tag[1] = in.readTTFByte();
  41. tag[2] = in.readTTFByte();
  42. tag[3] = in.readTTFByte();
  43. in.skip(4); // Skip checksum
  44. offset = in.readTTFULong();
  45. length = in.readTTFULong();
  46. String tagStr = new String(tag, "ISO-8859-1");
  47. return tagStr;
  48. }
  49. public String toString() {
  50. return "Read dir tab ["
  51. + tag[0] + " " + tag[1] + " " + tag[2] + " " + tag[3] + "]"
  52. + " offset: " + offset
  53. + " length: " + length
  54. + " name: " + tag;
  55. }
  56. /**
  57. * Returns the checksum.
  58. * @return int
  59. */
  60. public int getChecksum() {
  61. return checksum;
  62. }
  63. /**
  64. * Returns the length.
  65. * @return long
  66. */
  67. public long getLength() {
  68. return length;
  69. }
  70. /**
  71. * Returns the offset.
  72. * @return long
  73. */
  74. public long getOffset() {
  75. return offset;
  76. }
  77. /**
  78. * Returns the tag bytes.
  79. * @return byte[]
  80. */
  81. public byte[] getTag() {
  82. return tag;
  83. }
  84. /**
  85. * Returns the tag bytes.
  86. * @return byte[]
  87. */
  88. public String getTagString() {
  89. try {
  90. return new String(tag, "ISO-8859-1");
  91. } catch (UnsupportedEncodingException e) {
  92. return this.toString(); // Should never happen.
  93. }
  94. }
  95. }