2 #include <glib/gi18n.h>
7 #include "comic-load.h"
12 #include "tbo-object.h"
15 #include "tbo-utils.h"
22 TextObj *CURRENT_TEXT = NULL;
31 parse_attrs (struct attr attrs[],
33 const gchar **attribute_names,
34 const gchar **attribute_values)
37 const gchar **name_cursor = attribute_names;
38 const gchar **value_cursor = attribute_values;
40 while (*name_cursor) {
41 for (i=0; i<attrs_size; i++)
43 if (strcmp (*name_cursor, attrs[i].name) == 0)
45 if (strcmp (attrs[i].format, "%s") == 0)
47 sprintf(attrs[i].pointer, "%s", *value_cursor);
50 sscanf (*value_cursor, attrs[i].format, attrs[i].pointer);
59 create_tbo_comic (const gchar **attribute_names, const gchar **attribute_values)
64 struct attr attrs[] = {
65 {"width", "%d", &width},
66 {"height", "%d", &height},
69 parse_attrs (attrs, G_N_ELEMENTS (attrs), attribute_names, attribute_values);
71 COMIC = tbo_comic_new (TITLE, width, height);
72 tbo_comic_del_page (COMIC, 0);
76 create_tbo_frame (const gchar **attribute_names, const gchar **attribute_values)
79 int width=0, height=0;
81 float r=0.0, g=0.0, b=0.0;
83 struct attr attrs[] = {
86 {"width", "%d", &width},
87 {"height", "%d", &height},
88 {"border", "%d", &border},
94 parse_attrs (attrs, G_N_ELEMENTS (attrs), attribute_names, attribute_values);
96 CURRENT_FRAME = tbo_page_new_frame (CURRENT_PAGE, x, y, width, height);
97 CURRENT_FRAME->border = border;
98 CURRENT_FRAME->color->r = r;
99 CURRENT_FRAME->color->g = g;
100 CURRENT_FRAME->color->b = b;
104 create_tbo_svgimage (const gchar **attribute_names, const gchar **attribute_values)
108 int width=0, height=0;
110 int flipv=0, fliph=0;
113 struct attr attrs[] = {
116 {"width", "%d", &width},
117 {"height", "%d", &height},
118 {"flipv", "%d", &flipv},
119 {"fliph", "%d", &fliph},
120 {"angle", "%f", &angle},
121 {"path", "%s", path},
124 parse_attrs (attrs, G_N_ELEMENTS (attrs), attribute_names, attribute_values);
126 svg = tbo_svgimage_new_width_params (x, y, width, height, path);
127 tbo_frame_add_obj (CURRENT_FRAME, svg);
131 create_tbo_text (const gchar **attribute_names, const gchar **attribute_values)
135 int width=0, height=0;
137 int flipv=0, fliph=0;
139 float r=0.0, g=0.0, b=0.0;
141 struct attr attrs[] = {
144 {"width", "%d", &width},
145 {"height", "%d", &height},
146 {"flipv", "%d", &flipv},
147 {"fliph", "%d", &fliph},
148 {"angle", "%f", &angle},
149 {"font", "%s", font},
155 parse_attrs (attrs, G_N_ELEMENTS (attrs), attribute_names, attribute_values);
156 textobj = tbo_text_new_width_params (x, y, width, height, "text", font, r, g, b);
157 textobj->angle = angle;
158 CURRENT_TEXT = textobj;
159 tbo_frame_add_obj (CURRENT_FRAME, textobj);
163 /* The handler functions. */
166 start_element (GMarkupParseContext *context,
167 const gchar *element_name,
168 const gchar **attribute_names,
169 const gchar **attribute_values,
173 if (strcmp (element_name, "tbo") == 0)
175 create_tbo_comic (attribute_names, attribute_values);
177 else if (strcmp (element_name, "page") == 0)
179 CURRENT_PAGE = tbo_page_new (COMIC);
180 COMIC->pages = g_list_append (COMIC->pages, CURRENT_PAGE);
182 else if (strcmp (element_name, "frame") == 0)
184 create_tbo_frame (attribute_names, attribute_values);
186 else if (strcmp (element_name, "svgimage") == 0)
188 create_tbo_svgimage (attribute_names, attribute_values);
190 else if (strcmp (element_name, "text") == 0)
192 create_tbo_text (attribute_names, attribute_values);
197 text (GMarkupParseContext *context,
205 char *text2 = g_strndup (text, text_len);
206 tbo_text_set_text (CURRENT_TEXT, g_strstrip (text2));
212 end_element (GMarkupParseContext *context,
213 const gchar *element_name,
217 if (strcmp (element_name, "tbo") == 0)
221 else if (strcmp (element_name, "text") == 0)
227 static GMarkupParser parser = {
236 tbo_comic_load (char *filename)
240 GMarkupParseContext *context = g_markup_parse_context_new (
247 get_base_name (filename, base_name, 255);
248 TITLE = g_strdup(base_name);
250 if (g_file_get_contents (filename, &text, &length, NULL) == FALSE) {
251 GtkWidget *dialog = gtk_message_dialog_new (NULL,
255 _("Couldn't load file"));
259 if (g_markup_parse_context_parse (context, text, length, NULL) == FALSE) {
260 GtkWidget *dialog = gtk_message_dialog_new (NULL,
264 _("Couldn't parse file"));
269 g_markup_parse_context_free (context);