changeset 4061:8ac799e47aae

RT-25355: check cascade rule of font shorthand against font style
author David Grieve<david.grieve@oracle.com>
date Fri, 21 Jun 2013 13:45:53 -0400
parents f4cb964fba96
children 8df61a4fc74c
files javafx-ui-common/src/javafx/scene/CssStyleHelper.java javafx-ui-common/test/unit/com/sun/javafx/css/FontTypeTest.java
diffstat 2 files changed, 146 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-common/src/javafx/scene/CssStyleHelper.java	Fri Jun 21 11:34:17 2013 -0400
+++ b/javafx-ui-common/src/javafx/scene/CssStyleHelper.java	Fri Jun 21 13:45:53 2013 -0400
@@ -1563,25 +1563,29 @@
         // font-size must be closer and more specific than font shorthand
         if (fontSize != null) {
 
-            if (origin == null || origin.compareTo(fontSize.getOrigin()) <= 0) {
+            if (fontShorthand == null || fontShorthand.compareTo(fontSize) > 0) {
 
-                final CalculatedValue cv =
-                        calculateValue(fontSize, styleable, dummyFontProperty,
-                                       states, styleable, cvFont, styleList);
+                if (origin == null || origin.compareTo(fontSize.getOrigin()) <= 0) {
 
-                if (cv.getValue() instanceof Double) {
-                    origin = cv.getOrigin();
+                    final CalculatedValue cv =
+                            calculateValue(fontSize, styleable, dummyFontProperty,
+                                    states, styleable, cvFont, styleList);
 
-                    if (cvFont != null) {
-                        boolean isRelative = cvFont.isRelative() || cv.isRelative();
-                        Font font = deriveFont((Font) cvFont.getValue(), ((Double) cv.getValue()).doubleValue());
-                        cvFont = new CalculatedValue(font, origin, isRelative);
-                    } else {
-                        boolean isRelative = cv.isRelative();
-                        Font font = deriveFont(Font.getDefault(), ((Double) cv.getValue()).doubleValue());
-                        cvFont = new CalculatedValue(font, origin, isRelative);
+                    if (cv.getValue() instanceof Double) {
+                        origin = cv.getOrigin();
+
+                        if (cvFont != null) {
+                            boolean isRelative = cvFont.isRelative() || cv.isRelative();
+                            Font font = deriveFont((Font) cvFont.getValue(), ((Double) cv.getValue()).doubleValue());
+                            cvFont = new CalculatedValue(font, origin, isRelative);
+                        } else {
+                            boolean isRelative = cv.isRelative();
+                            Font font = deriveFont(Font.getDefault(), ((Double) cv.getValue()).doubleValue());
+                            cvFont = new CalculatedValue(font, origin, isRelative);
+                        }
                     }
                 }
+
             }
 
         }
@@ -1595,22 +1599,25 @@
 
             if (fontWeight != null) {
 
-                if (origin == null || origin.compareTo(fontWeight.getOrigin()) <= 0) {
+                if (fontShorthand == null || fontShorthand.compareTo(fontWeight) > 0) {
 
-                    final CalculatedValue cv =
-                            calculateValue(fontWeight, styleable, dummyFontProperty,
-                                           states, styleable, null, null);
+                    if (origin == null || origin.compareTo(fontWeight.getOrigin()) <= 0) {
 
-                    if (cv.getValue() instanceof FontWeight) {
-                        origin = cv.getOrigin();
+                        final CalculatedValue cv =
+                                calculateValue(fontWeight, styleable, dummyFontProperty,
+                                        states, styleable, null, null);
 
-                        if (cvFont != null) {
-                            boolean isRelative = cvFont.isRelative();
-                            Font font = deriveFont((Font) cvFont.getValue(), (FontWeight) cv.getValue());
-                            cvFont = new CalculatedValue(font, origin, isRelative);
-                        } else {
-                            Font font = deriveFont(Font.getDefault(), (FontWeight) cv.getValue());
-                            cvFont = new CalculatedValue(font, origin, false);
+                        if (cv.getValue() instanceof FontWeight) {
+                            origin = cv.getOrigin();
+
+                            if (cvFont != null) {
+                                boolean isRelative = cvFont.isRelative();
+                                Font font = deriveFont((Font) cvFont.getValue(), (FontWeight) cv.getValue());
+                                cvFont = new CalculatedValue(font, origin, isRelative);
+                            } else {
+                                Font font = deriveFont(Font.getDefault(), (FontWeight) cv.getValue());
+                                cvFont = new CalculatedValue(font, origin, false);
+                            }
                         }
                     }
                 }
@@ -1624,27 +1631,30 @@
 
             if (fontStyle != null) {
 
-                if (origin == null || origin.compareTo(fontStyle.getOrigin()) <= 0) {
+                if (fontShorthand == null || fontShorthand.compareTo(fontStyle) > 0) {
 
-                    final CalculatedValue cv =
-                            calculateValue(fontStyle, styleable, dummyFontProperty,
-                                           states, styleable, null, null);
+                    if (origin == null || origin.compareTo(fontStyle.getOrigin()) <= 0) {
 
-                    if (cv.getValue() instanceof FontPosture) {
-                        origin = cv.getOrigin();
+                        final CalculatedValue cv =
+                                calculateValue(fontStyle, styleable, dummyFontProperty,
+                                        states, styleable, null, null);
 
-                        if (cvFont != null) {
-                            boolean isRelative = cvFont.isRelative();
-                            Font font = deriveFont((Font) cvFont.getValue(), (FontPosture) cv.getValue());
-                            cvFont = new CalculatedValue(font, origin, isRelative);
-                        } else {
-                            boolean isRelative = cv.isRelative();
-                            Font font = deriveFont(Font.getDefault(), (FontPosture) cv.getValue());
-                            cvFont = new CalculatedValue(font, origin, false);
+                        if (cv.getValue() instanceof FontPosture) {
+                            origin = cv.getOrigin();
+
+                            if (cvFont != null) {
+                                boolean isRelative = cvFont.isRelative();
+                                Font font = deriveFont((Font) cvFont.getValue(), (FontPosture) cv.getValue());
+                                cvFont = new CalculatedValue(font, origin, isRelative);
+                            } else {
+                                boolean isRelative = cv.isRelative();
+                                Font font = deriveFont(Font.getDefault(), (FontPosture) cv.getValue());
+                                cvFont = new CalculatedValue(font, origin, false);
+                            }
                         }
                     }
+
                 }
-
             }
 
             CascadingStyle fontFamily = getStyle(styleable, property.concat("-family"), states);
@@ -1654,22 +1664,25 @@
 
             if (fontFamily != null) {
 
-                if (origin == null || origin.compareTo(fontFamily.getOrigin()) <= 0) {
+                if (fontShorthand == null || fontShorthand.compareTo(fontFamily) > 0) {
 
-                    final CalculatedValue cv =
-                            calculateValue(fontFamily, styleable, dummyFontProperty,
-                                           states, styleable, null, null);
+                    if (origin == null || origin.compareTo(fontFamily.getOrigin()) <= 0) {
 
-                    if (cv.getValue() instanceof String) {
-                        origin = cv.getOrigin();
+                        final CalculatedValue cv =
+                                calculateValue(fontFamily, styleable, dummyFontProperty,
+                                        states, styleable, null, null);
 
-                        if (cvFont != null) {
-                            boolean isRelative = cvFont.isRelative();
-                            Font font = deriveFont((Font) cvFont.getValue(), (String) cv.getValue());
-                            cvFont = new CalculatedValue(font, origin, isRelative);
-                        } else {
-                            Font font = deriveFont(Font.getDefault(), (String) cv.getValue());
-                            cvFont = new CalculatedValue(font, origin, false);
+                        if (cv.getValue() instanceof String) {
+                            origin = cv.getOrigin();
+
+                            if (cvFont != null) {
+                                boolean isRelative = cvFont.isRelative();
+                                Font font = deriveFont((Font) cvFont.getValue(), (String) cv.getValue());
+                                cvFont = new CalculatedValue(font, origin, isRelative);
+                            } else {
+                                Font font = deriveFont(Font.getDefault(), (String) cv.getValue());
+                                cvFont = new CalculatedValue(font, origin, false);
+                            }
                         }
                     }
                 }
--- a/javafx-ui-common/test/unit/com/sun/javafx/css/FontTypeTest.java	Fri Jun 21 11:34:17 2013 -0400
+++ b/javafx-ui-common/test/unit/com/sun/javafx/css/FontTypeTest.java	Fri Jun 21 13:45:53 2013 -0400
@@ -29,9 +29,13 @@
 import com.sun.javafx.css.converters.SizeConverter;
 import com.sun.javafx.css.parser.CSSParser;
 import javafx.css.ParsedValue;
+import javafx.scene.Group;
+import javafx.scene.Scene;
 import javafx.scene.text.Font;
 import javafx.scene.text.FontPosture;
 import javafx.scene.text.FontWeight;
+import javafx.scene.text.Text;
+
 import static org.junit.Assert.assertEquals;
 import org.junit.Test;
 
@@ -142,6 +146,79 @@
         assertEquals("Regular", f.getStyle());
         assertEquals("Amble", f.getFamily());
         assertEquals(24, f.getSize(),0);
-    }    
+    }
+
+    @Test public void test_RT_25355_shorthandLast() {
+
+        Text txt = new Text("test_RT_25355");
+        txt.setStyle("-fx-font-weight: bold; -fx-font: 16 Amble;");
+
+        Scene scene  = new Scene(new Group());
+        ((Group)scene.getRoot()).getChildren().add(txt);
+
+        txt.impl_processCSS(true);
+
+        Font f = txt.getFont();
+        assertEquals("Regular", f.getStyle());
+        assertEquals("Amble", f.getFamily());
+        assertEquals(16, f.getSize(),0);
+    }
+
+    @Test public void test_RT_25355_shorthandFirst() {
+
+        Text txt = new Text("test_RT_25355");
+        txt.setStyle("-fx-font: 16 Amble; -fx-font-weight: bold;");
+
+        Scene scene  = new Scene(new Group());
+        ((Group)scene.getRoot()).getChildren().add(txt);
+
+        txt.impl_processCSS(true);
+
+        Font f = txt.getFont();
+        assertEquals("Bold", f.getStyle());
+        assertEquals("Amble", f.getFamily());
+        assertEquals(16, f.getSize(),0);
+
+    }
+
+    @Test public void test_RT_25355_shorthandFirstInheritedWeight() {
+
+        Text txt = new Text("test_RT_25355");
+        txt.setStyle("-fx-font: 16 Amble;");
+
+        Group g = new Group();
+        g.setStyle("-fx-font-weight: bold");
+
+        Scene scene  = new Scene(g);
+        g.getChildren().add(txt);
+
+        g.impl_processCSS(true);
+
+        Font f = txt.getFont();
+        assertEquals("Regular", f.getStyle());
+        assertEquals("Amble", f.getFamily());
+        assertEquals(16, f.getSize(),0);
+
+    }
+
+    @Test public void test_RT_25355_weightFirstInheritedShorthand() {
+
+        Text txt = new Text("test_RT_25355");
+        txt.setStyle("-fx-font-weight: bold;");
+
+        Group g = new Group();
+        g.setStyle("-fx-font: 16 Amble;");
+
+        Scene scene  = new Scene(g);
+        g.getChildren().add(txt);
+
+        g.impl_processCSS(true);
+
+        Font f = txt.getFont();
+        assertEquals("Bold", f.getStyle());
+        assertEquals("Amble", f.getFamily());
+        assertEquals(16, f.getSize(),0);
+
+    }
 
 }