diff --git a/src/lib/evas/canvas/efl_canvas_vg_object.c b/src/lib/evas/canvas/efl_canvas_vg_object.c --- a/src/lib/evas/canvas/efl_canvas_vg_object.c +++ b/src/lib/evas/canvas/efl_canvas_vg_object.c @@ -626,28 +626,30 @@ (vg_entry->h != h)) { Eina_Size2D size = evas_cache_vg_entry_default_size_get(pd->vg_entry); - - //adjust size for aspect ratio. - if (size.w > 0 && size.h > 0) + if (!vg_entry->vfd->is_wrap) { - float rw = (float) w / (float) size.w; - float rh = (float) h / (float) size.h; - - if (rw < rh) + //adjust size for aspect ratio. + if (size.w > 0 && size.h > 0) { - size.w = w; - size.h = (int) ((float) size.h * rw); + float rw = (float) w / (float) size.w; + float rh = (float) h / (float) size.h; + + if (rw < rh) + { + size.w = w; + size.h = (int) ((float) size.h * rw); + } + else + { + size.w = (int) ((float) size.w * rh); + size.h = h; + } } else { - size.w = (int) ((float) size.w * rh); - size.h = h; - } - } - else - { - size.w = w; - size.h = h; + size.w = w; + size.h = h; + } } //Size is changed, cached data is invalid. @@ -676,10 +678,11 @@ } //update for adjusted pos and size. - offset.x = w - size.w; + offset.x = vg_entry->vfd->is_wrap?0:(w - size.w); if (offset.x > 0) offset.x /= 2; - offset.y = h - size.h; + offset.y = vg_entry->vfd->is_wrap?0:(h - size.h); if (offset.y > 0) offset.y /= 2; + w = size.w; h = size.h; } @@ -1075,6 +1078,27 @@ return evas_cache_vg_entry_default_size_get(pd->vg_entry); } +EOLIAN static Eina_Position2D +_efl_canvas_vg_object_default_position_get(const Eo *eo_obj EINA_UNUSED, + Efl_Canvas_Vg_Object_Data *pd EINA_UNUSED) +{ + return evas_cache_vg_entry_default_position_get(pd->vg_entry); +} + +EOLIAN static Eina_Size2D +_efl_canvas_vg_object_default_min_size_get(const Eo *eo_obj EINA_UNUSED, + Efl_Canvas_Vg_Object_Data *pd EINA_UNUSED) +{ + return evas_cache_vg_entry_default_min_size_get(pd->vg_entry); +} + +EOLIAN static void +_efl_canvas_vg_object_wrap_mode_set(Eo *obj EINA_UNUSED, + Efl_Canvas_Vg_Object_Data *pd, Eina_Bool wrap_mode) +{ + evas_cache_vg_entry_wrap_mode_set(pd->vg_entry, wrap_mode); +} + /* the actual api call to add a vector graphic object */ EAPI Eo * evas_object_vg_add(Evas *e) diff --git a/src/lib/evas/canvas/efl_canvas_vg_object.eo b/src/lib/evas/canvas/efl_canvas_vg_object.eo --- a/src/lib/evas/canvas/efl_canvas_vg_object.eo +++ b/src/lib/evas/canvas/efl_canvas_vg_object.eo @@ -74,6 +74,27 @@ size: Eina.Size2D; } } + @property default_position { + get { + } + values { + size: Eina.Position2D; + } + } + @property default_min_size { + get { + } + values { + size: Eina.Size2D; + } + } + @property wrap_mode { + set { + } + values { + wrap_mode: bool; + } + } } implements { Efl.Object.constructor; diff --git a/src/lib/evas/canvas/evas_vg_private.h b/src/lib/evas/canvas/evas_vg_private.h --- a/src/lib/evas/canvas/evas_vg_private.h +++ b/src/lib/evas/canvas/evas_vg_private.h @@ -145,6 +145,9 @@ Eina_Bool evas_cache_vg_anim_sector_get(const Vg_Cache_Entry* vg_entry, const char *name, int* startframe, int* endframe); unsigned int evas_cache_vg_anim_frame_count_get(const Vg_Cache_Entry *vg_entry); Eina_Size2D evas_cache_vg_entry_default_size_get(const Vg_Cache_Entry *vg_entry); +Eina_Position2D evas_cache_vg_entry_default_position_get(const Vg_Cache_Entry *vg_entry); +Eina_Size2D evas_cache_vg_entry_default_min_size_get(const Vg_Cache_Entry *vg_entry); +void evas_cache_vg_entry_wrap_mode_set(const Vg_Cache_Entry *vg_entry, Eina_Bool wrap_mode); void * evas_cache_vg_surface_key_get(Efl_Canvas_Vg_Node *root, int w, int h, int frame_idx); void efl_canvas_vg_node_vg_obj_set(Efl_VG *node, Efl_VG *vg_obj, Efl_Canvas_Vg_Object_Data *vd); void efl_canvas_vg_node_change(Efl_VG *node); diff --git a/src/lib/evas/include/evas_private.h b/src/lib/evas/include/evas_private.h --- a/src/lib/evas/include/evas_private.h +++ b/src/lib/evas/include/evas_private.h @@ -1136,6 +1136,8 @@ Vg_File_Anim_Data *anim_data; //only when animation supported. int ref; int w, h; //default size + int minw, minh; + double bl, bt, br, bb; Eina_List *vp_list; //Value providers. void *loader_data; //loader specific local data @@ -1144,6 +1146,7 @@ Eina_Bool preserve_aspect : 1; //Used in SVG Eina_Bool shareable: 1; + Eina_Bool is_wrap: 1; }; struct _Evas_Vg_Load_Func diff --git a/src/lib/evas/vg/evas_vg_cache.c b/src/lib/evas/vg/evas_vg_cache.c --- a/src/lib/evas/vg/evas_vg_cache.c +++ b/src/lib/evas/vg/evas_vg_cache.c @@ -227,6 +227,16 @@ } static void +_local_wrap_transform(Efl_VG *root, Vg_File_Data *vfd) +{ + Eina_Matrix3 m; + + eina_matrix3_identity(&m); + eina_matrix3_translate(&m, -vfd->bl, -vfd->bt); + efl_canvas_vg_node_transformation_set(root, &m); +} + +static void _local_transform(Efl_VG *root, double w, double h, Vg_File_Data *vfd) { double sx = 0, sy= 0, scale; @@ -514,7 +524,10 @@ _root_update(vg_entry); - _local_transform(vg_entry->root, vg_entry->w, vg_entry->h, vfd); + if (vfd->is_wrap) + _local_wrap_transform(vg_entry->root, vfd); + else + _local_transform(vg_entry->root, vg_entry->w, vg_entry->h, vfd); return vg_entry->root; } @@ -547,6 +560,27 @@ return EINA_SIZE2D(vg_entry->vfd->w, vg_entry->vfd->h); } +Eina_Size2D +evas_cache_vg_entry_default_min_size_get(const Vg_Cache_Entry *vg_entry) +{ + if (!vg_entry) return EINA_SIZE2D(0, 0); + return EINA_SIZE2D(vg_entry->vfd->minw, vg_entry->vfd->minh); +} + +Eina_Position2D +evas_cache_vg_entry_default_position_get(const Vg_Cache_Entry *vg_entry) +{ + if (!vg_entry) return EINA_POSITION2D(0, 0); + return EINA_POSITION2D(vg_entry->vfd->bl, vg_entry->vfd->bt); +} + +void +evas_cache_vg_entry_wrap_mode_set(const Vg_Cache_Entry *vg_entry, Eina_Bool wrap_mode) +{ + if (!vg_entry) return; + vg_entry->vfd->is_wrap = wrap_mode; +} + Eina_Bool evas_cache_vg_entry_file_save(Vg_Cache_Entry *vg_entry, const char *file, const char *key, const Efl_File_Save_Info *info) { diff --git a/src/static_libs/vg_common/vg_common_json.c b/src/static_libs/vg_common/vg_common_json.c --- a/src/static_libs/vg_common/vg_common_json.c +++ b/src/static_libs/vg_common/vg_common_json.c @@ -18,7 +18,7 @@ } static void -_construct_drawable_nodes(Efl_Canvas_Vg_Container *parent, const LOTLayerNode *layer, int depth EINA_UNUSED) +_construct_drawable_nodes(Vg_File_Data *vfd, Efl_Canvas_Vg_Container *parent, const LOTLayerNode *layer, int depth EINA_UNUSED) { if (!parent) return; @@ -86,6 +86,21 @@ const float *data = node->mPath.ptPtr; if (!data) continue; + + for (unsigned int i = 0; imPath.ptCount; i++) + { + if (i%2 == 0) + { + if (vfd->bl > data[i]) vfd->bl = data[i]; + if (vfd->br < data[i]) vfd->br = data[i]; + } + else + { + if (vfd->bt > data[i]) vfd->bt = data[i]; + if (vfd->bb < data[i]) vfd->bb = data[i]; + } + } + if (node->keypath) efl_key_data_set(shape, "_lot_node_name", node->keypath); efl_gfx_entity_visible_set(shape, EINA_TRUE); #if DEBUG @@ -401,7 +416,7 @@ } static void -_update_vg_tree(Efl_Canvas_Vg_Container *root, const LOTLayerNode *layer, int depth EINA_UNUSED) +_update_vg_tree(Vg_File_Data *vfd, Efl_Canvas_Vg_Container *root, const LOTLayerNode *layer, int depth EINA_UNUSED) { if (!layer->mVisible) return; @@ -436,7 +451,7 @@ for (int i = 0; i < depth; i++) printf(" "); printf("%s (%p) matte:%d => %p %s\n", efl_class_name_get(efl_class_get(ctree)), ctree, matte_mode, ptree, clayer->keypath); #endif - _update_vg_tree(ctree, clayer, depth+1); + _update_vg_tree(vfd, ctree, clayer, depth+1); if (matte_mode != 0) { @@ -485,9 +500,10 @@ ptree = _construct_masks(mtarget, mlayer->mMaskList.ptr, mlayer->mMaskList.size, depth + 1); } + efl_key_data_set(root, "_lot_node_size", &layer->mNodeList.size); //Construct drawable nodes. if (layer->mNodeList.size > 0) - _construct_drawable_nodes(root, layer, depth); + _construct_drawable_nodes(vfd, root, layer, depth); } #endif @@ -591,9 +607,20 @@ if (vfd->vp_list) _value_provider_override(vfd); unsigned int frame_num = (vfd->anim_data) ? vfd->anim_data->frame_num : 0; + + //This Calculates Bound Size using Raw Data + vfd->bl = 100000; + vfd->bt = 100000; + vfd->br = -1; + vfd->bb = -1; + + int lot_render_w, lot_render_h; + lot_render_w = vfd->is_wrap?vfd->w:vfd->view_box.w; + lot_render_h = vfd->is_wrap?vfd->h:vfd->view_box.h; + const LOTLayerNode *tree = lottie_animation_render_tree(lot_anim, frame_num, - vfd->view_box.w, vfd->view_box.h); + lot_render_w, lot_render_h); //Root node Efl_Canvas_Vg_Container *root = vfd->root; if (!root) @@ -610,7 +637,11 @@ printf("%s (%p)\n", efl_class_name_get(efl_class_get(vfd->root)), vfd->root); #endif - _update_vg_tree(root, tree, 1); + _update_vg_tree(vfd, root, tree, 1); + + vfd->minw = (int)(vfd->br - vfd->bl); + vfd->minh = (int)(vfd->bb - vfd->bt); + #else return EINA_FALSE; #endif