[dia] [path] implement text_to_path()
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] [path] implement text_to_path()
- Date: Sun, 14 Oct 2012 13:26:40 +0000 (UTC)
commit 0063d2ea92dda0970c2265436a423e5c3fb89487
Author: Hans Breuer <hans breuer org>
Date: Fri Oct 12 10:59:57 2012 +0200
[path] implement text_to_path()
just some small reorganization of existing code
lib/standard-path.c | 37 ++++++++++++++++++++++++++++---------
lib/standard-path.h | 4 +++-
2 files changed, 31 insertions(+), 10 deletions(-)
---
diff --git a/lib/standard-path.c b/lib/standard-path.c
index 07b0869..daa898e 100644
--- a/lib/standard-path.c
+++ b/lib/standard-path.c
@@ -737,15 +737,15 @@ stdpath_select (StdPath *stdpath, Point *clicked_point,
stdpath_update_handles (stdpath);
}
-DiaObject *
-create_standard_path_from_text (const Text *text)
+gboolean
+text_to_path (const Text *text, GArray *points)
{
cairo_t *cr;
cairo_surface_t *surface;
PangoLayout *layout;
PangoRectangle ink_rect;
char *str;
- DiaObject *obj = NULL;
+ gboolean ret = FALSE;
layout = pango_layout_new(dia_font_get_context());
pango_layout_set_font_description (layout, dia_font_get_description (text->font));
@@ -767,13 +767,14 @@ create_standard_path_from_text (const Text *text)
cairo_surface_destroy (surface);
pango_cairo_layout_path (cr, layout);
+
+ /* convert the path */
+ if (cairo_status (cr) == CAIRO_STATUS_SUCCESS)
{
cairo_path_t *path;
- GArray *points = g_array_new (FALSE, FALSE, sizeof(BezPoint));
int i;
path = cairo_copy_path (cr);
- g_array_set_size (points, 0);
for (i=0; i < path->num_data; i += path->data[i].header.length) {
cairo_path_data_t *data = &path->data[i];
@@ -801,9 +802,29 @@ create_standard_path_from_text (const Text *text)
}
g_array_append_val (points, bp);
}
- obj = create_standard_path (points->len, &g_array_index (points, BezPoint, 0));
- g_array_free (points, TRUE);
+ ret = (path->status == CAIRO_STATUS_SUCCESS);
+ cairo_path_destroy (path);
}
+ /* finally scale it ? */
+
+ /* clean up */
+ g_object_unref (layout);
+ cairo_destroy (cr);
+
+ return ret;
+}
+
+DiaObject *
+create_standard_path_from_text (const Text *text)
+{
+ DiaObject *obj = NULL;
+ GArray *points = g_array_new (FALSE, FALSE, sizeof(BezPoint));
+
+ if (text_to_path (text, points))
+ obj = create_standard_path (points->len, &g_array_index (points, BezPoint, 0));
+
+ g_array_free (points, TRUE);
+
if (obj) {
StdPath *path = (StdPath *)obj;
Rectangle text_box;
@@ -824,8 +845,6 @@ create_standard_path_from_text (const Text *text)
/* also adjust top left corner - calling update, too */
stdpath_move (path, &pos);
}
- g_object_unref (layout);
- cairo_destroy (cr);
return obj;
}
diff --git a/lib/standard-path.h b/lib/standard-path.h
index b86d78d..a5ec7dd 100644
--- a/lib/standard-path.h
+++ b/lib/standard-path.h
@@ -2,7 +2,7 @@
* Copyright (C) 1998 Alexander Larsson
*
* standard-path.c -- path based object drawing
- * Copyright (C) 2012, Hans Breuer <Hans Breuer Org>
+ * Copyright (C) 2012 Hans Breuer <hans breuer org>
*
* 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
@@ -27,4 +27,6 @@
/* there should be no need to use DIAVAR */
extern DiaObjectType stdpath_type;
+gboolean text_to_path (const Text *text, GArray *points);
+
#endif /* STANDARD_PATH_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]