blob: ba7b874b467bc504beae3d825435ff9e19809a21 (
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
|
/*
* Copyright (c) 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Andre Weinand, OTI - Initial version
*/
package org.eclipse.swt.internal.carbon;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
public class MacFont {
public short fID= 1;
public short fSize= 12;
public short fFace= 0;
public MacFont() {
}
public MacFont(String name, int size, int face) {
fFace= OS.normal;
if ((face & SWT.BOLD) != 0)
fFace |= OS.bold;
if ((face & SWT.ITALIC) != 0)
fFace |= OS.italic;
if ("Courier".equals(name)) {
name= "Monaco";
}
if ("MS Sans Serif".equals(name)) {
MacFont f= Display.getThemeFont(OS.kThemeSystemFont);
fID= f.fID;
fSize= f.fSize;
return;
}
if (size < 10)
size= 10;
short id= OS.FMGetFontFamilyFromName(MacUtil.Str255(name));
//System.out.print("MacFont(" + name + ", " + size + ", " + face + "): ");
if (id == OS.kInvalidFontFamily) {
fID= (short) 1;
//System.out.println("not found");
} else {
fID= id;
//System.out.println(fID);
}
fSize= (short)size;
}
public MacFont(short ID, short size, short face) {
fID= ID;
fSize= size;
fFace= OS.normal;
if ((face & SWT.BOLD) != 0)
fFace |= OS.bold;
if ((face & SWT.ITALIC) != 0)
fFace |= OS.italic;
}
public MacFont(short ID) {
fID= ID;
}
public String getName() {
byte[] name= new byte[256];
if (OS.FMGetFontFamilyName(fID, name) == OS.kNoErr)
return MacUtil.toString(name);
return "no name";
}
public short getSize() {
return fSize;
}
public int getFace() {
int face= 0;
if ((fFace & OS.bold) != 0)
face |= SWT.BOLD;
if ((fFace & OS.italic) != 0)
face |= SWT.ITALIC;
return face;
}
public void installInGrafPort() {
OS.TextFont(fID);
OS.TextSize(fSize);
OS.TextFace(fFace);
}
public boolean equals(Object object) {
if (object == this) return true;
if (!(object instanceof MacFont)) return false;
MacFont font= (MacFont) object;
return fID == font.fID && fSize == font.fSize && fFace == font.fFace;
}
public int hashCode() {
return (fID << 16) | (fSize << 8) | fFace;
}
public String toString() {
return fID + "," + fSize + "," + fFace;
}
}
|