Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
//
//
// Mono.Cairo drawing samples using image (png) as drawing surface
// Author: Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using Cairo;
public class CairoTest
{
static readonly double M_PI = 3.14159265358979323846;
static void draw (Cairo.Context gr, int width, int height)
{
double xc = 0.5;
double yc = 0.5;
double radius = 0.4;
double angle1 = 45.0 * (M_PI/180.0);
double angle2 = 180.0 * (M_PI/180.0);
gr.Scale (width, height);
gr.LineWidth = 0.04;
gr.Arc (xc, yc, radius, angle1, angle2);
gr.Stroke ();
/* draw helping lines */
gr.Color = new Color(1, 0.2, 0.2, 0.6);
gr.Arc (xc, yc, 0.05, 0, 2*M_PI);
gr.Fill ();
gr.LineWidth = 0.03;
gr.Arc (xc, yc, radius, angle1, angle1);
gr.LineTo (new PointD(xc, yc));
gr.Arc (xc, yc, radius, angle2, angle2);
gr.LineTo (new PointD(xc, yc));
gr.Stroke ();
}
static void Main ()
{
Surface s = new ImageSurface (Format.ARGB32, 500, 500);
Cairo.Context g = new Cairo.Context (s);
draw (g, 500, 500);
s.WriteToPng ("arc.png");
}
}

View File

@@ -0,0 +1,73 @@
//
//
// Mono.Cairo drawing samples using image (png) as drawing surface
// Author: Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using Cairo;
public class CairoTest
{
static readonly double M_PI = 3.14159265358979323846;
static void draw (Cairo.Context gr, int width, int height)
{
double xc = 0.5;
double yc = 0.5;
double radius = 0.4;
double angle1 = 45.0 * (M_PI/180.0); /* angles are specified */
double angle2 = 180.0 * (M_PI/180.0); /* in radians */
gr.Scale (width, height);
gr.LineWidth = 0.04;
gr.ArcNegative (xc, yc, radius, angle1, angle2);
gr.Stroke ();
/* draw helping lines */
gr.Color = new Color(1, 0.2, 0.2, 0.6);
gr.Arc (xc, yc, 0.05, 0, 2*M_PI);
gr.Fill ();
gr.LineWidth = 0.03;
gr.Arc (xc, yc, radius, angle1, angle1);
gr.LineTo (new PointD(xc, yc));
gr.Arc (xc, yc, radius, angle2, angle2);
gr.LineTo (new PointD(xc, yc));
gr.Stroke ();
}
static void Main ()
{
Surface s = new ImageSurface (Format.ARGB32, 500, 500);
Cairo.Context g = new Cairo.Context (s);
draw (g, 500, 500);
s.WriteToPng ("arcneg.png");
}
}

View File

@@ -0,0 +1,67 @@
//
//
// Mono.Cairo drawing samples using image (png) as drawing surface
// Author: Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using Cairo;
public class CairoTest
{
static readonly double M_PI = 3.14159265358979323846;
static void draw (Cairo.Context gr, int width, int height)
{
gr.Scale (width, height);
gr.LineWidth = 0.04;
gr.Arc (0.5, 0.5, 0.3, 0, 2 * M_PI);
gr.Clip ();
gr.NewPath ();
gr.Rectangle (new PointD (0, 0), 1, 1);
gr.Fill ();
gr.Color = new Color (0, 1, 0, 1);
gr.MoveTo ( new PointD (0, 0) );
gr.LineTo ( new PointD (1, 1) );
gr.MoveTo ( new PointD (1, 0) );
gr.LineTo ( new PointD (0, 1) );
gr.Stroke ();
}
static void Main ()
{
Surface s = new ImageSurface (Format.ARGB32, 500, 500);
Cairo.Context g = new Cairo.Context (s);
draw (g, 500, 500);
s.WriteToPng ("clip.png");
}
}

View File

@@ -0,0 +1,83 @@
//
//
// Mono.Cairo drawing samples using image (png) as drawing surface
// Author: Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using Cairo;
public class CairoTest
{
static readonly double M_PI = 3.14159265358979323846;
static void draw (Cairo.Context gr, int width, int height)
{
int w, h;
ImageSurface image;
gr.Scale (width, height);
gr.LineWidth = 0.04;
gr.Arc (0.5, 0.5, 0.3, 0, 2*M_PI);
gr.Clip ();
gr.NewPath ();
image = new ImageSurface("data/e.png");
w = image.Width;
h = image.Height;
gr.Scale (1.0/w, 1.0/h);
image.Show (gr, 0, 0);
image.Destroy();
gr.Arc (0.5, 0.5, 0.3, 0, 2 * M_PI);
gr.Clip ();
gr.NewPath ();
gr.Rectangle (new PointD (0, 0), 1, 1);
gr.Fill ();
gr.Color = new Color (0, 1, 0, 1);
gr.MoveTo ( new PointD (0, 0) );
gr.LineTo ( new PointD (1, 1) );
gr.MoveTo ( new PointD (1, 0) );
gr.LineTo ( new PointD (0, 1) );
gr.Stroke ();
}
static void Main ()
{
Surface s = new ImageSurface (Format.ARGB32, 500, 500);
Cairo.Context g = new Cairo.Context (s);
draw (g, 500, 500);
s.WriteToPng ("clip_img.png");
}
}

View File

@@ -0,0 +1,13 @@
#!/bin/bash
mcs -r:System.Drawing -r:Mono.Cairo -pkg:gtk-sharp arc.cs
mcs -r:System.Drawing -r:Mono.Cairo -pkg:gtk-sharp arcneg.cs
mcs -r:System.Drawing -r:Mono.Cairo -pkg:gtk-sharp clip.cs
mcs -r:System.Drawing -r:Mono.Cairo -pkg:gtk-sharp clip_img.cs
mcs -r:System.Drawing -r:Mono.Cairo -pkg:gtk-sharp curve_rect.cs
mcs -r:System.Drawing -r:Mono.Cairo -pkg:gtk-sharp curve_to.cs
mcs -r:System.Drawing -r:Mono.Cairo -pkg:gtk-sharp fillstroke.cs
mcs -r:System.Drawing -r:Mono.Cairo -pkg:gtk-sharp gradient.cs
mcs -r:System.Drawing -r:Mono.Cairo -pkg:gtk-sharp image.cs
mcs -r:System.Drawing -r:Mono.Cairo -pkg:gtk-sharp image_pattern.cs
mcs -r:System.Drawing -r:Mono.Cairo -pkg:gtk-sharp knockout.cs
mcs -r:System.Drawing -r:Mono.Cairo -pkg:gtk-sharp text.cs

View File

@@ -0,0 +1,177 @@
//
//
// Mono.Cairo drawing samples using image (png) as drawing surface
// Author: Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using Cairo;
public class CairoTest
{
static void draw (Cairo.Context gr, int width, int height)
{
double x0 = 0.1;
double y0 = 0.1;
double rect_width = 0.8;
double rect_height = 0.8;
double radius = 0.4;
double x1,y1;
gr.Scale (width, height);
gr.LineWidth = 0.04;
x1=x0+rect_width;
y1=y0+rect_height;
if (rect_width == 0 || rect_height == 0)
return;
if (rect_width/2<radius) {
if (rect_height/2<radius) {
gr.MoveTo( new PointD(x0, (y0 + y1)/2) );
gr.CurveTo ( new PointD (x0 ,y0),
new PointD (x0, y0),
new PointD ((x0 + x1)/2, y0)
);
gr.CurveTo ( new PointD (x1, y0 ),
new PointD (x1, y0 ),
new PointD (x1, (y0 + y1)/2)
);
gr.CurveTo ( new PointD (x1, y1),
new PointD (x1, y1),
new PointD ((x1 + x0)/2, y1)
);
gr.CurveTo ( new PointD (x0, y1),
new PointD (x0, y1),
new PointD (x0, (y0 + y1)/2)
);
}
else {
gr.MoveTo ( new PointD (x0, y0 + radius) );
gr.CurveTo ( new PointD (x0 ,y0),
new PointD (x0, y0),
new PointD ((x0 + x1)/2, y0)
);
gr.CurveTo ( new PointD (x1, y0),
new PointD (x1, y0),
new PointD (x1, y0 + radius)
);
gr.LineTo ( new PointD (x1 , y1 - radius) );
gr.CurveTo ( new PointD (x1, y1),
new PointD (x1, y1),
new PointD ((x1 + x0)/2, y1)
);
gr.CurveTo ( new PointD (x0, y1),
new PointD (x0, y1),
new PointD (x0, y1- radius)
);
}
}
else {
if (rect_height/2<radius) {
gr.MoveTo ( new PointD (x0, (y0 + y1)/2) );
gr.CurveTo ( new PointD (x0 , y0),
new PointD (x0 , y0),
new PointD (x0 + radius, y0)
);
gr.LineTo ( new PointD (x1 - radius, y0) );
gr.CurveTo ( new PointD (x1, y0),
new PointD (x1, y0),
new PointD (x1, (y0 + y1)/2)
);
gr.CurveTo ( new PointD (x1, y1),
new PointD (x1, y1),
new PointD (x1 - radius, y1)
);
gr.LineTo ( new PointD (x0 + radius, y1) );
gr.CurveTo ( new PointD ( x0, y1),
new PointD (x0, y1),
new PointD (x0, (y0 + y1)/2)
);
}
else {
gr.MoveTo ( new PointD (x0, y0 + radius) );
gr.CurveTo ( new PointD (x0 , y0),
new PointD (x0 , y0),
new PointD (x0 + radius, y0)
);
gr.LineTo ( new PointD (x1 - radius, y0) );
gr.CurveTo ( new PointD (x1, y0),
new PointD (x1, y0),
new PointD (x1, y0 + radius)
);
gr.LineTo ( new PointD (x1 , y1 - radius) );
gr.CurveTo ( new PointD ( x1, y1),
new PointD (x1, y1),
new PointD (x1 - radius, y1)
);
gr.LineTo ( new PointD (x0 + radius, y1) );
gr.CurveTo ( new PointD ( x0, y1),
new PointD (x0, y1),
new PointD (x0, y1- radius)
);
}
}
gr.Color = new Color (0.5,0.5,1, 1);
gr.FillPreserve ();
gr.Color = new Color(0.5, 0, 0, 0.5);
gr.Stroke ();
}
static void Main ()
{
Surface s = new ImageSurface (Format.ARGB32, 500, 500);
Cairo.Context g = new Cairo.Context (s);
draw (g, 500, 500);
s.WriteToPng ("curve_rect.png");
}
}

View File

@@ -0,0 +1,72 @@
//
//
// Mono.Cairo drawing samples using image (png) as drawing surface
// Author: Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using Cairo;
public class CairoTest
{
static void draw (Cairo.Context gr, int width, int height)
{
double x=0.1, y=0.5;
double x1=0.4, y1=0.9, x2=0.6, y2=0.1, x3=0.9, y3=0.5;
gr.Scale (width, height);
gr.LineWidth = 0.04;
gr.MoveTo ( new PointD (x, y) );
gr.CurveTo ( new PointD (x1, y1),
new PointD (x2, y2),
new PointD (x3, y3)
);
gr.Stroke ();
gr.Color = new Color (1, 0.2, 0.2, 0.6);
gr.LineWidth = 0.03;
gr.MoveTo ( new PointD (x, y) );
gr.LineTo ( new PointD (x1, y1) );
gr.MoveTo ( new PointD (x2, y2) );
gr.LineTo ( new PointD (x3, y3) );
gr.Stroke ();
}
static void Main ()
{
Surface s = new ImageSurface (Format.ARGB32, 500, 500);
Cairo.Context g = new Cairo.Context (s);
draw (g, 500, 500);
s.WriteToPng ("curve_to.png");
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

View File

@@ -0,0 +1,71 @@
//
//
// Mono.Cairo drawing samples using image (png) as drawing surface
// Author: Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using Cairo;
public class CairoTest
{
static void draw (Cairo.Context gr, int width, int height)
{
gr.Scale (width, height);
gr.LineWidth = 0.04;
gr.MoveTo ( new PointD (0.5, 0.1) );
gr.LineTo ( new PointD (0.9, 0.9) );
gr.RelLineTo ( new Distance (-0.4, 0.0) );
gr.CurveTo ( new PointD (0.2, 0.9),
new PointD ( 0.2, 0.5),
new PointD (0.5, 0.5)
);
gr.ClosePath ();
gr.MoveTo ( new PointD (0.25, 0.1) );
gr.RelLineTo ( new Distance (0.2, 0.2) );
gr.RelLineTo ( new Distance ( -0.2, 0.2) );
gr.RelLineTo ( new Distance (-0.2, -0.2) );
gr.ClosePath ();
gr.Color = new Color (0, 0, 1, 1);
gr.FillPreserve ();
gr.Color = new Color ( 0, 0, 0, 1);
gr.Stroke ();
}
static void Main ()
{
Surface s = new ImageSurface (Format.ARGB32, 500, 500);
Cairo.Context g = new Cairo.Context (s);
draw (g, 500, 500);
s.WriteToPng ("fillstroke.png");
}
}

View File

@@ -0,0 +1,76 @@
//
//
// Mono.Cairo drawing samples using image (png) as drawing surface
// Author: Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using Cairo;
public class CairoTest
{
static readonly double M_PI = 3.14159265358979323846;
static void draw (Cairo.Context gr, int width, int height)
{
gr.Scale (width, height);
gr.LineWidth = 0.04;
LinearGradient pat;
pat = new LinearGradient (0.0, 0.0, 0.0, 1.0);
pat.AddColorStop (1, new Color (0, 0, 0, 1) );
pat.AddColorStop (0, new Color (1, 1, 1, 1) );
gr.Rectangle ( new PointD (0, 0),
1, 1
);
gr.Pattern = pat;
gr.Fill ();
pat.Destroy ();
RadialGradient pat2 = new RadialGradient (0.45, 0.4, 0.1,
0.4, 0.4, 0.5);
pat2.AddColorStop (0, new Color (1, 1, 1, 1) );
pat2.AddColorStop (1, new Color (0, 0, 0, 1) );
gr.Pattern = pat2;
gr.Arc (0.5, 0.5, 0.3, 0, 2 * M_PI);
gr.Fill ();
pat2.Destroy ();
}
static void Main ()
{
Surface s = new ImageSurface (Format.ARGB32, 500, 500);
Cairo.Context g = new Cairo.Context (s);
draw (g, 500, 500);
s.WriteToPng ("gradient.png");
}
}

View File

@@ -0,0 +1,69 @@
//
//
// Mono.Cairo drawing samples using image (png) as drawing surface
// Author: Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using Cairo;
public class CairoTest
{
static readonly double M_PI = 3.14159265358979323846;
static void draw (Cairo.Context gr, int width, int height)
{
int w, h;
ImageSurface image;
gr.Scale (width, height);
gr.LineWidth = 0.04;
image = new ImageSurface ("data/e.png");
w = image.Width;
h = image.Height;
gr.Translate (0.5, 0.5);
gr.Rotate (45* M_PI/180);
gr.Scale (1.0/w, 1.0/h);
gr.Translate (-0.5*w, -0.5*h);
image.Show (gr, 0, 0);
image.Destroy ();
}
static void Main ()
{
Surface s = new ImageSurface (Format.ARGB32, 500, 500);
Cairo.Context g = new Cairo.Context (s);
draw (g, 500, 500);
s.WriteToPng ("image.png");
}
}

View File

@@ -0,0 +1,83 @@
//
//
// Mono.Cairo drawing samples using image (png) as drawing surface
// Author: Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using Cairo;
public class CairoTest
{
static readonly double M_PI = 3.14159265358979323846;
static void draw (Cairo.Context gr, int width, int height)
{
int w, h;
ImageSurface image;
Matrix matrix;
SurfacePattern pattern;
gr.Scale (width, height);
gr.LineWidth = 0.04;
image = new ImageSurface ("data/e.png");
w = image.Width;
h = image.Height;
pattern = new SurfacePattern (image);
pattern.Extend = Cairo.Extend.Repeat;
gr.Translate (0.5, 0.5);
gr.Rotate (M_PI / 4);
gr.Scale (1 / Math.Sqrt (2), 1 / Math.Sqrt (2));
gr.Translate (- 0.5, - 0.5);
matrix = new Matrix ();
matrix.InitScale (w * 5.0, h * 5.0);
pattern.Matrix = matrix;
gr.Pattern = pattern;
gr.Rectangle ( new PointD (0, 0),
1.0, 1.0);
gr.Fill ();
pattern.Destroy ();
image.Destroy();
}
static void Main ()
{
Surface s = new ImageSurface (Format.ARGB32, 500, 500);
Cairo.Context g = new Cairo.Context (s);
draw (g, 500, 500);
s.WriteToPng ("image_pattern.png");
}
}

View File

@@ -0,0 +1,133 @@
using System;
using Cairo;
class Knockout
{
void OvalPath (Context ctx, double xc, double yc, double xr, double yr)
{
Matrix m = ctx.Matrix;
ctx.Translate (xc, yc);
ctx.Scale (1.0, yr / xr);
ctx.MoveTo (xr, 0.0);
ctx.Arc (0, 0, xr, 0, 2 * Math.PI);
ctx.ClosePath ();
ctx.Matrix = m;
}
void FillChecks (Context ctx, int x, int y, int width, int height)
{
int CHECK_SIZE = 32;
ctx.Save ();
Surface check = ctx.Target.CreateSimilar (Content.Color, 2 * CHECK_SIZE, 2 * CHECK_SIZE);
// draw the check
Context cr2 = new Context (check);
cr2.Operator = Operator.Source;
cr2.Color = new Color (0.4, 0.4, 0.4);
cr2.Rectangle (0, 0, 2 * CHECK_SIZE, 2 * CHECK_SIZE);
cr2.Fill ();
cr2.Color = new Color (0.7, 0.7, 0.7);
cr2.Rectangle (x, y, CHECK_SIZE, CHECK_SIZE);
cr2.Fill ();
cr2.Rectangle (x + CHECK_SIZE, y + CHECK_SIZE, CHECK_SIZE, CHECK_SIZE);
cr2.Fill ();
//cr2.Destroy ();
// Fill the whole surface with the check
SurfacePattern check_pattern = new SurfacePattern (check);
check_pattern.Extend = Extend.Repeat;
ctx.Source = check_pattern;
ctx.Rectangle (0, 0, width, height);
ctx.Fill ();
check_pattern.Destroy ();
check.Destroy ();
ctx.Restore ();
}
void Draw3Circles (Context ctx, int xc, int yc, double radius, double alpha)
{
double subradius = radius * (2 / 3.0 - 0.1);
ctx.Color = new Color (1.0, 0.0, 0.0, alpha);
OvalPath (ctx, xc + radius / 3.0 * Math.Cos (Math.PI * 0.5), yc - radius / 3.0 * Math.Sin (Math.PI * 0.5), subradius, subradius);
ctx.Fill ();
ctx.Color = new Color (0.0, 1.0, 0.0, alpha);
OvalPath (ctx, xc + radius / 3.0 * Math.Cos (Math.PI * (0.5 + 2 / 0.3)), yc - radius / 3.0 * Math.Sin (Math.PI * (0.5 + 2 / 0.3)), subradius, subradius);
ctx.Fill ();
ctx.Color = new Color (0.0, 0.0, 1.0, alpha);
OvalPath (ctx, xc + radius / 3.0 * Math.Cos (Math.PI * (0.5 + 4 / 0.3)), yc - radius / 3.0 * Math.Sin (Math.PI * (0.5 + 4 / 0.3)), subradius, subradius);
ctx.Fill ();
}
void Draw (Context ctx, int width, int height)
{
double radius = 0.5 * Math.Min (width, height) - 10;
int xc = width / 2;
int yc = height / 2;
Surface overlay = ctx.Target.CreateSimilar (Content.ColorAlpha, width, height);
Surface punch = ctx.Target.CreateSimilar (Content.Alpha, width, height);
Surface circles = ctx.Target.CreateSimilar (Content.ColorAlpha, width, height);
FillChecks (ctx, 0, 0, width, height);
ctx.Save ();
// Draw a black circle on the overlay
Context cr_overlay = new Context (overlay);
cr_overlay.Color = new Color (0.0, 0.0, 0.0);
OvalPath (cr_overlay, xc, yc, radius, radius);
cr_overlay.Fill ();
// Draw 3 circles to the punch surface, then cut
// that out of the main circle in the overlay
Context cr_tmp = new Context (punch);
Draw3Circles (cr_tmp, xc, yc, radius, 1.0);
//cr_tmp.Destroy ();
cr_overlay.Operator = Operator.DestOut;
cr_overlay.SetSourceSurface (punch, 0, 0);
cr_overlay.Paint ();
// Now draw the 3 circles in a subgroup again
// at half intensity, and use OperatorAdd to join up
// without seams.
Context cr_circles = new Context (circles);
cr_circles.Operator = Operator.Over;
Draw3Circles (cr_circles, xc, yc, radius, 0.5);
// cr_circles.Destroy ();
cr_overlay.Operator = Operator.Add;
cr_overlay.SetSourceSurface (circles, 0, 0);
cr_overlay.Paint ();
// cr_overlay.Destroy ();
ctx.SetSourceSurface (overlay, 0, 0);
ctx.Paint ();
overlay.Destroy ();
punch.Destroy ();
circles.Destroy ();
}
static void Main ()
{
new Knockout ();
}
Knockout ()
{
Surface s = new ImageSurface (Format.ARGB32, 400, 400);
Context ctx = new Context (s);
Draw (ctx, 400, 400);
s.WriteToPng ("knockout.png");
}
}

View File

@@ -0,0 +1,145 @@
//
//
// Mono.Cairo drawing samples using image (png) as drawing surface
// Author: Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using Cairo;
public class CairoTest
{
static readonly double M_PI = 3.14159265358979323846;
static void draw (Cairo.Context gr, int width, int height)
{
//gr.Scale (width, height);
//gr.LineWidth = 0.04;
double X_FUZZ = 0.08;
double Y_FUZZ = 0.08;
double X_INNER_RADIUS = 0.3;
double Y_INNER_RADIUS = 0.2;
double X_OUTER_RADIUS = 0.45;
double Y_OUTER_RADIUS = 0.35;
double SPIKES = 10;
int i;
double x;
double y;
string text = "KAPOW!";
cairo_text_extents_t extents;
srand (45);
cairo_set_line_width (cr, 0.01);
for (i = 0; i < SPIKES * 2; i++) {
x = 0.5 + cos (M_PI * i / SPIKES) * X_INNER_RADIUS +
(double) rand() * X_FUZZ / RAND_MAX;
y = 0.5 + sin (M_PI * i / SPIKES) * Y_INNER_RADIUS +
(double) rand() * Y_FUZZ / RAND_MAX;
if (i == 0)
cairo_move_to (cr, x, y);
else
cairo_line_to (cr, x, y);
i++;
x = 0.5 + cos (M_PI * i / SPIKES) * X_OUTER_RADIUS +
(double) rand() * X_FUZZ / RAND_MAX;
y = 0.5 + sin (M_PI * i / SPIKES) * Y_OUTER_RADIUS +
(double) rand() * Y_FUZZ / RAND_MAX;
cairo_line_to (cr, x, y);
}
cairo_close_path (cr);
cairo_stroke (cr);
cairo_select_font_face (cr, "Sans",
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_BOLD);
cairo_move_to (cr, x, y);
cairo_text_path (cr, text);
cairo_set_font_size (cr, 0.2);
cairo_text_extents (cr, text, &extents);
x = 0.5-(extents.width/2 + extents.x_bearing);
y = 0.5-(extents.height/2 + extents.y_bearing);
cairo_set_source_rgb (cr, 1 , 1, 0.5);
cairo_fill (cr);
cairo_move_to (cr, x, y);
cairo_text_path (cr, text);
cairo_set_source_rgb (cr, 0 , 0, 0);
cairo_stroke (cr);
gr.Arc (xc, yc, radius, angle1, angle2);
gr.Stroke ();
/* draw helping lines */
gr.Color = new Color(1, 0.2, 0.2, 0.6);
gr.Arc (xc, yc, 0.05, 0, 2*M_PI);
gr.Fill ();
gr.LineWidth = 0.03;
gr.Arc (xc, yc, radius, angle1, angle1);
gr.LineTo (new PointD(xc, yc));
gr.Arc (xc, yc, radius, angle2, angle2);
gr.LineTo (new PointD(xc, yc));
gr.Stroke ();
}
static void Main ()
{
Surface s = new ImageSurface (Format.ARGB32, 500, 500);
Cairo.Context g = new Cairo.Context (s);
draw (g, 500, 500);
s.WriteToPng ("pattern_fill.png");
}
}

View File

@@ -0,0 +1,71 @@
//
//
// Mono.Cairo drawing samples using image (png) as drawing surface
// Author: Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using Cairo;
public class CairoTest
{
static readonly double M_PI = 3.14159265358979323846;
static void draw (Cairo.Context gr, int width, int height)
{
gr.Scale (width, height);
gr.LineWidth = 0.04;
gr.SelectFontFace ("Sans", FontSlant.Normal, FontWeight.Bold);
gr.SetFontSize (0.35);
gr.MoveTo ( new PointD(0.04, 0.53) );
gr.ShowText ("Hello");
gr.MoveTo ( new PointD(0.27, 0.65) );
gr.TextPath ("void");
gr.ColorRgb = new Color (0.5, 0.5, 1, 0);
gr.FillPreserve ();
gr.ColorRgb = new Color (0, 0, 0, 0);
gr.LineWidth = 0.01;
gr.Stroke ();
gr.Color = new Color (1,0.2,0.2, 0.6);
gr.Arc (0.04, 0.53, 0.02, 0, 2*M_PI);
gr.Arc (0.27, 0.65, 0.02, 0, 2*M_PI);
gr.Fill ();
}
static void Main ()
{
Surface s = new ImageSurface (Format.ARGB32, 500, 500);
Cairo.Context g = new Cairo.Context (s);
draw (g, 500, 500);
s.WriteToPng ("text.png");
}
}