-
Bug
-
Resolution: Unresolved
-
P4
-
jfx13
-
x86
-
os_x
ADDITIONAL SYSTEM INFORMATION :
macOS Mojave 10.14.6
A DESCRIPTION OF THE PROBLEM :
When a file name including Emoji (or surrogate pair) code is received by drag and drop, the file name is not received correctly.
The problem is that NewStringUTF cannot handle emoji code correctly. You can fix it by using NewString instead.
modules/javafx.graphics/src/main/native-glass/mac/GlassSystemClipboard.m
------
JNIEXPORT jstring JNICALL Java_com_sun_glass_ui_mac_MacSystemClipboard__1convertFileReferencePath
(JNIEnv *env, jclass clazz, jstring jPath)
{
jstring result = nil;
GLASS_POOL_ENTER;
{
NSString* path = [GlassHelper nsStringWithJavaString:jPath withEnv:env];
NSURL *url = [NSURL URLWithString:path];
if (url != nil) {
url = [url filePathURL];
if (url != nil) {
path = [url path];
}
}
result = (*env) -> NewStringUTF(env, [path UTF8String]);
}
GLASS_POOL_EXIT;
GLASS_CHECK_EXCEPTION(env);
return result;
}
------
The following is the source after rewriting.
------
JNIEXPORT jstring JNICALL Java_com_sun_glass_ui_mac_MacSystemClipboard__1convertFileReferencePath
(JNIEnv *env, jclass clazz, jstring jPath)
{
jstring result = nil;
GLASS_POOL_ENTER;
{
NSString* path = [GlassHelper nsStringWithJavaString:jPath withEnv:env];
NSURL *url = [NSURL URLWithString:path];
if (url != nil) {
url = [url filePathURL];
if (url != nil) {
path = [url path];
}
}
jsize buflen = [path length];
unichar buffer[buflen];
[path getCharacters:buffer];
result = (*env)->NewString(env, (jchar *)buffer, buflen);
}
GLASS_POOL_EXIT;
GLASS_CHECK_EXCEPTION(env);
return result;
}
------
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a file that includes Emoji in the file name in advance.
2. Launch the test and drag and drop the file to TextField or TextArea.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The correct file name is displayed in the text input control
ACTUAL -
File names containing garbled characters are displayed in the text input control
---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.TextInputControl;
import javafx.scene.input.Dragboard;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;
public class EmojiDnDTest extends Application{
private static Font emojiFont = Font.font("Apple Color Emoji");
@Override
public void start(Stage stage) throws Exception {
TextField textField = new TextField();
TextArea textArea = new TextArea();
textField.setFont(emojiFont);
textArea.setFont(emojiFont);
installDnD(textField);
installDnD(textArea);
VBox root = new VBox(8, new Label("TextField"),textField, new Label("TextArea"), textArea);
Scene scene = new Scene(root, 400, 700);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
private static void installDnD(TextInputControl control){
control.setOnDragOver(event -> {
Dragboard board = event.getDragboard();
if (board.hasFiles()) {
event.acceptTransferModes(TransferMode.MOVE);
}
});
control.setOnDragDropped(event -> {
Dragboard board = event.getDragboard();
if (board.hasFiles()) {
board.getFiles().forEach(file ->control.setText(file.getName()));
event.setDropCompleted(true);
} else {
event.setDropCompleted(false);
}
});
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
There is no workaround for this problem, but I proposed a fix for the Glass module.
FREQUENCY : always
macOS Mojave 10.14.6
A DESCRIPTION OF THE PROBLEM :
When a file name including Emoji (or surrogate pair) code is received by drag and drop, the file name is not received correctly.
The problem is that NewStringUTF cannot handle emoji code correctly. You can fix it by using NewString instead.
modules/javafx.graphics/src/main/native-glass/mac/GlassSystemClipboard.m
------
JNIEXPORT jstring JNICALL Java_com_sun_glass_ui_mac_MacSystemClipboard__1convertFileReferencePath
(JNIEnv *env, jclass clazz, jstring jPath)
{
jstring result = nil;
GLASS_POOL_ENTER;
{
NSString* path = [GlassHelper nsStringWithJavaString:jPath withEnv:env];
NSURL *url = [NSURL URLWithString:path];
if (url != nil) {
url = [url filePathURL];
if (url != nil) {
path = [url path];
}
}
result = (*env) -> NewStringUTF(env, [path UTF8String]);
}
GLASS_POOL_EXIT;
GLASS_CHECK_EXCEPTION(env);
return result;
}
------
The following is the source after rewriting.
------
JNIEXPORT jstring JNICALL Java_com_sun_glass_ui_mac_MacSystemClipboard__1convertFileReferencePath
(JNIEnv *env, jclass clazz, jstring jPath)
{
jstring result = nil;
GLASS_POOL_ENTER;
{
NSString* path = [GlassHelper nsStringWithJavaString:jPath withEnv:env];
NSURL *url = [NSURL URLWithString:path];
if (url != nil) {
url = [url filePathURL];
if (url != nil) {
path = [url path];
}
}
jsize buflen = [path length];
unichar buffer[buflen];
[path getCharacters:buffer];
result = (*env)->NewString(env, (jchar *)buffer, buflen);
}
GLASS_POOL_EXIT;
GLASS_CHECK_EXCEPTION(env);
return result;
}
------
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a file that includes Emoji in the file name in advance.
2. Launch the test and drag and drop the file to TextField or TextArea.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The correct file name is displayed in the text input control
ACTUAL -
File names containing garbled characters are displayed in the text input control
---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.TextInputControl;
import javafx.scene.input.Dragboard;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;
public class EmojiDnDTest extends Application{
private static Font emojiFont = Font.font("Apple Color Emoji");
@Override
public void start(Stage stage) throws Exception {
TextField textField = new TextField();
TextArea textArea = new TextArea();
textField.setFont(emojiFont);
textArea.setFont(emojiFont);
installDnD(textField);
installDnD(textArea);
VBox root = new VBox(8, new Label("TextField"),textField, new Label("TextArea"), textArea);
Scene scene = new Scene(root, 400, 700);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
private static void installDnD(TextInputControl control){
control.setOnDragOver(event -> {
Dragboard board = event.getDragboard();
if (board.hasFiles()) {
event.acceptTransferModes(TransferMode.MOVE);
}
});
control.setOnDragDropped(event -> {
Dragboard board = event.getDragboard();
if (board.hasFiles()) {
board.getFiles().forEach(file ->control.setText(file.getName()));
event.setDropCompleted(true);
} else {
event.setDropCompleted(false);
}
});
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
There is no workaround for this problem, but I proposed a fix for the Glass module.
FREQUENCY : always