From 14bb2d4cf7ba071ef4c314367550bb49c6b9870f Mon Sep 17 00:00:00 2001 From: Bernd Jendrissek Date: Sun, 15 Apr 2018 03:41:05 +0200 Subject: [PATCH] Use a text object as context for calculating size. --- gschem/src/o_misc.c | 4 ++-- libgeda/include/libgeda/prototype.h | 4 ++-- libgeda/src/o_text_basic.c | 43 ++++++++++++++++++------------------- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/gschem/src/o_misc.c b/gschem/src/o_misc.c index 22d2924f0..c2808ffd5 100644 --- a/gschem/src/o_misc.c +++ b/gschem/src/o_misc.c @@ -640,14 +640,14 @@ int o_edit_find_text(GSCHEM_TOPLEVEL *w_current, OBJECT * o_list, char *stext, if (!skiplast) { a_zoom(w_current, page, ZOOM_FULL, DONTCARE, A_PAN_DONT_REDRAW); text_screen_height = - SCREENabs(page, o_text_height(str, o_current->text->size)); + SCREENabs(page, o_text_height(o_current, str)); /* this code will zoom/pan till the text screen height is about */ /* 50 pixels high, perhaps a future enhancement will be to make */ /* this number configurable */ while (text_screen_height < 50) { a_zoom(w_current, page, ZOOM_IN, DONTCARE, A_PAN_DONT_REDRAW); text_screen_height = - SCREENabs(page, o_text_height(str, o_current->text->size)); + SCREENabs(page, o_text_height(o_current, str)); } a_pan_general(w_current, page, o_current->text->x, o_current->text->y, diff --git a/libgeda/include/libgeda/prototype.h b/libgeda/include/libgeda/prototype.h index 3bd1e84cd..b7156e383 100644 --- a/libgeda/include/libgeda/prototype.h +++ b/libgeda/include/libgeda/prototype.h @@ -315,8 +315,8 @@ void o_text_init(void); void o_text_print_set(void); OBJECT *o_text_load_font(TOPLEVEL *toplevel, gunichar needed_char); int o_text_num_lines(const char *string); -int o_text_height(const char *string, int size); -int o_text_width(TOPLEVEL *toplevel, char const *string, int size); +int o_text_height(OBJECT *obj, const char *string); +int o_text_width(TOPLEVEL *toplevel, OBJECT *obj, char const *string); OBJECT *o_text_new(TOPLEVEL *toplevel, char type, int color, int x, int y, int alignment, int angle, const char *string, int size, int visibility, int show_name_value); void o_text_set_info_font(char buf[]); void o_text_recreate(OBJECT *o_current); diff --git a/libgeda/src/o_text_basic.c b/libgeda/src/o_text_basic.c index bfc470aa1..645e602ac 100644 --- a/libgeda/src/o_text_basic.c +++ b/libgeda/src/o_text_basic.c @@ -386,11 +386,11 @@ int o_text_num_lines(const char *string) * on it's text \a size. The number of lines and the spacing * between the lines are taken into account. * + * \param [in] obj The text object that will contain the string. * \param [in] string the text string - * \param [in] size the text size of the character * \return the total height of the text string */ -int o_text_height(const char *string, int size) +int o_text_height(OBJECT *obj, const char *string) { int line_count = 0; @@ -405,22 +405,23 @@ int o_text_height(const char *string, int size) /* which represents a character which is 2 pts high */ /* So size has to be divided in half */ /* and it's added the LINE_SPACING*character_height of each line */ - return(26*size/2*(1+LINE_SPACING*(line_count-1))); + return(26*obj->text->size/2*(1+LINE_SPACING*(line_count-1))); } /*! \brief calculate the width of a text * \par Function Description * This function calculates the width of a text \a string - * depending on the text \a size and the width of the individual + * depending on the text size and the width of the individual * characters that are in the text string. * * \param [in] toplevel The TOPLEVEL object + * \param [in] obj The text object that will contain the string. * \param [in] string The text string - * \param [in] size The text size * \return the total width of the text. */ -int o_text_width(TOPLEVEL *toplevel, char const *string, int size) +int o_text_width(TOPLEVEL *toplevel, OBJECT *obj, char const *string) { + int size = obj->text->size/2; int width=0, max_width=0; int size_of_tab_in_coord; OBJECT *o_font_set; @@ -545,9 +546,9 @@ static void o_text_create_string(TOPLEVEL *toplevel, OBJECT *object, /* now read in the chars */ temp_tail = toplevel->page_current->object_tail; - text_height = o_text_height(string, size); - char_height = o_text_height("a", size); - text_width = o_text_width(toplevel, string, size/2); + text_height = o_text_height(object, string); + char_height = o_text_height(object, "a"); + text_width = o_text_width(toplevel, object, string); switch(angle) { case(0): @@ -565,7 +566,7 @@ static void o_text_create_string(TOPLEVEL *toplevel, OBJECT *object, } if (angle == 0 || angle == 180) { - y = y - o_text_height("a", size) + text_height; + y = y - o_text_height(object, "a") + text_height; switch(alignment) { @@ -625,7 +626,7 @@ static void o_text_create_string(TOPLEVEL *toplevel, OBJECT *object, break; } } else { /* angle is 90 or 270 */ - x = x + sign*(o_text_height("a", size) - text_height); + x = x + sign*(o_text_height(object, "a") - text_height); switch(alignment) { @@ -694,7 +695,7 @@ static void o_text_create_string(TOPLEVEL *toplevel, OBJECT *object, } if (GEDA_DEBUG) { - printf("width: %d\n", o_text_width(toplevel, string, size/2)); + printf("width: %d\n", o_text_width(toplevel, object, string)); printf("1 %d %d\n", x_offset, y_offset); } @@ -824,7 +825,7 @@ static void o_text_create_string(TOPLEVEL *toplevel, OBJECT *object, gint rel_char_coord; /* Get the maximum tab width's in coordinates */ size_of_tab_in_coord = (tab_in_chars * - o_text_width(toplevel, TAB_CHAR_MODEL, size/2)); + o_text_width(toplevel, object, TAB_CHAR_MODEL)); switch (angle) { case 0: @@ -1023,9 +1024,9 @@ OBJECT *o_text_new(TOPLEVEL *toplevel, o_text_create_string(toplevel, new_node, text->disp_string, size, color, x, y, alignment, angle); - new_node->text->displayed_width = o_text_width(toplevel, - text->disp_string, size/2); - new_node->text->displayed_height = o_text_height(text->disp_string, size); + new_node->text->displayed_width = o_text_width(toplevel, new_node, + text->disp_string); + new_node->text->displayed_height = o_text_height(new_node, text->disp_string); } else { new_node->text->displayed_width = 0; new_node->text->displayed_height = 0; @@ -1385,11 +1386,9 @@ void o_text_recreate(OBJECT *o_current) text->angle); o_complex_set_saved_color_only(o_current, o_current->saved_color); - text->displayed_width = o_text_width (text->toplevel, - text->disp_string, - text->size/2); - text->displayed_height = o_text_height (text->disp_string, - text->size); + text->displayed_width = o_text_width(text->toplevel, o_current, + text->disp_string); + text->displayed_height = o_text_height(o_current, text->disp_string); } else { /* make sure list is truly free */ text->displayed_width = 0; @@ -1684,7 +1683,7 @@ void o_text_print(TOPLEVEL *toplevel, FILE *fp, OBJECT *o_current, break; } - char_height = o_text_height("a", o_current->text->size); + char_height = o_text_height(o_current, "a"); fprintf(fp,"%s %f [",centering_control,(float)(char_height*LINE_SPACING)); /* split the line at each newline and print them */ -- 2.11.4.GIT