JavaFX WebView & JavaFX HTMLEditor: A Tale of Two Cities

Tough times in the world of Fosfor, the EPUB Open Toolbox. Turns out that while the JavaFX WebView has perfect rendering but no editing capabilities, the JavaFX HTMLEditor has perfect editing capabilities but crap rendering.

Exhibit one is right here, with the JavaFX HTMLEditor on the left and the JavaFX WebView on the right, rendering the same XHTML file:

As can be seen, the images, CSS, and entities defined in the XHTML file above are perfectly rendered in WebView, but not at all in the HTMLEditor. It seems to me that the HTMLEditor is meant for rendering text only, nothing else.

I then hacked my own HTMLEditor on top of the JavaFX HTMLEditor, which searches through all the text prior to rendering and uses the file protocol to locally locate images and CSS:

https://java.net/projects/epubopentoolbox/sources/epub/content/jepub-browser-external/src/main/java/com/eirik/jepub/browser/external/HTMLEditorControl.java

The result is as follows, i.e., I've fixed the images and CSS problem, but not the entities, yet:

In short, I'm going to try and create a set of service providers for a "fixHTMLEditorRendering" service which will pre-process images, CSS, and HTML entities prior to them being rendered in the JavaFX HTMLEditor. Then, when saving the file back to EPUB, I'm going to have to reverse the process.

Not ideal, but I think it's workable.

Issue: https://javafx-jira.kenai.com/browse/RT-30487

Comments:

Thanks for sharing.

Posted by TPC on June 20, 2013 at 02:25 AM PDT #

Gaertjan, I think that it's better to keep only the JavaFX WebView - the rationale is that after many years of broken HTML rendering with pure-Java solutions, the only working approach has been to embed the WebKit. Thus I'd like to stick with it. A possible solution that I'm exploring (code probably in the weekend) is to integrate a JS editor, such as the Aloha Editor [1]. I've already tried it in the past, in other circumstances, and it looks good. Basically, it notifies document updates by REST calls, so the whole idea is to run an embedded web server (e.g. Jetty), preprocess the HTML document so the proper JS/CSS stuff for Aloha is integrated, then have the WebView to connect to the embedded webserver.

[1] http://www.aloha-editor.org/

Posted by guest on June 28, 2013 at 05:08 AM PDT #

For the record, I implemented the thing. Conceptually it works, but it seems that there are some WebView issues that break the character selection in the editor.

Posted by Fabrizio Giudici on July 02, 2013 at 12:17 AM PDT #

Would love to see it. The problems described in this blog entry are a blocker to a really cool app I've been working on.

Posted by Geertjan on July 02, 2013 at 02:50 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
24
25
26
27
28
29
30
   
       
Today