I am writing a movie script editor using AvalonEdit.
I extended the DocumentLine class to have a "Type" property, with the value representing either a "Character", "Dialog Line", etc.
I would like document lines of a certain type within the script to be written in upper case (character names for example).
Is there an extension point within the rendering pipeline that would allow me to fetch a document line and change it's casing ?
I tried creating a class that extends DocumentColorizingTransformer, but changing the casing within the "protected override void ColorizeLine(DocumentLine line)" method didn't work.
This is difficult, because upper-casing can change the mapping between displayed characters and the document (visual columns vs. document offsets).
For example, the single character 'ß' (German sharp s) exists only as a lower-case letter, and gets converted to the two-character string "SS" when calling
string.ToUpper()
. Editing this text is tricky: we can't allow the user to replace only one of the 'S', as the underlying document only contains the 'ß'.A simple solution is to use the
char.ToUpper()
method instead, enforcing a one-to-one mapping between original and uppercase characters. This will keep letters like 'ß' unchanged.In AvalonEdit 4.2, only two transformations are allowed on the already generated VisualLineElements:
ChangeLinePart()
so that properties can be changed for a text portion.This means it is not possible to do a text replacement in a colorizer, you need to implement this using a
VisualLineElementGenerator
.In AvalonEdit 4.3.0.8868, I added the method
VisualLine.ReplaceElement()
. This can be used to replace the defaultVisualText
elements withUppercaseText
elements within a line transformer (colorizer).Note that it is also possible to implement support for 'ß' being displayed as 'SS'. For that, you would have to implement your own copy of
VisualLineText
instead of just overriding the existing one. Then you can use a visual length that differs from the document length. TheGetRelativeOffset
andGetVisualColumns
methods would be used to provide the mapping between the document and visual coordinates.There is another option you could use: small caps.
However, WPF will render small caps only when using an OpenType font that supports them. In my testing,
Cambria
worked with small caps, most other fonts don't. Also, theSetTypographyProperties
method andDefaultTextRunTypographyProperties
class require AvalonEdit 4.3.