summaryrefslogtreecommitdiff
path: root/src/lib/evas/common/evas_font_main.c
diff options
context:
space:
mode:
authorAli Alzyod <ali198724@gmail.com>2019-12-12 16:22:12 +0900
committerWooHyun Jung <wh0705.jung@samsung.com>2019-12-12 16:22:12 +0900
commit2d7622491884843ce15e2717675b128af1bdbefc (patch)
treebadc8961affe622f541c3347e3b1b6d620bff898 /src/lib/evas/common/evas_font_main.c
parentc62a7dae6316df60c6c47577743b62185ca56951 (diff)
evas_object_textblock: add support for variation sequences
Summary: update font processing to handle variation sequences unicodes to select proper glypg in respect to variation seqences Test Plan: ``` #define EFL_EO_API_SUPPORT 1 #define EFL_BETA_API_SUPPORT 1 #include <Eina.h> #include <Efl.h> #include <Elementary.h> EAPI_MAIN int elm_main(int argc, char **argv) { Evas_Object *win, *textblock; elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); win = elm_win_util_standard_add("Main", ""); elm_win_autodel_set(win, EINA_TRUE); textblock = evas_object_textblock_add(win); efl_canvas_text_style_set(textblock,NULL,"DEFAULT='font=DejaVuSans font_fallbacks=SamsungColorEmoji color=#000 font_size=20'"); evas_object_textblock_text_markup_set(textblock, "8&#xfe0f;&#x20E3;&#x262a;&#xfe0f;AAA&#x262a;&#xfe0E;1234567&#xfe0f;&#x20E3;"); evas_object_size_hint_weight_set(textblock, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(textblock, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(textblock); evas_object_move(textblock, 0, 0); evas_object_resize(textblock, 320, 320); evas_object_resize(win, 320, 320); evas_object_show(win); elm_run(); return 0; } ELM_MAIN() ``` Reviewers: woohyun, bowonryu, segfaultxavi, cedric, bu5hm4n Reviewed By: woohyun, cedric Subscribers: raster, bu5hm4n, subodh6129, herdsman, segfaultxavi, zmike, cedric, #committers, #reviewers Tags: #efl Differential Revision: https://phab.enlightenment.org/D9053
Diffstat (limited to '')
-rw-r--r--src/lib/evas/common/evas_font_main.c296
1 files changed, 268 insertions, 28 deletions
diff --git a/src/lib/evas/common/evas_font_main.c b/src/lib/evas/common/evas_font_main.c
index 1a163748ca..c41e350dcf 100644
--- a/src/lib/evas/common/evas_font_main.c
+++ b/src/lib/evas/common/evas_font_main.c
@@ -355,33 +355,182 @@ end:
355/* Set of common functions that are used in a couple of places. */ 355/* Set of common functions that are used in a couple of places. */
356 356
357static void 357static void
358_fash_int2_free(Fash_Int_Map2 *fash) 358_fash_int_map_and_variations_free(Fash_Int_Map *map)
359{ 359 {
360 if(!map)
361 return;
360 int i; 362 int i;
361 363
362 for (i = 0; i < 256; i++) if (fash->bucket[i]) free(fash->bucket[i]); 364 for (i = 0; i < 256; i++)
363 free(fash); 365 {
366 if (map->items[i].variations)
367 {
368 if (map->items[i].variations->list)
369 {
370 free(map->items[i].variations->list);
371 map->items[i].variations->list = NULL;
372 map->items[i].variations->capacity = 0;
373 map->items[i].variations->length = 0;
374 }
375 free(map->items[i].variations);
376 map->items[i].variations = NULL;
377 }
378 }
379
380 free(map);
381}
382
383static void
384_fash_int2_free(Fash_Int_Map2 *fash)
385 {
386 int i;
387 if (fash)
388 {
389 for (i = 0; i < 256; i++)
390 if (fash->bucket[i])
391 {
392 _fash_int_map_and_variations_free(fash->bucket[i]);
393 fash->bucket[i] = NULL;
394 }
395 free(fash);
396 fash = NULL;
397 }
364} 398}
365 399
366static void 400static void
367_fash_int_free(Fash_Int *fash) 401_fash_int_free(Fash_Int *fash)
368{ 402{
369 int i; 403 int i;
404 if (fash)
405 {
406 if (fash->MAGIC != FASH_INT_MAGIC)
407 {
408 return;
409 }
370 410
371 for (i = 0; i < 256; i++) if (fash->bucket[i]) _fash_int2_free(fash->bucket[i]); 411 for (i = 0; i < 256; i++)
372 free(fash); 412 {
413 if (fash->bucket[i])
414 {
415 _fash_int2_free(fash->bucket[i]);
416 fash->bucket[i] = NULL;
417 }
418 }
419 free(fash);
420 }
373} 421}
374 422
375static Fash_Int * 423static Fash_Int *
376_fash_int_new(void) 424_fash_int_new(void)
377{ 425{
378 Fash_Int *fash = calloc(1, sizeof(Fash_Int)); 426 Fash_Int *fash = calloc(1, sizeof(Fash_Int));
427 EINA_SAFETY_ON_NULL_RETURN_VAL(fash, NULL);
428 fash->MAGIC = FASH_INT_MAGIC;
379 fash->freeme = _fash_int_free; 429 fash->freeme = _fash_int_free;
380 return fash; 430 return fash;
381} 431}
382 432
433static Fash_Item_variation_List *
434_variations_list_new(void)
435{
436 Fash_Item_variation_List *variations = calloc(1, sizeof(Fash_Item_variation_List));
437 EINA_SAFETY_ON_NULL_RETURN_VAL(variations, NULL);
438 variations->capacity = 0;
439 variations->length = 0;
440 variations->list = 0;
441 return variations;
442}
443
444static void
445_variations_list_add(Fash_Item_variation_List *variations,RGBA_Font_Int *fint, int index, Eina_Unicode variation_sequence)
446{
447 Fash_Item_variation_Index_Item *list = variations->list;
448 if (variations->capacity == variations->length)
449 {
450 list = (Fash_Item_variation_Index_Item *) realloc(list, (variations->capacity + 4) * sizeof(Fash_Item_variation_Index_Item));
451 if (list)
452 {
453 variations->list = list;
454 variations->capacity += 4;
455 }
456 }
457
458 EINA_SAFETY_ON_NULL_RETURN(list);
459
460 int start = 0;
461 int end = variations->length;
462 if (end == 0)
463 {
464 // if only on element just add it in 0 index
465 variations->list[0].item.fint = fint;
466 variations->list[0].item.index = index;
467 variations->list[0].variation_sequence = variation_sequence;
468 variations->length++;
469 }
470 else
471 {
472 // find lower bound
473 while (end > start)
474 {
475 int middle = start + (end - start) / 2;
476 if (variations->list[middle].variation_sequence >= variation_sequence)
477 end = middle;
478 else
479 start = middle + 1;
480 }
481
482 // if passed value founded in list, just replace it
483 if (start < (int)variations->length && variations->list[start].variation_sequence == variation_sequence)
484 {
485 variations->list[start].item.fint = fint;
486 variations->list[start].item.index = index;
487 variations->list[start].variation_sequence = variation_sequence;
488 return;
489 }
490
491 // shift array to insert item
492 for (int i = (variations->length - 1) ; i >= start; i--)
493 {
494 variations->list[i + 1] = variations->list[i];
495 }
496
497 // insert new item and keep array sorted
498 variations->list[start].item.fint = fint;
499 variations->list[start].item.index = index;
500 variations->list[start].variation_sequence = variation_sequence;
501 variations->length++;
502 }
503}
504
505
383static Fash_Item_Index_Map * 506static Fash_Item_Index_Map *
384_fash_int_find(Fash_Int *fash, int item) 507_variations_list_find(Fash_Item_variation_List * variations, Eina_Unicode variation_sequence)
508{
509 if (!variations)
510 return NULL;
511
512 if (!variations->list)
513 return NULL;
514
515 int start = 0;
516 int end = variations->length;
517
518 while(end > start)
519 {
520 int middle = start + (end - start) / 2;
521 if (variations->list[middle].variation_sequence == variation_sequence)
522 return &(variations->list[middle].item);
523 else if (variations->list[middle].variation_sequence < variation_sequence)
524 start = middle + 1;
525 else
526 end = middle - 1;
527 }
528
529 return NULL;
530}
531
532static const Fash_Item_Index_Map *
533_fash_int_find(Fash_Int *fash, int item, Eina_Unicode variation_sequence)
385{ 534{
386 int grp, maj, min; 535 int grp, maj, min;
387 536
@@ -391,14 +540,22 @@ _fash_int_find(Fash_Int *fash, int item)
391 min = item & 0xff; 540 min = item & 0xff;
392 if (!fash->bucket[grp]) return NULL; 541 if (!fash->bucket[grp]) return NULL;
393 if (!fash->bucket[grp]->bucket[maj]) return NULL; 542 if (!fash->bucket[grp]->bucket[maj]) return NULL;
394 return &(fash->bucket[grp]->bucket[maj]->item[min]); 543 if (!variation_sequence)
544 return &(fash->bucket[grp]->bucket[maj]->items[min].item);
545 else
546 return _variations_list_find(fash->bucket[grp]->bucket[maj]->items[min].variations, variation_sequence);
395} 547}
396 548
397static void 549static void
398_fash_int_add(Fash_Int *fash, int item, RGBA_Font_Int *fint, int idx) 550_fash_int_add(Fash_Int *fash, int item, RGBA_Font_Int *fint, int idx, Eina_Unicode variation_sequence)
399{ 551{
400 int grp, maj, min; 552 int grp, maj, min;
401 553
554 // If we already have cached passed item, skip adding it again
555 const Fash_Item_Index_Map *fm = _fash_int_find(fash, item, variation_sequence);
556 if (fm && fm->fint)
557 return;
558
402 // 24bits for unicode - v6 up to E01EF (chrs) & 10FFFD for private use (plane 16) 559 // 24bits for unicode - v6 up to E01EF (chrs) & 10FFFD for private use (plane 16)
403 grp = (item >> 16) & 0xff; 560 grp = (item >> 16) & 0xff;
404 maj = (item >> 8) & 0xff; 561 maj = (item >> 8) & 0xff;
@@ -409,8 +566,20 @@ _fash_int_add(Fash_Int *fash, int item, RGBA_Font_Int *fint, int idx)
409 if (!fash->bucket[grp]->bucket[maj]) 566 if (!fash->bucket[grp]->bucket[maj])
410 fash->bucket[grp]->bucket[maj] = calloc(1, sizeof(Fash_Int_Map)); 567 fash->bucket[grp]->bucket[maj] = calloc(1, sizeof(Fash_Int_Map));
411 EINA_SAFETY_ON_NULL_RETURN(fash->bucket[grp]->bucket[maj]); 568 EINA_SAFETY_ON_NULL_RETURN(fash->bucket[grp]->bucket[maj]);
412 fash->bucket[grp]->bucket[maj]->item[min].fint = fint; 569 if (variation_sequence)
413 fash->bucket[grp]->bucket[maj]->item[min].index = idx; 570 {
571 if (!fash->bucket[grp]->bucket[maj]->items[min].variations)
572 {
573 fash->bucket[grp]->bucket[maj]->items[min].variations =_variations_list_new();
574 EINA_SAFETY_ON_NULL_RETURN(fash->bucket[grp]->bucket[maj]->items[min].variations);
575 }
576 _variations_list_add(fash->bucket[grp]->bucket[maj]->items[min].variations, fint, idx, variation_sequence);
577 }
578 else
579 {
580 fash->bucket[grp]->bucket[maj]->items[min].item.fint = fint;
581 fash->bucket[grp]->bucket[maj]->items[min].item.index = idx;
582 }
414} 583}
415 584
416static void 585static void
@@ -462,24 +631,45 @@ _fash_gl2_free(Fash_Glyph_Map2 *fash)
462 int i; 631 int i;
463 632
464 // 24bits for unicode - v6 up to E01EF (chrs) & 10FFFD for private use (plane 16) 633 // 24bits for unicode - v6 up to E01EF (chrs) & 10FFFD for private use (plane 16)
465 for (i = 0; i < 256; i++) if (fash->bucket[i]) _fash_glyph_free(fash->bucket[i]); 634 for (i = 0; i < 256; i++)
635 {
636 if (fash->bucket[i])
637 {
638 _fash_glyph_free(fash->bucket[i]);
639 fash->bucket[i] = NULL;
640 }
641 }
466 free(fash); 642 free(fash);
467} 643}
468 644
469static void 645static void
470_fash_gl_free(Fash_Glyph *fash) 646_fash_gl_free(Fash_Glyph *fash)
471{ 647{
472 int i; 648 if (fash)
649 {
650 if (fash->MAGIC != FASH_GLYPH_MAGIC)
651 return;
473 652
474 // 24bits for unicode - v6 up to E01EF (chrs) & 10FFFD for private use (plane 16) 653 int i;
475 for (i = 0; i < 256; i++) if (fash->bucket[i]) _fash_gl2_free(fash->bucket[i]); 654 // 24bits for unicode - v6 up to E01EF (chrs) & 10FFFD for private use (plane 16)
476 free(fash); 655 for (i = 0; i < 256; i++)
656 {
657 if (fash->bucket[i])
658 {
659 _fash_gl2_free(fash->bucket[i]);
660 fash->bucket[i] = NULL;
661 }
662 }
663 free(fash);
664 }
477} 665}
478 666
479static Fash_Glyph * 667static Fash_Glyph *
480_fash_gl_new(void) 668_fash_gl_new(void)
481{ 669{
482 Fash_Glyph *fash = calloc(1, sizeof(Fash_Glyph)); 670 Fash_Glyph *fash = calloc(1, sizeof(Fash_Glyph));
671 EINA_SAFETY_ON_NULL_RETURN_VAL(fash, NULL);
672 fash->MAGIC = FASH_GLYPH_MAGIC;
483 fash->freeme = _fash_gl_free; 673 fash->freeme = _fash_gl_free;
484 return fash; 674 return fash;
485} 675}
@@ -680,7 +870,7 @@ struct _Font_Char_Index
680}; 870};
681 871
682EAPI FT_UInt 872EAPI FT_UInt
683evas_common_get_char_index(RGBA_Font_Int* fi, Eina_Unicode gl) 873evas_common_get_char_index(RGBA_Font_Int* fi, Eina_Unicode gl, Eina_Unicode variation_sequence)
684{ 874{
685 static const unsigned short mapfix[] = 875 static const unsigned short mapfix[] =
686 { 876 {
@@ -742,7 +932,10 @@ evas_common_get_char_index(RGBA_Font_Int* fi, Eina_Unicode gl)
742 * that something else try to use it. 932 * that something else try to use it.
743 */ 933 */
744 /* FTLOCK(); */ 934 /* FTLOCK(); */
745 result.index = FT_Get_Char_Index(fi->src->ft.face, gl); 935 if (variation_sequence)
936 result.index = FT_Face_GetCharVariantIndex(fi->src->ft.face, gl, variation_sequence);
937 else
938 result.index = FT_Get_Char_Index(fi->src->ft.face, gl);
746 /* FTUNLOCK(); */ 939 /* FTUNLOCK(); */
747 result.gl = gl; 940 result.gl = gl;
748 941
@@ -774,7 +967,10 @@ evas_common_get_char_index(RGBA_Font_Int* fi, Eina_Unicode gl)
774 { 967 {
775 gl = mapfix[(i << 1) + 1]; 968 gl = mapfix[(i << 1) + 1];
776 FTLOCK(); 969 FTLOCK();
777 result.index = FT_Get_Char_Index(fi->src->ft.face, gl); 970 if (variation_sequence)
971 result.index = FT_Face_GetCharVariantIndex(fi->src->ft.face, gl, variation_sequence);
972 else
973 result.index = FT_Get_Char_Index(fi->src->ft.face, gl);
778 FTUNLOCK(); 974 FTUNLOCK();
779 break; 975 break;
780 } 976 }
@@ -799,20 +995,49 @@ evas_common_get_char_index(RGBA_Font_Int* fi, Eina_Unicode gl)
799 return result.index; 995 return result.index;
800} 996}
801 997
998
999/*
1000 * @internal
1001 * Search for unicode glyph inside all font files, and return font and glyph index
1002 *
1003 * @param[in] fn the font to use.
1004 * @param[out] fi_ret founded font.
1005 * @param[in] gl unicode glyph to search for
1006 * @param[in] variation_sequence for the gl glyph
1007 * @param[in] evas_font_search_options search options when searching font files
1008 *
1009 */
1010
802EAPI int 1011EAPI int
803evas_common_font_glyph_search(RGBA_Font *fn, RGBA_Font_Int **fi_ret, Eina_Unicode gl) 1012evas_common_font_glyph_search(RGBA_Font *fn, RGBA_Font_Int **fi_ret, Eina_Unicode gl, Eina_Unicode variation_sequence, uint32_t evas_font_search_options)
804{ 1013{
805 Eina_List *l; 1014 Eina_List *l;
806 1015
807 if (fn->fash) 1016 if (fn->fash)
808 { 1017 {
809 Fash_Item_Index_Map *fm = _fash_int_find(fn->fash, gl); 1018 const Fash_Item_Index_Map *fm = _fash_int_find(fn->fash, gl, variation_sequence);
810 if (fm) 1019 if (fm)
811 { 1020 {
812 if (fm->fint) 1021 if (fm->fint)
813 { 1022 {
814 *fi_ret = fm->fint; 1023 if (evas_font_search_options == EVAS_FONT_SEARCH_OPTION_NONE)
815 return fm->index; 1024 {
1025 *fi_ret = fm->fint;
1026 return fm->index;
1027 }
1028 else if( (evas_font_search_options & EVAS_FONT_SEARCH_OPTION_SKIP_COLOR) == EVAS_FONT_SEARCH_OPTION_SKIP_COLOR)
1029 {
1030 if (!fm->fint->src->ft.face)
1031 {
1032 evas_common_font_int_reload(fm->fint);
1033 }
1034
1035 if (fm->fint->src->ft.face && !FT_HAS_COLOR(fm->fint->src->ft.face))
1036 {
1037 *fi_ret = fm->fint;
1038 return fm->index;
1039 }
1040 }
816 } 1041 }
817 else if (fm->index == -1) return 0; 1042 else if (fm->index == -1) return 0;
818 } 1043 }
@@ -851,20 +1076,35 @@ evas_common_font_glyph_search(RGBA_Font *fn, RGBA_Font_Int **fi_ret, Eina_Unicod
851 } 1076 }
852 if (fi->src->ft.face) 1077 if (fi->src->ft.face)
853 { 1078 {
854 idx = evas_common_get_char_index(fi, gl); 1079 Eina_Bool is_color_only = (evas_font_search_options & EVAS_FONT_SEARCH_OPTION_SKIP_COLOR) == EVAS_FONT_SEARCH_OPTION_SKIP_COLOR &&
1080 FT_HAS_COLOR(fi->src->ft.face);
1081
1082 if (is_color_only)
1083 {
1084 /* This is color font ignore it */
1085 continue;
1086 }
1087
1088 idx = (int) evas_common_get_char_index(fi, gl, variation_sequence);
855 if (idx != 0) 1089 if (idx != 0)
856 { 1090 {
857 if (!fi->ft.size) 1091 if (!fi->ft.size)
858 evas_common_font_int_load_complete(fi); 1092 evas_common_font_int_load_complete(fi);
859 if (!fn->fash) fn->fash = _fash_int_new(); 1093 if (!is_color_only)
860 if (fn->fash) _fash_int_add(fn->fash, gl, fi, idx); 1094 {
1095 if (!fn->fash) fn->fash = _fash_int_new();
1096 if (fn->fash) _fash_int_add(fn->fash, gl, fi, idx, variation_sequence);
1097 }
861 *fi_ret = fi; 1098 *fi_ret = fi;
862 return idx; 1099 return idx;
863 } 1100 }
864 else 1101 else
865 { 1102 {
866 if (!fn->fash) fn->fash = _fash_int_new(); 1103 if (!is_color_only)
867 if (fn->fash) _fash_int_add(fn->fash, gl, NULL, -1); 1104 {
1105 if (!fn->fash) fn->fash = _fash_int_new();
1106 if (fn->fash) _fash_int_add(fn->fash, gl, NULL, -1, variation_sequence);
1107 }
868 } 1108 }
869 } 1109 }
870 } 1110 }