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

JavaFX HTMLEditor Font Family should not default to a platform-specific font.

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 8u51
    • javafx
    • x86
    • windows_8

      A DESCRIPTION OF THE REQUEST :
      The HTMLEditor explicitly chooses a platform-specific default font, and has no provision for *not* selecting a specific font. A document created on a Mac explicitly sets each paragraph to use <font face="Lucida Grande">, while a document created on Windows explicitly sets each paragraph to use <font face="Segoe UI">. The default should be not explicitly set any font at all.

      JUSTIFICATION :
      HTML document formatting should not be a function of the platform in which it was created, and the user should not be forced to explicitly embed a particular font family in the document.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The easiest way to demonstrate how this should work is with a more mature HTML editor. CKEditor maintains a live demo page here:

      http://ckeditor.com/demo#full

      In that editor, type something simple (e.g. 1<ENTER>2<ENTER>3).

      Click the Source button to see how that input was rendered to HTML; it looks like this:

      <p>1</p>

      <p>2</p>

      <p>3</p>

      Since the user didn't explicitly choose a font, the HTML doesn't explicitly set a font. The "Font" and "Size" dropdowns have no explicit default setting; the default is no selection at all. The user can, of course, select any font or size to explicitly set a paragraph to use a particular font.
      ACTUAL -
      The actual behaviour is platform-dependent.

      Run the attached sample (or any HTMLEditor sample).

      Type: 1<ENTER>2<ENTER>3<ENTER>

      On Windows, the HTML is:

      getHtmlText: <html dir="ltr"><head></head><body contenteditable="true"><p><font face="Segoe UI">1</font></p><p><font face="Segoe UI">2</font></p><p><font face="Segoe UI">3</font></p><p><font face="Segoe UI"><br></font></p></body></html>

      On a Mac, the HTML is:

      getHtmlText: <html dir="ltr"><head></head><body contenteditable="true"><p><font face="Lucida Grande">1</font></p><p><font face="Lucida Grande">2</font></p><p><font face="Lucida Grande">3</font></p><p><font face="Lucida Grande"><br></font></p></body></html>

      As a related issue (and related to 8091855), fonts should not be set with <font face=... size=...>. When the user explicitly chooses a font (and only when the user explicitly chooses a font), it should be set with CSS font-family and font-size).

      ---------- BEGIN SOURCE ----------
      import javafx.application.Platform;
      import javafx.embed.swing.JFXPanel;
      import javafx.event.EventHandler;
      import javafx.scene.input.KeyEvent;
      import javafx.scene.Scene;
      import javafx.scene.web.HTMLEditor;

      import javax.swing.JFrame;
      import javax.swing.SwingUtilities;

      public class JavaFXDemo
      {
          private static void initAndShowGUI()
          {
              JFrame frame = new JFrame("HTML Editor");
              final JFXPanel fxPanel = new JFXPanel();
              frame.add(fxPanel);
              frame.setSize(600, 400);
              frame.setVisible(true);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

              Platform.runLater(new Runnable()
              {
                  @Override
                  public void run()
                  {
                      final HTMLEditor htmlEditor = new HTMLEditor();
                      Scene scene = new Scene(htmlEditor);
                      fxPanel.setScene(scene);
                      htmlEditor.setOnKeyReleased(new EventHandler<KeyEvent>()
                      {
                          @Override
                          public void handle(KeyEvent ke)
                          {
      System.out.println("getHtmlText: " + htmlEditor.getHtmlText());
                          }
                      });
                  }
              });
          }

          public static void main(String[] args)
          {
              SwingUtilities.invokeLater(new Runnable()
              {
                  @Override
                  public void run()
                  {
                      initAndShowGUI();
                  }
              });
          }
      }

      ---------- END SOURCE ----------

            leifs Leif Samuelsson (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: