| 1 |
// Copyright 2007, FreeHEP |
| 2 |
package org.freehep.graphicsio.emf.gdi; |
| 3 |
|
| 4 |
import org.freehep.graphicsio.emf.EMFConstants; |
| 5 |
import org.freehep.graphicsio.emf.EMFTag; |
| 6 |
import org.freehep.graphicsio.emf.EMFRenderer; |
| 7 |
import org.freehep.graphicsio.emf.EMFOutputStream; |
| 8 |
|
| 9 |
import java.awt.Rectangle; |
| 10 |
import java.io.IOException; |
| 11 |
|
| 12 |
/** |
| 13 |
* Abstraction of commonality between the {@link ExtTextOutA} and {@link ExtTextOutW} tags. |
| 14 |
* |
| 15 |
* @author Daniel Noll ([email protected]) |
| 16 |
* @version $Id: freehep-graphicsio-emf/src/main/java/org/freehep/graphicsio/emf/gdi/AbstractExtTextOut.java bdaaed6f344d 2007/02/12 04:08:30 duns $ |
| 17 |
*/ |
| 18 |
public abstract class AbstractExtTextOut extends EMFTag implements EMFConstants { |
| 19 |
|
| 20 |
private Rectangle bounds; |
| 21 |
|
| 22 |
private int mode; |
| 23 |
|
| 24 |
private float xScale, yScale; |
| 25 |
|
| 26 |
/** |
| 27 |
* Constructs the tag. |
| 28 |
* |
| 29 |
* @param id id of the element |
| 30 |
* @param version emf version in which this element was first supported |
| 31 |
* @param bounds text boundary |
| 32 |
* @param mode text mode |
| 33 |
* @param xScale horizontal scale factor |
| 34 |
* @param yScale vertical scale factor |
| 35 |
*/ |
| 36 |
protected AbstractExtTextOut( |
| 37 |
int id, |
| 38 |
int version, |
| 39 |
Rectangle bounds, |
| 40 |
int mode, |
| 41 |
float xScale, |
| 42 |
float yScale) { |
| 43 |
|
| 44 |
super(id, version); |
| 45 |
this.bounds = bounds; |
| 46 |
this.mode = mode; |
| 47 |
this.xScale = xScale; |
| 48 |
this.yScale = yScale; |
| 49 |
} |
| 50 |
|
| 51 |
public abstract Text getText(); |
| 52 |
|
| 53 |
public String toString() { |
| 54 |
return super.toString() + |
| 55 |
"\n bounds: " + bounds + |
| 56 |
"\n mode: " + mode + |
| 57 |
"\n xScale: " + xScale + |
| 58 |
"\n yScale: " + yScale + |
| 59 |
"\n" + getText().toString(); |
| 60 |
} |
| 61 |
|
| 62 |
public void write(int tagID, EMFOutputStream emf) throws IOException { |
| 63 |
emf.writeRECTL(bounds); |
| 64 |
emf.writeDWORD(mode); |
| 65 |
emf.writeFLOAT(xScale); |
| 66 |
emf.writeFLOAT(yScale); |
| 67 |
getText().write(emf); |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* displays the tag using the renderer |
| 72 |
* |
| 73 |
* @param renderer EMFRenderer storing the drawing session data |
| 74 |
*/ |
| 75 |
public void render(EMFRenderer renderer) { |
| 76 |
Text text = getText(); |
| 77 |
renderer.drawOrAppendText( |
| 78 |
text.getString(), |
| 79 |
text.getPos().getX(), |
| 80 |
text.getPos().getY()); |
| 81 |
} |
| 82 |
} |