[poppler] [PATCH] makes PopplerPSFile GObject

Kouhei Sutou kou at cozmixng.org
Fri May 12 07:30:17 PDT 2006


Hi,

I'm writing Ruby bindings to poppler-glib.

I want PopplerPSFile to provide GType for writing the
bindings.

Thanks,
--
kou
-------------- next part --------------
? poppler-features.h
Index: poppler-document.cc
===================================================================
RCS file: /cvs/poppler/poppler/glib/poppler-document.cc,v
retrieving revision 1.34
diff -u -p -r1.34 poppler-document.cc
--- poppler-document.cc	16 Apr 2006 22:59:44 -0000	1.34
+++ poppler-document.cc	12 May 2006 14:30:01 -0000
@@ -1210,6 +1210,45 @@ poppler_font_info_free (PopplerFontInfo 
 	g_free (font_info);
 }
 
+
+typedef struct _PopplerPSFileClass PopplerPSFileClass;
+struct _PopplerPSFileClass
+{
+        GObjectClass parent_class;
+};
+
+G_DEFINE_TYPE (PopplerPSFile, poppler_ps_file, G_TYPE_OBJECT);
+
+static void poppler_ps_file_finalize (GObject *object);
+
+
+static void
+poppler_ps_file_class_init (PopplerPSFileClass *klass)
+{
+        GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+        gobject_class->finalize = poppler_ps_file_finalize;
+}
+
+static void
+poppler_ps_file_init (PopplerPSFile *ps_file)
+{
+        ps_file->out = NULL;
+        ps_file->paper_width = -1;
+        ps_file->paper_height = -1;
+        ps_file->duplex = FALSE;
+}
+
+static void
+poppler_ps_file_finalize (GObject *object)
+{
+        PopplerPSFile *ps_file = POPPLER_PS_FILE (object);
+
+        delete ps_file->out;
+        g_object_unref (ps_file->document);
+        g_free (ps_file->filename);
+}
+
 /**
  * poppler_ps_file_new:
  * @document: a #PopplerDocument
@@ -1231,12 +1270,12 @@ poppler_ps_file_new (PopplerDocument *do
 	g_return_val_if_fail (filename != NULL, NULL);
 	g_return_val_if_fail (n_pages > 0, NULL);
 
-	ps_file = g_new0 (PopplerPSFile, 1);
+        ps_file = (PopplerPSFile *) g_object_new (POPPLER_TYPE_PS_FILE, NULL);
 	ps_file->document = (PopplerDocument *) g_object_ref (document);
         ps_file->filename = g_strdup (filename);
         ps_file->first_page = first_page + 1;
         ps_file->last_page = first_page + 1 + n_pages - 1;
-        
+
 	return ps_file;
 }
 
@@ -1288,11 +1327,5 @@ void
 poppler_ps_file_free (PopplerPSFile *ps_file)
 {
 	g_return_if_fail (ps_file != NULL);
-
-	delete ps_file->out;
-	g_object_unref (ps_file->document);
-        g_free (ps_file->filename);
-	g_free (ps_file);
+        g_object_unref (ps_file);
 }
-
-
Index: poppler-document.h
===================================================================
RCS file: /cvs/poppler/poppler/glib/poppler-document.h,v
retrieving revision 1.19
diff -u -p -r1.19 poppler-document.h
--- poppler-document.h	16 Apr 2006 22:59:44 -0000	1.19
+++ poppler-document.h	12 May 2006 14:30:01 -0000
@@ -137,6 +137,10 @@ gboolean	  poppler_fonts_iter_is_subset 
 gboolean          poppler_fonts_iter_next          (PopplerFontsIter  *iter);
 
 /* Export to ps */
+#define POPPLER_TYPE_PS_FILE             (poppler_ps_file_get_type ())
+#define POPPLER_PS_FILE(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), POPPLER_TYPE_PS_FILE, PopplerPSFile))
+#define POPPLER_IS_PS_FILE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), POPPLER_TYPE_PS_FILE))
+GType          poppler_ps_file_get_type       (void) G_GNUC_CONST;
 PopplerPSFile *poppler_ps_file_new            (PopplerDocument *document,
                                                const char      *filename,
                                                int              first_page,
Index: poppler-private.h
===================================================================
RCS file: /cvs/poppler/poppler/glib/poppler-private.h,v
retrieving revision 1.15
diff -u -p -r1.15 poppler-private.h
--- poppler-private.h	16 Apr 2006 22:59:44 -0000	1.15
+++ poppler-private.h	12 May 2006 14:30:01 -0000
@@ -32,6 +32,8 @@ struct _PopplerDocument
 
 struct _PopplerPSFile
 {
+  GObject parent_instance;
+
   PopplerDocument *document;
   PSOutputDev *out;
   char *filename;


More information about the poppler mailing list