1 #include "evas_common.h" /* Includes evas_bidi_utils stuff. */
2 #include "evas_private.h"
5 #define ENFN obj->layer->evas->engine.func
6 #define ENDT obj->layer->evas->engine.data.output
8 /* private magic number for text objects */
9 static const char o_type[] = "textgrid";
11 /* private struct for line object internal data */
12 typedef struct _Evas_Object_Textgrid Evas_Object_Textgrid;
13 typedef struct _Evas_Object_Textgrid_Cell Evas_Object_Textgrid_Cell;
14 typedef struct _Evas_Object_Textgrid_Color Evas_Object_Textgrid_Color;
16 typedef struct _Evas_Object_Textgrid_Row Evas_Object_Textgrid_Row;
17 typedef struct _Evas_Object_Textgrid_Rect Evas_Object_Textgrid_Rect;
18 typedef struct _Evas_Object_Textgrid_Text Evas_Object_Textgrid_Text;
19 typedef struct _Evas_Object_Textgrid_Line Evas_Object_Textgrid_Line;
21 struct _Evas_Object_Textgrid
29 Evas_Object_Textgrid_Row *rows;
30 Evas_Textgrid_Cell *cells;
32 const char *font_source;
33 const char *font_name;
34 Evas_Font_Size font_size;
35 Evas_Font_Description *font_description;
37 Eina_Array *palette_standard;
38 Eina_Array *palette_extended;
45 unsigned int changed : 1;
46 unsigned int core_change : 1;
47 unsigned int row_change : 1;
48 unsigned int pal_change : 1;
51 struct _Evas_Object_Textgrid_Color
53 unsigned char r, g, b, a;
56 struct _Evas_Object_Textgrid_Row
58 int ch1, ch2; // change region, -1 == none
59 int rects_num, texts_num, lines_num;
60 int rects_alloc, texts_alloc, lines_alloc;
61 Evas_Object_Textgrid_Rect *rects; // rects + colors
62 Evas_Object_Textgrid_Text *texts; // text
63 Evas_Object_Textgrid_Line *lines; // underlines, strikethroughs
66 struct _Evas_Object_Textgrid_Rect
68 unsigned char r, g, b, a;
72 struct _Evas_Object_Textgrid_Text
74 unsigned char r, g, b, a;
76 Evas_Text_Props text_props;
79 struct _Evas_Object_Textgrid_Line
81 unsigned char r, g, b, a;
85 /* private methods for textgrid objects */
86 static void evas_object_textgrid_init(Evas_Object *obj);
87 static void *evas_object_textgrid_new(void);
88 static void evas_object_textgrid_render(Evas_Object *obj, void *output, void *context, void *surface, int x, int y);
89 static void evas_object_textgrid_free(Evas_Object *obj);
90 static void evas_object_textgrid_render_pre(Evas_Object *obj);
91 static void evas_object_textgrid_render_post(Evas_Object *obj);
93 static unsigned int evas_object_textgrid_id_get(Evas_Object *obj);
94 static unsigned int evas_object_textgrid_visual_id_get(Evas_Object *obj);
95 static void *evas_object_textgrid_engine_data_get(Evas_Object *obj);
97 static int evas_object_textgrid_is_opaque(Evas_Object *obj);
98 static int evas_object_textgrid_was_opaque(Evas_Object *obj);
100 static void evas_object_textgrid_scale_update(Evas_Object *obj);
102 static const Evas_Object_Func object_func =
104 /* methods (compulsory) */
105 evas_object_textgrid_free,
106 evas_object_textgrid_render,
107 evas_object_textgrid_render_pre,
108 evas_object_textgrid_render_post,
109 evas_object_textgrid_id_get,
110 evas_object_textgrid_visual_id_get,
111 evas_object_textgrid_engine_data_get,
112 /* these are optional. NULL = nothing */
117 evas_object_textgrid_is_opaque,
118 evas_object_textgrid_was_opaque,
122 evas_object_textgrid_scale_update,
128 EVAS_MEMPOOL(_mp_obj);
130 /* all nice and private */
132 evas_object_textgrid_init(Evas_Object *obj)
134 /* alloc textgrid ob, setup methods and default values */
135 obj->object_data = evas_object_textgrid_new();
136 /* set up default settings for this kind of object */
137 obj->cur.color.r = 255;
138 obj->cur.color.g = 255;
139 obj->cur.color.b = 255;
140 obj->cur.color.a = 255;
141 obj->cur.geometry.x = 0;
142 obj->cur.geometry.y = 0;
143 obj->cur.geometry.w = 0;
144 obj->cur.geometry.h = 0;
146 /* set up object-specific settings */
147 obj->prev = obj->cur;
148 /* set up methods (compulsory) */
149 obj->func = &object_func;
154 evas_object_textgrid_new(void)
156 Evas_Object_Textgrid *o;
158 /* FIXME: using evas mempool like text ? */
159 EVAS_MEMPOOL_INIT(_mp_obj, "evas_object_textgrid", Evas_Object_Textgrid, 4, NULL);
160 o = EVAS_MEMPOOL_ALLOC(_mp_obj, Evas_Object_Textgrid);
161 EVAS_MEMPOOL_PREP(_mp_obj, o, Evas_Object_Textgrid);
162 o->magic = MAGIC_OBJ_TEXTGRID;
164 o->cur.palette_standard = eina_array_new(16);
165 o->cur.palette_extended = eina_array_new(16);
170 evas_object_textgrid_row_clear(Evas_Object_Textgrid_Row *r)
183 for (i = 0; i < r->texts_num; i++)
184 evas_common_text_props_content_unref(&(r->texts[i].text_props));
200 evas_object_textgrid_rows_clear(Evas_Object *obj)
202 Evas_Object_Textgrid *o;
205 o = (Evas_Object_Textgrid *)(obj->object_data);
206 if (!o->cur.rows) return;
207 for (i = 0; i < o->cur.h; i++)
209 evas_object_textgrid_row_clear(&(o->cur.rows[i]));
210 o->cur.rows[i].ch1 = 0;
211 o->cur.rows[i].ch2 = o->cur.w - 1;
216 evas_object_textgrid_free(Evas_Object *obj)
218 Evas_Object_Textgrid *o;
221 /* frees private object data. very simple here */
222 o = (Evas_Object_Textgrid *)(obj->object_data);
223 MAGIC_CHECK(o, Evas_Object_Textgrid, MAGIC_OBJ_TEXTGRID);
228 evas_object_textgrid_rows_clear(obj);
229 if (o->cur.rows) free(o->cur.rows);
230 if (o->cur.font_name) eina_stringshare_del(o->cur.font_name);
231 if (o->cur.font_source) eina_stringshare_del(o->cur.font_source);
232 if (o->cur.font_description) evas_font_desc_unref(o->cur.font_description);
233 if (o->font) evas_font_free(obj->layer->evas, o->font);
234 if (o->cur.cells) free(o->cur.cells);
235 for (i = 0; i < eina_array_count(o->cur.palette_standard); i++)
236 free(eina_array_data_get(o->cur.palette_standard, i));
237 eina_array_free(o->cur.palette_standard);
238 for (i = 0; i < eina_array_count(o->cur.palette_extended); i++)
239 free(eina_array_data_get(o->cur.palette_extended, i));
240 eina_array_free(o->cur.palette_extended);
242 /* FIXME: using evas mempool like text ? */
243 EVAS_MEMPOOL_FREE(_mp_obj, o);
248 evas_object_textgrid_row_rect_append(Evas_Object_Textgrid_Row *row, int x, int w, int r, int g, int b, int a)
251 if (row->rects_num > row->rects_alloc)
253 Evas_Object_Textgrid_Rect *t;
255 row->rects_alloc += 8; // dont expect many rects per line
256 t = realloc(row->rects, sizeof(Evas_Object_Textgrid_Rect) * row->rects_alloc);
264 row->rects[row->rects_num - 1].x = x;
265 row->rects[row->rects_num - 1].w = w;
266 row->rects[row->rects_num - 1].r = r;
267 row->rects[row->rects_num - 1].g = g;
268 row->rects[row->rects_num - 1].b = b;
269 row->rects[row->rects_num - 1].a = a;
273 evas_object_textgrid_row_text_append(Evas_Object_Textgrid_Row *row, Evas_Object *obj, Evas_Object_Textgrid *o, int x, Eina_Unicode codepoint, int r, int g, int b, int a)
275 Evas_Script_Type script;
276 Evas_Font_Instance *script_fi = NULL;
277 Evas_Font_Instance *cur_fi = NULL;
280 if (row->texts_num > row->texts_alloc)
282 Evas_Object_Textgrid_Text *t;
284 row->texts_alloc += 32; // expect more text per line
285 t = realloc(row->texts, sizeof(Evas_Object_Textgrid_Text) * row->texts_alloc);
294 script = evas_common_language_script_type_get(&codepoint, 1);
295 ENFN->font_run_end_get(ENDT, o->font, &script_fi, &cur_fi,
296 script, &codepoint, 1);
297 memset(&(row->texts[row->texts_num - 1].text_props), 0,
298 sizeof(Evas_Text_Props));
299 evas_common_text_props_script_set
300 (&(row->texts[row->texts_num - 1].text_props), script);
301 ENFN->font_text_props_info_create
302 (ENDT, script_fi, &codepoint,
303 &(row->texts[row->texts_num - 1].text_props), NULL, 0, 1,
304 EVAS_TEXT_PROPS_MODE_NONE);
305 row->texts[row->texts_num - 1].x = x;
306 row->texts[row->texts_num - 1].r = r;
307 row->texts[row->texts_num - 1].g = g;
308 row->texts[row->texts_num - 1].b = b;
309 row->texts[row->texts_num - 1].a = a;
313 evas_object_textgrid_row_line_append(Evas_Object_Textgrid_Row *row, int x, int w, int y, int r, int g, int b, int a)
316 if (row->lines_num > row->lines_alloc)
318 Evas_Object_Textgrid_Line *t;
320 row->lines_alloc += 8; // dont expect many lines per line
321 t = realloc(row->lines, sizeof(Evas_Object_Textgrid_Line) * row->lines_alloc);
329 row->lines[row->lines_num - 1].x = x;
330 row->lines[row->lines_num - 1].w = w;
331 row->lines[row->lines_num - 1].y = y;
332 row->lines[row->lines_num - 1].r = r;
333 row->lines[row->lines_num - 1].g = g;
334 row->lines[row->lines_num - 1].b = b;
335 row->lines[row->lines_num - 1].a = a;
339 evas_object_textgrid_render(Evas_Object *obj, void *output, void *context, void *surface, int x, int y)
341 Evas_Object_Textgrid *o;
342 Evas_Textgrid_Cell *cells;
343 Evas_Object_Textgrid_Color *c;
345 int xx, yy, xp, yp, w, h, ww, hh;
346 int rr = 0, rg = 0, rb = 0, ra = 0, rx = 0, rw = 0, run;
348 /* render object to surface with context, and offxet by x,y */
349 o = (Evas_Object_Textgrid *)(obj->object_data);
350 ENFN->context_multiplier_unset(output, context);
351 ENFN->context_render_op_set(output, context, obj->cur.render_op);
353 if (!(o->font) || (!o->cur.cells)) return;
355 w = o->cur.char_width;
356 h = o->cur.char_height;
357 ww = obj->cur.geometry.w;
358 hh = obj->cur.geometry.h;
360 // generate row data from cells (and only deal with rows that updated)
361 for (yy = 0, cells = o->cur.cells; yy < o->cur.h; yy++)
363 Evas_Object_Textgrid_Row *row = &(o->cur.rows[yy]);
373 xp = obj->cur.geometry.x;
374 for (xx = 0; xx < o->cur.w; xx++, cells++)
376 if (cells->bg_extended) palette = o->cur.palette_extended;
377 else palette = o->cur.palette_standard;
378 c = eina_array_data_get(palette, cells->bg);
379 if ((c) && (c->a > 0))
391 else if ((c->r != rr) || (c->g != rg) ||
392 (c->b != rb) || (c->a != ra))
394 evas_object_textgrid_row_rect_append(row, rx, rw,
408 evas_object_textgrid_row_rect_append(row, rx, rw,
411 if (cells->codepoint > 0)
413 if (cells->fg_extended) palette = o->cur.palette_extended;
414 else palette = o->cur.palette_standard;
415 c = eina_array_data_get(palette, cells->fg);
416 if ((c) && (c->a > 0))
418 evas_object_textgrid_row_text_append(row, obj, o, xp,
420 c->r, c->g, c->b, c->a);
421 // XXX: underlines and strikethroughs dont get
422 // merghed into horizontal runs like bg rects above
423 if (cells->underline)
424 evas_object_textgrid_row_line_append(row, rx, rw,
427 if (cells->strikethrough)
428 evas_object_textgrid_row_line_append(row, rx, rw,
429 ((3 * o->max_ascent) / 4),
438 evas_object_textgrid_row_rect_append(row, rx, rw,
442 yp = obj->cur.geometry.y + y;
443 // draw the row data that is generated from the cell array
444 for (yy = 0, cells = o->cur.cells; yy < o->cur.h; yy++)
446 Evas_Object_Textgrid_Row *row = &(o->cur.rows[yy]);
448 xp = obj->cur.geometry.x + x;
449 for (xx = 0; xx < row->rects_num; xx++)
451 ENFN->context_color_set(output, context,
452 row->rects[xx].r, row->rects[xx].g,
453 row->rects[xx].b, row->rects[xx].a);
454 ENFN->rectangle_draw(output, context, surface,
455 xp + row->rects[xx].x, yp,
456 row->rects[xx].w, h);
458 for (xx = 0; xx < row->texts_num; xx++)
460 ENFN->context_color_set(output, context,
461 row->texts[xx].r, row->texts[xx].g,
462 row->texts[xx].b, row->texts[xx].a);
463 ENFN->font_draw(output, context, surface, o->font,
464 xp + row->texts[xx].x, yp + o->max_ascent,
465 ww, hh, ww, hh, &(row->texts[xx].text_props));
467 for (xx = 0; xx < row->lines_num; xx++)
469 ENFN->context_color_set(output, context,
470 row->lines[xx].r, row->lines[xx].g,
471 row->lines[xx].b, row->lines[xx].a);
472 ENFN->rectangle_draw(output, context, surface,
473 xp + row->lines[xx].x, yp + row->lines[xx].y,
474 row->lines[xx].w, h);
481 evas_object_textgrid_render_pre(Evas_Object *obj)
483 Evas_Object_Textgrid *o;
486 /* dont pre-render the obj twice! */
487 if (obj->pre_render_done) return;
488 obj->pre_render_done = 1;
489 /* pre-render phase. this does anything an object needs to do just before */
490 /* rendering. this could mean loading the image data, retrieving it from */
491 /* elsewhere, decoding video etc. */
492 /* then when this is done the object needs to figure if it changed and */
493 /* if so what and where and add thr appropriate redraw rectangles */
494 o = (Evas_Object_Textgrid *)(obj->object_data);
495 /* if someone is clipping this obj - go calculate the clipper */
496 if (obj->cur.clipper)
498 if (obj->cur.cache.clip.dirty)
499 evas_object_clip_recalc(obj->cur.clipper);
500 obj->cur.clipper->func->render_pre(obj->cur.clipper);
502 /* now figure what changed and add draw rects */
503 /* if it just became visible or invisible */
504 is_v = evas_object_is_visible(obj);
505 was_v = evas_object_was_visible(obj);
508 evas_object_render_pre_visible_change(&obj->layer->evas->clip_changes, obj, is_v, was_v);
511 if (obj->changed_map)
513 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes,
517 /* its not visible - we accounted for it appearing or not so just abort */
518 if (!is_v) goto done;
519 /* clipper changed this is in addition to anything else for obj */
520 evas_object_render_pre_clipper_change(&obj->layer->evas->clip_changes, obj);
521 /* if we restacked (layer or just within a layer) and dont clip anyone */
524 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, obj);
527 /* if it changed color */
528 if ((obj->cur.color.r != obj->prev.color.r) ||
529 (obj->cur.color.g != obj->prev.color.g) ||
530 (obj->cur.color.b != obj->prev.color.b) ||
531 (obj->cur.color.a != obj->prev.color.a))
533 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, obj);
536 /* if it changed geometry - and obviously not visibility or color */
537 /* calculate differences since we have a constant color fill */
538 /* we really only need to update the differences */
539 if ((obj->cur.geometry.x != obj->prev.geometry.x) ||
540 (obj->cur.geometry.y != obj->prev.geometry.y) ||
541 (obj->cur.geometry.w != obj->prev.geometry.w) ||
542 (obj->cur.geometry.h != obj->prev.geometry.h))
544 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, obj);
547 if (obj->cur.render_op != obj->prev.render_op)
549 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, obj);
552 if (obj->cur.scale != obj->prev.scale)
554 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, obj);
562 if ((o->cur.h != o->prev.h) ||
563 (o->cur.w != o->prev.w) ||
564 (o->cur.font_size != o->prev.font_size) ||
565 ((o->cur.font_name) && (o->prev.font_name) &&
566 (strcmp(o->cur.font_name, o->prev.font_name))) ||
567 ((o->cur.font_name) && (!o->prev.font_name)) ||
568 ((!o->cur.font_name) && (o->prev.font_name)))
570 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes,
579 if (eina_array_count(o->cur.palette_standard) != eina_array_count(o->prev.palette_standard))
581 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, obj);
584 for (i = 0; i < eina_array_count(o->cur.palette_standard); i++)
586 Evas_Object_Textgrid_Color *c_cur;
587 Evas_Object_Textgrid_Color *c_prev;
589 c_cur = eina_array_data_get(o->cur.palette_standard, i);
590 c_prev = eina_array_data_get(o->prev.palette_standard, i);
591 if ((c_cur->a != c_prev->a) ||
592 (c_cur->r != c_prev->r) ||
593 (c_cur->g != c_prev->g) ||
594 (c_cur->b != c_prev->b))
596 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, obj);
600 if (eina_array_count(o->cur.palette_extended) != eina_array_count(o->prev.palette_extended))
602 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, obj);
605 for (i = 0; i < eina_array_count(o->cur.palette_extended); i++)
607 Evas_Object_Textgrid_Color *c_cur;
608 Evas_Object_Textgrid_Color *c_prev;
610 c_cur = eina_array_data_get(o->cur.palette_extended, i);
611 c_prev = eina_array_data_get(o->prev.palette_extended, i);
612 if ((c_cur->a != c_prev->a) ||
613 (c_cur->r != c_prev->r) ||
614 (c_cur->g != c_prev->g) ||
615 (c_cur->b != c_prev->b))
617 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, obj);
626 for (i = 0; i < o->cur.h; i++)
628 Evas_Object_Textgrid_Row *r = &(o->cur.rows[i]);
630 evas_add_rect(&obj->layer->evas->clip_changes,
631 obj->cur.geometry.x +
632 (r->ch1 * o->cur.char_width),
633 obj->cur.geometry.y +
634 (i * o->cur.char_height),
635 (r->ch2 - r->ch1 + 1) * o->cur.char_width,
645 evas_object_render_pre_effect_updates(&obj->layer->evas->clip_changes, obj, is_v, was_v);
649 evas_object_textgrid_render_post(Evas_Object *obj)
651 Evas_Object_Textgrid *o;
653 /* this moves the current data to the previous state parts of the object */
654 /* in whatever way is safest for the object. also if we don't need object */
655 /* data anymore we can free it if the object deems this is a good idea */
656 o = (Evas_Object_Textgrid *)(obj->object_data);
657 /* remove those pesky changes */
658 evas_object_clip_changes_clean(obj);
659 /* move cur to prev safely for object data */
660 obj->prev = obj->cur;
666 evas_object_textgrid_id_get(Evas_Object *obj)
668 Evas_Object_Textgrid *o;
670 o = (Evas_Object_Textgrid *)(obj->object_data);
672 return MAGIC_OBJ_TEXTGRID;
676 evas_object_textgrid_visual_id_get(Evas_Object *obj)
678 Evas_Object_Textgrid *o;
680 o = (Evas_Object_Textgrid *)(obj->object_data);
682 return MAGIC_OBJ_SHAPE;
686 evas_object_textgrid_engine_data_get(Evas_Object *obj)
688 Evas_Object_Textgrid *o;
690 o = (Evas_Object_Textgrid *)(obj->object_data);
696 evas_object_textgrid_is_opaque(Evas_Object *obj __UNUSED__)
698 /* this returns 1 if the internal object data implies that the object is
699 currently fully opaque over the entire gradient it occupies */
704 evas_object_textgrid_was_opaque(Evas_Object *obj __UNUSED__)
706 /* this returns 1 if the internal object data implies that the object was
707 currently fully opaque over the entire gradient it occupies */
712 evas_object_textgrid_scale_update(Evas_Object *obj)
714 Evas_Object_Textgrid *o;
716 const char *font_name;
718 o = (Evas_Object_Textgrid *)(obj->object_data);
719 font_name = eina_stringshare_add(o->cur.font_name);
720 font_size = o->cur.font_size;
721 if (o->cur.font_name) eina_stringshare_del(o->cur.font_name);
722 o->cur.font_name = NULL;
723 o->prev.font_name = NULL;
724 o->cur.font_size = 0;
725 o->prev.font_size = 0;
726 evas_object_textgrid_font_set(obj, font_name, font_size);
729 /********************* LOCAL *********************/
731 /********************* API *********************/
734 evas_object_textgrid_add(Evas *e)
738 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
742 obj = evas_object_new(e);
743 evas_object_textgrid_init(obj);
744 evas_object_inject(obj, e);
749 evas_object_textgrid_size_set(Evas_Object *obj, int w, int h)
751 Evas_Object_Textgrid *o;
754 if ((h <= 0) || (w <= 0)) return;
756 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
759 o = (Evas_Object_Textgrid *)(obj->object_data);
760 MAGIC_CHECK(o, Evas_Object_Textgrid, MAGIC_OBJ_TEXTGRID);
764 if ((o->cur.w == w) && (o->cur.h == h)) return;
766 evas_object_textgrid_rows_clear(obj);
777 o->cur.cells = calloc(w * h, sizeof(Evas_Textgrid_Cell));
778 if (!o->cur.cells) return;
779 o->cur.rows = calloc(h, sizeof(Evas_Object_Textgrid_Row));
786 for (i = 0; i < h; i++)
788 o->cur.rows[i].ch1 = 0;
789 o->cur.rows[i].ch2 = w - 1;
795 evas_object_change(obj);
799 evas_object_textgrid_size_get(const Evas_Object *obj, int *w, int *h)
801 Evas_Object_Textgrid *o;
806 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
809 o = (Evas_Object_Textgrid *)(obj->object_data);
810 MAGIC_CHECK(o, Evas_Object_Textgrid, MAGIC_OBJ_TEXTGRID);
814 if (w) *w = o->cur.w;
815 if (h) *h = o->cur.h;
819 evas_object_textgrid_font_source_set(Evas_Object *obj, const char *font_source)
821 Evas_Object_Textgrid *o;
823 if ((!font_source) || (!*font_source))
826 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
829 o = (Evas_Object_Textgrid *)(obj->object_data);
830 MAGIC_CHECK(o, Evas_Object_Textgrid, MAGIC_OBJ_TEXTGRID);
834 if ((o->cur.font_source) && (font_source) &&
835 (!strcmp(o->cur.font_source, font_source))) return;
837 eina_stringshare_replace(&o->cur.font_source, font_source);
840 evas_object_change(obj);
844 evas_object_textgrid_font_source_get(const Evas_Object *obj)
846 Evas_Object_Textgrid *o;
848 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
851 o = (Evas_Object_Textgrid *)(obj->object_data);
852 MAGIC_CHECK(o, Evas_Object_Textgrid, MAGIC_OBJ_TEXTGRID);
856 return o->cur.font_source;
860 evas_object_textgrid_font_set(Evas_Object *obj, const char *font_name, Evas_Font_Size font_size)
862 Evas_Object_Textgrid *o;
863 int is, was = 0, pass = 0, freeze = 0;
864 Evas_Font_Description *font_description;
866 if ((!font_name) || (!*font_name) || (font_size <= 0))
869 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
872 o = (Evas_Object_Textgrid *)(obj->object_data);
873 MAGIC_CHECK(o, Evas_Object_Textgrid, MAGIC_OBJ_TEXTGRID);
877 font_description = evas_font_desc_new();
878 evas_font_name_parse(font_description, font_name);
879 if (o->cur.font_description &&
880 !evas_font_desc_cmp(font_description, o->cur.font_description) &&
881 (font_size == o->cur.font_size))
883 evas_font_desc_unref(font_description);
887 if (o->cur.font_description) evas_font_desc_unref(o->cur.font_description);
888 o->cur.font_description = font_description;
890 o->cur.font_size = font_size;
891 eina_stringshare_replace(&o->cur.font_name, font_name);
892 o->prev.font_name = NULL;
894 if (obj->layer->evas->events_frozen <= 0)
896 pass = evas_event_passes_through(obj);
897 freeze = evas_event_freezes_through(obj);
898 if ((!pass) && (!freeze))
899 was = evas_object_is_in_output_rect(obj,
900 obj->layer->evas->pointer.x,
901 obj->layer->evas->pointer.y,
908 evas_font_free(obj->layer->evas, o->font);
912 o->font = evas_font_load(obj->layer->evas, o->cur.font_description,
914 (int)(((double) o->cur.font_size) *
918 Eina_Unicode W[2] = { 'W', 0 };
919 Evas_Font_Instance *script_fi = NULL;
920 Evas_Font_Instance *cur_fi = NULL;
921 Evas_Text_Props text_props;
922 Evas_Script_Type script;
924 script = evas_common_language_script_type_get(W, 1);
925 ENFN->font_run_end_get(ENDT, o->font, &script_fi, &cur_fi,
927 memset(&text_props, 0, sizeof(Evas_Text_Props));
928 evas_common_text_props_script_set(&text_props, script);
929 ENFN->font_text_props_info_create(ENDT, script_fi, W, &text_props,
931 EVAS_TEXT_PROPS_MODE_NONE);
932 ENFN->font_string_size_get(ENDT, o->font, &text_props,
933 &o->cur.char_width, &o->cur.char_height);
934 o->max_ascent = ENFN->font_max_ascent_get(ENDT, o->font);
935 evas_common_text_props_content_unref(&text_props);
939 obj->cur.geometry.w = 0;
940 obj->cur.geometry.h = 0;
945 evas_object_change(obj);
946 evas_object_clip_dirty(obj);
947 evas_object_coords_recalc(obj);
948 if (obj->layer->evas->events_frozen <= 0)
950 if ((!pass) && (!freeze))
952 is = evas_object_is_in_output_rect(obj,
953 obj->layer->evas->pointer.x,
954 obj->layer->evas->pointer.y,
956 if ((is ^ was) && obj->cur.visible)
957 evas_event_feed_mouse_move(obj->layer->evas,
958 obj->layer->evas->pointer.x,
959 obj->layer->evas->pointer.y,
960 obj->layer->evas->last_timestamp,
964 evas_object_inform_call_resize(obj);
967 evas_object_textgrid_rows_clear(obj);
968 evas_object_change(obj);
972 evas_object_textgrid_font_get(const Evas_Object *obj, const char **font_name, Evas_Font_Size *font_size)
974 Evas_Object_Textgrid *o;
976 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
977 if (font_name) *font_name = "";
978 if (font_size) *font_size = 0;
981 o = (Evas_Object_Textgrid *)(obj->object_data);
982 MAGIC_CHECK(o, Evas_Object_Textgrid, MAGIC_OBJ_TEXTGRID);
983 if (font_name) *font_name = "";
984 if (font_size) *font_size = 0;
988 if (font_name) *font_name = o->cur.font_name;
989 if (font_size) *font_size = o->cur.font_size;
993 evas_object_textgrid_cell_size_get(const Evas_Object *obj, int *width, int *height)
995 Evas_Object_Textgrid *o;
997 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
998 if (width) *width = 0;
999 if (height) *height = 0;
1002 o = (Evas_Object_Textgrid *)(obj->object_data);
1003 MAGIC_CHECK(o, Evas_Object_Textgrid, MAGIC_OBJ_TEXTGRID);
1004 if (width) *width = 0;
1005 if (height) *height = 0;
1009 if (width) *width = o->cur.char_width;
1010 if (height) *height = o->cur.char_height;
1014 evas_object_textgrid_palette_set(Evas_Object *obj, Evas_Textgrid_Palette pal, int idx, int r, int g, int b, int a)
1016 Evas_Object_Textgrid *o;
1017 Eina_Array *palette;
1018 Evas_Object_Textgrid_Color *color, *c;
1021 if ((idx < 0) || (idx > 255)) return;
1023 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1026 o = (Evas_Object_Textgrid *)(obj->object_data);
1027 MAGIC_CHECK(o, Evas_Object_Textgrid, MAGIC_OBJ_TEXTGRID);
1031 if (a > 255) a = 255; if (a < 0) a = 0;
1032 if (r > 255) r = 255; if (r < 0) r = 0;
1033 if (g > 255) g = 255; if (g < 0) g = 0;
1034 if (b > 255) b = 255; if (b < 0) b = 0;
1038 ERR("Evas only handles pre multiplied colors!");
1043 ERR("Evas only handles pre multiplied colors!");
1048 ERR("Evas only handles pre multiplied colors!");
1053 case EVAS_TEXTGRID_PALETTE_STANDARD:
1054 palette = o->cur.palette_standard;
1056 case EVAS_TEXTGRID_PALETTE_EXTENDED:
1057 palette = o->cur.palette_extended;
1063 color = malloc(sizeof(Evas_Object_Textgrid_Color));
1071 count = eina_array_count(palette);
1072 if (idx < count) eina_array_data_set(palette, idx, color);
1073 else if (idx == count) eina_array_push(palette, color);
1076 for (i = count; i < idx; i++)
1078 c = calloc(1, sizeof(Evas_Object_Textgrid_Color));
1081 ERR("Evas can not allocate memory");
1084 eina_array_push(palette, c);
1086 eina_array_push(palette, color);
1090 evas_object_textgrid_rows_clear(obj);
1091 evas_object_change(obj);
1095 evas_object_textgrid_palette_get(const Evas_Object *obj, Evas_Textgrid_Palette pal, int idx, int *r, int *g, int *b, int *a)
1097 Evas_Object_Textgrid *o;
1098 Eina_Array *palette;
1099 Evas_Object_Textgrid_Color *color;
1101 if (idx < 0) return;
1103 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1110 o = (Evas_Object_Textgrid *)(obj->object_data);
1111 MAGIC_CHECK(o, Evas_Object_Textgrid, MAGIC_OBJ_TEXTGRID);
1121 case EVAS_TEXTGRID_PALETTE_STANDARD:
1122 palette = o->cur.palette_standard;
1124 case EVAS_TEXTGRID_PALETTE_EXTENDED:
1125 palette = o->cur.palette_extended;
1131 if (idx >= (int)eina_array_count(palette)) return;
1132 color = eina_array_data_get(palette, idx);
1135 if (a) *a = color->a;
1136 if (r) *r = color->r;
1137 if (g) *g = color->g;
1138 if (b) *b = color->b;
1143 evas_object_textgrid_supported_font_styles_set(Evas_Object *obj, Evas_Textgrid_Font_Style styles)
1145 Evas_Object_Textgrid *o;
1147 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1150 o = (Evas_Object_Textgrid *)(obj->object_data);
1151 MAGIC_CHECK(o, Evas_Object_Textgrid, MAGIC_OBJ_TEXTGRID);
1159 evas_object_change(obj);
1163 EAPI Evas_Textgrid_Font_Style
1164 evas_object_textgrid_supported_font_styles_get(const Evas_Object *obj)
1166 Evas_Object_Textgrid *o;
1168 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1169 return EVAS_TEXTGRID_FONT_STYLE_NORMAL;
1171 o = (Evas_Object_Textgrid *)(obj->object_data);
1172 MAGIC_CHECK(o, Evas_Object_Textgrid, MAGIC_OBJ_TEXTGRID);
1173 return EVAS_TEXTGRID_FONT_STYLE_NORMAL;
1181 evas_object_textgrid_cellrow_set(Evas_Object *obj, int y, const Evas_Textgrid_Cell *row)
1183 Evas_Object_Textgrid *o;
1187 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1190 o = (Evas_Object_Textgrid *)(obj->object_data);
1191 MAGIC_CHECK(o, Evas_Object_Textgrid, MAGIC_OBJ_TEXTGRID);
1195 if ((y < 0) || (y >= o->cur.h)) return;
1198 EAPI Evas_Textgrid_Cell *
1199 evas_object_textgrid_cellrow_get(const Evas_Object *obj, int y)
1201 Evas_Object_Textgrid *o;
1203 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1206 o = (Evas_Object_Textgrid *)(obj->object_data);
1207 MAGIC_CHECK(o, Evas_Object_Textgrid, MAGIC_OBJ_TEXTGRID);
1211 if ((y < 0) || (y >= o->cur.h)) return NULL;
1213 return o->cur.cells + (y * o->cur.w);
1217 evas_object_textgrid_update_add(Evas_Object *obj, int x, int y, int w, int h)
1219 Evas_Object_Textgrid *o;
1222 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1225 o = (Evas_Object_Textgrid *)(obj->object_data);
1226 MAGIC_CHECK(o, Evas_Object_Textgrid, MAGIC_OBJ_TEXTGRID);
1230 RECTS_CLIP_TO_RECT(x, y, w, h, 0, 0, o->cur.w, o->cur.h);
1231 if ((w <= 0) || (h <= 0)) return;
1234 for (i = 0; i < h; i++)
1236 Evas_Object_Textgrid_Row *r = &(o->cur.rows[y + i]);
1240 evas_object_textgrid_row_clear(r);
1246 if (x < r->ch1) r->ch1 = x;
1247 if (x2 > r->ch2) r->ch2 = x2;
1252 evas_object_change(obj);