aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/edje/edje_calc.c
blob: e2a662fb6b75f698aef04ab984eb2ff056e7aa70 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
#define EFL_GFX_FILTER_BETA

#include "edje_private.h"

static void                          _edje_part_make_rtl(Edje_Part_Description_Common *desc);
static Edje_Part_Description_Common *_edje_get_description_by_orientation(Edje *ed, Edje_Part_Description_Common *src, Edje_Part_Description_Common **dst, unsigned char type);

static void                          _edje_part_recalc_single(Edje *ed, Edje_Real_Part *ep,
                                                              Edje_Part_Description_Common *desc, Edje_Part_Description_Common *chosen_desc,
                                                              Edje_Real_Part *center, Edje_Real_Part *light, Edje_Real_Part *persp,
                                                              Edje_Real_Part *rel1_to_x, Edje_Real_Part *rel1_to_y,
                                                              Edje_Real_Part *rel2_to_x, Edje_Real_Part *rel2_to_y,
                                                              Edje_Real_Part *clip_to,
                                                              Edje_Real_Part *confine_to, Edje_Real_Part *threshold,
                                                              Edje_Calc_Params *params,
                                                              Evas_Coord mmw, Evas_Coord mmh,
                                                              FLOAT_T pos);

#define EINA_COW_CALC_PHYSICS_BEGIN(Calc, Write) \
  EINA_COW_WRITE_BEGIN(_edje_calc_params_physics_cow, Calc->physics, Edje_Calc_Params_Physics, Write)

#define EINA_COW_CALC_PHYSICS_END(Calc, Write) \
  EINA_COW_WRITE_END(_edje_calc_params_physics_cow, Calc->physics, Write)

#define EINA_COW_CALC_MAP_BEGIN(Calc, Write) \
  EINA_COW_WRITE_BEGIN(_edje_calc_params_map_cow, Calc->map, Edje_Calc_Params_Map, Write)

#define EINA_COW_CALC_MAP_END(Calc, Write) \
  EINA_COW_WRITE_END(_edje_calc_params_map_cow, Calc->map, Write);

#ifdef BUILD_EDJE_FP

#define TYPE_EPSILON FLT_EPSILON

#else

#define TYPE_EPSILON DBL_EPSILON

#endif


#define SET_QUATERNION(type)                                                 \
   double norm;                                                              \
   Eina_Quaternion quaternion;                                               \
                                                                             \
   eina_quaternion_set(&quaternion, pd_##type->type.orientation.data[0],     \
                                    pd_##type->type.orientation.data[1],     \
                                    pd_##type->type.orientation.data[2],     \
                                    pd_##type->type.orientation.data[3]);    \
                                                                             \
   norm = eina_quaternion_norm(&quaternion);                                 \
                                                                             \
   if ((norm - 0.0) <= TYPE_EPSILON)                                         \
     ERR("%s %s",                                                            \
         "{0, 0, 0, 0} quaternion gives rotation on non-zero angle",         \
         "around axis without orientation");                                 \
                                                                             \
   eina_quaternion_scale(&quaternion, &quaternion, 1/norm);                  \
                                                                             \
   eo_do(ep->node,                                                           \
         evas_canvas3d_node_orientation_set(quaternion.x, quaternion.y,            \
                                      quaternion.z, quaternion.w));

#define SET_LOOK_AT(type)                                                 \
   eo_do(ep->node,                                                        \
         evas_canvas3d_node_look_at_set(pd_##type->type.position.space,         \
                                  pd_##type->type.orientation.data[0],    \
                                  pd_##type->type.orientation.data[1],    \
                                  pd_##type->type.orientation.data[2],    \
                                  pd_##type->type.position.space,         \
                                  pd_##type->type.orientation.data[3],    \
                                  pd_##type->type.orientation.data[4],    \
                                  pd_##type->type.orientation.data[5]));

#define SET_LOOK_TO(type)                                                                    \
   Edje_Real_Part *look_to;                                                                  \
   Evas_Real x, y ,z;                                                                        \
   look_to = ed->table_parts[pd_##type->type.orientation.look_to % ed->table_parts_size];    \
   eo_do(look_to->node,                                                                      \
         evas_canvas3d_node_position_get(pd_##type->type.position.space, &x, &y, &z));             \
   eo_do(ep->node,                                                                           \
         evas_canvas3d_node_look_at_set(pd_##type->type.position.space, x, y, z,                   \
                                  pd_##type->type.position.space,                            \
                                  pd_##type->type.orientation.data[3],                       \
                                  pd_##type->type.orientation.data[4],                       \
                                  pd_##type->type.orientation.data[5]));

#define SET_ANGLE_AXIS(type)                                                             \
   eo_do(ep->node,                                                                       \
         evas_canvas3d_node_orientation_angle_axis_set(pd_##type->type.orientation.data[0],    \
                                                 pd_##type->type.orientation.data[1],    \
                                                 pd_##type->type.orientation.data[2],    \
                                                 pd_##type->type.orientation.data[3]));


void
_edje_part_pos_set(Edje *ed, Edje_Real_Part *ep, int mode, FLOAT_T pos, FLOAT_T v1, FLOAT_T v2, FLOAT_T v3, FLOAT_T v4)
{
   FLOAT_T fp_pos;
   FLOAT_T npos;
   double v[4];

   pos = CLAMP(pos, ZERO, FROM_INT(1));

   fp_pos = pos;

#if 0 // old code - easy to enable for comparing float vs fixed point
      /* take linear pos along timescale and use interpolation method */
   switch (mode)
     {
      case EDJE_TWEEN_MODE_SINUSOIDAL:
        /* npos = (1.0 - cos(pos * PI)) / 2.0; */
        npos = DIV2(SUB(FROM_INT(1),
                        COS(MUL(fp_pos,
                                PI))));
        break;

      case EDJE_TWEEN_MODE_ACCELERATE:
        /* npos = 1.0 - sin((PI / 2.0) + (pos * PI / 2.0)); */
        npos = SUB(FROM_INT(1),
                   SIN(ADD(DIV2(PI),
                           MUL(fp_pos,
                               DIV2(PI)))));
        break;

      case EDJE_TWEEN_MODE_DECELERATE:
        /* npos = sin(pos * PI / 2.0); */
        npos = SIN(MUL(fp_pos,
                       DIV2(PI)));
        break;

      case EDJE_TWEEN_MODE_LINEAR:
        npos = fp_pos;
        break;

      default:
        npos = fp_pos;
        break;
     }
#else
   switch (mode & EDJE_TWEEN_MODE_MASK)
     {
      case EDJE_TWEEN_MODE_SINUSOIDAL:
        npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
                                                  ECORE_POS_MAP_SINUSOIDAL,
                                                  0.0, 0.0));
        break;

      case EDJE_TWEEN_MODE_ACCELERATE:
        npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
                                                  ECORE_POS_MAP_ACCELERATE,
                                                  0.0, 0.0));
        break;

      case EDJE_TWEEN_MODE_DECELERATE:
        npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
                                                  ECORE_POS_MAP_DECELERATE,
                                                  0.0, 0.0));
        break;

      case EDJE_TWEEN_MODE_LINEAR:
        npos = fp_pos;
/*        npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
                                                  ECORE_POS_MAP_LINEAR,
                                                  0.0, 0.0));
 */
        break;

      case EDJE_TWEEN_MODE_ACCELERATE_FACTOR:
        npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
                                                  ECORE_POS_MAP_ACCELERATE_FACTOR,
                                                  TO_DOUBLE(v1), 0.0));
        break;

      case EDJE_TWEEN_MODE_DECELERATE_FACTOR:
        npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
                                                  ECORE_POS_MAP_DECELERATE_FACTOR,
                                                  TO_DOUBLE(v1), 0.0));
        break;

      case EDJE_TWEEN_MODE_SINUSOIDAL_FACTOR:
        npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
                                                  ECORE_POS_MAP_SINUSOIDAL_FACTOR,
                                                  TO_DOUBLE(v1), 0.0));
        break;

      case EDJE_TWEEN_MODE_DIVISOR_INTERP:
        npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
                                                  ECORE_POS_MAP_DIVISOR_INTERP,
                                                  TO_DOUBLE(v1), TO_DOUBLE(v2)));
        break;

      case EDJE_TWEEN_MODE_BOUNCE:
        npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
                                                  ECORE_POS_MAP_BOUNCE,
                                                  TO_DOUBLE(v1), TO_DOUBLE(v2)));
        break;

      case EDJE_TWEEN_MODE_SPRING:
        npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
                                                  ECORE_POS_MAP_SPRING,
                                                  TO_DOUBLE(v1), TO_DOUBLE(v2)));
        break;

      case EDJE_TWEEN_MODE_CUBIC_BEZIER:
        v[0] = TO_DOUBLE(v1);
        v[1] = TO_DOUBLE(v2);
        v[2] = TO_DOUBLE(v3);
        v[3] = TO_DOUBLE(v4);

        npos = FROM_DOUBLE(ecore_animator_pos_map_n(TO_DOUBLE(pos),
                                                    ECORE_POS_MAP_CUBIC_BEZIER,
                                                    4, v));
        break;

      default:
        npos = fp_pos;
        break;
     }
#endif
   if (npos == ep->description_pos) return;

   ep->description_pos = npos;

   ed->dirty = EINA_TRUE;
   ed->recalc_call = EINA_TRUE;
#ifdef EDJE_CALC_CACHE
   ep->invalidate = EINA_TRUE;
#endif
}

/**
 * Returns part description
 *
 * @internal
 *
 * Converts part description to RTL-desc.
 *
 * @param desc Pointer to desc buffer.
 *
 **/
static void
_edje_part_make_rtl(Edje_Part_Description_Common *desc)
{
   double t;
   int i;

   if (!desc)
     return;

   /* This makes alignment right-oriented */
   desc->align.x = 1.0 - desc->align.x;

   /* same as above for relative components */
   t = desc->rel1.relative_x;
   desc->rel1.relative_x = 1.0 - desc->rel2.relative_x;
   desc->rel2.relative_x = 1.0 - t;

   /* +1 and +1 are because how edje works with right
    * side borders - nothing is printed beyond that limit
    *
    * rel2 is now to the left of rel1, and Edje assumes
    * the opposite so we switch corners on x-axis to define
    * offset from right to left */
   i = desc->rel1.offset_x;
   desc->rel1.offset_x = -(desc->rel2.offset_x + 1);
   desc->rel2.offset_x = -(i + 1);

   i = desc->rel1.id_x;
   desc->rel1.id_x = desc->rel2.id_x;
   desc->rel2.id_x = i;
}

/**
 * Returns part description
 *
 * @internal
 *
 * Returns part description according to object orientation.
 * When object is in RTL-orientation (RTL flag is set)
 * this returns the RTL-desc of it.
 * RTL-desc would be allocated if was not created by a previous call.
 * The dst pointer is updated in case of an allocation.
 *
 * @param ed Edje object.
 * @param src The Left To Right (LTR), original desc.
 * @param dst Pointer to Right To Left (RTL) desc-list.
 * @param type name of dec type. Example: "default".
 *
 * @return Edje part description.
 *
 **/
static Edje_Part_Description_Common *
_edje_get_description_by_orientation(Edje *ed, Edje_Part_Description_Common *src, Edje_Part_Description_Common **dst, unsigned char type)
{
   Edje_Part_Description_Common *desc_rtl = NULL;
   Edje_Part_Collection_Directory_Entry *ce;
   size_t memsize = 0;

   /* RTL flag is not set, return original description */
   if (!edje_object_mirrored_get(ed->obj))
     return src;

   if (*dst)
     return *dst;  /* Was allocated before and we should use it */

#define EDIT_ALLOC_POOL_RTL(Short, Type, Name)                        \
case EDJE_PART_TYPE_##Short:                                          \
{                                                                     \
   Edje_Part_Description_##Type * Name;                               \
   Name = eina_mempool_malloc(ce->mp_rtl.Short,                       \
                              sizeof (Edje_Part_Description_##Type)); \
   desc_rtl = &Name->common;                                          \
   memsize = sizeof(Edje_Part_Description_##Type);                    \
   break;                                                             \
}

   ce = eina_hash_find(ed->file->collection, ed->group);

   switch (type)
     {
      case EDJE_PART_TYPE_RECTANGLE:
        desc_rtl = eina_mempool_malloc(ce->mp_rtl.RECTANGLE,
                                       sizeof (Edje_Part_Description_Common));
        ce->count.RECTANGLE++;
        memsize = sizeof(Edje_Part_Description_Common);
        break;

      case EDJE_PART_TYPE_SNAPSHOT:
        desc_rtl = eina_mempool_malloc(ce->mp_rtl.SNAPSHOT,
                                       sizeof (Edje_Part_Description_Snapshot));
        ce->count.SNAPSHOT++;
        memsize = sizeof(Edje_Part_Description_Snapshot);
        break;

      case EDJE_PART_TYPE_SWALLOW:
        desc_rtl = eina_mempool_malloc(ce->mp_rtl.SWALLOW,
                                       sizeof (Edje_Part_Description_Common));
        ce->count.SWALLOW++;
        memsize = sizeof(Edje_Part_Description_Common);
        break;

      case EDJE_PART_TYPE_GROUP:
        desc_rtl = eina_mempool_malloc(ce->mp_rtl.GROUP,
                                       sizeof (Edje_Part_Description_Common));
        ce->count.GROUP++;
        memsize = sizeof(Edje_Part_Description_Common);
        break;

      case EDJE_PART_TYPE_SPACER:
        desc_rtl = eina_mempool_malloc(ce->mp_rtl.SPACER,
                                       sizeof (Edje_Part_Description_Common));
        ce->count.SPACER++;
        memsize = sizeof(Edje_Part_Description_Common);
        break;
        EDIT_ALLOC_POOL_RTL(TEXT, Text, text);
        EDIT_ALLOC_POOL_RTL(TEXTBLOCK, Text, text);
        EDIT_ALLOC_POOL_RTL(IMAGE, Image, image);
        EDIT_ALLOC_POOL_RTL(PROXY, Proxy, proxy);
        EDIT_ALLOC_POOL_RTL(BOX, Box, box);
        EDIT_ALLOC_POOL_RTL(TABLE, Table, table);
        EDIT_ALLOC_POOL_RTL(EXTERNAL, External, external_params);
        EDIT_ALLOC_POOL_RTL(CAMERA, Camera, camera);
        EDIT_ALLOC_POOL_RTL(LIGHT, Light, light);
        EDIT_ALLOC_POOL_RTL(MESH_NODE, Mesh_Node, mesh_node);
     }

   if (desc_rtl)
     memcpy(desc_rtl, src, memsize);

   _edje_part_make_rtl(desc_rtl);

   *dst = desc_rtl;
   return desc_rtl;
}

Edje_Part_Description_Common *
_edje_part_description_find(Edje *ed, Edje_Real_Part *rp, const char *state_name,
                            double state_val, Eina_Bool approximate)
{
   Edje_Part *ep = rp->part;
   Edje_Part_Description_Common *ret = NULL;
   Edje_Part_Description_Common *d;

   double min_dst = 99999.0;
   unsigned int i;

   /* RTL flag is set, return RTL description */
   if (edje_object_mirrored_get(ed->obj))
     if (!ep->other.desc_rtl)
       ep->other.desc_rtl = (Edje_Part_Description_Common **)
         calloc(ep->other.desc_count,
                sizeof (Edje_Part_Description_Common *));

   if (!strcmp(state_name, "default") && state_val == 0.0)
     return _edje_get_description_by_orientation(ed,
                                                 ep->default_desc, &ep->default_desc_rtl, ep->type);

   if (!strcmp(state_name, "custom"))
     return rp->custom ?
            _edje_get_description_by_orientation(ed, rp->custom->description,
                                                 &rp->custom->description_rtl, ep->type) : NULL;

   if (!strcmp(state_name, "default") && approximate)
     {
        ret = _edje_get_description_by_orientation(ed, ep->default_desc,
                                                   &ep->default_desc_rtl,
                                                   ep->type);

        min_dst = ABS(ep->default_desc->state.value - state_val);
     }

   for (i = 0; i < ep->other.desc_count; ++i)
     {
        d = ep->other.desc[i];

        if (d->state.name && (d->state.name == state_name ||
                              !strcmp(d->state.name, state_name)))
          {
             if (!approximate)
               {
                  if (d->state.value == state_val)
                    return _edje_get_description_by_orientation(ed, d,
                                                                &ep->other.desc_rtl[i], ep->type);
                  else
                    continue;
               }
             else
               {
                  double dst;

                  dst = ABS(d->state.value - state_val);
                  if (dst < min_dst)
                    {
                       ret = _edje_get_description_by_orientation(ed, d,
                                                                  &ep->other.desc_rtl[i], ep->type);
                       min_dst = dst;
                    }
               }
          }
     }

   return ret;
}

static int
_edje_image_find(Evas_Object *obj, Edje *ed, Edje_Real_Part_Set **eps,
                 Edje_Part_Description_Image *st, Edje_Part_Image_Id *imid)
{
   Edje_Image_Directory_Set_Entry *entry;
   Edje_Image_Directory_Set *set = NULL;
   Eina_List *l;
   int w = 0, h = 0, id;

   if (!st && !imid) return -1;
   if (st && !st->image.set) return st->image.id;
   if (imid && !imid->set) return imid->id;

   if (imid) id = imid->id;
   else id = st->image.id;

   evas_object_geometry_get(obj, NULL, NULL, &w, &h);
   if (eps && *eps)
     {
        if ((*eps)->id == id) set = (*eps)->set;
        if (set)
          {
             if (((*eps)->entry->size.min.w <= w) &&
                 (w <= (*eps)->entry->size.max.w))
               {
                  if (((*eps)->entry->size.min.h <= h) &&
                      (h <= (*eps)->entry->size.max.h))
                    {
                       return (*eps)->entry->id;
                    }
               }
          }
     }

   if (!set) set = ed->file->image_dir->sets + id;

   EINA_LIST_FOREACH(set->entries, l, entry)
     {
        if ((entry->size.min.w <= w) && (w <= entry->size.max.w))
          {
             if ((entry->size.min.h <= h) && (h <= entry->size.max.h))
               {
                  if (eps)
                    {
                       if (!*eps) *eps = calloc(1, sizeof(Edje_Real_Part_Set));
                       if (*eps)
                         {
                            (*eps)->entry = entry;
                            (*eps)->set = set;
                            (*eps)->id = id;
                         }
                    }
                  return entry->id;
               }
          }
     }

   entry = eina_list_data_get(set->entries);
   if (entry)
     {
        if (eps)
          {
             if (!*eps)
               *eps = calloc(1, sizeof (Edje_Real_Part_Set));
             if (*eps)
               {
                  (*eps)->entry = entry;
                  (*eps)->set = set;
                  (*eps)->id = id;
               }
          }
        return entry->id;
     }

   return -1;
}

static void
_edje_real_part_image_set(Edje *ed, Edje_Real_Part *ep, Edje_Real_Part_Set **set, FLOAT_T pos)
{
   int image_id;
   int image_count, image_num;

   image_id = _edje_image_find(ep->object, ed,
                               &ep->param1.set,
                               (Edje_Part_Description_Image *)ep->param1.description,
                               NULL);
   if (set) *set = ep->param1.set;
   if (image_id < 0)
     {
        Edje_Image_Directory_Entry *ie;

        if (!ed->file->image_dir) ie = NULL;
        else ie = ed->file->image_dir->entries + (-image_id) - 1;
        if ((ie) &&
            (ie->source_type == EDJE_IMAGE_SOURCE_TYPE_EXTERNAL) &&
            (ie->entry))
          {
             evas_object_image_file_set(ep->object, ie->entry, NULL);
          }
     }
   else
     {
        image_count = 2;
        if (ep->param2)
          image_count += ((Edje_Part_Description_Image *)ep->param2->description)->image.tweens_count;
        image_num = TO_INT(MUL(pos, SUB(FROM_INT(image_count),
                                        FROM_DOUBLE(0.5))));
        if (image_num > (image_count - 1))
          image_num = image_count - 1;
        if (image_num <= 0)
          {
             image_id = _edje_image_find(ep->object, ed,
                                         &ep->param1.set,
                                         (Edje_Part_Description_Image *)ep->param1.description,
                                         NULL);
             if (set) *set = ep->param1.set;
          }
        else
        if (ep->param2)
          {
             if (image_num == (image_count - 1))
               {
                  image_id = _edje_image_find(ep->object, ed,
                                              &ep->param2->set,
                                              (Edje_Part_Description_Image *)ep->param2->description,
                                              NULL);
                  if (set) *set = ep->param2->set;
               }
             else
               {
                  Edje_Part_Image_Id *imid;

                  imid = ((Edje_Part_Description_Image *)ep->param2->description)->image.tweens[image_num - 1];
                  image_id = _edje_image_find(ep->object, ed, NULL, NULL, imid);
                  if (set) *set = NULL;
               }
          }
        if (image_id < 0)
          {
             ERR("¨Part \"%s\" description, "
                 "\"%s\" %3.3f with image %i index has a missing image id in a set of %i !!!",
                 ep->part->name,
                 ep->param1.description->state.name,
                 ep->param1.description->state.value,
                 image_num,
                 image_count);
          }
        else
          {
             char buf[1024] = "edje/images/";

             /* Replace snprint("edje/images/%i") == memcpy + itoa */
             eina_convert_itoa(image_id, buf + 12); /* No need to check length as 2³² need only 10 characteres. */

             evas_object_image_mmap_set(ep->object, ed->file->f, buf);
             if (evas_object_image_load_error_get(ep->object) != EVAS_LOAD_ERROR_NONE)
               {
                  ERR("Error loading image collection \"%s\" from "
                      "file \"%s\". Missing EET Evas loader module?",
                      buf, ed->file->path);
                  switch (evas_object_image_load_error_get(ep->object))
                    {
                     case EVAS_LOAD_ERROR_GENERIC:
                       ERR("Error type: EVAS_LOAD_ERROR_GENERIC");
                       break;

                     case EVAS_LOAD_ERROR_DOES_NOT_EXIST:
                       ERR("Error type: EVAS_LOAD_ERROR_DOES_NOT_EXIST");
                       break;

                     case EVAS_LOAD_ERROR_PERMISSION_DENIED:
                       ERR("Error type: EVAS_LOAD_ERROR_PERMISSION_DENIED");
                       break;

                     case EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED:
                       ERR("Error type: EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED");
                       break;

                     case EVAS_LOAD_ERROR_CORRUPT_FILE:
                       ERR("Error type: EVAS_LOAD_ERROR_CORRUPT_FILE");
                       break;

                     case EVAS_LOAD_ERROR_UNKNOWN_FORMAT:
                       ERR("Error type: EVAS_LOAD_ERROR_UNKNOWN_FORMAT");
                       break;

                     default:
                       ERR("Error type: ???");
                       break;
                    }
               }
          }
     }
}

static void
_edje_real_part_rel_to_apply(Edje *ed EINA_UNUSED,
                             Edje_Real_Part *ep,
                             Edje_Real_Part_State *state)
{
   if (state->description)
     {
        if (ep->part->type == EDJE_PART_TYPE_EXTERNAL)
          {
             Edje_Part_Description_External *external;

             if ((ep->type != EDJE_RP_TYPE_SWALLOW) ||
                 (!ep->typedata.swallow)) return;

             external = (Edje_Part_Description_External *)state->description;

             if (state->external_params)
               _edje_external_parsed_params_free(ep->typedata.swallow->swallowed_object, state->external_params);
             state->external_params = _edje_external_params_parse(ep->typedata.swallow->swallowed_object, external->external_params);
          }
     }
}

void
_edje_part_description_apply(Edje *ed, Edje_Real_Part *ep, const char *d1, double v1, const char *d2, double v2)
{
   Edje_Part_Description_Common *epd1;
   Edje_Part_Description_Common *epd2 = NULL;
   Edje_Part_Description_Common *last_desc;
   Eina_Bool change_w, change_h;
   Edje_Part_Description_Image *epdi;

   if (!d1) d1 = "default";

   epd1 = _edje_part_description_find(ed, ep, d1, v1, EINA_TRUE);
   if (!epd1)
     epd1 = ep->part->default_desc;  /* never NULL */

   if (d2)
     epd2 = _edje_part_description_find(ed, ep, d2, v2, EINA_TRUE);

   epdi = (Edje_Part_Description_Image *)epd2;
   /* There is an animation if both description are different or if description is an image with tweens */
   if (epd2 && (epd1 != epd2 || (ep->part->type == EDJE_PART_TYPE_IMAGE && epdi->image.tweens_count)))
     {
        if (!ep->param2)
          {
             ep->param2 = eina_mempool_malloc(_edje_real_part_state_mp,
                                              sizeof(Edje_Real_Part_State));
             memset(ep->param2, 0, sizeof(Edje_Real_Part_State));
             ep->param2->p.map = eina_cow_alloc(_edje_calc_params_map_cow);
#ifdef HAVE_EPHYSICS
             ep->param2->p.physics = eina_cow_alloc(_edje_calc_params_physics_cow);
#endif
          }
        else if (ep->part->type == EDJE_PART_TYPE_EXTERNAL)
          {
             if ((ep->type == EDJE_RP_TYPE_SWALLOW) &&
                 (ep->typedata.swallow))
               _edje_external_parsed_params_free(ep->typedata.swallow->swallowed_object,
                                                 ep->param2->external_params);
          }
        ep->param2->external_params = NULL;
     }
   else
   if (ep->param2)
     {
        if (ep->part->type == EDJE_PART_TYPE_EXTERNAL)
          {
             if ((ep->type == EDJE_RP_TYPE_SWALLOW) &&
                 (ep->typedata.swallow))
               _edje_external_parsed_params_free(ep->typedata.swallow->swallowed_object,
                                                 ep->param2->external_params);
          }
        if (ep->param2)
          {
             free(ep->param2->set);
             eina_cow_free(_edje_calc_params_map_cow, (const Eina_Cow_Data **)&ep->param2->p.map);
#ifdef HAVE_EPHYSICS
             eina_cow_free(_edje_calc_params_physics_cow, (const Eina_Cow_Data **)&ep->param2->p.physics);
#endif
          }
        eina_mempool_free(_edje_real_part_state_mp, ep->param2);
        ep->param2 = NULL;
     }

   last_desc = ep->chosen_description;
   ep->param1.description = epd1;
   ep->chosen_description = epd1;
   if (last_desc)
     {
        change_w = ep->chosen_description->fixed.w != last_desc->fixed.w;
        change_h = ep->chosen_description->fixed.h != last_desc->fixed.h;
     }
   _edje_real_part_rel_to_apply(ed, ep, &ep->param1);

   if (ep->param2)
     {
        ep->param2->description = epd2;

        _edje_real_part_rel_to_apply(ed, ep, ep->param2);

        if (ep->description_pos > FROM_DOUBLE(0.0))
          ep->chosen_description = epd2;
     }

   if (last_desc != ep->chosen_description)
     {
        if (ep->part->type == EDJE_PART_TYPE_EXTERNAL)
          _edje_external_recalc_apply(ed, ep, NULL, last_desc);
        else if ((last_desc) && (ep->part->type == EDJE_PART_TYPE_GROUP))
          {
             Edje_Size *min, *max, *pmin, *pmax;

             min = &ep->chosen_description->min;
             max = &ep->chosen_description->max;
             pmin = &last_desc->min;
             pmax = &last_desc->max;
             if (change_w || change_h ||
                 (((pmin->w == pmax->w) && (pmin->h == pmax->h) && (pmin->w > 0) && (pmin->h > 0)) &&
                  (((min->w != max->w) || (min->h != max->h) || (min->w <= 0) || (min->h <= 0)))))
               {
                  Edje *ted;

                  ted = _edje_fetch(ep->typedata.swallow->swallowed_object);
                  ted->recalc_call = ted->dirty = ted->recalc_hints = EINA_TRUE;
                  _edje_recalc(ted);
               }
          }
     }

   ed->recalc_hints = EINA_TRUE;
   ed->dirty = EINA_TRUE;
   ed->recalc_call = EINA_TRUE;
#ifdef EDJE_CALC_CACHE
   ep->invalidate = EINA_TRUE;
#endif
}

void
_edje_recalc(Edje *ed)
{
   if ((ed->freeze > 0) || (_edje_util_freeze_val > 0))
     {
        ed->recalc = EINA_TRUE;
        if (!ed->calc_only)
          {
             if (_edje_util_freeze_val > 0)
               {
                  if (!ed->freeze_calc)
                    {
                       _edje_util_freeze_calc_count++;
                       _edje_util_freeze_calc_list = eina_list_append(_edje_util_freeze_calc_list, ed);
                       ed->freeze_calc = EINA_TRUE;
                    }
               }
             return;
          }
     }
// XXX: dont need this with current smart calc infra. remove me later
//   if (ed->postponed) return;
//   if (!ed->calc_only)
   evas_object_smart_changed(ed->obj);
// XXX: dont need this with current smart calc infra. remove me later
//   ed->postponed = EINA_TRUE;
}

void
_edje_recalc_do(Edje *ed)
{
   unsigned int i;
   Eina_Bool need_calc;

// XXX: dont need this with current smart calc infra. remove me later
//   ed->postponed = EINA_FALSE;
   need_calc = evas_object_smart_need_recalculate_get(ed->obj);
   evas_object_smart_need_recalculate_set(ed->obj, 0);
   if (!ed->dirty) return;
   ed->dirty = EINA_FALSE;
   ed->state++;
   for (i = 0; i < ed->table_parts_size; i++)
     {
        Edje_Real_Part *ep;

        ep = ed->table_parts[i];
        ep->calculated = FLAG_NONE; // FIXME: this is dubious (see below)
        ep->calculating = FLAG_NONE;
     }
   for (i = 0; i < ed->table_parts_size; i++)
     {
        Edje_Real_Part *ep;

        ep = ed->table_parts[i];
        if (ep->calculated != FLAG_XY) // FIXME: this is always true (see for above)
          _edje_part_recalc(ed, ep, (~ep->calculated) & FLAG_XY, NULL);
     }
   if (!ed->calc_only) ed->recalc = EINA_FALSE;
#ifdef EDJE_CALC_CACHE
   ed->all_part_change = EINA_FALSE;
   ed->text_part_change = EINA_FALSE;
#endif
   if (!ed->calc_only)
     {
        if (ed->recalc_call)
          eo_do(ed->obj, eo_event_callback_call(EDJE_OBJECT_EVENT_RECALC, NULL));
     }
   else
     evas_object_smart_need_recalculate_set(ed->obj, need_calc);
   ed->recalc_call = EINA_FALSE;

   if (ed->update_hints && ed->recalc_hints && !ed->calc_only)
     {
        Evas_Coord w, h;

        ed->recalc_hints = EINA_FALSE;

        eo_do(ed->obj, edje_obj_size_min_calc(&w, &h));
        eo_do(ed->obj, evas_obj_size_hint_min_set(w, h));
     }

   if (!ed->collection) return;

   for (i = 0; i < ed->collection->limits.parts_count; i++)
     {
        const char *name;
        unsigned char limit;
        int part;

        part = ed->collection->limits.parts[i].part;
        name = ed->collection->parts[part]->name;
        limit = ed->table_parts[part]->chosen_description->limit;
        switch (limit)
          {
           case 0:
             ed->collection->limits.parts[i].width = EDJE_PART_LIMIT_UNKNOWN;
             ed->collection->limits.parts[i].height = EDJE_PART_LIMIT_UNKNOWN;
             break;

           case 1:
             ed->collection->limits.parts[i].height = EDJE_PART_LIMIT_UNKNOWN;
             break;

           case 2:
             ed->collection->limits.parts[i].width = EDJE_PART_LIMIT_UNKNOWN;
             break;

           case 3:
             break;
          }

        if ((limit & 1) == 1)
          {
             if (ed->table_parts[part]->w > 0 &&
                 (ed->collection->limits.parts[i].width != EDJE_PART_LIMIT_OVER))
               {
                  ed->collection->limits.parts[i].width = EDJE_PART_LIMIT_OVER;
                  _edje_emit(ed, "limit,width,over", name);
               }
             else if (ed->table_parts[part]->w < 0 &&
                      ed->collection->limits.parts[i].width != EDJE_PART_LIMIT_BELOW)
               {
                  ed->collection->limits.parts[i].width = EDJE_PART_LIMIT_BELOW;
                  _edje_emit(ed, "limit,width,below", name);
               }
             else if (ed->table_parts[part]->w == 0 &&
                      ed->collection->limits.parts[i].width != EDJE_PART_LIMIT_ZERO)
               {
                  ed->collection->limits.parts[i].width = EDJE_PART_LIMIT_ZERO;
                  _edje_emit(ed, "limit,width,zero", name);
               }
          }
        if ((limit & 2) == 2)
          {
             if (ed->table_parts[part]->h > 0 &&
                 (ed->collection->limits.parts[i].height != EDJE_PART_LIMIT_OVER))
               {
                  ed->collection->limits.parts[i].height = EDJE_PART_LIMIT_OVER;
                  _edje_emit(ed, "limit,height,over", name);
               }
             else if (ed->table_parts[part]->h < 0 &&
                      ed->collection->limits.parts[i].height != EDJE_PART_LIMIT_BELOW)
               {
                  ed->collection->limits.parts[i].height = EDJE_PART_LIMIT_BELOW;
                  _edje_emit(ed, "limit,height,below", name);
               }
             else if (ed->table_parts[part]->h == 0 &&
                      ed->collection->limits.parts[i].height != EDJE_PART_LIMIT_ZERO)
               {
                  ed->collection->limits.parts[i].height = EDJE_PART_LIMIT_ZERO;
                  _edje_emit(ed, "limit,height,zero", name);
               }
          }
     }
}

int
_edje_part_dragable_calc(Edje *ed EINA_UNUSED, Edje_Real_Part *ep, FLOAT_T *x, FLOAT_T *y)
{
   if (ep->drag)
     {
        Eina_Bool tx = EINA_FALSE;
        Eina_Bool ty = EINA_FALSE;

        if (ep->drag->threshold)
          {
             // Check if we are in the threshold or not and cancel the movement.
             tx = ep->drag->threshold_x && ep->drag->threshold_started_x;
             ty = ep->drag->threshold_y && ep->drag->threshold_started_y;
          }
        if (ep->drag->confine_to)
          {
             FLOAT_T dx, dy, dw, dh;
             int ret = 0;

             if ((ep->part->dragable.x != 0) &&
                 (ep->part->dragable.y != 0)) ret = 3;
             else if (ep->part->dragable.x != 0)
               ret = 1;
             else if (ep->part->dragable.y != 0)
               ret = 2;

             dx = FROM_INT(ep->x - ep->drag->confine_to->x);
             dw = FROM_INT(ep->drag->confine_to->w - ep->w);
             if (dw != ZERO) dx = DIV(dx, dw);
             else dx = ZERO;

             dy = FROM_INT(ep->y - ep->drag->confine_to->y);
             dh = FROM_INT(ep->drag->confine_to->h - ep->h);
             if (dh != ZERO) dy = DIV(dy, dh);
             else dy = ZERO;

             if (x) *x = tx ? ep->drag->x : dx;
             if (y) *y = ty ? ep->drag->y : dy;

             return ret;
          }
        else
          {
             if (x) *x = tx ? ep->drag->x : ADD(FROM_INT(ep->drag->tmp.x), ep->drag->x);
             if (y) *y = ty ? ep->drag->y : ADD(FROM_INT(ep->drag->tmp.y), ep->drag->y);
             return 0;
          }
     }
   if (x) *x = ZERO;
   if (y) *y = ZERO;
   return 0;
}

void
_edje_dragable_pos_set(Edje *ed, Edje_Real_Part *ep, FLOAT_T x, FLOAT_T y)
{
   /* check whether this part is dragable at all */
   if (!ep->drag) return;

   /* instead of checking for equality, we really should check that
    * the difference is greater than foo, but I have no idea what
    * value we would set foo to, because it would depend on the
    * size of the dragable...
    */
   if (ep->drag->x != x || ep->drag->tmp.x)
     {
        ep->drag->x = x;
        ep->drag->tmp.x = 0;
        ep->drag->need_reset = 0;
        ed->dirty = EINA_TRUE;
        ed->recalc_call = EINA_TRUE;
     }

   if (ep->drag->y != y || ep->drag->tmp.y)
     {
        ep->drag->y = y;
        ep->drag->tmp.y = 0;
        ep->drag->need_reset = 0;
        ed->dirty = EINA_TRUE;
        ed->recalc_call = EINA_TRUE;
     }

#ifdef EDJE_CALC_CACHE
   ep->invalidate = EINA_TRUE;
#endif
   _edje_recalc(ed); /* won't do anything if dirty flag isn't set */
}

static void
_edje_part_recalc_single_rel(Edje *ed,
                             Edje_Real_Part *ep EINA_UNUSED,
                             Edje_Part_Description_Common *desc,
                             Edje_Real_Part *rel1_to_x,
                             Edje_Real_Part *rel1_to_y,
                             Edje_Real_Part *rel2_to_x,
                             Edje_Real_Part *rel2_to_y,
                             Edje_Calc_Params *params)
{
   FLOAT_T x, w;
   FLOAT_T y, h;

   if (rel1_to_x)
     x = ADD(FROM_INT(desc->rel1.offset_x + rel1_to_x->x),
             SCALE(desc->rel1.relative_x, rel1_to_x->w));
   else
     x = ADD(FROM_INT(desc->rel1.offset_x),
             SCALE(desc->rel1.relative_x, ed->w));
   params->eval.x = x;

   if (rel2_to_x)
     w = ADD(SUB(ADD(FROM_INT(desc->rel2.offset_x + rel2_to_x->x),
                     SCALE(desc->rel2.relative_x, rel2_to_x->w)),
                 x),
             FROM_INT(1));
   else
     w = ADD(SUB(ADD(FROM_INT(desc->rel2.offset_x),
                     SCALE(desc->rel2.relative_x, ed->w)),
                 x),
             FROM_INT(1));
   params->eval.w = w;

   if (rel1_to_y)
     y = ADD(FROM_INT(desc->rel1.offset_y + rel1_to_y->y),
             SCALE(desc->rel1.relative_y, rel1_to_y->h));
   else
     y = ADD(FROM_INT(desc->rel1.offset_y),
             SCALE(desc->rel1.relative_y, ed->h));
   params->eval.y = y;

   if (rel2_to_y)
     h = ADD(SUB(ADD(FROM_INT(desc->rel2.offset_y + rel2_to_y->y),
                     SCALE(desc->rel2.relative_y, rel2_to_y->h)),
                 y),
             FROM_INT(1));
   else
     h = ADD(SUB(ADD(FROM_INT(desc->rel2.offset_y),
                     SCALE(desc->rel2.relative_y, ed->h)),
                 y),
             FROM_INT(1));
   params->eval.h = h;
}

static Edje_Internal_Aspect
_edje_part_recalc_single_aspect(Edje *ed,
                                Edje_Real_Part *ep,
                                Edje_Part_Description_Common *desc,
                                Edje_Calc_Params *params,
                                int *minw, int *minh,
                                int *maxw, int *maxh,
                                FLOAT_T pos)
{
   Edje_Internal_Aspect apref = EDJE_ASPECT_PREFER_NONE;
   FLOAT_T aspect, amax, amin;
   FLOAT_T new_w = ZERO, new_h = ZERO, want_x, want_y, want_w, want_h;

   if (params->eval.h <= ZERO) aspect = FROM_INT(999999);
   else aspect = DIV(params->eval.w, params->eval.h);
   amax = desc->aspect.max;
   amin = desc->aspect.min;
   if (desc->aspect.prefer == EDJE_ASPECT_PREFER_SOURCE &&
       ep->part->type == EDJE_PART_TYPE_IMAGE)
     {
        Evas_Coord w, h;

        /* We only need pose to find the right image that would be displayed,
           and the right aspect ratio in that case */
        _edje_real_part_image_set(ed, ep, NULL, pos);
        evas_object_image_size_get(ep->object, &w, &h);
        amin = amax = DIV(FROM_INT(w), FROM_INT(h));
     }
   if ((ep->type == EDJE_RP_TYPE_SWALLOW) &&
       (ep->typedata.swallow))
     {
        if ((ep->typedata.swallow->swallow_params.aspect.w > 0) &&
            (ep->typedata.swallow->swallow_params.aspect.h > 0))
          amin = amax =
              DIV(FROM_INT(ep->typedata.swallow->swallow_params.aspect.w),
                  FROM_INT(ep->typedata.swallow->swallow_params.aspect.h));
     }
   want_x = params->eval.x;
   want_w = new_w = params->eval.w;

   want_y = params->eval.y;
   want_h = new_h = params->eval.h;

   if ((amin > ZERO) && (amax > ZERO))
     {
        apref = desc->aspect.prefer;
        if ((ep->type == EDJE_RP_TYPE_SWALLOW) &&
            (ep->typedata.swallow))
          {
             if (ep->typedata.swallow->swallow_params.aspect.mode > EDJE_ASPECT_CONTROL_NONE)
               {
                  switch (ep->typedata.swallow->swallow_params.aspect.mode)
                    {
                     case EDJE_ASPECT_CONTROL_NEITHER:
                       apref = EDJE_ASPECT_PREFER_NONE;
                       break;

                     case EDJE_ASPECT_CONTROL_HORIZONTAL:
                       apref = EDJE_ASPECT_PREFER_HORIZONTAL;
                       break;

                     case EDJE_ASPECT_CONTROL_VERTICAL:
                       apref = EDJE_ASPECT_PREFER_VERTICAL;
                       break;

                     case EDJE_ASPECT_CONTROL_BOTH:
                       apref = EDJE_ASPECT_PREFER_BOTH;
                       break;

                     default:
                       break;
                    }
               }
          }
        switch (apref)
          {
           case EDJE_ASPECT_PREFER_NONE:
             /* keep both dimensions in check */
             /* adjust for min aspect (width / height) */
             if ((amin > ZERO) && (aspect < amin))
               {
                  new_h = DIV(params->eval.w, amin);
                  new_w = MUL(amin, params->eval.h);
               }
             /* adjust for max aspect (width / height) */
             if ((amax > ZERO) && (aspect > amax))
               {
                  new_h = DIV(params->eval.w, amax);
                  new_w = MUL(amax, params->eval.h);
               }
             if ((amax > ZERO) && (new_w < params->eval.w))
               {
                  new_w = params->eval.w;
                  new_h = DIV(params->eval.w, amax);
               }
             if ((amax > ZERO) && (new_h < params->eval.h))
               {
                  new_w = MUL(amax, params->eval.h);
                  new_h = params->eval.h;
               }
             break;

           /* prefer vertical size as determiner */
           case  EDJE_ASPECT_PREFER_VERTICAL:
             /* keep both dimensions in check */
             /* adjust for max aspect (width / height) */
             if ((amax > ZERO) && (aspect > amax))
               new_w = MUL(amax, params->eval.h);
             /* adjust for min aspect (width / height) */
             if ((amin > ZERO) && (aspect < amin))
               new_w = MUL(amin, params->eval.h);
             break;

           /* prefer horizontal size as determiner */
           case EDJE_ASPECT_PREFER_HORIZONTAL:
             /* keep both dimensions in check */
             /* adjust for max aspect (width / height) */
             if ((amax > ZERO) && (aspect > amax))
               new_h = DIV(params->eval.w, amax);
             /* adjust for min aspect (width / height) */
             if ((amin > ZERO) && (aspect < amin))
               new_h = DIV(params->eval.w, amin);
             break;

           case EDJE_ASPECT_PREFER_SOURCE:
           case EDJE_ASPECT_PREFER_BOTH:
             /* keep both dimensions in check */
             /* adjust for max aspect (width / height) */
             if ((amax > ZERO) && (aspect > amax))
               {
                  new_w = MUL(amax, params->eval.h);
                  new_h = DIV(params->eval.w, amax);
               }
             /* adjust for min aspect (width / height) */
             if ((amin > ZERO) && (aspect < amin))
               {
                  new_w = MUL(amin, params->eval.h);
                  new_h = DIV(params->eval.w, amin);
               }
             break;

           default:
             break;
          }

        if (!((amin > ZERO) && (amax > ZERO) &&
              (apref == EDJE_ASPECT_PREFER_NONE)))
          {
             if ((*maxw >= 0) && (new_w > FROM_INT(*maxw)))
               new_w = FROM_INT(*maxw);
             if (new_w < FROM_INT(*minw))
               new_w = FROM_INT(*minw);

             if ((FROM_INT(*maxh) >= 0) && (new_h > FROM_INT(*maxh)))
               new_h = FROM_INT(*maxh);
             if (new_h < FROM_INT(*minh))
               new_h = FROM_INT(*minh);
          }

        /* do real adjustment */
        if (apref == EDJE_ASPECT_PREFER_BOTH)
          {
             if (amin == ZERO) amin = amax;
             if (amin != ZERO)
               {
                  /* fix h and vary w */
                  if (new_w > params->eval.w)
                    {
                       //		  params->w = new_w;
                       // EXCEEDS BOUNDS in W
                       new_h = DIV(params->eval.w, amin);
                       new_w = params->eval.w;
                       if (new_h > params->eval.h)
                         {
                            new_h = params->eval.h;
                            new_w = MUL(amin, params->eval.h);
                         }
                    }
                  /* fix w and vary h */
                  else
                    {
                       //		  params->h = new_h;
                       // EXCEEDS BOUNDS in H
                       new_h = params->eval.h;
                       new_w = MUL(amin, params->eval.h);
                       if (new_w > params->eval.w)
                         {
                            new_h = DIV(params->eval.w, amin);
                            new_w = params->eval.w;
                         }
                    }
                  params->eval.w = new_w;
                  params->eval.h = new_h;
               }
          }
     }
   if (apref != EDJE_ASPECT_PREFER_BOTH)
     {
        if ((amin > 0.0) && (amax > ZERO) && (apref == EDJE_ASPECT_PREFER_NONE))
          {
             params->eval.w = new_w;
             params->eval.h = new_h;
          }
        else if (SUB(params->eval.h, new_h) > SUB(params->eval.w, new_w))
          {
             if (params->eval.h < new_h)
               params->eval.h = new_h;
             else if (params->eval.h > new_h)
               params->eval.h = new_h;
             if (apref == EDJE_ASPECT_PREFER_VERTICAL)
               params->eval.w = new_w;
          }
        else
          {
             if (params->eval.w < new_w)
               params->eval.w = new_w;
             else if (params->eval.w > new_w)
               params->eval.w = new_w;
             if (apref == EDJE_ASPECT_PREFER_HORIZONTAL)
               params->eval.h = new_h;
          }
     }

   params->eval.x = ADD(want_x,
                        MUL(SUB(want_w, params->eval.w),
                            desc->align.x));
   params->eval.y = ADD(want_y,
                        MUL(SUB(want_h, params->eval.h),
                            desc->align.y));
   return apref;
}

static void
_edje_part_recalc_single_step(Edje_Part_Description_Common *desc,
                              Edje_Calc_Params *params)
{
   if (desc->step.x > 0)
     {
        int steps;
        int new_w;

        steps = TO_INT(params->eval.w) / desc->step.x;
        new_w = desc->step.x * steps;
        if (params->eval.w > FROM_INT(new_w))
          {
             params->eval.x = ADD(params->eval.x, SCALE(desc->align.x, SUB(params->eval.w, FROM_INT(new_w))));
             params->eval.w = FROM_INT(new_w);
          }
     }

   if (desc->step.y > 0)
     {
        int steps;
        int new_h;

        steps = TO_INT(params->eval.h) / desc->step.y;
        new_h = desc->step.y * steps;
        if (params->eval.h > FROM_INT(new_h))
          {
             params->eval.y = ADD(params->eval.y, SCALE(desc->align.y, SUB(params->eval.h, FROM_INT(new_h))));
             params->eval.h = FROM_INT(new_h);
          }
     }
}

static double
_edje_part_recalc_single_textblock_scale_range_adjust(Edje_Part_Description_Text *chosen_desc, double base_scale, double scale)
{
   double size, min, max;

   if (chosen_desc->text.size == 0)
     return scale;

   min = base_scale * chosen_desc->text.size_range_min;
   max = chosen_desc->text.size_range_max * base_scale;
   size = chosen_desc->text.size * scale;

   if ((size > max) && (max > 0))
     scale = max / (double)chosen_desc->text.size;
   else if (size < min)
     scale = min / (double)chosen_desc->text.size;

   return scale;
}

static void
_edje_part_recalc_single_textblock(FLOAT_T sc,
                                   Edje *ed,
                                   Edje_Real_Part *ep,
                                   Edje_Part_Description_Text *chosen_desc,
                                   Edje_Calc_Params *params,
                                   int *minw, int *minh,
                                   int *maxw, int *maxh)
{
   if ((ep->type != EDJE_RP_TYPE_TEXT) ||
       (!ep->typedata.text))
     return;
   if (chosen_desc)
     {
        Evas_Coord tw, th, ins_l, ins_r, ins_t, ins_b;
        const char *text = "";
        const char *style = "";
        Edje_Style *stl = NULL;
        const char *tmp;
        Eina_List *l;

        if (chosen_desc->text.id_source >= 0)
          {
             Edje_Part_Description_Text *et;

             ep->typedata.text->source = ed->table_parts[chosen_desc->text.id_source % ed->table_parts_size];

             et = _edje_real_part_text_source_description_get(ep, NULL);
             tmp = edje_string_get(&et->text.style);
             if (tmp) style = tmp;
          }
        else
          {
             ep->typedata.text->source = NULL;

             tmp = edje_string_get(&chosen_desc->text.style);
             if (tmp) style = tmp;
          }

        if (chosen_desc->text.id_text_source >= 0)
          {
             Edje_Part_Description_Text *et;
             Edje_Real_Part *rp;

             ep->typedata.text->text_source = ed->table_parts[chosen_desc->text.id_text_source % ed->table_parts_size];

             et = _edje_real_part_text_text_source_description_get(ep, &rp);
             text = edje_string_get(&et->text.text);

             if (rp->typedata.text->text) text = rp->typedata.text->text;
          }
        else
          {
             ep->typedata.text->text_source = NULL;
             text = edje_string_get(&chosen_desc->text.text);
             if (ep->typedata.text->text) text = ep->typedata.text->text;
          }

        EINA_LIST_FOREACH(ed->file->styles, l, stl)
          {
             if ((stl->name) && (!strcmp(stl->name, style))) break;
             stl = NULL;
          }

        if (ep->part->scale)
          evas_object_scale_set(ep->object, TO_DOUBLE(sc));

        if ((chosen_desc->text.fit_x) || (chosen_desc->text.fit_y))
          {
             double base_s = 1.0;
             double orig_s;
             double s = base_s;

             if (ep->part->scale) base_s = TO_DOUBLE(sc);
             eo_do(ep->object,
                   evas_obj_scale_set(base_s),
                   evas_obj_textblock_size_native_get(&tw, &th));

             orig_s = base_s;
             /* Now make it bigger so calculations will be more accurate
              * and less influenced by hinting... */
             {
                orig_s = _edje_part_recalc_single_textblock_scale_range_adjust(chosen_desc, base_s,
                                                                               orig_s * TO_INT(params->eval.w) / tw);
                eo_do(ep->object,
                      evas_obj_scale_set(orig_s),
                      evas_obj_textblock_size_native_get(&tw, &th));
             }
             if (chosen_desc->text.fit_x)
               {
                  if (tw > 0)
                    {
                       s = _edje_part_recalc_single_textblock_scale_range_adjust(chosen_desc, base_s,
                                                                                 orig_s * TO_INT(params->eval.w) / tw);
                       eo_do(ep->object,
                             evas_obj_scale_set(s),
                             evas_obj_textblock_size_native_get(NULL, NULL));
                    }
               }
             if (chosen_desc->text.fit_y)
               {
                  if (th > 0)
                    {
                       double tmp_s = _edje_part_recalc_single_textblock_scale_range_adjust(chosen_desc, base_s,
                                                                                            orig_s * TO_INT(params->eval.h) / th);
                       /* If we already have X fit, restrict Y to be no bigger
                        * than what we got with X. */
                       if (!((chosen_desc->text.fit_x) && (tmp_s > s)))
                         {
                            s = tmp_s;
                         }

                       eo_do(ep->object,
                             evas_obj_scale_set(s),
                             evas_obj_textblock_size_native_get(NULL, NULL));
                    }
               }

             /* Final tuning, try going down 90% at a time, hoping it'll
              * actually end up being correct. */
             {
                int i = 5;   /* Tries before we give up. */
                Evas_Coord fw, fh;
                eo_do(ep->object,
                      evas_obj_textblock_size_native_get(&fw, &fh));

                /* If we are still too big, try reducing the size to
                 * 95% each try. */
                while ((i > 0) &&
                       ((chosen_desc->text.fit_x && (fw > TO_INT(params->eval.w))) ||
                        (chosen_desc->text.fit_y && (fh > TO_INT(params->eval.h)))))
                  {
                     double tmp_s = _edje_part_recalc_single_textblock_scale_range_adjust(chosen_desc, base_s, s * 0.95);

                     /* Break if we are not making any progress. */
                     if (tmp_s == s)
                       break;
                     s = tmp_s;

                     eo_do(ep->object,
                           evas_obj_scale_set(s),
                           evas_obj_textblock_size_native_get(&fw, &fh));
                     i--;
                  }
             }
          }

        if (stl)
          {
             const char *ptxt;

             if (evas_object_textblock_style_get(ep->object) != stl->style)
               evas_object_textblock_style_set(ep->object, stl->style);
             // FIXME: need to account for editing
             if (ep->part->entry_mode > EDJE_ENTRY_EDIT_MODE_NONE)
               {
                  // do nothing - should be done elsewhere
               }
             else
               {
                  ptxt = evas_object_textblock_text_markup_get(ep->object);
                  if (((!ptxt) && (text)) ||
                      ((ptxt) && (text) && (strcmp(ptxt, text))) ||
                      ((ptxt) && (!text)))
                    evas_object_textblock_text_markup_set(ep->object, text);
               }
             if ((chosen_desc->text.min_x) || (chosen_desc->text.min_y))
               {
                  int mw = 0, mh = 0;

                  tw = th = 0;
                  if (!chosen_desc->text.min_x)
                    {
                       eo_do(ep->object,
                             efl_gfx_size_set(TO_INT(params->eval.w), TO_INT(params->eval.h)),
                             evas_obj_textblock_size_formatted_get(&tw, &th));
                    }
                  else
                    evas_object_textblock_size_native_get(ep->object, &tw, &th);
                  evas_object_textblock_style_insets_get(ep->object, &ins_l,
                                                         &ins_r, &ins_t, &ins_b);
                  mw = ins_l + tw + ins_r;
                  mh = ins_t + th + ins_b;
                  if (minw && chosen_desc->text.min_x)
                    {
                       if (mw > *minw) *minw = mw;
                    }
                  if (minh && chosen_desc->text.min_y)
                    {
                       if (mh > *minh) *minh = mh;
                    }
               }
          }

        if ((chosen_desc->text.max_x) || (chosen_desc->text.max_y))
          {
             int mw = 0, mh = 0;

             tw = th = 0;
             if (!chosen_desc->text.max_x)
               {
                  eo_do(ep->object,
                        efl_gfx_size_set(TO_INT(params->eval.w), TO_INT(params->eval.h)),
                        evas_obj_textblock_size_formatted_get(&tw, &th));
               }
             else
               evas_object_textblock_size_native_get(ep->object, &tw, &th);
             evas_object_textblock_style_insets_get(ep->object, &ins_l, &ins_r,
                                                    &ins_t, &ins_b);
             mw = ins_l + tw + ins_r;
             mh = ins_t + th + ins_b;
             if (maxw && chosen_desc->text.max_x)
               {
                  if (mw > *maxw) *maxw = mw;
                  if (minw && (*maxw < *minw)) *maxw = *minw;
               }
             if (maxh && chosen_desc->text.max_y)
               {
                  if (mh > *maxh) *maxh = mh;
                  if (minh && (*maxh < *minh)) *maxh = *minh;
               }
          }

        evas_object_textblock_valign_set(ep->object, TO_DOUBLE(chosen_desc->text.align.y));
     }
}

static void
_edje_textblock_recalc_apply(Edje *ed, Edje_Real_Part *ep,
                             Edje_Calc_Params *params,
                             Edje_Part_Description_Text *chosen_desc)
{
   /* FIXME: this is just an hack. */
   FLOAT_T sc;
   sc = DIV(ed->scale, ed->file->base_scale);
   if (sc == ZERO) sc = DIV(_edje_scale, ed->file->base_scale);
   if (chosen_desc->text.fit_x || chosen_desc->text.fit_y)
     {
        _edje_part_recalc_single_textblock(sc, ed, ep, chosen_desc, params,
                                           NULL, NULL, NULL, NULL);
     }
}

static void
_edje_part_recalc_single_text(FLOAT_T sc EINA_UNUSED,
                              Edje *ed,
                              Edje_Real_Part *ep,
                              Edje_Part_Description_Text *desc,
                              Edje_Part_Description_Text *chosen_desc,
                              Edje_Calc_Params *params,
                              int *minw, int *minh,
                              int *maxw, int *maxh)
#define RECALC_SINGLE_TEXT_USING_APPLY 1
#if RECALC_SINGLE_TEXT_USING_APPLY
/*
 * XXX TODO NOTE:
 *
 * Original _edje_part_recalc_single_text() was not working as
 * expected since it was not doing size fit, range, ellipsis and so
 * on.
 *
 * The purpose of this function compared with
 * _edje_text_recalc_apply() is to be faster, not calling Evas update
 * functions. However for text this is quite difficult given that to
 * fit we need to set the font, size, style, etc. If it was done
 * correctly, we'd save some calls to move and some color sets,
 * however those shouldn't matter much in the overall picture.
 *
 * I've changed this to force applying the value, it should be more
 * correct and not so slow. The previous code is kept below for
 * reference but should be removed before next release!
 *
 * -- Gustavo Barbieri at 20-Aug-2011
 */
{
   int mw, mh, size;
   char *sfont = NULL;

   _edje_text_class_font_get(ed, desc, &size, &sfont);
   free(sfont);
   params->type.text.size = size; /* XXX TODO used by further calcs, go inside recalc_apply? */

   _edje_text_recalc_apply(ed, ep, params, chosen_desc, EINA_TRUE);

   if ((!chosen_desc) ||
       ((!chosen_desc->text.min_x) && (!chosen_desc->text.min_y) &&
        (!chosen_desc->text.max_x) && (!chosen_desc->text.max_y)))
     return;

   // Note: No need to add padding to that, it's already in the geometry
   eo_do(ep->object, efl_gfx_size_get(&mw, &mh));

   if (chosen_desc->text.max_x)
     {
        if ((*maxw < 0) || (mw < *maxw)) *maxw = mw;
     }
   if (chosen_desc->text.max_y)
     {
        if ((*maxh < 0) || (mh < *maxh)) *maxh = mh;
     }
   if (chosen_desc->text.min_x)
     {
        if (mw > *minw) *minw = mw;
     }
   if (chosen_desc->text.min_y)
     {
        if (mh > *minh) *minh = mh;
     }
}

#else
{
   char *sfont = NULL;
   int size;

   if (chosen_desc)
     {
        const char *text;
        const char *font;
        Evas_Coord tw, th;
        int inlined_font = 0;
        Edje_Real_Part *source, *text_source;

        /* Update a object_text part */

        if (chosen_desc->text.id_source >= 0)
          ep->typedata.text->source = ed->table_parts[chosen_desc->text.id_source % ed->table_parts_size];
        else
          source = ep->typedata.text->source = NULL;

        if (chosen_desc->text.id_text_source >= 0)
          ep->typedata.text->text_source = ed->table_parts[chosen_desc->text.id_text_source % ed->table_parts_size];
        else
          text_source = ep->typedata.text->text_source = NULL;

        if (ep->typedata.text->text_source)
          text = edje_string_get(&_edje_real_part_text_text_source_description_get(ep, &text_source)->text.text);
        else
          text = edje_string_get(&chosen_desc->text.text);

        if (ep->typedata.text->source)
          font = _edje_text_class_font_get(ed, _edje_real_part_text_source_description_get(ep, &source), &size, &sfont);
        else
          font = _edje_text_class_font_get(ed, chosen_desc, &size, &sfont);

        if (!font) font = "";

        if (text_source)
          {
             if (text_source->typedata.text->text) text = text_source->typedata.text->text;
          }
        else
          {
             if (ep->typedata.text->text) text = ep->typedata.text->text;
          }

        if (source)
          {
             if (source->typedata.text->font) font = source->typedata.text->font;
             if (source->typedata.text->size > 0) size = source->typedata.text->size;
          }
        else
          {
             if (ep->typedata.text->font) font = ep->typedata.text->font;
             if (ep->typedata.text->size > 0) size = ep->typedata.text->size;
          }
        if (!text) text = "";

        /* check if the font is embedded in the .eet */
        if (ed->file->fonts)
          {
             Edje_Font_Directory_Entry *fnt;

             fnt = eina_hash_find(ed->file->fonts, font);

             if (fnt)
               {
                  char *font2;

                  size_t len = strlen(font) + sizeof("edje/fonts/") + 1;
                  font2 = alloca(len);
                  sprintf(font2, "edje/fonts/%s", font);
                  font = font2;
                  inlined_font = 1;
               }
          }
        if (ep->part->scale)
          evas_object_scale_set(ep->object, TO_DOUBLE(sc));
        if (inlined_font)
          {
             evas_object_text_font_source_set(ep->object, ed->path);
          }
        else evas_object_text_font_source_set(ep->object, NULL);

        if ((_edje_fontset_append) && (font))
          {
             char *font2;

             font2 = malloc(strlen(font) + 1 + strlen(_edje_fontset_append) + 1);
             if (font2)
               {
                  strcpy(font2, font);
                  strcat(font2, ",");
                  strcat(font2, _edje_fontset_append);
                  evas_object_text_font_set(ep->object, font2, size);
                  free(font2);
               }
          }
        else
          evas_object_text_font_set(ep->object, font, size);
        if ((chosen_desc->text.min_x) || (chosen_desc->text.min_y) ||
            (chosen_desc->text.max_x) || (chosen_desc->text.max_y))
          {
             int mw, mh;
             Evas_Text_Style_Type
               style = EVAS_TEXT_STYLE_PLAIN,
               shadow = EVAS_TEXT_STYLE_SHADOW_DIRECTION_BOTTOM_RIGHT;
             const Evas_Text_Style_Type styles[] = {
                EVAS_TEXT_STYLE_PLAIN,
                EVAS_TEXT_STYLE_PLAIN,
                EVAS_TEXT_STYLE_OUTLINE,
                EVAS_TEXT_STYLE_SOFT_OUTLINE,
                EVAS_TEXT_STYLE_SHADOW,
                EVAS_TEXT_STYLE_SOFT_SHADOW,
                EVAS_TEXT_STYLE_OUTLINE_SHADOW,
                EVAS_TEXT_STYLE_OUTLINE_SOFT_SHADOW,
                EVAS_TEXT_STYLE_FAR_SHADOW,
                EVAS_TEXT_STYLE_FAR_SOFT_SHADOW,
                EVAS_TEXT_STYLE_GLOW
             };
             const Evas_Text_Style_Type shadows[] = {
                EVAS_TEXT_STYLE_SHADOW_DIRECTION_BOTTOM_RIGHT,
                EVAS_TEXT_STYLE_SHADOW_DIRECTION_BOTTOM,
                EVAS_TEXT_STYLE_SHADOW_DIRECTION_BOTTOM_LEFT,
                EVAS_TEXT_STYLE_SHADOW_DIRECTION_LEFT,
                EVAS_TEXT_STYLE_SHADOW_DIRECTION_TOP_LEFT,
                EVAS_TEXT_STYLE_SHADOW_DIRECTION_TOP,
                EVAS_TEXT_STYLE_SHADOW_DIRECTION_TOP_RIGHT,
                EVAS_TEXT_STYLE_SHADOW_DIRECTION_RIGHT
             };

             if ((ep->part->effect & EVAS_TEXT_STYLE_MASK_BASIC)
                 < EDJE_TEXT_EFFECT_LAST)
               style = styles[ep->part->effect];
             shadow = shadows
               [(ep->part->effect & EDJE_TEXT_EFFECT_MASK_SHADOW_DIRECTION) >> 4];
             EVAS_TEXT_STYLE_SHADOW_DIRECTION_SET(style, shadow);

             eo_do(ep->object,
                   evas_obj_text_style_set(style),
                   evas_obj_text_set(text),
                   efl_gfx_size_get(&tw, &th));
             if (chosen_desc->text.max_x)
               {
                  int l, r;
                  evas_object_text_style_pad_get(ep->object, &l, &r, NULL, NULL);
                  mw = tw + l + r;
                  if ((*maxw < 0) || (mw < *maxw)) *maxw = mw;
               }
             if (chosen_desc->text.max_y)
               {
                  int t, b;
                  evas_object_text_style_pad_get(ep->object, NULL, NULL, &t, &b);
                  mh = th + t + b;
                  if ((*maxh < 0) || (mh < *maxh)) *maxh = mh;
               }
             if (chosen_desc->text.min_x)
               {
                  int l, r;
                  evas_object_text_style_pad_get(ep->object, &l, &r, NULL, NULL);
                  mw = tw + l + r;
                  if (mw > *minw) *minw = mw;
               }
             if (chosen_desc->text.min_y)
               {
                  int t, b;
                  evas_object_text_style_pad_get(ep->object, NULL, NULL, &t, &b);
                  mh = th + t + b;
                  if (mh > *minh) *minh = mh;
               }
          }
        if (sfont) free(sfont);
     }

   /* FIXME: Do we really need to call it twice if chosen_desc ? */
   sfont = NULL;
   _edje_text_class_font_get(ed, desc, &size, &sfont);
   free(sfont);
   params->type.text.size = size;
}
#endif

static void
_edje_part_recalc_single_min_length(FLOAT_T align, FLOAT_T *start, FLOAT_T *length, int min)
{
   if (min >= 0)
     {
        if (*length < FROM_INT(min))
          {
             *start = ADD(*start, (SCALE(align, (*length - min))));
             *length = FROM_INT(min);
          }
     }
}

static void
_edje_part_recalc_single_min(Edje_Part_Description_Common *desc,
                             Edje_Calc_Params *params,
                             int minw, int minh,
                             Edje_Internal_Aspect aspect)
{
   FLOAT_T tmp;
   FLOAT_T w;
   FLOAT_T h;

   w = params->eval.w ? params->eval.w : FROM_INT(99999);
   h = params->eval.h ? params->eval.h : 99999;

   switch (aspect)
     {
      case EDJE_ASPECT_PREFER_NONE:
        break;

      case EDJE_ASPECT_PREFER_VERTICAL:
        tmp = DIV(SCALE(params->eval.w, minh), h);
        if (tmp >= FROM_INT(minw))
          {
             minw = TO_INT(tmp);
             break;
          }

      case EDJE_ASPECT_PREFER_HORIZONTAL:
        tmp = DIV(SCALE(params->eval.h, minw), w);
        if (tmp >= FROM_INT(minh))
          {
             minh = TO_INT(tmp);
             break;
          }

      case EDJE_ASPECT_PREFER_SOURCE:
      case EDJE_ASPECT_PREFER_BOTH:
        tmp = DIV(SCALE(params->eval.w, minh), h);
        if (tmp >= FROM_INT(minw))
          {
             minw = TO_INT(tmp);
             break;
          }

        tmp = DIV(SCALE(params->eval.h, minw), w);
        if (tmp >= FROM_INT(minh))
          {
             minh = TO_INT(tmp);
             break;
          }

        break;
     }

   _edje_part_recalc_single_min_length(desc->align.x, &params->eval.x, &params->eval.w, minw);
   _edje_part_recalc_single_min_length(desc->align.y, &params->eval.y, &params->eval.h, minh);
}

static void
_edje_part_recalc_single_max_length(FLOAT_T align, FLOAT_T *start, FLOAT_T *length, int max)
{
   if (max >= 0)
     {
        if (*length > max)
          {
             *start = ADD(*start, SCALE(align, (*length - max)));
             *length = max;
          }
     }
}

static void
_edje_part_recalc_single_max(Edje_Part_Description_Common *desc,
                             Edje_Calc_Params *params,
                             int maxw, int maxh,
                             Edje_Internal_Aspect aspect)
{
   FLOAT_T tmp;
   FLOAT_T w;
   FLOAT_T h;

   w = params->eval.w ? params->eval.w : FROM_INT(99999);
   h = params->eval.h ? params->eval.h : FROM_INT(99999);

   switch (aspect)
     {
      case EDJE_ASPECT_PREFER_NONE:
        break;

      case EDJE_ASPECT_PREFER_VERTICAL:
        tmp = DIV(SCALE(params->eval.w, maxh), h);
        if (tmp <= FROM_INT(maxw))
          {
             maxw = TO_INT(tmp);
             break;
          }

      case EDJE_ASPECT_PREFER_HORIZONTAL:
        tmp = DIV(SCALE(params->eval.h, maxw), w);
        if (tmp <= FROM_INT(maxh))
          {
             maxh = TO_INT(tmp);
             break;
          }

      case EDJE_ASPECT_PREFER_SOURCE:
      case EDJE_ASPECT_PREFER_BOTH:
        tmp = DIV(SCALE(params->eval.w, maxh), h);
        if (tmp <= FROM_INT(maxw))
          {
             maxw = TO_INT(tmp);
             break;
          }

        tmp = DIV(SCALE(params->eval.h, maxw), w);
        if (tmp <= FROM_INT(maxh))
          {
             maxh = TO_INT(tmp);
             break;
          }

        break;
     }

   _edje_part_recalc_single_max_length(desc->align.x, &params->eval.x, &params->eval.w, maxw);
   _edje_part_recalc_single_max_length(desc->align.y, &params->eval.y, &params->eval.h, maxh);
}

static void
_edje_part_recalc_single_drag_threshold(Edje_Real_Part *ep,
                                        Edje_Real_Part *threshold,
                                        Edje_Calc_Params *params)
{
   if (threshold)
     {
        if (ep->drag->threshold_started_x &&
            threshold->x < TO_INT(params->eval.x) &&
            TO_INT(params->eval.x) + TO_INT(params->eval.w) < threshold->x + threshold->w)
          {
             // Cancel movement to previous position due to our presence inside the threshold
             params->eval.x = FROM_INT(params->req_drag.x);
             params->eval.w = FROM_INT(params->req_drag.w);
             ep->drag->threshold_x = EINA_TRUE;
          }
        else
          {
             params->req_drag.x = TO_INT(params->eval.x);
             params->req_drag.w = TO_INT(params->eval.w);
             ep->drag->threshold_started_x = EINA_FALSE;
          }
        if (ep->drag->threshold_started_y &&
            threshold->y < TO_INT(params->eval.y) &&
            TO_INT(params->eval.y) + TO_INT(params->eval.h) < threshold->y + threshold->h)
          {
             // Cancel movement to previous position due to our presence inside the threshold
             params->eval.y = FROM_INT(params->req_drag.y);
             params->eval.h = FROM_INT(params->req_drag.h);
             ep->drag->threshold_y = EINA_TRUE;
          }
        else
          {
             params->req_drag.y = TO_INT(params->eval.y);
             params->req_drag.h = TO_INT(params->eval.h);
             ep->drag->threshold_started_y = EINA_FALSE;
          }
     }
   else
     {
        params->req_drag.x = TO_INT(params->eval.x);
        params->req_drag.w = TO_INT(params->eval.w);
        params->req_drag.y = TO_INT(params->eval.y);
        params->req_drag.h = TO_INT(params->eval.h);
     }
}

static void
_edje_part_recalc_single_drag(Edje_Real_Part *ep,
                              Edje_Real_Part *confine_to,
                              Edje_Real_Part *threshold,
                              Edje_Calc_Params *params,
                              int minw, int minh,
                              int maxw, int maxh)
{
   /* confine */
   if (confine_to)
     {
        int offset;
        int step;
        FLOAT_T v;

        /* complex dragable params */
        v = SCALE(ep->drag->size.x, confine_to->w);

        if ((minw > 0) && (TO_INT(v) < minw)) params->eval.w = FROM_INT(minw);
        else if ((maxw >= 0) && (TO_INT(v) > maxw))
          params->eval.w = FROM_INT(maxw);
        else params->eval.w = v;

        offset = TO_INT(SCALE(ep->drag->x, (confine_to->w - TO_INT(params->eval.w))))
          + ep->drag->tmp.x;
        if (ep->part->dragable.step_x > 0)
          {
             params->eval.x = FROM_INT(confine_to->x +
                                       ((offset / ep->part->dragable.step_x) * ep->part->dragable.step_x));
          }
        else if (ep->part->dragable.count_x > 0)
          {
             step = (confine_to->w - TO_INT(params->eval.w)) / ep->part->dragable.count_x;
             if (step < 1) step = 1;
             params->eval.x = FROM_INT(confine_to->x +
                                       ((offset / step) * step));
          }

        v = SCALE(ep->drag->size.y, confine_to->h);

        if ((minh > 0) && (TO_INT(v) < minh)) params->eval.h = FROM_INT(minh);
        else if ((maxh >= 0) && (TO_INT(v) > maxh))
          params->eval.h = FROM_INT(maxh);
        else params->eval.h = v;

        offset = TO_INT(SCALE(ep->drag->y, (confine_to->h - TO_INT(params->eval.h))))
          + ep->drag->tmp.y;
        if (ep->part->dragable.step_y > 0)
          {
             params->eval.y = FROM_INT(confine_to->y +
                                       ((offset / ep->part->dragable.step_y) * ep->part->dragable.step_y));
          }
        else if (ep->part->dragable.count_y > 0)
          {
             step = (confine_to->h - TO_INT(params->eval.h)) / ep->part->dragable.count_y;
             if (step < 1) step = 1;
             params->eval.y = FROM_INT(confine_to->y +
                                       ((offset / step) * step));
          }

        _edje_part_recalc_single_drag_threshold(ep, threshold, params);

        /* limit to confine */
        if (params->eval.x < FROM_INT(confine_to->x))
          {
             params->eval.x = FROM_INT(confine_to->x);
          }
        if ((ADD(params->eval.x, params->eval.w)) > FROM_INT(confine_to->x + confine_to->w))
          {
             params->eval.x = SUB(FROM_INT(confine_to->x + confine_to->w), params->eval.w);
          }
        if (params->eval.y < FROM_INT(confine_to->y))
          {
             params->eval.y = FROM_INT(confine_to->y);
          }
        if ((ADD(params->eval.y, params->eval.h)) > FROM_INT(confine_to->y + confine_to->h))
          {
             params->eval.y = SUB(FROM_INT(confine_to->y + confine_to->h), params->eval.h);
          }
     }
   else
     {
        /* simple dragable params */
        params->eval.x = ADD(ADD(params->eval.x, ep->drag->x), FROM_INT(ep->drag->tmp.x));
        params->eval.y = ADD(ADD(params->eval.y, ep->drag->y), FROM_INT(ep->drag->tmp.y));

        _edje_part_recalc_single_drag_threshold(ep, threshold, params);
     }
}

static void
_edje_part_recalc_single_fill(Edje_Real_Part *ep,
                              Edje_Part_Description_Spec_Fill *fill,
                              Edje_Calc_Params *params)
{
   int fw;
   int fh;

   params->smooth = fill->smooth;

   if (fill->type == EDJE_FILL_TYPE_TILE)
     evas_object_image_size_get(ep->object, &fw, NULL);
   else
     fw = params->final.w;

   params->type.common.fill.x = fill->pos_abs_x
     + TO_INT(SCALE(fill->pos_rel_x, fw));
   params->type.common.fill.w = fill->abs_x
     + TO_INT(SCALE(fill->rel_x, fw));

   if (fill->type == EDJE_FILL_TYPE_TILE)
     evas_object_image_size_get(ep->object, NULL, &fh);
   else
     fh = params->final.h;

   params->type.common.fill.y = fill->pos_abs_y
     + TO_INT(SCALE(fill->pos_rel_y, fh));
   params->type.common.fill.h = fill->abs_y
     + TO_INT(SCALE(fill->rel_y, fh));

   params->type.common.fill.angle = fill->angle;
   params->type.common.fill.spread = fill->spread;
}

static void
_edje_part_recalc_single_min_max(FLOAT_T sc,
                                 Edje *ed,
                                 Edje_Real_Part *ep,
                                 Edje_Part_Description_Common *desc,
                                 int *minw, int *minh,
                                 int *maxw, int *maxh)
{
   *minw = desc->min.w;
   if (ep->part->scale) *minw = TO_INT(SCALE(sc, *minw));
   if ((ep->type == EDJE_RP_TYPE_SWALLOW) &&
       (ep->typedata.swallow))
     {
        if (ep->typedata.swallow->swallow_params.min.w > desc->min.w)
          *minw = ep->typedata.swallow->swallow_params.min.w;
     }

   if (ed->calc_only)
     {
        if (desc->minmul.have)
          {
             FLOAT_T mmw = desc->minmul.w;
             if (mmw != FROM_INT(1)) *minw = TO_INT(SCALE(mmw, *minw));
          }
     }

   if ((ep->type == EDJE_RP_TYPE_SWALLOW) &&
       (ep->typedata.swallow))
     {
        /* XXX TODO: remove need of EDJE_INF_MAX_W, see edje_util.c */
        if ((ep->typedata.swallow->swallow_params.max.w <= 0) ||
            (ep->typedata.swallow->swallow_params.max.w == EDJE_INF_MAX_W))
          {
             *maxw = desc->max.w;
             if (*maxw > 0)
               {
                  if (ep->part->scale) *maxw = TO_INT(SCALE(sc, *maxw));
                  if (*maxw < 1) *maxw = 1;
               }
          }
        else
          {
             if (desc->max.w <= 0)
               *maxw = ep->typedata.swallow->swallow_params.max.w;
             else
               {
                  *maxw = desc->max.w;
                  if (*maxw > 0)
                    {
                       if (ep->part->scale) *maxw = TO_INT(SCALE(sc, *maxw));
                       if (*maxw < 1) *maxw = 1;
                    }
                  if (ep->typedata.swallow->swallow_params.max.w < *maxw)
                    *maxw = ep->typedata.swallow->swallow_params.max.w;
               }
          }
     }
   else
     {
        *maxw = desc->max.w;
        if (*maxw > 0)
          {
             if (ep->part->scale) *maxw = TO_INT(SCALE(sc, *maxw));
             if (*maxw < 1) *maxw = 1;
          }
     }
   if ((ed->calc_only) && (desc->minmul.have) &&
       (desc->minmul.w != FROM_INT(1))) *maxw = *minw;
   if (*maxw >= 0)
     {
        if (*maxw < *minw) *maxw = *minw;
     }

   *minh = desc->min.h;
   if (ep->part->scale) *minh = TO_INT(SCALE(sc, *minh));
   if ((ep->type == EDJE_RP_TYPE_SWALLOW) &&
       (ep->typedata.swallow))
     {
        if (ep->typedata.swallow->swallow_params.min.h > desc->min.h)
          *minh = ep->typedata.swallow->swallow_params.min.h;
     }

   if (ed->calc_only)
     {
        if (desc->minmul.have)
          {
             FLOAT_T mmh = desc->minmul.h;
             if (mmh != FROM_INT(1)) *minh = TO_INT(SCALE(mmh, *minh));
          }
     }

   if ((ep->type == EDJE_RP_TYPE_SWALLOW) &&
       (ep->typedata.swallow))
     {
        /* XXX TODO: remove need of EDJE_INF_MAX_H, see edje_util.c */
        if ((ep->typedata.swallow->swallow_params.max.h <= 0) ||
            (ep->typedata.swallow->swallow_params.max.h == EDJE_INF_MAX_H))
          {
             *maxh = desc->max.h;
             if (*maxh > 0)
               {
                  if (ep->part->scale) *maxh = TO_INT(SCALE(sc, *maxh));
                  if (*maxh < 1) *maxh = 1;
               }
          }
        else
          {
             if (desc->max.h <= 0)
               *maxh = ep->typedata.swallow->swallow_params.max.h;
             else
               {
                  *maxh = desc->max.h;
                  if (*maxh > 0)
                    {
                       if (ep->part->scale) *maxh = TO_INT(SCALE(sc, *maxh));
                       if (*maxh < 1) *maxh = 1;
                    }
                  if (ep->typedata.swallow->swallow_params.max.h < *maxh)
                    *maxh = ep->typedata.swallow->swallow_params.max.h;
               }
          }
     }
   else
     {
        *maxh = desc->max.h;
        if (*maxh > 0)
          {
             if (ep->part->scale) *maxh = TO_INT(SCALE(sc, *maxh));
             if (*maxh < 1) *maxh = 1;
          }
     }
   if ((ed->calc_only) && (desc->minmul.have) &&
       (desc->minmul.h != FROM_INT(1))) *maxh = *minh;
   if (*maxh >= 0)
     {
        if (*maxh < *minh) *maxh = *minh;
     }
}

static void
_edje_part_recalc_single_map(Edje *ed,
                             Edje_Real_Part *ep EINA_UNUSED,
                             Edje_Real_Part *center,
                             Edje_Real_Part *light,
                             Edje_Real_Part *persp,
                             Edje_Part_Description_Common *desc,
                             Edje_Part_Description_Common *chosen_desc,
                             Edje_Calc_Params *params)
{
   params->mapped = chosen_desc->map.on;
   params->lighted = params->mapped ? !!light : 0;
   params->persp_on = params->mapped ? !!persp : 0;

   if (!params->mapped) return;

   EINA_COW_CALC_MAP_BEGIN(params, params_write)
   {
      if (center)
        {
           params_write->center.x = ed->x + center->x + (center->w / 2);
           params_write->center.y = ed->y + center->y + (center->h / 2);
        }
      else
        {
           params_write->center.x = ed->x + params->final.x + (params->final.w / 2);
           params_write->center.y = ed->y + params->final.y + (params->final.h / 2);
        }
      params_write->center.z = 0;

      params_write->rotation.x = desc->map.rot.x;
      params_write->rotation.y = desc->map.rot.y;
      params_write->rotation.z = desc->map.rot.z;
      params_write->zoom.x = desc->map.zoom.x;
      params_write->zoom.y = desc->map.zoom.y;

      if (light)
        {
           Edje_Part_Description_Common *light_desc2;
           FLOAT_T pos, pos2;

           params_write->light.x = ed->x + light->x + (light->w / 2);
           params_write->light.y = ed->y + light->y + (light->h / 2);

           pos = light->description_pos;
           pos2 = (pos < ZERO) ? ZERO : ((pos > FROM_INT(1)) ? FROM_INT(1) : pos);

           light_desc2 = light->param2 ? light->param2->description : NULL;

           /* take into account CURRENT state also */
           if (pos != ZERO && light_desc2)
             {
                params_write->light.z = light->param1.description->persp.zplane +
                  TO_INT(SCALE(pos, light_desc2->persp.zplane - light->param1.description->persp.zplane));
                params_write->light.r = light->param1.description->color.r +
                  TO_INT(SCALE(pos2, light_desc2->color.r - light->param1.description->color.r));
                params_write->light.g = light->param1.description->color.g +
                  TO_INT(SCALE(pos2, light_desc2->color.g - light->param1.description->color.g));
                params_write->light.b = light->param1.description->color.b +
                  TO_INT(SCALE(pos2, light_desc2->color.b - light->param1.description->color.b));
                params_write->light.ar = light->param1.description->color2.r +
                  TO_INT(SCALE(pos2, light_desc2->color2.r - light->param1.description->color2.r));
                params_write->light.ag = light->param1.description->color2.g +
                  TO_INT(SCALE(pos2, light_desc2->color2.g - light->param1.description->color2.g));
                params_write->light.ab = light->param1.description->color2.b +
                  TO_INT(SCALE(pos2, light_desc2->color2.b - light->param1.description->color2.b));
             }
           else
             {
                params_write->light.z = light->param1.description->persp.zplane;
                params_write->light.r = light->param1.description->color.r;
                params_write->light.g = light->param1.description->color.g;
                params_write->light.b = light->param1.description->color.b;
                params_write->light.ar = light->param1.description->color2.r;
                params_write->light.ag = light->param1.description->color2.g;
                params_write->light.ab = light->param1.description->color2.b;
             }
        }

      if (persp)
        {
           FLOAT_T pos;

           params_write->persp.x = ed->x + persp->x + (persp->w / 2);
           params_write->persp.y = ed->y + persp->y + (persp->h / 2);

           pos = persp->description_pos;

           if (pos != 0 && persp->param2)
             {
                params_write->persp.z = persp->param1.description->persp.zplane +
                  TO_INT(SCALE(pos, persp->param2->description->persp.zplane -
                               persp->param1.description->persp.zplane));
                params_write->persp.focal = persp->param1.description->persp.focal +
                  TO_INT(SCALE(pos, persp->param2->description->persp.focal -
                               persp->param1.description->persp.focal));
             }
           else
             {
                params_write->persp.z = persp->param1.description->persp.zplane;
                params_write->persp.focal = persp->param1.description->persp.focal;
             }
        }
      params_write->colors = desc->map.colors;
      params_write->colors_count = desc->map.colors_count;
   }
   EINA_COW_CALC_MAP_END(params, params_write);
}

static int
_filter_bsearch_cmp(const void *a, const void *b)
{
   const Edje_Gfx_Filter *filter = b;
   const char *key = a;

   return strcmp(key, filter->name);
}

static inline const char *
_edje_filter_get(Edje *ed, Edje_Part_Description_Spec_Filter *filter)
{
   if (!filter->code) return NULL;
   if (EINA_UNLIKELY(!filter->checked_data))
     {
        Edje_Gfx_Filter *found;

        filter->checked_data = EINA_TRUE;
        if (!ed->file->filter_dir)
          return filter->code;

        found = bsearch(filter->code, &(ed->file->filter_dir->filters[0]),
                        ed->file->filter_dir->filters_count,
                        sizeof(Edje_Gfx_Filter), _filter_bsearch_cmp);
        if (found)
          {
             filter->name = found->name;
             filter->code = found->script;
             filter->no_free = EINA_TRUE;
             return filter->code;
          }
     }
   return filter->code;
}

static void
_edje_part_recalc_single_filter(Edje *ed,
                                Edje_Real_Part *ep,
                                Edje_Part_Description_Common *desc,
                                Edje_Part_Description_Common *chosen_desc,
                                double pos)
{
   Edje_Part_Description_Spec_Filter *filter;
   Eina_List *filter_sources = NULL, *prev_sources = NULL;
   const char *src1, *src2, *part, *code;
   Evas_Object *obj = ep->object;
   Eina_List *li1, *li2;

   /* handle TEXT, IMAGE, PROXY, SNAPSHOT part types here */
   if (ep->part->type == EDJE_PART_TYPE_TEXT)
     {
        Edje_Part_Description_Text *chosen_edt = (Edje_Part_Description_Text *) chosen_desc;
        Edje_Part_Description_Text *edt = (Edje_Part_Description_Text *) desc;
        filter = &chosen_edt->filter;
        prev_sources = edt->filter.sources;
        filter_sources = chosen_edt->filter.sources;
     }
   else if (ep->part->type == EDJE_PART_TYPE_IMAGE)
     {
        Edje_Part_Description_Image *chosen_edi = (Edje_Part_Description_Image *) chosen_desc;
        Edje_Part_Description_Image *edi = (Edje_Part_Description_Image *) desc;
        filter = &chosen_edi->filter;
        prev_sources = edi->filter.sources;
        filter_sources = chosen_edi->filter.sources;
     }
   else if (ep->part->type == EDJE_PART_TYPE_PROXY)
     {
        Edje_Part_Description_Proxy *chosen_edp = (Edje_Part_Description_Proxy *) chosen_desc;
        Edje_Part_Description_Proxy *edp = (Edje_Part_Description_Proxy *) desc;
        filter = &chosen_edp->filter;
        prev_sources = edp->filter.sources;
        filter_sources = chosen_edp->filter.sources;
     }
   else if (ep->part->type == EDJE_PART_TYPE_SNAPSHOT)
     {
        Edje_Part_Description_Snapshot *chosen_eds = (Edje_Part_Description_Snapshot *) chosen_desc;
        Edje_Part_Description_Snapshot *eds = (Edje_Part_Description_Snapshot *) desc;
        filter = &chosen_eds->filter;
        prev_sources = eds->filter.sources;
        filter_sources = chosen_eds->filter.sources;
     }
   else
     {
        CRI("Invalid call to filter recalc");
        return;
     }

   /* common code below */
   code = _edje_filter_get(ed, filter);
   if (!code)
     {
        eo_do(obj, efl_gfx_filter_program_set(NULL, NULL));
        return;
     }

   if (!filter->sources_set)
     {
        filter->sources_set = 1;
        prev_sources = NULL;
     }

   eo_do(obj,
         /* pass extra data items */
         if (filter->data)
           {
              unsigned int k;
              for (k = 0; k < filter->data_count; k++)
                {
                   Edje_Part_Description_Spec_Filter_Data *data = &(filter->data[k]);
                   if (data->invalid_cc)
                     continue;
                   if (!data->value)
                     {
                        efl_gfx_filter_data_set(data->name, NULL, EINA_FALSE);
                     }
                   else if (!strncmp(data->value, "color_class('", sizeof("color_class('") - 1))
                     {
                        /* special handling for color classes even tho they're not that great */
                        char *ccname, *buffer, *r;
                        Edje_Color_Class *cc;

                        ccname = strdup(data->value + sizeof("color_class('") - 1);
                        if (ccname)
                          {
                             r = strchr(ccname, '\'');
                             if (r && (r[1] == ')') && (r[2] == '\0'))
                               {
                                  *r = '\0';
                                  cc = _edje_color_class_find(ed, ccname);
                                  if (cc)
                                    {
                                       static const char fmt[] =
                                             "%s={r=%d,g=%d,b=%d,a=%d,"
                                             "r2=%d,g2=%d,b2=%d,a2=%d,"
                                             "r3=%d,g3=%d,b3=%d,a3=%d}";
                                       int len = sizeof(fmt) + 20;
                                       len += strlen(data->name);
                                       buffer = alloca(len);
                                       snprintf(buffer, len - 1, fmt, data->name,
                                                (int) cc->r, (int) cc->g, (int) cc->b, (int) cc->a,
                                                (int) cc->r2, (int) cc->g2, (int) cc->b2, (int) cc->a2,
                                                (int) cc->r3, (int) cc->g3, (int) cc->b3, (int) cc->a3);
                                       buffer[len - 1] = 0;
                                       efl_gfx_filter_data_set(data->name, buffer, EINA_TRUE);
                                    }
                                  else
                                    {
                                       ERR("Unknown color class: %s", ccname);
                                       data->invalid_cc = EINA_TRUE;
                                    }
                               }
                             else
                               {
                                  ERR("Failed to parse color class: %s", data->value);
                                  data->invalid_cc = EINA_TRUE;
                               }
                             free(ccname);
                          }
                     }
                   else
                     efl_gfx_filter_data_set(data->name, data->value, EINA_FALSE);
                }
           }
         efl_gfx_filter_program_set(code, filter->name);
         if (prev_sources != filter_sources)
           {
              /* remove sources that are not there anymore
               * this O(n^2) loop assumes a very small number of sources */
              EINA_LIST_FOREACH(prev_sources, li1, src1)
                {
                   Eina_Bool found = 0;
                   EINA_LIST_FOREACH(filter_sources, li2, src2)
                     {
                        if (!strcmp(src1, src2))
                          {
                             found = 1;
                             break;
                          }
                     }
                   if (!found)
                     {
                        part = strchr(src1, ':');
                        if (!part)
                          efl_gfx_filter_source_set(src1, NULL);
                        else
                          {
                             char *name = strdup(src1);
                             name[part - src1] = 0;
                             efl_gfx_filter_source_set(name, NULL);
                             free(name);
                          }
                     }
                }
              /* add all sources by part name */
              EINA_LIST_FOREACH(filter_sources, li1, src1)
                {
                   Edje_Real_Part *rp;
                   char *name = NULL;
                   if ((part = strchr(src1, ':')) != NULL)
                     {
                        name = strdup(src1);
                        name[part - src1] = 0;
                        part++;
                     }
                   else
                     part = src1;
                   rp = _edje_real_part_get(ed, part);
                   efl_gfx_filter_source_set(name ? name : part, rp ? rp->object : NULL);
                   free(name);
                }
            }
         /* pass edje state for transitions */
         if (ep->param2)
           {
              efl_gfx_filter_state_set(chosen_desc->state.name, chosen_desc->state.value,
                                       ep->param2->description->state.name, ep->param2->description->state.value,
                                       pos);
           }
         else
           {
              efl_gfx_filter_state_set(chosen_desc->state.name, chosen_desc->state.value,
                                       NULL, 0.0, pos);
           }
         );
}

static void
_edje_part_recalc_single(Edje *ed,
                         Edje_Real_Part *ep,
                         Edje_Part_Description_Common *desc,
                         Edje_Part_Description_Common *chosen_desc,
                         Edje_Real_Part *center,
                         Edje_Real_Part *light,
                         Edje_Real_Part *persp,
                         Edje_Real_Part *rel1_to_x,
                         Edje_Real_Part *rel1_to_y,
                         Edje_Real_Part *rel2_to_x,
                         Edje_Real_Part *rel2_to_y,
                         Edje_Real_Part *clip_to,
                         Edje_Real_Part *confine_to,
                         Edje_Real_Part *threshold,
                         Edje_Calc_Params *params,
                         Evas_Coord mmw, Evas_Coord mmh,
                         FLOAT_T pos)
{
   Edje_Color_Class *cc = NULL;
   Edje_Internal_Aspect apref;
   int minw = 0, minh = 0, maxw = 0, maxh = 0;
   FLOAT_T sc;

   sc = DIV(ed->scale, ed->file->base_scale);
   if (sc == ZERO) sc = DIV(_edje_scale, ed->file->base_scale);
   _edje_part_recalc_single_min_max(sc, ed, ep, desc, &minw, &minh, &maxw, &maxh);
   if (minw < mmw) minw = mmw;
   if (minh < mmh) minh = mmh;

   /* relative coords of top left & bottom right */
   _edje_part_recalc_single_rel(ed, ep, desc, rel1_to_x, rel1_to_y, rel2_to_x, rel2_to_y, params);

   /* aspect */
   apref = _edje_part_recalc_single_aspect(ed, ep, desc, params, &minw, &minh, &maxw, &maxh, pos);

   /* size step */
   _edje_part_recalc_single_step(desc, params);

   /* colors */
   if (ep->part->type != EDJE_PART_TYPE_SPACER)
     {
        if ((desc->color_class) && (*desc->color_class))
          cc = _edje_color_class_find(ed, desc->color_class);

        if (cc)
          {
             params->color.r = (((int)cc->r + 1) * desc->color.r) >> 8;
             params->color.g = (((int)cc->g + 1) * desc->color.g) >> 8;
             params->color.b = (((int)cc->b + 1) * desc->color.b) >> 8;
             params->color.a = (((int)cc->a + 1) * desc->color.a) >> 8;
          }
        else
          {
             params->color.r = desc->color.r;
             params->color.g = desc->color.g;
             params->color.b = desc->color.b;
             params->color.a = desc->color.a;
          }
     }

   /* visible */
   params->visible = desc->visible;

   /* clip override */
   params->clip_to = clip_to;

   /* set parameters, some are required for recalc_single_text[block] */
   switch (ep->part->type)
     {
      case EDJE_PART_TYPE_IMAGE:
      {
         Edje_Real_Part_Set *set;
         Edje_Part_Description_Image *img_desc = (Edje_Part_Description_Image *)desc;

         _edje_real_part_image_set(ed, ep, &set, pos);

         /* border */
         params->type.common.spec.image.l = img_desc->image.border.l;
         params->type.common.spec.image.r = img_desc->image.border.r;

         params->type.common.spec.image.t = img_desc->image.border.t;
         params->type.common.spec.image.b = img_desc->image.border.b;

         params->type.common.spec.image.border_scale_by = img_desc->image.border.scale_by;

         if (set && set->set)
           {
#define SET_BORDER_DEFINED(Result, Value) Result = Value ? Value : Result;
              SET_BORDER_DEFINED(params->type.common.spec.image.l, set->entry->border.l);
              SET_BORDER_DEFINED(params->type.common.spec.image.r, set->entry->border.r);
              SET_BORDER_DEFINED(params->type.common.spec.image.t, set->entry->border.t);
              SET_BORDER_DEFINED(params->type.common.spec.image.b, set->entry->border.b);

              SET_BORDER_DEFINED(params->type.common.spec.image.border_scale_by, set->entry->border.scale_by);
           }

         break;
      }

      case EDJE_PART_TYPE_TEXT:
      case EDJE_PART_TYPE_TEXTBLOCK:
      {
         Edje_Part_Description_Text *text_desc = (Edje_Part_Description_Text *)desc;

         /* text.align */
         params->type.text.align.x = text_desc->text.align.x;
         params->type.text.align.y = text_desc->text.align.y;
         params->type.text.ellipsis = text_desc->text.ellipsis;

         /* text colors */
         if (cc)
           {
              params->type.text.color2.r = (((int)cc->r2 + 1) * text_desc->common.color2.r) >> 8;
              params->type.text.color2.g = (((int)cc->g2 + 1) * text_desc->common.color2.g) >> 8;
              params->type.text.color2.b = (((int)cc->b2 + 1) * text_desc->common.color2.b) >> 8;
              params->type.text.color2.a = (((int)cc->a2 + 1) * text_desc->common.color2.a) >> 8;
              params->type.text.color3.r = (((int)cc->r3 + 1) * text_desc->text.color3.r) >> 8;
              params->type.text.color3.g = (((int)cc->g3 + 1) * text_desc->text.color3.g) >> 8;
              params->type.text.color3.b = (((int)cc->b3 + 1) * text_desc->text.color3.b) >> 8;
              params->type.text.color3.a = (((int)cc->a3 + 1) * text_desc->text.color3.a) >> 8;
           }
         else
           {
              params->type.text.color2.r = text_desc->common.color2.r;
              params->type.text.color2.g = text_desc->common.color2.g;
              params->type.text.color2.b = text_desc->common.color2.b;
              params->type.text.color2.a = text_desc->common.color2.a;
              params->type.text.color3.r = text_desc->text.color3.r;
              params->type.text.color3.g = text_desc->text.color3.g;
              params->type.text.color3.b = text_desc->text.color3.b;
              params->type.text.color3.a = text_desc->text.color3.a;
           }

         break;
      }

      case EDJE_PART_TYPE_SPACER:
      case EDJE_PART_TYPE_RECTANGLE:
      case EDJE_PART_TYPE_BOX:
      case EDJE_PART_TYPE_TABLE:
      case EDJE_PART_TYPE_SWALLOW:
      case EDJE_PART_TYPE_GROUP:
      case EDJE_PART_TYPE_PROXY:
      case EDJE_PART_TYPE_MESH_NODE:
      case EDJE_PART_TYPE_LIGHT:
      case EDJE_PART_TYPE_CAMERA:
      case EDJE_PART_TYPE_SNAPSHOT:
        break;

      case EDJE_PART_TYPE_GRADIENT:
        /* FIXME: THIS ONE SHOULD NEVER BE TRIGGERED. */
        break;

      default:
        break;
     }

   /* if we have text that wants to make the min size the text size... */
   if (ep->part->type == EDJE_PART_TYPE_TEXTBLOCK)
     _edje_part_recalc_single_textblock(sc, ed, ep, (Edje_Part_Description_Text *)chosen_desc, params, &minw, &minh, &maxw, &maxh);
   else if (ep->part->type == EDJE_PART_TYPE_TEXT)
     {
        _edje_part_recalc_single_text(sc, ed, ep, (Edje_Part_Description_Text*) desc, (Edje_Part_Description_Text*) chosen_desc, params, &minw, &minh, &maxw, &maxh);
        _edje_part_recalc_single_filter(ed, ep, desc, chosen_desc, pos);
     }

   if ((ep->part->type == EDJE_PART_TYPE_TABLE) &&
       (((((Edje_Part_Description_Table *)chosen_desc)->table.min.h) ||
         (((Edje_Part_Description_Table *)chosen_desc)->table.min.v))))
     {
        Evas_Coord lminw = 0, lminh = 0;

        eo_do(ep->object,
              evas_obj_smart_need_recalculate_set(1),
              evas_obj_smart_calculate(),
              evas_obj_size_hint_min_get(&lminw, &lminh));
        if (((Edje_Part_Description_Table *)chosen_desc)->table.min.h)
          {
             if (lminw > minw) minw = lminw;
          }
        if (((Edje_Part_Description_Table *)chosen_desc)->table.min.v)
          {
             if (lminh > minh) minh = lminh;
          }
     }
   else if ((ep->part->type == EDJE_PART_TYPE_BOX) &&
            ((((Edje_Part_Description_Box *)chosen_desc)->box.min.h) ||
             (((Edje_Part_Description_Box *)chosen_desc)->box.min.v)))
     {
        Evas_Coord lminw = 0, lminh = 0;

        eo_do(ep->object,
              evas_obj_smart_need_recalculate_set(1),
              evas_obj_smart_calculate(),
              evas_obj_size_hint_min_get(&lminw, &lminh));
        if (((Edje_Part_Description_Box *)chosen_desc)->box.min.h)
          {
             if (lminw > minw) minw = lminw;
          }
        if (((Edje_Part_Description_Box *)chosen_desc)->box.min.v)
          {
             if (lminh > minh) minh = lminh;
          }
     }
   else if (ep->part->type == EDJE_PART_TYPE_IMAGE)
     {
        if (chosen_desc->min.limit || chosen_desc->max.limit)
          {
             Evas_Coord w, h;

             /* We only need pos to find the right image that would be displayed */
             /* Yes, if someone set aspect preference to SOURCE and also max,min
           to SOURCE, it will be under efficient, but who cares at the
           moment. */
             _edje_real_part_image_set(ed, ep, NULL, pos);
             evas_object_image_size_get(ep->object, &w, &h);

             if (chosen_desc->min.limit)
               {
                  if (w > minw) minw = w;
                  if (h > minh) minh = h;
               }
             if (chosen_desc->max.limit)
               {
                  if ((maxw <= 0) || (w < maxw)) maxw = w;
                  if ((maxh <= 0) || (h < maxh)) maxh = h;
               }
          }
        _edje_part_recalc_single_filter(ed, ep, desc, chosen_desc, pos);
     }
   else if (ep->part->type == EDJE_PART_TYPE_PROXY)
     {
        _edje_part_recalc_single_filter(ed, ep, desc, chosen_desc, pos);
     }
   else if (ep->part->type == EDJE_PART_TYPE_SNAPSHOT)
     {
        _edje_part_recalc_single_filter(ed, ep, desc, chosen_desc, pos);
     }

   /* remember what our size is BEFORE we go limit it */
   params->req.x = TO_INT(params->eval.x);
   params->req.y = TO_INT(params->eval.y);
   params->req.w = TO_INT(params->eval.w);
   params->req.h = TO_INT(params->eval.h);

   /* adjust for min size */
   _edje_part_recalc_single_min(desc, params, minw, minh, apref);

   /* adjust for max size */
   _edje_part_recalc_single_max(desc, params, maxw, maxh, apref);

   /* take care of dragable part */
   if (ep->drag)
     _edje_part_recalc_single_drag(ep, confine_to, threshold, params, minw, minh, maxw, maxh);

   /* Update final size after last change to its position */
   params->final.x = TO_INT(params->eval.x);
   params->final.y = TO_INT(params->eval.y);
   params->final.w = TO_INT(params->eval.w);
   params->final.h = TO_INT(params->eval.h);

   /* Adjust rounding to not loose one pixels compared to float
      information only when rendering to avoid infinite adjustement
      when doing min restricted calc */
   if (ABS(params->final.x) + params->final.w < TO_INT(ADD(ABS(params->eval.x), params->eval.w)))
     {
        if (!ed->calc_only)
          {
             params->final.w += 1;
          }
        else
          {
             ep->invalidate = EINA_TRUE;
          }
     }
   else if (ABS(params->final.x) + params->final.w > TO_INT(ADD(ABS(params->eval.x), params->eval.w)))
     {
        if (!ed->calc_only)
          {
             params->final.w -= 1;
          }
        else
          {
             ep->invalidate = EINA_TRUE;
          }
     }
   if (ABS(params->final.y) + params->final.h < TO_INT(ADD(ABS(params->eval.y), params->eval.h)))
     {
        if (!ed->calc_only)
          {
             params->final.h += 1;
          }
        else
          {
             ep->invalidate = EINA_TRUE;
          }
     }
   else if (ABS(params->final.y) + params->final.h > TO_INT(ADD(ABS(params->eval.y), params->eval.h)))
     {
        if (!ed->calc_only)
          {
             params->final.h -= 1;
          }
        else
          {
             ep->invalidate = EINA_TRUE;
          }
     }

   /* fill */
   if (ep->part->type == EDJE_PART_TYPE_IMAGE)
     _edje_part_recalc_single_fill(ep, &((Edje_Part_Description_Image *)desc)->image.fill, params);
   else if (ep->part->type == EDJE_PART_TYPE_PROXY)
     _edje_part_recalc_single_fill(ep, &((Edje_Part_Description_Proxy *)desc)->proxy.fill, params);

#ifdef HAVE_EPHYSICS
   if (ep->part->physics_body || ep->body)
     {
        EINA_COW_CALC_PHYSICS_BEGIN(params, params_write)
        {
           params_write->mass = desc->physics.mass;
           params_write->restitution = desc->physics.restitution;
           params_write->friction = desc->physics.friction;
           params_write->damping.linear = desc->physics.damping.linear;
           params_write->damping.angular = desc->physics.damping.angular;
           params_write->sleep.linear = desc->physics.sleep.linear;
           params_write->sleep.angular = desc->physics.sleep.angular;
           params_write->material = desc->physics.material;
           params_write->density = desc->physics.density;
           params_write->hardness = desc->physics.hardness;
           params_write->ignore_part_pos = desc->physics.ignore_part_pos;
           params_write->light_on = desc->physics.light_on;
           params_write->mov_freedom.lin.x = desc->physics.mov_freedom.lin.x;
           params_write->mov_freedom.lin.y = desc->physics.mov_freedom.lin.y;
           params_write->mov_freedom.lin.z = desc->physics.mov_freedom.lin.z;
           params_write->mov_freedom.ang.x = desc->physics.mov_freedom.ang.x;
           params_write->mov_freedom.ang.y = desc->physics.mov_freedom.ang.y;
           params_write->mov_freedom.ang.z = desc->physics.mov_freedom.ang.z;
           params_write->backcull = desc->physics.backcull;
           params_write->z = desc->physics.z;
           params_write->depth = desc->physics.depth;
        }
        EINA_COW_CALC_PHYSICS_END(params, params_write);
     }
#endif
   _edje_part_recalc_single_map(ed, ep, center, light, persp, desc, chosen_desc, params);
}

static void
_edje_table_recalc_apply(Edje *ed EINA_UNUSED,
                         Edje_Real_Part *ep,
                         Edje_Calc_Params *p3 EINA_UNUSED,
                         Edje_Part_Description_Table *chosen_desc)
{
   eo_do(ep->object,
         evas_obj_table_homogeneous_set(chosen_desc->table.homogeneous),
         evas_obj_table_align_set(TO_DOUBLE(chosen_desc->table.align.x), TO_DOUBLE(chosen_desc->table.align.y)),
         evas_obj_table_padding_set(chosen_desc->table.padding.x, chosen_desc->table.padding.y));
   if (evas_object_smart_need_recalculate_get(ep->object))
     {
        eo_do(ep->object,
              evas_obj_smart_need_recalculate_set(0),
              evas_obj_smart_calculate());
     }
}

static void
_edje_proxy_recalc_apply(Edje *ed, Edje_Real_Part *ep, Edje_Calc_Params *p3, Edje_Part_Description_Proxy *chosen_desc, FLOAT_T pos)
{
   Edje_Real_Part *pp;
   int part_id = -1;

   if (ep->param2 && (pos >= FROM_DOUBLE(0.5)))
     part_id = ((Edje_Part_Description_Proxy *)ep->param2->description)->proxy.id;
   else
     part_id = chosen_desc->proxy.id;

   if ((p3->type.common.fill.w == 0) || (p3->type.common.fill.h == 0) ||
       (part_id < 0))
     {
        evas_object_image_source_set(ep->object, NULL);
        return;
     }
   pp = ed->table_parts[part_id % ed->table_parts_size];

   if (pp->nested_smart)  /* using nested_smart for nested parts */
     {
        evas_object_image_source_set(ep->object, pp->nested_smart);
     }
   else
     {
        switch (pp->part->type)
          {
           case EDJE_PART_TYPE_IMAGE:
           case EDJE_PART_TYPE_TEXT:
           case EDJE_PART_TYPE_TEXTBLOCK:
           case EDJE_PART_TYPE_RECTANGLE:
           case EDJE_PART_TYPE_BOX:
           case EDJE_PART_TYPE_TABLE:
           case EDJE_PART_TYPE_PROXY:
           case EDJE_PART_TYPE_SNAPSHOT:
             evas_object_image_source_set(ep->object, pp->object);
             break;

           case EDJE_PART_TYPE_GRADIENT:
             /* FIXME: THIS ONE SHOULD NEVER BE TRIGGERED. */
             break;

           case EDJE_PART_TYPE_GROUP:
           case EDJE_PART_TYPE_SWALLOW:
           case EDJE_PART_TYPE_EXTERNAL:
             if ((pp->type == EDJE_RP_TYPE_SWALLOW) &&
                 (pp->typedata.swallow))
               {
                  evas_object_image_source_set(ep->object, pp->typedata.swallow->swallowed_object);
               }
             break;

           case EDJE_PART_TYPE_SPACER:
             /* FIXME: detect that at compile time and prevent it */
             break;
          }
     }

   eo_do(ep->object,
         efl_gfx_fill_set(p3->type.common.fill.x,
                          p3->type.common.fill.y,
                          p3->type.common.fill.w,
                          p3->type.common.fill.h),
         efl_image_smooth_scale_set(p3->smooth),
         evas_obj_image_source_visible_set(chosen_desc->proxy.source_visible),
         evas_obj_image_source_clip_set(chosen_desc->proxy.source_clip));
}

static void
_edje_image_recalc_apply(Edje *ed, Edje_Real_Part *ep, Edje_Calc_Params *p3, Edje_Part_Description_Image *chosen_desc, FLOAT_T pos)
{
   FLOAT_T sc;
   Edje_Real_Part_Set *set;

   sc = DIV(ed->scale, ed->file->base_scale);
   if (sc == ZERO) sc = DIV(_edje_scale, ed->file->base_scale);

   _edje_real_part_image_set(ed, ep, &set, pos);

   /* border */
   p3->type.common.spec.image.l = chosen_desc->image.border.l;
   p3->type.common.spec.image.r = chosen_desc->image.border.r;

   p3->type.common.spec.image.t = chosen_desc->image.border.t;
   p3->type.common.spec.image.b = chosen_desc->image.border.b;

   p3->type.common.spec.image.border_scale_by = chosen_desc->image.border.scale_by;

   if (set && set->set)
     {
#define SET_BORDER_DEFINED(Result, Value) Result = Value ? Value : Result;
        SET_BORDER_DEFINED(p3->type.common.spec.image.l, set->entry->border.l);
        SET_BORDER_DEFINED(p3->type.common.spec.image.r, set->entry->border.r);
        SET_BORDER_DEFINED(p3->type.common.spec.image.t, set->entry->border.t);
        SET_BORDER_DEFINED(p3->type.common.spec.image.b, set->entry->border.b);

        SET_BORDER_DEFINED(p3->type.common.spec.image.border_scale_by, set->entry->border.scale_by);
     }

   eo_do(ep->object,
         efl_gfx_fill_set(p3->type.common.fill.x, p3->type.common.fill.y,
                          p3->type.common.fill.w, p3->type.common.fill.h),
         efl_image_smooth_scale_set(p3->smooth));
   if (chosen_desc->image.border.scale)
     {
        if (p3->type.common.spec.image.border_scale_by > FROM_DOUBLE(0.0))
          {
             FLOAT_T sc2 = MUL(sc, p3->type.common.spec.image.border_scale_by);
             evas_object_image_border_scale_set(ep->object, TO_DOUBLE(sc2));
          }
        else
          evas_object_image_border_scale_set(ep->object, TO_DOUBLE(sc));
     }
   else
     {
        if (p3->type.common.spec.image.border_scale_by > FROM_DOUBLE(0.0))
          evas_object_image_border_scale_set
            (ep->object, TO_DOUBLE(p3->type.common.spec.image.border_scale_by));
        else
          evas_object_image_border_scale_set(ep->object, 1.0);
     }
   evas_object_image_border_set(ep->object, p3->type.common.spec.image.l, p3->type.common.spec.image.r,
                                p3->type.common.spec.image.t, p3->type.common.spec.image.b);
   if (chosen_desc->image.border.no_fill == 0)
     evas_object_image_border_center_fill_set(ep->object, EVAS_BORDER_FILL_DEFAULT);
   else if (chosen_desc->image.border.no_fill == 1)
     evas_object_image_border_center_fill_set(ep->object, EVAS_BORDER_FILL_NONE);
   else if (chosen_desc->image.border.no_fill == 2)
     evas_object_image_border_center_fill_set(ep->object, EVAS_BORDER_FILL_SOLID);
}

static Edje_Real_Part *
_edje_real_part_state_get(Edje *ed, Edje_Real_Part *ep, int flags, int id, int *state)
{
   Edje_Real_Part *result = NULL;

   if (id >= 0 && id != ep->part->id)
     {
        result = ed->table_parts[id % ed->table_parts_size];
        if (result)
          {
             if (!result->calculated) _edje_part_recalc(ed, result, flags, NULL);
#ifdef EDJE_CALC_CACHE
             if (state) *state = result->state;
#else
             (void)state;
#endif
          }
     }
   return result;
}

#ifdef HAVE_EPHYSICS
static Eina_Bool
_edje_physics_world_geometry_check(EPhysics_World *world)
{
   Evas_Coord w, h, d;
   ephysics_world_render_geometry_get(world, NULL, NULL, NULL, &w, &h, &d);
   return w && h && d;
}

static void
_edje_physics_body_props_update(Edje *ed, Edje_Real_Part *ep, Edje_Calc_Params *pf,
                                Eina_Bool pos_update)
{
   ephysics_body_linear_movement_enable_set(ep->body,
                                            pf->physics->mov_freedom.lin.x,
                                            pf->physics->mov_freedom.lin.y,
                                            pf->physics->mov_freedom.lin.z);
   ephysics_body_angular_movement_enable_set(ep->body,
                                             pf->physics->mov_freedom.ang.x,
                                             pf->physics->mov_freedom.ang.y,
                                             pf->physics->mov_freedom.ang.z);

   /* Boundaries geometry and mass shouldn't be changed */
   if (ep->part->physics_body < EDJE_PART_PHYSICS_BODY_BOUNDARY_TOP)
     {
        Evas_Coord x, y, z, w, h, d;

        if (pos_update)
          {
             ephysics_body_move(ep->body,
                                ed->x + pf->final.x,
                                ed->y + pf->final.y,
                                pf->physics->z);
             ep->x = pf->final.x;
             ep->y = pf->final.y;
             ep->w = pf->final.w;
             ep->h = pf->final.h;
          }

        ephysics_body_geometry_get(ep->body, &x, &y, &z, &w, &h, &d);
        if ((d) && (d != pf->physics->depth))
          ephysics_body_resize(ep->body, w, h, pf->physics->depth);
        if (z != pf->physics->z)
          ephysics_body_move(ep->body, x, y, pf->physics->z);

        ephysics_body_material_set(ep->body, pf->physics->material);
        if (!pf->physics->material)
          {
             if (pf->physics->density)
               ephysics_body_density_set(ep->body, pf->physics->density);
             else
               ephysics_body_mass_set(ep->body, pf->physics->mass);
          }

        if ((ep->part->physics_body == EDJE_PART_PHYSICS_BODY_SOFT_BOX) ||
            (ep->part->physics_body == EDJE_PART_PHYSICS_BODY_SOFT_SPHERE) ||
            (ep->part->physics_body == EDJE_PART_PHYSICS_BODY_SOFT_CYLINDER) ||
            (ep->part->physics_body == EDJE_PART_PHYSICS_BODY_CLOTH))
          ephysics_body_soft_body_hardness_set(ep->body,
                                               pf->physics->hardness * 100);
     }

   if (!pf->physics->material)
     {
        ephysics_body_restitution_set(ep->body, pf->physics->restitution);
        ephysics_body_friction_set(ep->body, pf->physics->friction);
     }

   ephysics_body_damping_set(ep->body, pf->physics->damping.linear,
                             pf->physics->damping.angular);
   ephysics_body_sleeping_threshold_set(ep->body, pf->physics->sleep.linear,
                                        pf->physics->sleep.angular);
   ephysics_body_light_set(ep->body, pf->physics->light_on);
   ephysics_body_back_face_culling_set(ep->body, pf->physics->backcull);
}

static void
_edje_physics_body_update_cb(void *data, EPhysics_Body *body, void *event_info EINA_UNUSED)
{
   Edje_Real_Part *rp = data;
   Edje *ed = ephysics_body_data_get(body);

   ephysics_body_geometry_get(body, &(rp->x), &(rp->y), NULL,
                              &(rp->w), &(rp->h), NULL);
   ephysics_body_evas_object_update(body);
   ed->dirty = EINA_TRUE;
}

static void
_edje_physics_body_add(Edje *ed, Edje_Real_Part *rp, EPhysics_World *world)
{
   Eina_Bool resize = EINA_TRUE;
   Edje_Physics_Face *pface;
   Eina_List *l;

   switch (rp->part->physics_body)
     {
      case EDJE_PART_PHYSICS_BODY_RIGID_BOX:
        rp->body = ephysics_body_box_add(world);
        break;

      case EDJE_PART_PHYSICS_BODY_RIGID_SPHERE:
        rp->body = ephysics_body_sphere_add(world);
        break;

      case EDJE_PART_PHYSICS_BODY_RIGID_CYLINDER:
        rp->body = ephysics_body_cylinder_add(world);
        break;

      case EDJE_PART_PHYSICS_BODY_SOFT_BOX:
        rp->body = ephysics_body_soft_box_add(world);
        break;

      case EDJE_PART_PHYSICS_BODY_SOFT_SPHERE:
        rp->body = ephysics_body_soft_sphere_add(world, 0);
        break;

      case EDJE_PART_PHYSICS_BODY_SOFT_CYLINDER:
        rp->body = ephysics_body_soft_cylinder_add(world);
        break;

      case EDJE_PART_PHYSICS_BODY_CLOTH:
        rp->body = ephysics_body_cloth_add(world, 0, 0);
        break;

      case EDJE_PART_PHYSICS_BODY_BOUNDARY_TOP:
        rp->body = ephysics_body_top_boundary_add(world);
        resize = EINA_FALSE;
        break;

      case EDJE_PART_PHYSICS_BODY_BOUNDARY_BOTTOM:
        rp->body = ephysics_body_bottom_boundary_add(world);
        resize = EINA_FALSE;
        break;

      case EDJE_PART_PHYSICS_BODY_BOUNDARY_RIGHT:
        rp->body = ephysics_body_right_boundary_add(world);
        resize = EINA_FALSE;
        break;

      case EDJE_PART_PHYSICS_BODY_BOUNDARY_LEFT:
        rp->body = ephysics_body_left_boundary_add(world);
        resize = EINA_FALSE;
        break;

      case EDJE_PART_PHYSICS_BODY_BOUNDARY_FRONT:
        rp->body = ephysics_body_front_boundary_add(world);
        resize = EINA_FALSE;
        break;

      case EDJE_PART_PHYSICS_BODY_BOUNDARY_BACK:
        rp->body = ephysics_body_back_boundary_add(world);
        resize = EINA_FALSE;
        break;

      default:
        ERR("Invalid body: %i", rp->part->physics_body);
        return;
     }

   EINA_LIST_FOREACH(rp->part->default_desc->physics.faces, l, pface)
     {
        Evas_Object *edje_obj;
        Evas *evas;

        if (!pface->source) continue;

        evas = evas_object_evas_get(rp->object);
        edje_obj = edje_object_add(evas);
        if (!edje_obj) continue;

        edje_object_file_set(edje_obj, ed->path, pface->source);
        evas_object_resize(edje_obj, 1, 1);
        ephysics_body_face_evas_object_set(rp->body, pface->type,
                                           edje_obj, EINA_FALSE);
        rp->body_faces = eina_list_append(rp->body_faces, edje_obj);
     }

   ephysics_body_evas_object_set(rp->body, rp->object, resize);
   ephysics_body_event_callback_add(rp->body, EPHYSICS_CALLBACK_BODY_UPDATE,
                                    _edje_physics_body_update_cb, rp);
   ephysics_body_data_set(rp->body, ed);
}

#endif

#define FINTP(_x1, _x2, _p) \
  (((_x1) == (_x2))         \
   ? FROM_INT((_x1))        \
   : ADD(FROM_INT(_x1),     \
         SCALE((_p), (_x2) - (_x1))))

#define FFP(_x1, _x2, _p) \
  (((_x1) == (_x2))       \
   ? (_x1)                \
   : ADD(_x1, MUL(_p, SUB(_x2, _x1))));

#define INTP(_x1, _x2, _p) TO_INT(FINTP(_x1, _x2, _p))

static void
_map_colors_free(Edje_Calc_Params *pf)
{
   Edje_Map_Color **colors = pf->map->colors;
   int i;

   for (i = 0; i < (int)pf->map->colors_count; i++)
     free(colors[i]);
   free(colors);
}

static Eina_Bool
_map_colors_interp(Edje_Calc_Params *p1, Edje_Calc_Params *p2,
                   Edje_Calc_Params_Map *pmap, FLOAT_T pos)
{
   Edje_Map_Color *col, *col2, *col3;
   int i, j, idx = 0;
   Eina_Bool matched = EINA_FALSE;

   if ((p1->map->colors_count > 0) || (p2->map->colors_count > 0))
     {
        pmap->colors_count = (p1->map->colors_count > p2->map->colors_count ? p1->map->colors_count : p2->map->colors_count);

        pmap->colors = (Edje_Map_Color **)malloc(sizeof(Edje_Map_Color *) * (int)pmap->colors_count);

        for (i = 0; i < (int)p1->map->colors_count; i++)
          {
             col = p1->map->colors[i];
             col3 = malloc(sizeof(Edje_Map_Color));
             col3->idx = col->idx;

             for (j = 0; j < (int)p2->map->colors_count; j++)
               {
                  col2 = p2->map->colors[j];
                  if (col->idx != col2->idx) continue;
                  col3->r = INTP(col->r, col2->r, pos);
                  col3->g = INTP(col->g, col2->g, pos);
                  col3->b = INTP(col->b, col2->b, pos);
                  col3->a = INTP(col->a, col2->a, pos);
                  pmap->colors[idx] = col3;
                  matched = EINA_TRUE;
                  break;
               }
             if (!matched)
               {
                  col3->r = INTP(col->r, 255, pos);
                  col3->g = INTP(col->g, 255, pos);
                  col3->b = INTP(col->b, 255, pos);
                  col3->a = INTP(col->a, 255, pos);
                  pmap->colors[idx] = col3;
               }
             idx++;
             matched = EINA_FALSE;
          }
        for (i = 0; i < (int)p2->map->colors_count; i++)
          {
             col = p2->map->colors[i];

             for (j = 0; j < (int)p1->map->colors_count; j++)
               {
                  col2 = p1->map->colors[j];
                  if (col->idx != col2->idx) continue;
                  matched = EINA_TRUE;
                  break;
               }
             if (!matched)
               {
                  col3 = malloc(sizeof(Edje_Map_Color));
                  col3->idx = col->idx;
                  col3->r = INTP(255, col->r, pos);
                  col3->g = INTP(255, col->g, pos);
                  col3->b = INTP(255, col->b, pos);
                  col3->a = INTP(255, col->a, pos);
                  pmap->colors[idx] = col3;
               }
             idx++;
             matched = EINA_FALSE;
          }
        return EINA_TRUE;
     }

   return EINA_FALSE;
}

static void
_edje_map_prop_set(Evas_Map *map, const Edje_Calc_Params *pf,
                   Edje_Part_Description_Common *chosen_desc,
                   Edje_Real_Part *ep, Evas_Object *mo)
{
   Edje_Map_Color **colors = pf->map->colors;
   int colors_cnt = pf->map->colors_count;
   int i;

   Edje_Map_Color *color;

   evas_map_util_points_populate_from_object(map, ep->object);

   if (ep->part->type == EDJE_PART_TYPE_IMAGE ||
       ((ep->part->type == EDJE_PART_TYPE_SWALLOW) &&
        (eo_isa(mo, EVAS_IMAGE_CLASS) &&
         (!evas_object_image_source_get(mo))))
       )
     {
        int iw = 1, ih = 1;

        evas_object_image_size_get(mo, &iw, &ih);
        evas_map_point_image_uv_set(map, 0, 0.0, 0.0);
        evas_map_point_image_uv_set(map, 1, iw, 0.0);
        evas_map_point_image_uv_set(map, 2, iw, ih);
        evas_map_point_image_uv_set(map, 3, 0.0, ih);
     }

   //map color
   if (colors_cnt == 0)
     {
        evas_map_point_color_set(map, 0, 255, 255, 255, 255);
        evas_map_point_color_set(map, 1, 255, 255, 255, 255);
        evas_map_point_color_set(map, 2, 255, 255, 255, 255);
        evas_map_point_color_set(map, 3, 255, 255, 255, 255);
     }
   else
     {
        for (i = 0; i < colors_cnt; i++)
          {
             color = colors[i];
             evas_map_point_color_set(map, color->idx, color->r, color->g,
                                      color->b, color->a);
          }
     }

   //zoom
   evas_map_util_zoom(map,
                      pf->map->zoom.x, pf->map->zoom.y,
                      pf->map->center.x, pf->map->center.y);

   //rotate
   evas_map_util_3d_rotate(map,
                           TO_DOUBLE(pf->map->rotation.x),
                           TO_DOUBLE(pf->map->rotation.y),
                           TO_DOUBLE(pf->map->rotation.z),
                           pf->map->center.x, pf->map->center.y,
                           pf->map->center.z);

   // calculate light color & position etc. if there is one
   if (pf->lighted)
     {
        evas_map_util_3d_lighting(map, pf->map->light.x, pf->map->light.y,
                                  pf->map->light.z, pf->map->light.r,
                                  pf->map->light.g, pf->map->light.b,
                                  pf->map->light.ar, pf->map->light.ag,
                                  pf->map->light.ab);
     }

   // calculate perspective point
   if (chosen_desc->map.persp_on)
     {
        evas_map_util_3d_perspective(map,
                                     pf->map->persp.x, pf->map->persp.y,
                                     pf->map->persp.z, pf->map->persp.focal);
     }

   // handle backface culling (object is facing away from view
   if (chosen_desc->map.backcull)
     {
        if (pf->visible)
          {
             if (evas_map_util_clockwise_get(map))
               evas_object_show(mo);
             else evas_object_hide(mo);
          }
     }

   // handle smooth
   if (chosen_desc->map.smooth) evas_map_smooth_set(map, EINA_TRUE);
   else evas_map_smooth_set(map, EINA_FALSE);
   // handle alpha
   if (chosen_desc->map.alpha) evas_map_alpha_set(map, EINA_TRUE);
   else evas_map_alpha_set(map, EINA_FALSE);
}

#define Rel1X 0
#define Rel1Y 1
#define Rel2X 2
#define Rel2Y 3

void
_edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *state)
{
#ifdef EDJE_CALC_CACHE
   Eina_Bool proxy_invalidate = EINA_FALSE;
   int state1 = -1;
   int state2 = -1;
   int statec = -1;
   int statet = -1;
#else
   Edje_Calc_Params lp1, lp2;
#endif
   int statec1 = -1;
   int statec2 = -1;
   int statel1 = -1;
   int statel2 = -1;
   int statep1 = -1;
   int statep2 = -1;
   int statecl = -1;
   Edje_Real_Part *center[2] = { NULL, NULL };
   Edje_Real_Part *light[2] = { NULL, NULL };
   Edje_Real_Part *persp[2] = { NULL, NULL };
   Edje_Real_Part *rp1[4] = { NULL, NULL, NULL, NULL };
   Edje_Real_Part *rp2[4] = { NULL, NULL, NULL, NULL };
   Edje_Real_Part *clip1 = NULL, *clip2 = NULL;
   Edje_Calc_Params *p1, *pf;
   Edje_Part_Description_Common *chosen_desc;
   Edje_Real_Part *confine_to = NULL;
   Edje_Real_Part *threshold = NULL;
   FLOAT_T pos = ZERO, pos2;
   Edje_Calc_Params lp3;
   Evas_Coord mmw = 0, mmh = 0;
   Eina_Bool map_colors_free = EINA_FALSE;

   /* GRADIENT ARE GONE, WE MUST IGNORE IT FROM OLD FILE. */
   if (ep->part->type == EDJE_PART_TYPE_GRADIENT)
     {
        ERR("GRADIENT spotted during recalc ! That should never happen ! Send your edje file to devel ml.");
        return;
     }

   if ((ep->calculated & FLAG_XY) == FLAG_XY && !state)
     {
        return;
     }
   if (ep->calculating & flags)
     {
#if 1
        const char *axes = "NONE", *faxes = "NONE";

        if ((ep->calculating & FLAG_X) &&
            (ep->calculating & FLAG_Y))
          axes = "XY";
        else if ((ep->calculating & FLAG_X))
          axes = "X";
        else if ((ep->calculating & FLAG_Y))
          axes = "Y";

        if ((flags & FLAG_X) &&
            (flags & FLAG_Y))
          faxes = "XY";
        else if ((flags & FLAG_X))
          faxes = "X";
        else if ((flags & FLAG_Y))
          faxes = "Y";
        ERR("Circular dependency when calculating part \"%s\". "
            "Already calculating %s [%02x] axes. "
            "Need to calculate %s [%02x] axes",
            ep->part->name,
            axes, ep->calculating,
            faxes, flags);
#endif
        return;
     }

   if (ep->part->type == EDJE_PART_TYPE_GROUP &&
       ((ep->type == EDJE_RP_TYPE_SWALLOW) &&
        (ep->typedata.swallow)) &&
       ep->typedata.swallow->swallowed_object)
     {
        edje_object_scale_set(ep->typedata.swallow->swallowed_object, TO_DOUBLE(ed->scale));

        if (ep->description_pos > FROM_DOUBLE(0.5) && ep->param2)
          {
             edje_object_update_hints_set(ep->typedata.swallow->swallowed_object, ep->param2->description->min.limit);
          }
        else
          {
             edje_object_update_hints_set(ep->typedata.swallow->swallowed_object, ep->param1.description->min.limit);
          }
        if (edje_object_update_hints_get(ep->typedata.swallow->swallowed_object))
          {
             Edje *ted;

             ted = _edje_fetch(ep->typedata.swallow->swallowed_object);
             _edje_recalc_do(ted);
          }
     }
   if (ep->part->type == EDJE_PART_TYPE_GROUP &&
       ((ep->type == EDJE_RP_TYPE_SWALLOW) &&
        (ep->typedata.swallow)) &&
       ep->typedata.swallow->swallowed_object)
     {
        Edje_Size *min = NULL, *max = NULL;

        if (ep->chosen_description)
          {
             min = &ep->chosen_description->min;
             max = &ep->chosen_description->max;
          }
        if (min && max && (min->w == max->w) && (min->h == max->h) && (min->w > 0) && (min->h > 0))
          mmw = min->w, mmh = min->h;
        else
          edje_object_size_min_calc(ep->typedata.swallow->swallowed_object,
                                    &mmw, &mmh);
     }

#ifdef EDJE_CALC_CACHE
   if (ep->state == ed->state && !state)
     return;
#endif

   if (ep->param1.description)
     {
        if (ep->param1.description->rel1.id_x >= 0)
          rp1[Rel1X] = ed->table_parts[ep->param1.description->rel1.id_x];
        if (ep->param1.description->rel2.id_x >= 0)
          rp1[Rel2X] = ed->table_parts[ep->param1.description->rel2.id_x];
        if (ep->param1.description->rel1.id_y >= 0)
          rp1[Rel1Y] = ed->table_parts[ep->param1.description->rel1.id_y];
        if (ep->param1.description->rel2.id_y >= 0)
          rp1[Rel2Y] = ed->table_parts[ep->param1.description->rel2.id_y];
        if (ep->param1.description->clip_to_id >= 0)
          clip1 = ed->table_parts[ep->param1.description->clip_to_id % ed->table_parts_size];
     }
   if (ep->param2)
     {
        if (ep->param2->description->rel1.id_x >= 0)
          rp2[Rel1X] = ed->table_parts[ep->param2->description->rel1.id_x];
        if (ep->param2->description->rel2.id_x >= 0)
          rp2[Rel2X] = ed->table_parts[ep->param2->description->rel2.id_x];
        if (ep->param2->description->rel1.id_y >= 0)
          rp2[Rel1Y] = ed->table_parts[ep->param2->description->rel1.id_y];
        if (ep->param2->description->rel2.id_y >= 0)
          rp2[Rel2Y] = ed->table_parts[ep->param2->description->rel2.id_y];
        if (ep->param2->description->clip_to_id >= 0)
          clip2 = ed->table_parts[ep->param2->description->clip_to_id % ed->table_parts_size];
     }

   if (flags & FLAG_X)
     {
        ep->calculating |= flags & FLAG_X;
        if (rp1[Rel1X])
          {
             _edje_part_recalc(ed, rp1[Rel1X], FLAG_X, NULL);
#ifdef EDJE_CALC_CACHE
             state1 = rp1[Rel1X]->state;
#endif
          }
        if (rp1[Rel2X])
          {
             _edje_part_recalc(ed, rp1[Rel2X], FLAG_X, NULL);
#ifdef EDJE_CALC_CACHE
             if (state1 < rp1[Rel2X]->state)
               state1 = rp1[Rel2X]->state;
#endif
          }
        if (ep->param2)
          {
             if (rp2[Rel1X])
               {
                  _edje_part_recalc(ed, rp2[Rel1X], FLAG_X, NULL);
#ifdef EDJE_CALC_CACHE
                  state2 = rp2[Rel1X]->state;
#endif
               }
             if (rp2[Rel2X])
               {
                  _edje_part_recalc(ed, rp2[Rel2X], FLAG_X, NULL);
#ifdef EDJE_CALC_CACHE
                  if (state2 < rp2[Rel2X]->state)
                    state2 = rp2[Rel2X]->state;
#endif
               }
          }
     }
   if (flags & FLAG_Y)
     {
        ep->calculating |= flags & FLAG_Y;
        if (rp1[Rel1Y])
          {
             _edje_part_recalc(ed, rp1[Rel1Y], FLAG_Y, NULL);
#ifdef EDJE_CALC_CACHE
             if (state1 < rp1[Rel1Y]->state)
               state1 = rp1[Rel1Y]->state;
#endif
          }
        if (rp1[Rel2Y])
          {
             _edje_part_recalc(ed, rp1[Rel2Y], FLAG_Y, NULL);
#ifdef EDJE_CALC_CACHE
             if (state1 < rp1[Rel2Y]->state)
               state1 = rp1[Rel2Y]->state;
#endif
          }
        if (ep->param2)
          {
             if (rp2[Rel1Y])
               {
                  _edje_part_recalc(ed, rp2[Rel1Y], FLAG_Y, NULL);
#ifdef EDJE_CALC_CACHE
                  if (state2 < rp2[Rel1Y]->state)
                    state2 = rp2[Rel1Y]->state;
#endif
               }
             if (rp2[Rel2Y])
               {
                  _edje_part_recalc(ed, rp2[Rel2Y], FLAG_Y, NULL);
#ifdef EDJE_CALC_CACHE
                  if (state2 < rp2[Rel2Y]->state)
                    state2 = rp2[Rel2Y]->state;
#endif
               }
          }
     }
   if (clip1)
     {
        _edje_part_recalc(ed, clip1, flags, NULL);
        statecl = clip1->state;
     }
   if (clip2)
     {
        _edje_part_recalc(ed, clip2, flags, NULL);
        if (statecl < clip2->state)
          statecl = clip2->state;
     }
   if (ep->drag)
     {
        if (ep->drag->confine_to)
          {
             confine_to = ep->drag->confine_to;
             _edje_part_recalc(ed, confine_to, flags, NULL);
#ifdef EDJE_CALC_CACHE
             statec = confine_to->state;
#endif
          }
        if (ep->drag->threshold)
          {
             threshold = ep->drag->threshold;
             // We shall not recalculate the threshold position as
             // we use it's previous position to assert the threshold
             // the one before moving take action.
#ifdef EDJE_CALC_CACHE
             statet = threshold->state;
#endif
          }
     }
   //   if (ep->text.source)       _edje_part_recalc(ed, ep->text.source, flags);
   //   if (ep->text.text_source)  _edje_part_recalc(ed, ep->text.text_source, flags);

   /* actually calculate now */
   chosen_desc = ep->chosen_description;
   if (!chosen_desc)
     {
        ep->calculating = FLAG_NONE;
        ep->calculated |= flags;
        return;
     }

   pos = ep->description_pos;

   if ((ep->part->type == EDJE_PART_TYPE_PROXY) && chosen_desc->visible)
     {
        int part_id = -1;

        if (ep->param2 && (pos >= FROM_DOUBLE(0.5)))
          part_id = ((Edje_Part_Description_Proxy *)ep->param2->description)->proxy.id;
        else
          part_id = ((Edje_Part_Description_Proxy *)chosen_desc)->proxy.id;

#ifdef EDJE_CALC_CACHE
        Edje_Real_Part *pp;
        pp = _edje_real_part_state_get(ed, ep, flags, part_id, NULL);
        if (pp && pp->invalidate) proxy_invalidate = EINA_TRUE;
#else
        _edje_real_part_state_get(ed, ep, flags, part_id, NULL);
#endif
     }

   /* Recalc if needed the map center && light source */
   if (ep->param1.description->map.on)
     {
        center[0] = _edje_real_part_state_get(ed, ep, flags, ep->param1.description->map.rot.id_center, &statec1);
        light[0] = _edje_real_part_state_get(ed, ep, flags, ep->param1.description->map.id_light, &statel1);

        if (chosen_desc->map.persp_on)
          {
             persp[0] = _edje_real_part_state_get(ed, ep, flags, ep->param1.description->map.id_persp, &statep1);
          }
     }

   if (ep->param2 && ep->param2->description->map.on)
     {
        center[1] = _edje_real_part_state_get(ed, ep, flags, ep->param2->description->map.rot.id_center, &statec2);
        light[1] = _edje_real_part_state_get(ed, ep, flags, ep->param2->description->map.id_light, &statel2);

        if (chosen_desc->map.persp_on)
          {
             persp[1] = _edje_real_part_state_get(ed, ep, flags, ep->param2->description->map.id_persp, &statep2);
          }
     }

#ifndef EDJE_CALC_CACHE
   p1 = &lp1;
   p1.map = eina_cow_alloc(_edje_calc_params_map_cow);
#ifdef HAVE_EPHYSICS
   p1.physics = eina_cow_alloc(_edje_calc_params_physics_cow);
#endif
#else
   p1 = &ep->param1.p;
#endif

   if (ep->param1.description)
     {
#ifdef EDJE_CALC_CACHE
        if (ed->all_part_change ||
            ep->invalidate ||
            (state1 >= ep->param1.state) ||
            (statec >= ep->param1.state) ||
            (statet >= ep->param1.state) ||
            (statec1 >= ep->param1.state) ||
            (statel1 >= ep->param1.state) ||
            (statep1 >= ep->param1.state) ||
            (statecl >= ep->param1.state) ||
            proxy_invalidate ||
            state ||
            ed->need_map_update ||
            ((ep->part->type == EDJE_PART_TYPE_TEXT ||
              ep->part->type == EDJE_PART_TYPE_TEXTBLOCK) &&
             ed->text_part_change))
#endif
        {
           _edje_part_recalc_single(ed, ep, ep->param1.description,
                                    chosen_desc, center[0], light[0],
                                    persp[0], rp1[Rel1X], rp1[Rel1Y],
                                    rp1[Rel2X], rp1[Rel2Y], clip1, confine_to,
                                    threshold, p1, mmw, mmh,
                                    pos);
#ifdef EDJE_CALC_CACHE
           if (flags == FLAG_XY) ep->param1.state = ed->state;
#endif
        }
     }
   if (ep->param2)
     {
        int beginning_pos, part_type;
        Edje_Calc_Params *p2, *p3;

        if (ep->current)
          {
             const Edje_Calc_Params_Map *map;
#ifdef HAVE_EPHYSICS
             const Edje_Calc_Params_Physics *physics;
#endif

             map = p1->map;
#ifdef HAVE_EPHYSICS
             physics = p1->physics;
#endif

             /* FIXME: except for text, we don't need in that case to recalc p1 at all*/
             memcpy(p1, ep->current, sizeof (Edje_Calc_Params));

             p1->map = map;
#ifdef HAVE_EPHYSICS
             p1->physics = physics;
#endif
          }

        p3 = &lp3;
        lp3.map = eina_cow_alloc(_edje_calc_params_map_cow);
#ifdef HAVE_EPHYSICS
        lp3.physics = eina_cow_alloc(_edje_calc_params_physics_cow);
#endif

#ifndef EDJE_CALC_CACHE
        p2 = &lp2;
        lp2.map = eina_cow_alloc(_edje_calc_params_map_cow);
#ifdef HAVE_EPHYSICS
        lp2.physics = eina_cow_alloc(_edje_calc_params_physics_cow);
#endif
#else
        p2 = &ep->param2->p;

        if (ed->all_part_change ||
            ep->invalidate ||
            (state2 >= ep->param2->state) ||
            (statec >= ep->param2->state) ||
            (statet >= ep->param2->state) ||
            (statec2 >= ep->param2->state) ||
            (statel2 >= ep->param2->state) ||
            (statep2 >= ep->param2->state) ||
            (statecl >= ep->param2->state) ||
            proxy_invalidate ||
            state ||
            ed->need_map_update ||
            ((ep->part->type == EDJE_PART_TYPE_TEXT ||
              ep->part->type == EDJE_PART_TYPE_TEXTBLOCK) &&
             ed->text_part_change))
#endif
        {
           _edje_part_recalc_single(ed, ep, ep->param2->description,
                                    chosen_desc, center[1], light[1],
                                    persp[1], rp2[Rel1X], rp2[Rel1Y],
                                    rp2[Rel2X], rp2[Rel2Y], clip2, confine_to,
                                    threshold, p2, mmw, mmh,
                                    pos);
#ifdef EDJE_CALC_CACHE
           if (flags == FLAG_XY) ep->param2->state = ed->state;
#endif
        }

        pos2 = pos;
        if (pos2 < ZERO) pos2 = ZERO;
        else if (pos2 > FROM_INT(1))
          pos2 = FROM_INT(1);
        beginning_pos = (pos < FROM_DOUBLE(0.5));
        part_type = ep->part->type;

        /* visible is special */
        if ((p1->visible) && (!p2->visible))
          p3->visible = (pos != FROM_INT(1));
        else if ((!p1->visible) && (p2->visible))
          p3->visible = (pos != ZERO);
        else
          p3->visible = p1->visible;

        /* clip_to will behave a bit like visible */
        if (pos == ZERO)
          p3->clip_to = p1->clip_to;
        else if (pos == FROM_INT(1))
          p3->clip_to = p2->clip_to;
        else if (!p1->clip_to)
          p3->clip_to = p2->clip_to;
        else
          p3->clip_to = p1->clip_to;

        p3->smooth = (beginning_pos) ? p1->smooth : p2->smooth;

        /* FIXME: do x and y separately base on flag */

        p3->final.x = INTP(p1->final.x, p2->final.x, pos);
        p3->final.y = INTP(p1->final.y, p2->final.y, pos);
        p3->final.w = INTP(p1->final.w, p2->final.w, pos);
        p3->final.h = INTP(p1->final.h, p2->final.h, pos);

        p3->eval.x = FFP(p1->eval.x, p2->eval.x, pos);
        p3->eval.y = FFP(p1->eval.y, p2->eval.y, pos);
        p3->eval.w = FFP(p1->eval.w, p2->eval.w, pos);
        p3->eval.h = FFP(p1->eval.h, p2->eval.h, pos);

        p3->req.x = INTP(p1->req.x, p2->req.x, pos);
        p3->req.y = INTP(p1->req.y, p2->req.y, pos);
        p3->req.w = INTP(p1->req.w, p2->req.w, pos);
        p3->req.h = INTP(p1->req.h, p2->req.h, pos);

        if (ep->part->dragable.x)
          {
             p3->req_drag.x = INTP(p1->req_drag.x, p2->req_drag.x, pos);
             p3->req_drag.w = INTP(p1->req_drag.w, p2->req_drag.w, pos);
          }
        if (ep->part->dragable.y)
          {
             p3->req_drag.y = INTP(p1->req_drag.y, p2->req_drag.y, pos);
             p3->req_drag.h = INTP(p1->req_drag.h, p2->req_drag.h, pos);
          }

        p3->color.r = INTP(p1->color.r, p2->color.r, pos2);
        p3->color.g = INTP(p1->color.g, p2->color.g, pos2);
        p3->color.b = INTP(p1->color.b, p2->color.b, pos2);
        p3->color.a = INTP(p1->color.a, p2->color.a, pos2);

#ifdef HAVE_EPHYSICS
        if (ep->part->physics_body || ep->body)
          {
             EINA_COW_CALC_PHYSICS_BEGIN(p3, p3_write)
             {
                p3_write->mass = TO_DOUBLE(FINTP(p1->physics->mass, p2->physics->mass,
                                                 pos));
                p3_write->restitution = TO_DOUBLE(FINTP(p1->physics->restitution,
                                                        p2->physics->restitution,
                                                        pos));
                p3_write->friction = TO_DOUBLE(FINTP(p1->physics->friction,
                                                     p2->physics->friction, pos));
                p3_write->density = TO_DOUBLE(FINTP(p1->physics->density,
                                                    p2->physics->density, pos));
                p3_write->hardness = TO_DOUBLE(FINTP(p1->physics->hardness,
                                                     p2->physics->hardness, pos));

                p3_write->damping.linear = TO_DOUBLE(FINTP(p1->physics->damping.linear,
                                                           p2->physics->damping.linear, pos));
                p3_write->damping.angular = TO_DOUBLE(FINTP(p1->physics->damping.angular,
                                                            p2->physics->damping.angular, pos));

                p3_write->sleep.linear = TO_DOUBLE(FINTP(p1->physics->sleep.linear,
                                                         p2->physics->sleep.linear, pos));
                p3_write->sleep.angular = TO_DOUBLE(FINTP(p1->physics->sleep.angular,
                                                          p2->physics->sleep.angular, pos));

                p3_write->z = INTP(p1->physics->z, p2->physics->z, pos);
                p3_write->depth = INTP(p1->physics->depth, p2->physics->depth, pos);

                if ((p1->physics->ignore_part_pos) && (p2->physics->ignore_part_pos))
                  p3_write->ignore_part_pos = 1;
                else
                  p3_write->ignore_part_pos = 0;

                if ((p1->physics->material) && (p2->physics->material))
                  p3_write->material = p1->physics->material;
                else
                  p3_write->material = EPHYSICS_BODY_MATERIAL_CUSTOM;

                p3_write->light_on = p1->physics->light_on || p2->physics->light_on;
                p3_write->backcull = p1->physics->backcull || p2->physics->backcull;

                p3_write->mov_freedom.lin.x = p1->physics->mov_freedom.lin.x ||
                  p2->physics->mov_freedom.lin.x;
                p3_write->mov_freedom.lin.y = p1->physics->mov_freedom.lin.y ||
                  p2->physics->mov_freedom.lin.y;
                p3_write->mov_freedom.lin.z = p1->physics->mov_freedom.lin.z ||
                  p2->physics->mov_freedom.lin.z;
                p3_write->mov_freedom.ang.x = p1->physics->mov_freedom.ang.x ||
                  p2->physics->mov_freedom.ang.x;
                p3_write->mov_freedom.ang.y = p1->physics->mov_freedom.ang.y ||
                  p2->physics->mov_freedom.ang.y;
                p3_write->mov_freedom.ang.z = p1->physics->mov_freedom.ang.z ||
                  p2->physics->mov_freedom.ang.z;
             }
             EINA_COW_CALC_PHYSICS_END(p3, p3_write);
          }
#endif

        switch (part_type)
          {
           case EDJE_PART_TYPE_IMAGE:
             p3->type.common.spec.image.l = INTP(p1->type.common.spec.image.l, p2->type.common.spec.image.l, pos);
             p3->type.common.spec.image.r = INTP(p1->type.common.spec.image.r, p2->type.common.spec.image.r, pos);
             p3->type.common.spec.image.t = INTP(p1->type.common.spec.image.t, p2->type.common.spec.image.t, pos);
             p3->type.common.spec.image.b = INTP(p1->type.common.spec.image.b, p2->type.common.spec.image.b, pos);
             p3->type.common.spec.image.border_scale_by = FFP(p1->type.common.spec.image.border_scale_by, p2->type.common.spec.image.border_scale_by, pos);

           case EDJE_PART_TYPE_PROXY:
             p3->type.common.fill.x = INTP(p1->type.common.fill.x, p2->type.common.fill.x, pos);
             p3->type.common.fill.y = INTP(p1->type.common.fill.y, p2->type.common.fill.y, pos);
             p3->type.common.fill.w = INTP(p1->type.common.fill.w, p2->type.common.fill.w, pos);
             p3->type.common.fill.h = INTP(p1->type.common.fill.h, p2->type.common.fill.h, pos);
             break;

           case EDJE_PART_TYPE_TEXT:
             p3->type.text.size = INTP(p1->type.text.size, p2->type.text.size, pos);

           /* no break as we share code with the TEXTBLOCK type here. Intended fall-through */
           case EDJE_PART_TYPE_TEXTBLOCK:
             p3->type.text.color2.r = INTP(p1->type.text.color2.r, p2->type.text.color2.r, pos2);
             p3->type.text.color2.g = INTP(p1->type.text.color2.g, p2->type.text.color2.g, pos2);
             p3->type.text.color2.b = INTP(p1->type.text.color2.b, p2->type.text.color2.b, pos2);
             p3->type.text.color2.a = INTP(p1->type.text.color2.a, p2->type.text.color2.a, pos2);

             p3->type.text.color3.r = INTP(p1->type.text.color3.r, p2->type.text.color3.r, pos2);
             p3->type.text.color3.g = INTP(p1->type.text.color3.g, p2->type.text.color3.g, pos2);
             p3->type.text.color3.b = INTP(p1->type.text.color3.b, p2->type.text.color3.b, pos2);
             p3->type.text.color3.a = INTP(p1->type.text.color3.a, p2->type.text.color3.a, pos2);

             p3->type.text.align.x = FFP(p1->type.text.align.x, p2->type.text.align.x, pos);
             p3->type.text.align.y = FFP(p1->type.text.align.y, p2->type.text.align.y, pos);
             p3->type.text.ellipsis = TO_DOUBLE(FINTP(p1->type.text.ellipsis, p2->type.text.ellipsis, pos2));
             break;
          }

        /* mapped is a special case like visible */
        if ((p1->mapped) && (!p2->mapped))
          p3->mapped = (pos != FROM_INT(1));
        else if ((!p1->mapped) && (p2->mapped))
          p3->mapped = (pos != ZERO);
        else
          p3->mapped = p1->mapped;

        p3->persp_on = p3->mapped ? p1->persp_on | p2->persp_on : 0;
        p3->lighted = p3->mapped ? p1->lighted | p2->lighted : 0;
        if (p3->mapped)
          {
             EINA_COW_CALC_MAP_BEGIN(p3, p3_write)
             {
                p3_write->center.x = INTP(p1->map->center.x, p2->map->center.x, pos);
                p3_write->center.y = INTP(p1->map->center.y, p2->map->center.y, pos);
                p3_write->center.z = INTP(p1->map->center.z, p2->map->center.z, pos);
                p3_write->rotation.x = FFP(p1->map->rotation.x, p2->map->rotation.x, pos);
                p3_write->rotation.y = FFP(p1->map->rotation.y, p2->map->rotation.y, pos);
                p3_write->rotation.z = FFP(p1->map->rotation.z, p2->map->rotation.z, pos);
                p3_write->zoom.x = FFP(p1->map->zoom.x, p2->map->zoom.x, pos);
                p3_write->zoom.y = FFP(p1->map->zoom.y, p2->map->zoom.y, pos);

#define MIX(P1, P2, P3, pos, info) \
  P3->info = P1->map->info + TO_INT(SCALE(pos, P2->map->info - P1->map->info));
                map_colors_free = _map_colors_interp(p1, p2, p3_write, pos);

                if (p1->lighted && p2->lighted)
                  {
                     MIX(p1, p2, p3_write, pos, light.x);
                     MIX(p1, p2, p3_write, pos, light.y);
                     MIX(p1, p2, p3_write, pos, light.z);
                     MIX(p1, p2, p3_write, pos, light.r);
                     MIX(p1, p2, p3_write, pos, light.g);
                     MIX(p1, p2, p3_write, pos, light.b);
                     MIX(p1, p2, p3_write, pos, light.ar);
                     MIX(p1, p2, p3_write, pos, light.ag);
                     MIX(p1, p2, p3_write, pos, light.ab);
                  }
                else if (p1->lighted)
                  {
                     memcpy(&p3_write->light, &p1->map->light, sizeof (p1->map->light));
                  }
                else if (p2->lighted)
                  {
                     memcpy(&p3_write->light, &p2->map->light, sizeof (p2->map->light));
                  }

                if (p1->persp_on && p2->persp_on)
                  {
                     MIX(p1, p2, p3_write, pos, persp.x);
                     MIX(p1, p2, p3_write, pos, persp.y);
                     MIX(p1, p2, p3_write, pos, persp.z);
                     MIX(p1, p2, p3_write, pos, persp.focal);
                  }
                else if (p1->persp_on)
                  {
                     memcpy(&p3_write->persp, &p1->map->persp, sizeof (p1->map->persp));
                  }
                else if (p2->persp_on)
                  {
                     memcpy(&p3_write->persp, &p2->map->persp, sizeof (p2->map->persp));
                  }
             }
             EINA_COW_CALC_MAP_END(p3, p3_write);
          }

#ifndef EDJE_CALC_CACHE
        eina_cow_free(_edje_calc_params_map_cow, (const Eina_Cow_Data **)&lp2.map);
#ifdef HAVE_EPHYSICS
        eina_cow_free(_edje_calc_params_physics_cow, (const Eina_Cow_Data **)&lp2.physics);
#endif
#endif
        pf = p3;
     }
   else
     {
        pf = p1;
     }

   if (!pf->persp_on && chosen_desc->map.persp_on)
     {
        if (ed->persp)
          {
             EINA_COW_CALC_MAP_BEGIN(pf, pf_write)
             {
                pf_write->persp.x = ed->persp->px;
                pf_write->persp.y = ed->persp->py;
                pf_write->persp.z = ed->persp->z0;
                pf_write->persp.focal = ed->persp->foc;
             }
             EINA_COW_CALC_MAP_END(pf, pf_write);
          }
        else
          {
             const Edje_Perspective *ps;

             // fixme: a tad inefficient as this is a has lookup
             ps = edje_object_perspective_get(ed->obj);
             if (!ps)
               ps = edje_evas_global_perspective_get(evas_object_evas_get(ed->obj));
             EINA_COW_CALC_MAP_BEGIN(pf, pf_write)
             {
                if (ps)
                  {
                     pf_write->persp.x = ps->px;
                     pf_write->persp.y = ps->py;
                     pf_write->persp.z = ps->z0;
                     pf_write->persp.focal = ps->foc;
                  }
                else
                  {
                     pf_write->persp.x = ed->x + (ed->w / 2);
                     pf_write->persp.y = ed->y + (ed->h / 2);
                     pf_write->persp.z = 0;
                     pf_write->persp.focal = 1000;
                  }
             }
             EINA_COW_CALC_MAP_END(pf, pf_write);
          }
     }

   if (state)
     {
        const Edje_Calc_Params_Map *map;
#ifdef HAVE_EPHYSICS
        const Edje_Calc_Params_Physics *physics;
#endif

        map = state->map;
#ifdef HAVE_EPHYSICS
        physics = state->physics;
#endif

        memcpy(state, pf, sizeof (Edje_Calc_Params));

        state->map = map;
#ifdef HAVE_EPHYSICS
        state->physics = physics;
#endif
        eina_cow_memcpy(_edje_calc_params_map_cow, (const Eina_Cow_Data **)&state->map, pf->map);
#ifdef HAVE_EPHYSICS
        eina_cow_memcpy(_edje_calc_params_physics_cow, (const Eina_Cow_Data **)&state->physics, pf->physics);
#endif
     }

   ep->req = pf->req;

   if (ep->drag && ep->drag->need_reset)
     {
        FLOAT_T dx, dy;

        dx = ZERO;
        dy = ZERO;
        _edje_part_dragable_calc(ed, ep, &dx, &dy);
        ep->drag->x = dx;
        ep->drag->y = dy;
        ep->drag->tmp.x = 0;
        ep->drag->tmp.y = 0;
        ep->drag->need_reset = 0;
     }
   if (!ed->calc_only)
     {
        Evas_Object *mo;

        /* Common move, resize and color_set for all part. */
        switch (ep->part->type)
          {
           case EDJE_PART_TYPE_IMAGE:
           {
              Edje_Part_Description_Image *img_desc = (Edje_Part_Description_Image *)chosen_desc;

              evas_object_image_scale_hint_set(ep->object,
                                               img_desc->image.scale_hint);
              /* No break here as we share the rest of the code for all types. Intended fall-through*/
           }

           case EDJE_PART_TYPE_PROXY:
           case EDJE_PART_TYPE_RECTANGLE:
           case EDJE_PART_TYPE_TEXTBLOCK:
           case EDJE_PART_TYPE_BOX:
           case EDJE_PART_TYPE_TABLE:
           case EDJE_PART_TYPE_SNAPSHOT:
             evas_object_color_set(ep->object,
                                   (pf->color.r * pf->color.a) / 255,
                                   (pf->color.g * pf->color.a) / 255,
                                   (pf->color.b * pf->color.a) / 255,
                                   pf->color.a);

#ifdef HAVE_EPHYSICS
/* body attributes should be updated for invisible objects */
             if (!ep->part->physics_body)
               {
                  if (!pf->visible)
                    {
                       evas_object_hide(ep->object);
                       break;
                    }
                  evas_object_show(ep->object);
               }
             else if (!pf->visible)
               {
                  Evas_Object *face_obj;
                  Eina_List *l;

                  EINA_LIST_FOREACH(ep->body_faces, l, face_obj)
                    evas_object_hide(face_obj);
                  evas_object_hide(ep->object);
               }
#else
             if (!pf->visible)
               {
                  evas_object_hide(ep->object);
                  break;
               }
             evas_object_show(ep->object);

#endif
           /* move and resize are needed for all previous object => no break here. */
           case EDJE_PART_TYPE_SWALLOW:
           case EDJE_PART_TYPE_GROUP:
           case EDJE_PART_TYPE_EXTERNAL:
             /* visibility and color have no meaning on SWALLOW and GROUP part. */
#ifdef HAVE_EPHYSICS
             eo_do(ep->object,
                   efl_gfx_size_set(pf->final.w, pf->final.h));
             if ((ep->part->physics_body) && (!ep->body))
               {
                  if (_edje_physics_world_geometry_check(ed->world))
                    {
                       _edje_physics_body_add(ed, ep, ed->world);
                       _edje_physics_body_props_update(ed, ep, pf, EINA_TRUE);
                    }
               }
             else if (ep->body)
               {
                  if (((ep->prev_description) &&
                       (chosen_desc != ep->prev_description)) ||
                      (pf != p1))
                    _edje_physics_body_props_update(ed, ep, pf, !pf->physics->ignore_part_pos);
               }
             else
               eo_do(ep->object,
                     efl_gfx_position_set(ed->x + pf->final.x, ed->y + pf->final.y));
#else
             eo_do(ep->object,
                   efl_gfx_position_set(ed->x + pf->final.x, ed->y + pf->final.y),
                   efl_gfx_size_set(pf->final.w, pf->final.h));
#endif

             if (ep->nested_smart) /* Move, Resize all nested parts */
               {   /* Not really needed but will improve the bounding box evaluation done by Evas */
                  eo_do(ep->nested_smart,
                        efl_gfx_position_set(ed->x + pf->final.x, ed->y + pf->final.y),
                        efl_gfx_size_set(pf->final.w, pf->final.h));
               }
             if (ep->part->entry_mode > EDJE_ENTRY_EDIT_MODE_NONE)
               _edje_entry_real_part_configure(ed, ep);

             /* handle clip overrides */
             if (pf->clip_to && pf->clip_to->object)
               evas_object_clip_set(ep->object, pf->clip_to->object);
             else if (ep->part->clip_to_id >= 0)
               evas_object_clip_set(ep->object, ed->table_parts[ep->part->clip_to_id % ed->table_parts_size]->object);
             else
               evas_object_clip_set(ep->object, ed->base->clipper);
             break;

           case EDJE_PART_TYPE_TEXT:
             /* This is correctly handle in _edje_text_recalc_apply at the moment. */
             break;

           case EDJE_PART_TYPE_GRADIENT:
             /* FIXME: definitivly remove this code when we switch to new format. */
             abort();
             break;

           case EDJE_PART_TYPE_SPACER:
             /* We really should do nothing on SPACER part */
             break;
           case EDJE_PART_TYPE_CAMERA:
             {
                Evas_Canvas3D_Camera *camera = NULL;
                Edje_Part_Description_Camera *pd_camera;

                pd_camera = (Edje_Part_Description_Camera*) ep->chosen_description;
                eo_do(ep->node, camera = evas_canvas3d_node_camera_get());

                eo_do(camera,
                      evas_canvas3d_camera_projection_perspective_set(pd_camera->camera.camera.fovy, pd_camera->camera.camera.aspect,
                                                                pd_camera->camera.camera.frustum_near, pd_camera->camera.camera.frustum_far));

                eo_do(ep->node,
                      evas_canvas3d_node_position_set(pd_camera->camera.position.point.x, pd_camera->camera.position.point.y,
                                                  pd_camera->camera.position.point.z));
                switch (pd_camera->camera.orientation.type)
                  {
                     case EVAS_CANVAS3D_NODE_ORIENTATION_TYPE_NONE:
                     case EVAS_CANVAS3D_NODE_ORIENTATION_TYPE_QUATERNION:
                       {
                          SET_QUATERNION(camera)
                          break;
                       }
                     case EVAS_CANVAS3D_NODE_ORIENTATION_TYPE_LOOK_AT:
                       SET_LOOK_AT(camera)
                       break;
                     case EVAS_CANVAS3D_NODE_ORIENTATION_TYPE_LOOK_TO:
                       {
                          SET_LOOK_TO(camera)
                          break;
                       }
                     case EVAS_CANVAS3D_NODE_ORIENTATION_TYPE_ANGLE_AXIS:
                       SET_ANGLE_AXIS(camera)
                       break;
                  }
                break;
             }
           case EDJE_PART_TYPE_LIGHT:
             {
                Evas_Canvas3D_Light *light_node = NULL;
                Edje_Part_Description_Light *pd_light;

                pd_light = (Edje_Part_Description_Light*) ep->chosen_description;
                eo_do(ep->node, light_node = evas_canvas3d_node_light_get());

                eo_do(light_node,
                      evas_canvas3d_light_ambient_set(pd_light->light.properties.ambient.r / 255, pd_light->light.properties.ambient.g / 255,
                                                pd_light->light.properties.ambient.b / 255, pd_light->light.properties.ambient.a / 255),
                      evas_canvas3d_light_diffuse_set(pd_light->light.properties.diffuse.r / 255, pd_light->light.properties.diffuse.g / 255,
                                                pd_light->light.properties.diffuse.b / 255, pd_light->light.properties.diffuse.a / 255),
                      evas_canvas3d_light_specular_set(pd_light->light.properties.specular.r / 255, pd_light->light.properties.specular.g / 255,
                                                 pd_light->light.properties.specular.b / 255, pd_light->light.properties.specular.a / 255),
                      evas_canvas3d_light_directional_set(EINA_TRUE));

                eo_do(ep->node,
                      evas_canvas3d_node_position_set(pd_light->light.position.point.x, pd_light->light.position.point.y,
                                                  pd_light->light.position.point.z));
                switch (pd_light->light.orientation.type)
                  {
                     case EVAS_CANVAS3D_NODE_ORIENTATION_TYPE_NONE:
                     case EVAS_CANVAS3D_NODE_ORIENTATION_TYPE_QUATERNION:
                       {
                          SET_QUATERNION(light);
                          break;
                       }
                     case EVAS_CANVAS3D_NODE_ORIENTATION_TYPE_LOOK_AT:
                       SET_LOOK_AT(light)
                       break;
                     case EVAS_CANVAS3D_NODE_ORIENTATION_TYPE_LOOK_TO:
                       {
                          SET_LOOK_TO(light)
                          break;
                       }
                     case EVAS_CANVAS3D_NODE_ORIENTATION_TYPE_ANGLE_AXIS:
                       SET_ANGLE_AXIS(light)
                       break;
                  }
                break;
             }
           case EDJE_PART_TYPE_MESH_NODE:
             {
                Evas_Canvas3D_Material *material = NULL;
                Evas_Canvas3D_Texture *texture = NULL;
                Evas_Canvas3D_Mesh *mesh = NULL;
                const char *proxy;
                Edje_Part_Description_Mesh_Node *pd_mesh_node;
                const Eina_List *meshes;
                const Eina_List *list;

                eo_do(ep->node, meshes = evas_canvas3d_node_mesh_list_get());

                EINA_LIST_FOREACH(meshes, list, mesh)
                  {
                     eo_do(mesh,  material = evas_canvas3d_mesh_frame_material_get(0));
                     eo_do(material,  texture = evas_canvas3d_material_texture_get(EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE));

                     pd_mesh_node = (Edje_Part_Description_Mesh_Node*) ep->chosen_description;

                     eo_do(material,
                           evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE),
                           evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE),
                           evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE),
                           evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_NORMAL, pd_mesh_node->mesh_node.properties.normal),
                           evas_canvas3d_material_color_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT,
                                                      pd_mesh_node->mesh_node.properties.ambient.r / 255,
                                                      pd_mesh_node->mesh_node.properties.ambient.g / 255,
                                                      pd_mesh_node->mesh_node.properties.ambient.b / 255,
                                                      pd_mesh_node->mesh_node.properties.ambient.a / 255),
                           evas_canvas3d_material_color_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE,
                                                      pd_mesh_node->mesh_node.properties.diffuse.r / 255,
                                                      pd_mesh_node->mesh_node.properties.diffuse.g / 255,
                                                      pd_mesh_node->mesh_node.properties.diffuse.b / 255,
                                                      pd_mesh_node->mesh_node.properties.diffuse.a / 255),
                           evas_canvas3d_material_color_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR,
                                                      pd_mesh_node->mesh_node.properties.specular.r / 255,
                                                      pd_mesh_node->mesh_node.properties.specular.g / 255,
                                                      pd_mesh_node->mesh_node.properties.specular.b / 255,
                                                      pd_mesh_node->mesh_node.properties.specular.a / 255),
                           evas_canvas3d_material_shininess_set(pd_mesh_node->mesh_node.properties.shininess));

                     switch(pd_mesh_node->mesh_node.mesh.primitive)
                       {
                          case EVAS_CANVAS3D_MESH_PRIMITIVE_CUBE:
                            {
                               Eo *primitive = NULL;

                               eo_do(primitive,
                                     evas_canvas3d_primitive_form_set(EVAS_CANVAS3D_MESH_PRIMITIVE_CUBE));

                               eo_do(mesh,
                                     evas_canvas3d_mesh_from_primitive_set(0, primitive));
                               break;
                            }
                          case EVAS_CANVAS3D_MESH_PRIMITIVE_SPHERE:
                            {
                               Eo *primitive = NULL;

                               eo_do(primitive,
                                     evas_canvas3d_primitive_form_set(EVAS_CANVAS3D_MESH_PRIMITIVE_SPHERE),
                                     evas_canvas3d_primitive_precision_set(20));

                               eo_do(mesh,
                                     evas_canvas3d_mesh_from_primitive_set(0, primitive));
                               break;
                            }
                          default:
                            break;
                       }

                     if (pd_mesh_node->mesh_node.texture.need_texture && pd_mesh_node->mesh_node.texture.textured)
                       {
                          proxy = NULL;

                          eo_do(material,
                                texture = evas_canvas3d_material_texture_get(EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE));

                          //proxy = _edje_image_name_find(ed, pd_mesh_node->mesh_node.texture.id);
                          /*FIXME Conflict with function _edje_image_name_find (two places in edje_utils and edje_edit.c,
                          temporary desicion need to clarify up to commit to phab*/
                          proxy = ed->file->image_dir->entries[pd_mesh_node->mesh_node.texture.id].entry;
                          if (proxy)
                            {
                               eo_do(texture,
                                     evas_canvas3d_texture_file_set(eina_stringshare_add(proxy), NULL),
                                     evas_canvas3d_texture_filter_set(pd_mesh_node->mesh_node.texture.filter1,
                                                                pd_mesh_node->mesh_node.texture.filter2),
                                     evas_canvas3d_texture_wrap_set(pd_mesh_node->mesh_node.texture.wrap1,
                                                              pd_mesh_node->mesh_node.texture.wrap2));
                            }
                       }

                     eo_do(mesh,
                           evas_canvas3d_mesh_frame_material_set(0, material),
                           evas_canvas3d_mesh_shade_mode_set(pd_mesh_node->mesh_node.properties.shade),
                           evas_canvas3d_mesh_vertex_assembly_set(pd_mesh_node->mesh_node.mesh.assembly));
                     eo_do(ep->node,
                           evas_canvas3d_node_scale_set(ep->part->scale_3d.x, ep->part->scale_3d.y,
                                                  ep->part->scale_3d.z),
                           evas_canvas3d_node_position_set(pd_mesh_node->mesh_node.position.point.x,
                                                     pd_mesh_node->mesh_node.position.point.y,
                                                     pd_mesh_node->mesh_node.position.point.z));
                     switch (pd_mesh_node->mesh_node.orientation.type)
                       {
                          case EVAS_CANVAS3D_NODE_ORIENTATION_TYPE_NONE:
                          case EVAS_CANVAS3D_NODE_ORIENTATION_TYPE_QUATERNION:
                            {
                               SET_QUATERNION(mesh_node)
                               break;
                            }
                          case EVAS_CANVAS3D_NODE_ORIENTATION_TYPE_LOOK_AT:
                            SET_LOOK_AT(mesh_node)
                            break;
                          case EVAS_CANVAS3D_NODE_ORIENTATION_TYPE_LOOK_TO:
                            {
                               SET_LOOK_TO(mesh_node)
                               break;
                            }
                          case EVAS_CANVAS3D_NODE_ORIENTATION_TYPE_ANGLE_AXIS:
                            SET_ANGLE_AXIS(mesh_node)
                            break;
                       }
                  }
                break;
             }
          }

        /* Some object need special recalc. */
        switch (ep->part->type)
          {
           case EDJE_PART_TYPE_TEXT:
             _edje_text_recalc_apply(ed, ep, pf, (Edje_Part_Description_Text*) chosen_desc, EINA_FALSE);
             break;

           case EDJE_PART_TYPE_PROXY:
             _edje_proxy_recalc_apply(ed, ep, pf, (Edje_Part_Description_Proxy *)chosen_desc, pos);
             break;

           case EDJE_PART_TYPE_IMAGE:
             _edje_image_recalc_apply(ed, ep, pf, (Edje_Part_Description_Image *)chosen_desc, pos);
             break;

           case EDJE_PART_TYPE_BOX:
             _edje_box_recalc_apply(ed, ep, pf, (Edje_Part_Description_Box *)chosen_desc);
             break;

           case EDJE_PART_TYPE_TABLE:
             _edje_table_recalc_apply(ed, ep, pf, (Edje_Part_Description_Table *)chosen_desc);
             break;

           case EDJE_PART_TYPE_TEXTBLOCK:
             _edje_textblock_recalc_apply(ed, ep, pf, (Edje_Part_Description_Text *)chosen_desc);
             break;

           case EDJE_PART_TYPE_EXTERNAL:
           case EDJE_PART_TYPE_RECTANGLE:
           case EDJE_PART_TYPE_SWALLOW:
           case EDJE_PART_TYPE_GROUP:
             /* Nothing special to do for this type of object. */
             break;

           case EDJE_PART_TYPE_GRADIENT:
             /* FIXME: definitivly remove this code when we switch to new format. */
             abort();
             break;

           case EDJE_PART_TYPE_SPACER:
             /* We really should do nothing on SPACER part */
             break;
          }

        if (((ep->type == EDJE_RP_TYPE_SWALLOW) &&
             (ep->typedata.swallow)) &&
            (ep->typedata.swallow->swallowed_object))
          {
             if (pf->clip_to && pf->clip_to->object)
               evas_object_clip_set(ep->typedata.swallow->swallowed_object, pf->clip_to->object);
             else if (ep->part->clip_to_id >= 0)
               evas_object_clip_set(ep->typedata.swallow->swallowed_object, ed->table_parts[ep->part->clip_to_id % ed->table_parts_size]->object);
             else
               evas_object_clip_set(ep->typedata.swallow->swallowed_object, ed->base->clipper);

             if (pf->visible)
               {
                  Eina_Bool vis = EINA_TRUE;

                  if (ep->part->type == EDJE_PART_TYPE_GROUP)
                    vis = evas_object_visible_get(ed->obj);
                  eo_do(ep->typedata.swallow->swallowed_object,
                        efl_gfx_position_set(ed->x + pf->final.x, ed->y + pf->final.y),
                        efl_gfx_size_set(pf->final.w, pf->final.h),
                        efl_gfx_visible_set(vis));
               }
             else evas_object_hide(ep->typedata.swallow->swallowed_object);
             mo = ep->typedata.swallow->swallowed_object;
          }
        else mo = ep->object;
        if (chosen_desc->map.on && ep->part->type != EDJE_PART_TYPE_SPACER)
          {
             static Evas_Map *map = NULL;

             ed->have_mapped_part = EINA_TRUE;
             // create map and populate with part geometry
             if (!map) map = evas_map_new(4);

             _edje_map_prop_set(map, pf, chosen_desc, ep, mo);

             Evas_Object *map_obj;

             /* Apply map to smart obj holding nested parts */
             if (ep->nested_smart) map_obj = ep->nested_smart;
             else map_obj = mo;
             if (map_obj)
               {
                  eo_do(map_obj,
                        evas_obj_map_set(map),
                        evas_obj_map_enable_set(EINA_TRUE));
               }
          }
        else
          {
             if (ep->nested_smart) /* Cancel map of smart obj holding nested parts */
               {
                  eo_do(ep->nested_smart,
                        evas_obj_map_enable_set(EINA_FALSE),
                        evas_obj_map_set(NULL));
               }
             else
               {
#ifdef HAVE_EPHYSICS
                  if (!ep->body)
                    {
#endif
                  if (mo)
                    eo_do(mo,
                          evas_obj_map_enable_set(0),
                          evas_obj_map_set(NULL));
#ifdef HAVE_EPHYSICS
               }
#endif
               }
          }
     }

   if (map_colors_free) _map_colors_free(pf);

#ifdef HAVE_EPHYSICS
   ep->prev_description = chosen_desc;
   if (!ep->body)
     {
#endif
   ep->x = pf->final.x;
   ep->y = pf->final.y;
   ep->w = pf->final.w;
   ep->h = pf->final.h;
#ifdef HAVE_EPHYSICS
}

#endif

   ep->calculated |= flags;
   ep->calculating = FLAG_NONE;

   if (pf == &lp3)
     {
        eina_cow_free(_edje_calc_params_map_cow, (const Eina_Cow_Data **)&lp3.map);
        lp3.map = NULL;
#ifdef HAVE_EPHYSICS
        eina_cow_free(_edje_calc_params_physics_cow, (const Eina_Cow_Data **)&lp3.physics);
        lp3.physics = NULL;
#endif
     }

#ifdef EDJE_CALC_CACHE
   if (ep->calculated == FLAG_XY)
     {
        ep->state = ed->state;
        ep->invalidate = EINA_FALSE;
     }
#else
   eina_cow_free(_edje_calc_params_map_cow, (const Eina_Cow_Data **)&lp1.map);
#ifdef HAVE_EPHYSICS
   eina_cow_free(_edje_calc_params_physics_cow, (const Eina_Cow_Data **)&lp1.physics);
#endif
#endif
}