summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gmathview/CMakeLists.txt2
-rw-r--r--gmathview/gmathview_utils.c65
-rw-r--r--include/gmathview.h10
3 files changed, 76 insertions, 1 deletions
diff --git a/gmathview/CMakeLists.txt b/gmathview/CMakeLists.txt
index 7c6d1b8..5501def 100644
--- a/gmathview/CMakeLists.txt
+++ b/gmathview/CMakeLists.txt
@@ -9,7 +9,7 @@ link_directories (
${GTK_LINK_DIRS}
)
-add_library (gmathview SHARED gmathview.c)
+add_library (gmathview SHARED gmathview.c gmathview_utils.c)
target_link_libraries (
gmathview ${GLIB_LIBRARIES} ${GTK_LIBRARIES} gmathcairo
)
diff --git a/gmathview/gmathview_utils.c b/gmathview/gmathview_utils.c
new file mode 100644
index 0000000..c466594
--- /dev/null
+++ b/gmathview/gmathview_utils.c
@@ -0,0 +1,65 @@
+/*
+ * gMathView, mathematic expressions viewing & editing widget
+ *
+ * # Helper functions
+ *
+ * Author : Guillaume Seguin
+ * Email : guillaume@segu.in
+ *
+ * Copyright (c) 2007 Guillaume Seguin <guillaume@segu.in>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <gmathview.h>
+
+cairo_surface_t*
+g_math_view_copy_surface (cairo_surface_t *source)
+{
+ cairo_surface_t *dest;
+ cairo_t *cr;
+
+ if (!source)
+ return NULL;
+
+ dest = cairo_image_surface_create (cairo_image_surface_get_format (source),
+ cairo_image_surface_get_width (source),
+ cairo_image_surface_get_height (source));
+ cr = cairo_create (dest);
+ cairo_set_source_surface (cr, source, 0, 0);
+ cairo_paint (cr);
+ cairo_destroy (cr);
+
+ return dest;
+}
+
+void
+g_math_view_outline_boxed (cairo_surface_t *surface, GMathBoxed *boxed)
+{
+ cairo_t *cr;
+
+ if (!surface || !boxed)
+ return;
+
+ cr = cairo_create (surface);
+ cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
+ cairo_set_line_width (cr, OUTLINE_WIDTH);
+ cairo_rectangle (cr, boxed->box.x, boxed->box.y,
+ boxed->box.width, boxed->box.height);
+ cairo_stroke (cr);
+
+ cairo_destroy (cr);
+}
diff --git a/include/gmathview.h b/include/gmathview.h
index 02e1470..8f59233 100644
--- a/include/gmathview.h
+++ b/include/gmathview.h
@@ -33,6 +33,8 @@
#include <gmathlib.h>
#include <gmathcairo.h>
+#define OUTLINE_WIDTH 1
+
G_BEGIN_DECLS
#define G_TYPE_MATH_VIEW (g_math_view_get_type ())
@@ -87,4 +89,12 @@ g_math_view_set_editor_mode (GMathView *mathview, gboolean editor_mode);
G_END_DECLS
+/* Helper functions */
+
+cairo_surface_t*
+g_math_view_copy_surface (cairo_surface_t *source);
+
+void
+g_math_view_outline_boxed (cairo_surface_t *surface, GMathBoxed *boxed);
+
#endif