From 6594955e4fffca8814d968b4b73cae0af92f6400 Mon Sep 17 00:00:00 2001 From: tasn Date: Sun, 27 Feb 2011 18:09:03 +0000 Subject: [PATCH] Edje text: Added size_range to limit the font size range. This lets you limit the allowed sizes of the TEXT part (font sizes) to a specific range. This is especially useful in combination with the "fit" property. git-svn-id: http://svn.enlightenment.org/svn/e/trunk/edje@57395 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- ChangeLog | 7 +++++++ src/bin/edje_cc_handlers.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ src/lib/edje_data.c | 4 ++++ src/lib/edje_private.h | 2 ++ src/lib/edje_text.c | 12 +++++++++-- 5 files changed, 73 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index b41b55e..6f6b21e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -41,3 +41,10 @@ 2011-02-25 Jihoon Kim * Add edje_object_part_text_cursor_pos_{set,get} API + +2011-02-27 Tom Hacohen (TAsn) + + * Added size_range property to TEXT parts in edje files. + This lets you limit the size of the font that will be used. + Especially useful when using fit. + diff --git a/src/bin/edje_cc_handlers.c b/src/bin/edje_cc_handlers.c index 5836704..0c97d59 100644 --- a/src/bin/edje_cc_handlers.c +++ b/src/bin/edje_cc_handlers.c @@ -198,6 +198,7 @@ static void st_collections_group_parts_part_description_text_font(void); static void st_collections_group_parts_part_description_text_style(void); static void st_collections_group_parts_part_description_text_repch(void); static void st_collections_group_parts_part_description_text_size(void); +static void st_collections_group_parts_part_description_text_size_range(void); static void st_collections_group_parts_part_description_text_fit(void); static void st_collections_group_parts_part_description_text_min(void); static void st_collections_group_parts_part_description_text_max(void); @@ -449,6 +450,7 @@ New_Statement_Handler statement_handlers[] = {"collections.group.parts.part.description.text.style", st_collections_group_parts_part_description_text_style}, {"collections.group.parts.part.description.text.repch", st_collections_group_parts_part_description_text_repch}, {"collections.group.parts.part.description.text.size", st_collections_group_parts_part_description_text_size}, + {"collections.group.parts.part.description.text.size_range", st_collections_group_parts_part_description_text_size_range}, {"collections.group.parts.part.description.text.fit", st_collections_group_parts_part_description_text_fit}, {"collections.group.parts.part.description.text.min", st_collections_group_parts_part_description_text_min}, {"collections.group.parts.part.description.text.max", st_collections_group_parts_part_description_text_max}, @@ -5345,6 +5347,54 @@ st_collections_group_parts_part_description_text_size(void) @page edcref @property + size_range + @parameters + [font min size in points (pt)] [font max size in points (pt)] + @effect + Sets the allowed font size for the text part. Setting min and max to 0 + means we won't restrict the sizing (default). + @endproperty + @since 1.1.0 +*/ +static void +st_collections_group_parts_part_description_text_size_range(void) +{ + Edje_Part_Collection *pc; + Edje_Part *ep; + Edje_Part_Description_Text *ed; + + check_arg_count(2); + + pc = eina_list_data_get(eina_list_last(edje_collections)); + ep = pc->parts[pc->parts_count - 1]; + + if ((ep->type != EDJE_PART_TYPE_TEXT) && + (ep->type != EDJE_PART_TYPE_TEXTBLOCK)) + { + ERR("%s: Error. parse error %s:%i. " + "text attributes in non-TEXT part.", + progname, file_in, line - 1); + exit(-1); + } + + ed = (Edje_Part_Description_Text*) ep->default_desc; + if (ep->other.desc_count) ed = (Edje_Part_Description_Text*) ep->other.desc[ep->other.desc_count - 1]; + + ed->text.size_range_min = parse_int_range(0, 0, 255); + ed->text.size_range_max = parse_int_range(1, 0, 255); + if (ed->text.size_range_min > ed->text.size_range_max) + { + ERR("%s: Error. parse error %s:%i. " + "min size is bigger than max size.", + progname, file_in, line - 1); + exit(-1); + } +} + +/** + @page edcref + + @property fit @parameters [horizontal] [vertical] diff --git a/src/lib/edje_data.c b/src/lib/edje_data.c index b10c988..23881b7 100644 --- a/src/lib/edje_data.c +++ b/src/lib/edje_data.c @@ -563,6 +563,8 @@ _edje_edd_init(void) EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_text, Edje_Part_Description_Text, "text.text_class", text.text_class, EET_T_STRING); EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_text, Edje_Part_Description_Text, "text.style", text.style, EET_T_STRING); EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_text, Edje_Part_Description_Text, "text.font", text.font, EET_T_STRING); + EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_text, Edje_Part_Description_Text, "text.size_range_min", text.size_range_min, EET_T_INT); + EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_text, Edje_Part_Description_Text, "text.size_range_max", text.size_range_max, EET_T_INT); EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_text, Edje_Part_Description_Text, "text.repch", text.repch, EET_T_STRING); EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_text, Edje_Part_Description_Text, "text.size", text.size, EET_T_INT); EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_text, Edje_Part_Description_Text, "text.fit_x", text.fit_x, EET_T_UCHAR); @@ -593,6 +595,8 @@ _edje_edd_init(void) EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_textblock, Edje_Part_Description_Text, "text.font", text.font, EET_T_STRING); EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_textblock, Edje_Part_Description_Text, "text.repch", text.repch, EET_T_STRING); EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_textblock, Edje_Part_Description_Text, "text.size", text.size, EET_T_INT); + EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_textblock, Edje_Part_Description_Text, "text.size_range_min", text.size_range_min, EET_T_INT); + EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_textblock, Edje_Part_Description_Text, "text.size_range_max", text.size_range_max, EET_T_INT); EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_textblock, Edje_Part_Description_Text, "text.fit_x", text.fit_x, EET_T_UCHAR); EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_textblock, Edje_Part_Description_Text, "text.fit_y", text.fit_y, EET_T_UCHAR); EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_textblock, Edje_Part_Description_Text, "text.min_x", text.min_x, EET_T_UCHAR); diff --git a/src/lib/edje_private.h b/src/lib/edje_private.h index 16e20e9..f2236be 100644 --- a/src/lib/edje_private.h +++ b/src/lib/edje_private.h @@ -862,6 +862,8 @@ struct _Edje_Part_Description_Spec_Text unsigned char min_y; /* if text size should be part min size */ unsigned char max_x; /* if text size should be part max size */ unsigned char max_y; /* if text size should be part max size */ + int size_range_min; + int size_range_max; /* -1 means, no bound. */ }; struct _Edje_Part_Description_Spec_Box diff --git a/src/lib/edje_text.c b/src/lib/edje_text.c index 655288f..ba9ecb8 100644 --- a/src/lib/edje_text.c +++ b/src/lib/edje_text.c @@ -539,9 +539,17 @@ _edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep, size = current - 1; } } - if (size < 1) size = 1; - if (!chosen_desc->text.fit_x) + /* Make sure the size is in range */ + if (size < 1) + size = 1; + else if ((size > chosen_desc->text.size_range_max) && + (chosen_desc->text.size_range_max > 0)) + size = chosen_desc->text.size_range_max; + else if (size < chosen_desc->text.size_range_min) + size = chosen_desc->text.size_range_min; + + /* Handle ellipsis */ { if (inlined_font) evas_object_text_font_source_set(ep->object, ed->path); else evas_object_text_font_source_set(ep->object, NULL); -- 2.7.4