From 4146343da1479918ca43395d6071c259ec43cdaa Mon Sep 17 00:00:00 2001 From: Sung-jae Park Date: Thu, 21 Feb 2013 10:57:00 +0000 Subject: [PATCH] Fix the EDJE scale factor problem. Sync with the latest code Change-Id: I96f32a257d0a7b47dadde447b04bcd997c311640 --- packaging/liblivebox-edje.spec | 2 +- src/script_port.c | 82 +++++++++++++++++++++--------------------- 2 files changed, 41 insertions(+), 43 deletions(-) diff --git a/packaging/liblivebox-edje.spec b/packaging/liblivebox-edje.spec index 99a9f9a..9fe7faa 100644 --- a/packaging/liblivebox-edje.spec +++ b/packaging/liblivebox-edje.spec @@ -1,6 +1,6 @@ Name: liblivebox-edje Summary: EDJE Script loader for the data provider master -Version: 0.2.3 +Version: 0.2.8 Release: 1 Group: framework/livebox License: Flora License diff --git a/src/script_port.c b/src/script_port.c index 48565c9..0afb6b3 100644 --- a/src/script_port.c +++ b/src/script_port.c @@ -35,6 +35,7 @@ #include "script_port.h" #define TEXT_CLASS "tizen" +#define BASE_WIDTH 720.0f #define PUBLIC __attribute__((visibility("default"))) @@ -87,6 +88,14 @@ static struct { .size = -100, }; +static inline double scale_get(void) +{ + int width; + int height; + ecore_x_window_size_get(0, &width, &height); + return (double)width / BASE_WIDTH; +} + /*! * \NOTE * Reservce this for future use @@ -314,6 +323,16 @@ static inline void parse_image_option(const char *option, struct image_option *i return; state = STATE_START; + /*! + * \note + * GCC 4.7 warnings uninitialized idx and tag value. + * But it will be initialized by the state machine. :( + * Anyway, I just reset idx and tag for reducing the GCC4.7 complains. + */ + idx = 0; + tag = 0; + cmd = NULL; + value = NULL; for (ptr = option; state != STATE_END; ptr++) { switch (state) { @@ -386,26 +405,6 @@ static inline void parse_image_option(const char *option, struct image_option *i } } -static void cropped_resize_cb(void *data, Evas *e, Evas_Object *obj, void *ei) -{ - Evas_Coord w; - Evas_Coord h; - int part_w; - int part_h; - - /* grab image size */ - part_w = (int)evas_object_data_get(obj, "part_w"); - part_h = (int)evas_object_data_get(obj, "part_h"); - w = (int)evas_object_data_get(obj, "w"); - h = (int)evas_object_data_get(obj, "h"); - - /* grab base object dimensions */ - evas_object_resize(obj, part_w, part_h); - evas_object_image_fill_set(obj, 0, 0, w, h); - - DbgPrint("Cropped: %dx%d - %dx%d, ImageSize(%dx%d)\n", (w - part_w) / 2, (h - part_h) / 2, part_w, part_h, w, h); -} - PUBLIC int script_update_image(void *_h, Evas *e, const char *id, const char *part, const char *path, const char *option) { struct info *handle = _h; @@ -482,11 +481,11 @@ PUBLIC int script_update_image(void *_h, Evas *e, const char *id, const char *pa return -EFAULT; } + evas_object_image_preload(img, EINA_FALSE); parse_image_option(option, &img_opt); evas_object_image_load_orientation_set(img, img_opt.orient); evas_object_image_file_set(img, path, NULL); - err = evas_object_image_load_error_get(img); if (err != EVAS_LOAD_ERROR_NONE) { ErrPrint("Load error: %s\n", evas_load_error_str(err)); @@ -501,44 +500,43 @@ PUBLIC int script_update_image(void *_h, Evas *e, const char *id, const char *pa if (img_opt.fill == FILL_OVER_SIZE) { Evas_Coord part_w; Evas_Coord part_h; - Evas_Coord tmp_w; - Evas_Coord tmp_h; if (img_opt.width >= 0 && img_opt.height >= 0) { - part_w = img_opt.width; - part_h = img_opt.height; + part_w = img_opt.width * scale_get(); + part_h = img_opt.height * scale_get(); } else { + part_w = 0; + part_h = 0; edje_object_part_geometry_get(edje, part, NULL, NULL, &part_w, &part_h); } - evas_object_data_set(img, "part_w", (void *)part_w); - evas_object_data_set(img, "part_h", (void *)part_h); DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h); - tmp_w = part_w - w; - tmp_h = part_h - h; + if (part_w > w || part_h > h) { + double fw; + double fh; - if (abs(tmp_w) > abs(tmp_h)) { - if (tmp_w > 0) { - DbgPrint("Before: (h = %d * %d / %d)\n", part_w, h, w); - h = (int)((double)part_w * (double)h / (double)w); + fw = (double)part_w / (double)w; + fh = (double)part_h / (double)h; + + if (fw > fh) { w = part_w; - DbgPrint("Size: %dx%d\n", w, h); - } - } else { - if (tmp_h > 0) { - DbgPrint("Before: (w = %d * %d / %d)\n", part_h, w, h); - w = (int)((double)part_h * (double)w / (double)h); + h = (double)h * fw; + } else { h = part_h; - DbgPrint("Size: %dx%d\n", w, h); + w = (double)w * fh; } } + DbgPrint("Size: %dx%d\n", w, h); + evas_object_data_set(img, "part_w", (void *)part_w); + evas_object_data_set(img, "part_h", (void *)part_h); evas_object_data_set(img, "w", (void *)w); evas_object_data_set(img, "h", (void *)h); + evas_object_image_load_size_set(img, w, h); evas_object_image_load_region_set(img, (w - part_w) / 2, (h - part_h) / 2, part_w, part_h); + evas_object_image_fill_set(img, 0, 0, part_w, part_h); evas_object_image_reload(img); - evas_object_event_callback_add(img, EVAS_CALLBACK_RESIZE, cropped_resize_cb, NULL); } else { evas_object_image_fill_set(img, 0, 0, w, h); evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL); @@ -1003,6 +1001,7 @@ PUBLIC int script_init(void) int ret; /* ecore is already initialized */ edje_init(); + edje_scale_set(scale_get()); s_info.property_handler = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY, property_cb, NULL); if (!s_info.property_handler) @@ -1021,7 +1020,6 @@ PUBLIC int script_init(void) PUBLIC int script_fini(void) { - vconf_ignore_key_changed("db/setting/accessibility/font_name", font_name_cb); vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, font_size_cb); ecore_event_handler_del(s_info.property_handler); -- 2.7.4