d145a0afa7c24bd44d067113e89a4c9dcd67fdfe
[platform/upstream/elementary.git] / src / lib / efl_ui_textpath.c
1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4
5 #define ELM_LAYOUT_PROTECTED
6
7 #include <Elementary.h>
8 #include "elm_priv.h"
9
10 #include "elm_widget_layout.h"
11 //#include "efl_ui_textpath_internal_part.eo.h"
12 //#include "elm_part_helper.h"
13
14
15 #define MY_CLASS EFL_UI_TEXTPATH_CLASS
16
17 #define MY_CLASS_NAME "Efl.Ui.Textpath"
18 #define MY_CLASS_NAME_LEGACY "elm_textpath"
19
20 #define SLICE_DEFAULT_NO 99
21
22 typedef struct _Efl_Ui_Textpath_Point Efl_Ui_Textpath_Point;
23 typedef struct _Efl_Ui_Textpath_Line Efl_Ui_Textpath_Line;
24 typedef struct _Efl_Ui_Textpath_Segment Efl_Ui_Textpath_Segment;
25 typedef struct _Efl_Ui_Textpath_Data Efl_Ui_Textpath_Data;
26
27 struct _Efl_Ui_Textpath_Point
28 {
29    double x;
30    double y;
31 };
32
33 struct _Efl_Ui_Textpath_Line
34 {
35    Efl_Ui_Textpath_Point start;
36    Efl_Ui_Textpath_Point end;
37 };
38
39 struct _Efl_Ui_Textpath_Segment
40 {
41    EINA_INLIST;
42    int length;
43    Efl_Gfx_Path_Command type;
44    union
45      {
46         Eina_Bezier bezier;
47         Efl_Ui_Textpath_Line line;
48      };
49 };
50
51 /* If you need to draw slices using Evas Line,
52  * define the following debug flag manually. */
53 //#define EFL_UI_TEXTPATH_LINE_DEBUG
54
55 struct _Efl_Ui_Textpath_Data
56 {
57    Evas_Object *text_obj;
58    char *text;
59    Efl_Gfx_Shape *path;
60    struct {
61         double x, y;
62         double radius;
63         double start_angle;
64    } circle;
65    Efl_Ui_Textpath_Direction direction;
66    int slice_no;
67    Eina_Bool autofit;
68    Eina_Bool ellipsis;
69
70    Eina_Inlist *segments;
71    int total_length;
72 #ifdef EFL_UI_TEXTPATH_LINE_DEBUG
73    Eina_List *lines;
74 #endif
75 };
76
77 #define EFL_UI_TEXTPATH_DATA_GET(o, sd) \
78    Efl_Ui_Textpath_Data *sd = eo_data_scope_get(o, EFL_UI_TEXTPATH_CLASS)
79
80 static inline double
81 _deg_to_rad(double angle)
82 {
83    return angle / 180 * M_PI;
84 }
85
86 static void
87 _segment_draw(Efl_Ui_Textpath_Data *pd, int slice_no, double dt, double dist,
88               int w1, int cmp, Evas_Map *map, Eina_Bezier bezier,
89               int *last_x1, int *last_y1, int *last_x2, int *last_y2)
90 {
91    int x = 0, y = 0, w = 0, h = 0;
92    int i;
93    double u0, u1, v0, v1;
94    double t;
95    double px, py, px2, py2;
96    double rad;
97    Eina_Vector2 vec, nvec, vec0, vec1, vec2, vec3;
98    Eina_Matrix2 mat;
99 #ifdef EFL_UI_TEXTPATH_LINE_DEBUG
100    static Eina_Bool yello_color_flag = EINA_FALSE;
101    yello_color_flag = !yello_color_flag;
102 #endif
103
104    evas_object_geometry_get(pd->text_obj, NULL, NULL, &w, &h);
105
106    rad = _deg_to_rad(90);
107    eina_matrix2_values_set(&mat, cos(rad), -sin(rad), sin(rad), cos(rad));
108
109    eina_bezier_values_get(&bezier, NULL, NULL, NULL, NULL, NULL, NULL, &px2, &py2);
110    t = 0;
111    eina_bezier_point_at(&bezier, t, &px, &py);
112    eina_bezier_point_at(&bezier, t + dt, &px2, &py2);
113
114    vec.x = (px2 - px);
115    vec.y = (py2 - py);
116    eina_vector2_normalize(&nvec, &vec);
117
118    eina_vector2_transform(&vec, &mat, &nvec);
119    eina_vector2_normalize(&nvec, &vec);
120    eina_vector2_scale(&vec, &nvec, ((double) h) * 0.5);
121
122    vec1.x = (vec.x + px);
123    vec1.y = (vec.y + py);
124    vec2.x = (-vec.x + px);
125    vec2.y = (-vec.y + py);
126
127    if (cmp == 0)
128      {
129         *last_x1 = (int) floor(vec1.x + x + 0.5);
130         *last_y1 = (int) floor(vec1.y + y + 0.5);
131         *last_x2 = (int) floor(vec2.x + x + 0.5);
132         *last_y2 = (int) floor(vec2.y + y + 0.5);
133      }
134
135    //add points to map
136    for (i = 0; i < slice_no; i++)
137      {
138         int mp0_x, mp0_y;
139         int mp1_x, mp1_y;
140         int mp2_x, mp2_y;
141         int mp3_x, mp3_y;
142         double next_dt = dt;
143
144         //v0, v3
145         vec0.x = vec1.x;
146         vec0.y = vec1.y;
147         vec3.x = vec2.x;
148         vec3.y = vec2.y;
149
150         //UV
151         u0 = w1 + i * dist;
152         u1 = u0 + dist;
153         if (u1 > w)
154           u1 = w;
155         v0 = (double) 0;
156         v1 = (double) h;
157
158         /* If u1 is modified not to exceed its end,
159          * modify next_dt according to changes of dist. */
160         if (u1 < u0 + dist)
161           next_dt = dt * (u1 - u0) / dist;
162
163         //v1, v2
164         t = (double) (i * dt) + next_dt;
165         eina_bezier_point_at(&bezier, t, &px, &py);
166         eina_bezier_point_at(&bezier, t + next_dt, &px2, &py2);
167
168         vec.x = (px2 - px);
169         vec.y = (py2 - py);
170         eina_vector2_normalize(&nvec, &vec);
171         eina_vector2_transform(&vec, &mat, &nvec);
172         eina_vector2_normalize(&nvec, &vec);
173         eina_vector2_scale(&vec, &nvec, ((double) h) * 0.5);
174
175         vec1.x = (vec.x + px);
176         vec1.y = (vec.y + py);
177         vec2.x = (-vec.x + px);
178         vec2.y = (-vec.y + py);
179
180         /* Set mp1, mp2 position according to difference between previous points and next points.
181          * It improves smoothness of curve's slope changing. */
182         mp0_x = *last_x1;
183         mp0_y = *last_y1;
184         mp1_x = *last_x1 + (int) floor(vec1.x - vec0.x + 0.5);
185         mp1_y = *last_y1 + (int) floor(vec1.y - vec0.y + 0.5);
186         mp2_x = *last_x2 + (int) floor(vec2.x - vec3.x + 0.5);
187         mp2_y = *last_y2 + (int) floor(vec2.y - vec3.y + 0.5);
188         mp3_x = *last_x2;
189         mp3_y = *last_y2;
190
191         evas_map_point_coord_set(map, cmp + i * 4, mp0_x, mp0_y, 0);
192         evas_map_point_coord_set(map, cmp + i * 4 + 1, mp1_x, mp1_y, 0);
193         evas_map_point_coord_set(map, cmp + i * 4 + 2, mp2_x, mp2_y, 0);
194         evas_map_point_coord_set(map, cmp + i * 4 + 3, mp3_x, mp3_y, 0);
195
196         evas_map_point_image_uv_set(map, cmp + i * 4, u0, v0);
197         evas_map_point_image_uv_set(map, cmp + i * 4 + 1, u1, v0);
198         evas_map_point_image_uv_set(map, cmp + i * 4 + 2, u1, v1);
199         evas_map_point_image_uv_set(map, cmp + i * 4 + 3, u0, v1);
200
201         *last_x1 = mp1_x;
202         *last_y1 = mp1_y;
203         *last_x2 = mp2_x;
204         *last_y2 = mp2_y;
205
206 #ifdef EFL_UI_TEXTPATH_LINE_DEBUG
207         Evas_Object *line = evas_object_line_add(evas_object_evas_get(pd->text_obj));
208         pd->lines = eina_list_append(pd->lines, line);
209         if (yello_color_flag)
210           evas_object_color_set(line, 255, 255, 0, 255);
211         else
212           evas_object_color_set(line, 255, 0, 0, 255);
213         evas_object_line_xy_set(line,
214                                 mp0_x, mp0_y,
215                                 mp1_x, mp1_y);
216         evas_object_show(line);
217
218         line = evas_object_line_add(evas_object_evas_get(pd->text_obj));
219         pd->lines = eina_list_append(pd->lines, line);
220         if (yello_color_flag)
221           evas_object_color_set(line, 255, 255, 0, 255);
222         else
223           evas_object_color_set(line, 255, 0, 0, 255);
224         evas_object_line_xy_set(line,
225                                 mp1_x, mp1_y,
226                                 mp2_x, mp2_y);
227         evas_object_show(line);
228
229         line = evas_object_line_add(evas_object_evas_get(pd->text_obj));
230         pd->lines = eina_list_append(pd->lines, line);
231         if (yello_color_flag)
232           evas_object_color_set(line, 255, 255, 0, 255);
233         else
234           evas_object_color_set(line, 255, 0, 0, 255);
235         evas_object_line_xy_set(line,
236                                 mp2_x, mp2_y,
237                                 mp3_x, mp3_y);
238         evas_object_show(line);
239
240         line = evas_object_line_add(evas_object_evas_get(pd->text_obj));
241         pd->lines = eina_list_append(pd->lines, line);
242         if (yello_color_flag)
243           evas_object_color_set(line, 255, 255, 0, 255);
244         else
245           evas_object_color_set(line, 255, 0, 0, 255);
246         evas_object_line_xy_set(line,
247                                 mp3_x, mp3_y,
248                                 mp0_x, mp0_y);
249         evas_object_show(line);
250 #endif
251
252         if (u1 >= w) break;
253      }
254 }
255
256 static void
257 _text_on_line_draw(Efl_Ui_Textpath_Data *pd, int w1, int w2, int cmp, Evas_Map *map, Efl_Ui_Textpath_Line line)
258 {
259    double x1, x2, y1, y2;
260    Evas_Coord x, y, w, h;
261    double line_len, len, sina, cosa;
262
263    x1 = line.start.x;
264    y1 = line.start.y;
265    x2 = line.end.x;
266    y2 = line.end.y;
267
268    line_len = sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
269    len = w2 - w1;
270    if (line_len > len)
271      {
272         x2 = x1 + len * (x2 - x1) / line_len;
273         y2 = y1 + len * (y2 - y1) / line_len;
274      }
275
276    evas_object_geometry_get(pd->text_obj, &x, &y, &w, &h);
277
278    len = sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
279    sina = (y2 - y1) / len;
280    cosa = (x2 - x1) / len;
281
282    h = h / 2;
283    evas_map_point_coord_set(map, cmp + 3, x1 - h * sina, y1 + h * cosa, 0);
284    evas_map_point_coord_set(map, cmp + 2, x2 - h * sina, y2 + h * cosa, 0);
285    evas_map_point_coord_set(map, cmp + 1, x2 + h * sina, y2 - h * cosa, 0);
286    evas_map_point_coord_set(map, cmp + 0, x1 + h * sina, y1 - h * cosa, 0);
287
288    h *= 2;
289    evas_map_point_image_uv_set(map, cmp + 0, w1, 0);
290    evas_map_point_image_uv_set(map, cmp + 1, w2, 0);
291    evas_map_point_image_uv_set(map, cmp + 2, w2, h);
292    evas_map_point_image_uv_set(map, cmp + 3, w1, h);
293 }
294
295 static int
296 _map_point_calc(Efl_Ui_Textpath_Data *pd)
297 {
298    int map_no = 0;
299    Efl_Ui_Textpath_Segment *seg;
300
301    EINA_INLIST_FOREACH(pd->segments, seg)
302      {
303         if (seg->type == EFL_GFX_PATH_COMMAND_TYPE_LINE_TO)
304           {
305              map_no++;
306           }
307         else if (seg->type == EFL_GFX_PATH_COMMAND_TYPE_CUBIC_TO)
308           {
309              int no = (int)ceil(pd->slice_no * seg->length / (double)pd->total_length);
310              if (no == 0) no = 1;
311              map_no += no;
312           }
313      }
314    map_no *= 4;
315
316    return map_no;
317 }
318
319 static void
320 _text_draw(Efl_Ui_Textpath_Data *pd)
321 {
322    Efl_Ui_Textpath_Segment *seg;
323    Evas_Map *map;
324    int w, h, w1, w2;
325    int remained_w;
326    int cur_map_point = 0, map_point_no;
327    int last_x1, last_y1, last_x2, last_y2;
328
329    last_x1 = last_y1 = last_x2 = last_y2 = 0;
330
331    evas_object_geometry_get(pd->text_obj, NULL, NULL, &w, &h);
332    if (pd->autofit)
333      remained_w = w;
334    else
335      remained_w = pd->total_length;
336
337    map_point_no = _map_point_calc(pd);
338    if (map_point_no == 0)
339      {
340         evas_object_map_enable_set(pd->text_obj, EINA_FALSE);
341         return;
342      }
343    map = evas_map_new(map_point_no);
344    /* TIZEN_ONLY(20180302): update map when object's position is updated */
345    evas_map_util_object_move_sync_set(map, EINA_TRUE);
346    /* END */
347
348 #ifdef EFL_UI_TEXTPATH_LINE_DEBUG
349    Evas_Object *line;
350    EINA_LIST_FREE(pd->lines, line)
351       evas_object_del(line);
352 #endif
353
354    w1 = w2 = 0;
355    EINA_INLIST_FOREACH(pd->segments, seg)
356      {
357         int len = seg->length;
358         if (!pd->autofit)
359           len = (double)seg->length * w / (double)pd->total_length;
360         if (remained_w <= 0)
361           break;
362         w2 = w1 + len;
363         if (w2 > w)
364           w2 = w;
365         if (seg->type == EFL_GFX_PATH_COMMAND_TYPE_LINE_TO)
366           {
367              _text_on_line_draw(pd, w1, w2, cur_map_point, map, seg->line);
368              cur_map_point += 4;
369           }
370         else
371           {
372              double slice_value, dt, dist;
373              int slice_no;
374
375              slice_value = pd->slice_no * seg->length / (double)pd->total_length;
376              dt = (double)pd->total_length / (pd->slice_no * seg->length);
377
378              if (pd->autofit)
379                dist = (double)pd->total_length / (double)pd->slice_no;
380              else
381                dist = (double)pd->total_length * (w2 - w1) / ((double)pd->slice_no * seg->length);
382
383              slice_no = (int)ceil(slice_value);
384              dt = (double)slice_value * dt / (double)slice_no;
385              dist = (double)slice_value * dist / (double)slice_no;
386
387              _segment_draw(pd, slice_no, dt, dist,
388                            w1, cur_map_point, map, seg->bezier,
389                            &last_x1, &last_y1, &last_x2, &last_y2);
390              cur_map_point += slice_no * 4;
391           }
392         w1 = w2;
393         remained_w -= seg->length;
394      }
395    evas_object_map_enable_set(pd->text_obj, EINA_TRUE);
396    evas_object_map_set(pd->text_obj, map);
397    evas_map_free(map);
398 }
399
400 static void
401 _path_data_get(Eo *obj, Efl_Ui_Textpath_Data *pd, Eina_Bool set_min)
402 {
403    const Efl_Gfx_Path_Command *cmd;
404    const double *points;
405    Efl_Ui_Textpath_Segment *seg;
406
407    EINA_INLIST_FREE(pd->segments, seg)
408      {
409         pd->segments = eina_inlist_remove(pd->segments, EINA_INLIST_GET(seg));
410         free(seg);
411      }
412
413    Evas_Coord x, y;
414    evas_object_geometry_get(obj, &x, &y, NULL, NULL);
415
416    pd->total_length = 0;
417    eo_do(obj, efl_gfx_shape_path_get(&cmd, &points));
418    if (cmd)
419      {
420         int pos = -1;
421         Eina_Rectangle *rect = eina_rectangle_new(0, 0, 0, 0);
422         double px0 = 0.0, py0 = 0.0, ctrl_x0, ctrl_y0, ctrl_x1, ctrl_y1, px1, py1;
423
424         while (*cmd != EFL_GFX_PATH_COMMAND_TYPE_END)
425           {
426
427              if (*cmd == EFL_GFX_PATH_COMMAND_TYPE_MOVE_TO)
428                {
429                   pos++;
430                   px0 = points[pos] + x;
431                   pos++;
432                   py0 = points[pos] + y;
433                }
434              else if (*cmd == EFL_GFX_PATH_COMMAND_TYPE_CUBIC_TO)
435                {
436                   Eina_Bezier bz;
437                   double bx, by, bw, bh;
438                   Eina_Rectangle *brect;
439
440                   pos++;
441                   ctrl_x0 = points[pos] + x;
442                   pos++;
443                   ctrl_y0 = points[pos] + y;
444                   pos++;
445                   ctrl_x1 = points[pos] + x;
446                   pos++;
447                   ctrl_y1 = points[pos] + y;
448                   pos++;
449                   px1 = points[pos] + x;
450                   pos++;
451                   py1 = points[pos] + y;
452
453                   eina_bezier_values_set(&bz, px0, py0, ctrl_x0, ctrl_y0, ctrl_x1, ctrl_y1, px1, py1);
454                   seg = malloc(sizeof(Efl_Ui_Textpath_Segment));
455                   if (!seg)
456                     {
457                        ERR("Failed to allocate segment");
458                        px0 = px1;
459                        py0 = py1;
460                        continue;
461                     }
462                   seg->length = eina_bezier_length_get(&bz);
463                   seg->bezier = bz;
464                   seg->type = EFL_GFX_PATH_COMMAND_TYPE_CUBIC_TO;
465                   pd->segments = eina_inlist_append(pd->segments, EINA_INLIST_GET(seg));
466                   pd->total_length += seg->length;
467
468                   //move points
469                   px0 = px1;
470                   py0 = py1;
471
472                   eina_bezier_bounds_get(&bz, &bx, &by, &bw, &bh);
473                   brect = eina_rectangle_new(bx, by, bw, bh);
474                   eina_rectangle_union(rect, brect);
475                   eina_rectangle_free(brect);
476                }
477              else if (*cmd == EFL_GFX_PATH_COMMAND_TYPE_LINE_TO)
478                {
479                   Eina_Rectangle *lrect;
480
481                   pos++;
482                   px1 = points[pos] + x;
483                   pos++;
484                   py1 = points[pos] + y;
485
486                   seg = malloc(sizeof(Efl_Ui_Textpath_Segment));
487                   if (!seg)
488                     {
489                        ERR("Failed to allocate segment");
490                        px0 = px1;
491                        py0 = py1;
492                     }
493                   seg->type = EFL_GFX_PATH_COMMAND_TYPE_LINE_TO;
494                   seg->line.start.x = px0;
495                   seg->line.start.y = py0;
496                   seg->line.end.x = px1;
497                   seg->line.end.y = py1;
498                   seg->length = sqrt((px1 - px0)*(px1 - px0) + (py1 - py0)*(py1 - py0));
499                   pd->segments = eina_inlist_append(pd->segments, EINA_INLIST_GET(seg));
500                   pd->total_length += seg->length;
501
502                   lrect = eina_rectangle_new(px0, py0, px1 - px0, py1 - py0);
503                   eina_rectangle_union(rect, lrect);
504                   eina_rectangle_free(lrect);
505                }
506              cmd++;
507           }
508         if (set_min)
509           {
510              evas_object_size_hint_min_set(obj, rect->w, rect->h);
511           }
512         eina_rectangle_free(rect);
513      }
514 }
515
516 static void
517 _sizing_eval(Efl_Ui_Textpath_Data *pd)
518 {
519    _text_draw(pd);
520 }
521
522 static void
523 _textpath_ellipsis_set(Efl_Ui_Textpath_Data *pd, Eina_Bool enabled)
524 {
525    const char *format;
526
527    edje_object_part_text_style_user_pop(pd->text_obj, "elm.text");
528    if (enabled)
529      {
530         Eina_Strbuf *buf = eina_strbuf_new();
531
532         eina_strbuf_append_printf(buf, "DEFAULT='ellipsis=1.0'");
533         format = eina_stringshare_add(eina_strbuf_string_get(buf));
534         eina_strbuf_free(buf);
535         edje_object_part_text_style_user_push(pd->text_obj, "elm.text", format);
536      }
537 }
538
539 static void
540 _ellipsis_set(Efl_Ui_Textpath_Data *pd)
541 {
542    if (!pd->text_obj) return;
543
544    Evas_Coord w = 0, h = 0;
545    Eina_Bool is_ellipsis = EINA_FALSE;
546    const Evas_Object *tb;
547
548    tb = edje_object_part_object_get(pd->text_obj, "elm.text");
549    evas_object_textblock_size_native_get(tb, &w, &h);
550    evas_object_size_hint_min_set(pd->text_obj, w, h);
551    if (pd->ellipsis)
552      {
553         if (w > pd->total_length)
554           {
555              is_ellipsis = EINA_TRUE;
556              w = pd->total_length;
557           }
558      }
559    evas_object_resize(pd->text_obj, w, h);
560    _textpath_ellipsis_set(pd, is_ellipsis);
561 }
562
563 static Eina_Bool
564 //_path_changed_cb(void *data, const Efl_Event *event EINA_UNUSED)
565 _path_changed_cb(void *data,
566                     Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED,
567                     void *event_info EINA_UNUSED)
568 {
569    EFL_UI_TEXTPATH_DATA_GET(data, sd);
570
571    _path_data_get(data, sd, EINA_TRUE);
572    _sizing_eval(sd);
573
574    return EINA_TRUE;
575 }
576
577 static Eina_Bool
578 _textpath_text_set_internal(Eo *obj, Efl_Ui_Textpath_Data *pd, const char *part EINA_UNUSED, const char *text)
579 {
580    ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, EINA_FALSE);
581    Eina_Bool ret = EINA_TRUE;
582
583    if (!text) text = "";
584    //ret = edje_object_part_text_set(pd->text_obj, part, text);
585    ret = edje_object_part_text_set(pd->text_obj, "elm.text", text);
586    _ellipsis_set(pd);
587
588    return ret;
589 }
590
591 /*EOLIAN static void
592 _efl_ui_textpath_efl_canvas_group_group_calculate(Eo *obj EINA_UNUSED, Efl_Ui_Textpath_Data *pd)
593 {
594    _sizing_eval(pd);
595 }*/
596
597
598 EOLIAN static void
599 _efl_ui_textpath_elm_layout_sizing_eval(Eo *obj EINA_UNUSED, Efl_Ui_Textpath_Data *pd)
600 {
601    _sizing_eval(pd);
602 }
603
604 EOLIAN static void
605 _efl_ui_textpath_evas_object_smart_calculate(Eo *obj EINA_UNUSED, Efl_Ui_Textpath_Data *pd)
606 {
607     _sizing_eval(pd);
608 }
609
610 EOLIAN static void
611 //_efl_ui_textpath_efl_canvas_group_group_add(Eo *obj, Efl_Ui_Textpath_Data *priv)
612 _efl_ui_textpath_evas_object_smart_add(Eo *obj, Efl_Ui_Textpath_Data *priv)
613 {
614    ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
615
616    eo_do_super(obj, MY_CLASS, evas_obj_smart_add());
617    elm_widget_sub_object_parent_add(obj);
618
619    priv->text_obj = edje_object_add(evas_object_evas_get(obj));
620    elm_widget_theme_object_set(obj, priv->text_obj, "textpath", "base",
621                                elm_widget_style_get(obj));
622    evas_object_size_hint_weight_set(priv->text_obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
623    evas_object_size_hint_align_set(priv->text_obj, EVAS_HINT_FILL, EVAS_HINT_FILL);
624    evas_object_show(priv->text_obj);
625
626    evas_object_smart_member_add(priv->text_obj, obj);
627    elm_widget_sub_object_add(obj, priv->text_obj);
628
629    //efl_event_callback_add(obj, EFL_GFX_PATH_EVENT_CHANGED, _path_changed_cb, obj);
630    eo_do(obj, eo_event_callback_add
631          (EFL_GFX_PATH_CHANGED, _path_changed_cb, obj));
632 }
633
634 EOLIAN static void
635 _efl_ui_textpath_class_constructor(Eo_Class *klass)
636 {
637    evas_smart_legacy_type_register(MY_CLASS_NAME_LEGACY, klass);
638 }
639
640 //EOLIAN static Efl_Object *
641 //_efl_ui_textpath_efl_object_constructor(Eo *obj, Efl_Ui_Textpath_Data *pd)
642 EOLIAN static Eo*
643 _efl_ui_textpath_eo_base_constructor(Eo *obj, Efl_Ui_Textpath_Data *pd)
644 {
645    //obj = efl_constructor(efl_super(obj, MY_CLASS));
646    obj = eo_do_super_ret(obj, MY_CLASS, obj, eo_constructor());
647    pd->autofit = EINA_TRUE;
648    pd->slice_no = SLICE_DEFAULT_NO;
649    pd->direction = EFL_UI_TEXTPATH_DIRECTION_CW;
650
651    return obj;
652 }
653
654 EOLIAN static void
655 //_efl_ui_textpath_efl_object_destructor(Eo *obj, Efl_Ui_Textpath_Data *pd)
656 _efl_ui_textpath_eo_base_destructor(Eo *obj, Efl_Ui_Textpath_Data *pd)
657 {
658    Efl_Ui_Textpath_Segment *seg;
659
660    if (pd->text) free(pd->text);
661    if (pd->text_obj) evas_object_del(pd->text_obj);
662    EINA_INLIST_FREE(pd->segments, seg)
663      {
664         pd->segments = eina_inlist_remove(pd->segments, EINA_INLIST_GET(seg));
665         free(seg);
666      }
667
668 #ifdef EFL_UI_TEXTPATH_LINE_DEBUG
669    Evas_Object *line;
670    EINA_LIST_FREE(pd->lines, line)
671       evas_object_del(line);
672 #endif
673
674    //efl_destructor(efl_super(obj, MY_CLASS));
675    eo_do_super(obj, MY_CLASS, eo_destructor());
676 }
677
678 EOLIAN static Eina_Bool
679 _efl_ui_textpath_elm_layout_text_set(Eo *obj, Efl_Ui_Textpath_Data *pd, const char *part, const char *text)
680 {
681    return _textpath_text_set_internal(obj, pd, part, text);
682 }
683
684 EOLIAN static const char *
685 _efl_ui_textpath_elm_layout_text_get(const Eo *obj EINA_UNUSED, Efl_Ui_Textpath_Data *pd, const char *part)
686 {
687    return edje_object_part_text_get(pd->text_obj, part);
688 }
689
690 /*
691 EOLIAN static Eina_Bool
692 _efl_ui_textpath_text_set(Eo *obj, Efl_Ui_Textpath_Data *pd, const char *part, const char *text)
693 {
694    return _textpath_text_set_internal(obj, pd, part, text);
695 }
696
697 EOLIAN static const char *
698 _efl_ui_textpath_text_get(Eo *obj EINA_UNUSED, Efl_Ui_Textpath_Data *pd, const char *part)
699 {
700    return edje_object_part_text_get(pd->text_obj, part);
701 }
702
703 EOLIAN static void
704 _efl_ui_textpath_efl_text_text_set(Eo *obj, Efl_Ui_Textpath_Data *pd, const char *text)
705 {
706    _textpath_text_set_internal(obj, pd, "elm.text", text);
707 }
708
709 EOLIAN static const char *
710 _efl_ui_textpath_efl_text_text_get(Eo *obj EINA_UNUSED, Efl_Ui_Textpath_Data *pd)
711 {
712    return edje_object_part_text_get(pd->text_obj, "elm.text");
713 }*/
714
715 //EOLIAN static Efl_Ui_Theme_Apply
716 EOLIAN static Elm_Theme_Apply
717 _efl_ui_textpath_elm_widget_theme_apply(Eo *obj, Efl_Ui_Textpath_Data *pd)
718 {
719    Elm_Theme_Apply ret = ELM_THEME_APPLY_FAILED;
720
721    eo_do_super(obj, MY_CLASS, ret = elm_obj_widget_theme_apply());
722    if (!ret) return ELM_THEME_APPLY_FAILED;
723
724    elm_widget_theme_object_set(obj, pd->text_obj, "textpath", "base",
725                                elm_widget_style_get(obj));
726    _ellipsis_set(pd);
727
728    return ret;
729 }
730
731
732 EOLIAN static void
733 //_efl_ui_textpath_evas_object_position_set(Eo *obj, Efl_Ui_Textpath_Data *pd, Evas_Coord x, Evas_Coord y)
734 _efl_ui_textpath_evas_object_smart_move(Eo *obj, Efl_Ui_Textpath_Data *pd, Evas_Coord x, Evas_Coord y)
735 {
736    eo_do_super(obj, MY_CLASS, evas_obj_smart_move(x, y));
737
738    /* TIZEN_ONLY(20180302): update map when object's position is updated
739     * Do Nothing. The position is not updated to the object in this function.
740     * Test with evas_object_geometry_get().
741    _path_data_get(obj, pd, EINA_FALSE);
742    _text_draw(pd);
743     */
744    /* END */
745 }
746
747 /*
748 EOLIAN static void
749 _efl_ui_textpath_evas_object_resize(Eo *obj, Efl_Ui_Textpath_Data *pd EINA_UNUSED, Evas_Coord w, Evas_Coord h)
750 {
751    eo_do_super(obj, MY_CLASS, evas_object_resize(w, h));
752 }*/
753
754 EOLIAN static void
755 _efl_ui_textpath_circle_set(Eo *obj, Efl_Ui_Textpath_Data *pd, double x, double y, double radius, double start_angle, Efl_Ui_Textpath_Direction direction)
756 {
757    if (pd->circle.x == x && pd->circle.y == y &&
758        pd->circle.radius == radius &&
759        pd->circle.start_angle == start_angle &&
760        pd->direction == direction &&
761        _map_point_calc(pd) > 0)
762      {
763         ERR("Same circle");
764         return;
765      }
766    pd->circle.x = x;
767    pd->circle.y = y;
768    pd->circle.radius = radius;
769    pd->circle.start_angle = start_angle;
770    pd->direction = direction;
771
772    eo_do(obj, efl_gfx_shape_reset());
773    if (direction == EFL_UI_TEXTPATH_DIRECTION_CW)
774      {
775         eo_do(obj, efl_gfx_shape_append_arc(x - radius, y - radius, radius * 2,
776                                 radius * 2,  start_angle, -360));
777      }
778    else
779      {
780         eo_do(obj, efl_gfx_shape_append_arc(x - radius, y - radius, radius * 2,
781                                 radius * 2,  start_angle, 360));
782      }
783
784    _sizing_eval(pd);
785 }
786
787 EOLIAN static Eina_Bool
788 _efl_ui_textpath_autofit_get(Eo *obj EINA_UNUSED, Efl_Ui_Textpath_Data *pd)
789 {
790    return pd->autofit;
791 }
792
793 EOLIAN static void
794 _efl_ui_textpath_autofit_set(Eo *obj EINA_UNUSED, Efl_Ui_Textpath_Data *pd, Eina_Bool autofit)
795 {
796    if (pd->autofit == autofit) return;
797    pd->autofit = autofit;
798    _sizing_eval(pd);
799 }
800
801 EOLIAN static int
802 _efl_ui_textpath_slice_number_get(Eo *obj EINA_UNUSED, Efl_Ui_Textpath_Data *pd)
803 {
804    return pd->slice_no;
805 }
806
807 EOLIAN static void
808 _efl_ui_textpath_slice_number_set(Eo *obj EINA_UNUSED, Efl_Ui_Textpath_Data *pd, int slice_no)
809 {
810    if (pd->slice_no == slice_no) return;
811    pd->slice_no = slice_no;
812    _sizing_eval(pd);
813 }
814
815 EOLIAN static void
816 _efl_ui_textpath_ellipsis_set(Eo *obj EINA_UNUSED, Efl_Ui_Textpath_Data *pd, Eina_Bool ellipsis)
817 {
818    if (pd->ellipsis == ellipsis) return;
819    pd->ellipsis = ellipsis;
820
821    _ellipsis_set(pd);
822    _sizing_eval(pd);
823 }
824
825 EOLIAN static Eina_Bool
826 _efl_ui_textpath_ellipsis_get(Eo *obj EINA_UNUSED, Efl_Ui_Textpath_Data *pd)
827 {
828    return pd->ellipsis;
829 }
830
831 /* Efl.Part begin */
832 //ELM_PART_OVERRIDE(efl_ui_textpath, EFL_UI_TEXTPATH, EFL_UI_LAYOUT, Efl_Ui_Textpath_Data, Elm_Part_Data)
833 //ELM_PART_OVERRIDE_TEXT_SET(efl_ui_textpath, EFL_UI_TEXTPATH, EFL_UI_LAYOUT, Efl_Ui_Textpath_Data, Elm_Part_Data)
834 //ELM_PART_OVERRIDE_TEXT_GET(efl_ui_textpath, EFL_UI_TEXTPATH, EFL_UI_LAYOUT, Efl_Ui_Textpath_Data, Elm_Part_Data)
835 //#include "efl_ui_textpath_internal_part.eo.c"
836 /* Efl.Part end */
837
838 EAPI Evas_Object *
839 elm_textpath_add(Evas_Object *parent)
840 {
841    EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
842    Evas_Object *obj = eo_add(MY_CLASS, parent);
843
844    return obj;
845 }
846
847 #define EFL_UI_TEXTPATH_EXTRA_OPS \
848       EFL_CANVAS_GROUP_ADD_OPS(efl_ui_textpath)
849
850 #include "efl_ui_textpath.eo.c"