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.

PDFT1Stream.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. // Java
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. // FOP
  22. import org.apache.fop.fonts.type1.PFBData;
  23. /**
  24. * Special PDFStream for embedding Type 1 fonts.
  25. */
  26. public class PDFT1Stream extends AbstractPDFStream {
  27. private PFBData pfb;
  28. /**
  29. * @see org.apache.fop.pdf.AbstractPDFStream#getSizeHint()
  30. */
  31. protected int getSizeHint() throws IOException {
  32. if (this.pfb != null) {
  33. return pfb.getLength();
  34. } else {
  35. return 0; //no hint available
  36. }
  37. }
  38. /**
  39. * Overload the base object method so we don't have to copy
  40. * byte arrays around so much
  41. * @see org.apache.fop.pdf.PDFObject#output(OutputStream)
  42. */
  43. protected int output(java.io.OutputStream stream)
  44. throws java.io.IOException {
  45. if (pfb == null) {
  46. throw new IllegalStateException("pfb must not be null at this point");
  47. }
  48. getDocumentSafely().getLogger().debug("Writing "
  49. + pfb.getLength() + " bytes of Type 1 font data");
  50. int length = super.output(stream);
  51. getDocumentSafely().getLogger().debug("Embedded Type1 font");
  52. return length;
  53. }
  54. /**
  55. * @see org.apache.fop.pdf.AbstractPDFStream#buildStreamDict(String)
  56. */
  57. protected String buildStreamDict(String lengthEntry) {
  58. final String filterEntry = getFilterList().buildFilterDictEntries();
  59. return (getObjectID()
  60. + "<< /Length " + lengthEntry
  61. + " /Length1 " + pfb.getLength1()
  62. + " /Length2 " + pfb.getLength2()
  63. + " /Length3 " + pfb.getLength3()
  64. + "\n" + filterEntry
  65. + "\n>>\n");
  66. }
  67. /**
  68. * @see org.apache.fop.pdf.PDFStream#outputRawStreamData(OutputStream)
  69. */
  70. protected void outputRawStreamData(OutputStream out) throws IOException {
  71. this.pfb.outputAllParts(out);
  72. }
  73. /**
  74. * Used to set the PFBData object that represents the embeddable Type 1
  75. * font.
  76. * @param pfb The PFB file
  77. * @throws IOException in case of an I/O problem
  78. */
  79. public void setData(PFBData pfb) throws IOException {
  80. this.pfb = pfb;
  81. }
  82. }