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);
128 tbo_frame_add_obj (CURRENT_FRAME, pix);
132 create_tbo_svgimage (const gchar **attribute_names, const gchar **attribute_values)
136 int width=0, height=0;
138 int flipv=0, fliph=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 {"path", "%s", path},
152 parse_attrs (attrs, G_N_ELEMENTS (attrs), attribute_names, attribute_values);
154 svg = tbo_svgimage_new_width_params (x, y, width, height, path);
155 tbo_frame_add_obj (CURRENT_FRAME, svg);
159 create_tbo_text (const gchar **attribute_names, const gchar **attribute_values)
163 int width=0, height=0;
165 int flipv=0, fliph=0;
167 float r=0.0, g=0.0, b=0.0;
169 struct attr attrs[] = {
172 {"width", "%d", &width},
173 {"height", "%d", &height},
174 {"flipv", "%d", &flipv},
175 {"fliph", "%d", &fliph},
176 {"angle", "%f", &angle},
177 {"font", "%s", font},
183 parse_attrs (attrs, G_N_ELEMENTS (attrs), attribute_names, attribute_values);
184 textobj = tbo_text_new_width_params (x, y, width, height, "text", font, r, g, b);
185 textobj->angle = angle;
186 CURRENT_TEXT = textobj;
187 tbo_frame_add_obj (CURRENT_FRAME, textobj);
191 /* The handler functions. */
194 start_element (GMarkupParseContext *context,
195 const gchar *element_name,
196 const gchar **attribute_names,
197 const gchar **attribute_values,
201 if (strcmp (element_name, "tbo") == 0)
203 create_tbo_comic (attribute_names, attribute_values);
205 else if (strcmp (element_name, "page") == 0)
207 CURRENT_PAGE = tbo_page_new (COMIC);
208 COMIC->pages = g_list_append (COMIC->pages, CURRENT_PAGE);
210 else if (strcmp (element_name, "frame") == 0)
212 create_tbo_frame (attribute_names, attribute_values);
214 else if (strcmp (element_name, "svgimage") == 0)
216 create_tbo_svgimage (attribute_names, attribute_values);
218 else if (strcmp (element_name, "piximage") == 0)
220 create_tbo_piximage (attribute_names, attribute_values);
222 else if (strcmp (element_name, "text") == 0)
224 create_tbo_text (attribute_names, attribute_values);
229 text (GMarkupParseContext *context,
237 char *text2 = g_strndup (text, text_len);
238 tbo_text_set_text (CURRENT_TEXT, g_strstrip (text2));
244 end_element (GMarkupParseContext *context,
245 const gchar *element_name,
249 if (strcmp (element_name, "tbo") == 0)
253 else if (strcmp (element_name, "text") == 0)
259 static GMarkupParser parser = {
268 tbo_comic_load (char *filename)
272 GMarkupParseContext *context = g_markup_parse_context_new (
279 get_base_name (filename, base_name, 255);
280 TITLE = g_strdup(base_name);
282 if (g_file_get_contents (filename, &text, &length, NULL) == FALSE) {
283 GtkWidget *dialog = gtk_message_dialog_new (NULL,
287 _("Couldn't load file"));
291 if (g_markup_parse_context_parse (context, text, length, NULL) == FALSE) {
292 GtkWidget *dialog = gtk_message_dialog_new (NULL,
296 _("Couldn't parse file"));
301 g_markup_parse_context_free (context);