2 #include <glib/gi18n.h>
7 #include "comic-load.h"
12 #include "tbo-object.h"
16 #include "tbo-utils.h"
23 TextObj *CURRENT_TEXT = NULL;
32 parse_attrs (struct attr attrs[],
34 const gchar **attribute_names,
35 const gchar **attribute_values)
38 const gchar **name_cursor = attribute_names;
39 const gchar **value_cursor = attribute_values;
41 while (*name_cursor) {
42 for (i=0; i<attrs_size; i++)
44 if (strcmp (*name_cursor, attrs[i].name) == 0)
46 if (strcmp (attrs[i].format, "%s") == 0)
48 sprintf(attrs[i].pointer, "%s", *value_cursor);
51 sscanf (*value_cursor, attrs[i].format, attrs[i].pointer);
60 create_tbo_comic (const gchar **attribute_names, const gchar **attribute_values)
65 struct attr attrs[] = {
66 {"width", "%d", &width},
67 {"height", "%d", &height},
70 parse_attrs (attrs, G_N_ELEMENTS (attrs), attribute_names, attribute_values);
72 COMIC = tbo_comic_new (TITLE, width, height);
73 tbo_comic_del_page (COMIC, 0);
77 create_tbo_frame (const gchar **attribute_names, const gchar **attribute_values)
80 int width=0, height=0;
82 float r=0.0, g=0.0, b=0.0;
84 struct attr attrs[] = {
87 {"width", "%d", &width},
88 {"height", "%d", &height},
89 {"border", "%d", &border},
95 parse_attrs (attrs, G_N_ELEMENTS (attrs), attribute_names, attribute_values);
97 CURRENT_FRAME = tbo_page_new_frame (CURRENT_PAGE, x, y, width, height);
98 CURRENT_FRAME->border = border;
99 CURRENT_FRAME->color->r = r;
100 CURRENT_FRAME->color->g = g;
101 CURRENT_FRAME->color->b = b;
105 create_tbo_piximage (const gchar **attribute_names, const gchar **attribute_values)
109 int width=0, height=0;
111 int flipv=0, fliph=0;
114 struct attr attrs[] = {
117 {"width", "%d", &width},
118 {"height", "%d", &height},
119 {"flipv", "%d", &flipv},
120 {"fliph", "%d", &fliph},
121 {"angle", "%f", &angle},
122 {"path", "%s", path},
125 parse_attrs (attrs, G_N_ELEMENTS (attrs), attribute_names, attribute_values);
127 pix = tbo_piximage_new_width_params (x, y, width, height, path);
131 tbo_frame_add_obj (CURRENT_FRAME, pix);
135 create_tbo_svgimage (const gchar **attribute_names, const gchar **attribute_values)
139 int width=0, height=0;
141 int flipv=0, fliph=0;
144 struct attr attrs[] = {
147 {"width", "%d", &width},
148 {"height", "%d", &height},
149 {"flipv", "%d", &flipv},
150 {"fliph", "%d", &fliph},
151 {"angle", "%f", &angle},
152 {"path", "%s", path},
155 parse_attrs (attrs, G_N_ELEMENTS (attrs), attribute_names, attribute_values);
157 svg = tbo_svgimage_new_width_params (x, y, width, height, path);
161 tbo_frame_add_obj (CURRENT_FRAME, svg);
165 create_tbo_text (const gchar **attribute_names, const gchar **attribute_values)
169 int width=0, height=0;
171 int flipv=0, fliph=0;
173 float r=0.0, g=0.0, b=0.0;
175 struct attr attrs[] = {
178 {"width", "%d", &width},
179 {"height", "%d", &height},
180 {"flipv", "%d", &flipv},
181 {"fliph", "%d", &fliph},
182 {"angle", "%f", &angle},
183 {"font", "%s", font},
189 parse_attrs (attrs, G_N_ELEMENTS (attrs), attribute_names, attribute_values);
190 textobj = tbo_text_new_width_params (x, y, width, height, "text", font, r, g, b);
191 textobj->angle = angle;
192 textobj->flipv = flipv;
193 textobj->fliph = fliph;
194 CURRENT_TEXT = textobj;
195 tbo_frame_add_obj (CURRENT_FRAME, textobj);
199 /* The handler functions. */
202 start_element (GMarkupParseContext *context,
203 const gchar *element_name,
204 const gchar **attribute_names,
205 const gchar **attribute_values,
209 if (strcmp (element_name, "tbo") == 0)
211 create_tbo_comic (attribute_names, attribute_values);
213 else if (strcmp (element_name, "page") == 0)
215 CURRENT_PAGE = tbo_page_new (COMIC);
216 COMIC->pages = g_list_append (COMIC->pages, CURRENT_PAGE);
218 else if (strcmp (element_name, "frame") == 0)
220 create_tbo_frame (attribute_names, attribute_values);
222 else if (strcmp (element_name, "svgimage") == 0)
224 create_tbo_svgimage (attribute_names, attribute_values);
226 else if (strcmp (element_name, "piximage") == 0)
228 create_tbo_piximage (attribute_names, attribute_values);
230 else if (strcmp (element_name, "text") == 0)
232 create_tbo_text (attribute_names, attribute_values);
237 text (GMarkupParseContext *context,
245 char *text2 = g_strndup (text, text_len);
246 tbo_text_set_text (CURRENT_TEXT, g_strstrip (text2));
252 end_element (GMarkupParseContext *context,
253 const gchar *element_name,
257 if (strcmp (element_name, "tbo") == 0)
261 else if (strcmp (element_name, "text") == 0)
267 static GMarkupParser parser = {
276 tbo_comic_load (char *filename)
280 GMarkupParseContext *context = g_markup_parse_context_new (
287 get_base_name (filename, base_name, 255);
288 TITLE = g_strdup(base_name);
290 if (g_file_get_contents (filename, &text, &length, NULL) == FALSE) {
291 GtkWidget *dialog = gtk_message_dialog_new (NULL,
295 _("Couldn't load file"));
299 if (g_markup_parse_context_parse (context, text, length, NULL) == FALSE) {
300 GtkWidget *dialog = gtk_message_dialog_new (NULL,
304 _("Couldn't parse file"));
309 g_markup_parse_context_free (context);