[libgxps] Move GXPSMatrix code to a new file



commit 17dbda82fff2232223ff34a9a61942333366136b
Author: Carlos Garcia Campos <carlosgc gnome org>
Date:   Mon Nov 14 17:47:38 2011 +0100

    Move GXPSMatrix code to a new file

 libgxps/Makefile.am         |    3 +
 libgxps/gxps-matrix.c       |  129 ++++++++++++++++++++++++++++++++++++++++
 libgxps/gxps-matrix.h       |   44 ++++++++++++++
 libgxps/gxps-page-private.h |   62 +++++++++++++++++++
 libgxps/gxps-page.c         |  137 ++----------------------------------------
 5 files changed, 245 insertions(+), 130 deletions(-)
---
diff --git a/libgxps/Makefile.am b/libgxps/Makefile.am
index d81780f..872c678 100644
--- a/libgxps/Makefile.am
+++ b/libgxps/Makefile.am
@@ -6,6 +6,8 @@ NOINST_H_FILES = \
 	gxps-debug.h		\
 	gxps-fonts.h		\
 	gxps-images.h		\
+	gxps-matrix.h		\
+	gxps-page-private.h	\
 	gxps-parse-utils.h	\
 	gxps-private.h
 
@@ -32,6 +34,7 @@ libgxps_la_SOURCES = \
 	gxps-file.c			\
 	gxps-fonts.c			\
 	gxps-links.c			\
+	gxps-matrix.c			\
 	gxps-images.c			\
 	gxps-page.c			\
 	gxps-parse-utils.c		\
diff --git a/libgxps/gxps-matrix.c b/libgxps/gxps-matrix.c
new file mode 100644
index 0000000..ac0c5a1
--- /dev/null
+++ b/libgxps/gxps-matrix.c
@@ -0,0 +1,129 @@
+/* GXPSMatrix
+ *
+ * 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 <string.h>
+
+#include "gxps-matrix.h"
+#include "gxps-parse-utils.h"
+
+GXPSMatrix *
+gxps_matrix_new (GXPSRenderContext *ctx)
+{
+        GXPSMatrix *matrix;
+
+        matrix = g_slice_new0 (GXPSMatrix);
+        matrix->ctx = ctx;
+        cairo_matrix_init_identity (&matrix->matrix);
+
+        return matrix;
+}
+
+void
+gxps_matrix_free (GXPSMatrix *matrix)
+{
+        if (G_UNLIKELY (!matrix))
+                return;
+
+        g_slice_free (GXPSMatrix, matrix);
+}
+
+gboolean
+gxps_matrix_parse (const gchar    *data,
+                   cairo_matrix_t *matrix)
+{
+        gchar **items;
+        gdouble mm[6];
+        guint   i;
+
+        items = g_strsplit (data, ",", 6);
+        if (g_strv_length (items) != 6) {
+                g_strfreev (items);
+
+                return FALSE;
+        }
+
+        for (i = 0; i < 6; i++) {
+                if (!gxps_value_get_double (items[i], &mm[i])) {
+                        g_strfreev (items);
+                        return FALSE;
+                }
+        }
+
+        g_strfreev (items);
+
+        cairo_matrix_init (matrix, mm[0], mm[1], mm[2], mm[3], mm[4], mm[5]);
+
+        return TRUE;
+}
+
+static void
+matrix_start_element (GMarkupParseContext  *context,
+                      const gchar          *element_name,
+                      const gchar         **names,
+                      const gchar         **values,
+                      gpointer              user_data,
+                      GError              **error)
+{
+        GXPSMatrix *matrix = (GXPSMatrix *)user_data;
+
+        if (strcmp (element_name, "MatrixTransform") == 0) {
+                gint i;
+
+                for (i = 0; names[i] != NULL; i++) {
+                        if (strcmp (names[i], "Matrix") == 0) {
+                                if (!gxps_matrix_parse (values[i], &matrix->matrix)) {
+                                        gxps_parse_error (context,
+                                                          matrix->ctx->page->priv->source,
+                                                          G_MARKUP_ERROR_INVALID_CONTENT,
+                                                          "MatrixTransform", "Matrix",
+                                                          values[i], error);
+                                }
+                        } else {
+                                gxps_parse_error (context,
+                                                  matrix->ctx->page->priv->source,
+                                                  G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
+                                                  "MatrixTransform", names[i],
+                                                  NULL, error);
+                        }
+                }
+        } else {
+                gxps_parse_error (context,
+                                  matrix->ctx->page->priv->source,
+                                  G_MARKUP_ERROR_UNKNOWN_ELEMENT,
+                                  element_name, NULL, NULL, error);
+        }
+}
+
+static GMarkupParser matrix_parser = {
+        matrix_start_element,
+        NULL,
+        NULL,
+        NULL
+};
+
+void
+gxps_matrix_parser_push (GMarkupParseContext *context,
+                         GXPSMatrix          *matrix)
+{
+        g_markup_parse_context_push (context, &matrix_parser, matrix);
+}
+
+
diff --git a/libgxps/gxps-matrix.h b/libgxps/gxps-matrix.h
new file mode 100644
index 0000000..215ea34
--- /dev/null
+++ b/libgxps/gxps-matrix.h
@@ -0,0 +1,44 @@
+/* GXPSMatrix
+ *
+ * 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_MATRIX_H__
+#define __GXPS_MATRIX_H__
+
+#include <cairo.h>
+#include "gxps-page-private.h"
+
+G_BEGIN_DECLS
+
+typedef struct _GXPSMatrix GXPSMatrix;
+
+struct _GXPSMatrix {
+        GXPSRenderContext *ctx;
+        cairo_matrix_t     matrix;
+};
+
+GXPSMatrix *gxps_matrix_new         (GXPSRenderContext   *ctx);
+void        gxps_matrix_free        (GXPSMatrix          *matrix);
+gboolean    gxps_matrix_parse       (const gchar         *data,
+                                     cairo_matrix_t      *matrix);
+void        gxps_matrix_parser_push (GMarkupParseContext *context,
+                                     GXPSMatrix          *matrix);
+
+G_END_DECLS
+
+#endif /* __GXPS_MATRIX_H__ */
diff --git a/libgxps/gxps-page-private.h b/libgxps/gxps-page-private.h
new file mode 100644
index 0000000..03aa547
--- /dev/null
+++ b/libgxps/gxps-page-private.h
@@ -0,0 +1,62 @@
+/* GXPSPage
+ *
+ * Copyright (C) 2010  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_PAGE_PRIVATE_H__
+#define __GXPS_PAGE_PRIVATE_H__
+
+#include <glib.h>
+#include <cairo.h>
+
+#include "gxps-page.h"
+#include "gxps-archive.h"
+
+G_BEGIN_DECLS
+
+typedef struct _GXPSRenderContext GXPSRenderContext;
+typedef struct _GXPSBrushVisual   GXPSBrushVisual;
+
+struct _GXPSPagePrivate {
+        GXPSArchive *zip;
+        gchar       *source;
+
+        gboolean     initialized;
+        GError      *init_error;
+
+        gdouble      width;
+        gdouble      height;
+        gchar       *lang;
+        gchar       *name;
+
+        /* Images */
+        GHashTable  *image_cache;
+
+        /* Anchors */
+        gboolean     has_anchors;
+        GHashTable  *anchors;
+};
+
+struct _GXPSRenderContext {
+        GXPSPage        *page;
+        cairo_t         *cr;
+        GXPSBrushVisual *visual;
+};
+
+G_END_DECLS
+
+#endif /* __GXPS_PAGE_PRIVATE_H__ */
diff --git a/libgxps/gxps-page.c b/libgxps/gxps-page.c
index 5eceebb..04a6422 100644
--- a/libgxps/gxps-page.c
+++ b/libgxps/gxps-page.c
@@ -22,8 +22,8 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "gxps-page.h"
-#include "gxps-archive.h"
+#include "gxps-page-private.h"
+#include "gxps-matrix.h"
 #include "gxps-fonts.h"
 #include "gxps-links.h"
 #include "gxps-images.h"
@@ -50,26 +50,6 @@ enum {
 	PROP_SOURCE
 };
 
-struct _GXPSPagePrivate {
-	GXPSArchive *zip;
-	gchar       *source;
-
-	gboolean     initialized;
-	GError      *init_error;
-
-	gdouble      width;
-	gdouble      height;
-	gchar       *lang;
-	gchar       *name;
-
-	/* Images */
-	GHashTable  *image_cache;
-
-	/* Anchors */
-	gboolean     has_anchors;
-	GHashTable  *anchors;
-};
-
 static void render_start_element (GMarkupParseContext  *context,
 				  const gchar          *element_name,
 				  const gchar         **names,
@@ -209,109 +189,6 @@ static GMarkupParser render_parser = {
 	NULL,
 	NULL
 };
-typedef struct _GXPSBrushVisual GXPSBrushVisual;
-typedef struct {
-	GXPSPage        *page;
-	cairo_t         *cr;
-	GXPSBrushVisual *visual;
-} GXPSRenderContext;
-
-typedef struct {
-	GXPSRenderContext *ctx;
-	cairo_matrix_t     matrix;
-} GXPSMatrix;
-
-static GXPSMatrix *
-gxps_matrix_new (GXPSRenderContext *ctx)
-{
-	GXPSMatrix *matrix;
-
-	matrix = g_slice_new0 (GXPSMatrix);
-	matrix->ctx = ctx;
-	cairo_matrix_init_identity (&matrix->matrix);
-
-	return matrix;
-}
-
-static void
-gxps_matrix_free (GXPSMatrix *matrix)
-{
-	if (G_UNLIKELY (!matrix))
-		return;
-
-	g_slice_free (GXPSMatrix, matrix);
-}
-
-static gboolean
-gxps_matrix_parse (const gchar    *data,
-		   cairo_matrix_t *matrix)
-{
-	gchar **items;
-        gdouble mm[6];
-        guint   i;
-
-	items = g_strsplit (data, ",", 6);
-	if (g_strv_length (items) != 6) {
-		g_strfreev (items);
-
-		return FALSE;
-	}
-
-        for (i = 0; i < 6; i++) {
-                if (!gxps_value_get_double (items[i], &mm[i])) {
-                        g_strfreev (items);
-                        return FALSE;
-                }
-        }
-
-        g_strfreev (items);
-
-	cairo_matrix_init (matrix, mm[0], mm[1], mm[2], mm[3], mm[4], mm[5]);
-
-	return TRUE;
-}
-
-static void
-matrix_start_element (GMarkupParseContext  *context,
-		      const gchar          *element_name,
-		      const gchar         **names,
-		      const gchar         **values,
-		      gpointer              user_data,
-		      GError              **error)
-{
-	GXPSMatrix *matrix = (GXPSMatrix *)user_data;
-
-	if (strcmp (element_name, "MatrixTransform") == 0) {
-		gint i;
-
-		for (i = 0; names[i] != NULL; i++) {
-			if (strcmp (names[i], "Matrix") == 0) {
-				if (!gxps_matrix_parse (values[i], &matrix->matrix)) {
-					gxps_parse_error (context,
-							  matrix->ctx->page->priv->source,
-							  G_MARKUP_ERROR_INVALID_CONTENT,
-							  "MatrixTransform", "Matrix",
-							  values[i], error);
-					return;
-				}
-			} else if (strcmp (names[i], "X:Key") == 0) {
-				/* TODO */
-			}
-		}
-	} else {
-		gxps_parse_error (context,
-				  matrix->ctx->page->priv->source,
-				  G_MARKUP_ERROR_UNKNOWN_ELEMENT,
-				  element_name, NULL, NULL, error);
-	}
-}
-
-static GMarkupParser matrix_parser = {
-	matrix_start_element,
-	NULL,
-	NULL,
-	NULL
-};
 
 typedef struct {
 	GXPSRenderContext *ctx;
@@ -1373,7 +1250,7 @@ brush_image_start_element (GMarkupParseContext  *context,
 		GXPSMatrix *matrix;
 
 		matrix = gxps_matrix_new (image->brush->ctx);
-		g_markup_parse_context_push (context, &matrix_parser, matrix);
+                gxps_matrix_parser_push (context, matrix);
 	} else {
 		gxps_parse_error (context,
 				  image->brush->ctx->page->priv->source,
@@ -2002,7 +1879,7 @@ canvas_start_element (GMarkupParseContext  *context,
 		GXPSMatrix *matrix;
 
 		matrix = gxps_matrix_new (canvas->ctx);
-		g_markup_parse_context_push (context, &matrix_parser, matrix);
+		gxps_matrix_parser_push (context, matrix);
 	} else if (strcmp (element_name, "Canvas.OpacityMask") == 0) {
 		GXPSBrush *brush;
 
@@ -2074,7 +1951,7 @@ path_geometry_start_element (GMarkupParseContext  *context,
 		GXPSMatrix *matrix;
 
 		matrix = gxps_matrix_new (path->ctx);
-		g_markup_parse_context_push (context, &matrix_parser, matrix);
+		gxps_matrix_parser_push (context, matrix);
 	} else if (strcmp (element_name, "PathFigure") == 0) {
 		gint     i;
                 gboolean has_start_point = FALSE;
@@ -2381,7 +2258,7 @@ path_start_element (GMarkupParseContext  *context,
 		GXPSMatrix *matrix;
 
 		matrix = gxps_matrix_new (path->ctx);
-		g_markup_parse_context_push (context, &matrix_parser, matrix);
+		gxps_matrix_parser_push (context, matrix);
 	} else {
 		GXPS_DEBUG (g_debug ("Unsupported path child %s", element_name));
 	}
@@ -2999,7 +2876,7 @@ glyphs_start_element (GMarkupParseContext  *context,
 		GXPSMatrix *matrix;
 
 		matrix = gxps_matrix_new (glyphs->ctx);
-		g_markup_parse_context_push (context, &matrix_parser, matrix);
+		gxps_matrix_parser_push (context, matrix);
 	} else if (strcmp (element_name, "Glyphs.Clip") == 0) {
 	} else if (strcmp (element_name, "Glyphs.Fill") == 0) {
 		GXPSBrush *brush;



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