Debian Codegraph @

freehep-graphicsio-emf/src/main/java/org/freehep/graphicsio/emf/gdi/TextW.java

raw
1 // Copyright 2002-2007, FreeHEP.
2 package org.freehep.graphicsio.emf.gdi;
3
4 import java.awt.Point;
5 import java.awt.Rectangle;
6 import java.io.IOException;
7
8 import org.freehep.graphicsio.emf.EMFInputStream;
9 import org.freehep.graphicsio.emf.EMFOutputStream;
10
11 /**
12 * EMF Text
13 *
14 * @author Mark Donszelmann
15 * @version $Id: freehep-graphicsio-emf/src/main/java/org/freehep/graphicsio/emf/gdi/TextW.java c0f15e7696d3 2007/01/22 19:26:48 duns $
16 */
17 public class TextW extends Text {
18
19 public TextW(Point pos, String string, int options, Rectangle bounds, int[] widths) {
20 super(pos, string, options, bounds, widths);
21 }
22
23 public static TextW read(EMFInputStream emf) throws IOException {
24 Point pos = emf.readPOINTL();
25 int sLen = emf.readDWORD();
26 /* int sOffset = */ emf.readDWORD();
27 int options = emf.readDWORD();
28 Rectangle bounds = emf.readRECTL();
29 /* int cOffset = */ emf.readDWORD();
30 // FIXME: nothing done with offsets
31 String string = new String(emf.readBYTE(2 * sLen), "UTF-16LE");
32 if ((2 * sLen) % 4 != 0)
33 for (int i = 0; i < 4 - (2 * sLen) % 4; i++)
34 emf.readBYTE();
35 int[] widths = new int[sLen];
36 for (int i = 0; i < sLen; i++)
37 widths[i] = emf.readDWORD();
38 return new TextW(pos, string, options, bounds, widths);
39 }
40
41 public void write(EMFOutputStream emf) throws IOException {
42 emf.writePOINTL(pos);
43 emf.writeDWORD(string.length());
44 emf.writeDWORD(8 + 28 + 40); // TagHeader + ExtTextOutA + Text
45 emf.writeDWORD(options);
46 emf.writeRECTL(bounds);
47 int pad = (2 * string.length()) % 4;
48 if (pad > 0)
49 pad = 4 - pad;
50 emf.writeDWORD(8 + 28 + 40 + 2 * string.length() + pad); // offset to
51 // character
52 // spacing
53 // array
54 emf.writeBYTE(string.getBytes("UTF-16LE"));
55 for (int i = 0; i < pad; i++)
56 emf.writeBYTE(0);
57 for (int i = 0; i < string.length(); i++)
58 emf.writeDWORD(widths[i]);
59 }
60
61 public String toString() {
62 StringBuffer widthsS = new StringBuffer();
63 for (int i = 0; i < string.length(); i++) {
64 widthsS.append(",");
65 widthsS.append(widths[i]);
66 }
67 widthsS.append(']');
68 widthsS.setCharAt(0, '[');
69 return " TextW\n" + " pos: " + pos +
70 "\n options: " + options +
71 "\n bounds: " + bounds +
72 "\n string: " + string +
73 "\n widths: " + widthsS;
74 }
75 }