1
2 package org.freehep.graphicsio.pdf;
3
4 import java.io.IOException;
5
6 import org.freehep.graphics2d.font.CharTable;
7 import org.freehep.graphicsio.font.FontEmbedder;
8
9 public class PDFCharTableWriter implements PDFRedundanceTracker.Writer {
10
11 private static PDFCharTableWriter ctw;
12
13 public static PDFCharTableWriter getInstance() {
14 if (ctw == null)
15 ctw = new PDFCharTableWriter();
16 return ctw;
17 }
18
19 public void writeObject(Object object, PDFRef ref, PDFWriter pdf)
20 throws IOException {
21
22 CharTable charTable = (CharTable) object;
23
24 PDFDictionary encoding = pdf.openDictionary(ref.getName());
25 encoding.entry("Type", pdf.name("Encoding"));
26
27 Object[] differences = new Object[257];
28 differences[0] = new Integer(0);
29 for (int i = 0; i < 256; i++) {
30 String charName = charTable.toName(i);
31 differences[i + 1] = (charName != null) ? pdf.name(charName) : pdf
32 .name(FontEmbedder.NOTDEF);
33 }
34 encoding.entry("Differences", differences);
35
36 pdf.close(encoding);
37 }
38 }