1 51 package org.apache.fop.pdf; 52 53 import java.io.UnsupportedEncodingException ; 55 56 58 61 public class PDFCIDFont extends PDFObject { 62 63 public static final byte CID_TYPE0 = 0; 64 public static final byte CID_TYPE2 = 1; 65 protected static final String [] TYPE_NAMES = { 66 "CIDFontType0", "CIDFontType2" 67 }; 68 69 protected String basefont; 70 71 protected String cidtype; 72 protected Integer dw; 73 protected PDFWArray w; 74 protected int[] dw2; 75 protected PDFWArray w2; 76 protected PDFCIDSystemInfo systemInfo; 77 protected PDFCIDFontDescriptor descriptor; 78 protected PDFCMap cmap; 79 80 84 protected PDFStream cidMap; 85 86 88 91 public PDFCIDFont(int number, String basefont, byte cidtype, int dw, 92 int[] w, String registry, String ordering, 93 int supplement, PDFCIDFontDescriptor descriptor) { 94 95 super(number); 96 97 this.basefont = basefont; 98 this.cidtype = TYPE_NAMES[(int)cidtype]; 99 this.dw = new Integer (dw); 100 this.w = new PDFWArray(); 101 this.w.addEntry(0, w); 102 this.dw2 = null; 103 this.w2 = null; 104 this.systemInfo = new PDFCIDSystemInfo(registry, ordering, 105 supplement); 106 this.descriptor = descriptor; 107 this.cidMap = null; 108 this.cmap = null; 109 } 110 111 114 public PDFCIDFont(int number, String basefont, byte cidtype, int dw, 115 PDFWArray w, PDFCIDSystemInfo systemInfo, 116 PDFCIDFontDescriptor descriptor) { 117 118 super(number); 119 120 this.basefont = basefont; 121 this.cidtype = TYPE_NAMES[(int)cidtype]; 122 this.dw = new Integer (dw); 123 this.w = w; 124 this.dw2 = null; 125 this.w2 = null; 126 this.systemInfo = systemInfo; 127 this.descriptor = descriptor; 128 this.cidMap = null; 129 this.cmap = null; 130 } 131 132 135 public void setDW(int dw) { 136 this.dw = new Integer (dw); 137 } 138 139 142 public void setW(PDFWArray w) { 143 this.w = w; 144 } 145 146 149 public void setDW2(int[] dw2) { 150 this.dw2 = dw2; 151 } 152 153 156 public void setDW2(int posY, int displacementY) { 157 this.dw2 = new int[] { 158 posY, displacementY 159 }; 160 } 161 162 165 public void setCMAP(PDFCMap cmap) { 166 this.cmap = cmap; 167 } 168 169 172 public void setW2(PDFWArray w2) { 173 this.w2 = w2; 174 } 175 176 179 public void setCIDMap(PDFStream map) { 180 this.cidMap = map; 181 } 182 183 186 public void setCIDMapIdentity() { 187 this.cidMap = null; } 189 190 195 public byte[] toPDF() { 196 try { 197 return toPDFString().getBytes(PDFDocument.ENCODING); 198 } catch (UnsupportedEncodingException ue) { 199 return toPDFString().getBytes(); 200 } 201 } 202 203 public String toPDFString() { 204 StringBuffer p = new StringBuffer (); 205 p.append(this.number); 206 p.append(" "); 207 p.append(this.generation); 208 p.append(" obj\n<< /Type /Font"); 209 p.append("\n/BaseFont /"); 210 p.append(this.basefont); 211 if (cidMap != null) { 212 p.append(" \n/CIDToGIDMap "); 213 p.append(cidMap.referencePDF()); 214 } 215 p.append(" \n/Subtype /"); 216 p.append(this.cidtype); 217 p.append("\n"); 218 p.append(systemInfo.toPDFString()); 219 p.append("\n/FontDescriptor "); 220 p.append(this.descriptor.referencePDF()); 221 222 if (cmap != null) { 223 p.append("\n/ToUnicode "); 224 p.append(cmap.referencePDF()); 225 } 226 if (dw != null) { 227 p.append("\n/DW "); 228 p.append(this.dw); 229 } 230 if (w != null) { 231 p.append("\n/W "); 232 p.append(w.toPDFString()); 233 } 234 if (dw2 != null) { 235 p.append("\n/DW2 ["); p.append(this.dw2[0]); 237 p.append(this.dw2[1]); 238 p.append("] \n>>\nendobj\n"); 239 } 240 if (w2 != null) { 241 p.append("\n/W2 "); 242 p.append(w2.toPDFString()); 243 p.append(" \n>>\nendobj\n"); 244 } 245 p.append(" \n>>\nendobj\n"); 246 return p.toString(); 247 } 248 249 } 250 251 | Popular Tags |