Cairo API 1.10 updates.

* cairo/*: merge changes to Mono.Cairo since we split back in Oct 2008.
  Not much changed.  Scrubbed the doc index and updated NativeMethods
  to match.  Commented with DONTCARE the ones we will ignore.  Implemented
  a few of them, including an initial Device binding.  Still some work
  to do, and some discovery to be done to see what happened to Xcb, Glitz,
  and DirectFB surfaces and whether we need to remove those classes.
This commit is contained in:
Mike Kestner 2011-02-17 23:00:12 -06:00
parent 5e6bd92b73
commit ee866216b1
13 changed files with 870 additions and 519 deletions

View file

@ -186,7 +186,7 @@ namespace Cairo {
public Context (IntPtr state)
{
this.state = state;
this.state = NativeMethods.cairo_reference (state);
}
~Context ()
@ -359,6 +359,10 @@ namespace Cairo {
}
}
public bool HasCurrentPoint {
get { return NativeMethods.cairo_has_current_point (state); }
}
public Cairo.Surface Target {
set {
if (state != IntPtr.Zero)
@ -530,6 +534,11 @@ namespace Cairo {
NativeMethods.cairo_append_path (state, path.handle);
}
public void PathExtents (out double x1, out double y1, out double x2, out double y2)
{
NativeMethods.cairo_path_extents (state, out x1, out y1, out x2, out y2);
}
#endregion
#region Painting Methods
@ -609,6 +618,11 @@ namespace Cairo {
return NativeMethods.cairo_in_stroke (state, x, y);
}
public bool InClip (double x, double y)
{
return NativeMethods.cairo_in_clip (state, x, y);
}
public bool InFill (double x, double y)
{
return NativeMethods.cairo_in_fill (state, x, y);
@ -898,5 +912,10 @@ namespace Cairo {
return extents;
}
public static int FormatStrideForWidth (Format format, int width)
{
return NativeMethods.cairo_format_stride_for_width (format, width);
}
}
}

85
cairo/Device.cs Normal file
View file

@ -0,0 +1,85 @@
// Copyright (c) 2011 Novell, Inc.
//
// 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;
namespace Cairo
{
public enum DeviceType {
Drm,
GL,
Script,
Xcb,
Xlib,
Xml,
}
public class Device : IDisposable
{
IntPtr handle;
internal Device (IntPtr handle)
{
this.handle = NativeMethods.cairo_device_reference (handle);
}
public Status Acquire ()
{
return NativeMethods.cairo_device_acquire (handle);
}
public void Dispose ()
{
if (handle != IntPtr.Zero)
NativeMethods.cairo_device_destroy (handle);
handle = IntPtr.Zero;
GC.SuppressFinalize (this);
}
public void Finish ()
{
NativeMethods.cairo_device_finish (handle);
}
public void Flush ()
{
NativeMethods.cairo_device_flush (handle);
}
public void Release ()
{
NativeMethods.cairo_device_release (handle);
}
public Status Status {
get { return NativeMethods.cairo_device_status (handle); }
}
public DeviceType Type {
get { return NativeMethods.cairo_device_get_type (handle); }
}
}
}

View file

@ -51,13 +51,13 @@ namespace Cairo
~FontFace ()
{
// Since Cairo is not thread safe, we can not unref the
// font_face here, the programmer must do this with IDisposable.Dispose
// font_face here, the programmer must do this with Dispose
Console.Error.WriteLine ("Programmer forgot to call Dispose on the FontFace");
Dispose (false);
}
void IDisposable.Dispose ()
public void Dispose ()
{
Dispose (true);
}

View file

@ -51,7 +51,10 @@ namespace Cairo {
}
}
public ImageSurface (ref byte[] data, Cairo.Format format, int width, int height, int stride)
[Obsolete ("Replaced by ctor (byte[] data, Cairo.Format format, int width, int height, int stride)")]
public ImageSurface (ref byte[] data, Cairo.Format format, int width, int height, int stride) : this (data, format, width, height, stride) {}
public ImageSurface (byte[] data, Cairo.Format format, int width, int height, int stride)
{
surface = NativeMethods.cairo_image_surface_create_for_data (data, format, width, height, stride);
lock (surfaces.SyncRoot){

View file

@ -14,6 +14,7 @@ sources = \
Cairo.cs \
Content.cs \
Context.cs \
Device.cs \
DirectFBSurface.cs \
Extend.cs \
FillRule.cs \

File diff suppressed because it is too large Load diff

View file

@ -46,12 +46,12 @@ namespace Cairo {
public void BeginPageSetup ()
{
NativeMethods.cairo_ps_surface_begin_page_setup (surface);
NativeMethods.cairo_ps_surface_dsc_begin_page_setup (surface);
}
public void BeginSetup ()
{
NativeMethods.cairo_ps_surface_begin_setup (surface);
NativeMethods.cairo_ps_surface_dsc_begin_setup (surface);
}
public void DscComment (string comment)

View file

@ -49,7 +49,7 @@ namespace Cairo {
}
void IDisposable.Dispose ()
public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);

View file

@ -89,7 +89,7 @@ namespace Cairo {
NativeMethods.cairo_pattern_reference (pattern);
}
void IDisposable.Dispose ()
public void Dispose ()
{
Dispose (true);
}
@ -112,6 +112,11 @@ namespace Cairo {
}
}
public Extend Extend {
get { return NativeMethods.cairo_pattern_get_extend (pattern); }
set { NativeMethods.cairo_pattern_set_extend (pattern, value); }
}
public Status Status
{
get { return NativeMethods.cairo_pattern_status (pattern); }

View file

@ -42,8 +42,6 @@ namespace Cairo
public class Region : IDisposable {
const string libname = "libcairo.dll";
IntPtr handle;
public IntPtr Handle {
get { return handle; }
@ -51,202 +49,136 @@ namespace Cairo
~Region ()
{
Dispose (false);
Console.WriteLine ("Cairo.Region finalizer reached - developer must dispose regions manually to avoid leakage due to thread-safety concerns.");
}
[DllImport (libname)]
static extern IntPtr cairo_region_reference (IntPtr region);
public Region (IntPtr handle) : this (handle, false) {}
public Region (IntPtr handle)
public Region (IntPtr handle, bool owned)
{
handle = cairo_region_reference (handle);
this.handle = handle;
if (!owned)
NativeMethods.cairo_region_reference (handle);
}
[DllImport (libname)]
static extern IntPtr cairo_region_create ();
public Region ()
{
handle = cairo_region_create ();
handle = NativeMethods.cairo_region_create ();
}
[DllImport (libname)]
static extern IntPtr cairo_region_create_rectangle (ref RectangleInt rect);
public Region (RectangleInt rect)
{
handle = cairo_region_create_rectangle (ref rect);
handle = NativeMethods.cairo_region_create_rectangle (ref rect);
}
[DllImport (libname)]
static extern IntPtr cairo_region_create_rectangles (RectangleInt[] rects, int count);
public Region (RectangleInt[] rects)
{
handle = cairo_region_create_rectangles (rects, rects.Length);
handle = NativeMethods.cairo_region_create_rectangles (rects, rects.Length);
}
[DllImport (libname)]
static extern IntPtr cairo_region_copy (IntPtr original);
public Region Copy ()
{
return new Region (cairo_region_copy (Handle));
return new Region (NativeMethods.cairo_region_copy (Handle), true);
}
[DllImport (libname)]
static extern void cairo_region_destroy (IntPtr region);
public void Dispose ()
{
Dispose (true);
}
void Dispose (bool disposing)
{
if (handle != IntPtr.Zero)
cairo_region_destroy (Handle);
NativeMethods.cairo_region_destroy (Handle);
handle = IntPtr.Zero;
if (disposing)
GC.SuppressFinalize (this);
GC.SuppressFinalize (this);
}
[DllImport (libname)]
static extern bool cairo_region_equal (IntPtr a, IntPtr b);
public override bool Equals (object obj)
{
return (obj is Region) && cairo_region_equal (Handle, (obj as Region).Handle);
return (obj is Region) && NativeMethods.cairo_region_equal (Handle, (obj as Region).Handle);
}
[DllImport (libname)]
static extern Status cairo_region_status (IntPtr region);
public override int GetHashCode ()
{
return Handle.GetHashCode ();
}
public Status Status {
get { return cairo_region_status (Handle); }
get { return NativeMethods.cairo_region_status (Handle); }
}
[DllImport (libname)]
static extern void cairo_region_get_extents (IntPtr region, out RectangleInt extents);
public RectangleInt Extents {
get {
RectangleInt result;
cairo_region_get_extents (Handle, out result);
NativeMethods.cairo_region_get_extents (Handle, out result);
return result;
}
}
[DllImport (libname)]
static extern int cairo_region_num_rectangles (IntPtr region);
public int NumRectangles {
get { return cairo_region_num_rectangles (Handle); }
get { return NativeMethods.cairo_region_num_rectangles (Handle); }
}
[DllImport (libname)]
static extern void cairo_region_get_rectangle (IntPtr region, int nth, out RectangleInt rectangle);
public RectangleInt GetRectangle (int nth)
{
RectangleInt val;
cairo_region_get_rectangle (Handle, nth, out val);
NativeMethods.cairo_region_get_rectangle (Handle, nth, out val);
return val;
}
[DllImport (libname)]
static extern bool cairo_region_is_empty (IntPtr region);
public bool IsEmpty {
get { return cairo_region_is_empty (Handle); }
get { return NativeMethods.cairo_region_is_empty (Handle); }
}
[DllImport (libname)]
static extern RegionOverlap cairo_region_contains_rectangle (IntPtr region, ref RectangleInt rectangle);
public RegionOverlap ContainsPoint (RectangleInt rectangle)
{
return cairo_region_contains_rectangle (Handle, ref rectangle);
return NativeMethods.cairo_region_contains_rectangle (Handle, ref rectangle);
}
[DllImport (libname)]
static extern bool cairo_region_contains_point (IntPtr region, int x, int y);
public bool ContainsPoint (int x, int y)
{
return cairo_region_contains_point (Handle, x, y);
return NativeMethods.cairo_region_contains_point (Handle, x, y);
}
[DllImport (libname)]
static extern void cairo_region_translate (IntPtr region, int dx, int dy);
public void Translate (int dx, int dy)
{
cairo_region_translate (Handle, dx, dy);
NativeMethods.cairo_region_translate (Handle, dx, dy);
}
[DllImport (libname)]
static extern Status cairo_region_subtract (IntPtr dst, IntPtr other);
public Status Subtract (Region other)
{
return cairo_region_subtract (Handle, other.Handle);
return NativeMethods.cairo_region_subtract (Handle, other.Handle);
}
[DllImport (libname)]
static extern Status cairo_region_subtract_rectangle (IntPtr dst, ref RectangleInt rectangle);
public Status SubtractRectangle (RectangleInt rectangle)
{
return cairo_region_subtract_rectangle (Handle, ref rectangle);
return NativeMethods.cairo_region_subtract_rectangle (Handle, ref rectangle);
}
[DllImport (libname)]
static extern Status cairo_region_intersect (IntPtr dst, IntPtr other);
public Status Intersect (Region other)
{
return cairo_region_intersect (Handle, other.Handle);
return NativeMethods.cairo_region_intersect (Handle, other.Handle);
}
[DllImport (libname)]
static extern Status cairo_region_intersect_rectangle (IntPtr dst, ref RectangleInt rectangle);
public Status IntersectRectangle (RectangleInt rectangle)
{
return cairo_region_intersect_rectangle (Handle, ref rectangle);
return NativeMethods.cairo_region_intersect_rectangle (Handle, ref rectangle);
}
[DllImport (libname)]
static extern Status cairo_region_union (IntPtr dst, IntPtr other);
public Status Union (Region other)
{
return cairo_region_union (Handle, other.Handle);
return NativeMethods.cairo_region_union (Handle, other.Handle);
}
[DllImport (libname)]
static extern Status cairo_region_union_rectangle (IntPtr dst, ref RectangleInt rectangle);
public Status UnionRectangle (RectangleInt rectangle)
{
return cairo_region_union_rectangle (Handle, ref rectangle);
return NativeMethods.cairo_region_union_rectangle (Handle, ref rectangle);
}
[DllImport (libname)]
static extern Status cairo_region_xor (IntPtr dst, IntPtr other);
public Status Xor (Region other)
{
return cairo_region_xor (Handle, other.Handle);
return NativeMethods.cairo_region_xor (Handle, other.Handle);
}
[DllImport (libname)]
static extern Status cairo_region_xor_rectangle (IntPtr dst, ref RectangleInt rectangle);
public Status XorRectangle (RectangleInt rectangle)
{
return cairo_region_xor_rectangle (Handle, ref rectangle);
return NativeMethods.cairo_region_xor_rectangle (Handle, ref rectangle);
}
}
}

View file

@ -91,7 +91,7 @@ namespace Cairo {
get { return NativeMethods.cairo_scaled_font_status (handle); }
}
void IDisposable.Dispose ()
public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);

View file

@ -139,7 +139,7 @@ namespace Cairo {
NativeMethods.cairo_paint (gr.Handle);
}
void IDisposable.Dispose ()
public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
@ -184,6 +184,13 @@ namespace Cairo {
}
}
public Device Device {
get {
IntPtr dev = NativeMethods.cairo_surface_get_device (surface);
return dev == IntPtr.Zero ? null : new Device (dev);
}
}
public PointD DeviceOffset {
get {
double x, y;

View file

@ -42,11 +42,6 @@ namespace Cairo {
pattern = NativeMethods.cairo_pattern_create_for_surface (surface.Handle);
}
public Extend Extend {
set { NativeMethods.cairo_pattern_set_extend (pattern, value); }
get { return NativeMethods.cairo_pattern_get_extend (pattern); }
}
public Filter Filter {
set { NativeMethods.cairo_pattern_set_filter (pattern, value); }
get { return NativeMethods.cairo_pattern_get_filter (pattern); }