[prev in list] [next in list] [prev in thread] [next in thread]
List: mono-devel-list
Subject: [Mono-dev] Mono.Cairo Context.StrokeExtents() and
From: "Greg Lowe" <greg () vis ! net ! nz>
Date: 2006-05-27 3:11:07
Message-ID: c20bed830605262011l1ef123f6jd185520e3d89eb26 () mail ! gmail ! com
[Download RAW message or body]
I found a bug in Context.StrokeExtents() and Context.FillExtents().
Luckily it's got an easy fix:
public Rectangle StrokeExtents ()
{
double x1, y1, x2, y2;
CairoAPI.cairo_stroke_extents (state, out x1, out y1, out x2, out y2);
return new Rectangle (x1, y1, x2, y2);
//fix: return new Rectangle (x1, y1, x2-x1, y2-y1);
}
public Rectangle FillExtents ()
{
double x1, y1, x2, y2;
CairoAPI.cairo_fill_extents (state, out x1, out y1, out x2, out y2);
return new Rectangle (x1, y1, x2, y2);
//fix: return new Rectangle (x1, y1, x2-x1, y2-y1);
}
Here are some example results from my test code (See test code first):
- Before the patch: http://greg.lowe.googlepages.com/mono-cairo-bug.png
- After the patch: http://greg.lowe.googlepages.com/mono-cairo-after-patch.png
And the code which created these images:
using System;
using Cairo;
public class TestExtents
{
public static void Main(string[] arg)
{
Surface s = new ImageSurface( Format.ARGB32, 250, 250 );
Context cr = new Context(s);
DrawTestCase(cr);
s.WriteToPng("test.png");
}
private static void DrawTestCase( Context cr ){
cr.Arc( 100, 100, 25, 0, 2*Math.PI );
cr.Color = new Color(1,0,0);
// lookup extents
Rectangle extents = cr.StrokeExtents();
cr.Stroke();
// draw raw extents
cr.NewPath();
cr.Rectangle( extents.X, extents.Y, extents.Width, extents.Height );
cr.Color = new Color(0,0,1);
cr.Stroke();
// correct extents with workaround
cr.NewPath();
cr.Color = new Color(1,0,0);
double realWidth, realHeight;
realWidth = extents.Width - extents.X; // workaround
realHeight = extents.Height - extents.Y; // workaround
cr.Rectangle( extents.X, extents.Y, realWidth, realHeight );
cr.Stroke();
}
}
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic