ext/cairo/rb_cairo_surface.c in cairo-1.17.5 vs ext/cairo/rb_cairo_surface.c in cairo-1.17.6
- old
+ new
@@ -1,10 +1,10 @@
/* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
- * Copyright 2005-2019 Kouhei Sutou <kou@cozmixng.org>
+ * Copyright 2005-2022 Sutou Kouhei <kou@cozmixng.org>
* Copyright 2014 Patrick Hanevold <patrick.hanevold@gmail.com>
* Copyright 2005 Øyvind Kolås <pippin@freedesktop.org>
* Copyright 2004-2005 MenTaLguY <mental@rydia.com>
*
* This file is made available under the same terms as Ruby
@@ -230,10 +230,32 @@
rb_gc_adjust_memory_usage (memory_usage_diff);
}
#endif
}
+static cairo_surface_t *
+rb_cairo_surface_from_ruby_object_without_null_check (VALUE obj)
+{
+ cairo_surface_t *surface;
+ if (!rb_cairo__is_kind_of (obj, rb_cCairo_Surface))
+ {
+ rb_raise (rb_eTypeError, "not a cairo surface");
+ }
+ Data_Get_Struct (obj, cairo_surface_t, surface);
+ return surface;
+}
+
+cairo_surface_t *
+rb_cairo_surface_from_ruby_object (VALUE obj)
+{
+ cairo_surface_t *surface =
+ rb_cairo_surface_from_ruby_object_without_null_check (obj);
+ if (!surface)
+ rb_cairo_check_status (CAIRO_STATUS_NULL_POINTER);
+ return surface;
+}
+
static void
cr_surface_destroy_raw (cairo_surface_t *surface)
{
rb_cairo_surface_adjust_memory_usage (surface, CR_FALSE);
cairo_surface_destroy (surface);
@@ -252,11 +274,11 @@
}
static VALUE
cr_surface_destroy_with_destroy_check (VALUE self)
{
- if (_SELF)
+ if (rb_cairo_surface_from_ruby_object_without_null_check (self))
cr_surface_destroy (self);
return Qnil;
}
static VALUE
@@ -405,25 +427,10 @@
#else
return Qfalse;
#endif
}
-/* constructor/de-constructor */
-cairo_surface_t *
-rb_cairo_surface_from_ruby_object (VALUE obj)
-{
- cairo_surface_t *surface;
- if (!rb_cairo__is_kind_of (obj, rb_cCairo_Surface))
- {
- rb_raise (rb_eTypeError, "not a cairo surface");
- }
- Data_Get_Struct (obj, cairo_surface_t, surface);
- if (!surface)
- rb_cairo_check_status (CAIRO_STATUS_NULL_POINTER);
- return surface;
-}
-
static rb_cairo__object_holder_t *
cr_object_holder_new (VALUE object)
{
return rb_cairo__object_holder_new (rb_cCairo_Surface, object);
}
@@ -513,10 +520,11 @@
closure = cairo_surface_get_user_data (surface, &cr_closure_key);
cairo_surface_finish (surface);
cairo_surface_set_user_data (surface, &cr_finished_key, (void *)CR_TRUE, NULL);
cairo_surface_set_user_data (surface, &cr_object_holder_key, NULL, NULL);
+ DATA_PTR (self) = NULL;
if (closure && !NIL_P (closure->error))
rb_exc_raise (closure->error);
rb_cairo_surface_check_status (surface);
@@ -529,11 +537,11 @@
VALUE rb_result;
cairo_surface_t *surface;
rb_result = rb_yield (self);
- surface = _SELF;
+ surface = rb_cairo_surface_from_ruby_object_without_null_check (self);
if (!surface)
return rb_result;
if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS)
return rb_result;
if (cairo_surface_get_user_data (surface, &cr_finished_key))
@@ -1326,10 +1334,30 @@
rb_cairo_surface_check_status (surface);
return Qnil;
}
# endif
+
+# if CAIRO_CHECK_VERSION(1, 17, 6)
+static VALUE
+cr_pdf_surface_set_custom_metadata (VALUE self,
+ VALUE rb_name,
+ VALUE rb_value)
+{
+ cairo_surface_t *surface;
+ const char *name;
+ const char *value;
+
+ surface = _SELF;
+ name = RVAL2CSTR (rb_name);
+ value = RVAL2CSTR (rb_value);
+ cairo_pdf_surface_set_custom_metadata (surface, name, value);
+ rb_cairo_surface_check_status (surface);
+
+ return Qnil;
+}
+# endif
#endif
#ifdef CAIRO_HAS_PS_SURFACE
/* PS-surface functions */
DEFINE_SURFACE(ps)
@@ -2173,9 +2201,14 @@
rb_define_method (rb_cCairo_PDFSurface, "set_page_label",
cr_pdf_surface_set_page_label, 1);
rb_define_method (rb_cCairo_PDFSurface, "set_thumbnail_size",
cr_pdf_surface_set_thumbnail_size, 2);
}
+# endif
+
+# if CAIRO_CHECK_VERSION(1, 17, 6)
+ rb_define_method (rb_cCairo_PDFSurface, "set_custom_metadata",
+ cr_pdf_surface_set_custom_metadata, 2);
# endif
RB_CAIRO_DEF_SETTERS (rb_cCairo_PDFSurface);
#endif