1 51 package org.apache.fop.pdf; 52 53 import java.io.UnsupportedEncodingException ; 55 56 61 public class PDFFontDescriptor extends PDFObject { 62 63 protected int ascent; 65 protected int capHeight; 66 protected int descent; 67 protected int flags; 68 protected PDFRectangle fontBBox; 69 protected String basefont; protected int italicAngle; 71 protected int stemV; 72 protected int stemH = 0; 74 protected int xHeight = 0; 75 protected int leading = 0; 76 protected int avgWidth = 0; 77 protected int maxWidth = 0; 78 protected int missingWidth = 0; 79 protected PDFStream fontfile; 80 82 protected byte subtype; 83 84 97 public PDFFontDescriptor(int number, String basefont, int ascent, 98 int descent, int capHeight, int flags, 99 PDFRectangle fontBBox, int italicAngle, 100 int stemV) { 101 102 103 super(number); 104 105 106 this.basefont = basefont; 107 this.ascent = ascent; 108 this.descent = descent; 109 this.capHeight = capHeight; 110 this.flags = flags; 111 this.fontBBox = fontBBox; 112 this.italicAngle = italicAngle; 113 this.stemV = stemV; 114 } 115 116 119 public void setMetrics(int avgWidth, int maxWidth, int missingWidth, 120 int leading, int stemH, int xHeight) { 121 this.avgWidth = avgWidth; 122 this.maxWidth = maxWidth; 123 this.missingWidth = missingWidth; 124 this.leading = leading; 125 this.stemH = stemH; 126 this.xHeight = xHeight; 127 } 128 129 135 public void setFontFile(byte subtype, PDFStream fontfile) { 136 this.subtype = subtype; 137 this.fontfile = fontfile; 138 } 139 140 142 147 public byte[] toPDF() { 148 StringBuffer p = new StringBuffer (this.number + " " + this.generation 149 + " obj\n<< /Type /FontDescriptor" 150 + "\n/FontName /" + this.basefont); 151 152 p.append("\n/FontBBox "); 153 p.append(fontBBox.toPDFString()); 154 p.append("\n/Flags "); 155 p.append(flags); 156 p.append("\n/CapHeight "); 157 p.append(capHeight); 158 p.append("\n/Ascent "); 159 p.append(ascent); 160 p.append("\n/Descent "); 161 p.append(descent); 162 p.append("\n/ItalicAngle "); 163 p.append(italicAngle); 164 p.append("\n/StemV "); 165 p.append(stemV); 166 if (stemH != 0) { 168 p.append("\n/StemH "); 169 p.append(stemH); 170 } 171 if (xHeight != 0) { 172 p.append("\n/XHeight "); 173 p.append(xHeight); 174 } 175 if (avgWidth != 0) { 176 p.append("\n/AvgWidth "); 177 p.append(avgWidth); 178 } 179 if (maxWidth != 0) { 180 p.append("\n/MaxWidth "); 181 p.append(maxWidth); 182 } 183 if (missingWidth != 0) { 184 p.append("\n/MissingWidth "); 185 p.append(missingWidth); 186 } 187 if (leading != 0) { 188 p.append("\n/Leading "); 189 p.append(leading); 190 } 191 if (fontfile != null) { 192 switch (subtype) { 193 case PDFFont.TYPE1: 194 p.append("\n/FontFile "); 195 break; 196 case PDFFont.TRUETYPE: 197 p.append("\n/FontFile2 "); 198 break; 199 case PDFFont.TYPE0: 200 p.append("\n/FontFile2 "); 201 break; 202 default: 203 p.append("\n/FontFile2 "); 204 } 205 p.append(fontfile.referencePDF()); 206 } 207 fillInPDF(p); 210 p.append("\n >>\nendobj\n"); 211 212 try { 213 return p.toString().getBytes(PDFDocument.ENCODING); 214 } catch (UnsupportedEncodingException ue) { 215 return p.toString().getBytes(); 216 } 217 } 218 219 226 protected void fillInPDF(StringBuffer begin) {} 227 228 } 229 | Popular Tags |