Skip to main content
summaryrefslogtreecommitdiffstats
blob: 646da8635c30b7f05d737f3304814307f013d16c (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
/*******************************************************************************
 * Copyright (c) 2006 Sybase, Inc. and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Sybase, Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.pagedesigner.css2.font;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;

/**
 * @author mengbo
 */
public class CSSFont implements ICSSFont {
	private String _family;

	private int _size;

	private int _style;

	private int _weight;

	private String _cssString;

	/**
	 * @param family 
	 * @param size 
	 * @param style 
	 * @param weight 
	 * @param cssString 
	 * 
	 */
	public CSSFont(String family, int size, int style, int weight,
			String cssString) {
		this._family = family;
		this._size = size;
		this._style = style;
		this._weight = weight;
		_cssString = cssString;
	}

	public String getFontFamily() {
		return _family;
	}

	public int getFontSize() {
		return _size;
	}

	public int getFontStyle() {
		return _style;
	}

	public String getCSSString() {
		return _cssString;
	}

	public int getWeight() {
		return _weight;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals(Object obj) {
		if (obj instanceof CSSFont) {
			CSSFont fd = (CSSFont) obj;
			return this._family.equals(fd._family) && this._size == fd._size
					&& this._style == fd._style && this._weight == fd._weight;
		}
        return false;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return _family.hashCode() + _size + _style + _weight;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jst.pagedesigner.css2.font.ICSSFont#getSwtFont()
	 */
	public Font getSwtFont() {
		// return FontPoolManager.getInstance().getFont(this);
		return CSSFontManager.getInstance().getSwtFont(this);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jst.pagedesigner.css2.font.ICSSFont#getXHeight()
	 */
	public int getXHeight() {
		return getFontSize();
	}

	/**
	 * @return the style mask for the font style
	 */
	public int getSwtFontStyle() {
		int style = SWT.NONE;
		// see:http://www.htmlhelp.com/reference/css/font/font-weight.html
		if (getWeight() >= 600)
			style |= SWT.BOLD;
		style |= getFontStyle();
		return style;
	}
}

Back to the top