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

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