1 package org.freehep.graphicsio.emf.gdi;
2
3 import java.awt.Point;
4 import java.awt.Rectangle;
5 import java.io.IOException;
6
7 import org.freehep.graphicsio.emf.EMFInputStream;
8 import org.freehep.graphicsio.emf.EMFOutputStream;
9
10 public class TextA extends Text {
11
12 public TextA(Point pos, String string, int options, Rectangle bounds, int[] widths) {
13 super(pos, string, options, bounds, widths);
14 }
15
16 public static TextA read(EMFInputStream emf) throws IOException {
17 Point pos = emf.readPOINTL();
18 int sLen = emf.readDWORD();
19
20 int options = emf.readDWORD();
21 Rectangle bounds = emf.readRECTL();
22
23
24 String string = new String(emf.readBYTE(sLen));
25 if ((sLen) % 4 != 0)
26 for (int i = 0; i < 4 - (sLen) % 4; i++)
27 emf.readBYTE();
28 int[] widths = new int[sLen];
29 for (int i = 0; i < sLen; i++)
30 widths[i] = emf.readDWORD();
31 return new TextA(pos, string, options, bounds, widths);
32 }
33
34 public void write(EMFOutputStream emf) throws IOException {
35 emf.writePOINTL(pos);
36 emf.writeDWORD(string.length());
37 emf.writeDWORD(8 + 28 + 40);
38 emf.writeDWORD(options);
39 emf.writeRECTL(bounds);
40 int pad = (string.length()) % 4;
41 if (pad > 0)
42 pad = 4 - pad;
43 emf.writeDWORD(8 + 28 + 40 + string.length() + pad);
44
45
46 emf.writeBYTE(string.getBytes());
47 for (int i = 0; i < pad; i++)
48 emf.writeBYTE(0);
49 for (int i = 0; i < string.length(); i++)
50 emf.writeDWORD(widths[i]);
51 }
52
53 public String toString() {
54 StringBuffer widthsS = new StringBuffer();
55 for (int i = 0; i < string.length(); i++) {
56 widthsS.append(",");
57 widthsS.append(widths[i]);
58 }
59 widthsS.append(']');
60 widthsS.setCharAt(0, '[');
61 return " TextA\n" + " pos: " + pos +
62 "\n options: " + options +
63 "\n bounds: " + bounds +
64 "\n string: " + string +
65 "\n widths: " + widthsS;
66 }
67 }