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.

PDFTTFStream.java 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.pdf;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. /**
  22. * Special PDFStream for embeddable TrueType fonts.
  23. */
  24. public class PDFTTFStream extends AbstractPDFFontStream {
  25. private int origLength;
  26. private byte[] ttfData;
  27. /**
  28. * Main constructor
  29. * @param len original length
  30. */
  31. public PDFTTFStream(int len) {
  32. super();
  33. origLength = len;
  34. }
  35. /** {@inheritDoc} */
  36. protected int getSizeHint() throws IOException {
  37. if (this.ttfData != null) {
  38. return ttfData.length;
  39. } else {
  40. return 0; //no hint available
  41. }
  42. }
  43. /**
  44. * Overload the base object method so we don't have to copy
  45. * byte arrays around so much
  46. * {@inheritDoc}
  47. */
  48. public int output(java.io.OutputStream stream)
  49. throws java.io.IOException {
  50. if (log.isDebugEnabled()) {
  51. log.debug("Writing " + origLength + " bytes of TTF font data");
  52. }
  53. int length = super.output(stream);
  54. log.debug("Embedded TrueType/OpenType font");
  55. return length;
  56. }
  57. /** {@inheritDoc} */
  58. protected void outputRawStreamData(OutputStream out) throws IOException {
  59. out.write(this.ttfData);
  60. }
  61. /** {@inheritDoc} */
  62. protected void populateStreamDict(Object lengthEntry) {
  63. put("Length1", origLength);
  64. super.populateStreamDict(lengthEntry);
  65. }
  66. /**
  67. * Sets the TrueType font data.
  68. * @param data the font payload
  69. * @param size size of the payload
  70. * @throws IOException in case of an I/O problem
  71. */
  72. public void setData(byte[] data, int size) throws IOException {
  73. this.ttfData = new byte[size];
  74. System.arraycopy(data, 0, this.ttfData, 0, size);
  75. }
  76. }