On Tue, 2006-06-20 at 22:23 -0700, Chris Nokleberg wrote: > On Tue, Jun 20, 2006 at 07:41:32PM -0700, douglas felt wrote: > > Have you filed RFE's for the features you had to implement yourself? > > Not yet, but I'll try to put something together. > > 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?". > > 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). > > 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
Chris, I'm not sure that my situation matches yours, but I'll describe my approach (about to be superseded by the use of TextMeasurer). I start with an AttributedString which has been constructed from chunks of text, each of which has its own map of attributes. This text is passed through a hyphenator, which inserts hyphenation marker characters with an associated custom subclass of Attribute. Each space character also gets an extra custom attribute, on a font-by-font basis, representing the amount of stretch or squeeze allowable on the space character. (This is the "glue" construct from the TeX line-breaker.) A new AttributedString is constructed from these sub-sets. It includes all of the original attribute mappings, and the custom attributes. Iterators are obtained for line breaks, word breaks, Font changes and the custom hyphenation breaks and spaces. I have the original text as a char[]. I process the AttributedString on the basis of the break iterators, into an array of GlyphVectors representing individual words or word fragments (in the case of hyphenated words). For each sub-vector, I obtain the mapping back to the text, and thereby back to the original AttributedString, through the getGlyphCharIndices method of GlyphVector. The sub-vectors are contained in a custom CompositeGlyphVector class, with inner classes CompositeGlyphIndex, CompositeTextIndex and CompositeGlyphCharIndices. Methos in these classes allow me to map back and forwards between the sub-vectors and the original text and attributes. It's not exactly quick and dirty, but it works for me. TextMeasurer will make this a lot easier. Peter =========================================================================== 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".