static Object * generalization_load(ObjectNode obj_node, int version, const char *filename) { Generalization *genlz; AttributeNode attr; OrthConn *orth; Object *obj; if (genlz_font == NULL) { genlz_font = font_getfont("Courier"); } genlz = g_new(Generalization, 1); orth = &genlz->orth; obj = (Object *) genlz; obj->type = &generalization_type; obj->ops = &generalization_ops; orthconn_load(orth, obj_node); genlz->name = NULL; attr = object_find_attribute(obj_node, "name"); if (attr != NULL) genlz->name = data_string(attribute_first_data(attr)); genlz->stereotype = NULL; attr = object_find_attribute(obj_node, "stereotype"); if (attr != NULL) genlz->stereotype = data_string(attribute_first_data(attr)); genlz->text_width = 0.0; genlz->properties_dialog = NULL; if (genlz->name != NULL) { genlz->text_width = font_string_width(genlz->name, genlz_font, GENERALIZATION_FONTHEIGHT); } if (genlz->stereotype != NULL) { genlz->text_width = MAX(genlz->text_width, font_string_width(genlz->stereotype, genlz_font, GENERALIZATION_FONTHEIGHT)); } generalization_update_data(genlz); return (Object *)genlz; }
static Object * implements_load(ObjectNode obj_node, int version, const char *filename) { Implements *implements; AttributeNode attr; Connection *conn; Object *obj; if (implements_font == NULL) implements_font = font_getfont("Courier"); implements = g_malloc(sizeof(Implements)); conn = &implements->connection; obj = (Object *) implements; obj->type = &implements_type; obj->ops = &implements_ops; connection_load(conn, obj_node); connection_init(conn, 4, 0); implements->circle_diameter = 1.0; attr = object_find_attribute(obj_node, "diameter"); if (attr != NULL) implements->circle_diameter = data_real(attribute_first_data(attr)); implements->text = NULL; attr = object_find_attribute(obj_node, "text"); if (attr != NULL) implements->text = data_string(attribute_first_data(attr)); attr = object_find_attribute(obj_node, "text_pos"); if (attr != NULL) data_point(attribute_first_data(attr), &implements->text_pos); implements->text_width = font_string_width(implements->text, implements_font, IMPLEMENTS_FONTHEIGHT); implements->text_handle.id = HANDLE_MOVE_TEXT; implements->text_handle.type = HANDLE_MINOR_CONTROL; implements->text_handle.connect_type = HANDLE_NONCONNECTABLE; implements->text_handle.connected_to = NULL; obj->handles[2] = &implements->text_handle; implements->circle_handle.id = HANDLE_CIRCLE_SIZE; implements->circle_handle.type = HANDLE_MINOR_CONTROL; implements->circle_handle.connect_type = HANDLE_NONCONNECTABLE; implements->circle_handle.connected_to = NULL; obj->handles[3] = &implements->circle_handle; implements->properties_dialog = NULL; implements_update_data(implements); return (Object *)implements; }
char * data_string_copy(char **data, int *avail) { char *sal = NULL; assert(data); assert(*data); assert(avail); assert(avail[0] > 0); if (avail[0] > 0) { int length = 0; char *s = data_string(data, &length, avail); assert(length >= 0); if (length > 0) { assert(s); assert((length + 1) > 0); sal = malloc(length + 1); assert(sal); memcpy(sal, s, length); sal[length] = 0; } else { assert(s == NULL); assert(sal == NULL); } } assert(avail[0] >= 0); return(sal); }
/** Return the value of a filename-type data node. * @param data The data node to read from. * @return The filename value found in the node. If the node is not a * filename node, an error message is displayed and NULL is returned. * The resulting string is in the local filesystem's encoding rather than * UTF-8, and should be freed after use. * @bug data_string() can return NULL, what does g_filename_from_utf8 do then? */ char * data_filename(DataNode data) { char *utf8 = data_string(data); char *filename = g_filename_from_utf8(utf8, -1, NULL, NULL, NULL); g_free(utf8); return filename; }
std::string Client_socket::read_line ( std::string linebreak ) { // Read until we have at least one line while ( next_lines.empty () ) { // This might actually happen ( look at the test for an example ) if ( ends_with ( line_rest, linebreak ) ) { // Remove the linebreak from the end next_lines.push_back ( line_rest.substr ( 0, line_rest.find_last_of ( linebreak ) ) ); line_rest = ""; break; } char buffer [ 1024 ]; int success = read ( socket_address, buffer, sizeof ( buffer ) - 1 ); if ( success < 0 ) error ( "read_line : Reading from socket failed"); else if ( success == 0 ) error ( "read_line : Connection closed"); buffer [ success ] = '\0'; // Create actual string from vector std::string data_string ( buffer, strlen ( buffer ) ); std::string line; // Split lines at delimiter while ( ( line = get_line ( data_string, linebreak ) ).size () > 0 ) { // Apply line_rest ( if any ) line = line_rest + line; line_rest.clear (); // Save yourself the hassle of dealing with DOS linebreaks next_lines.push_back ( line ); } // If buffer_string doesn't end with a linebreak if ( data_string.size () > 0 ) { // Create a line_rest line_rest += data_string; } } // Return next line while ( !next_lines.empty () && next_lines.front () == "" ) next_lines.pop_front (); if ( !next_lines.empty () ) { std::string line = next_lines.front (); next_lines.pop_front (); return line; } else return read_line (); }
static void stringprop_load(StringProperty *prop, AttributeNode attr, DataNode data, DiaContext *ctx) { g_free(prop->string_data); prop->string_data = data_string(data, ctx); if (prop->string_data == NULL) { prop->string_data = g_strdup(""); } }
/* *NOT A CALLBACK* --> Must be called by inherited class (see aadldata.c) */ void aadlbox_load(ObjectNode obj_node, int version, DiaContext *ctx, Aadlbox *aadlbox) { AttributeNode attr; DataNode composite, data; Aadl_type type; gchar *declaration; Aadlport *port; ConnectionPoint *connection; int i, num; attr = object_find_attribute(obj_node, "aadlbox_ports"); composite = attribute_first_data(attr); num = attribute_num_data(attr); for (i=0; i<num; i++) { Point p; attr = composite_find_attribute(composite, "point"); data_point(attribute_first_data(attr), &p, ctx); attr = composite_find_attribute(composite, "port_type"); type = data_enum(attribute_first_data(attr), ctx); attr = composite_find_attribute(composite, "port_declaration"); declaration = data_string(attribute_first_data(attr), ctx); port = g_new0(Aadlport,1); port->handle = g_new0(Handle,1); port->type = type; port->declaration = declaration; aadlbox_add_port(aadlbox, &p, port); composite = data_next(composite); } attr = object_find_attribute(obj_node, "aadlbox_connections"); num = attribute_num_data(attr); data = attribute_first_data(attr); for (i=0; i<num; i++) { Point p; data_point(data, &p, ctx); connection = g_new0(ConnectionPoint,1); aadlbox_add_connection(aadlbox, &p, connection); data = data_next(data); } object_load_props(&aadlbox->element.object,obj_node, ctx); }
UMLAttribute * uml_attribute_read(DataNode composite) { UMLAttribute *attr; AttributeNode attr_node; attr = g_new(UMLAttribute, 1); attr->name = NULL; attr_node = composite_find_attribute(composite, "name"); if (attr_node != NULL) attr->name = data_string( attribute_first_data(attr_node) ); attr->type = NULL; attr_node = composite_find_attribute(composite, "type"); if (attr_node != NULL) attr->type = data_string( attribute_first_data(attr_node) ); attr->value = NULL; attr_node = composite_find_attribute(composite, "value"); if (attr_node != NULL) attr->value = data_string( attribute_first_data(attr_node) ); attr->visibility = FALSE; attr_node = composite_find_attribute(composite, "visibility"); if (attr_node != NULL) attr->visibility = data_enum( attribute_first_data(attr_node) ); attr->abstract = FALSE; attr_node = composite_find_attribute(composite, "abstract"); if (attr_node != NULL) attr->abstract = data_boolean( attribute_first_data(attr_node) ); attr->class_scope = FALSE; attr_node = composite_find_attribute(composite, "class_scope"); if (attr_node != NULL) attr->class_scope = data_boolean( attribute_first_data(attr_node) ); attr->left_connection = NULL; attr->right_connection = NULL; return attr; }
UMLFormalParameter * uml_formalparameter_read(DataNode composite) { UMLFormalParameter *param; AttributeNode attr_node; param = g_new(UMLFormalParameter, 1); param->name = NULL; attr_node = composite_find_attribute(composite, "name"); if (attr_node != NULL) param->name = data_string( attribute_first_data(attr_node) ); param->type = NULL; attr_node = composite_find_attribute(composite, "type"); if (attr_node != NULL) param->type = data_string( attribute_first_data(attr_node) ); return param; }
static Object * message_load(ObjectNode obj_node, int version, const char *filename) { Message *message; AttributeNode attr; Connection *conn; Object *obj; if (message_font == NULL) message_font = font_getfont("Helvetica"); message = g_malloc(sizeof(Message)); conn = &message->connection; obj = (Object *) message; obj->type = &message_type; obj->ops = &message_ops; connection_load(conn, obj_node); connection_init(conn, 3, 0); message->text = NULL; attr = object_find_attribute(obj_node, "text"); if (attr != NULL) message->text = data_string(attribute_first_data(attr)); attr = object_find_attribute(obj_node, "text_pos"); if (attr != NULL) data_point(attribute_first_data(attr), &message->text_pos); attr = object_find_attribute(obj_node, "type"); if (attr != NULL) message->type = (MessageType)data_int(attribute_first_data(attr)); if (message->text) message->text_width = font_string_width(message->text, message_font, MESSAGE_FONTHEIGHT); else message->text_width = 0; message->text_handle.id = HANDLE_MOVE_TEXT; message->text_handle.type = HANDLE_MINOR_CONTROL; message->text_handle.connect_type = HANDLE_NONCONNECTABLE; message->text_handle.connected_to = NULL; obj->handles[2] = &message->text_handle; message_update_data(message); return (Object *)message; }
static void charprop_load(CharProperty *prop, AttributeNode attr, DataNode data) { gchar *str = data_string(data); if (str && str[0]) { prop->char_data = g_utf8_get_char(str); g_free(str); } else { g_warning("Could not read character data for attribute %s", prop->common.name); } }
/*! * \brief Return the value of a filename-type data node. * @param data The data node to read from. * @param ctx The context in which this function is called * @return The filename value found in the node. If the node is not a * filename node, an error message is added to ctx and NULL is returned. * The resulting string is in the local filesystem's encoding rather than * UTF-8, and should be freed after use. * \ingroup DiagramXmlIn */ char * data_filename(DataNode data, DiaContext *ctx) { char *utf8 = data_string(data, ctx); char *filename = NULL; if (utf8) { GError *error = NULL; if ((filename = g_filename_from_utf8(utf8, -1, NULL, NULL, &error)) == NULL) { dia_context_add_message (ctx, "%s", error->message); g_error_free (error); } g_free(utf8); } return filename; }
Text * data_text(AttributeNode text_attr) { char *string = ""; Font *font; real height; Point pos = {0.0, 0.0}; Color col; Alignment align; AttributeNode attr; DataNode composite_node; Text *text; composite_node = attribute_first_data(text_attr); attr = composite_find_attribute(text_attr, "string"); if (attr != NULL) string = data_string(attribute_first_data(attr)); font = font_getfont("Courier"); attr = composite_find_attribute(text_attr, "font"); if (attr != NULL) font = data_font(attribute_first_data(attr)); height = 1.0; attr = composite_find_attribute(text_attr, "height"); if (attr != NULL) height = data_real(attribute_first_data(attr)); attr = composite_find_attribute(text_attr, "pos"); if (attr != NULL) data_point(attribute_first_data(attr), &pos); col = color_black; attr = composite_find_attribute(text_attr, "color"); if (attr != NULL) data_color(attribute_first_data(attr), &col); align = ALIGN_LEFT; attr = composite_find_attribute(text_attr, "alignment"); if (attr != NULL) align = data_enum(attribute_first_data(attr)); text = new_text(string, font, height, &pos, &col, align); if (string) free(string); return text; }
Text * data_text(AttributeNode text_attr, DiaContext *ctx) { char *string = NULL; DiaFont *font; real height; Point pos = {0.0, 0.0}; Color col; Alignment align; AttributeNode attr; Text *text; attr = composite_find_attribute(text_attr, "string"); if (attr != NULL) string = data_string(attribute_first_data(attr), ctx); height = 1.0; attr = composite_find_attribute(text_attr, "height"); if (attr != NULL) height = data_real(attribute_first_data(attr), ctx); attr = composite_find_attribute(text_attr, "font"); if (attr != NULL) { font = data_font(attribute_first_data(attr), ctx); } else { font = dia_font_new_from_style(DIA_FONT_SANS,1.0); } attr = composite_find_attribute(text_attr, "pos"); if (attr != NULL) data_point(attribute_first_data(attr), &pos, ctx); col = color_black; attr = composite_find_attribute(text_attr, "color"); if (attr != NULL) data_color(attribute_first_data(attr), &col, ctx); align = ALIGN_LEFT; attr = composite_find_attribute(text_attr, "alignment"); if (attr != NULL) align = data_enum(attribute_first_data(attr), ctx); text = new_text(string ? string : "", font, height, &pos, &col, align); if (font) dia_font_unref(font); if (string) g_free(string); return text; }
static Object * constraint_load(ObjectNode obj_node, int version, const char *filename) { Constraint *constraint; AttributeNode attr; Connection *conn; Object *obj; if (constraint_font == NULL) constraint_font = font_getfont("Courier"); constraint = g_malloc(sizeof(Constraint)); conn = &constraint->connection; obj = (Object *) constraint; obj->type = &constraint_type; obj->ops = &constraint_ops; connection_load(conn, obj_node); connection_init(conn, 3, 0); constraint->text = NULL; attr = object_find_attribute(obj_node, "text"); if (attr != NULL) constraint->text = data_string(attribute_first_data(attr)); attr = object_find_attribute(obj_node, "text_pos"); if (attr != NULL) data_point(attribute_first_data(attr), &constraint->text_pos); constraint->text_width = font_string_width(constraint->text, constraint_font, CONSTRAINT_FONTHEIGHT); constraint->text_handle.id = HANDLE_MOVE_TEXT; constraint->text_handle.type = HANDLE_MINOR_CONTROL; constraint->text_handle.connect_type = HANDLE_NONCONNECTABLE; constraint->text_handle.connected_to = NULL; obj->handles[2] = &constraint->text_handle; constraint->properties_dialog = NULL; constraint_update_data(constraint); return (Object *)constraint; }
static void dictprop_load(DictProperty *prop, AttributeNode attr, DataNode data) { DataNode kv; guint nvals = attribute_num_data(attr); if (!nvals) return; kv = attribute_first_data (data); while (kv) { xmlChar *key = xmlGetProp(kv, (const xmlChar *)"name"); if (key) { gchar *value = data_string(attribute_first_data (kv)); if (value) g_hash_table_insert (prop->dict, g_strdup((gchar *)key), value); } else { g_warning ("Dictionary key missing"); } kv = data_next(kv); } }
Boolequation * load_boolequation(ObjectNode obj_node, const gchar *attrname, const gchar *defaultvalue, DiaFont *font, real fontheight, Color *color) { gchar *value = NULL; Boolequation *booleq; AttributeNode attr; booleq = boolequation_create(NULL,font,fontheight,color); attr = object_find_attribute(obj_node,attrname); if (attr) value = data_string(attribute_first_data(attr)); else if (defaultvalue) value = g_strdup (defaultvalue); if (value) boolequation_set_value(booleq,value); g_free(value); return booleq; }
UMLOperation * uml_operation_read(DataNode composite) { UMLOperation *op; UMLParameter *param; AttributeNode attr_node; AttributeNode attr_node2; DataNode composite2; int i, num; op = g_new(UMLOperation, 1); op->name = NULL; attr_node = composite_find_attribute(composite, "name"); if (attr_node != NULL) op->name = data_string( attribute_first_data(attr_node) ); op->type = NULL; attr_node = composite_find_attribute(composite, "type"); if (attr_node != NULL) op->type = data_string( attribute_first_data(attr_node) ); op->visibility = FALSE; attr_node = composite_find_attribute(composite, "visibility"); if (attr_node != NULL) op->visibility = data_enum( attribute_first_data(attr_node) ); op->abstract = FALSE; attr_node = composite_find_attribute(composite, "abstract"); if (attr_node != NULL) op->abstract = data_boolean( attribute_first_data(attr_node) ); op->class_scope = FALSE; attr_node = composite_find_attribute(composite, "class_scope"); if (attr_node != NULL) op->class_scope = data_boolean( attribute_first_data(attr_node) ); op->parameters = NULL; attr_node2 = composite_find_attribute(composite, "parameters"); num = attribute_num_data(attr_node2); composite2 = attribute_first_data(attr_node2); for (i=0;i<num;i++) { param = g_new(UMLParameter, 1); param->name = NULL; attr_node = composite_find_attribute(composite2, "name"); if (attr_node != NULL) param->name = data_string( attribute_first_data(attr_node) ); param->type = NULL; attr_node = composite_find_attribute(composite2, "type"); if (attr_node != NULL) param->type = data_string( attribute_first_data(attr_node) ); param->value = NULL; attr_node = composite_find_attribute(composite2, "value"); if (attr_node != NULL) param->value = data_string( attribute_first_data(attr_node) ); param->kind = UML_UNDEF_KIND; attr_node = composite_find_attribute(composite2, "kind"); if (attr_node != NULL) param->kind = data_enum( attribute_first_data(attr_node) ); op->parameters = g_list_append(op->parameters, param); composite2 = data_next(composite2); } op->left_connection = NULL; op->right_connection = NULL; return op; }
static DiaObject * image_load(ObjectNode obj_node, int version, const char *filename) { EImage *image; Element *elem; DiaObject *obj; int i; AttributeNode attr; char *diafile_dir; Diagram *dia; GList *list; image = g_malloc0(sizeof(EImage)); elem = &image->element; obj = &elem->object; obj->type = &eimage_type; obj->ops = &eimage_ops; element_load(elem, obj_node); image->border_width = 0.1; attr = object_find_attribute(obj_node, "border_width"); if (attr != NULL) image->border_width = data_real( attribute_first_data(attr) ); image->border_color = color_black; attr = object_find_attribute(obj_node, "border_color"); if (attr != NULL) data_color(attribute_first_data(attr), &image->border_color); image->line_style = LINESTYLE_SOLID; attr = object_find_attribute(obj_node, "line_style"); if (attr != NULL) image->line_style = data_enum( attribute_first_data(attr) ); image->dashlength = DEFAULT_LINESTYLE_DASHLEN; attr = object_find_attribute(obj_node, "dashlength"); if (attr != NULL) image->dashlength = data_real(attribute_first_data(attr)); image->draw_border = TRUE; attr = object_find_attribute(obj_node, "draw_border"); if (attr != NULL) image->draw_border = data_boolean( attribute_first_data(attr) ); image->keep_aspect = TRUE; attr = object_find_attribute(obj_node, "keep_aspect"); if (attr != NULL) image->keep_aspect = data_boolean( attribute_first_data(attr) ); image->keep_orig_aspect = TRUE; attr = object_find_attribute(obj_node, "keep_orig_aspect"); if (attr != NULL) image->keep_orig_aspect = data_boolean( attribute_first_data(attr) ); attr = object_find_attribute(obj_node, "file"); if (attr != NULL) { image->file = data_filename( attribute_first_data(attr) ); } else { image->file = g_strdup(""); } attr = object_find_attribute(obj_node, "embed_id"); if (attr) { image->embed_id = dtree_conv_longname_from_xml(data_string(attribute_first_data(attr))); } else { image->embed_id = get_default_embed_id("embed_image"); } register_embed_id(image->embed_id); element_init(elem, 8, NUM_CONNECTIONS); for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = &image->connections[i]; image->connections[i].object = obj; image->connections[i].connected = NULL; } image->connections[8].flags = CP_FLAGS_MAIN; image->image = NULL; if (strcmp(image->file, "")!=0) { diafile_dir = get_directory(filename); if (g_path_is_absolute(image->file)) { /* Absolute pathname */ image->image = dia_image_load(image->file); if (image->image == NULL) { /* Not found as abs path, try in same dir as diagram. */ char *temp_string; const char *image_file_name = image->file; const char *psep; psep = strrchr(image->file, G_DIR_SEPARATOR); /* try the other G_OS as well */ if (!psep) psep = strrchr(image->file, G_DIR_SEPARATOR == '/' ? '\\' : '/'); if (psep) image_file_name = psep + 1; temp_string = g_build_filename(diafile_dir, image_file_name, NULL); image->image = dia_image_load(temp_string); if (image->image != NULL) { /* Found file in same dir as diagram. */ message_warning(_("The image file '%s' was not found in that directory.\n" "Using the file '%s' instead\n"), image->file, temp_string); g_free(image->file); image->file = temp_string; } else { g_free(temp_string); image->image = dia_image_load((char *)image_file_name); if (image->image != NULL) { char *tmp; /* Found file in current dir. */ message_warning(_("The image file '%s' was not found in that directory.\n" "Using the file '%s' instead\n"), image->file, image_file_name); tmp = image->file; image->file = g_strdup(image_file_name); g_free(tmp); } else { message_warning(_("The image file '%s' was not found.\n"), image_file_name); } } } } else { /* Relative pathname: */ char *temp_string; temp_string = g_build_filename (diafile_dir, image->file, NULL); image->image = dia_image_load(temp_string); if (image->image != NULL) { /* Found file in same dir as diagram. */ g_free(image->file); image->file = temp_string; } else { g_free(temp_string); image->image = dia_image_load(image->file); if (image->image == NULL) { /* Didn't find file in current dir. */ message_warning(_("The image file '%s' was not found.\n"), image->file); } } } g_free(diafile_dir); } /* update mtime */ { struct stat st; if (g_stat (image->file, &st) != 0) st.st_mtime = 0; image->mtime = st.st_mtime; } image_update_data(image); obj->node = NULL; list = dia_open_diagrams(); while (list != NULL) { dia = (Diagram *)list->data; if (!g_strcmp0(dia->filename,filename)) { obj->node = dtree_set_data_by_longname(DIA_DIAGRAM_DATA(dia)->dtree, image->embed_id,&image->element.object); } list = g_list_next(list); } return &image->element.object; }
static DiaObject * attribute_load(ObjectNode obj_node, int version,DiaContext *ctx) { Attribute *attribute; Element *elem; DiaObject *obj; int i; AttributeNode attr; attribute = g_malloc0(sizeof(Attribute)); elem = &attribute->element; obj = &elem->object; obj->type = &attribute_type; obj->ops = &attribute_ops; element_load(elem, obj_node, ctx); attribute->border_width = 0.1; attr = object_find_attribute(obj_node, "border_width"); if (attr != NULL) attribute->border_width = data_real(attribute_first_data(attr), ctx); attribute->border_color = color_black; attr = object_find_attribute(obj_node, "border_color"); if (attr != NULL) data_color(attribute_first_data(attr), &attribute->border_color, ctx); attribute->inner_color = color_white; attr = object_find_attribute(obj_node, "inner_color"); if (attr != NULL) data_color(attribute_first_data(attr), &attribute->inner_color, ctx); attribute->name = NULL; attr = object_find_attribute(obj_node, "name"); if (attr != NULL) attribute->name = data_string(attribute_first_data(attr), ctx); attr = object_find_attribute(obj_node, "key"); if (attr != NULL) attribute->key = data_boolean(attribute_first_data(attr), ctx); attr = object_find_attribute(obj_node, "weak_key"); if (attr != NULL) attribute->weakkey = data_boolean(attribute_first_data(attr), ctx); attr = object_find_attribute(obj_node, "derived"); if (attr != NULL) attribute->derived = data_boolean(attribute_first_data(attr), ctx); attr = object_find_attribute(obj_node, "multivalued"); if (attr != NULL) attribute->multivalue = data_boolean(attribute_first_data(attr), ctx); if (attribute->font != NULL) { /* This shouldn't happen, but doesn't hurt */ dia_font_unref(attribute->font); attribute->font = NULL; } attr = object_find_attribute (obj_node, "font"); if (attr != NULL) attribute->font = data_font (attribute_first_data (attr), ctx); attribute->font_height = FONT_HEIGHT; attr = object_find_attribute (obj_node, "font_height"); if (attr != NULL) attribute->font_height = data_real(attribute_first_data(attr), ctx); element_init(elem, 8, NUM_CONNECTIONS); for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = &attribute->connections[i]; attribute->connections[i].object = obj; attribute->connections[i].connected = NULL; } attribute->connections[8].flags = CP_FLAGS_MAIN; if (attribute->font == NULL) attribute->font = dia_font_new_from_style(DIA_FONT_MONOSPACE, attribute->font_height); attribute->name_width = dia_font_string_width(attribute->name, attribute->font, attribute->font_height); attribute_update_data(attribute); for (i=0;i<8;i++) obj->handles[i]->type = HANDLE_NON_MOVABLE; return &attribute->element.object; }
static void _data(uint8_t** buf, ujvalue* v, int i) { uint16_t n; uint8_t* sizefield; switch(v->type) { case uj_true: data_bool(buf, 1); break; case uj_false: data_bool(buf, 0); break; case uj_null: data_null(buf); break; case uj_number: switch(v->numbertype) { case uj_uint8: data_uint8(buf, v->data_as.uint8); break; case uj_int8: data_int8(buf, v->data_as.int8); break; case uj_uint16: data_uint16(buf, v->data_as.uint16); break; case uj_int16: data_int16(buf, v->data_as.int16); break; case uj_uint32: data_uint32(buf, v->data_as.uint32); break; case uj_int32: data_int32(buf, v->data_as.int32); break; case uj_uint64: data_uint64(buf, v->data_as.uint64); break; case uj_int64: data_int64(buf, v->data_as.int64); break; case uj_float: data_float(buf, v->data_as.f); break; case uj_double: data_double(buf, v->data_as.d); break; } break; case uj_string: data_string(buf, v->data_as.string); break; case uj_array: sizefield = *buf; (*buf) += 2; for (n = 0; n < array_length(v->data_as.array); n++) _data(buf, v->data_as.array->values[n], i+1); _data_size(sizefield, (uint16_t)((*buf) - sizefield - 2)); break; case uj_object: sizefield = *buf; (*buf) += 2; for (n = 0; n < v->data_as.object->size; n++) { data_string(buf, (ujstring*)v->data_as.object->data[n*2]); _data(buf, v->data_as.object->data[n*2+1], i+1); } _data_size(sizefield, (uint16_t)((*buf) - sizefield - 2)); break; } }
static Object * image_load(ObjectNode obj_node, int version, const char *filename) { Image *image; Element *elem; Object *obj; int i; AttributeNode attr; char *diafile_dir; image = g_malloc(sizeof(Image)); elem = (Element *)image; obj = (Object *)image; obj->type = &image_type; obj->ops = &image_ops; element_load(elem, obj_node); image->border_width = 0.1; attr = object_find_attribute(obj_node, "border_width"); if (attr != NULL) image->border_width = data_real( attribute_first_data(attr) ); image->border_color = color_black; attr = object_find_attribute(obj_node, "border_color"); if (attr != NULL) data_color(attribute_first_data(attr), &image->border_color); image->line_style = LINESTYLE_SOLID; attr = object_find_attribute(obj_node, "line_style"); if (attr != NULL) image->line_style = data_enum( attribute_first_data(attr) ); image->draw_border = TRUE; attr = object_find_attribute(obj_node, "draw_border"); if (attr != NULL) image->draw_border = data_boolean( attribute_first_data(attr) ); image->keep_aspect = TRUE; attr = object_find_attribute(obj_node, "keep_aspect"); if (attr != NULL) image->keep_aspect = data_boolean( attribute_first_data(attr) ); attr = object_find_attribute(obj_node, "file"); if (attr != NULL) { image->file = data_string( attribute_first_data(attr) ); } else { image->file = g_strdup(""); } element_init(elem, 8, 8); for (i=0;i<8;i++) { obj->connections[i] = &image->connections[i]; image->connections[i].object = obj; image->connections[i].connected = NULL; } image->image = NULL; if (strcmp(image->file, "")!=0) { diafile_dir = get_directory(filename); if (g_path_is_absolute(image->file)) { /* Absolute pathname */ image->image = dia_image_load(image->file); if (image->image == NULL) { /* Not found as abs path, try in same dir as diagram. */ char *temp_string; const char *image_file_name; image_file_name = strrchr(image->file, G_DIR_SEPARATOR) + 1; temp_string = g_malloc(strlen(diafile_dir) + strlen(image_file_name) +1); strcpy(temp_string, diafile_dir); strcat(temp_string, image_file_name); image->image = dia_image_load(temp_string); if (image->image != NULL) { /* Found file in same dir as diagram. */ message_warning(_("The image file '%s' was not found in that directory.\n" "Using the file '%s' instead\n"), image->file, temp_string); g_free(image->file); image->file = temp_string; } else { g_free(temp_string); image->image = dia_image_load((char *)image_file_name); if (image->image != NULL) { char *tmp; /* Found file in current dir. */ message_warning(_("The image file '%s' was not found in that directory.\n" "Using the file '%s' instead\n"), image->file, image_file_name); tmp = image->file; image->file = strdup(image_file_name); g_free(tmp); } else { message_warning(_("The image file '%s' was not found.\n"), image_file_name); } } } } else { /* Relative pathname: */ char *temp_string; temp_string = g_malloc(strlen(diafile_dir) + strlen(image->file) +1); strcpy(temp_string, diafile_dir); strcat(temp_string, image->file); image->image = dia_image_load(temp_string); if (image->image != NULL) { /* Found file in same dir as diagram. */ g_free(image->file); image->file = temp_string; } else { g_free(temp_string); image->image = dia_image_load(image->file); if (image->image == NULL) { /* Didn't find file in current dir. */ message_warning(_("The image file '%s' was not found.\n"), image->file); } } } g_free(diafile_dir); } image_update_data(image); return (Object *)image; }
static DiaObject * association_load(ObjectNode obj_node, int version, const char *filename) { Association *assoc; AttributeNode attr; DataNode composite; OrthConn *orth; DiaObject *obj; int i; /* first calls our _create() method */ obj = object_load_using_properties(&association_type, obj_node, version, filename); assoc = (Association *)obj; orth = &assoc->orth; /* ... butnot orthconn_load() */ if (version < 1) orth->autorouting = FALSE; if (version < 2) { /* vesrion 1 used to name it differently */ attr = object_find_attribute(obj_node, "autorouting"); if (attr != NULL) orth->autorouting = data_boolean(attribute_first_data(attr)); attr = object_find_attribute(obj_node, "ends"); composite = attribute_first_data(attr); for (i=0;i<2;i++) { assoc->end[i].role = NULL; attr = composite_find_attribute(composite, "role"); if (attr != NULL) { assoc->end[i].role = data_string(attribute_first_data(attr)); } if ( assoc->end[i].role != NULL && 0 == strcmp(assoc->end[i].role, "")) { g_free(assoc->end[i].role); assoc->end[i].role = NULL; } assoc->end[i].multiplicity = NULL; attr = composite_find_attribute(composite, "multiplicity"); if (attr != NULL) { assoc->end[i].multiplicity = data_string(attribute_first_data(attr)); } if ( assoc->end[i].multiplicity != NULL && 0 == strcmp(assoc->end[i].multiplicity, "")) { g_free(assoc->end[i].multiplicity); assoc->end[i].multiplicity = NULL; } assoc->end[i].arrow = FALSE; attr = composite_find_attribute(composite, "arrow"); if (attr != NULL) assoc->end[i].arrow = data_boolean(attribute_first_data(attr)); assoc->end[i].aggregate = AGGREGATE_NONE; attr = composite_find_attribute(composite, "aggregate"); if (attr != NULL) assoc->end[i].aggregate = data_enum(attribute_first_data(attr)); assoc->end[i].visibility = FALSE; attr = composite_find_attribute(composite, "visibility"); if (attr != NULL) assoc->end[i].visibility = data_enum( attribute_first_data(attr) ); assoc->end[i].text_width = 0.0; if (assoc->end[i].role != NULL) { assoc->end[i].text_width = dia_font_string_width(assoc->end[i].role, assoc_font, ASSOCIATION_FONTHEIGHT); } if (assoc->end[i].multiplicity != NULL) { assoc->end[i].text_width = MAX(assoc->end[i].text_width, dia_font_string_width(assoc->end[i].multiplicity, assoc_font, ASSOCIATION_FONTHEIGHT) ); } composite = data_next(composite); } /* derive new members state from ends */ assoc->show_direction = (assoc->direction != ASSOC_NODIR); if (assoc->end[0].aggregate == AGGREGATE_NORMAL) { assoc->assoc_type = AGGREGATE_NORMAL; assoc->direction = ASSOC_RIGHT; } else if (assoc->end[0].aggregate == AGGREGATE_COMPOSITION) { assoc->assoc_type = AGGREGATE_COMPOSITION; assoc->direction = ASSOC_RIGHT; } else if (assoc->end[1].aggregate == AGGREGATE_NORMAL) { assoc->assoc_type = AGGREGATE_NORMAL; assoc->direction = ASSOC_LEFT; } else if (assoc->end[1].aggregate == AGGREGATE_COMPOSITION) { assoc->assoc_type = AGGREGATE_COMPOSITION; assoc->direction = ASSOC_LEFT; } } /* version < 2 */ association_set_state(assoc, association_get_state(assoc)); return &assoc->orth.object; }