1 51 package org.apache.fop.pdf; 52 53 import java.io.UnsupportedEncodingException ; 55 import java.util.Iterator ; 56 import java.util.HashMap ; 57 import java.util.ArrayList ; 58 59 69 public class PDFEncoding extends PDFObject { 70 71 74 public static final String MacRomanEncoding = "MacRomanEncoding"; 75 76 79 public static final String MacExpertEncoding = "MacExpertEncoding"; 80 81 84 public static final String WinAnsiEncoding = "WinAnsiEncoding"; 85 86 91 protected String basename; 92 93 96 protected HashMap differences; 97 98 104 public PDFEncoding(int number, String basename) { 105 106 107 super(number); 108 109 110 this.basename = basename; 111 this.differences = new HashMap (); 112 } 113 114 120 public void addDifferences(int code, ArrayList sequence) { 121 differences.put(new Integer (code), sequence); 122 } 123 124 129 public byte[] toPDF() { 130 StringBuffer p = new StringBuffer (); 131 p.append(this.number + " " + this.generation 132 + " obj\n<< /Type /Encoding"); 133 if ((basename != null) && (!basename.equals(""))) { 134 p.append("\n/BaseEncoding /" + this.basename); 135 } 136 if (!differences.isEmpty()) { 137 p.append("\n/Differences [ "); 138 Object code; 139 Iterator codes = differences.keySet().iterator(); 140 while (codes.hasNext()) { 141 code = codes.next(); 142 p.append(" "); 143 p.append(code); 144 ArrayList sequence = (ArrayList )differences.get(code); 145 for (int i = 0; i < sequence.size(); i++) { 146 p.append(" /"); 147 p.append((String )sequence.get(i)); 148 } 149 } 150 p.append(" ]"); 151 } 152 p.append(" >>\nendobj\n"); 153 154 try { 155 return p.toString().getBytes(PDFDocument.ENCODING); 156 } catch (UnsupportedEncodingException ue) { 157 return p.toString().getBytes(); 158 } 159 } 160 161 172 } 173 | Popular Tags |