Content Fit Enhancment

Summary:
Allow user to get currently used font size when Text Fitting is enabled.

previously, the user can not know what is current font size, he only specifies font size ranges, and the algorithm internally decides suitable font size.
with this change, the user has the ability to know the font size, that the fitting algorithm has picked

Reviewers: raster

Subscribers: raster, cedric, #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D12288
This commit is contained in:
Ali Alzyod 2021-08-30 21:13:38 +03:00
parent dfd0bafdcc
commit 3a5d04b125
3 changed files with 35 additions and 3 deletions

View File

@ -320,7 +320,8 @@ enum BUTTON{
BUTTON_ARRAY = 4,
BUTTON_CONTENT = 5,
BUTTON_STYLE = 6,
BUTTON_ALL = BUTTON_STYLE+1,
BUTTON_SIZE = 7,
BUTTON_ALL = BUTTON_SIZE+1,
};
char* BUTTON_STR[BUTTON_ALL] ={
@ -331,6 +332,7 @@ char* BUTTON_STR[BUTTON_ALL] ={
"ARRAY",
"CONTENT",
"STYLE",
"Get Size",
};
char *contents[] = {
@ -430,6 +432,8 @@ char * get_fit_status(Eo * textblock)
static char status[0xFFF];
unsigned int options,min,max,step,size_array[256];
size_t size_array_len;
int current_fitting_fontsize = 0;
current_fitting_fontsize = evas_textblock_fit_font_size_get(textblock);
evas_textblock_fit_options_get(textblock,&options);
evas_textblock_fit_size_range_get(textblock,&min,&max);
evas_textblock_fit_step_size_get(textblock,&step);
@ -464,8 +468,13 @@ char * get_fit_status(Eo * textblock)
sprintf(status + strlen(status)," ]");
sprintf(status + strlen(status),"<br>");
sprintf(status + strlen(status),"%s",styles_names[app->i_style]);
sprintf(status + strlen(status),"%s<br>",styles_names[app->i_style]);
if (current_fitting_fontsize == -1) {
sprintf(status + strlen(status),"Current Font Size = No Fitting");
}
else {
sprintf(status + strlen(status),"Current Font Size = %d", current_fitting_fontsize);
}
return status;

View File

@ -431,6 +431,7 @@ struct _TEXT_FIT_CONTENT_CONFIG
unsigned int min_font_size,max_font_size;
unsigned int step_size;
unsigned int *p_size_array;
int font_size;
size_t size_list_length;
Eina_Size2D size_cache[256+1]; /** used hash font sizes 1-255 */
Eina_Size2D last_size;
@ -17881,6 +17882,7 @@ int fit_text_block(Evas_Object *eo_obj)
/*Lower bound founded, subtract one to move for nearest value*/
fc->last_size_index = MAX(l-1, 0);
fit_style_update(eo_obj,fc->p_size_array[fc->last_size_index],(fc->last_size_index != 0) && fc->options != TEXTBLOCK_FIT_MODE_HEIGHT ,EINA_FALSE);
fc->font_size = fc->p_size_array[fc->last_size_index];
fit_finish_fitting(eo_obj);
}
}
@ -18052,6 +18054,20 @@ int compareUINT(const void * a, const void * b)
else return 0;
}
EVAS_API int evas_textblock_fit_font_size_get(Evas_Object *obj){
EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EVAS_ERROR_INVALID_PARAM);
Efl_Canvas_Textblock_Data *o = efl_data_scope_get(obj, MY_CLASS);
TEXT_FIT_CONTENT_CONFIG *fc = &o->fit_content_config;
if (fc->options == TEXTBLOCK_FIT_MODE_NONE)
{
return -1;
}
else
{
return fc->font_size;
}
}
EVAS_API int evas_textblock_fit_size_array_set(Evas_Object *obj, const unsigned int *p_size_array, size_t size_array_len)
{
int n_ret = EVAS_ERROR_SUCCESS;

View File

@ -1143,6 +1143,13 @@ EVAS_API int evas_textblock_fit_size_array_get(const Evas_Object *obj, unsigned
*/
EVAS_API int evas_textblock_fit_size_array_set(Evas_Object *obj, const unsigned int *p_size_array, size_t size_array_len);
/** Get the object fitting font size that is currently used.
*
* @param obj The textblock object.
* @return Returns current used font size for fitting, or -1 if there is no fitting.
* @since 1.26
*/
EVAS_API int evas_textblock_fit_font_size_get(Evas_Object *obj);