Not sure if my earlier post ever made it out.

You can use TextMeasurer instead of LineBreakMeasurer in order to do
custom line break.  TextMeasurer lets you measure the graphical distance
between two points in the text, or find the offset of the last character
before a given graphical advance.  It 'knows' about things like
ligatures and local reorderings in that it will treat all such
'clusters' as single units for the purpose of measurement (in
particular, the first character of the cluster gets all the advance and
subsequent characters in the cluster have zero advance, so you can
handle them the same as you would combining marks).  TextMeasurer also
knows about styles, since it works on AttributedCharacterIterator, and
so will take into account some other odd things like numeric
substitution, bidirectional styles, etc.

TextMeasurer and LineBreakMeasurer use GlyphVectors internally.
GlyphVector is the lowest-level java interface to the layout code
(OpenType, etc.) and only supports a subset of the styles (those
directly affecting metrics, i.e. no colors, strikethrough, etc.)  As a
low-level API it expects that you've dealt with these things at a higher
level (or know you can ignore them).  This is either 'more power' or
'less power' depending on your point of view :-)

Since TextMeasurer lets you make multiple measurements without
committing to a TextLayout up front, it's  much better suited to
multipass line-breaking algorithms. There are still issues, of course--
you can't form/unform ligatures on the fly to fine-tune your
measurements, for example, you'd have to insert/remove a non-joiner or
restyle the text, and then remeasure.  But if you're doing full layout
then you might already be expecting to take a bit of additional time, so
perhaps that's not an issue.

If you find things that you absolutely can't do with the API, please
file RFEs.  It always helps to have actual client requests.

Doug

Peter B. West wrote On 06/16/06 16:46,:
> ---------------------- Information from the mail header 
> -----------------------
> Sender:       Discussion list for Java 2D API <[EMAIL PROTECTED]>
> Poster:       "Peter B. West" <[EMAIL PROTECTED]>
> Subject:      Re: Using GlyphVectors
> -------------------------------------------------------------------------------
>
> Phil Race wrote:
>
>>Peter B. West wrote:
>>
>>
>>>On Thu, 2006-06-15 at 17:24 +0100, Peter B. West wrote:
>>>
>>>
>>>
>>>>David,
>>>>
>>>>Thanks for the response.  I did look at LineBreakMeasurer, but in looks
>>>>as though the most powerful layout mechanism available is
>>>>Font.layoutGlyphVector. The docs say:
>>>>
>>>>
>>
>>its not 'the most powerful'
>>
>>
>>>>"Returns a new GlyphVector object, performing full layout of the text if
>>>>possible. Full layout is required for complex text, such as Arabic or
>>>>Hindi."
>>>>
>>>>It was that flexibility and power I was after. You have to do your own
>>>>Bidi which is a complicationg factor, but you get everything else, as
>>>>far as I can tell.
>>>>
>>>>
>>
>>as you say it doesn't do Bidi and as David Kavanagh as trying to remember
>>AttributedString can handle text in multiple fonts (ie suppose you wnat
>>to style
>>one word in italics,) and with various stylings (have a word in red or
>>have it underlined)
>>AttributedString together with LineBreakMeasurer can handle that. It
>>will also handle Bidi
>>
>>
>>>>I'm using AttributedString as well, with subclasses of
>>>>AttributedCharacterIterator.Attribute for hyphenation markers and
>>>>character replacement graphics.
>>>>
>>>>Full layout is an expensive process, so I would like to be able to work
>>>>off the GlyphVectors I have, if possible, to retrieve the broken lines.
>>>>
>>>>
>>>
>>>
>>>
>>you get most of the same benefit by caching the TextLayout objects that
>>LineBreakMeasurer
>>returns. Mostly apps should avoid GlyphVector unless you know you can
>>make some
>>simplifying assumptions about the text you will be handling.
>>
>>So my feeling is you are digging into the guts rather than using the
>>higher level APIs
>>that have been designed for this sort of purpose.
>>
>>I am not sure if you are also wanting to somehow break at hyphens or
>>have some
>>special behaviour associated with them. LineBreakMeasurer could also do
>>that
>>by telling calling the overload of LBM.nextLayout() that takes offSetLimit.
>>
>>-phil.
>
>
> Thanks for the input Phil. Now I'm more confused. I would love to use
> LineBreakMeasurer.  However, the best conclusion I could draw from the
> documentation available was that it made a few simplifying assumptions
> itself.
>
> What does layoutGlyphVector do, if anything, that LineBreakMeasurer and
> TextLayout do not. I'm assuming that the full layout of complex scripts,
> including kerning, ligatures and context-dependent text shaping are
> being performed in both. Is this the case?
>
> If so, that's great. However, "LineBreakMeasurer implements the most
> commonly used line-breaking policy: Every word that fits within the
> wrapping width is placed on the line. If the first word does not fit,
> then all of the characters that fit within the wrapping width are placed
> on the line. At least one character is placed on each line."
>
> This is the fly in the ointment. It seems to me that this limitation is
> recognized as being serious in the Java2D "white paper".  The exit path
> offered is GlyphVectors. They are adjustable, where TextLayouts are
> immutable.
>
> I am performing paragraph layout with complex Knuth/Plass style
> line-breaking and adjustment. Given this requirement, and the
> requirement to support complex scripts, how do you suggest I go about this?
>
> Peter
>
>
> --
> Peter B. West <http://cv.pbw.id.au/>
> Folio <http://defoe.sourceforge.net/folio/>
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff JAVA2D-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to