Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8251241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:10:14+00:00 2026-06-08T00:10:14+00:00

I am writing a movie script editor using AvalonEdit. I extended the DocumentLine class

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T00:10:17+00:00Added an answer on June 8, 2026 at 12:10 am

    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:

    • Change the text run properties, e.g. font size, text color, etc.
    • Split a VisualLineElement in two – this is used internally by 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.

    /// <summary>
    /// Makes all text after a colon (until the end of line) upper-case.
    /// </summary>
    public class UppercaseGenerator : VisualLineElementGenerator
    {
        public override int GetFirstInterestedOffset(int startOffset)
        {
            TextDocument document = CurrentContext.Document;
            int endOffset = CurrentContext.VisualLine.LastDocumentLine.EndOffset;
            for (int i = startOffset; i < endOffset; i++) {
                char c = document.GetCharAt(i);
                if (c == ':')
                    return i + 1;
            }
            return -1;
        }
    
        public override VisualLineElement ConstructElement(int offset)
        {
            DocumentLine line = CurrentContext.Document.GetLineByOffset(offset);
            return new UppercaseText(CurrentContext.VisualLine, line.EndOffset - offset);
        }
    
        /// <summary>
        /// Displays a portion of the document text, but upper-cased.
        /// </summary>
        class UppercaseText : VisualLineText
        {
            public UppercaseText(VisualLine parentVisualLine, int length) : base(parentVisualLine, length)
            {
            }
    
            protected override VisualLineText CreateInstance(int length)
            {
                return new UppercaseText(ParentVisualLine, length);
            }
    
            public override TextRun CreateTextRun(int startVisualColumn, ITextRunConstructionContext context)
            {
                if (context == null)
                    throw new ArgumentNullException("context");
    
                int relativeOffset = startVisualColumn - VisualColumn;
                StringSegment text = context.GetText(context.VisualLine.FirstDocumentLine.Offset + RelativeTextOffset + relativeOffset, DocumentLength - relativeOffset);
                char[] uppercase = new char[text.Count];
                for (int i = 0; i < text.Count; i++) {
                    uppercase[i] = char.ToUpper(text.Text[text.Offset + i]);
                }
                return new TextCharacters(uppercase, 0, uppercase.Length, this.TextRunProperties);
            }
        }
    }
    

    In AvalonEdit 4.3.0.8868, I added the method VisualLine.ReplaceElement(). This can be used to replace the default VisualText elements with UppercaseText 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. The GetRelativeOffset and GetVisualColumns methods would be used to provide the mapping between the document and visual coordinates.


    There is another option you could use: small caps.

    // in the colorizer:
    ChangeLinePart(start, end, e => e.TextRunProperties.SetTypographyProperties(new CapsTypography()));
    
    // helper class
    class CapsTypography : DefaultTextRunTypographyProperties
    {
        public override FontCapitals Capitals {
            get { return FontCapitals.SmallCaps; }
        }
    }
    

    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, the SetTypographyProperties method and DefaultTextRunTypographyProperties class require AvalonEdit 4.3.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing some automated acceptance tests for a flash movie (driving the movie using
I'm using SQL Server MS. I'm having trouble writing this script: CREATE VIEW rental_view
In the past, I have written a script using the Python IMAP library to
I am writing a lua script and I have to execute two shell commands
I am writing a php script (I have to use php) to cycle through
I'm writing a script to move files out of a certain folder in my
I was writing a script on Windows Vista to move the files in a
I'm writing a PHP script that I want to disable from web access (I
I am writing a Autohotkey script that need to 'check' and 'uncheck' checkboxes defined
I am writing Perl scripts and when I have too many functions, I usually

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.