• Post Reply Bookmark Topic Watch Topic
  • New Topic

Undesired word break on curly apostrophe in JTextPane  RSS feed

 
Chris Crawford
Ranch Hand
Posts: 116
1
Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This might be in the running for Most Obscure Problem ever reported. I have a JTextPane; Java inserts line breaks in ALMOST all of the right places. It correctly does NOT insert a line break on a flat apostrophe (the character ') but it DOES insert a line break after a curly apostrophe, which I cannot insert with this editor. Thus, the word we'll with a flat apostrophe is not broken, but the version with the curly apostrophe is broken so that it looks like this: we'
ll
Obviously, this is unacceptable. I have searched the web and been hobbled by a huge number of hits on discussions of how to turn word breaking on and off. There's a topic here http://www.coderanch.com/t/380931/java/java/Parse-Smart-Quotes-regular-quotes from seven years ago about using smart quotes (curly double quotes), but it wasn't about line breaks.

There is something called DefaultEditorKit.insertBreakAction, but that does not seem to address this problem.

Here are the possibilities I am considering:
1. Hope, hope, hope, that there's a method along the lines of JTextPane.setWordBreakOnCurlyApostrophe(boolean). (Yeah, right.)
2. Replace all curly apostrophes with flat apostrophes (ugly!)
3. Accept the rare case of the improperly broken word (it's rather jarring).
4. Write special code that fakes Java into doing the right thing (probably a lot of work).
5. Find another Swing object that can do this correctly. So far, no luck.

Does anybody have any better ideas?
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris Crawford wrote:4. Write special code that fakes Java into doing the right thing (probably a lot of work).

Having spent a couple of hours trying to find out where things happen, I'd say it's not possible.

FWIW -- creating a line break starts getting serious in public static final int javax,swing.text.Utilities#getBreakLocation(Segment s, FontMetrics metrics, int x0, int x, TabExpander e, int startOffset) (line 421) which makes use of a BreakIterator#getLineInstance() (another static method), which returns a java.text.RuleBasedBreakIterator (default-access aka package-private class) which uses sun/text/resources/LineBreakIteratorData in jre/lib/resources.jar. Between all the statics, limited access and proprietary stuff that seems to rule out subclassing for desired behavior.

There just might be a way to replace the with a ' for computing the line break, and using the original curly quote for rendering, but I couldn't trace that path of execution ... got stuck at a firePropertyChange somewhere and couldn't find where the listener was that picked up on the property change.

Sorry, but it rather looks like you have to make a choice between 2 and 3.
 
Chris Crawford
Ranch Hand
Posts: 116
1
Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. It's good to have my ignorant superstitions verified by rational analysis, for once.
 
Tony Docherty
Bartender
Posts: 3206
78
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not that this is of any help to you but it is a known bug with the BreakIterator. See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6609664
And as it was first reported in 2007 and is still open it looks like there is no rush to fix this.
 
Chris Crawford
Ranch Hand
Posts: 116
1
Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I was only 5 and a half years late in noticing. From my perspective, I think that represents an improvement.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!