From a26d9214724a12fab776d11d9d3f6a071eaa5993 Mon Sep 17 00:00:00 2001 From: Hugo Parente Lima Date: Sun, 24 Jul 2022 21:04:51 -0300 Subject: [PATCH] Make possible to use Pango::AttrList and Pango::Attributes. --- src/bindings/pango/attribute.cr | 20 ++++++++++++++++++++ src/bindings/pango/binding.yml | 12 ++++++++++++ src/bindings/pango/font_metrics.cr | 3 +++ 3 files changed, 35 insertions(+) create mode 100644 src/bindings/pango/attribute.cr diff --git a/src/bindings/pango/attribute.cr b/src/bindings/pango/attribute.cr new file mode 100644 index 000000000..64e4f2e81 --- /dev/null +++ b/src/bindings/pango/attribute.cr @@ -0,0 +1,20 @@ +module Pango + class Attribute + def initialize(pointer : Pointer(Void), transfer : GICrystal::Transfer) + raise ArgumentError.new("Tried to generate struct with a NULL pointer") if pointer.null? + + @pointer = if transfer.none? + LibPango.pango_attribute_copy(pointer) + else + pointer + end + end + + def finalize + {% if flag?(:debugmemory) %} + LibC.printf("~%s at %p\n", self.class.name.to_unsafe, self) + {% end %} + LibPango.pango_attribute_destroy(to_unsafe) + end + end +end diff --git a/src/bindings/pango/binding.yml b/src/bindings/pango/binding.yml index b375e90ad..d5d513c9e 100644 --- a/src/bindings/pango/binding.yml +++ b/src/bindings/pango/binding.yml @@ -1,10 +1,22 @@ namespace: Pango version: "1.0" require_after: +- attribute.cr - font_metrics.cr - layout.cr types: + Attribute: + binding_strategy: heap_wrapper_struct + ignore_fields: + - klass + ignore_methods: + - init + - destroy + AttrList: + ignore_methods: + - ref + - unref FontMetrics: binding_strategy: heap_wrapper_struct ignore_methods: diff --git a/src/bindings/pango/font_metrics.cr b/src/bindings/pango/font_metrics.cr index 29e8843e2..fcbbc2f5d 100644 --- a/src/bindings/pango/font_metrics.cr +++ b/src/bindings/pango/font_metrics.cr @@ -8,6 +8,9 @@ module Pango end def finalize + {% if flag?(:debugmemory) %} + LibC.printf("~%s at %p - ref count: %d\n", self.class.name.to_unsafe, self, ref_count) + {% end %} LibPango.pango_font_metrics_unref(to_unsafe) end end