Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing FontRenderingEmSize with DocumentColorizingTransformer causing incorrect rendering #436

Open
gebodal opened this issue Jul 2, 2024 · 0 comments

Comments

@gebodal
Copy link

gebodal commented Jul 2, 2024

Using SetFontRenderingEmSize(double) to change the size of text on an individual line in the editor using DocumentColorizingTransformer does not render correctly.

Current Behaviour (AvaloniaEdit 11.0.6)

image

The line height is not being set correctly, and the text baseline is offset from its expected position. However the actual fontsize seems to be correct, and text decorations are still being correctly placed relative to the scaled glyphs.

Expected Behaviour (AvalonEdit 6.3.0.90)

image

Example Code

public class ExampleFontSizeTransformer : DocumentColorizingTransformer {
    protected override void ColorizeLine(DocumentLine line) {
        string chars = CurrentContext.GetText(line.Offset, Math.Min(1, line.Length)).Text;

        if (!chars.StartsWith("#")) { return; }

        float multiplier = 3f;

        foreach (VisualLineElement elem in CurrentContext.VisualLine.Elements) {
            ChangeVisualElements(
                elem.VisualColumn, // startOffset
                elem.VisualColumn + elem.VisualLength, // endOffset
                (VisualLineElement element) => {
                    double initial = element.TextRunProperties.FontRenderingEmSize;
                    element.TextRunProperties.SetFontRenderingEmSize(initial * multiplier);
                });
        }
    }
}

And then during initialization:

textEditor.TextArea.TextView.LineTransformers.Add(new ExampleFontSizeTransformer());

Notes

Same behaviour with FontFamily set to: Roboto Mono, Consolas, Times New Roman.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant