JDK-8304041 : [WebView] Text on the left and right of emoji is not visible
  • Type: Bug
  • Component: javafx
  • Sub-Component: graphics
  • Affected Version: jfx21
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: os_x
  • CPU: generic
  • Submitted: 2023-03-11
  • Updated: 2024-07-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
jfx24Unresolved
Related Reports
Relates :  
Relates :  
Description
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



Comments
A pull request was submitted for review. URL: https://git.openjdk.org/jfx/pull/1083 Date: 2023-04-06 20:00:01 +0000
06-04-2023

Clearly every previous build was very wrong too. Looks to me as if webview has emoji in the same TextRun as regular glyphs. The implementation expects them in separate runs. I don't know why this is happening .. I wouldn't expect Webview to have its own way of creating the runs ... but that could explain it.
15-03-2023

Checked with attached testcase in macOS ventura 13.2.1, Text to the left and right of the emoji is clearly visible<attached screenshot> Test Result ========= jfx17: Pass jfx19: Pass jfx20:Pass jfx21ea5:Pass jfx21ea8: Fail<-Regression Mail to Submitter ============= Please share the screenshot of the Issue.
15-03-2023

Additional information from submitter: ============================ Either the recent merge of significant emoji changes or the merge of webkit 615 appears to be a factor. * 8290866: Apple Color Emoji turns gray after JavaFX version 18 * 8299977: Update WebKit to 615.1 The emoji issue can be reproduced with javafx21 ea8 at the following URL * https://jdk.java.net/javafx21/ * https://github.com/openjdk/jfx/compare/21+5...21+8 <attaching a screenshot from submitter>
15-03-2023

I can confirm that this was introduced by the fix for JDK-8290866. Prior to that fix, the text surrounding the emojis was correct (but the emojis were gray).
15-03-2023