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
|
#include "evas_common.h" /* Includes evas_bidi_utils stuff. */
#include "evas_private.h"
/* save typing */
#define ENFN obj->layer->evas->engine.func
#define ENDT obj->layer->evas->engine.data.output
/* private magic number for text objects */
static const char o_type[] = "text";
/* private struct for text object internal data */
typedef struct _Evas_Object_Text Evas_Object_Text;
typedef struct _Evas_Object_Text_Item Evas_Object_Text_Item;
struct _Evas_Object_Text
{
DATA32 magic;
struct {
const char *utf8_text; /* The text exposed to the API */
const char *font;
Evas_Font_Description *fdesc;
const char *source;
Evas_Font_Size size;
struct {
unsigned char r, g, b, a;
} outline, shadow, glow, glow2;
unsigned char style;
} cur, prev;
float ascent, descent;
float max_ascent, max_descent;
Evas_BiDi_Paragraph_Props *bidi_par_props;
const char *bidi_delimiters;
Evas_Object_Text_Item *items;
Evas_Font_Set *font;
char changed : 1;
};
struct _Evas_Object_Text_Item
{
EINA_INLIST;
size_t text_pos;
size_t visual_pos;
Evas_Text_Props text_props;
Evas_Coord x, w, h, adv;
};
/* private methods for text objects */
static void evas_object_text_init(Evas_Object *obj);
static void *evas_object_text_new(void);
static void evas_object_text_render(Evas_Object *obj, void *output, void *context, void *surface, int x, int y);
static void evas_object_text_free(Evas_Object *obj);
static void evas_object_text_render_pre(Evas_Object *obj);
static void evas_object_text_render_post(Evas_Object *obj);
static unsigned int evas_object_text_id_get(Evas_Object *obj);
static unsigned int evas_object_text_visual_id_get(Evas_Object *obj);
static void *evas_object_text_engine_data_get(Evas_Object *obj);
static int evas_object_text_is_opaque(Evas_Object *obj);
static int evas_object_text_was_opaque(Evas_Object *obj);
static void evas_object_text_scale_update(Evas_Object *obj);
static void _evas_object_text_recalc(Evas_Object *obj);
static const Evas_Object_Func object_func =
{
/* methods (compulsory) */
evas_object_text_free,
evas_object_text_render,
evas_object_text_render_pre,
evas_object_text_render_post,
evas_object_text_id_get,
evas_object_text_visual_id_get,
evas_object_text_engine_data_get,
/* these are optional. NULL = nothing */
NULL,
NULL,
NULL,
NULL,
evas_object_text_is_opaque,
evas_object_text_was_opaque,
NULL,
NULL,
NULL,
evas_object_text_scale_update,
NULL,
NULL,
NULL
};
/* the actual api call to add a rect */
/* it has no other api calls as all properties are standard */
EVAS_MEMPOOL(_mp_obj);
static int
_evas_object_text_char_coords_get(const Evas_Object *obj,
const Evas_Object_Text *o,
size_t pos, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
{
Evas_Object_Text_Item *it;
EINA_INLIST_FOREACH(EINA_INLIST_GET(o->items), it)
{
if ((it->text_pos <= pos) &&
(pos < (it->text_pos + it->text_props.text_len)))
{
int ret;
ret = ENFN->font_char_coords_get(ENDT, o->font,
&it->text_props, pos - it->text_pos, x, y, w, h);
if (x) *x += it->x;
return ret;
}
}
return 0;
}
static void
_evas_object_text_item_clean(Evas_Object_Text_Item *it)
{
evas_common_text_props_content_unref(&it->text_props);
}
static void
_evas_object_text_items_clear(Evas_Object_Text *o)
{
Evas_Object_Text_Item *it;
while (o->items)
{
it = o->items;
o->items = (Evas_Object_Text_Item *) eina_inlist_remove(
EINA_INLIST_GET(o->items),
EINA_INLIST_GET(it));
_evas_object_text_item_clean(it);
free(it);
}
}
#ifdef BIDI_SUPPORT
static int
_evas_object_text_it_compare_logical(const void *_it1, const void *_it2)
{
const Evas_Object_Text_Item *it1 = _it1, *it2 = _it2;
if (it1->text_pos < it2->text_pos)
return -1;
else if (it1->text_pos == it2->text_pos)
return 0;
else
return 1;
}
#endif
static int
_evas_object_text_last_up_to_pos(const Evas_Object *obj,
const Evas_Object_Text *o, Evas_Coord cx, Evas_Coord cy)
{
Evas_Object_Text_Item *it;
#ifdef BIDI_SUPPORT
/*FIXME: not very efficient, sort the items arrays. */
/* Reorder if it's a bidi text */
if (o->bidi_par_props)
{
Eina_List *logical_it = NULL;
Evas_Object_Text_Item *i;
Eina_List *itr;
Evas_Coord x = 0;
/* Insert all to the logical list */
EINA_INLIST_FOREACH(o->items, i)
{
logical_it = eina_list_sorted_insert(logical_it,
_evas_object_text_it_compare_logical, i);
}
EINA_LIST_FOREACH(logical_it, itr, it)
{
if ((x <= cx) && (cx < x + it->adv))
{
return it->text_pos + ENFN->font_last_up_to_pos(ENDT,
o->font,
&it->text_props,
cx - x,
cy);
}
x += it->adv;
}
eina_list_free(logical_it);
}
else
#endif
{
EINA_INLIST_FOREACH(EINA_INLIST_GET(o->items), it)
{
if ((it->x <= cx) && (cx < it->x + it->adv))
{
return it->text_pos + ENFN->font_last_up_to_pos(ENDT,
o->font,
&it->text_props,
cx - it->x,
cy);
}
}
}
return -1;
}
static int
_evas_object_text_char_at_coords(const Evas_Object *obj,
const Evas_Object_Text *o, Evas_Coord cx, Evas_Coord cy,
Evas_Coord *rx, Evas_Coord *ry, Evas_Coord *rw, Evas_Coord *rh)
{
Evas_Object_Text_Item *it;
EINA_INLIST_FOREACH(EINA_INLIST_GET(o->items), it)
{
if ((it->x <= cx) && (cx < it->x + it->adv))
{
return it->text_pos + ENFN->font_char_at_coords_get(ENDT,
o->font,
&it->text_props,
cx - it->x,
cy,
rx, ry,
rw, rh);
}
}
return -1;
}
static Evas_Coord
_evas_object_text_horiz_advance_get(const Evas_Object *obj,
const Evas_Object_Text *o)
{
Evas_Object_Text_Item *it;
Evas_Coord adv;
(void) obj;
adv = 0;
EINA_INLIST_FOREACH(EINA_INLIST_GET(o->items), it)
{
adv += it->adv;
}
return adv;
}
static Evas_Coord
_evas_object_text_vert_advance_get(const Evas_Object *obj __UNUSED__,
const Evas_Object_Text *o)
{
return o->max_ascent + o->max_descent;
}
EAPI Evas_Object *
evas_object_text_add(Evas *e)
{
Evas_Object *obj;
MAGIC_CHECK(e, Evas, MAGIC_EVAS);
return NULL;
MAGIC_CHECK_END();
obj = evas_object_new(e);
evas_object_text_init(obj);
evas_object_inject(obj, e);
return obj;
}
EAPI void
evas_object_text_font_source_set(Evas_Object *obj, const char *font_source)
{
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return;
MAGIC_CHECK_END();
if ((o->cur.source) && (font_source) &&
(!strcmp(o->cur.source, font_source)))
return;
/*
if (o->cur.source) eina_stringshare_del(o->cur.source);
if (font_source) o->cur.source = eina_stringshare_add(font_source);
else o->cur.source = NULL;
*/
eina_stringshare_replace(&o->cur.source, font_source);
}
EAPI const char *
evas_object_text_font_source_get(const Evas_Object *obj)
{
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return NULL;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return NULL;
MAGIC_CHECK_END();
return o->cur.source;
}
EAPI void
evas_object_text_font_set(Evas_Object *obj, const char *font, Evas_Font_Size size)
{
Evas_Object_Text *o;
int is, was = 0, pass = 0, freeze = 0;
Evas_Font_Description *fdesc;
if ((!font) || (size <= 0)) return;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return;
MAGIC_CHECK_END();
fdesc = evas_font_desc_new();
evas_font_name_parse(fdesc, font);
if (o->cur.fdesc && !evas_font_desc_cmp(fdesc, o->cur.fdesc) &&
(size == o->cur.size))
{
evas_font_desc_unref(fdesc);
return;
}
if (o->cur.fdesc) evas_font_desc_unref(o->cur.fdesc);
o->cur.fdesc = fdesc;
o->cur.size = size;
eina_stringshare_replace(&o->cur.font, font);
o->prev.font = NULL;
if (obj->layer->evas->events_frozen <= 0)
{
pass = evas_event_passes_through(obj);
freeze = evas_event_freezes_through(obj);
if ((!pass) && (!freeze))
was = evas_object_is_in_output_rect(obj,
obj->layer->evas->pointer.x,
obj->layer->evas->pointer.y, 1, 1);
}
#ifdef EVAS_FRAME_QUEUING
if (o->font)
evas_common_pipe_op_text_flush((RGBA_Font *) o->font);
#endif
/* DO IT */
if (o->font)
{
evas_font_free(obj->layer->evas, o->font);
o->font = NULL;
}
o->font = evas_font_load(obj->layer->evas, o->cur.fdesc, o->cur.source,
(int)(((double) o->cur.size) * obj->cur.scale));
if (o->font)
{
o->ascent = ENFN->font_ascent_get(ENDT, o->font);
o->descent = ENFN->font_descent_get(ENDT, o->font);
o->max_ascent = ENFN->font_max_ascent_get(ENDT, o->font);
o->max_descent = ENFN->font_max_descent_get(ENDT, o->font);
}
else
{
o->ascent = 0;
o->descent = 0;
o->max_ascent = 0;
o->max_descent = 0;
}
_evas_object_text_recalc(obj);
o->changed = 1;
evas_object_change(obj);
evas_object_clip_dirty(obj);
evas_object_coords_recalc(obj);
if (obj->layer->evas->events_frozen <= 0)
{
if ((!pass) && (!freeze))
{
is = evas_object_is_in_output_rect(obj,
obj->layer->evas->pointer.x,
obj->layer->evas->pointer.y,
1, 1);
if ((is ^ was) && obj->cur.visible)
evas_event_feed_mouse_move(obj->layer->evas,
obj->layer->evas->pointer.x,
obj->layer->evas->pointer.y,
obj->layer->evas->last_timestamp,
NULL);
}
}
evas_object_inform_call_resize(obj);
}
EAPI void
evas_object_text_font_get(const Evas_Object *obj, const char **font, Evas_Font_Size *size)
{
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
if (font) *font = "";
if (size) *size = 0;
return;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
if (font) *font = "";
if (size) *size = 0;
return;
MAGIC_CHECK_END();
if (font) *font = o->cur.font;
if (size) *size = o->cur.size;
}
/**
* @internal
* Create a new text layout item from the string and the format.
*
* @param c the context to work on - Not NULL.
* @param fmt the format to use.
* @param str the string to use.
*/
static Evas_Object_Text_Item *
_evas_object_text_item_new(Evas_Object *obj, Evas_Object_Text *o,
Evas_Font_Instance *fi, const Eina_Unicode *str, Evas_Script_Type script,
size_t pos, size_t visual_pos, size_t len)
{
Evas_Object_Text_Item *it;
it = calloc(1, sizeof(Evas_Object_Text_Item));
it->text_pos = pos;
it->visual_pos = visual_pos;
evas_common_text_props_bidi_set(&it->text_props, o->bidi_par_props,
it->text_pos);
evas_common_text_props_script_set(&it->text_props, script);
if (fi)
{
ENFN->font_text_props_info_create(ENDT,
fi, str + pos, &it->text_props,
o->bidi_par_props, it->text_pos, len);
ENFN->font_string_size_get(ENDT,
o->font,
&it->text_props,
&it->w, &it->h);
it->adv = ENFN->font_h_advance_get(ENDT, o->font,
&it->text_props);
}
o->items = (Evas_Object_Text_Item *)
eina_inlist_append(EINA_INLIST_GET(o->items), EINA_INLIST_GET(it));
return it;
}
/**
* @internal
* Orders o->items according to the visual position.
*
* @param obj the evas object
* @param o the text object
*/
static void
_evas_object_text_item_order(Evas_Object *obj, Evas_Object_Text *o)
{
(void) obj;
#ifdef BIDI_SUPPORT
/*FIXME: not very efficient, sort the items arrays. */
/* Reorder if it's a bidi text */
if (o->bidi_par_props)
{
Evas_Object_Text_Item *i, *j, *min;
i = o->items;
while (i)
{
min = i;
EINA_INLIST_FOREACH(i, j)
{
if (j->visual_pos < min->visual_pos)
{
min = j;
}
}
if (min != i)
{
o->items = (Evas_Object_Text_Item *) eina_inlist_remove(EINA_INLIST_GET(o->items), EINA_INLIST_GET(min));
o->items = (Evas_Object_Text_Item *) eina_inlist_prepend_relative(EINA_INLIST_GET(o->items), EINA_INLIST_GET(min), EINA_INLIST_GET(i));
}
i = (Evas_Object_Text_Item *) EINA_INLIST_GET(min)->next;
}
}
#endif
/* calculate the positions according to the order. */
{
Evas_Object_Text_Item *it = o->items;
Evas_Coord x = 0;
while (it)
{
it->x = x;
x += it->adv;
it = (Evas_Object_Text_Item *) EINA_INLIST_GET(it)->next;
}
}
}
/**
* @internal
* Populates o->items with the items of the text according to text
*
* @param obj the evas object
* @param o the text object
* @param text the text to layout
*/
static void
_evas_object_text_layout(Evas_Object *obj, Evas_Object_Text *o, const Eina_Unicode *text)
{
EvasBiDiStrIndex *v_to_l = NULL;
size_t pos, visual_pos;
int len = eina_unicode_strlen(text);
#ifdef BIDI_SUPPORT
int par_len = len;
int *segment_idxs = NULL;
if (o->bidi_delimiters)
segment_idxs = evas_bidi_segment_idxs_get(text, o->bidi_delimiters);
evas_bidi_paragraph_props_unref(o->bidi_par_props);
o->bidi_par_props = evas_bidi_paragraph_props_get(text, len, segment_idxs);
evas_bidi_props_reorder_line(NULL, 0, len, o->bidi_par_props, &v_to_l);
if (segment_idxs) free(segment_idxs);
#endif
visual_pos = pos = 0;
while (len > 0)
{
Evas_Font_Instance *script_fi = NULL;
int script_len = len, tmp_cut;
Evas_Script_Type script;
tmp_cut = evas_common_language_script_end_of_run_get(
text + pos,
o->bidi_par_props,
pos, len);
if (tmp_cut > 0)
script_len = tmp_cut;
script = evas_common_language_script_type_get(text, script_len);
while (script_len > 0)
{
Evas_Font_Instance *cur_fi = NULL;
int run_len = script_len;
if (o->font)
{
run_len = ENFN->font_run_end_get(ENDT,
o->font, &script_fi, &cur_fi,
script, text + pos, script_len);
}
#ifdef BIDI_SUPPORT
visual_pos = evas_bidi_position_logical_to_visual(
v_to_l, par_len, pos);
#else
visual_pos = pos;
#endif
_evas_object_text_item_new(obj, o, cur_fi, text, script,
pos, visual_pos, run_len);
pos += run_len;
script_len -= run_len;
len -= run_len;
}
}
_evas_object_text_item_order(obj, o);
if (v_to_l) free(v_to_l);
}
EAPI void
evas_object_text_text_set(Evas_Object *obj, const char *_text)
{
Evas_Object_Text *o;
int is, was, len;
Eina_Unicode *text;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return;
MAGIC_CHECK_END();
if ((o->cur.utf8_text) && (_text) && (!strcmp(o->cur.utf8_text, _text)))
return;
text = eina_unicode_utf8_to_unicode(_text, &len);
if (!text) text = eina_unicode_strdup(EINA_UNICODE_EMPTY_STRING);
was = evas_object_is_in_output_rect(obj,
obj->layer->evas->pointer.x,
obj->layer->evas->pointer.y, 1, 1);
/* DO II */
/*Update bidi_props*/
if (o->items) _evas_object_text_items_clear(o);
if ((text) && (*text))
{
_evas_object_text_layout(obj, o, text);
eina_stringshare_replace(&o->cur.utf8_text, _text);
o->prev.utf8_text = NULL;
}
else
{
eina_stringshare_replace(&o->cur.utf8_text, NULL);
}
if (text)
{
free(text);
text = NULL;
}
_evas_object_text_recalc(obj);
o->changed = 1;
evas_object_change(obj);
evas_object_clip_dirty(obj);
evas_object_coords_recalc(obj);
is = evas_object_is_in_output_rect(obj,
obj->layer->evas->pointer.x,
obj->layer->evas->pointer.y, 1, 1);
if ((is || was) && obj->cur.visible)
evas_event_feed_mouse_move(obj->layer->evas,
obj->layer->evas->pointer.x,
obj->layer->evas->pointer.y,
obj->layer->evas->last_timestamp,
NULL);
evas_object_inform_call_resize(obj);
if (text) free(text);
}
EAPI void
evas_object_text_bidi_delimiters_set(Evas_Object *obj, const char *delim)
{
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return;
MAGIC_CHECK_END();
eina_stringshare_replace(&o->bidi_delimiters, delim);
}
EAPI const char *
evas_object_text_bidi_delimiters_get(const Evas_Object *obj)
{
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return NULL;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return NULL;
MAGIC_CHECK_END();
return o->bidi_delimiters;
}
EAPI const char *
evas_object_text_text_get(const Evas_Object *obj)
{
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return NULL;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return NULL;
MAGIC_CHECK_END();
return o->cur.utf8_text;
}
EAPI Evas_BiDi_Direction
evas_object_text_direction_get(const Evas_Object *obj)
{
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return EVAS_BIDI_DIRECTION_NEUTRAL;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return EVAS_BIDI_DIRECTION_NEUTRAL;
MAGIC_CHECK_END();
if (o->items)
{
return o->items->text_props.bidi.dir;
}
return EVAS_BIDI_DIRECTION_NEUTRAL;
}
EAPI Evas_Coord
evas_object_text_ascent_get(const Evas_Object *obj)
{
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return 0;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return 0;
MAGIC_CHECK_END();
return o->ascent;
}
EAPI Evas_Coord
evas_object_text_descent_get(const Evas_Object *obj)
{
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return 0;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return 0;
MAGIC_CHECK_END();
return o->descent;
}
EAPI Evas_Coord
evas_object_text_max_ascent_get(const Evas_Object *obj)
{
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return 0;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return 0;
MAGIC_CHECK_END();
return o->max_ascent;
}
EAPI Evas_Coord
evas_object_text_max_descent_get(const Evas_Object *obj)
{
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return 0;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return 0;
MAGIC_CHECK_END();
return o->max_descent;
}
EAPI Evas_Coord
evas_object_text_inset_get(const Evas_Object *obj)
{
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return 0;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return 0;
MAGIC_CHECK_END();
if (!o->font) return 0;
if (!o->items) return 0;
return ENFN->font_inset_get(ENDT, o->font, &o->items->text_props);
}
EAPI Evas_Coord
evas_object_text_horiz_advance_get(const Evas_Object *obj)
{
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return 0;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return 0;
MAGIC_CHECK_END();
if (!o->font) return 0;
if (!o->items) return 0;
return _evas_object_text_horiz_advance_get(obj, o);
}
EAPI Evas_Coord
evas_object_text_vert_advance_get(const Evas_Object *obj)
{
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return 0;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return 0;
MAGIC_CHECK_END();
if (!o->font) return 0;
if (!o->items) return o->ascent + o->descent;
return _evas_object_text_vert_advance_get(obj, o);
}
EAPI Eina_Bool
evas_object_text_char_pos_get(const Evas_Object *obj, int pos, Evas_Coord *cx, Evas_Coord *cy, Evas_Coord *cw, Evas_Coord *ch)
{
Evas_Object_Text *o;
int l = 0, r = 0, t = 0, b = 0;
int ret, x = 0, y = 0, w = 0, h = 0;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return EINA_FALSE;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return EINA_FALSE;
MAGIC_CHECK_END();
if (!o->font) return EINA_FALSE;
if (!o->items || (pos < 0)) return EINA_FALSE;
ret = _evas_object_text_char_coords_get(obj, o, (size_t) pos,
&x, &y, &w, &h);
evas_text_style_pad_get(o->cur.style, &l, &r, &t, &b);
y += o->max_ascent - t;
x -= l;
if (x < 0)
{
w += x;
x = 0;
}
if ((x + w) > obj->cur.geometry.w) w = obj->cur.geometry.w - x;
if (w < 0) w = 0;
if (y < 0)
{
h += y;
y = 0;
}
if ((y + h) > obj->cur.geometry.h) h = obj->cur.geometry.h - y;
if (h < 0) h = 0;
if (cx) *cx = x;
if (cy) *cy = y;
if (cw) *cw = w + l + r;
if (ch) *ch = h + t + b;
return ret;
}
EAPI int
evas_object_text_last_up_to_pos(const Evas_Object *obj, Evas_Coord x, Evas_Coord y)
{
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return -1;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return -1;
MAGIC_CHECK_END();
if (!o->font) return -1;
if (!o->items) return -1;
return _evas_object_text_last_up_to_pos(obj, o, x, y - o->max_ascent);
}
EAPI int
evas_object_text_char_coords_get(const Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord *cx, Evas_Coord *cy, Evas_Coord *cw, Evas_Coord *ch)
{
Evas_Object_Text *o;
int l = 0, r = 0, t = 0, b = 0;
int ret, rx = 0, ry = 0, rw = 0, rh = 0;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return -1;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return -1;
MAGIC_CHECK_END();
if (!o->font) return -1;
if (!o->items) return -1;
ret = _evas_object_text_char_at_coords(obj, o, x, y - o->max_ascent,
&rx, &ry, &rw, &rh);
evas_text_style_pad_get(o->cur.style, &l, &r, &t, &b);
ry += o->max_ascent - t;
rx -= l;
if (rx < 0)
{
rw += rx;
rx = 0;
}
if ((rx + rw) > obj->cur.geometry.w) rw = obj->cur.geometry.w - rx;
if (rw < 0) rw = 0;
if (ry < 0)
{
rh += ry;
ry = 0;
}
if ((ry + rh) > obj->cur.geometry.h) rh = obj->cur.geometry.h - ry;
if (rh < 0) rh = 0;
if (cx) *cx = rx;
if (cy) *cy = ry;
if (cw) *cw = rw + l + r;
if (ch) *ch = rh + t + b;
return ret;
}
EAPI void
evas_object_text_style_set(Evas_Object *obj, Evas_Text_Style_Type style)
{
Evas_Object_Text *o;
int pl = 0, pr = 0, pt = 0, pb = 0, l = 0, r = 0, t = 0, b = 0;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return;
MAGIC_CHECK_END();
if (o->cur.style == style) return;
evas_text_style_pad_get(o->cur.style, &pl, &pr, &pt, &pb);
o->cur.style = style;
evas_text_style_pad_get(o->cur.style, &l, &r, &t, &b);
if (o->items)
obj->cur.geometry.w += (l - pl) + (r - pr);
else
obj->cur.geometry.w = 0;
obj->cur.geometry.h += (t - pt) + (b - pb);
evas_object_change(obj);
evas_object_clip_dirty(obj);
}
EAPI Evas_Text_Style_Type
evas_object_text_style_get(const Evas_Object *obj)
{
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return EVAS_TEXT_STYLE_PLAIN;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return EVAS_TEXT_STYLE_PLAIN;
MAGIC_CHECK_END();
return o->cur.style;
}
EAPI void
evas_object_text_shadow_color_set(Evas_Object *obj, int r, int g, int b, int a)
{
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return;
MAGIC_CHECK_END();
if ((o->cur.shadow.r == r) && (o->cur.shadow.g == g) &&
(o->cur.shadow.b == b) && (o->cur.shadow.a == a))
return;
o->cur.shadow.r = r;
o->cur.shadow.g = g;
o->cur.shadow.b = b;
o->cur.shadow.a = a;
o->changed = 1;
evas_object_change(obj);
}
EAPI void
evas_object_text_shadow_color_get(const Evas_Object *obj, int *r, int *g, int *b, int *a)
{
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
if (r) *r = 0;
if (g) *g = 0;
if (b) *b = 0;
if (a) *a = 0;
return;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
if (r) *r = 0;
if (g) *g = 0;
if (b) *b = 0;
if (a) *a = 0;
return;
MAGIC_CHECK_END();
if (r) *r = o->cur.shadow.r;
if (g) *g = o->cur.shadow.g;
if (b) *b = o->cur.shadow.b;
if (a) *a = o->cur.shadow.a;
}
EAPI void
evas_object_text_glow_color_set(Evas_Object *obj, int r, int g, int b, int a)
{
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return;
MAGIC_CHECK_END();
if ((o->cur.glow.r == r) && (o->cur.glow.g == g) &&
(o->cur.glow.b == b) && (o->cur.glow.a == a))
return;
o->cur.glow.r = r;
o->cur.glow.g = g;
o->cur.glow.b = b;
o->cur.glow.a = a;
o->changed = 1;
evas_object_change(obj);
}
EAPI void
evas_object_text_glow_color_get(const Evas_Object *obj, int *r, int *g, int *b, int *a)
{
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
if (r) *r = 0;
if (g) *g = 0;
if (b) *b = 0;
if (a) *a = 0;
return;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
if (r) *r = 0;
if (g) *g = 0;
if (b) *b = 0;
if (a) *a = 0;
return;
MAGIC_CHECK_END();
if (r) *r = o->cur.glow.r;
if (g) *g = o->cur.glow.g;
if (b) *b = o->cur.glow.b;
if (a) *a = o->cur.glow.a;
}
EAPI void
evas_object_text_glow2_color_set(Evas_Object *obj, int r, int g, int b, int a)
{
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return;
MAGIC_CHECK_END();
if ((o->cur.glow2.r == r) && (o->cur.glow2.g == g) &&
(o->cur.glow2.b == b) && (o->cur.glow2.a == a))
return;
o->cur.glow2.r = r;
o->cur.glow2.g = g;
o->cur.glow2.b = b;
o->cur.glow2.a = a;
o->changed = 1;
evas_object_change(obj);
}
EAPI void
evas_object_text_glow2_color_get(const Evas_Object *obj, int *r, int *g, int *b, int *a)
{
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
if (r) *r = 0;
if (g) *g = 0;
if (b) *b = 0;
if (a) *a = 0;
return;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
if (r) *r = 0;
if (g) *g = 0;
if (b) *b = 0;
if (a) *a = 0;
return;
MAGIC_CHECK_END();
if (r) *r = o->cur.glow2.r;
if (g) *g = o->cur.glow2.g;
if (b) *b = o->cur.glow2.b;
if (a) *a = o->cur.glow2.a;
}
EAPI void
evas_object_text_outline_color_set(Evas_Object *obj, int r, int g, int b, int a)
{
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
return;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return;
MAGIC_CHECK_END();
if ((o->cur.outline.r == r) && (o->cur.outline.g == g) &&
(o->cur.outline.b == b) && (o->cur.outline.a == a))
return;
o->cur.outline.r = r;
o->cur.outline.g = g;
o->cur.outline.b = b;
o->cur.outline.a = a;
o->changed = 1;
evas_object_change(obj);
}
EAPI void
evas_object_text_outline_color_get(const Evas_Object *obj, int *r, int *g, int *b, int *a)
{
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
if (r) *r = 0;
if (g) *g = 0;
if (b) *b = 0;
if (a) *a = 0;
return;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
if (r) *r = 0;
if (g) *g = 0;
if (b) *b = 0;
if (a) *a = 0;
return;
MAGIC_CHECK_END();
if (r) *r = o->cur.outline.r;
if (g) *g = o->cur.outline.g;
if (b) *b = o->cur.outline.b;
if (a) *a = o->cur.outline.a;
}
EAPI void
evas_object_text_style_pad_get(const Evas_Object *obj, int *l, int *r, int *t, int *b)
{
int sl = 0, sr = 0, st = 0, sb = 0;
Evas_Object_Text *o;
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
if (l) *l = 0;
if (r) *r = 0;
if (t) *t = 0;
if (b) *b = 0;
return;
MAGIC_CHECK_END();
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
if (l) *l = 0;
if (r) *r = 0;
if (t) *t = 0;
if (b) *b = 0;
return;
MAGIC_CHECK_END();
/* use temps to be certain we have initialized values */
evas_text_style_pad_get(o->cur.style, &sl, &sr, &st, &sb);
if (l) *l = sl;
if (r) *r = sr;
if (t) *t = st;
if (b) *b = sb;
}
EAPI int
evas_string_char_next_get(const char *str, int pos, int *decoded)
{
int p, d;
if (decoded) *decoded = 0;
if ((!str) || (pos < 0)) return 0;
p = pos;
d = eina_unicode_utf8_get_next(str, &p);
if (decoded) *decoded = d;
return p;
}
EAPI int
evas_string_char_prev_get(const char *str, int pos, int *decoded)
{
int p, d;
if (decoded) *decoded = 0;
if ((!str) || (pos < 1)) return 0;
p = pos;
d = eina_unicode_utf8_get_prev(str, &p);
if (decoded) *decoded = d;
return p;
}
EAPI int
evas_string_char_len_get(const char *str)
{
if (!str) return 0;
return eina_unicode_utf8_get_len(str);
}
void
evas_text_style_pad_get(Evas_Text_Style_Type style, int *l, int *r, int *t, int *b)
{
int sl = 0, sr = 0, st = 0, sb = 0;
/* Don't calc anything if there's no style. */
if (style != EVAS_TEXT_STYLE_PLAIN)
{
int shad_sz = 0, shad_dst = 0, out_sz = 0;
int dx = 0, minx = 0, maxx = 0;
int dy = 0, miny = 0, maxy = 0;
Eina_Bool have_shadow = EINA_FALSE;
switch (style & EVAS_TEXT_STYLE_MASK_BASIC)
{
case EVAS_TEXT_STYLE_SHADOW:
shad_dst = 1;
have_shadow = EINA_TRUE;
break;
case EVAS_TEXT_STYLE_OUTLINE_SHADOW:
case EVAS_TEXT_STYLE_FAR_SHADOW:
shad_dst = 2;
out_sz = 1;
have_shadow = EINA_TRUE;
break;
case EVAS_TEXT_STYLE_OUTLINE_SOFT_SHADOW:
shad_dst = 1;
shad_sz = 2;
out_sz = 1;
have_shadow = EINA_TRUE;
break;
case EVAS_TEXT_STYLE_FAR_SOFT_SHADOW:
shad_dst = 2;
shad_sz = 2;
have_shadow = EINA_TRUE;
break;
case EVAS_TEXT_STYLE_SOFT_SHADOW:
shad_dst = 1;
shad_sz = 2;
have_shadow = EINA_TRUE;
break;
case EVAS_TEXT_STYLE_GLOW:
case EVAS_TEXT_STYLE_SOFT_OUTLINE:
out_sz = 2;
break;
case EVAS_TEXT_STYLE_OUTLINE:
out_sz = 1;
break;
default:
break;
}
minx = -out_sz;
maxx = out_sz;
miny = -out_sz;
maxy = out_sz;
if (have_shadow)
{
int shx1, shx2, shy1, shy2;
switch (style & EVAS_TEXT_STYLE_MASK_SHADOW_DIRECTION)
{
case EVAS_TEXT_STYLE_SHADOW_DIRECTION_BOTTOM_RIGHT:
dx = 1;
dy = 1;
break;
case EVAS_TEXT_STYLE_SHADOW_DIRECTION_BOTTOM:
dx = 0;
dy = 1;
break;
case EVAS_TEXT_STYLE_SHADOW_DIRECTION_BOTTOM_LEFT:
dx = -1;
dy = 1;
break;
case EVAS_TEXT_STYLE_SHADOW_DIRECTION_LEFT:
dx = -1;
dy = 0;
break;
case EVAS_TEXT_STYLE_SHADOW_DIRECTION_TOP_LEFT:
dx = -1;
dy = -1;
break;
case EVAS_TEXT_STYLE_SHADOW_DIRECTION_TOP:
dx = 0;
dy = -1;
break;
case EVAS_TEXT_STYLE_SHADOW_DIRECTION_TOP_RIGHT:
dx = 1;
dy = -1;
break;
case EVAS_TEXT_STYLE_SHADOW_DIRECTION_RIGHT:
dx = 1;
dy = 0;
default:
break;
}
shx1 = dx * shad_dst;
shx1 -= shad_sz;
shx2 = dx * shad_dst;
shx2 += shad_sz;
if (shx1 < minx) minx = shx1;
if (shx2 > maxx) maxx = shx2;
shy1 = dy * shad_dst;
shy1 -= shad_sz;
shy2 = dy * shad_dst;
shy2 += shad_sz;
if (shy1 < miny) miny = shy1;
if (shy2 > maxy) maxy = shy2;
}
if (l) sl = *l;
if (r) sr = *r;
if (t) st = *t;
if (b) sb = *b;
if (sr < maxx) sr = maxx;
if (sl < -minx) sl = -minx;
if (sb < maxy) sb = maxy;
if (st < -miny) st = -miny;
}
if (l) *l = sl;
if (r) *r = sr;
if (t) *t = st;
if (b) *b = sb;
}
/* all nice and private */
static void
evas_object_text_init(Evas_Object *obj)
{
/* alloc text ob, setup methods and default values */
obj->object_data = evas_object_text_new();
/* set up default settings for this kind of object */
obj->cur.color.r = 255;
obj->cur.color.g = 255;
obj->cur.color.b = 255;
obj->cur.color.a = 255;
obj->cur.geometry.x = 0;
obj->cur.geometry.y = 0;
obj->cur.geometry.w = 0;
obj->cur.geometry.h = 0;
obj->cur.layer = 0;
/* set up object-specific settings */
obj->prev = obj->cur;
/* set up methods (compulsory) */
obj->func = &object_func;
obj->type = o_type;
}
static void *
evas_object_text_new(void)
{
Evas_Object_Text *o;
/* alloc obj private data */
EVAS_MEMPOOL_INIT(_mp_obj, "evas_object_text", Evas_Object_Text, 128, NULL);
o = EVAS_MEMPOOL_ALLOC(_mp_obj, Evas_Object_Text);
if (!o) return NULL;
EVAS_MEMPOOL_PREP(_mp_obj, o, Evas_Object_Text);
o->magic = MAGIC_OBJ_TEXT;
o->prev = o->cur;
#ifdef BIDI_SUPPORT
o->bidi_par_props = evas_bidi_paragraph_props_new();
#endif
return o;
}
static void
evas_object_text_free(Evas_Object *obj)
{
Evas_Object_Text *o;
/* frees private object data. very simple here */
o = (Evas_Object_Text *)(obj->object_data);
MAGIC_CHECK(o, Evas_Object_Text, MAGIC_OBJ_TEXT);
return;
MAGIC_CHECK_END();
/* free obj */
if (o->items) _evas_object_text_items_clear(o);
if (o->cur.utf8_text) eina_stringshare_del(o->cur.utf8_text);
if (o->cur.font) eina_stringshare_del(o->cur.font);
if (o->cur.fdesc) evas_font_desc_unref(o->cur.fdesc);
if (o->cur.source) eina_stringshare_del(o->cur.source);
if (o->font) evas_font_free(obj->layer->evas, o->font);
#ifdef BIDI_SUPPORT
evas_bidi_paragraph_props_unref(o->bidi_par_props);
#endif
o->magic = 0;
EVAS_MEMPOOL_FREE(_mp_obj, o);
}
static void
evas_object_text_render(Evas_Object *obj, void *output, void *context, void *surface, int x, int y)
{
int i, j;
Evas_Object_Text *o;
Evas_Object_Text_Item *it;
const char vals[5][5] =
{
{0, 1, 2, 1, 0},
{1, 3, 4, 3, 1},
{2, 4, 5, 4, 2},
{1, 3, 4, 3, 1},
{0, 1, 2, 1, 0}
};
int sl = 0, st = 0;
int shad_dst, shad_sz, dx, dy, haveshad;
/* render object to surface with context, and offxet by x,y */
o = (Evas_Object_Text *)(obj->object_data);
evas_text_style_pad_get(o->cur.style, &sl, NULL, &st, NULL);
ENFN->context_multiplier_unset(output, context);
ENFN->context_render_op_set(output, context, obj->cur.render_op);
/* FIXME: This clipping is just until we fix inset handling correctly. */
ENFN->context_clip_clip(output, context,
obj->cur.geometry.x + x,
obj->cur.geometry.y + y,
obj->cur.geometry.w,
obj->cur.geometry.h);
/*
ENFN->context_color_set(output,
context,
230, 160, 30, 100);
ENFN->rectangle_draw(output,
context,
surface,
obj->cur.geometry.x + x,
obj->cur.geometry.y + y,
obj->cur.geometry.w,
obj->cur.geometry.h);
*/
#define COLOR_ONLY_SET(object, sub, col) \
ENFN->context_color_set(output, context, \
object->sub.col.r, \
object->sub.col.g, \
object->sub.col.b, \
object->sub.col.a);
#define COLOR_SET(object, sub, col) \
if (obj->cur.clipper)\
ENFN->context_color_set(output, context, \
((int)object->sub.col.r * ((int)obj->cur.clipper->cur.cache.clip.r + 1)) >> 8, \
((int)object->sub.col.g * ((int)obj->cur.clipper->cur.cache.clip.g + 1)) >> 8, \
((int)object->sub.col.b * ((int)obj->cur.clipper->cur.cache.clip.b + 1)) >> 8, \
((int)object->sub.col.a * ((int)obj->cur.clipper->cur.cache.clip.a + 1)) >> 8); \
else\
ENFN->context_color_set(output, context, \
object->sub.col.r, \
object->sub.col.g, \
object->sub.col.b, \
object->sub.col.a);
#define COLOR_SET_AMUL(object, sub, col, amul) \
if (obj->cur.clipper) \
ENFN->context_color_set(output, context, \
(((int)object->sub.col.r) * ((int)obj->cur.clipper->cur.cache.clip.r) * (amul)) / 65025, \
(((int)object->sub.col.g) * ((int)obj->cur.clipper->cur.cache.clip.g) * (amul)) / 65025, \
(((int)object->sub.col.b) * ((int)obj->cur.clipper->cur.cache.clip.b) * (amul)) / 65025, \
(((int)object->sub.col.a) * ((int)obj->cur.clipper->cur.cache.clip.a) * (amul)) / 65025); \
else \
ENFN->context_color_set(output, context, \
(((int)object->sub.col.r) * (amul)) / 255, \
(((int)object->sub.col.g) * (amul)) / 255, \
(((int)object->sub.col.b) * (amul)) / 255, \
(((int)object->sub.col.a) * (amul)) / 255);
#define DRAW_TEXT(ox, oy) \
if ((o->font) && (it->text_props.len > 0)) \
ENFN->font_draw(output, \
context, \
surface, \
o->font, \
obj->cur.geometry.x + x + sl + ox + it->x, \
obj->cur.geometry.y + y + st + oy + \
(int) \
(((o->max_ascent * obj->cur.geometry.h) / obj->cur.geometry.h) - 0.5), \
obj->cur.geometry.w, \
obj->cur.geometry.h, \
obj->cur.geometry.w, \
obj->cur.geometry.h, \
&it->text_props);
/* shadows */
shad_dst = shad_sz = dx = dy = haveshad = 0;
switch (o->cur.style & EVAS_TEXT_STYLE_MASK_BASIC)
{
case EVAS_TEXT_STYLE_SHADOW:
case EVAS_TEXT_STYLE_OUTLINE_SOFT_SHADOW:
shad_dst = 1;
haveshad = 1;
break;
case EVAS_TEXT_STYLE_OUTLINE_SHADOW:
case EVAS_TEXT_STYLE_FAR_SHADOW:
shad_dst = 2;
haveshad = 1;
break;
case EVAS_TEXT_STYLE_FAR_SOFT_SHADOW:
shad_dst = 2;
shad_sz = 2;
haveshad = 1;
break;
case EVAS_TEXT_STYLE_SOFT_SHADOW:
shad_dst = 1;
shad_sz = 2;
haveshad = 1;
break;
default:
break;
}
if (haveshad)
{
if (shad_dst > 0)
{
switch (o->cur.style & EVAS_TEXT_STYLE_MASK_SHADOW_DIRECTION)
{
case EVAS_TEXT_STYLE_SHADOW_DIRECTION_BOTTOM_RIGHT:
dx = 1;
dy = 1;
break;
case EVAS_TEXT_STYLE_SHADOW_DIRECTION_BOTTOM:
dx = 0;
dy = 1;
break;
case EVAS_TEXT_STYLE_SHADOW_DIRECTION_BOTTOM_LEFT:
dx = -1;
dy = 1;
break;
case EVAS_TEXT_STYLE_SHADOW_DIRECTION_LEFT:
dx = -1;
dy = 0;
break;
case EVAS_TEXT_STYLE_SHADOW_DIRECTION_TOP_LEFT:
dx = -1;
dy = -1;
break;
case EVAS_TEXT_STYLE_SHADOW_DIRECTION_TOP:
dx = 0;
dy = -1;
break;
case EVAS_TEXT_STYLE_SHADOW_DIRECTION_TOP_RIGHT:
dx = 1;
dy = -1;
break;
case EVAS_TEXT_STYLE_SHADOW_DIRECTION_RIGHT:
dx = 1;
dy = 0;
default:
break;
}
dx *= shad_dst;
dy *= shad_dst;
}
}
EINA_INLIST_FOREACH(EINA_INLIST_GET(o->items), it)
{
/* Shadows */
if (haveshad)
{
switch (shad_sz)
{
case 0:
COLOR_SET(o, cur, shadow);
DRAW_TEXT(dx, dy);
break;
case 2:
for (j = 0; j < 5; j++)
{
for (i = 0; i < 5; i++)
{
if (vals[i][j] != 0)
{
COLOR_SET_AMUL(o, cur, shadow, vals[i][j] * 50);
DRAW_TEXT(i - 2 + dx, j - 2 + dy);
}
}
}
break;
default:
break;
}
}
/* glows */
if (o->cur.style == EVAS_TEXT_STYLE_GLOW)
{
for (j = 0; j < 5; j++)
{
for (i = 0; i < 5; i++)
{
if (vals[i][j] != 0)
{
COLOR_SET_AMUL(o, cur, glow, vals[i][j] * 50);
DRAW_TEXT(i - 2, j - 2);
}
}
}
COLOR_SET(o, cur, glow2);
DRAW_TEXT(-1, 0);
DRAW_TEXT(1, 0);
DRAW_TEXT(0, -1);
DRAW_TEXT(0, 1);
}
/* outlines */
if ((o->cur.style == EVAS_TEXT_STYLE_OUTLINE) ||
(o->cur.style == EVAS_TEXT_STYLE_OUTLINE_SHADOW) ||
(o->cur.style == EVAS_TEXT_STYLE_OUTLINE_SOFT_SHADOW))
{
COLOR_SET(o, cur, outline);
DRAW_TEXT(-1, 0);
DRAW_TEXT(1, 0);
DRAW_TEXT(0, -1);
DRAW_TEXT(0, 1);
}
else if (o->cur.style == EVAS_TEXT_STYLE_SOFT_OUTLINE)
{
for (j = 0; j < 5; j++)
{
for (i = 0; i < 5; i++)
{
if (((i != 2) || (j != 2)) && (vals[i][j] != 0))
{
COLOR_SET_AMUL(o, cur, outline, vals[i][j] * 50);
DRAW_TEXT(i - 2, j - 2);
}
}
}
}
/* normal text */
COLOR_ONLY_SET(obj, cur.cache, clip);
DRAW_TEXT(0, 0);
}
}
static void
evas_object_text_render_pre(Evas_Object *obj)
{
Evas_Object_Text *o;
int is_v, was_v;
/* dont pre-render the obj twice! */
if (obj->pre_render_done) return;
obj->pre_render_done = 1;
/* pre-render phase. this does anything an object needs to do just before
rendering. This could mean loading the image data, retrieving it from
elsewhere, decoding video etc.
Then when this is done the object needs to figure if it changed and
if so what and where and add the appropriate redraw rectangles */
o = (Evas_Object_Text *)(obj->object_data);
/* if someone is clipping this obj - go calculate the clipper */
if (obj->cur.clipper)
{
if (obj->cur.cache.clip.dirty)
evas_object_clip_recalc(obj->cur.clipper);
obj->cur.clipper->func->render_pre(obj->cur.clipper);
}
/* now figure what changed and add draw rects
if it just became visible or invisible */
is_v = evas_object_is_visible(obj);
was_v = evas_object_was_visible(obj);
if (is_v != was_v)
{
evas_object_render_pre_visible_change(&obj->layer->evas->clip_changes,
obj, is_v, was_v);
goto done;
}
if ((obj->cur.map != obj->prev.map) ||
(obj->cur.usemap != obj->prev.usemap))
{
evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes,
obj);
goto done;
}
/* its not visible - we accounted for it appearing or not so just abort */
if (!is_v) goto done;
/* clipper changed this is in addition to anything else for obj */
evas_object_render_pre_clipper_change(&obj->layer->evas->clip_changes, obj);
/* if we restacked (layer or just within a layer) and dont clip anyone */
if (obj->restack)
{
evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes,
obj);
goto done;
}
/* if it changed color */
if ((obj->cur.color.r != obj->prev.color.r) ||
(obj->cur.color.g != obj->prev.color.g) ||
(obj->cur.color.b != obj->prev.color.b) ||
(obj->cur.color.a != obj->prev.color.a))
{
evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes,
obj);
goto done;
}
/* if it changed geometry - and obviously not visibility or color
calculate differences since we have a constant color fill
we really only need to update the differences */
if ((obj->cur.geometry.x != obj->prev.geometry.x) ||
(obj->cur.geometry.y != obj->prev.geometry.y) ||
(obj->cur.geometry.w != obj->prev.geometry.w) ||
(obj->cur.geometry.h != obj->prev.geometry.h))
{
evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes,
obj);
goto done;
}
if (obj->cur.render_op != obj->prev.render_op)
{
evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes,
obj);
goto done;
}
if (obj->cur.scale != obj->prev.scale)
{
evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes,
obj);
goto done;
}
if (o->changed)
{
if ((o->cur.size != o->prev.size) ||
((o->cur.font != o->prev.font)) ||
((o->cur.utf8_text != o->prev.utf8_text)) ||
((o->cur.style != o->prev.style)) ||
((o->cur.shadow.r != o->prev.shadow.r)) ||
((o->cur.shadow.g != o->prev.shadow.g)) ||
((o->cur.shadow.b != o->prev.shadow.b)) ||
((o->cur.shadow.a != o->prev.shadow.a)) ||
((o->cur.outline.r != o->prev.outline.r)) ||
((o->cur.outline.g != o->prev.outline.g)) ||
((o->cur.outline.b != o->prev.outline.b)) ||
((o->cur.outline.a != o->prev.outline.a)) ||
((o->cur.glow.r != o->prev.glow.r)) ||
((o->cur.glow.g != o->prev.glow.g)) ||
((o->cur.glow.b != o->prev.glow.b)) ||
((o->cur.glow.a != o->prev.glow.a)) ||
((o->cur.glow2.r != o->prev.glow2.r)) ||
((o->cur.glow2.g != o->prev.glow2.g)) ||
((o->cur.glow2.b != o->prev.glow2.b)) ||
((o->cur.glow2.a != o->prev.glow2.a)))
{
evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes,
obj);
goto done;
}
}
done:
evas_object_render_pre_effect_updates(&obj->layer->evas->clip_changes,
obj, is_v, was_v);
}
static void
evas_object_text_render_post(Evas_Object *obj)
{
Evas_Object_Text *o;
/* this moves the current data to the previous state parts of the object
in whatever way is safest for the object. also if we don't need object
data anymore we can free it if the object deems this is a good idea */
o = (Evas_Object_Text *)(obj->object_data);
/* remove those pesky changes */
evas_object_clip_changes_clean(obj);
/* move cur to prev safely for object data */
obj->prev = obj->cur;
o->prev = o->cur;
o->changed = 0;
}
static unsigned int
evas_object_text_id_get(Evas_Object *obj)
{
Evas_Object_Text *o;
o = (Evas_Object_Text *)(obj->object_data);
if (!o) return 0;
return MAGIC_OBJ_TEXT;
}
static unsigned int
evas_object_text_visual_id_get(Evas_Object *obj)
{
Evas_Object_Text *o;
o = (Evas_Object_Text *)(obj->object_data);
if (!o) return 0;
return MAGIC_OBJ_SHAPE;
}
static void *
evas_object_text_engine_data_get(Evas_Object *obj)
{
Evas_Object_Text *o;
o = (Evas_Object_Text *)(obj->object_data);
if (!o) return NULL;
return o->font;
}
static int
evas_object_text_is_opaque(Evas_Object *obj __UNUSED__)
{
/* this returns 1 if the internal object data implies that the object is
currently fully opaque over the entire gradient it occupies */
return 0;
}
static int
evas_object_text_was_opaque(Evas_Object *obj __UNUSED__)
{
/* this returns 1 if the internal object data implies that the object was
currently fully opaque over the entire gradient it occupies */
return 0;
}
static void
evas_object_text_scale_update(Evas_Object *obj)
{
Evas_Object_Text *o;
int size;
const char *font;
o = (Evas_Object_Text *)(obj->object_data);
font = eina_stringshare_add(o->cur.font);
size = o->cur.size;
if (o->cur.font) eina_stringshare_del(o->cur.font);
o->cur.font = NULL;
o->prev.font = NULL;
o->cur.size = 0;
o->prev.size = 0;
evas_object_text_font_set(obj, font, size);
}
void
_evas_object_text_rehint(Evas_Object *obj)
{
Evas_Object_Text *o;
int is, was;
o = (Evas_Object_Text *)(obj->object_data);
if (!o->font) return;
#ifdef EVAS_FRAME_QUEUING
evas_common_pipe_op_text_flush((RGBA_Font *) o->font);
#endif
evas_font_load_hinting_set(obj->layer->evas, o->font,
obj->layer->evas->hinting);
was = evas_object_is_in_output_rect(obj,
obj->layer->evas->pointer.x,
obj->layer->evas->pointer.y, 1, 1);
/* DO II */
_evas_object_text_recalc(obj);
o->changed = 1;
evas_object_change(obj);
evas_object_clip_dirty(obj);
evas_object_coords_recalc(obj);
is = evas_object_is_in_output_rect(obj,
obj->layer->evas->pointer.x,
obj->layer->evas->pointer.y, 1, 1);
if ((is || was) && obj->cur.visible)
evas_event_feed_mouse_move(obj->layer->evas,
obj->layer->evas->pointer.x,
obj->layer->evas->pointer.y,
obj->layer->evas->last_timestamp,
NULL);
evas_object_inform_call_resize(obj);
}
static void
_evas_object_text_recalc(Evas_Object *obj)
{
Evas_Object_Text *o;
Eina_Unicode *text = NULL;
o = (Evas_Object_Text *)(obj->object_data);
if (o->items) _evas_object_text_items_clear(o);
if (o->cur.utf8_text)
text = eina_unicode_utf8_to_unicode(o->cur.utf8_text,
NULL);
if (!text) text = eina_unicode_strdup(EINA_UNICODE_EMPTY_STRING);
_evas_object_text_layout(obj, o, text);
if (text) free(text);
if ((o->font) && (o->items))
{
int w, h;
int l = 0, r = 0, t = 0, b = 0;
w = _evas_object_text_horiz_advance_get(obj, o);
h = _evas_object_text_vert_advance_get(obj, o);
evas_text_style_pad_get(o->cur.style, &l, &r, &t, &b);
obj->cur.geometry.w = w + l + r;
obj->cur.geometry.h = h + t + b;
//// obj->cur.cache.geometry.validity = 0;
}
else
{
int t = 0, b = 0;
evas_text_style_pad_get(o->cur.style, NULL, NULL, &t, &b);
obj->cur.geometry.w = 0;
obj->cur.geometry.h = o->max_ascent + o->max_descent + t + b;
//// obj->cur.cache.geometry.validity = 0;
}
}
|