Chris: Chris Nokleberg wrote:
The worst part is that there is no way to work backwards from the GlyphVectors to the associated range in the AttributedString. If there was, and custom Attributes affected the division of the string into GlyphVectors, then you could just check "is the range this GlyphVector comes from tagged with my custom shadow Attribute?".
TextLayout has run bidi for you, and possibly reordered the GlyphVectors based on that, so the order in which you are capturing the drawGlyphVector calls reflects the visual order and not the logical one. Otherwise you could use the character length to create a mapping back from the GlyphVectors to the range of text. Without running Bidi yourself, you're stuck, I'm afraid-- you can't recreate the bidi reordering from information in the GlyphVector.
As it is, I need to create a completely separate AttributedString, and overload an existing attribute like FOREGROUND. Then, in the Graphics2D proxy, I keep track of the current Paint and if it matches the one that actually means "shadow" I override the color, offset the GlyphVector, etc. This also means that the line breaking algorithm has to run twice, for each of the AttributedStrings (there is no way to duplicate a TextLayout but tell it to use different styles).
I'm not sure why you need to duplicate the TextLayout at that level. Once you have a GlyphVector can't the proxy just use it to render however it wants? The only problem I see would be if you needed to rebuild the glyphvector to use a different font or different number of glyphs-- all bets are off in that case.
For other attributes the hacks are even worse. For example I need to support superscripting as a percentage of line height, without affecting the font size (it only acts as a vertical offset). Currently I have to "tunnel" the amount of superscripting via the alpha channel of the foreground color :-P Chris
I hear your pain. :-) Your line height requirement sounds like a good candidate for an RFE. There is a slightly cleaner hack you might try if you're willing to forgo styled text streaming and some rendering performance. Since the foreground and background attributes use Paint as a value, and this is an interface, you can use any subclass of Paint you want, including one you build. You can then provide your own implementation of Paint, hang any data you want off it, and then delegate Paint's one API method to a standard Color or other Paint subclass that you keep as a member. I suspect (I'm not sure) our rendering loops are optimized for our standard Paint implementations, and using your own would cause slower software loops to be used. This of course is still a hack but it's the only semi-compatible way to do this with existing JVMs. New API is of course the real answer, but then you need to be able to require a new JVM that provides it... Doug =========================================================================== 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".
