| 1 |
// Copyright 2002, FreeHEP. |
| 2 |
package org.freehep.graphicsio.emf.gdi; |
| 3 |
|
| 4 |
import java.awt.Font; |
| 5 |
import java.io.IOException; |
| 6 |
|
| 7 |
import org.freehep.graphicsio.emf.EMFConstants; |
| 8 |
import org.freehep.graphicsio.emf.EMFInputStream; |
| 9 |
import org.freehep.graphicsio.emf.EMFOutputStream; |
| 10 |
import org.freehep.graphicsio.emf.EMFRenderer; |
| 11 |
|
| 12 |
/** |
| 13 |
* EMF LogFontW |
| 14 |
* |
| 15 |
* @author Mark Donszelmann |
| 16 |
* @version $Id: freehep-graphicsio-emf/src/main/java/org/freehep/graphicsio/emf/gdi/LogFontW.java c0f15e7696d3 2007/01/22 19:26:48 duns $ |
| 17 |
*/ |
| 18 |
public class LogFontW implements EMFConstants, GDIObject { |
| 19 |
|
| 20 |
private int height; |
| 21 |
|
| 22 |
private int width; |
| 23 |
|
| 24 |
private int escapement; |
| 25 |
|
| 26 |
private int orientation; |
| 27 |
|
| 28 |
private int weight; |
| 29 |
|
| 30 |
private boolean italic; |
| 31 |
|
| 32 |
private boolean underline; |
| 33 |
|
| 34 |
private boolean strikeout; |
| 35 |
|
| 36 |
private int charSet; |
| 37 |
|
| 38 |
private int outPrecision; |
| 39 |
|
| 40 |
private int clipPrecision; |
| 41 |
|
| 42 |
private int quality; |
| 43 |
|
| 44 |
private int pitchAndFamily; |
| 45 |
|
| 46 |
private String faceFamily; |
| 47 |
|
| 48 |
/** |
| 49 |
* cache for getFont() |
| 50 |
*/ |
| 51 |
private Font font; |
| 52 |
|
| 53 |
public LogFontW(int height, int width, int escapement, int orientation, |
| 54 |
int weight, boolean italic, boolean underline, boolean strikeout, |
| 55 |
int charSet, int outPrecision, int clipPrecision, int quality, |
| 56 |
int pitchAndFamily, String faceFamily) { |
| 57 |
this.height = height; |
| 58 |
this.width = width; |
| 59 |
this.escapement = escapement; |
| 60 |
this.orientation = orientation; |
| 61 |
this.weight = weight; |
| 62 |
this.italic = italic; |
| 63 |
this.underline = underline; |
| 64 |
this.strikeout = strikeout; |
| 65 |
this.charSet = charSet; |
| 66 |
this.outPrecision = outPrecision; |
| 67 |
this.clipPrecision = clipPrecision; |
| 68 |
this.quality = quality; |
| 69 |
this.pitchAndFamily = pitchAndFamily; |
| 70 |
this.faceFamily = faceFamily; |
| 71 |
} |
| 72 |
|
| 73 |
public LogFontW(Font font) { |
| 74 |
this.height = -font.getSize(); |
| 75 |
this.width = 0; |
| 76 |
this.escapement = 0; |
| 77 |
this.orientation = 0; |
| 78 |
this.weight = font.isBold() ? FW_BOLD : FW_NORMAL; |
| 79 |
this.italic = font.isItalic(); |
| 80 |
this.underline = false; |
| 81 |
this.strikeout = false; |
| 82 |
this.charSet = 0; // ANSI_CHARSET; |
| 83 |
this.outPrecision = 0; // OUT_DEFAULT_PRECIS; |
| 84 |
this.clipPrecision = 0; // CLIP_DEFAULT_PRECIS; |
| 85 |
this.quality = 5; // CLEARTYPE_QUALITY; |
| 86 |
this.pitchAndFamily = 0; |
| 87 |
this.faceFamily = font.getName(); |
| 88 |
} |
| 89 |
|
| 90 |
public LogFontW(EMFInputStream emf) throws IOException { |
| 91 |
height = emf.readLONG(); |
| 92 |
width = emf.readLONG(); |
| 93 |
escapement = emf.readLONG(); |
| 94 |
orientation = emf.readLONG(); |
| 95 |
weight = emf.readLONG(); |
| 96 |
italic = emf.readBOOLEAN(); |
| 97 |
underline = emf.readBOOLEAN(); |
| 98 |
strikeout = emf.readBOOLEAN(); |
| 99 |
charSet = emf.readBYTE(); |
| 100 |
outPrecision = emf.readBYTE(); |
| 101 |
clipPrecision = emf.readBYTE(); |
| 102 |
quality = emf.readBYTE(); |
| 103 |
pitchAndFamily = emf.readBYTE(); |
| 104 |
faceFamily = emf.readWCHAR(32); |
| 105 |
} |
| 106 |
|
| 107 |
public void write(EMFOutputStream emf) throws IOException { |
| 108 |
emf.writeLONG(height); |
| 109 |
emf.writeLONG(width); |
| 110 |
emf.writeLONG(escapement); |
| 111 |
emf.writeLONG(orientation); |
| 112 |
emf.writeLONG(weight); |
| 113 |
emf.writeBYTE(italic); |
| 114 |
emf.writeBYTE(underline); |
| 115 |
emf.writeBYTE(strikeout); |
| 116 |
emf.writeBYTE(charSet); |
| 117 |
emf.writeBYTE(outPrecision); |
| 118 |
emf.writeBYTE(clipPrecision); |
| 119 |
emf.writeBYTE(quality); |
| 120 |
emf.writeBYTE(pitchAndFamily); |
| 121 |
emf.writeWCHAR(faceFamily, 32); |
| 122 |
} |
| 123 |
|
| 124 |
public Font getFont() { |
| 125 |
if (font == null) { |
| 126 |
int style = 0; |
| 127 |
if (italic) { |
| 128 |
style |= Font.ITALIC; |
| 129 |
} |
| 130 |
|
| 131 |
// 400 is considered to be normal. |
| 132 |
if (weight > 400) { |
| 133 |
style |= Font.BOLD; |
| 134 |
} |
| 135 |
|
| 136 |
int size = Math.abs(height); |
| 137 |
font = new Font(faceFamily, style, size); |
| 138 |
|
| 139 |
} |
| 140 |
return font; |
| 141 |
} |
| 142 |
|
| 143 |
public String toString() { |
| 144 |
return " LogFontW\n" + " height: " + height + |
| 145 |
"\n width: " + width + |
| 146 |
"\n orientation: " + orientation + |
| 147 |
"\n weight: " + weight + |
| 148 |
"\n italic: " + italic + |
| 149 |
"\n underline: " + underline + |
| 150 |
"\n strikeout: " + strikeout + |
| 151 |
"\n charSet: " + charSet + |
| 152 |
"\n outPrecision: " + outPrecision + |
| 153 |
"\n clipPrecision: " + clipPrecision + |
| 154 |
"\n quality: " + quality + |
| 155 |
"\n pitchAndFamily: " + pitchAndFamily + |
| 156 |
"\n faceFamily: " + faceFamily; |
| 157 |
} |
| 158 |
|
| 159 |
/** |
| 160 |
* displays the tag using the renderer |
| 161 |
* |
| 162 |
* @param renderer EMFRenderer storing the drawing session data |
| 163 |
*/ |
| 164 |
public void render(EMFRenderer renderer) { |
| 165 |
// TODO: See if this ever happens. |
| 166 |
renderer.setFont(font); |
| 167 |
} |
| 168 |
} |