9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package test.javafx.css;
27
28 import com.sun.javafx.css.ParsedValueImpl;
29 import javafx.css.CssParser;
30 import javafx.css.ParsedValue;
31 import javafx.css.Size;
32 import javafx.css.SizeUnits;
33 import javafx.css.converter.FontConverter;
34 import javafx.css.converter.SizeConverter;
35
36 import javafx.scene.Group;
37 import javafx.scene.Scene;
38 import javafx.scene.text.Font;
39 import javafx.scene.text.FontPosture;
40 import javafx.scene.text.FontWeight;
41 import javafx.scene.text.Text;
42
43 import static org.junit.Assert.*;
44 import org.junit.Test;
45
46
47 public class FontTypeTest {
48
49 public FontTypeTest() {
101
102 size =
103 new ParsedValueImpl<ParsedValue<?,Size>,Number>(
104 new ParsedValueImpl<Size,Size>(new Size(font.getSize(), SizeUnits.PT), null),
105 SizeConverter.getInstance()
106 );
107
108 value = new ParsedValueImpl<ParsedValue[],Font>(
109 new ParsedValue[] {family, size, weight, style},
110 FontConverter.getInstance()
111 );
112
113 expResult = Font.font(font.getFamily(), font.getSize() * (96.0/72.0));
114 result = value.convert(font);
115 checkFont(expResult, result);
116
117 }
118
119 @Test public void test_RT_21960_Bold_Italic() {
120
121 ParsedValue pv = new CssParser().parseExpr("-fx-font", "italic bold 24 Amble");
122 Font f = (Font)pv.convert(null);
123 assertEquals("Bold Italic", f.getStyle());
124 assertEquals("Amble", f.getFamily());
125 assertEquals(24, f.getSize(),0);
126 }
127
128 @Test public void test_RT_21960_Bold() {
129
130 ParsedValue pv = new CssParser().parseExpr("-fx-font", "bold 24 Amble");
131 Font f = (Font)pv.convert(null);
132 assertEquals("Bold", f.getStyle());
133 assertEquals("Amble", f.getFamily());
134 assertEquals(24, f.getSize(),0);
135 }
136
137 @Test public void test_RT_21960_Italic() {
138
139 ParsedValue pv = new CssParser().parseExpr("-fx-font", "italic 24 Amble");
140 Font f = (Font)pv.convert(null);
141 assertEquals("Italic", f.getStyle());
142 assertEquals("Amble", f.getFamily());
143 assertEquals(24, f.getSize(),0);
144 }
145
146 @Test public void test_RT_21960_Neither_Bold_Nor_Italic() {
147
148 ParsedValue pv = new CssParser().parseExpr("-fx-font", "24 Amble");
149 Font f = (Font)pv.convert(null);
150 assertEquals("Regular", f.getStyle());
151 assertEquals("Amble", f.getFamily());
152 assertEquals(24, f.getSize(),0);
153 }
154
155 @Test public void test_RT_25355_shorthandLast() {
156
157 Text txt = new Text("test_RT_25355");
158 txt.setStyle("-fx-font-weight: bold; -fx-font: 16 Amble;");
159
160 Scene scene = new Scene(new Group());
161 ((Group)scene.getRoot()).getChildren().add(txt);
162
163 txt.applyCss();
164
165 Font f = txt.getFont();
166 assertEquals("Regular", f.getStyle());
167 assertEquals("Amble", f.getFamily());
168 assertEquals(16, f.getSize(),0);
|
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package test.javafx.css;
27
28 import com.sun.javafx.css.ParsedValueImpl;
29 import javafx.css.CssParserShim;
30 import javafx.css.ParsedValue;
31 import javafx.css.Size;
32 import javafx.css.SizeUnits;
33 import javafx.css.converter.FontConverter;
34 import javafx.css.converter.SizeConverter;
35
36 import javafx.scene.Group;
37 import javafx.scene.Scene;
38 import javafx.scene.text.Font;
39 import javafx.scene.text.FontPosture;
40 import javafx.scene.text.FontWeight;
41 import javafx.scene.text.Text;
42
43 import static org.junit.Assert.*;
44 import org.junit.Test;
45
46
47 public class FontTypeTest {
48
49 public FontTypeTest() {
101
102 size =
103 new ParsedValueImpl<ParsedValue<?,Size>,Number>(
104 new ParsedValueImpl<Size,Size>(new Size(font.getSize(), SizeUnits.PT), null),
105 SizeConverter.getInstance()
106 );
107
108 value = new ParsedValueImpl<ParsedValue[],Font>(
109 new ParsedValue[] {family, size, weight, style},
110 FontConverter.getInstance()
111 );
112
113 expResult = Font.font(font.getFamily(), font.getSize() * (96.0/72.0));
114 result = value.convert(font);
115 checkFont(expResult, result);
116
117 }
118
119 @Test public void test_RT_21960_Bold_Italic() {
120
121 ParsedValue pv = new CssParserShim().parseExpr("-fx-font", "italic bold 24 Amble");
122 Font f = (Font)pv.convert(null);
123 assertEquals("Bold Italic", f.getStyle());
124 assertEquals("Amble", f.getFamily());
125 assertEquals(24, f.getSize(),0);
126 }
127
128 @Test public void test_RT_21960_Bold() {
129
130 ParsedValue pv = new CssParserShim().parseExpr("-fx-font", "bold 24 Amble");
131 Font f = (Font)pv.convert(null);
132 assertEquals("Bold", f.getStyle());
133 assertEquals("Amble", f.getFamily());
134 assertEquals(24, f.getSize(),0);
135 }
136
137 @Test public void test_RT_21960_Italic() {
138
139 ParsedValue pv = new CssParserShim().parseExpr("-fx-font", "italic 24 Amble");
140 Font f = (Font)pv.convert(null);
141 assertEquals("Italic", f.getStyle());
142 assertEquals("Amble", f.getFamily());
143 assertEquals(24, f.getSize(),0);
144 }
145
146 @Test public void test_RT_21960_Neither_Bold_Nor_Italic() {
147
148 ParsedValue pv = new CssParserShim().parseExpr("-fx-font", "24 Amble");
149 Font f = (Font)pv.convert(null);
150 assertEquals("Regular", f.getStyle());
151 assertEquals("Amble", f.getFamily());
152 assertEquals(24, f.getSize(),0);
153 }
154
155 @Test public void test_RT_25355_shorthandLast() {
156
157 Text txt = new Text("test_RT_25355");
158 txt.setStyle("-fx-font-weight: bold; -fx-font: 16 Amble;");
159
160 Scene scene = new Scene(new Group());
161 ((Group)scene.getRoot()).getChildren().add(txt);
162
163 txt.applyCss();
164
165 Font f = txt.getFont();
166 assertEquals("Regular", f.getStyle());
167 assertEquals("Amble", f.getFamily());
168 assertEquals(16, f.getSize(),0);
|