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

RFE: TextFlow.rangeShape() ignores lineSpacing

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • jfx21
    • javafx
    • None

      Problem:

      When TextFlow has non-zero lineSpacing property set, the shape returned by TextFlow.rangeShape() does not include the line spacing (notice the yellow highlight in the screenshot). This presents an issue for implementing a rich text area where the selection shape is obtained by calling rangeShape().

      Compare this to what MS Word does where selection highlight does include line spacing (word.png).

      This might be considered a bug or an enhancement, depending on whether we want to do. The main reason for this ticket is to initiate a discussion.

      We might have at least three options:

      - provide an alternative method that accepts may be a boolean option to control whether lineSpacing should be included
      - modify the existing method to include lineSpacing (raised a backward compatibility alert)
      - let the application code derive a new shape that includes lineSpacing


      SCCE:

      ```
      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.layout.Background;
      import javafx.scene.layout.Priority;
      import javafx.scene.layout.VBox;
      import javafx.scene.paint.Color;
      import javafx.scene.shape.Path;
      import javafx.scene.shape.PathElement;
      import javafx.scene.text.Text;
      import javafx.scene.text.TextFlow;
      import javafx.stage.Stage;

      public class TextFlow_RangeShape extends Application {

          @Override
          public void start(Stage stage) throws Exception {
              String text = "TextFlow{lineSpacing=20}\nline two\nline three\nline four";
              TextFlow t = new TextFlow(new Text(text));
              t.setLineSpacing(20);
              
              Path path = new Path();
              path.setManaged(false);
              path.setFill(Color.rgb(255, 255, 128, 0.5));
              path.setStroke(Color.rgb(128, 128, 0));
              
              Label label = new Label("Next Component Starts Here");
              label.setOpacity(1.0);
              label.setBackground(Background.fill(Color.DARKGRAY));
              
              VBox vb = new VBox();
              vb.getChildren().addAll(path, t, label);
              VBox.setVgrow(label, Priority.ALWAYS);

              Scene scene = new Scene(vb);
              stage.setScene(scene);
              stage.setWidth(400);
              stage.setHeight(200);
              stage.setTitle("TextFlow.rangeShape() ignores lineSpacing");
              stage.show();
              
              Platform.runLater(() -> {
                  PathElement[] pe = t.rangeShape(0, text.length());
                  path.getElements().setAll(pe);
              });
          }
      }
      ```

            prr Philip Race
            angorya Andy Goryachev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: