QWv3 – Dev blog 18

So good news, bad news… again.

It’s been a couple of months since my last post. I haven’t been idle (never mind what my wife says!) I have been deliberately staying silent, trying to get all the features I need in place. In my last post I described how I was having to ditch Java Swing completely and move to a JavaFX text component RichTextFX. Now RichTextFX is great but when you start getting into the weeds you begin to see the design philosophy behind it. Superficially it is designed for editing any type of text but in reality it is designed to edit computer code, i.e. lines of text that don’t wrap, where every line is a paragraph essentially. Let me be clear, there is nothing wrong with this at all, but it means a lot of work has to be done when you try and use it for a different type of text, for example prose, where a paragraph wraps onto multiple lines.

Everything was going pretty well, I implemented the spell checker, the margin, text properties, undo/redo, writing line highlighting, position tracking, spelling replacements and synonyms. But then I discovered that neither RichTextFX or the TextFlow it relies on support indenting of the first line of text in a paragraph.

That is, this style of text:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris id neque efficitur, hendrerit dui non, pretium est. Maecenas eu dolor enim. Cras at lacus eleifend, blandit ex eu, convallis sapien. Praesent et suscipit augue. Ut quis nisi velit. Aliquam tristique vehicula ultrices. Maecenas in imperdiet eros. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed vitae luctus nisl. Aliquam odio ipsum, interdum nec suscipit id, pulvinar non magna. Vestibulum nec iaculis enim. Vivamus vitae cursus velit.

In congue nisl ac dictum sagittis. Nunc non mauris eget felis imperdiet rhoncus eu non risus. Ut sed nunc elementum, fringilla mauris id, posuere ligula. Morbi sit amet ultrices felis, ut condimentum ligula. Mauris eu tempus nibh. Sed congue mollis orci, vel tristique tortor imperdiet posuere. Aliquam erat volutpat. Suspendisse et condimentum orci, a rhoncus erat.

Where the first line of the paragraph (contiguous text) has an indent before the first word. This was a bit of a shock for me since HTML CSS supports indenting the first line of text via the “text-indent” property. JTextPane (Java Swing) supported the feature which is why it is present in QW. The current maintainer of RichTextFX has been extremely helpful in both adding requested features (such as writing line highlighting) and offering suggestions for implementing the indent. Unfortunately his suggestion for implementing the indent means that I have to add something to the text but then try and pretend that the something isn’t there. Which leads to a conflict and issues within my code.

I then investigated handling laying out the text within RichTextFX myself and while, with a few nasty hacks I can lay the text out, I can’t (without even more hacks) get access to the underlying components I need to make the indent be transparent, i.e. to be “not there” to my code.

This has left me with a quandary. First line indenting is a vital feature for many writers, its omission from a relatively mature and stable platform like JavaFX is baffling to me. JavaFX is currently at version 13 and the TextFlow was introduced in 2014, however this one feature is missing. I suspect this was a deliberate decision on the part of the JavaFX developers, but of course I’ve no idea why. So I’m left with a choice, do I bring the development of version 3 to a halt and try to find a workaround, or do I try and persuade the JavaFX developers to implement the feature themselves and plough on with the rest of version 3’s development?

I’ve chosen the second path. I don’t believe I can workaround this problem, it’s what I call a “sinking ship problem”, where your solution creates so many other issues that you wind up spending all your time correcting the issues the solution causes. For me this is a layout issue, it’s fundamental to how the text is laid out and as such it should be solved by the TextFlow itself, the user of the TextFlow should not know that the indent is there. Without hacking most of the javax.scene.text components apart, I don’t believe I can solve this issue.

To that end I’ve raised some feature requests for the JavaFX TextFlow component, see: here and here. I need to now move on with developing the rest of v3 and have to hope that the JavaFX developers implement this feature at some point in the future. I may revisit this problem again before the release of v3 but for now I need to move on.

1 thought on “QWv3 – Dev blog 18

  1. alucardnoir

    …I wouldn’t build my hopes up for this feature ever being implemented. If you’re right and the feature was omitted intentionally in 2014 then it’s likely to not be implemented.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: