/** Return the value of a font-type data node. This handles both the current * format (family and style) and the old format (name). * @param data The data node to read from. * @return The font value found in the node. If the node is not a * font node, an error message is displayed and NULL is returned. The * resulting value should be freed after use. */ DiaFont * data_font(DataNode data) { xmlChar *family; DiaFont *font; if (data_type(data)!=DATATYPE_FONT) { message_error("Taking font value of non-font node."); return NULL; } family = xmlGetProp(data, (const xmlChar *)"family"); /* always prefer the new format */ if (family) { DiaFontStyle style; char* style_name = (char *) xmlGetProp(data, (const xmlChar *)"style"); style = style_name ? atoi(style_name) : 0; font = dia_font_new ((char *)family, style, 1.0); if (family) free(family); if (style_name) xmlFree(style_name); } else { /* Legacy format support */ char *name = (char *)xmlGetProp(data, (const xmlChar *)"name"); font = dia_font_new_from_legacy_name(name); free(name); } return font; }
static DiaObject * fig_read_text(FILE *file, DiaContext *ctx) { GPtrArray *props = NULL; TextProperty *tprop; DiaObject *newobj = NULL; int sub_type; int color; int depth; int pen_style; int font; real font_size; real angle; int font_flags; real height; real length; int x, y; char *text_buf = NULL; char* old_locale; old_locale = setlocale(LC_NUMERIC, "C"); if (fscanf(file, " %d %d %d %d %d %lf %lf %d %lf %lf %d %d", &sub_type, &color, &depth, &pen_style, &font, &font_size, &angle, &font_flags, &height, &length, &x, &y) != 12) { dia_context_add_message_with_errno(ctx, errno, _("Couldn't read text info.")); setlocale(LC_NUMERIC, old_locale); return NULL; } /* Skip one space exactly */ text_buf = fig_read_text_line(file); newobj = create_standard_text(x/FIG_UNIT, y/FIG_UNIT); if (newobj == NULL) goto exit; props = prop_list_from_descs(xfig_text_descs,pdtpp_true); tprop = g_ptr_array_index(props,0); tprop->text_data = g_strdup(text_buf); /*g_free(text_buf); */ tprop->attr.alignment = sub_type; tprop->attr.position.x = x/FIG_UNIT; tprop->attr.position.y = y/FIG_UNIT; if ((font_flags & 4) == 0) { switch (font) { case 0: tprop->attr.font = dia_font_new_from_legacy_name("Times-Roman"); break; case 1: tprop->attr.font = dia_font_new_from_legacy_name("Times-Roman"); break; case 2: tprop->attr.font = dia_font_new_from_legacy_name("Times-Bold"); break; case 3: tprop->attr.font = dia_font_new_from_legacy_name("Times-Italic"); break; case 4: tprop->attr.font = dia_font_new_from_legacy_name("Helvetica"); break; case 5: tprop->attr.font = dia_font_new_from_legacy_name("Courier"); break; default: dia_context_add_message(ctx, _("Can't find LaTeX font nr. %d, using sans"), font); tprop->attr.font = dia_font_new_from_legacy_name("Helvetica"); } } else { if (font == -1) { /* "Default font" - wazzat? */ tprop->attr.font = dia_font_new_from_legacy_name("Times-Roman"); } else if (font < 0 || font >= num_fig_fonts()) { dia_context_add_message(ctx, _("Can't find Postscript font nr. %d, using sans"), font); tprop->attr.font = dia_font_new_from_legacy_name("Helvetica"); } else { tprop->attr.font = dia_font_new_from_legacy_name(fig_fonts[font]); } } tprop->attr.height = font_size*2.54/72.0; tprop->attr.color = fig_color(color, ctx); newobj->ops->set_props(newobj, props); /* Depth field */ add_at_depth(newobj, depth, ctx); exit: setlocale(LC_NUMERIC, old_locale); if (text_buf != NULL) g_free(text_buf); if (props != NULL) prop_list_free(props); return newobj; }