Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

OTFSubSetWriter.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.ByteArrayOutputStream;
  20. import java.io.IOException;
  21. public class OTFSubSetWriter extends OTFFile {
  22. protected int currentPos;
  23. protected ByteArrayOutputStream output = new ByteArrayOutputStream();
  24. public OTFSubSetWriter() throws IOException {
  25. super();
  26. }
  27. public static byte[] concatArray(byte[] a, byte[] b) {
  28. int aLen = a.length;
  29. int bLen = b.length;
  30. byte[] c = new byte[aLen + bLen];
  31. System.arraycopy(a, 0, c, 0, aLen);
  32. System.arraycopy(b, 0, c, aLen, bLen);
  33. return c;
  34. }
  35. /**
  36. * Appends a byte to the output array,
  37. * updates currentPost but not realSize
  38. */
  39. protected void writeByte(int b) {
  40. output.write(b);
  41. currentPos++;
  42. }
  43. /**
  44. * Appends a USHORT to the output array,
  45. * updates currentPost but not realSize
  46. */
  47. protected void writeCard16(int s) {
  48. byte b1 = (byte)((s >> 8) & 0xff);
  49. byte b2 = (byte)(s & 0xff);
  50. writeByte(b1);
  51. writeByte(b2);
  52. }
  53. protected void writeThreeByteNumber(int s) {
  54. byte b1 = (byte)((s >> 16) & 0xFF);
  55. byte b2 = (byte)((s >> 8) & 0xFF);
  56. byte b3 = (byte)(s & 0xFF);
  57. writeByte(b1);
  58. writeByte(b2);
  59. writeByte(b3);
  60. }
  61. /**
  62. * Appends a ULONG to the output array,
  63. * at the given position
  64. */
  65. protected void writeULong(int s) {
  66. byte b1 = (byte)((s >> 24) & 0xff);
  67. byte b2 = (byte)((s >> 16) & 0xff);
  68. byte b3 = (byte)((s >> 8) & 0xff);
  69. byte b4 = (byte)(s & 0xff);
  70. writeByte(b1);
  71. writeByte(b2);
  72. writeByte(b3);
  73. writeByte(b4);
  74. }
  75. protected void writeBytes(byte[] out) {
  76. for (byte anOut : out) {
  77. writeByte(anOut);
  78. }
  79. }
  80. /**
  81. * Returns a subset of the fonts (readFont() MUST be called first in order to create the
  82. * subset).
  83. * @return byte array
  84. */
  85. public byte[] getFontSubset() {
  86. return output.toByteArray();
  87. }
  88. }