001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Alexey A. Ivanov
019: * @version $Revision$
020: */package javax.swing.text.html;
021:
022: import javax.swing.BasicSwingTestCase;
023: import javax.swing.text.MutableAttributeSet;
024: import javax.swing.text.SimpleAttributeSet;
025: import javax.swing.text.html.CSS.Attribute;
026:
027: public class StyleSheet_ConvertAttr_FontTest extends BasicSwingTestCase {
028: private StyleSheet ss;
029: private MutableAttributeSet simple;
030:
031: private String sansSerif;
032:
033: protected void setUp() throws Exception {
034: super .setUp();
035: ss = new StyleSheet();
036: simple = new SimpleAttributeSet();
037:
038: sansSerif = isHarmony() ? "sans-serif" : "SansSerif";
039: }
040:
041: // Invalid values
042: public void testFont01() {
043: ss.addCSSAttribute(simple, Attribute.FONT, "normal");
044: if (isHarmony()) {
045: assertEquals(0, simple.getAttributeCount());
046: return;
047: }
048:
049: assertAttributes("normal", "normal", "normal", "medium",
050: "normal", sansSerif);
051: }
052:
053: public void testFont02() {
054: ss.addCSSAttribute(simple, Attribute.FONT, "12pt");
055: if (isHarmony()) {
056: assertEquals(0, simple.getAttributeCount());
057: return;
058: }
059:
060: assertAttributes("normal", "normal", "normal", "12pt",
061: "normal", sansSerif);
062: }
063:
064: public void testFont03() {
065: ss.addCSSAttribute(simple, Attribute.FONT, "monospace");
066: if (isHarmony()) {
067: assertEquals(0, simple.getAttributeCount());
068: return;
069: }
070:
071: assertAttributes("normal", "normal", "normal",
072: /*size*/"monospace", "normal", /*family*/sansSerif);
073: }
074:
075: // Valid values
076: public void testFont05() {
077: ss.addCSSAttribute(simple, Attribute.FONT, "small serif");
078: assertAttributes("normal", "normal", "normal", "small",
079: "normal", "serif");
080: }
081:
082: public void testFont06() {
083: ss
084: .addCSSAttribute(simple, Attribute.FONT,
085: "italic small serif");
086: assertAttributes("italic", "normal", "normal", "small",
087: "normal", "serif");
088: }
089:
090: public void testFont07() {
091: ss.addCSSAttribute(simple, Attribute.FONT,
092: "italic bold small serif");
093: assertAttributes("italic", "normal", "bold", "small", "normal",
094: "serif");
095: }
096:
097: public void testFont08() {
098: ss.addCSSAttribute(simple, Attribute.FONT,
099: "bold italic small serif");
100: assertAttributes("italic", "normal", "bold", "small", "normal",
101: "serif");
102: }
103:
104: public void testFont09() {
105: ss.addCSSAttribute(simple, Attribute.FONT,
106: "bold small-caps italic small serif");
107: assertAttributes("italic", "small-caps", "bold", "small",
108: "normal", "serif");
109: }
110:
111: public void testFont10() {
112: ss.addCSSAttribute(simple, Attribute.FONT,
113: "bold normal small-caps italic small serif");
114: if (isHarmony()) {
115: assertEquals(0, simple.getAttributeCount());
116: return;
117: }
118: assertAttributes("normal", "small-caps", "bold",
119: /*size*/"italic", "normal", "small serif");
120: }
121:
122: public void testFont11() {
123: ss.addCSSAttribute(simple, Attribute.FONT,
124: "bold small-caps italic normal small serif");
125: if (isHarmony()) {
126: assertEquals(0, simple.getAttributeCount());
127: return;
128: }
129: assertAttributes("italic", "small-caps", "bold",
130: /*size*/"normal", "normal", "small serif");
131: }
132:
133: public void testFont12() {
134: ss.addCSSAttribute(simple, Attribute.FONT,
135: "bold italic large 'Times New Roman', Garamond, serif");
136: assertAttributes("italic", "normal", "bold", "large", "normal",
137: "'Times New Roman', Garamond, serif");
138: }
139:
140: public void testFont13() {
141: ss.addCSSAttribute(simple, Attribute.FONT,
142: "larger/1.2 Arial, Verdana, sans-serif");
143: assertAttributes("normal", "normal", "normal", "larger", "1.2",
144: "Arial, Verdana, sans-serif");
145: }
146:
147: public void testFont14() {
148: ss.addCSSAttribute(simple, Attribute.FONT,
149: "100% / 110% \"Courier New\", \"Lucida Console\", "
150: + "monospace");
151: assertAttributes("normal", "normal", "normal", "100%", "110%",
152: "\"Courier New\", \"Lucida Console\", monospace");
153: }
154:
155: public void testFont15() {
156: ss.addCSSAttribute(simple, Attribute.FONT,
157: "smaller /120% fantasy");
158: assertAttributes("normal", "normal", "normal", "smaller",
159: "120%", "fantasy");
160: }
161:
162: public void testFont16() {
163: ss.addCSSAttribute(simple, Attribute.FONT,
164: "small/ 120% cursive");
165: assertAttributes("normal", "normal", "normal", "small", "120%",
166: "cursive");
167: }
168:
169: public void testFont17() {
170: ss.addCSSAttribute(simple, Attribute.FONT,
171: "x-small/ /18pt sans-serif");
172: if (isHarmony()) {
173: assertEquals(0, simple.getAttributeCount());
174: return;
175: }
176:
177: assertAttributes("normal", "normal", "normal", "x-small",
178: "/18pt", "sans-serif");
179: }
180:
181: public void testFont18() {
182: ss.addCSSAttribute(simple, Attribute.FONT,
183: "14/ 18pt sans-serif");
184: if (isHarmony()) {
185: assertEquals(0, simple.getAttributeCount());
186: return;
187: }
188:
189: assertAttributes("normal", "normal", "normal", "14", "18pt",
190: "sans-serif");
191: }
192:
193: public void testFont19() {
194: ss.addCSSAttribute(simple, Attribute.FONT, "14pt/");
195: if (isHarmony()) {
196: assertEquals(0, simple.getAttributeCount());
197: return;
198: }
199:
200: assertAttributes("normal", "normal", "normal", "14pt",
201: "normal", "SansSerif");
202: }
203:
204: public void testFont20() {
205: ss.addCSSAttribute(simple, Attribute.FONT, "14pt /");
206: if (isHarmony()) {
207: assertEquals(0, simple.getAttributeCount());
208: return;
209: }
210:
211: assertAttributes("normal", "normal", "normal", "14pt",
212: "normal", "SansSerif");
213: }
214:
215: private void assertAttributes(final String style,
216: final String variant, final String weight,
217: final String size, final String lineHeight,
218: final String family) {
219: assertEquals("Attribute count", 6, simple.getAttributeCount());
220:
221: assertEquals("font-style", style,
222: getCSSAttribute(Attribute.FONT_STYLE));
223: assertEquals("font-variant", variant,
224: getCSSAttribute(Attribute.FONT_VARIANT));
225: assertEquals("font-weight", weight,
226: getCSSAttribute(Attribute.FONT_WEIGHT));
227: assertEquals("font-size", size,
228: getCSSAttribute(Attribute.FONT_SIZE));
229: assertEquals("line-height", lineHeight,
230: getCSSAttribute(Attribute.LINE_HEIGHT));
231: assertEquals("font-family", family,
232: getCSSAttribute(Attribute.FONT_FAMILY));
233: }
234:
235: private String getCSSAttribute(final Attribute cssKey) {
236: final Object result = simple.getAttribute(cssKey);
237: return result != null ? result.toString() : null;
238: }
239: }
|