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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.pdf;
  18. import java.io.IOException;
  19. /**
  20. * Special PDFStream for embeddable TrueType fonts.
  21. */
  22. public class PDFTTFStream extends PDFStream {
  23. private int origLength;
  24. /**
  25. * Main constructor
  26. * @param len original length
  27. */
  28. public PDFTTFStream(int len) {
  29. super();
  30. origLength = len;
  31. }
  32. /**
  33. * Overload the base object method so we don't have to copy
  34. * byte arrays around so much
  35. * @see org.apache.fop.pdf.PDFObject#output(OutputStream)
  36. */
  37. protected int output(java.io.OutputStream stream)
  38. throws java.io.IOException {
  39. getDocumentSafely().getLogger().debug("Writing "
  40. + origLength + " bytes of TTF font data");
  41. int length = super.output(stream);
  42. getDocumentSafely().getLogger().debug("Embedded TrueType/OpenType font");
  43. return length;
  44. }
  45. /**
  46. * @see org.apache.fop.pdf.AbstractPDFStream#buildStreamDict(String)
  47. */
  48. protected String buildStreamDict(String lengthEntry) {
  49. final String filterEntry = getFilterList().buildFilterDictEntries();
  50. return (getObjectID()
  51. + "<< /Length " + lengthEntry
  52. + " /Length1 " + origLength
  53. + "\n" + filterEntry
  54. + "\n>>\n");
  55. }
  56. /**
  57. * Sets the TrueType font data.
  58. * @param data the font payload
  59. * @param size size of the payload
  60. * @throws IOException in case of an I/O problem
  61. */
  62. public void setData(byte[] data, int size) throws IOException {
  63. this.data.clear();
  64. this.data.getOutputStream().write(data, 0, size);
  65. }
  66. }