3

I'm using ICSharpCode's AvalonEdit text editor, and I have a custom DocumentColorizingTransformer.

I would like to center certain lines of text inside of ColorizeLine. Is this possible?

I've been able to figure out how to change the line's text in every other way I want (color, italics, underline, etc), but I can't figure out how to change the line's text alignment...

Etheryte
  • 20,940
  • 10
  • 58
  • 98
encoder
  • 595
  • 4
  • 14

1 Answers1

2

I ended up having to dig into the editor's source for this:

First, in VisualLineTextParagraphProperties.cs, I had to expose the TextAlignment via a new internal property (defaulted to LeftAligned), so I could set it (and, of course, return it from the getter of the public property).

Then, in TextView.cs, in the BuildVisualLine method, I had to test the text of documentLine for the conditions under which I wanted the line centered, then change the paragraphProperties object accordingly.

Do note that I had to make a copy of paragraphProperties - otherwise the centered alignment would bleed over into the next line (because the given paragraphProperties object seems to be reused).

Also note that I could not find a way to use a VisualLineElementGenerator to do this - even though it still looks to me like that would be the place to change something like TextAlignment...

encoder
  • 595
  • 4
  • 14
  • For right-hand-side alignment, few 2 pixels decrement to `availableSize.Width` is required when `TextLine` is constructed. Otherwise, beam cursor will be invisible as it's pushed beyond right border. – zmechanic Oct 27 '15 at 08:13