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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.fonts.truetype;
  18. import java.io.IOException;
  19. import java.io.UnsupportedEncodingException;
  20. /**
  21. * This class represents an entry to a TrueType font's Dir Tab.
  22. */
  23. class TTFDirTabEntry {
  24. private byte[] tag = new byte[4];
  25. private int checksum;
  26. private long offset;
  27. private long length;
  28. /**
  29. * Read Dir Tab, return tag name
  30. */
  31. public String read(FontFileReader in) throws IOException {
  32. tag[0] = in.readTTFByte();
  33. tag[1] = in.readTTFByte();
  34. tag[2] = in.readTTFByte();
  35. tag[3] = in.readTTFByte();
  36. in.skip(4); // Skip checksum
  37. offset = in.readTTFULong();
  38. length = in.readTTFULong();
  39. String tagStr = new String(tag, "ISO-8859-1");
  40. return tagStr;
  41. }
  42. public String toString() {
  43. return "Read dir tab ["
  44. + tag[0] + " " + tag[1] + " " + tag[2] + " " + tag[3] + "]"
  45. + " offset: " + offset
  46. + " length: " + length
  47. + " name: " + tag;
  48. }
  49. /**
  50. * Returns the checksum.
  51. * @return int
  52. */
  53. public int getChecksum() {
  54. return checksum;
  55. }
  56. /**
  57. * Returns the length.
  58. * @return long
  59. */
  60. public long getLength() {
  61. return length;
  62. }
  63. /**
  64. * Returns the offset.
  65. * @return long
  66. */
  67. public long getOffset() {
  68. return offset;
  69. }
  70. /**
  71. * Returns the tag bytes.
  72. * @return byte[]
  73. */
  74. public byte[] getTag() {
  75. return tag;
  76. }
  77. /**
  78. * Returns the tag bytes.
  79. * @return byte[]
  80. */
  81. public String getTagString() {
  82. try {
  83. return new String(tag, "ISO-8859-1");
  84. } catch (UnsupportedEncodingException e) {
  85. return this.toString(); // Should never happen.
  86. }
  87. }
  88. }