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