Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Bug with MeasureCharacterRanges on Linux, if text contains LF/CR #663

@IshmaZX82

Description

@IshmaZX82

I'm using the System.Drawing.Common NuGet package.
Main problem: there is a difference in how method MeasureCharacterRanges work on Windows and on Linux.
On Windows this code works correctly: each char -> rectangle, CR/LF -> empty rectangle.
On Linux: CR symbols disappear, the first symbols of each line after LF also disappear.

Code:

                    var g = Graphics.FromImage(new Bitmap(1, 1));
                    var font = new Font("Arial", 11f);
                    var rect = new RectangleF(0, 0, 99999, 99999);
                    var sf = new StringFormat();
                    string text = "12\r\n34\r\n56";
                    var count = text.Length;

                    CharacterRange[] cr = new CharacterRange[count];
                    for (int index = 0; index < count; index++)
                    {
                        cr[index].First = index;
                        cr[index].Length = 1;
                    }
                    sf.SetMeasurableCharacterRanges(cr);
                    Region[] ranges = g.MeasureCharacterRanges(text, font, rect, sf);

                    RectangleF?[] rects = new RectangleF?[count];
                    for (int index = 0; index < count; index++)
                    {
                        rects[index] = ranges[index].GetBounds(g);
                    }

Results on Windows:

on win

Results on Linux:

on linux

I highlighted the symbols and their rectangles in yellow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions