+ else if (!strcmp(element_name, "text")) { // start of a text item
+ if (tmpLayer == NULL || tmpItem != NULL) {
+ *error = xoj_invalid();
+ return;
+ }
+ tmpItem = (struct Item *)g_malloc0(sizeof(struct Item));
+ tmpItem->type = ITEM_TEXT;
+ tmpItem->canvas_item = NULL;
+ tmpLayer->items = g_list_append(tmpLayer->items, tmpItem);
+ tmpLayer->nitems++;
+ // scan for font, size, x, y, and color attributes
+ has_attr = 0;
+ while (*attribute_names!=NULL) {
+ if (!strcmp(*attribute_names, "font")) {
+ if (has_attr & 1) *error = xoj_invalid();
+ tmpItem->font_name = g_strdup(*attribute_values);
+ has_attr |= 1;
+ }
+ else if (!strcmp(*attribute_names, "size")) {
+ if (has_attr & 2) *error = xoj_invalid();
+ cleanup_numeric((gchar *)*attribute_values);
+ tmpItem->font_size = g_ascii_strtod(*attribute_values, &ptr);
+ if (ptr == *attribute_values) *error = xoj_invalid();
+ has_attr |= 2;
+ }
+ else if (!strcmp(*attribute_names, "x")) {
+ if (has_attr & 4) *error = xoj_invalid();
+ cleanup_numeric((gchar *)*attribute_values);
+ tmpItem->bbox.left = g_ascii_strtod(*attribute_values, &ptr);
+ if (ptr == *attribute_values) *error = xoj_invalid();
+ has_attr |= 4;
+ }
+ else if (!strcmp(*attribute_names, "y")) {
+ if (has_attr & 8) *error = xoj_invalid();
+ cleanup_numeric((gchar *)*attribute_values);
+ tmpItem->bbox.top = g_ascii_strtod(*attribute_values, &ptr);
+ if (ptr == *attribute_values) *error = xoj_invalid();
+ has_attr |= 8;
+ }
+ else if (!strcmp(*attribute_names, "color")) {
+ if (has_attr & 16) *error = xoj_invalid();
+ tmpItem->brush.color_no = COLOR_OTHER;
+ for (i=0; i<COLOR_MAX; i++)
+ if (!strcmp(*attribute_values, color_names[i])) {
+ tmpItem->brush.color_no = i;
+ tmpItem->brush.color_rgba = predef_colors_rgba[i];
+ }
+ // there's also the case of hex (#rrggbbaa) colors
+ if (tmpItem->brush.color_no == COLOR_OTHER && **attribute_values == '#') {
+ tmpItem->brush.color_rgba = strtol(*attribute_values + 1, &ptr, 16);
+ if (*ptr!=0) *error = xoj_invalid();
+ }
+ has_attr |= 16;
+ }
+ else *error = xoj_invalid();
+ attribute_names++;
+ attribute_values++;
+ }
+ if (has_attr!=31) *error = xoj_invalid();
+ }