Skip to main content
summaryrefslogtreecommitdiffstats
blob: a28e21da9fd68758e80c12ae229a8cedf65e6d8d (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
189
190
191
192
193
194
195
196
197
198
/*******************************************************************************
 * Copyright (c) 2004 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.css.core.internal.contentmodel;



import java.util.Collection;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

/**
 * 
 */
public class PropCMFontProperty extends PropCMProperty {

	// static fields
	private static java.util.Hashtable instances = null;
	private static java.util.Hashtable cachedIdMap = null;
	// selecting properties
	public final static String PF_FONT_FAMILY = "font-family";//$NON-NLS-1$
	public final static String PF_FONT_STYLE = "font-style";//$NON-NLS-1$
	public final static String PF_FONT_VARIANT = "font-variant";//$NON-NLS-1$
	public final static String PF_FONT_WEIGHT = "font-weight";//$NON-NLS-1$
	public final static String PF_FONT_STRETCH = "font-stretch";//$NON-NLS-1$
	public final static String PF_FONT_SIZE = "font-size";//$NON-NLS-1$
	// qualification properties
	public final static String PF_UNICODE_RANGE = "unicode-range";//$NON-NLS-1$
	// numeric properties
	public final static String PF_UNITS_PER_EM = "units-per-em";//$NON-NLS-1$
	// referencing properties
	public final static String PF_SRC = "src";//$NON-NLS-1$
	// matching properties
	public final static String PF_PANOSE_1 = "panose-1";//$NON-NLS-1$
	public final static String PF_STEMV = "stemv";//$NON-NLS-1$
	public final static String PF_STEMH = "stemh";//$NON-NLS-1$
	public final static String PF_SLOPE = "slope";//$NON-NLS-1$
	public final static String PF_CAP_HEIGHT = "cap-height";//$NON-NLS-1$
	public final static String PF_X_HEIGHT = "x-height";//$NON-NLS-1$
	public final static String PF_ASCENT = "ascent";//$NON-NLS-1$
	public final static String PF_DESCENT = "descent";//$NON-NLS-1$
	// synthesis properties
	public final static String PF_WIDTHS = "widths";//$NON-NLS-1$
	public final static String PF_BBOX = "bbox";//$NON-NLS-1$
	public final static String PF_DEFINITION_SRC = "definition-src";//$NON-NLS-1$
	// alignment properties
	public final static String PF_BASELINE = "baseline";//$NON-NLS-1$
	public final static String PF_CENTERLINE = "centerline";//$NON-NLS-1$
	public final static String PF_MATHLINE = "mathline";//$NON-NLS-1$
	public final static String PF_TOPLINE = "topline";//$NON-NLS-1$

	/**
	 * 
	 */
	protected PropCMFontProperty(String name) {
		super(name);
	}

	/**
	 * 
	 */
	public static PropCMProperty getInstanceOf(String name) {
		// initialize
		if (instances == null)
			instances = new Hashtable(10);

		// Initialize of DB
		if (isNeedInitialize())
			PropCMNode.initPropertyCM();

		// query
		Object node = instances.get(name);
		if (node != null)
			return (PropCMProperty) node;

		// register
		if (PropCMNode.isLoading()) {
			node = new PropCMFontProperty(name);
			instances.put(name, node);
		}

		return (PropCMProperty) node;
	}

	/**
	 * 
	 */
	public static Enumeration getNameEnum() {
		// Initialize of DB
		if (isNeedInitialize())
			PropCMNode.initPropertyCM();

		return instances.keys();
	}

	/**
	 * 
	 */
	public static Enumeration getPropertyEnum() {
		// Initialize of DB
		if (isNeedInitialize())
			PropCMNode.initPropertyCM();

		return instances.elements();
	}

	/**
	 * 
	 */
	public short getType() {
		return VAL_FONTPROPERTY;
	}

	/**
	 * 
	 */
	public static Vector names() {
		// Initialize of DB
		if (isNeedInitialize())
			PropCMNode.initPropertyCM();

		return new Vector(instances.keySet());
	}

	/**
	 * 
	 */
	public static List names(Object mediaGroup) {
		if (mediaGroup == null)
			return names();

		// Initialize of DB
		if (isNeedInitialize())
			PropCMNode.initPropertyCM();

		Vector properties = new Vector();

		Iterator it = instances.values().iterator();
		while (it.hasNext()) {
			PropCMProperty prop = (PropCMProperty) it.next();
			if (prop.getMediaGroups().contains(mediaGroup))
				properties.add(prop.getName());
		}

		return properties;
	}

	/**
	 * If itentifier is null, get all properties
	 */
	public static Vector propertiesFor(String identifier, boolean shorthands) {
		// Initialize of DB
		if (isNeedInitialize())
			PropCMNode.initPropertyCM();

		// if identifier is null, get all properties
		if (identifier == null)
			return new Vector(instances.values());

		if (cachedIdMap == null) {
			// start cacheing
			cachedIdMap = new Hashtable();
		}
		else {
			// search cached
			Object ret = cachedIdMap.get(identifier + String.valueOf(shorthands));
			if (ret != null)
				return new Vector((Collection) ret);
		}

		// create
		Enumeration properties = getPropertyEnum();
		HashSet set = new HashSet();
		while (properties.hasMoreElements()) {
			PropCMProperty prop = (PropCMProperty) properties.nextElement();
			if (!shorthands && prop.isShorthand())
				continue;
			if (prop.canHave(identifier))
				set.add(prop);
		}

		// cache
		cachedIdMap.put(identifier + String.valueOf(shorthands), set);

		return new Vector(set);
	}
}

Back to the top