static void prop_dialog_fill(PropDialog *dialog, GList *objects, gboolean is_default) { const PropDescription *pdesc; GPtrArray *props; g_return_if_fail(objects_comply_with_stdprop(objects)); dialog->objects = g_list_copy(objects); dialog->copies = object_copy_list(objects); pdesc = object_list_get_prop_descriptions(objects, PROP_UNION); if (!pdesc) return; if (is_default) props = prop_list_from_descs(pdesc,pdtpp_is_visible_default); else props = prop_list_from_descs(pdesc,pdtpp_is_visible); if (!props) return; _prop_list_extend_for_meta (props); dialog->props = props; object_list_get_props(objects, props); prop_dialog_add_properties(dialog, props); }
DiaObject * create_standard_bezierline(int num_points, BezPoint *points, Arrow *end_arrow, Arrow *start_arrow) { DiaObjectType *otype = object_get_type("Standard - BezierLine"); DiaObject *new_obj; Handle *h1, *h2; BezierCreateData bcd; GPtrArray *props; if (otype == NULL){ message_error(_("Can't find standard object")); return NULL; } bcd.num_points = num_points; bcd.points = points; new_obj = otype->ops->create(NULL, &bcd, &h1, &h2); props = prop_list_from_descs(create_line_prop_descs,pdtpp_true); g_assert(props->len == 2); if (start_arrow != NULL) ((ArrowProperty *)g_ptr_array_index(props, 0))->arrow_data = *start_arrow; if (end_arrow != NULL) ((ArrowProperty *)g_ptr_array_index(props, 1))->arrow_data = *end_arrow; new_obj->ops->set_props(new_obj, props); prop_list_free(props); return new_obj; }
/*! Match and possibly modify all the given object's properties. */ static GPtrArray * _match_all_props (DiaObject *obj, const SearchData *sd, const gchar *replacement) { GPtrArray *all_plist = NULL; GPtrArray *matched_plist = NULL; const PropDescription *desc; guint pnum; if (!obj) return NULL; desc = object_get_prop_descriptions (obj); if (!desc) return NULL; all_plist = prop_list_from_descs (desc, pdtpp_true); if (!all_plist) return NULL; /* Step though all object properties. * Along the way, construct a list of matching properties (or * replaced properties). */ for (pnum = 0; pnum < all_plist->len; ++pnum) { Property *prop = g_ptr_array_index (all_plist, pnum); gboolean is_match = FALSE; const gchar *prop_name; if (!prop || !prop->name) continue; /* This extra step seems to be necessary to populate the property data. */ prop_name = prop->name; prop->ops->free (prop); prop = object_prop_by_name (obj, prop_name); is_match = _match_prop (obj, sd, replacement, prop); if (!is_match) { prop->ops->free (prop); continue; } /* We have a match. */ if (!matched_plist) { /* First time. */ matched_plist = prop_list_from_single (prop); } else { /* FIXME: do we realy want a replace all here? */ /* Subsequent finds. */ GPtrArray *append_plist; append_plist = prop_list_from_single (prop); prop_list_add_list (matched_plist, append_plist); prop_list_free (append_plist); } } /* Continue stepping through all object properties. */ return matched_plist; }
static GPtrArray * make_posision_and_size_prop_list (void) { GPtrArray *props; props = prop_list_from_descs(_prop_descs,pdtpp_true); return props; }
static void fig_simple_properties(DiaObject *obj, int line_style, float dash_length, int thickness, int pen_color, int fill_color, int area_fill, DiaContext *ctx) { GPtrArray *props = prop_list_from_descs(xfig_simple_prop_descs_line, pdtpp_true); RealProperty *rprop; ColorProperty *cprop; g_assert(props->len == 2); rprop = g_ptr_array_index(props,0); rprop->real_data = thickness/FIG_ALT_UNIT; cprop = g_ptr_array_index(props,1); cprop->color_data = fig_color(pen_color, ctx); if (line_style != -1) { LinestyleProperty *lsprop = (LinestyleProperty *)make_new_prop("line_style", PROP_TYPE_LINESTYLE, PROP_FLAG_DONT_SAVE); lsprop->dash = dash_length/FIG_ALT_UNIT; lsprop->style = fig_line_style_to_dia(line_style, ctx); g_ptr_array_add(props,lsprop); } if (area_fill == -1) { BoolProperty *bprop = (BoolProperty *)make_new_prop("show_background", PROP_TYPE_BOOL,PROP_FLAG_DONT_SAVE); bprop->bool_data = FALSE; g_ptr_array_add(props,bprop); } else { ColorProperty *cprop = (ColorProperty *)make_new_prop("fill_colour", PROP_TYPE_COLOUR, PROP_FLAG_DONT_SAVE); cprop->color_data = fig_area_fill_color(area_fill, fill_color, ctx); g_ptr_array_add(props,cprop); } obj->ops->set_props(obj, props); prop_list_free(props); }
void object_save_props(DiaObject *obj, ObjectNode obj_node, DiaContext *ctx) { GPtrArray *props; g_return_if_fail(obj != NULL); g_return_if_fail(obj_node != NULL); g_return_if_fail(object_complies_with_stdprop(obj)); props = prop_list_from_descs(object_get_prop_descriptions(obj), pdtpp_do_save); obj->ops->get_props(obj, props); prop_list_save(props,obj_node,ctx); prop_list_free(props); }
void object_load_props(DiaObject *obj, ObjectNode obj_node, DiaContext *ctx) { GPtrArray *props; g_return_if_fail(obj != NULL); g_return_if_fail(obj_node != NULL); g_return_if_fail(object_complies_with_stdprop(obj)); props = prop_list_from_descs(object_get_prop_descriptions(obj), pdtpp_do_load); if (!prop_list_load(props,obj_node, ctx)) { /* context already has the message */ } obj->ops->set_props(obj, props); prop_list_free(props); }
static GPtrArray *make_element_props(real xpos, real ypos, real width, real height) { GPtrArray *props; PointProperty *pprop; RealProperty *rprop; props = prop_list_from_descs(create_element_prop_descs,pdtpp_true); g_assert(props->len == 3); pprop = g_ptr_array_index(props,0); pprop->point_data.x = xpos; pprop->point_data.y = ypos; rprop = g_ptr_array_index(props,1); rprop->real_data = width; rprop = g_ptr_array_index(props,2); rprop->real_data = height; return props; }
/** * dia_object_default_create: * @param type The objects type * @param startpoint The left upper corner * @param user_data * @param handle1 * @param handle2 * @return A newly created object. * * Create an object respecting defaults if available */ DiaObject * dia_object_default_create (const DiaObjectType *type, Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { const DiaObject *def_obj; DiaObject *obj; g_return_val_if_fail (type != NULL, NULL); /* don't use dia_object_default_get() as it would insert the object into the hashtable (store defaults without being asked for it) */ def_obj = g_hash_table_lookup (defaults_hash, type->name); if (def_obj && def_obj->ops->describe_props) { /* copy properties to new object, but keep position */ // factory_debug_to_log(g_strdup_printf(factory_utf8("拖入对像def_obj,名字:%s.\n"),type->name)); obj = type->ops->create (startpoint, user_data, handle1, handle2); if (obj) { GPtrArray *props = prop_list_from_descs ( object_get_prop_descriptions(def_obj), pdtpp_standard_or_defaults); // factory_debug_to_log(factory_utf8("拖入对像def_obj->ops->get_props(def_obj, props)\n")); def_obj->ops->get_props(def_obj, props); // factory_debug_to_log(factory_utf8("拖入对像obj->ops->set_props(obj, props)\n")); obj->ops->set_props(obj, props); obj->ops->move (obj, startpoint); prop_list_free(props); } } else { // factory_debug_to_log(g_strdup_printf(factory_utf8("拖入对像def_obj==NULL,名字:%s.\n"),type->name)); obj = type->ops->create (startpoint, user_data, handle1, handle2); } return obj; }
DiaObject * create_standard_arc(real x1, real y1, real x2, real y2, real distance, Arrow *end_arrow, Arrow *start_arrow) { DiaObjectType *otype = object_get_type("Standard - Arc"); DiaObject *new_obj; Handle *h1, *h2; Point p1, p2; GPtrArray *props; if (otype == NULL){ message_error(_("Can't find standard object")); return NULL; } p1.x = x1; p1.y = y1; p2.x = x2; p2.y = y2; new_obj = otype->ops->create(&p1, otype->default_user_data, &h1, &h2); new_obj->ops->move_handle(new_obj, h2, &p2, NULL, HANDLE_MOVE_USER_FINAL,0); props = prop_list_from_descs(create_arc_prop_descs,pdtpp_true); g_assert(props->len == 3); ((RealProperty *)g_ptr_array_index(props,0))->real_data = distance; if (start_arrow != NULL) ((ArrowProperty *)g_ptr_array_index(props, 1))->arrow_data = *start_arrow; if (end_arrow != NULL) ((ArrowProperty *)g_ptr_array_index(props, 2))->arrow_data = *end_arrow; new_obj->ops->set_props(new_obj, props); prop_list_free(props); return new_obj; }
void object_copy_props(DiaObject *dest, const DiaObject *src, gboolean is_default) { GPtrArray *props; g_return_if_fail(src != NULL); g_return_if_fail(dest != NULL); g_return_if_fail(strcmp(src->type->name,dest->type->name)==0); g_return_if_fail(src->ops == dest->ops); g_return_if_fail(object_complies_with_stdprop(src)); g_return_if_fail(object_complies_with_stdprop(dest)); props = prop_list_from_descs(object_get_prop_descriptions(src), (is_default?pdtpp_do_save_no_standard_default: pdtpp_do_save)); src->ops->get_props((DiaObject *)src, props); /* FIXME: really should make get_props' first argument a (const DiaObject *) */ dest->ops->set_props(dest, props); prop_list_free(props); }
static void _prop_list_extend_for_meta (GPtrArray *props) { static PropDescription extras[] = { PROP_STD_NOTEBOOK_BEGIN, PROP_NOTEBOOK_PAGE("general_page",PROP_FLAG_DONT_MERGE,N_("General")), PROP_NOTEBOOK_PAGE("meta_page",0,N_("Meta")), { "meta", PROP_TYPE_DICT, PROP_FLAG_VISIBLE|PROP_FLAG_SELF_ONLY, "", ""}, PROP_STD_NOTEBOOK_END, {NULL} }; /* Some objects have no properties in case of defaults */ Property *p = props->len > 0 ? g_ptr_array_index(props,0) : NULL; GPtrArray *pex = prop_list_from_descs(extras,pdtpp_is_visible); if (!p || strcmp (p->descr->type, PROP_TYPE_NOTEBOOK_BEGIN) != 0) { int i, olen = props->len; /* wrap everything into a first notebook page */ g_ptr_array_set_size (props, olen + 2); /* make room for 2 at the beginning */ for (i = olen - 1; i >= 0; --i) g_ptr_array_index (props, i + 2) = g_ptr_array_index (props, i); g_ptr_array_index (props, 0) = g_ptr_array_index (pex, 0); g_ptr_array_index (props, 1) = g_ptr_array_index (pex, 1); } else { p = g_ptr_array_index (props, props->len - 1); g_assert (strcmp (p->descr->type, PROP_TYPE_NOTEBOOK_END) == 0); /* drop the end, we'll add it again below */ g_ptr_array_set_size (props, props->len - 1); } g_ptr_array_add (props, g_ptr_array_index (pex, 2)); g_ptr_array_add (props, g_ptr_array_index (pex, 3)); g_ptr_array_add (props, g_ptr_array_index (pex, 4)); /* free the array, but not the reused segments */ g_ptr_array_free (pex, FALSE); }
DiaObject * create_standard_image(real xpos, real ypos, real width, real height, char *file) { DiaObjectType *otype = object_get_type("Standard - Image"); DiaObject *new_obj; Handle *h1, *h2; Point point; GPtrArray *props; StringProperty *sprop; if (otype == NULL){ message_error(_("Can't find standard object")); return NULL; } point.x = xpos; point.y = ypos; new_obj = otype->ops->create(&point, otype->default_user_data, &h1, &h2); props = make_element_props(xpos,ypos,width,height); new_obj->ops->set_props(new_obj, props); prop_list_free(props); props = prop_list_from_descs(create_file_prop_descs,pdtpp_true); g_assert(props->len == 1); sprop = g_ptr_array_index(props,0); g_free(sprop->string_data); sprop->string_data = g_strdup(file); new_obj->ops->set_props(new_obj, props); prop_list_free(props); return new_obj; }
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; }
static DiaObject * read_entity_text_dxf(FILE *filedxf, DxfData *data, DiagramData *dia) { RGB_t color = { 0, }; /* text data */ Point location = {0, 0}; real height = text_scale * coord_scale * measure_scale; real y_offset = 0; Alignment textalignment = ALIGN_LEFT; char *textvalue = NULL, *textp; DiaObjectType *otype = object_get_type("Standard - Text"); Handle *h1, *h2; DiaObject *text_obj; Color text_colour; TextProperty *tprop; GPtrArray *props; Layer *layer = dia->active_layer; do { if (read_dxf_codes(filedxf, data) == FALSE) { return( NULL ); } switch (data->code) { case 1: textvalue = g_strdup(data->value); textp = textvalue; /* FIXME - poor tab to space converter */ do { if( textp[0] == '^' && textp[1] == 'I' ) { textp[0] = ' '; textp[1] = ' '; textp++; } } while( *(++textp) != '\0' ); /*printf( "Found text: %s\n", textvalue );*/ break; case 8: layer = layer_find_by_name(data->value, dia); color = pal_get_rgb (_dxf_color_get_by_layer (layer)); break; case 10: location.x = g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale; /*printf( "Found text location x: %f\n", location.x );*/ break; case 11: location.x = g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale; /*printf( "Found text location x: %f\n", location.x );*/ break; case 20: location.y = (-1)*g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale; /*printf( "Found text location y: %f\n", location.y );*/ break; case 21: location.y = (-1)*g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale; /*location.y = (-1)*g_ascii_strtod(data->value, NULL) / text_scale;*/ /*printf( "Found text location y: %f\n", location.y );*/ break; case 40: height = g_ascii_strtod(data->value, NULL) * text_scale * coord_scale * measure_scale; /*printf( "text height %f\n", height );*/ break; case 62: color = pal_get_rgb (atoi(data->value)); break; case 72: switch(atoi(data->value)) { case 0: textalignment = ALIGN_LEFT; break; case 1: textalignment = ALIGN_CENTER; break; case 2: textalignment = ALIGN_RIGHT; break; case 3: /* FIXME - it's not clear what these are */ break; case 4: /* FIXME - it's not clear what these are */ break; case 5: /* FIXME - it's not clear what these are */ break; } break; case 73: switch(atoi(data->value)) { case 0: case 1: /* FIXME - not really the same vertical alignment */ /* 0 = baseline */ /* 1 = bottom */ y_offset = 0; break; case 2: /* 2 = middle */ y_offset = 0.5; break; case 3: /* 3 = top */ y_offset = 1; break; } break; } } while(data->code != 0); location.y += y_offset * height; _color_init_from_rgb (&text_colour, color); text_obj = otype->ops->create(&location, otype->default_user_data, &h1, &h2); props = prop_list_from_descs(dxf_text_prop_descs,pdtpp_true); g_assert(props->len == 1); tprop = g_ptr_array_index(props,0); g_free(tprop->text_data); tprop->text_data = textvalue; tprop->attr.alignment = textalignment; tprop->attr.position.x = location.x; tprop->attr.position.y = location.y; attributes_get_default_font(&tprop->attr.font, &tprop->attr.height); tprop->attr.color = text_colour; tprop->attr.height = height; text_obj->ops->set_props(text_obj, props); prop_list_free(props); if (layer) layer_add_object(layer, text_obj); else return text_obj; return NULL; /* don't add it twice */ }