Mercurial > emacs
comparison src/fontset.c @ 103587:1db851c2440a
(fontset_find_font): When a usable rfont_def is found
in a fallback font-group, make it the first element of the group.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Thu, 25 Jun 2009 08:02:19 +0000 |
parents | 67e242fdd3e1 |
children | 9bc67103bc1d |
comparison
equal
deleted
inserted
replaced
103586:c78f612cb825 | 103587:1db851c2440a |
---|---|
529 int c; | 529 int c; |
530 struct face *face; | 530 struct face *face; |
531 int id, fallback; | 531 int id, fallback; |
532 { | 532 { |
533 Lisp_Object vec, font_group; | 533 Lisp_Object vec, font_group; |
534 int i, charset_matched = -1; | 534 int i, charset_matched = -1, found_index; |
535 FRAME_PTR f = (FRAMEP (FONTSET_FRAME (fontset))) | 535 FRAME_PTR f = (FRAMEP (FONTSET_FRAME (fontset))) |
536 ? XFRAME (selected_frame) : XFRAME (FONTSET_FRAME (fontset)); | 536 ? XFRAME (selected_frame) : XFRAME (FONTSET_FRAME (fontset)); |
537 Lisp_Object rfont_def; | |
537 | 538 |
538 font_group = fontset_get_font_group (fontset, fallback ? -1 : c); | 539 font_group = fontset_get_font_group (fontset, fallback ? -1 : c); |
539 if (! CONSP (font_group)) | 540 if (! CONSP (font_group)) |
540 return font_group; | 541 return font_group; |
541 vec = XCDR (font_group); | 542 vec = XCDR (font_group); |
551 if (id >= 0) | 552 if (id >= 0) |
552 /* Find a spec matching with the charset ID to try at | 553 /* Find a spec matching with the charset ID to try at |
553 first. */ | 554 first. */ |
554 for (i = 0; i < ASIZE (vec); i++) | 555 for (i = 0; i < ASIZE (vec); i++) |
555 { | 556 { |
556 Lisp_Object rfont_def = AREF (vec, i); | |
557 Lisp_Object repertory; | 557 Lisp_Object repertory; |
558 | 558 |
559 rfont_def = AREF (vec, i); | |
559 if (NILP (rfont_def)) | 560 if (NILP (rfont_def)) |
560 break; | 561 break; |
561 repertory = FONT_DEF_REPERTORY (RFONT_DEF_FONT_DEF (rfont_def)); | 562 repertory = FONT_DEF_REPERTORY (RFONT_DEF_FONT_DEF (rfont_def)); |
562 | 563 |
563 if (XINT (repertory) == id) | 564 if (XINT (repertory) == id) |
569 } | 570 } |
570 | 571 |
571 /* Find the first available font in the vector of RFONT-DEF. */ | 572 /* Find the first available font in the vector of RFONT-DEF. */ |
572 for (i = 0; i < ASIZE (vec); i++) | 573 for (i = 0; i < ASIZE (vec); i++) |
573 { | 574 { |
574 Lisp_Object rfont_def, font_def; | 575 Lisp_Object font_def; |
575 Lisp_Object font_entity, font_object; | 576 Lisp_Object font_entity, font_object; |
576 | 577 |
577 if (i == 0 && charset_matched >= 0) | 578 if (i == 0 && charset_matched >= 0) |
578 { | 579 { |
579 /* Try the element matching with the charset ID at first. */ | 580 /* Try the element matching with the charset ID at first. */ |
580 rfont_def = AREF (vec, charset_matched); | 581 rfont_def = AREF (vec, charset_matched); |
582 found_index = charset_matched; | |
581 charset_matched = -1; | 583 charset_matched = -1; |
582 i--; | 584 i--; |
583 } | 585 } |
584 else if (i != charset_matched) | 586 else if (i != charset_matched) |
585 rfont_def = AREF (vec, i); | 587 { |
588 rfont_def = AREF (vec, i); | |
589 found_index = i; | |
590 } | |
586 else | 591 else |
587 continue; | 592 continue; |
588 | 593 |
589 if (NILP (rfont_def)) | 594 if (NILP (rfont_def)) |
590 /* This is a sign of not to try the other fonts. */ | 595 /* This is a sign of not to try the other fonts. */ |
628 } | 633 } |
629 RFONT_DEF_SET_OBJECT (rfont_def, font_object); | 634 RFONT_DEF_SET_OBJECT (rfont_def, font_object); |
630 } | 635 } |
631 | 636 |
632 if (font_has_char (f, font_object, c)) | 637 if (font_has_char (f, font_object, c)) |
633 return rfont_def; | 638 goto found; |
634 | 639 |
635 /* Find a font already opened, maching with the current spec, | 640 /* Find a font already opened, maching with the current spec, |
636 and supporting C. */ | 641 and supporting C. */ |
637 font_def = RFONT_DEF_FONT_DEF (rfont_def); | 642 font_def = RFONT_DEF_FONT_DEF (rfont_def); |
638 for (i++; i < ASIZE (vec); i++) | 643 for (i++; i < ASIZE (vec); i++) |
642 return Qt; | 647 return Qt; |
643 if (! EQ (RFONT_DEF_FONT_DEF (rfont_def), font_def)) | 648 if (! EQ (RFONT_DEF_FONT_DEF (rfont_def), font_def)) |
644 break; | 649 break; |
645 font_object = RFONT_DEF_OBJECT (AREF (vec, i)); | 650 font_object = RFONT_DEF_OBJECT (AREF (vec, i)); |
646 if (! NILP (font_object) && font_has_char (f, font_object, c)) | 651 if (! NILP (font_object) && font_has_char (f, font_object, c)) |
647 return rfont_def; | 652 goto found; |
648 } | 653 } |
649 | 654 |
650 /* Find a font-entity with the current spec and supporting C. */ | 655 /* Find a font-entity with the current spec and supporting C. */ |
651 font_entity = font_find_for_lface (f, face->lface, | 656 font_entity = font_find_for_lface (f, face->lface, |
652 FONT_DEF_SPEC (font_def), c); | 657 FONT_DEF_SPEC (font_def), c); |
659 | 664 |
660 font_object = font_open_for_lface (f, font_entity, face->lface, | 665 font_object = font_open_for_lface (f, font_entity, face->lface, |
661 Qnil); | 666 Qnil); |
662 if (NILP (font_object)) | 667 if (NILP (font_object)) |
663 continue; | 668 continue; |
669 found_index = i; | |
664 RFONT_DEF_NEW (rfont_def, font_def); | 670 RFONT_DEF_NEW (rfont_def, font_def); |
665 RFONT_DEF_SET_OBJECT (rfont_def, font_object); | 671 RFONT_DEF_SET_OBJECT (rfont_def, font_object); |
666 RFONT_DEF_SET_SCORE (rfont_def, RFONT_DEF_SCORE (rfont_def)); | 672 RFONT_DEF_SET_SCORE (rfont_def, RFONT_DEF_SCORE (rfont_def)); |
667 new_vec = Fmake_vector (make_number (ASIZE (vec) + 1), Qnil); | 673 new_vec = Fmake_vector (make_number (ASIZE (vec) + 1), Qnil); |
668 for (j = 0; j < i; j++) | 674 for (j = 0; j < i; j++) |
669 ASET (new_vec, j, AREF (vec, j)); | 675 ASET (new_vec, j, AREF (vec, j)); |
670 ASET (new_vec, j, rfont_def); | 676 ASET (new_vec, j, rfont_def); |
677 found_index = j; | |
671 for (j++; j < ASIZE (new_vec); j++) | 678 for (j++; j < ASIZE (new_vec); j++) |
672 ASET (new_vec, j, AREF (vec, j - 1)); | 679 ASET (new_vec, j, AREF (vec, j - 1)); |
673 XSETCDR (font_group, new_vec); | 680 XSETCDR (font_group, new_vec); |
674 return rfont_def; | 681 vec = new_vec; |
682 goto found; | |
675 } | 683 } |
676 | 684 |
677 /* No font of the current spec for C. Try the next spec. */ | 685 /* No font of the current spec for C. Try the next spec. */ |
678 i--; | 686 i--; |
679 } | 687 } |
680 | 688 |
681 FONTSET_SET (fontset, make_number (c), make_number (0)); | 689 FONTSET_SET (fontset, make_number (c), make_number (0)); |
682 return Qnil; | 690 return Qnil; |
691 | |
692 found: | |
693 if (fallback && found_index > 0) | |
694 { | |
695 /* The order of fonts in the fallback font-group is not that | |
696 important, and it is better to move the found font to the | |
697 first of the group so that the next try will find it | |
698 quickly. */ | |
699 for (i = found_index; i > 0; i--) | |
700 ASET (vec, i, AREF (vec, i - 1)); | |
701 ASET (vec, 0, rfont_def); | |
702 } | |
703 return rfont_def; | |
683 } | 704 } |
684 | 705 |
685 | 706 |
686 static Lisp_Object | 707 static Lisp_Object |
687 fontset_font (fontset, c, face, id) | 708 fontset_font (fontset, c, face, id) |