8a3769d8db8c9efdbf7173668fe311b97556077e
[framework/uifw/ise-default.git] / mcf / gwes / efl / mcfgraphics-efl.cpp
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.tizenopensource.org/license
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18
19 #include "mcfgraphics-efl.h"
20 #include "mcfimageproxy.h"
21 #include "mcffontproxy.h"
22 #include "mcfdebug.h"
23 #include "mcfwindows.h"
24 #include "mcfresourcecache.h"
25 #include "mcfwindows-efl.h"
26 #include "mcfutils.h"
27 #include "mcfcontext.h"
28 #include <Ecore_Evas.h>
29 #include <Ecore.h>
30 #include <Elementary.h>
31 #include <vector>
32
33 #ifdef TEST_NEWBACKEND
34 std::vector<ImageCache> g_ImageCache;
35 std::vector<TextCache> g_TextCache;
36 mcfint hash_string(const mcfchar* str) {
37     mcfint ret = 0;
38     mcfint len = strlen(str);
39     for(mcfint loop = 0;loop < len && str[loop];loop++) {
40         ret = ((loop + 1) * str[loop]);
41     }
42
43     return ret;
44 }
45 #else
46 #endif
47 using namespace mcf;
48
49 int iNumCreate = 0;
50
51 extern void mouse_press (void *data, Evas *e, Evas_Object *obj, void *event_info);
52 extern void mouse_release (void *data, Evas *e, Evas_Object *obj, void *event_info);
53 extern void mouse_move (void *data, Evas *e, Evas_Object *obj, void *event_info);
54
55 /**
56  * Constructor
57  */
58 CMCFGraphicsImplEfl::CMCFGraphicsImplEfl()
59 {
60     MCF_DEBUG();
61     /* Initializes all window resources */
62 }
63
64 /**
65  * De-constructor
66  */
67 CMCFGraphicsImplEfl::~CMCFGraphicsImplEfl()
68 {
69     MCF_DEBUG();
70 }
71
72 Evas_Object* extract_partimage_from_fullimage(Evas_Object* fullimage,
73                                               int img_x,int img_y,
74                                               int cell_x,int cell_y,
75                                               int cell_cx, int cell_cy)
76 {
77     unsigned int *data;
78     unsigned int *t_data;
79     int i,j;
80     int w,h;
81     Evas_Object *image_ob;
82
83     evas_object_image_size_get(fullimage, &w, &h);
84
85     data = (unsigned int*)evas_object_image_data_get(fullimage,0);
86     if (data == NULL) {
87         return NULL;
88     }
89
90     t_data=(unsigned int*)malloc(sizeof(unsigned int)*cell_cx*cell_cy);
91     if (t_data == NULL) {
92         free(data);
93         return NULL;
94     }
95
96     for (i=img_y; i<img_y+cell_cy; i++) {
97         for (j=img_x; j<img_x+cell_cx; j++) {
98             t_data[(i-img_y)*cell_cx+(j-img_x)] = data[i*w+j];
99         }
100     }
101
102     image_ob = evas_object_image_add(evas_object_evas_get(fullimage));
103     if (image_ob == NULL) {
104         free(data);
105         free(t_data);
106         return NULL;
107     }
108     evas_object_image_size_set(image_ob,cell_cx,cell_cy);
109     evas_object_image_data_set(image_ob,t_data);
110     evas_object_image_fill_set(image_ob,0,0,cell_cx,cell_cy);
111     evas_object_resize(image_ob,cell_cx,cell_cy);
112
113     evas_object_show(image_ob);
114     //Changed for Memory Leak
115     free(t_data);
116     return image_ob;
117 }
118
119 void
120 CMCFGraphicsImplEfl::draw_image(mcfwindow window, const mcfdrawctx drawCtx, mcfchar* imgPath,
121                                 mcfint destX, mcfint destY, mcfint destWidth, mcfint destHeight,
122                                 mcfint srcX, mcfint srcY, mcfint srcWidth, mcfint srcHeight, mcfboolean extractImg)
123 {
124     MCF_DEBUG();
125
126     mcf_assert_return(imgPath);
127
128     CMCFResourceCache *cache = CMCFResourceCache::get_instance();
129     CMCFWindows *windows = CMCFWindows::get_instance();
130     CMCFUtils *utils = CMCFUtils::get_instance();
131     McfWindowContext *winctx = NULL;
132     McfWindowContext *targetctx = NULL;
133     if(windows) {
134         winctx = windows->get_window_context(window, FALSE);
135         targetctx = windows->get_window_context(drawCtx, FALSE);
136     }
137
138     if (winctx && targetctx && imgPath && utils && cache && windows) {
139         if (strlen(imgPath) > 0) {
140 #ifdef TEST_NEWBACKEND
141             mcfboolean bFound = FALSE;
142             mcfboolean bOrgSizeMinusOne = (srcWidth == -1 && srcHeight == -1);
143             mcfint hashval = hash_string(imgPath);
144             for(mcfint loop = 0;loop < g_ImageCache.size() && !bFound;loop++) {
145                 if(g_ImageCache[loop].used &&
146                    window == g_ImageCache[loop].window &&
147                    hashval == g_ImageCache[loop].imgPathHash &&
148                    destX == g_ImageCache[loop].destX &&
149                    destY == g_ImageCache[loop].destY &&
150                    destWidth == g_ImageCache[loop].destWidth &&
151                    destHeight == g_ImageCache[loop].destHeight &&
152                    srcX == g_ImageCache[loop].srcX &&
153                    srcY == g_ImageCache[loop].srcY &&
154                    srcWidth == g_ImageCache[loop].srcWidth &&
155                    srcHeight == g_ImageCache[loop].srcHeight &&
156                    extractImg == g_ImageCache[loop].extractImg) {
157                         if(strcmp(imgPath, g_ImageCache[loop].imgPath) == 0) {
158                             bFound = TRUE;
159                             evas_object_show(g_ImageCache[loop].image);
160                             evas_object_raise(g_ImageCache[loop].image);
161                             if(g_ImageCache[loop].clipper) {
162                                 evas_object_show(g_ImageCache[loop].clipper);
163                                 evas_object_raise(g_ImageCache[loop].clipper);
164                             }
165                         }
166                     }
167             }
168             if(!bFound) {
169 #endif
170             EFLObject *obj = new EFLObject;
171             EFLObject *clipobj = NULL;
172             if (obj) {
173                 Evas_Object *winobj = (Evas_Object*)window;
174
175                 Evas *evas = evas_object_evas_get(winobj);
176                 Evas_Object *imgobj = evas_object_image_add(evas);
177
178                 obj->bExtracted = FALSE;
179
180                 if (imgobj) {
181                     int imgWidth = 0;
182                     int imgHeight = 0;
183                     evas_object_image_file_set(imgobj, imgPath, NULL);
184                     evas_object_image_size_get(imgobj, &imgWidth, &imgHeight);
185                     const McfNinePatchInfo *nine_patch_info = utils->get_nine_patch_info(imgPath);
186                     if(nine_patch_info) {
187                         evas_object_image_border_set(imgobj,
188                                                      nine_patch_info->left, nine_patch_info->right,
189                                                      nine_patch_info->top, nine_patch_info->bottom);
190                     }
191                     const McfLayout *layout = cache->get_cur_layout(window);
192                     if(layout) {
193                         if(layout->displayType == MCFDISPLAY_PORTRAIT) {
194                             imgWidth = utils->get_scale_x(imgWidth);
195                             imgHeight = utils->get_scale_y(imgHeight);
196                         } else {
197                             imgWidth = utils->get_scale_y(imgWidth);
198                             imgHeight = utils->get_scale_x(imgHeight);
199                         }
200                     }
201                     if(srcWidth == -1 && srcHeight == -1) {
202                         srcWidth = imgWidth;
203                         srcHeight = imgHeight;
204                     }
205                     if((srcWidth > 0 && srcHeight > 0) && (imgWidth != destWidth || imgHeight != destHeight) && extractImg) {
206 #ifdef EXTRACT_PARTIMAGE
207                         Evas_Object *newobj = extract_partimage_from_fullimage(imgobj, srcX, srcY, 0, 0, srcWidth, srcHeight);
208                         obj->bExtracted = TRUE;
209                         evas_object_del(imgobj);
210                         imgobj = newobj;
211                         evas_object_move(imgobj, destX, destY);
212                         if (destWidth > 0 && destHeight > 0) {
213                             evas_object_image_fill_set(imgobj, 0, 0, destWidth,destHeight);
214                             evas_object_resize(imgobj, destWidth, destHeight);
215                         }
216 #else
217                         evas_object_move(imgobj, destX - srcX, destY - srcY);
218                         evas_object_image_fill_set(imgobj, 0, 0, imgWidth, imgHeight);
219                         if(extractImg) {
220                             evas_object_resize(imgobj, imgWidth, imgHeight);
221                         } else {
222                             evas_object_resize(imgobj, destWidth, destHeight);
223                         }
224
225                         Evas_Object *clipper = evas_object_rectangle_add(evas);
226                         evas_object_color_set(clipper, 255, 255, 255, 255);
227                         evas_object_move(clipper, destX, destY);
228                         evas_object_resize(clipper, destWidth, destHeight);
229                         evas_object_clip_set(imgobj, clipper);
230                         evas_object_show(clipper);
231
232                         clipobj = new EFLObject;
233                         clipobj->obj = clipper;
234                         clipobj->type = EFLOBJECT_CLIPOBJECT;
235                         clipobj->position.x = destX;
236                         clipobj->position.y = destY;
237                         clipobj->position.width = destWidth;
238                         clipobj->position.height = destHeight;
239                         clipobj->etcInfo = imgPath;
240                         clipobj->bExtracted = FALSE;
241                         clipobj->data = NULL;
242
243                         if(winctx->isVirtual) {
244                             McfWindowContext *basectx = windows->get_window_context(windows->get_base_window());
245                             if(basectx) {
246                                 clipobj->position.x -= (winctx->x - basectx->x);
247                                 clipobj->position.y -= (winctx->y - basectx->y);
248                             }
249                         }
250 #endif
251                     } else {
252                         evas_object_move(imgobj, destX, destY);
253                         if (destWidth > 0 && destHeight > 0) {
254                             evas_object_image_fill_set(imgobj, 0, 0, destWidth,destHeight);
255                             evas_object_resize(imgobj, destWidth, destHeight);
256                         }
257                     }
258                     evas_object_raise(imgobj);
259                     evas_object_show(imgobj);
260
261                     obj->obj = imgobj;
262                     obj->type = EFLOBJECT_IMAGE;
263                     obj->position.x = destX;
264                     obj->position.y = destY;
265                     obj->position.width = destWidth;
266                     obj->position.height = destHeight;
267                     obj->etcInfo = imgPath;
268                     obj->data = NULL;
269
270                     if(winctx->isVirtual) {
271                         McfWindowContext *basectx = windows->get_window_context(windows->get_base_window());
272                         if(basectx) {
273                             obj->position.x -= (winctx->x - basectx->x);
274                             obj->position.y -= (winctx->y - basectx->y);
275                         }
276                     }
277
278                     targetctx->etcInfoPtr = eina_list_append((Eina_List*)(targetctx->etcInfoPtr), obj);
279                     if(clipobj) {
280                         targetctx->etcInfoPtr = eina_list_append((Eina_List*)(targetctx->etcInfoPtr), clipobj);
281                     }
282
283                     /* FIXME : this is for placing the background image at the lowest depth */
284                     mcfint window_layer = 29000;
285                     if(!windows->is_base_window(reinterpret_cast<mcfwindow>(drawCtx))) {
286                         window_layer = 29010;
287                     }
288
289                     if(winctx->width == destWidth && winctx->height == destHeight) {
290                         evas_object_layer_set(imgobj, window_layer + 0);
291                     } else {
292                         evas_object_layer_set(imgobj, window_layer + 1);
293                     }
294                 }
295             }
296 #ifdef TEST_NEWBACKEND
297                 ImageCache cache;
298                 cache.used = true;
299                 cache.window = window;
300                 strncpy(cache.imgPath, imgPath, sizeof(cache.imgPath));
301                 cache.imgPathHash = hashval;
302                 cache.destX = destX;
303                 cache.destY = destY;
304                 cache.destWidth = destWidth;
305                 cache.destHeight = destHeight;
306                 cache.srcX = srcX;
307                 cache.srcY = srcY;
308                 if(bOrgSizeMinusOne) {
309                     cache.srcWidth = -1;
310                     cache.srcHeight = -1;
311                 } else {
312                     cache.srcWidth = srcWidth;
313                     cache.srcHeight = srcHeight;
314                 }
315                 cache.extractImg= extractImg;
316                 cache.image = obj->obj;
317                 if(clipobj) {
318                     cache.clipper = clipobj->obj;
319                 } else {
320                     cache.clipper = NULL;
321                 }
322
323                 mcfboolean bInserted = FALSE;
324                 for(mcfint loop = 0;loop < g_ImageCache.size() && !bInserted;loop++) {
325                     if(!g_ImageCache[loop].used) {
326                         g_ImageCache[loop] = cache;
327                     }
328                 }
329                 if(!bInserted) {
330                     g_ImageCache.push_back(cache);
331                 }
332             }
333 #endif
334         }
335     }
336 }
337
338 mcfimage
339 CMCFGraphicsImplEfl::load_image(const mcfchar *imgPath)
340 {
341     MCF_DEBUG();
342     return NULL;
343 }
344
345 void
346 CMCFGraphicsImplEfl::unload_image(mcfimage imgData)
347 {
348     MCF_DEBUG();
349 }
350
351 /**
352  * Initializes the drawing context for double-buffering.
353  * This func should be called before using a drawing primitive at first.
354  */
355 mcfdrawctx
356 CMCFGraphicsImplEfl::begin_paint(const mcfwindow window, const mcfboolean forcedraw /* = FALSE */)
357 {
358     MCF_DEBUG();
359     mcfdrawctx drawctx = reinterpret_cast<mcfdrawctx>(window);
360
361     return drawctx;
362 }
363
364 /**
365  * Notices that drawing tasks have done.
366  */
367 void
368 CMCFGraphicsImplEfl::end_paint(const mcfwindow window, mcfdrawctx drawCtx)
369 {
370
371 }
372
373 mcffont
374 CMCFGraphicsImplEfl::create_font(const McfFontInfo& info)
375 {
376     return NULL;
377 }
378
379 void
380 CMCFGraphicsImplEfl::destroy_font(mcffont font)
381 {
382 }
383
384
385 typedef struct {
386     const char *szString;
387     const float actual_width;
388 } HARDCODED_WIDTH;
389 HARDCODED_WIDTH hardcoded_width[] = {
390     {"\xe3\x85\x82" , 0.59 }, // q
391     {"\xe3\x85\x83" , 0.59 }, // Q
392     {"\xe3\x85\x88" , 0.59 }, // w
393     {"\xe3\x85\x89" , 0.59 }, // W
394     {"\xe3\x84\xb7" , 0.59 }, // e
395     {"\xe3\x84\xb8" , 0.59 }, // E
396     {"\xe3\x84\xb1" , 0.59 }, // r
397     {"\xe3\x84\xb2" , 0.59 }, // R
398     {"\xe3\x85\x85" , 0.59 }, // t
399     {"\xe3\x85\x86" , 0.59 }, // T
400     {"\xe3\x85\x9b" , 0.72 }, // y
401     {"\xe3\x85\x95" , 0.40 }, // u
402     {"\xe3\x85\x91" , 0.40 }, // i
403     {"\xe3\x85\x90" , 0.50 }, // o
404     {"\xe3\x85\x92" , 0.55 }, // O
405     {"\xe3\x85\x94" , 0.59 }, // p
406     {"\xe3\x85\x96" , 0.59 }, // P
407     {"\xe3\x85\x81" , 0.59 }, // a
408     {"\xe3\x84\xb4" , 0.59 }, // s
409     {"\xe3\x85\x87" , 0.59 }, // d
410     {"\xe3\x84\xb9" , 0.59 }, // f
411     {"\xe3\x85\x8e" , 0.59 }, // g
412     {"\xe3\x85\x97" , 0.72 }, // h
413     {"\xe3\x85\x93" , 0.40 }, // j
414     {"\xe3\x85\x8f" , 0.40 }, // k
415     {"\xe3\x85\xa3" , 0.30 }, // l
416     {"\xe3\x85\x8b" , 0.59 }, // z
417     {"\xe3\x85\x8c" , 0.59 }, // x
418     {"\xe3\x85\x8a" , 0.59 }, // c
419     {"\xe3\x85\x8d" , 0.59 }, // v
420     {"\xe3\x85\xa0" , 0.72 }, // b
421     {"\xe3\x85\x9c" , 0.72 }, // n
422     {"\xe3\x85\xa1" , 0.75 }, // m
423
424     {"\xe3\x85\xa3" , 0.30 }, // ï¿½ï¿½
425     {"\xe3\x86\x8d" , 0.30 }, // .
426     {"\xe3\x85\xa1" , 0.75 }, // ï¿½ï¿½
427     {"\xe3\x84\xb1\xe3\x85\x8b" , 1.18 }, // ï¿½ï¿½ï¿½ï¿½
428     {"\xe3\x84\xb4\xe3\x84\xb9" , 1.18 }, // ï¿½ï¿½ï¿½ï¿½
429     {"\xe3\x84\xb7\xe3\x85\x8c" , 1.18 }, // ï¿½ï¿½ï¿½ï¿½
430     {"\xe3\x85\x82\xe3\x85\x8d" , 1.18 }, // ï¿½ï¿½ï¿½ï¿½
431     {"\xe3\x85\x85\xe3\x85\x8e" , 1.18 }, // ï¿½ï¿½ï¿½ï¿½
432     {"\xe3\x85\x88\xe3\x85\x8a" , 1.18 }, // ï¿½ï¿½ï¿½ï¿½
433     {"\xe3\x85\x87\xe3\x85\x81" , 1.18 }, // ï¿½ï¿½ï¿½ï¿½
434     {"\xe3\x85\x87\xe3\x85\x81" , 1.18 }, // ï¿½ï¿½ï¿½ï¿½
435     {"\xe3\x84\xb1\xe3\x84\xb4" , 1.38 }, // ï¿½ï¿½ï¿½ï¿½
436     {"\xe1\x84\x88" , 0.59 }, // ï¿½ï¿½
437     {"\xe1\x84\x8d" , 0.59 }, // ï¿½ï¿½
438     {"\xe1\x84\x84" , 0.59 }, // ï¿½ï¿½
439     {"\xe1\x84\x81" , 0.59 }, // ï¿½ï¿½
440     {"\xe1\x84\x8a" , 0.59 }, // ï¿½ï¿½
441
442     {"\xe2\x86\x90" , 0.50 }, // Arrows
443     {"\xe2\x86\x91" , 0.40 }, //
444     {"\xe2\x86\x92" , 0.55 }, //
445     {"\xe2\x86\x93" , 0.40 }, //
446
447         {"\xe3\x85\xa0" , 0.1 }, // ï¿½ï¿½
448         {"\341\205\262" , 0.9 }, // ï¿½ï¿½
449 };
450
451 int find_hardcoded_width(const char *szString, int fontsize) {
452     for(unsigned int loop = 0;loop < sizeof(hardcoded_width) / sizeof(HARDCODED_WIDTH);loop++) {
453         if(strcmp(szString, hardcoded_width[loop].szString) == 0) {
454             return hardcoded_width[loop].actual_width * fontsize;
455         }
456     }
457     return 0;
458 }
459
460 /**
461  * Draws the given text on cairo-surface
462  */
463 void
464 CMCFGraphicsImplEfl::draw_text(mcfwindow window, const mcfdrawctx drawCtx, const McfFontInfo& fontinfo, const McfColor& color,
465                                const mcfchar *str, mcfint posx, mcfint posy, mcfint width, mcfint height,
466                                MCFLabelAlignment align, mcfbyte paddingx, mcfbyte paddingy)
467 {
468     MCF_DEBUG();
469
470     CMCFWindows *windows = CMCFWindows::get_instance();
471     McfWindowContext *winctx = NULL;
472     McfWindowContext *targetctx = NULL;
473
474     if (windows) {
475         winctx = windows->get_window_context(window, FALSE);
476         targetctx = windows->get_window_context(drawCtx, FALSE);
477     }
478
479     if (winctx && targetctx && str && windows) {
480         if (strlen(str) > 0) {
481 #ifdef TEST_NEWBACKEND
482             mcfboolean bFound = FALSE;
483             mcfint hashval = hash_string(str);
484             mcfint org_posx = posx;
485             mcfint org_posy = posy;
486             for(mcfint loop = 0;loop < g_TextCache.size() && !bFound;loop++) {
487                     if(g_TextCache[loop].used &&
488                        window == g_TextCache[loop].window &&
489                        strncmp(fontinfo.fontname, g_TextCache[loop].fontinfo.fontname, MAX_FONT_NAME_LEN) == 0 &&
490                        fontinfo.fontsize == g_TextCache[loop].fontinfo.fontsize &&
491                        fontinfo.isBold == g_TextCache[loop].fontinfo.isBold &&
492                        fontinfo.isItalic == g_TextCache[loop].fontinfo.isItalic &&
493                        memcmp(&color, &(g_TextCache[loop].color), sizeof(McfColor)) == 0 &&
494                        hashval == g_TextCache[loop].strHash &&
495                        posx == g_TextCache[loop].posx&&
496                        posy == g_TextCache[loop].posy &&
497                        width == g_TextCache[loop].width &&
498                        height == g_TextCache[loop].height &&
499                        align == g_TextCache[loop].align &&
500                        paddingx == g_TextCache[loop].paddingx &&
501                        paddingy == g_TextCache[loop].paddingy) {
502                         if(strcmp(str, g_TextCache[loop].str) == 0) {
503                             bFound = TRUE;
504                             evas_object_show(g_TextCache[loop].text);
505                             evas_object_raise(g_TextCache[loop].text);
506                         }
507                     }
508             }
509             if(!bFound) {
510 #endif
511             EFLObject *obj = new EFLObject;
512             if (obj) {
513                 Evas_Object *winobj = (Evas_Object*)window;
514                 Evas *evas = evas_object_evas_get(winobj);
515                 Evas_Object *txtobj = evas_object_textblock_add(evas);
516
517                 if (txtobj) {
518                     mcfchar strStyle[128];
519                     sprintf(strStyle, "DEFAULT='font=%s font_size=%d align=%s color=#%02X%02X%02X%02X wrap=word left_margin=%d right_margin=%d'",
520                             fontinfo.fontname, fontinfo.fontsize,
521                             (((int)align % 3) == 1 ) ? "center" : ((((int)align % 3) == 2 ) ? "right" : "left"),
522                             color.r, color.g, color.b, color.a, paddingx, paddingx);
523
524                     Evas_Textblock_Style *st;
525                     st = evas_textblock_style_new();
526                     evas_textblock_style_set(st, strStyle);
527                     evas_object_textblock_style_set(txtobj, st);
528                     evas_object_textblock_text_markup_set(txtobj, str);
529                     evas_object_resize(txtobj, width, height);
530
531                     obj->bExtracted = FALSE;
532                     obj->type = EFLOBJECT_TEXTBLOCK;
533                     obj->obj = txtobj;
534                     obj->position.x = posx;
535                     obj->position.y = posy;
536                     obj->position.width = width;
537                     obj->position.height = height;
538                     obj->etcInfo = (char*)str;
539                     obj->data = st;
540
541                     if(winctx->isVirtual) {
542                         McfWindowContext *basectx = windows->get_window_context(windows->get_base_window());
543                         if(basectx) {
544                             obj->position.x -= (winctx->x - basectx->x);
545                             obj->position.y -= (winctx->y - basectx->y);
546                         }
547                     }
548
549                     mcfint calwidth, calheight;
550                     evas_object_textblock_size_native_get(txtobj, &calwidth, &calheight);
551                     /* FIXME : The following 2 lines are workaround for problem that EFL does not return correct font size */
552                     mcfint hardcoded_width = find_hardcoded_width(str, fontinfo.fontsize);
553                     if(hardcoded_width != 0) calwidth = hardcoded_width;
554
555                     if(calwidth > width) {
556                         sprintf(strStyle, "DEFAULT='font=%s font_size=%d align=%s color=#%02X%02X%02X%02X wrap=word left_margin=%d right_margin=%d'",
557                                 fontinfo.fontname, (int)(0.9 * fontinfo.fontsize * ((float)width / (float)calwidth)),
558                                 (((int)align % 3) == 1 ) ? "center" : ((((int)align % 3) == 2 ) ? "right" : "left"),
559                                 color.r, color.g, color.b, color.a, paddingx, paddingx);
560                         evas_textblock_style_set(st, strStyle);
561                         evas_object_textblock_style_set(txtobj, st);
562                         evas_object_textblock_text_markup_set(txtobj, str);
563                         evas_object_resize(txtobj, width, height);
564                         evas_object_textblock_size_native_get(txtobj, &calwidth, &calheight);
565                     }
566
567                     if (align == LABEL_ALIGN_LEFT_MIDDLE ||
568                         align == LABEL_ALIGN_CENTER_MIDDLE ||
569                         align == LABEL_ALIGN_RIGHT_MIDDLE) {
570                         posy = posy + ((height - calheight) / 2) + paddingy;
571                     } else if (align == LABEL_ALIGN_LEFT_BOTTOM ||
572                                    align == LABEL_ALIGN_CENTER_BOTTOM ||
573                                    align == LABEL_ALIGN_RIGHT_BOTTOM) {
574                         posy = posy + (height - calheight) - paddingy;
575                     } else {
576                         posy += paddingy;
577                     }
578
579                     evas_object_move(txtobj, posx, posy);
580                     evas_object_raise(txtobj);
581                     evas_object_show(txtobj);
582
583                     targetctx->etcInfoPtr = eina_list_append((Eina_List*)(targetctx->etcInfoPtr), obj);
584
585                     mcfint window_layer = 29000;
586                     if(!windows->is_base_window(reinterpret_cast<mcfwindow>(drawCtx))) {
587                         window_layer = 29010;
588                     }
589                     evas_object_layer_set(txtobj, window_layer + 1);
590                 }
591             }
592 #ifdef TEST_NEWBACKEND
593                 TextCache cache;
594                 cache.used = true;
595                 cache.window = window;
596                 cache.fontinfo = fontinfo;
597                 cache.color = color;
598                 strncpy(cache.fontinfo.fontname, fontinfo.fontname, MAX_FONT_NAME_LEN);
599                 cache.fontinfo.fontsize = fontinfo.fontsize;
600                 cache.fontinfo.isBold = fontinfo.isBold;
601                 cache.fontinfo.isItalic = fontinfo.isItalic;
602                 memcpy(&(cache.color), &(color), sizeof(McfColor));
603                 strncpy(cache.str, str, sizeof(cache.str));
604                 cache.strHash = hashval;
605                 cache.posx = org_posx;
606                 cache.posy = org_posy;
607                 cache.width = width;
608                 cache.height = height;
609                 cache.align = align;
610                 cache.paddingx = paddingx;
611                 cache.paddingy = paddingy;
612
613                 cache.text = obj->obj;
614
615                 mcfboolean bInserted = FALSE;
616                 for(mcfint loop = 0;loop < g_TextCache.size() && !bInserted;loop++) {
617                     if(!g_TextCache[loop].used) {
618                         g_TextCache[loop] = cache;
619                     }
620                 }
621                 if(!bInserted) {
622                     g_TextCache.push_back(cache);
623                 }
624             }
625 #endif
626         }
627     }
628 }
629
630 /**
631  * Draws a rectangle on cairo-surface
632  */
633 void
634 CMCFGraphicsImplEfl::draw_rectangle(mcfwindow window, const mcfdrawctx drawCtx, mcfdouble posx, mcfdouble posy,
635                                     mcfdouble width, mcfdouble height, const mcfdouble lineWidth,
636                                     const McfColor& lineColor, mcfboolean fill, const McfColor& fillColor,
637                                     mcfdouble radius, mcffloat alpha)
638 {
639     MCF_DEBUG();
640
641     CMCFResourceCache *cache = CMCFResourceCache::get_instance();
642     CMCFWindows *windows = CMCFWindows::get_instance();
643     CMCFUtils *utils = CMCFUtils::get_instance();
644     McfWindowContext *winctx = NULL;
645     McfWindowContext *targetctx = NULL;
646
647     if(windows) {
648         winctx = windows->get_window_context(window, FALSE);
649         targetctx = windows->get_window_context(drawCtx, FALSE);
650     }
651
652     if (winctx && utils && cache && windows) {
653         EFLObject *obj = new EFLObject;
654         if (obj) {
655             Evas_Object *winobj = (Evas_Object*)window;
656             Evas *evas = evas_object_evas_get(winobj);
657             Evas_Object *rectobj = evas_object_rectangle_add(evas);
658
659             evas_object_size_hint_weight_set(rectobj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
660             elm_win_resize_object_add(winobj, rectobj);
661             evas_object_color_set(rectobj, fillColor.r, fillColor.g, fillColor.b, fillColor.a);
662
663             evas_object_move(rectobj, posx, posy);
664             evas_object_resize(rectobj, width, height);
665
666             evas_object_show(rectobj);
667
668             obj->obj = rectobj;
669             obj->type = EFLOBJECT_RECTANGLE;
670             obj->position.x = posx;
671             obj->position.y = posy;
672             obj->position.width = width;
673             obj->position.height = height;
674             obj->etcInfo = NULL;
675             obj->data = NULL;
676
677             if(winctx->isVirtual) {
678                 McfWindowContext *basectx = windows->get_window_context(windows->get_base_window());
679                 if(basectx) {
680                     obj->position.x -= (winctx->x - basectx->x);
681                     obj->position.y -= (winctx->y - basectx->y);
682                 }
683             }
684
685             targetctx->etcInfoPtr = eina_list_append((Eina_List*)(targetctx->etcInfoPtr), obj);
686
687             mcfint window_layer = 29000;
688             if(!windows->is_base_window(reinterpret_cast<mcfwindow>(drawCtx))) {
689                 window_layer = 29010;
690             }
691             evas_object_layer_set(rectobj, window_layer + 1);
692         }
693     }
694 }
695
696 McfSize
697 CMCFGraphicsImplEfl::get_image_size(mcfchar* imgPath)
698 {
699     MCF_DEBUG();
700     McfSize ret = { 0, 0 };
701
702     CMCFWindows *windows = CMCFWindows::get_instance();
703
704     Evas_Object *winobj = (Evas_Object*)(windows->get_base_window());
705     Evas *evas = evas_object_evas_get(winobj);
706     Evas_Object *imgobj = evas_object_image_add(evas);
707
708     if (imgobj) {
709         int w, h;
710         evas_object_image_file_set(imgobj, imgPath, NULL);
711         evas_object_image_size_get(imgobj, &w, &h);
712         evas_object_del(imgobj);
713         ret.width = w;ret.height = h;
714     }
715
716     return ret;
717 }
718
719