1 51 package org.apache.fop.pdf; 52 53 import java.io.UnsupportedEncodingException ; 55 import java.util.ArrayList ; 56 57 60 public class PDFWArray { 61 62 65 private ArrayList entries; 66 67 public PDFWArray() { 68 entries = new ArrayList (); 69 } 70 71 78 public void addEntry(int start, int[] metrics) { 79 entries.add(new Entry(start, metrics)); 80 } 81 82 89 public void addEntry(int first, int last, int width) { 90 entries.add(new int[] { 91 first, last, width 92 }); 93 } 94 95 104 public void addEntry(int first, int last, int width, int posX, int posY) { 105 entries.add(new int[] { 106 first, last, width, posX, posY 107 }); 108 } 109 110 public byte[] toPDF() { 111 try { 112 return toPDFString().getBytes(PDFDocument.ENCODING); 113 } catch (UnsupportedEncodingException ue) { 114 return toPDFString().getBytes(); 115 } 116 } 117 118 public String toPDFString() { 119 StringBuffer p = new StringBuffer (); 120 p.append("[ "); 121 int len = entries.size(); 122 for (int i = 0; i < len; i++) { 123 Object entry = entries.get(i); 124 if (entry instanceof int[]) { 125 int[] line = (int[])entry; 126 for (int j = 0; j < line.length; j++) { 127 p.append(line[j]); 128 p.append(" "); 129 } 130 } else { 131 ((Entry)entry).fillInPDF(p); 132 } 133 } 134 p.append("]"); 135 return p.toString(); 136 } 137 138 141 private static class Entry { 142 private static final StringBuffer p = new StringBuffer (); 143 private int start; 144 private int[] metrics; 145 public Entry(int s, int[] m) { 146 start = s; 147 metrics = m; 148 } 149 150 public void fillInPDF(StringBuffer p) { 151 p.append(start); 153 p.append(" ["); 154 for (int i = 0; i < metrics.length; i++) { 155 p.append(this.metrics[i]); 156 p.append(" "); 157 } 158 p.append("] "); 159 } 160 161 } 162 } 163 | Popular Tags |