Skip to main content
summaryrefslogtreecommitdiffstats
blob: b7e0fe27cebe1228325a03bcec9156f9deb2a0db (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package org.eclipse.swt.graphics;

/*
 * Licensed Materials - Property of IBM,
 * (c) Copyright IBM Corp. 1998, 2001  All Rights Reserved
 */

import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.photon.*;
import org.eclipse.swt.*;

public final class FontData {

	/**
	 * the font name
	 * (Warning: This field is platform dependent)
	 */
	String name;

	/**
	 * the font height
	 * (Warning: This field is platform dependent)
	 */
	int    height;

	/**
	 * the font style
	 * (Warning: This field is platform dependent)
	 */
	int    style;
	
	/**
	 * A Photon stem
	 * (Warning: This field is platform dependent)
	 */
	public byte[] stem;

FontData(byte[] stem) {
	FontQueryInfo info = new FontQueryInfo();
	if (OS.PfQueryFontInfo(stem, info) == 0) {
		this.stem = info.font;
		name = new String(Converter.mbcsToWcs(null, info.desc)).trim();
		if ((info.style & OS.PHFONT_INFO_PLAIN) != 0) style = SWT.NORMAL;
		else if ((info.style & OS.PHFONT_INFO_BOLD) != 0) style = SWT.BOLD;
		else if ((info.style & OS.PHFONT_INFO_ITALIC) != 0) style = SWT.ITALIC;
		else if ((info.style & OS.PHFONT_INFO_BLDITC) != 0) style = SWT.BOLD | SWT.ITALIC;
		else style = SWT.NORMAL;
		/*
		* For some reason, sometimes PfQueryFontInfo does not
		* set the size of the font.  In that case, the size is
		* parsed from the stem.
		*/
		if (info.size != 0) {
			height = info.size;
		} else {
			String fontName = new String(Converter.mbcsToWcs(null, this.stem)).trim();
			int end = fontName.length();
			for (int i = end - 1; i >= 0; i--) {
				if (Character.isDigit(fontName.charAt(i))) break;
				end--;
			}
			int start = end;
			for (int i = end - 1; i >= 0; i--) {
				if (!Character.isDigit(fontName.charAt(i))) break;
				start--;
			}
			try {
				height = Integer.parseInt(fontName.substring(start, end));
			} catch (NumberFormatException e) {}
		}
	} else {
		this.stem = stem;
	}
}

public FontData() {
	this("", 12, SWT.NORMAL);
}

public FontData(String string) {	
	if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
	int start = 0;
	int end = string.indexOf('|');
	if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
	String version1 = string.substring(start, end);
	
	start = end + 1;
	end = string.indexOf('|', start);
	if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
	String name = string.substring(start, end);
	
	start = end + 1;
	end = string.indexOf('|', start);
	if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
	int height = 0;
	try {
		height = Integer.parseInt(string.substring(start, end));
	} catch (NumberFormatException e) {
		SWT.error(SWT.ERROR_INVALID_ARGUMENT);
	}
	
	start = end + 1;
	end = string.indexOf('|', start);
	if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
	int style = 0;
	try {
		style = Integer.parseInt(string.substring(start, end));
	} catch (NumberFormatException e) {
		SWT.error(SWT.ERROR_INVALID_ARGUMENT);
	}

	start = end + 1;
	end = string.indexOf('|', start);
	setName(name);
	setHeight(height);
	setStyle(style);
	if (end == -1) return;
	String platform = string.substring(start, end);

	start = end + 1;
	end = string.indexOf('|', start);
	if (end == -1) return;
	String version2 = string.substring(start, end);

	if (platform.equals("PHOTON") && version2.equals("1")) {
		return;
	}
}

public FontData(String name, int height, int style) {
	setName(name);
	setHeight(height);
	setStyle(style);
}

public boolean equals (Object object) {
	if (object == this) return true;
	if (!(object instanceof FontData)) return false;
	FontData data = (FontData)object;
	return name == name && height == data.height && style == data.style;
}

public int getHeight() {
	return height;
}

public String getName() {
	return name;
}

public int getStyle() {
	return style;
}

public int hashCode () {
	return name.hashCode() ^ height ^ style;
}

public void setHeight(int height) {
	this.height = height;
}

public void setName(String name) {
	this.name = name;
}

public void setStyle(int style) {
	this.style = style;
}

public String toString() {
	StringBuffer buffer = new StringBuffer();
	buffer.append("1|");
	buffer.append(getName());
	buffer.append("|");
	buffer.append(getHeight());
	buffer.append("|");
	buffer.append(getStyle());
	buffer.append("|");
	buffer.append("PHOTON|1|");	
	return buffer.toString();
}

public static FontData photon_new(byte[] stem) {
	return new FontData(stem);
}

}

Back to the top