Merge pull request #4723 from lambdageek/bug-54485
[mono.git] / mcs / class / Mono.Cairo / Mono.Cairo / ScaledFont.cs
index 8ac48f38476c3fc47f1fceb8a707a4f8125b8318..937194607af414e35fbb5ee6a0b80b02a7949c07 100644 (file)
@@ -32,14 +32,18 @@ namespace Cairo {
        {
                protected IntPtr handle = IntPtr.Zero;
 
-               internal ScaledFont (IntPtr handle)
+               internal ScaledFont (IntPtr handle, bool owner)
                {
                        this.handle = handle;
+                       if (!owner)
+                               NativeMethods.cairo_scaled_font_reference (handle);
+                       if (CairoDebug.Enabled)
+                               CairoDebug.OnAllocated (handle);
                }
 
                public ScaledFont (FontFace fontFace, Matrix matrix, Matrix ctm, FontOptions options)
+                       : this (NativeMethods.cairo_scaled_font_create (fontFace.Handle, matrix, ctm, options.Handle), true)
                {
-                       handle = NativeMethods.cairo_scaled_font_create (fontFace.Handle, matrix, ctm, options.Handle);
                }
 
                ~ScaledFont ()
@@ -47,19 +51,19 @@ namespace Cairo {
                        Dispose (false);
                }
 
-                public IntPtr Handle {
-                        get {
-                                return handle;
-                        }
-                }
+               public IntPtr Handle {
+                       get {
+                               return handle;
+                       }
+               }
 
                public FontExtents FontExtents {
-                        get {
-                                FontExtents extents;
-                                NativeMethods.cairo_scaled_font_extents (handle, out extents);
-                                return extents;
-                        }
-                }
+                       get {
+                               FontExtents extents;
+                               NativeMethods.cairo_scaled_font_extents (handle, out extents);
+                               return extents;
+                       }
+               }
 
                public Matrix FontMatrix {
                        get {
@@ -91,7 +95,7 @@ namespace Cairo {
                        get { return NativeMethods.cairo_scaled_font_status (handle); }
                }
 
-               void IDisposable.Dispose ()
+               public void Dispose ()
                {
                        Dispose (true);
                        GC.SuppressFinalize (this);
@@ -99,16 +103,21 @@ namespace Cairo {
 
                protected virtual void Dispose (bool disposing)
                {
-                       if (disposing) {
-                               NativeMethods.cairo_scaled_font_destroy (handle);
-                               handle = IntPtr.Zero;
-                       }
+                       if (!disposing || CairoDebug.Enabled)
+                               CairoDebug.OnDisposed<ScaledFont> (handle, disposing);
+
+                       if (!disposing|| handle == IntPtr.Zero)
+                               return;
+
+                       NativeMethods.cairo_scaled_font_destroy (handle);
+                       handle = IntPtr.Zero;
+               }
+
+               [Obsolete]
+               protected void Reference ()
+               {
+                       NativeMethods.cairo_scaled_font_reference (handle);
                }
-               
-                protected void Reference ()
-                {
-                        NativeMethods.cairo_scaled_font_reference (handle);
-                }
        }
 }