// 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
using System;
using System.Runtime.InteropServices;
+using System.Text;
using Cairo;
namespace Cairo {
- public struct Point
- {
- public Point (int x, int y)
- {
- this.x = x;
- this.y = y;
- }
-
- int x, y;
- public int X {
- get { return x; }
- set { x = value; }
- }
-
- public int Y {
- get { return y; }
- set { y = value; }
- }
- }
-
- public struct PointD
- {
- public PointD (double x, double y)
- {
- this.x = x;
- this.y = y;
- }
-
- double x, y;
- public double X {
- get { return x; }
- set { x = value; }
- }
-
- public double Y {
- get { return y; }
- set { y = value; }
- }
- }
-
-
- public struct Distance
- {
- public Distance (double dx, double dy)
- {
- this.dx = dx;
- this.dy = dy;
- }
-
- double dx, dy;
- public double Dx {
- get { return dx; }
- set { dx = value; }
- }
-
- public double Dy {
- get { return dy; }
- set { dy = value; }
- }
- }
-
- public struct Color
- {
- public Color(double r, double g, double b) : this (r, g, b, 1.0)
- {
- }
-
- public Color(double r, double g, double b, double a)
- {
- this.r = r;
- this.g = g;
- this.b = b;
- this.a = a;
- }
-
- double r, g, b, a;
-
- public double R {
- get { return r; }
- set { r = value; }
- }
-
- public double G {
- get { return g; }
- set { g = value; }
- }
-
- public double B {
- get { return b; }
- set { b = value; }
- }
-
- public double A {
- get { return a; }
- set { a = value; }
- }
-
- }
-
[Obsolete ("Renamed Cairo.Context per suggestion from cairo binding guidelines.")]
public class Graphics : Context {
public Graphics (IntPtr state) : base (state) {}
public Graphics (Surface surface) : base (surface) {}
}
- public class Context : IDisposable
- {
- internal IntPtr state = IntPtr.Zero;
+ public class Context : IDisposable
+ {
+ IntPtr handle = IntPtr.Zero;
static int native_glyph_size, c_compiler_long_size;
-
+
static Context ()
{
//
// is 32 bits
//
int ptr_size = Marshal.SizeOf (typeof (IntPtr));
-
+
PlatformID platform = Environment.OSVersion.Platform;
if (platform == PlatformID.Win32NT ||
platform == PlatformID.Win32S ||
native_glyph_size = Marshal.SizeOf (typeof (Glyph));
}
}
-
- public Context (Surface surface)
- {
- state = CairoAPI.cairo_create (surface.Handle);
- }
-
- public Context (IntPtr state)
+
+ public Context (Surface surface) : this (NativeMethods.cairo_create (surface.Handle), true)
+ {
+ }
+
+
+ public Context (IntPtr handle, bool owner)
+ {
+ this.handle = handle;
+ if (!owner)
+ NativeMethods.cairo_reference (handle);
+ if (CairoDebug.Enabled)
+ CairoDebug.OnAllocated (handle);
+ }
+
+ [Obsolete]
+ public Context (IntPtr state) : this (state, true)
{
- this.state = state;
}
-
+
~Context ()
{
Dispose (false);
}
- void IDisposable.Dispose ()
+ public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
}
-
- protected virtual void Dispose (bool disposing)
- {
- if (!disposing){
- //Console.WriteLine ("Cairo.Context: called from thread");
- return;
- }
-
- if (state == IntPtr.Zero)
+
+ protected virtual void Dispose (bool disposing)
+ {
+ if (!disposing || CairoDebug.Enabled)
+ CairoDebug.OnDisposed<Context> (handle, disposing);
+
+ if (!disposing|| handle == IntPtr.Zero)
return;
- //Console.WriteLine ("Destroying");
- CairoAPI.cairo_destroy (state);
- state = IntPtr.Zero;
- }
+ NativeMethods.cairo_destroy (handle);
+ handle = IntPtr.Zero;
+
+ }
- public void Save ()
- {
- CairoAPI.cairo_save (state);
- }
+ public void Save ()
+ {
+ NativeMethods.cairo_save (handle);
+ }
- public void Restore ()
- {
- CairoAPI.cairo_restore (state);
- }
+ public void Restore ()
+ {
+ NativeMethods.cairo_restore (handle);
+ }
public Antialias Antialias {
- get { return CairoAPI.cairo_get_antialias (state); }
- set { CairoAPI.cairo_set_antialias (state, value); }
- }
-
- public Cairo.Status Status {
- get {
- return CairoAPI.cairo_status (state);
- }
- }
-
- public IntPtr Handle {
- get {
- return state;
- }
- }
-
- public Cairo.Operator Operator {
- set {
- CairoAPI.cairo_set_operator (state, value);
- }
-
- get {
- return CairoAPI.cairo_get_operator (state);
- }
- }
-
- //FIXME: obsolete this property
- public Cairo.Color Color {
- set {
- CairoAPI.cairo_set_source_rgba (state, value.R,
- value.G, value.B,
- value.A);
- }
- }
-
- [Obsolete ("Use Color property")]
- public Cairo.Color ColorRgb {
- set {
+ get { return NativeMethods.cairo_get_antialias (handle); }
+ set { NativeMethods.cairo_set_antialias (handle, value); }
+ }
+
+ public Cairo.Status Status {
+ get {
+ return NativeMethods.cairo_status (handle);
+ }
+ }
+
+ public IntPtr Handle {
+ get {
+ return handle;
+ }
+ }
+
+ public Operator Operator {
+ set {
+ NativeMethods.cairo_set_operator (handle, value);
+ }
+
+ get {
+ return NativeMethods.cairo_get_operator (handle);
+ }
+ }
+
+ [Obsolete ("Use SetSourceColor method")]
+ public Color Color {
+ set {
+ SetSourceColor (value);
+ }
+ }
+
+ [Obsolete ("Use SetSourceRGBA method")]
+ public Cairo.Color ColorRgb {
+ set {
Color = new Color (value.R, value.G, value.B);
}
- }
-
- public double Tolerance {
- get { return CairoAPI.cairo_get_tolerance (state); }
- set {
- CairoAPI.cairo_set_tolerance (state, value);
- }
- }
-
- public Cairo.FillRule FillRule {
- set {
- CairoAPI.cairo_set_fill_rule (state, value);
- }
-
- get {
- return CairoAPI.cairo_get_fill_rule (state);
- }
- }
-
- public double LineWidth {
- set {
- CairoAPI.cairo_set_line_width (state, value);
- }
-
- get {
- return CairoAPI.cairo_get_line_width (state);
- }
- }
-
- public Cairo.LineCap LineCap {
- set {
- CairoAPI.cairo_set_line_cap (state, value);
- }
-
- get {
- return CairoAPI.cairo_get_line_cap (state);
- }
- }
-
- public Cairo.LineJoin LineJoin {
- set {
- CairoAPI.cairo_set_line_join (state, value);
- }
-
- get {
- return CairoAPI.cairo_get_line_join (state);
- }
- }
-
- public void SetDash (double [] dashes, double offset)
- {
- CairoAPI.cairo_set_dash (state, dashes, dashes.Length, offset);
- }
-
- public Pattern Pattern {
- set {
- CairoAPI.cairo_set_source (state, value.Pointer);
- }
-
+ }
+
+ public double Tolerance {
get {
- return new Pattern (CairoAPI.cairo_get_source (state));
- }
- }
-
- public Pattern Source {
- set {
- CairoAPI.cairo_set_source (state, value.Pointer);
- }
-
+ return NativeMethods.cairo_get_tolerance (handle);
+ }
+
+ set {
+ NativeMethods.cairo_set_tolerance (handle, value);
+ }
+ }
+
+ public Cairo.FillRule FillRule {
+ set {
+ NativeMethods.cairo_set_fill_rule (handle, value);
+ }
+
get {
- return new Pattern (CairoAPI.cairo_get_source (state));
- }
- }
-
- public double MiterLimit {
- set {
- CairoAPI.cairo_set_miter_limit (state, value);
- }
-
- get {
- return CairoAPI.cairo_get_miter_limit (state);
- }
- }
-
- public PointD CurrentPoint {
- get {
- double x, y;
- CairoAPI.cairo_get_current_point (state, out x, out y);
- return new PointD (x, y);
- }
- }
-
- public Cairo.Surface Target {
- set {
- state = CairoAPI.cairo_create (value.Handle);
- }
-
- get {
- return Cairo.Surface.LookupExternalSurface (
- CairoAPI.cairo_get_target (state));
- }
- }
-
- [Obsolete ("Use Color property")]
+ return NativeMethods.cairo_get_fill_rule (handle);
+ }
+ }
+
+ public double LineWidth {
+ set {
+ NativeMethods.cairo_set_line_width (handle, value);
+ }
+
+ get {
+ return NativeMethods.cairo_get_line_width (handle);
+ }
+ }
+
+ public Cairo.LineCap LineCap {
+ set {
+ NativeMethods.cairo_set_line_cap (handle, value);
+ }
+
+ get {
+ return NativeMethods.cairo_get_line_cap (handle);
+ }
+ }
+
+ public Cairo.LineJoin LineJoin {
+ set {
+ NativeMethods.cairo_set_line_join (handle, value);
+ }
+
+ get {
+ return NativeMethods.cairo_get_line_join (handle);
+ }
+ }
+
+ public void SetDash (double [] dashes, double offset)
+ {
+ NativeMethods.cairo_set_dash (handle, dashes, dashes.Length, offset);
+ }
+
+ [Obsolete("Use GetSource/SetSource")]
+ public Pattern Pattern {
+ set {
+ SetSource (value);
+ }
+ get {
+ return GetSource ();
+ }
+ }
+
+ //This is obsolete because it wasn't obvious it needed to be disposed
+ [Obsolete("Use GetSource/SetSource")]
+ public Pattern Source {
+ set {
+ SetSource (value);
+ }
+ get {
+ return GetSource ();
+ }
+ }
+
+ public void SetSource (Pattern source)
+ {
+ NativeMethods.cairo_set_source (handle, source.Handle);
+ }
+
+ public Pattern GetSource ()
+ {
+ var ptr = NativeMethods.cairo_get_source (handle);
+ return Cairo.Pattern.Lookup (ptr, false);
+ }
+
+ public double MiterLimit {
+ set {
+ NativeMethods.cairo_set_miter_limit (handle, value);
+ }
+
+ get {
+ return NativeMethods.cairo_get_miter_limit (handle);
+ }
+ }
+
+ public PointD CurrentPoint {
+ get {
+ double x, y;
+ NativeMethods.cairo_get_current_point (handle, out x, out y);
+ return new PointD (x, y);
+ }
+ }
+
+ public bool HasCurrentPoint {
+ get {
+ return NativeMethods.cairo_has_current_point (handle);
+ }
+ }
+
+ [Obsolete ("Use GetTarget/SetTarget")]
+ public Cairo.Surface Target {
+ set {
+ if (handle != IntPtr.Zero)
+ NativeMethods.cairo_destroy (handle);
+
+ handle = NativeMethods.cairo_create (value.Handle);
+ }
+
+ get {
+ return GetTarget ();
+ }
+ }
+
+ public Surface GetTarget ()
+ {
+ return Surface.Lookup (NativeMethods.cairo_get_target (handle), false);
+ }
+
+ public void SetTarget (Surface target)
+ {
+ if (handle != IntPtr.Zero)
+ NativeMethods.cairo_destroy (handle);
+ handle = NativeMethods.cairo_create (target.Handle);
+ }
+
+ [Obsolete("Use GetScaledFont/SetScaledFont")]
+ public ScaledFont ScaledFont {
+ set {
+ SetScaledFont (value);
+ }
+
+ get {
+ return GetScaledFont ();
+ }
+ }
+
+ public ScaledFont GetScaledFont ()
+ {
+ return new ScaledFont (NativeMethods.cairo_get_scaled_font (handle), false);
+ }
+
+ public void SetScaledFont (ScaledFont font)
+ {
+ NativeMethods.cairo_set_scaled_font (handle, font.Handle);
+ }
+
+ public uint ReferenceCount {
+ get { return NativeMethods.cairo_get_reference_count (handle); }
+ }
+
+ public void SetSourceColor (Color color)
+ {
+ NativeMethods.cairo_set_source_rgba (handle, color.R, color.G, color.B, color.A);
+ }
+
public void SetSourceRGB (double r, double g, double b)
{
- Color = new Color (r, g, b);
+ NativeMethods.cairo_set_source_rgb (handle, r, g, b);
}
- [Obsolete ("Use Color property")]
public void SetSourceRGBA (double r, double g, double b, double a)
{
- Color = new Color (r, g, b, a);
+ NativeMethods.cairo_set_source_rgba (handle, r, g, b, a);
}
- [Obsolete ("Use SetSource method (with double parameters)")]
- public void SetSourceSurface (Surface source, int x, int y)
- {
- CairoAPI.cairo_set_source_surface (state, source.Handle, x, y);
- }
+ //[Obsolete ("Use SetSource method (with double parameters)")]
+ public void SetSourceSurface (Surface source, int x, int y)
+ {
+ NativeMethods.cairo_set_source_surface (handle, source.Handle, x, y);
+ }
- public void SetSource (Surface source, double x, double y)
- {
- CairoAPI.cairo_set_source_surface (state, source.Handle, x, y);
- }
+ public void SetSource (Surface source, double x, double y)
+ {
+ NativeMethods.cairo_set_source_surface (handle, source.Handle, x, y);
+ }
+
+ public void SetSource (Surface source)
+ {
+ NativeMethods.cairo_set_source_surface (handle, source.Handle, 0, 0);
+ }
#region Path methods
-
- public void NewPath ()
- {
- CairoAPI.cairo_new_path (state);
- }
-#if CAIRO_1_2
+ public void NewPath ()
+ {
+ NativeMethods.cairo_new_path (handle);
+ }
+
public void NewSubPath ()
{
- CairoAPI.cairo_new_sub_path (state);
+ NativeMethods.cairo_new_sub_path (handle);
}
-#endif
-
- public void MoveTo (PointD p)
- {
- MoveTo (p.X, p.Y);
- }
- public void MoveTo (double x, double y)
- {
- CairoAPI.cairo_move_to (state, x, y);
- }
-
- public void LineTo (PointD p)
- {
- LineTo (p.X, p.Y);
- }
+ public void MoveTo (PointD p)
+ {
+ MoveTo (p.X, p.Y);
+ }
- public void LineTo (double x, double y)
- {
- CairoAPI.cairo_line_to (state, x, y);
- }
+ public void MoveTo (double x, double y)
+ {
+ NativeMethods.cairo_move_to (handle, x, y);
+ }
- public void CurveTo (PointD p1, PointD p2, PointD p3)
- {
- CurveTo (p1.X, p1.Y, p2.X, p2.Y, p3.X, p3.Y);
- }
-
- public void CurveTo (double x1, double y1, double x2, double y2, double x3, double y3)
- {
- CairoAPI.cairo_curve_to (state, x1, y1, x2, y2, x3, y3);
- }
-
- public void RelMoveTo (Distance d)
- {
- RelMoveTo (d.Dx, d.Dy);
- }
-
- public void RelMoveTo (double dx, double dy)
- {
- CairoAPI.cairo_rel_move_to (state, dx, dy);
- }
-
- public void RelLineTo (Distance d)
- {
- RelLineTo (d.Dx, d.Dy);
- }
-
- public void RelLineTo (double dx, double dy)
- {
- CairoAPI.cairo_rel_line_to (state, dx, dy);
- }
+ public void LineTo (PointD p)
+ {
+ LineTo (p.X, p.Y);
+ }
+
+ public void LineTo (double x, double y)
+ {
+ NativeMethods.cairo_line_to (handle, x, y);
+ }
- public void RelCurveTo (Distance d1, Distance d2, Distance d3)
+ public void CurveTo (PointD p1, PointD p2, PointD p3)
+ {
+ CurveTo (p1.X, p1.Y, p2.X, p2.Y, p3.X, p3.Y);
+ }
+
+ public void CurveTo (double x1, double y1, double x2, double y2, double x3, double y3)
+ {
+ NativeMethods.cairo_curve_to (handle, x1, y1, x2, y2, x3, y3);
+ }
+
+ public void RelMoveTo (Distance d)
+ {
+ RelMoveTo (d.Dx, d.Dy);
+ }
+
+ public void RelMoveTo (double dx, double dy)
+ {
+ NativeMethods.cairo_rel_move_to (handle, dx, dy);
+ }
+
+ public void RelLineTo (Distance d)
+ {
+ RelLineTo (d.Dx, d.Dy);
+ }
+
+ public void RelLineTo (double dx, double dy)
+ {
+ NativeMethods.cairo_rel_line_to (handle, dx, dy);
+ }
+
+ public void RelCurveTo (Distance d1, Distance d2, Distance d3)
{
RelCurveTo (d1.Dx, d1.Dy, d2.Dx, d2.Dy, d3.Dx, d3.Dy);
}
- public void RelCurveTo (double dx1, double dy1, double dx2, double dy2, double dx3, double dy3)
- {
- CairoAPI.cairo_rel_curve_to (state, dx1, dy1, dx2, dy2, dx3, dy3);
- }
+ public void RelCurveTo (double dx1, double dy1, double dx2, double dy2, double dx3, double dy3)
+ {
+ NativeMethods.cairo_rel_curve_to (handle, dx1, dy1, dx2, dy2, dx3, dy3);
+ }
- public void Arc (double xc, double yc, double radius, double angle1, double angle2)
- {
- CairoAPI.cairo_arc (state, xc, yc, radius, angle1, angle2);
- }
+ public void Arc (double xc, double yc, double radius, double angle1, double angle2)
+ {
+ NativeMethods.cairo_arc (handle, xc, yc, radius, angle1, angle2);
+ }
- public void ArcNegative (double xc, double yc, double radius, double angle1, double angle2)
- {
- CairoAPI.cairo_arc_negative (state, xc, yc, radius, angle1, angle2);
- }
-
- public void Rectangle (Rectangle rectangle)
+ public void ArcNegative (double xc, double yc, double radius, double angle1, double angle2)
+ {
+ NativeMethods.cairo_arc_negative (handle, xc, yc, radius, angle1, angle2);
+ }
+
+ public void Rectangle (Rectangle rectangle)
{
Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
}
- public void Rectangle (PointD p, double width, double height)
+ public void Rectangle (PointD p, double width, double height)
{
Rectangle (p.X, p.Y, width, height);
}
- public void Rectangle (double x, double y, double width, double height)
- {
- CairoAPI.cairo_rectangle (state, x, y, width, height);
- }
-
- public void ClosePath ()
- {
- CairoAPI.cairo_close_path (state);
- }
+ public void Rectangle (double x, double y, double width, double height)
+ {
+ NativeMethods.cairo_rectangle (handle, x, y, width, height);
+ }
+
+ public void ClosePath ()
+ {
+ NativeMethods.cairo_close_path (handle);
+ }
+
+ public Path CopyPath ()
+ {
+ return new Path (NativeMethods.cairo_copy_path (handle));
+ }
+
+ public Path CopyPathFlat ()
+ {
+ return new Path (NativeMethods.cairo_copy_path_flat (handle));
+ }
+
+ public void AppendPath (Path path)
+ {
+ NativeMethods.cairo_append_path (handle, path.Handle);
+ }
+
#endregion
#region Painting Methods
- public void Paint ()
- {
- CairoAPI.cairo_paint (state);
- }
+ public void Paint ()
+ {
+ NativeMethods.cairo_paint (handle);
+ }
- public void PaintWithAlpha (double alpha)
- {
- CairoAPI.cairo_paint_with_alpha (state, alpha);
- }
+ public void PaintWithAlpha (double alpha)
+ {
+ NativeMethods.cairo_paint_with_alpha (handle, alpha);
+ }
- public void Mask (Pattern pattern)
- {
- CairoAPI.cairo_mask (state, pattern.Pointer);
- }
+ public void Mask (Pattern pattern)
+ {
+ NativeMethods.cairo_mask (handle, pattern.Handle);
+ }
- public void MaskSurface (Surface surface, double x, double y)
- {
- CairoAPI.cairo_mask_surface (state, surface.Handle, x, y);
- }
+ public void MaskSurface (Surface surface, double surface_x, double surface_y)
+ {
+ NativeMethods.cairo_mask_surface (handle, surface.Handle, surface_x, surface_y);
+ }
- public void Stroke ()
- {
- CairoAPI.cairo_stroke (state);
- }
-
- public void StrokePreserve ()
- {
- CairoAPI.cairo_stroke_preserve (state);
- }
+ public void Stroke ()
+ {
+ NativeMethods.cairo_stroke (handle);
+ }
+
+ public void StrokePreserve ()
+ {
+ NativeMethods.cairo_stroke_preserve (handle);
+ }
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);
+ NativeMethods.cairo_stroke_extents (handle, out x1, out y1, out x2, out y2);
+ return new Rectangle (x1, y1, x2 - x1, y2 - y1);
}
- public void Fill ()
- {
- CairoAPI.cairo_fill (state);
- }
+ public void Fill ()
+ {
+ NativeMethods.cairo_fill (handle);
+ }
- public Rectangle FillExtents ()
+ 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);
+ NativeMethods.cairo_fill_extents (handle, out x1, out y1, out x2, out y2);
+ return new Rectangle (x1, y1, x2 - x1, y2 - y1);
}
public void FillPreserve ()
{
- CairoAPI.cairo_fill_preserve (state);
+ NativeMethods.cairo_fill_preserve (handle);
}
#endregion
- public void Clip ()
- {
- CairoAPI.cairo_clip (state);
- }
+ public void Clip ()
+ {
+ NativeMethods.cairo_clip (handle);
+ }
- public void ClipPreserve ()
- {
- CairoAPI.cairo_clip_preserve (state);
- }
+ public void ClipPreserve ()
+ {
+ NativeMethods.cairo_clip_preserve (handle);
+ }
public void ResetClip ()
{
- CairoAPI.cairo_reset_clip (state);
+ NativeMethods.cairo_reset_clip (handle);
+ }
+
+ public bool InClip (double x, double y)
+ {
+ return NativeMethods.cairo_in_clip (handle, x, y);
}
-
+
public bool InStroke (double x, double y)
{
- return CairoAPI.cairo_in_stroke (state, x, y);
+ return NativeMethods.cairo_in_stroke (handle, x, y);
}
public bool InFill (double x, double y)
{
- return CairoAPI.cairo_in_fill (state, x, y);
+ return NativeMethods.cairo_in_fill (handle, x, y);
}
-#if CAIRO_1_2
public Pattern PopGroup ()
{
- IntPtr pattern = CairoAPI.cairo_pop_group (state);
- PatternType pt = CairoAPI.cairo_pattern_get_type (pattern);
- switch (pt) {
- case PatternType.Solid:
- return new SolidPattern (pattern);
- case PatternType.Surface:
- return new SurfacePattern (pattern);
- case PatternType.Linear:
- return new LinearGradient (pattern);
- case PatternType.Radial:
- return new RadialGradient (pattern);
- default:
- return new Pattern (pattern);
- }
+ return Pattern.Lookup (NativeMethods.cairo_pop_group (handle), true);
}
public void PopGroupToSource ()
{
- CairoAPI.cairo_pop_group_to_source (state);
+ NativeMethods.cairo_pop_group_to_source (handle);
}
public void PushGroup ()
{
- CairoAPI.cairo_push_group (state);
+ NativeMethods.cairo_push_group (handle);
}
public void PushGroup (Content content)
{
- CairoAPI.cairo_push_group_with_content (state, content);
+ NativeMethods.cairo_push_group_with_content (handle, content);
}
+ [Obsolete ("Use GetGroupTarget()")]
public Surface GroupTarget {
get {
- IntPtr surface = CairoAPI.cairo_get_group_target (state);
- return Surface.LookupSurface (surface);
+ return GetGroupTarget ();
}
}
-#endif
- public void Rotate (double angle)
- {
- CairoAPI.cairo_rotate (state, angle);
- }
+ public Surface GetGroupTarget ()
+ {
+ IntPtr surface = NativeMethods.cairo_get_group_target (handle);
+ return Surface.Lookup (surface, false);
+ }
+
+ public void Rotate (double angle)
+ {
+ NativeMethods.cairo_rotate (handle, angle);
+ }
+
+ public void Scale (double sx, double sy)
+ {
+ NativeMethods.cairo_scale (handle, sx, sy);
+ }
- public void Scale (double sx, double sy)
- {
- CairoAPI.cairo_scale (state, sx, sy);
- }
+ public void Translate (double tx, double ty)
+ {
+ NativeMethods.cairo_translate (handle, tx, ty);
+ }
- public void Translate (double tx, double ty)
- {
- CairoAPI.cairo_translate (state, tx, ty);
- }
-
public void Transform (Matrix m)
{
- CairoAPI.cairo_transform (state, m);
+ NativeMethods.cairo_transform (handle, m);
}
-
- //FIXME: obsolete these methods
+ [Obsolete("Use UserToDevice instead")]
public void TransformPoint (ref double x, ref double y)
{
- CairoAPI.cairo_user_to_device (state, ref x, ref y);
+ NativeMethods.cairo_user_to_device (handle, ref x, ref y);
}
-
- public void TransformDistance (ref double dx, ref double dy)
+
+ [Obsolete("Use UserToDeviceDistance instead")]
+ public void TransformDistance (ref double dx, ref double dy)
{
- CairoAPI.cairo_user_to_device_distance (state, ref dx, ref dy);
+ NativeMethods.cairo_user_to_device_distance (handle, ref dx, ref dy);
}
-
+
+ [Obsolete("Use InverseTransformPoint instead")]
public void InverseTransformPoint (ref double x, ref double y)
{
- CairoAPI.cairo_device_to_user (state, ref x, ref y);
+ NativeMethods.cairo_device_to_user (handle, ref x, ref y);
}
+ [Obsolete("Use DeviceToUserDistance instead")]
public void InverseTransformDistance (ref double dx, ref double dy)
{
- CairoAPI.cairo_device_to_user_distance (state, ref dx, ref dy);
+ NativeMethods.cairo_device_to_user_distance (handle, ref dx, ref dy);
+ }
+
+ public void UserToDevice (ref double x, ref double y)
+ {
+ NativeMethods.cairo_user_to_device (handle, ref x, ref y);
+ }
+
+ public void UserToDeviceDistance (ref double dx, ref double dy)
+ {
+ NativeMethods.cairo_user_to_device_distance (handle, ref dx, ref dy);
}
-
- public Cairo.Matrix Matrix {
- set {
- CairoAPI.cairo_set_matrix (state, value);
- }
- get {
+ public void DeviceToUser (ref double x, ref double y)
+ {
+ NativeMethods.cairo_device_to_user (handle, ref x, ref y);
+ }
+
+ public void DeviceToUserDistance (ref double dx, ref double dy)
+ {
+ NativeMethods.cairo_device_to_user_distance (handle, ref dx, ref dy);
+ }
+
+ public Matrix Matrix {
+ set {
+ NativeMethods.cairo_set_matrix (handle, value);
+ }
+
+ get {
Matrix m = new Matrix();
- CairoAPI.cairo_get_matrix (state, m);
- return m;
- }
- }
+ NativeMethods.cairo_get_matrix (handle, m);
+ return m;
+ }
+ }
public void SetFontSize (double scale)
{
- CairoAPI.cairo_set_font_size (state, scale);
+ NativeMethods.cairo_set_font_size (handle, scale);
+ }
+
+ public void IdentityMatrix ()
+ {
+ NativeMethods.cairo_identity_matrix (handle);
}
[Obsolete ("Use SetFontSize() instead.")]
public double FontSize {
set { SetFontSize (value); }
}
-
+
public Matrix FontMatrix {
- get { return CairoAPI.cairo_get_font_matrix (state); }
- set { CairoAPI.cairo_set_font_matrix (state, value); }
+ get {
+ Matrix m;
+ NativeMethods.cairo_get_font_matrix (handle, out m);
+ return m;
+ }
+ set { NativeMethods.cairo_set_font_matrix (handle, value); }
}
public FontOptions FontOptions {
get {
FontOptions options = new FontOptions ();
- CairoAPI.cairo_get_font_options (state, options.Handle);
+ NativeMethods.cairo_get_font_options (handle, options.Handle);
return options;
}
- set { CairoAPI.cairo_set_font_options (state, value.Handle); }
+ set { NativeMethods.cairo_set_font_options (handle, value.Handle); }
}
[StructLayout(LayoutKind.Sequential)]
static internal IntPtr FromGlyphToUnManagedMemory(Glyph [] glyphs)
{
IntPtr dest = Marshal.AllocHGlobal (native_glyph_size * glyphs.Length);
- int pos = dest.ToInt32();
+ long pos = dest.ToInt64();
if (c_compiler_long_size == 8){
foreach (Glyph g in glyphs){
} else {
foreach (Glyph g in glyphs){
NativeGlyph_4byte_longs n = new NativeGlyph_4byte_longs (g);
-
+
Marshal.StructureToPtr (n, (IntPtr)pos, false);
pos += native_glyph_size;
}
return dest;
}
- public void ShowGlyphs (Glyph[] glyphs)
+ public void ShowGlyphs (Glyph[] glyphs)
{
- IntPtr ptr;
+ IntPtr ptr;
+
+ ptr = FromGlyphToUnManagedMemory (glyphs);
- ptr = FromGlyphToUnManagedMemory (glyphs);
-
- CairoAPI.cairo_show_glyphs (state, ptr, glyphs.Length);
+ NativeMethods.cairo_show_glyphs (handle, ptr, glyphs.Length);
- Marshal.FreeHGlobal (ptr);
+ Marshal.FreeHGlobal (ptr);
}
[Obsolete("The matrix argument was never used, use ShowGlyphs(Glyphs []) instead")]
- public void ShowGlyphs (Matrix matrix, Glyph[] glyphs)
- {
+ public void ShowGlyphs (Matrix matrix, Glyph[] glyphs)
+ {
ShowGlyphs (glyphs);
- }
+ }
[Obsolete("The matrix argument was never used, use GlyphPath(Glyphs []) instead")]
- public void GlyphPath (Matrix matrix, Glyph[] glyphs)
- {
+ public void GlyphPath (Matrix matrix, Glyph[] glyphs)
+ {
GlyphPath (glyphs);
}
public void GlyphPath (Glyph[] glyphs)
{
- IntPtr ptr;
+ IntPtr ptr;
- ptr = FromGlyphToUnManagedMemory (glyphs);
+ ptr = FromGlyphToUnManagedMemory (glyphs);
- CairoAPI.cairo_glyph_path (state, ptr, glyphs.Length);
+ NativeMethods.cairo_glyph_path (handle, ptr, glyphs.Length);
- Marshal.FreeHGlobal (ptr);
+ Marshal.FreeHGlobal (ptr);
- }
+ }
+
+ public FontExtents FontExtents {
+ get {
+ FontExtents f_extents;
+ NativeMethods.cairo_font_extents (handle, out f_extents);
+ return f_extents;
+ }
+ }
- public FontExtents FontExtents {
- get {
-
- FontExtents f_extents = new FontExtents();
- CairoAPI.cairo_font_extents (state, ref f_extents);
- return f_extents;
- }
- }
-
public void CopyPage ()
{
- CairoAPI.cairo_copy_page (state);
+ NativeMethods.cairo_copy_page (handle);
}
[Obsolete ("Use SelectFontFace() instead.")]
{
SelectFontFace (family, slant, weight);
}
-
+
+ [Obsolete("Use GetFontFace/SetFontFace")]
+ public FontFace ContextFontFace {
+ get {
+ return GetContextFontFace ();
+ }
+ set {
+ SetContextFontFace (value);
+ }
+ }
+
+ public FontFace GetContextFontFace ()
+ {
+ return Cairo.FontFace.Lookup (NativeMethods.cairo_get_font_face (handle), false);
+ }
+
+ public void SetContextFontFace (FontFace value)
+ {
+ NativeMethods.cairo_set_font_face (handle, value == null ? IntPtr.Zero : value.Handle);
+ }
+
public void SelectFontFace (string family, FontSlant slant, FontWeight weight)
{
- CairoAPI.cairo_select_font_face (state, family, slant, weight);
+ NativeMethods.cairo_select_font_face (handle, family, slant, weight);
}
public void ShowPage ()
{
- CairoAPI.cairo_show_page (state);
+ NativeMethods.cairo_show_page (handle);
+ }
+
+ private static byte[] TerminateUtf8(byte[] utf8)
+ {
+ if (utf8.Length > 0 && utf8[utf8.Length - 1] == 0)
+ return utf8;
+ var termedArray = new byte[utf8.Length + 1];
+ Array.Copy(utf8, termedArray, utf8.Length);
+ termedArray[utf8.Length] = 0;
+ return termedArray;
}
-
- public void ShowText (string str)
- {
- CairoAPI.cairo_show_text (state, str);
- }
-
- public void TextPath (string str)
- {
- CairoAPI.cairo_text_path (state, str);
- }
- public TextExtents TextExtents (string utf8)
+ private static byte[] TerminateUtf8(string s)
+ {
+ // compute the byte count including the trailing \0
+ var byteCount = Encoding.UTF8.GetMaxByteCount(s.Length + 1);
+ var bytes = new byte[byteCount];
+ Encoding.UTF8.GetBytes(s, 0, s.Length, bytes, 0);
+ return bytes;
+ }
+
+ public void ShowText(string str)
+ {
+ NativeMethods.cairo_show_text (handle, TerminateUtf8(str));
+ }
+
+ public void ShowText(byte[] utf8)
+ {
+ NativeMethods.cairo_show_text (handle, TerminateUtf8(utf8));
+ }
+
+ public void TextPath(string str)
+ {
+ NativeMethods.cairo_text_path (handle, TerminateUtf8(str));
+ }
+
+ public void TextPath(byte[] utf8)
+ {
+ NativeMethods.cairo_text_path (handle, TerminateUtf8(utf8));
+ }
+
+ public TextExtents TextExtents(string s)
+ {
+ TextExtents extents;
+ NativeMethods.cairo_text_extents (handle, TerminateUtf8(s), out extents);
+ return extents;
+ }
+
+ public TextExtents TextExtents(byte[] utf8)
{
TextExtents extents;
- CairoAPI.cairo_text_extents (state, utf8, out extents);
+ NativeMethods.cairo_text_extents (handle, TerminateUtf8(utf8), out extents);
return extents;
}
TextExtents extents;
- CairoAPI.cairo_glyph_extents (state, ptr, glyphs.Length, out extents);
+ NativeMethods.cairo_glyph_extents (handle, ptr, glyphs.Length, out extents);
Marshal.FreeHGlobal (ptr);
return extents;
}
- }
+ }
}