// Java
import java.io.UnsupportedEncodingException;
+// FOP
+import org.apache.fop.fonts.type1.PFBData;
+
public class PDFT1Stream extends PDFStream {
- private int origLength;
- private int len1, len3;
- private byte[] originalData = null;
+
+ private PFBData pfb;
- public PDFT1Stream(int num, int len) {
+ public PDFT1Stream(int num) {
super(num);
- origLength = len;
- }
-
- private final static boolean byteCmp(byte[] src, int offset, byte[] cmp) {
- boolean ret = true;
- for (int i = 0; ret == true && i < cmp.length; i++) {
- // System.out.println("Compare: ");
- // System.out.println(" "+src[offset+i]+" "+cmp[i]);
- if (src[offset + i] != cmp[i])
- ret = false;
- }
- return ret;
}
- /**
- * calculates the Length1 and Length3 PDFStream attributes for type1
- * font embedding
- */
- private void calcLengths(byte[] originalData) {
- // Calculate length 1 and 3
- // System.out.println ("Checking font, size = "+originalData.length);
-
- // Length1 is the size of the initial ascii portion
- // search for "currentfile eexec"
- // Get the first binary number and search backwards for "eexec"
- len1 = 30;
-
- byte[] eexec;
- try {
- eexec = "currentfile eexec".getBytes(PDFDocument.ENCODING);
- } catch (UnsupportedEncodingException ue) {
- eexec = "currentfile eexec".getBytes();
- }
- // System.out.println("Length1="+len1);
- while (!byteCmp(originalData, len1 - eexec.length, eexec))
- len1++;
- // Skip newline
- len1++;
-
- // Length3 is length of the last portion of the file
- len3 = 0;
- byte[] cltom;
- try {
- cltom = "cleartomark".getBytes(PDFDocument.ENCODING);
- } catch (UnsupportedEncodingException ue) {
- cltom = "cleartomark".getBytes();
- }
-
- len3 -= cltom.length;
- while (!byteCmp(originalData, origLength + len3, cltom)) {
- len3--;
- // System.out.println("Len3="+len3);
- }
- len3 = -len3;
- len3++;
- // Eat 512 zeroes
- int numZeroes = 0;
- byte[] ws1;
- try {
- ws1 = "\n".getBytes(PDFDocument.ENCODING);
- } catch (UnsupportedEncodingException ue) {
- ws1 = "\n".getBytes();
- }
- byte[] ws2;
- try {
- ws2 = "\r".getBytes(PDFDocument.ENCODING);
- } catch (UnsupportedEncodingException ue) {
- ws2 = "\r".getBytes();
- }
- byte[] ws3;
- try {
- ws3 = "0".getBytes(PDFDocument.ENCODING);
- } catch (UnsupportedEncodingException ue) {
- ws3 = "0".getBytes();
- }
- while ((originalData[origLength - len3] == ws1[0] || originalData[origLength - len3] == ws2[0] || originalData[origLength - len3] == ws3[0])
- && numZeroes < 512) {
- len3++;
- if (originalData[origLength - len3] == ws3[0])
- numZeroes++;
- }
- // System.out.println("Length3="+len3);
- }
// overload the base object method so we don't have to copy
// byte arrays around so much
protected int output(java.io.OutputStream stream)
throws java.io.IOException {
+ if (pfb == null) throw new NullPointerException("pfb must not be null at this point");
int length = 0;
String filterEntry = applyFilters();
- String preData = new String(this.number + " " + this.generation
- + " obj\n<< /Length "
- + (_data.size() + 1) + " " + filterEntry
- + " " + "/Length1 " + len1 + " /Length2 "
- + (origLength - len3 - len1)
- + " /Length3 " + len3 + " >>\n");
+ String preData = this.number + " " + this.generation
+ + " obj\n<< /Length " + pfb.getLength() + " "
+ + filterEntry
+ + " /Length1 " + pfb.getLength1()
+ + " /Length2 " + pfb.getLength2()
+ + " /Length3 " + pfb.getLength3() + " >>\n";
byte[] p;
try {
return length;
}
- public void setData(byte[] data, int size) throws java.io.IOException {
- calcLengths(data);
+ public void setData(PFBData pfb) throws java.io.IOException {
_data.reset();
// System.out.println("Writing " + size + " bytes of font data");
- _data.write(data, 0, size);
+ this.pfb = pfb;
+ pfb.outputAllParts(_data);
}
}