aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Hirt <hirt.danny@gmail.com>2017-07-29 08:52:27 +0300
committerDaniel Hirt <hirt.danny@gmail.com>2017-08-14 20:20:38 +0300
commita81b0f04f6a7a7cfe65d264546014fa75f4f0dc5 (patch)
treec18deea40beb1d5b59b80aab1e6ae6121c58bdea
parentTextblock: unify glow/outline, glow2/shadow (diff)
downloadefl-a81b0f04f6a7a7cfe65d264546014fa75f4f0dc5.tar.gz
Edje calc: support "text { font, align.x, ellipsis }" for TEXTBLOCK
@feature
-rw-r--r--src/lib/edje/edje_calc.c170
1 files changed, 170 insertions, 0 deletions
diff --git a/src/lib/edje/edje_calc.c b/src/lib/edje/edje_calc.c
index 4ec2d0288a..6d8dca5f6c 100644
--- a/src/lib/edje/edje_calc.c
+++ b/src/lib/edje/edje_calc.c
@@ -1471,6 +1471,29 @@ _edje_part_recalc_single_textblock_scale_range_adjust(Edje_Part_Description_Text
return scale;
}
+
+/**
+ * @internal
+ * Creates and returns a string of the format: "#RRGGBBAA"
+ * From given rgba integer values.
+ *
+ * @param[in] r The Red value - NOT NULL.
+ * @param[in] g The Green value - NOT NULL.
+ * @param[in] b The Blue value - NOT NULL.
+ * @param[in] a The Alpha value - NOT NULL.
+ */
+char *
+_edje_common_color_to_format(unsigned char r, unsigned char g,
+ unsigned char b, unsigned char a)
+{
+ char *ret;
+ Eina_Strbuf *str = eina_strbuf_new();
+ eina_strbuf_append_printf(str, "%02x%02x%02x%02x",
+ r, g, b, a);
+ ret = eina_strbuf_string_steal(str);
+ return ret;
+}
+
/*
* Legacy function for min/max calculation of textblock part.
* It can't calculate min/max properly in many cases.
@@ -1835,6 +1858,100 @@ _edje_part_recalc_single_textblock_min_max_calc(Edje_Real_Part *ep,
}
static void
+_edje_part_recalc_textblock_font_get(Edje *ed, Edje_Real_Part *ep,
+ Edje_Part_Description_Text *chosen_desc,
+ const char *text,
+ const char **ret_font_source,
+ const char **ret_font, int *ret_size)
+
+{
+ Edje_Real_Part *source, *text_source;
+ const char *font;
+ int size;
+ Eina_Bool inlined_font = EINA_FALSE;
+ const char *font_source = NULL;
+ char *sfont, *font2;
+
+ sfont = font2 = NULL;
+
+ text_source = ep->typedata.text->text_source;
+ source = ep->typedata.text->source;
+
+ if (source)
+ font = _edje_text_class_font_get(ed,
+ _edje_real_part_text_source_description_get(ep,
+ &source), &size, &sfont);
+ else
+ font = _edje_text_class_font_get(ed, chosen_desc, &size, &sfont);
+
+ if (!font) font = "";
+
+ if (text_source)
+ {
+ if (text_source->typedata.text->text)
+ {
+ text = text_source->typedata.text->text;
+ }
+ }
+ else
+ {
+ if (ep->typedata.text->text) text = ep->typedata.text->text;
+ }
+
+ if (source)
+ {
+ if (source->typedata.text->font) font = source->typedata.text->font;
+ if (source->typedata.text->size > 0) size = source->typedata.text->size;
+ }
+ else
+ {
+ if (ep->typedata.text->font) font = ep->typedata.text->font;
+ if (ep->typedata.text->size > 0) size = ep->typedata.text->size;
+ }
+ if (!text) text = "";
+
+ if (ed->file->fonts)
+ {
+ Edje_Font_Directory_Entry *fnt;
+
+ fnt = eina_hash_find(ed->file->fonts, font);
+
+ if (fnt)
+ {
+ size_t len = strlen(font) + sizeof("edje/fonts/") + 1;
+ font2 = alloca(len);
+ sprintf(font2, "edje/fonts/%s", font);
+ font = font2;
+ inlined_font = 1;
+ font2 = NULL; // so it is not freed at the end of the function
+ }
+ }
+ if (inlined_font)
+ {
+ font_source = ed->path;
+ }
+
+ if ((_edje_fontset_append) && (font))
+ {
+ font2 = malloc(strlen(font) + 1 + strlen(_edje_fontset_append) + 1);
+ if (font2)
+ {
+ strcpy(font2, font);
+ strcat(font2, ",");
+ strcat(font2, _edje_fontset_append);
+ font = font2; //font2 needs to be freed at the end of the
+ // function.
+ }
+ }
+ if (ret_font) *ret_font = font;
+ if (ret_size) *ret_size = size;
+ if (ret_font_source) *ret_font_source = font_source;
+
+ if (font2) free(font2);
+ if (sfont) free(sfont);
+}
+
+static void
_edje_part_recalc_single_textblock(FLOAT_T sc,
Edje *ed,
Edje_Real_Part *ep,
@@ -1978,8 +2095,61 @@ _edje_part_recalc_single_textblock(FLOAT_T sc,
if (stl)
{
+ const char *font, *font_source;
+ int size;
+
+ _edje_part_recalc_textblock_font_get(ed, ep, chosen_desc,
+ text, &font_source, &font, &size);
+
+ // Set main style
+ Eina_Strbuf *sstr;
+ FLOAT_T align_x = params->type.text->align.x;
+ FLOAT_T ellip = params->type.text->ellipsis;
+
if (evas_object_textblock_style_get(ep->object) != stl->style)
evas_object_textblock_style_set(ep->object, stl->style);
+
+ // Overlay with text parameters using one more style
+ if (font || (size > 0) ||
+ font_source ||
+ (params->type.text->align.x >= 0) ||
+ (params->type.text->ellipsis >= 0))
+ {
+ sstr = eina_strbuf_new();
+ eina_strbuf_append(sstr, "DEFAULT='");
+
+ if (font && *font)
+ {
+ eina_strbuf_append_printf(sstr,
+ "font=%s ", font);
+ }
+
+ if (size > 0)
+ {
+ eina_strbuf_append_printf(sstr,
+ "font_size=%d ", size);
+ }
+
+ if (font_source)
+ {
+ eina_strbuf_append_printf(sstr,
+ "font_source=%s ", font_source);
+ }
+ if (align_x >= FROM_INT(0))
+ {
+ eina_strbuf_append_printf(sstr,
+ "align=%f ", align_x);
+ }
+ if (ellip >= FROM_INT(0.1))
+ {
+ eina_strbuf_append_printf(sstr,
+ "ellipsis=%f ", ellip);
+ }
+ eina_strbuf_append(sstr, "'");
+ efl_canvas_text_style_set(ep->object, "__edje_text",
+ eina_strbuf_string_get(sstr));
+ eina_strbuf_free(sstr);
+ }
// FIXME: need to account for editing
if (ep->part->entry_mode > EDJE_ENTRY_EDIT_MODE_NONE)
{