[libgxps] tools: Add xpstopdf tool



commit 63449fb61972757fd2cb589f456a2eb7b26b4379
Author: Carlos Garcia Campos <carlosgc gnome org>
Date:   Sat Oct 29 19:42:24 2011 +0200

    tools: Add xpstopdf tool

 configure.ac               |    8 ++++
 tools/Makefile.am          |   24 ++++++++++++-
 tools/gxps-pdf-converter.c |   86 ++++++++++++++++++++++++++++++++++++++++++++
 tools/gxps-pdf-converter.h |   41 +++++++++++++++++++++
 4 files changed, 158 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 05c659c..ce222be 100644
--- a/configure.ac
+++ b/configure.ac
@@ -167,6 +167,14 @@ AM_CONDITIONAL(HAVE_LIBPNG, test x$have_libpng = xyes)
 AC_SUBST(LIBPNG_CFLAGS)
 AC_SUBST(LIBPNG_LIBS)
 
+dnl Cairo PDF
+PKG_CHECK_MODULES(CAIRO_PDF, cairo-pdf, [have_cairo_pdf="yes"], [have_cairo_pdf="no"])
+
+AM_CONDITIONAL(HAVE_CAIRO_PDF, test x$have_cairo_pdf = xyes)
+
+AC_SUBST(CAIRO_PDF_CFLAGS)
+AC_SUBST(CAIRO_PDF_LIBS)
+
 dnl gtk-doc
 GTK_DOC_CHECK([1.14],[--flavour no-tmpl])
 
diff --git a/tools/Makefile.am b/tools/Makefile.am
index fa4dab5..ffcab7a 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -55,4 +55,26 @@ xpstopng_CFLAGS = \
 xpstopng_LDADD = \
 	libgxpstools.la		\
 	$(LIBPNG_LIBS)
-endif # HAVE_LIBPNG
\ No newline at end of file
+endif # HAVE_LIBPNG
+
+if HAVE_CAIRO_PDF
+bin_PROGRAMS += xpstopdf
+
+xpstopdf_SOURCES = \
+	gxps-converter-main.c	\
+	gxps-pdf-converter.c	\
+	gxps-pdf-converter.h
+
+xpstopdf_CPPFLAGS = \
+	$(tools_cppflags)				\
+	-DCONVERTER_TYPE=GXPS_TYPE_PDF_CONVERTER	\
+	-DCONVERTER_HEADER=gxps-pdf-converter.h
+
+xpstopdf_CFLAGS = \
+	$(tools_cflags)		\
+	$(CAIRO_PDF_CFLAGS)
+
+xpstopdf_LDADD = \
+	libgxpstools.la		\
+	$(CAIRO_PDF_LIBS)
+endif # HAVE_CAIRO_PDF
\ No newline at end of file
diff --git a/tools/gxps-pdf-converter.c b/tools/gxps-pdf-converter.c
new file mode 100644
index 0000000..fb5798c
--- /dev/null
+++ b/tools/gxps-pdf-converter.c
@@ -0,0 +1,86 @@
+/* GXPSPdfConverter
+ *
+ * Copyright (C) 2011  Carlos Garcia Campos <carlosgc gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <config.h>
+
+#include "gxps-pdf-converter.h"
+#include <libgxps/gxps.h>
+#include <cairo-pdf.h>
+#include <string.h>
+
+struct _GXPSPdfConverter {
+	GXPSPrintConverter parent;
+};
+
+struct _GXPSPdfConverterClass {
+	GXPSPrintConverterClass parent_class;
+};
+
+G_DEFINE_TYPE (GXPSPdfConverter, gxps_pdf_converter, GXPS_TYPE_PRINT_CONVERTER)
+
+static const gchar *
+gxps_pdf_converter_get_extension (GXPSConverter *converter)
+{
+        return "pdf";
+}
+
+static void
+gxps_pdf_converter_begin_document (GXPSConverter *converter,
+                                   const gchar   *output_filename,
+                                   GXPSPage      *first_page)
+{
+        GXPSPrintConverter *print_converter = GXPS_PRINT_CONVERTER (converter);
+        gdouble             width, height;
+
+        GXPS_CONVERTER_CLASS (gxps_pdf_converter_parent_class)->begin_document (converter, output_filename, first_page);
+
+        _gxps_converter_print_get_output_size (print_converter, first_page, &width, &height);
+        converter->surface = cairo_pdf_surface_create (print_converter->filename, width, height);
+}
+
+static cairo_t *
+gxps_pdf_converter_begin_page (GXPSConverter *converter,
+                               GXPSPage      *page,
+                               guint          n_page)
+{
+        GXPSPrintConverter *print_converter = GXPS_PRINT_CONVERTER (converter);
+        gdouble             width, height;
+
+        g_return_val_if_fail (converter->surface != NULL, NULL);
+
+        _gxps_converter_print_get_output_size (print_converter, page, &width, &height);
+        cairo_pdf_surface_set_size (converter->surface, width, height);
+
+        return GXPS_CONVERTER_CLASS (gxps_pdf_converter_parent_class)->begin_page (converter, page, n_page);
+}
+
+static void
+gxps_pdf_converter_init (GXPSPdfConverter *converter)
+{
+}
+
+static void
+gxps_pdf_converter_class_init (GXPSPdfConverterClass *klass)
+{
+        GXPSConverterClass *converter_class = GXPS_CONVERTER_CLASS (klass);
+
+        converter_class->get_extension = gxps_pdf_converter_get_extension;
+        converter_class->begin_document = gxps_pdf_converter_begin_document;
+        converter_class->begin_page = gxps_pdf_converter_begin_page;
+}
diff --git a/tools/gxps-pdf-converter.h b/tools/gxps-pdf-converter.h
new file mode 100644
index 0000000..9d26198
--- /dev/null
+++ b/tools/gxps-pdf-converter.h
@@ -0,0 +1,41 @@
+/* GXPSPdfConverter
+ *
+ * Copyright (C) 2011  Carlos Garcia Campos <carlosgc gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef __GXPS_PDF_CONVERTER_H__
+#define __GXPS_PDF_CONVERTER_H__
+
+#include "gxps-print-converter.h"
+
+G_BEGIN_DECLS
+
+#define GXPS_TYPE_PDF_CONVERTER           (gxps_pdf_converter_get_type ())
+#define GXPS_PDF_CONVERTER(obj)           (G_TYPE_CHECK_INSTANCE_CAST (obj, GXPS_TYPE_PDF_CONVERTER, GXPSPdfConverter))
+#define GXPS_PDF_CONVERTER_CLASS(cls)     (G_TYPE_CHECK_CLASS_CAST (cls, GXPS_TYPE_PDF_CONVERTER, GXPSPdfConverterClass))
+#define GXPS_IS_PDF_CONVERTER(obj)        (G_TYPE_CHECK_INSTANCE_TYPE (obj, GXPS_TYPE_PDF_CONVERTER))
+#define GXPS_IS_PDF_CONVERTER_CLASS(obj)  (G_TYPE_CHECK_CLASS_TYPE (obj, GXPS_TYPE_PDF_CONVERTER))
+#define GXPS_PDF_CONVERTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GXPS_TYPE_PDF_CONVERTER, GXPSPdfConverterClass))
+
+typedef struct _GXPSPdfConverter        GXPSPdfConverter;
+typedef struct _GXPSPdfConverterClass   GXPSPdfConverterClass;
+
+GType gxps_pdf_converter_get_type (void);
+
+G_END_DECLS
+
+#endif /* __GXPS_PDF_CONVERTER_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]