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

[WebView] Text on the left and right of emoji is not visible

XMLWordPrintable

    • b08
    • generic
    • os_x

      ADDITIONAL SYSTEM INFORMATION :
      openjdk version "17.0.6" 2023-01-17
      OpenJDK Runtime Environment (build 17.0.6+10)
      OpenJDK 64-Bit Server VM (build 17.0.6+10, mixed mode, sharing)
      macOS Monterey 12.6.3



      A DESCRIPTION OF THE PROBLEM :
      WebView incorrectly renders left and right text when emoji characters are included.
      This problem did not occur in the OpenJFX master snapshot of 2022-08-29.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
       launch the attached test app.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The text on the left and right side of the emoji is rendered.
      ACTUAL -
      The text on the left and right side of the emoji is not rendered. Or, rendering is corrupted.

      ---------- BEGIN SOURCE ----------

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.control.SplitPane;
      import javafx.scene.layout.VBox;
      import javafx.scene.text.Font;
      import javafx.scene.web.WebView;
      import javafx.stage.Stage;
      import netscape.javascript.JSObject;

      public class WebViewEmojiTest extends Application{

          @Override
          public void init() throws Exception {
      Font font = Font.font("Apple Color Emoji");
      System.out.println("font-name:"+font.getFamily());
          }
          
      @Override
      public void start(Stage primaryStage) throws Exception {
      WebView webView = new WebView();
      SplitPane root = new SplitPane();
      root.getItems().add(webView);
      root.getItems().add(new VBox(
      new Label("😄EMOJI"),
      new Label("EMOJI😄")
      ));

      webView.getEngine().documentProperty().addListener((ob, oldValue, newValue)->{
      // Workaround for problem with loadContent() method not handling surrogate pairs correctly.
      JSObject body = (JSObject)webView.getEngine().executeScript("document.body");
      body.setMember(
      "innerHTML",
      testHtmlFragment
      );
      });

      Scene scene = new Scene(root, 600, 600);
      primaryStage.setScene(scene);
      primaryStage.show();

      webView.getEngine().loadContent(html);
      }

      public static void main(String[] args) {
      Application.launch(args);
      }

      String html = "<html>\n" +
      "<head>\n" +
      "</head>\n" +
      "</html>";

      String testHtmlFragment =
      "<h2>Error case</h2>" +
      "<div>😄EMOJI</div>" +
      "<div>EMOJI😄</div>" +
      "<div><button>😄EMOJI</button></div>" +
      "<div><button>EMOJI😄</button></div>" +
      "<textarea>😄EMOJI\nEMOJI😄</textarea>" +
      "<h2>Workarround</h2>" +
      "<div><span>😄</span>EMOJI</div>"+
      "<div>EMOJI<span>😄</span></div>"+
      "<div><button><span>😄</span>EMOJI</button></div>"+
      "<div><button>EMOJI<span>😄</span></button></div>"
      ;
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      * Enclose emoji characters in span tags.
      * The sample code also uses a workaround for a problem with loadContent not rendering surrogate pair characters correctly. This problem is being addressed by inserting html fragments in executeScript.

      FREQUENCY : always


        1. WebViewEmojiTest.java
          2 kB
        2. Windows_Capture.PNG
          Windows_Capture.PNG
          48 kB
        3. jfx21.png
          jfx21.png
          150 kB
        4. jfx17.png
          jfx17.png
          139 kB
        5. from_submitter.png
          from_submitter.png
          443 kB
        6. jfx21ea8.png
          jfx21ea8.png
          170 kB

            prr Philip Race
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: