Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8222222

Gradients defined in CSS always use "reflect" even when "repeat" is specified

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: openjfx12
    • Fix Version/s: openjfx13
    • Component/s: javafx
    • Labels:
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Java Version:

      openjdk 12 2019-03-19
      OpenJDK Runtime Environment (build 12+33)
      OpenJDK 64-Bit Server VM (build 12+33, mixed mode, sharing)

      JavaFX Version:

      javafx.version=12
      javafx.runtime.version=12+14
      javafx.runtime.build=14



      A DESCRIPTION OF THE PROBLEM :
      When setting a LinearGradient or RadialGradient as the background of a Region—using CSS—it will use CycleMethod.REFLECT even when set to use CycleMethod.REPEAT. This **appears** to be caused by a bug in javafx.css.CssParser. Looking at the JavaFX 12 sources, inside CssParser#parseLinearGradient(Term), near line 1872 you'll see:

      CycleMethod cycleMethod = CycleMethod.NO_CYCLE;
      if ("reflect".equalsIgnoreCase(arg.token.getText())) {
          cycleMethod = CycleMethod.REFLECT;
          prev = arg;
          arg = arg.nextArg;
      } else if ("repeat".equalsIgnoreCase(arg.token.getText())) {
          cycleMethod = CycleMethod.REFLECT; // PROBLEM HERE
          prev = arg;
          arg = arg.nextArg;
      }

      The same issue appears in CssParser#parseRadialGradient(Term) near line 2172.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a Region
      2. Set its background via CSS (external file or setStyle) using a "repeating" LinearGradient
      3. Observe bug

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      LinearGradient should be using CycleMethod.REPEAT
      ACTUAL -
      LinearGradient is using CycleMethod.REFLECT

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.layout.Region;
      import javafx.scene.paint.LinearGradient;
      import javafx.stage.Stage;

      public class Main extends Application {

          @Override
          public void start(Stage primaryStage) {
              Region region = new Region();
              region.backgroundProperty().addListener((obs, ov, nv) -> {
                  LinearGradient gradient = (LinearGradient) nv.getFills().get(0).getFill();
                  System.out.println(gradient.getCycleMethod());
              });
              region.setStyle("-fx-background-color: linear-gradient(from 0% 0% to 25% 25%, repeat, red 33%, black 66%);");
              primaryStage.setScene(new Scene(region, 600, 400));
              primaryStage.show();
          }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Set the background programmatically rather than through CSS.

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              arapte Ambarish Rapte
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: