Description
The following code first measures a piece of text and then tries to draw that text into a bounding box of the same size. But as you can see in the screenshot, the text doesn't fit and overflows, even though its exact size was measured.
Example
public void Draw(ICanvas canvas, RectF dirtyRect)
{
var font = new Font("Arial");
var fontSize = 16.0f;
// Measure text
var text = "abcdef ABCDEF vwxyz VWXYZ";
var textSize = canvas.GetStringSize(text, font, fontSize, HorizontalAlignment.Left, VerticalAlignment.Top);
var textRect = new Rect(new Point(100, 100), textSize);
// Draw background
canvas.FillColor = Colors.LightBlue;
canvas.FillRectangle(textRect);
// Draw text
canvas.Font = font;
canvas.FontSize = fontSize;;
canvas.DrawString(text, textRect, HorizontalAlignment.Left, VerticalAlignment.Top, TextFlow.OverflowBounds);
}
Description The following code first measures a piece of text and then tries to draw that text into a bounding box of the same size. But as you can see in the screenshot, the text doesn't fit and overflows, even though its exact size was measured.
Example
Screenshots
Versions