8000 DrawString clips text · Issue #736 · mono/libgdiplus · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
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.
DrawString clips text #736
Open
Open
@jhergens

Description

@jhergens

The DrawString method clips text. At least for some fonts. The following code:

using var font = new Font("Liberation Sans", 11f, GraphicsUnit.Pixel);
using var backBuffer = new Bitmap(50, 80);
using (var graphics = Graphics.FromImage(backBuffer))
using (var stringFormat = new StringFormat())
{
    graphics.Clear(Color.White);

    // Draw a right aligned string with clipping on.
    var text = "Hello";
    var bounds = new RectangleF(10, 10, 30, 16);
    stringFormat.Alignment = StringAlignment.Far;
    graphics.FillRectangle(Brushes.Red, bounds);
    graphics.DrawString(text, font, Brushes.Black, bounds, stringFormat);

    // Draw it without clipping
    bounds.Offset(0, 25);
    stringFormat.FormatFlags |= StringFormatFlags.NoClip;
    graphics.FillRectangle(Brushes.Red, bounds);
    graphics.DrawString(text, font, Brushes.Black, bounds, stringFormat);

    // Measure string and render in resulting rectangle
    stringFormat.Alignment = StringAlignment.Near;
    bounds.Offset(0, 25);
    var size = graphics.MeasureString(text, font);
    bounds.Size = size;
    graphics.FillRectangle(Brushes.Red, bounds);
    graphics.DrawString(text, font, Brushes.Black, bounds, stringFormat);
}

Yields the following result:
text_linux

The first line is rendered with clipping. The other two without. It is clear that the last glyph will not be rendered correctly when clipping is on.

We are building libgdiplus with Pango backend.

Metadata

Metadata

Assignees

No one assigned

    Labels

    33CF
    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0