… | |
… | |
40 | #define FOW_DARKNESS 32 |
40 | #define FOW_DARKNESS 32 |
41 | |
41 | |
42 | #define MAP_EXTEND_X 32 |
42 | #define MAP_EXTEND_X 32 |
43 | #define MAP_EXTEND_Y 512 |
43 | #define MAP_EXTEND_Y 512 |
44 | |
44 | |
|
|
45 | #define MIN_FONT_HEIGHT 8 |
|
|
46 | |
45 | typedef Mix_Chunk *CFClient__MixChunk; |
47 | typedef Mix_Chunk *CFClient__MixChunk; |
46 | typedef Mix_Music *CFClient__MixMusic; |
48 | typedef Mix_Music *CFClient__MixMusic; |
47 | |
49 | |
48 | static PangoContext *context; |
50 | typedef PangoFontDescription *CFClient__Font; |
49 | static PangoFontMap *fontmap; |
|
|
50 | |
51 | |
51 | typedef struct cf_layout { |
52 | typedef struct cf_layout { |
52 | PangoLayout *pl; |
53 | PangoLayout *pl; |
53 | int base_height; |
54 | int base_height; |
|
|
55 | CFClient__Font font; |
54 | } *CFClient__Layout; |
56 | } *CFClient__Layout; |
|
|
57 | |
|
|
58 | static CFClient__Font default_font; |
|
|
59 | static PangoContext *context; |
|
|
60 | static PangoFontMap *fontmap; |
55 | |
61 | |
56 | static void |
62 | static void |
57 | substitute_func (FcPattern *pattern, gpointer data) |
63 | substitute_func (FcPattern *pattern, gpointer data) |
58 | { |
64 | { |
59 | FcPatternAddBool (pattern, FC_HINTING , 1); |
65 | FcPatternAddBool (pattern, FC_HINTING , 1); |
60 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
66 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
61 | } |
67 | } |
62 | |
68 | |
63 | static void |
69 | static void |
64 | layout_update (CFClient__Layout self) |
70 | layout_update_font (CFClient__Layout self) |
65 | { |
71 | { |
66 | /* use a random scale factor to account for unknown descenders, 0.8 works |
72 | /* use a random scale factor to account for unknown descenders, 0.8 works |
67 | * reasonably well with bitstream vera |
73 | * reasonably well with bitstream vera |
68 | */ |
74 | */ |
69 | PangoFontDescription *font = pango_context_get_font_description (context); |
75 | PangoFontDescription *font = self->font ? self->font : default_font; |
70 | |
76 | |
71 | int height = self->base_height * (PANGO_SCALE * 8 / 10); |
|
|
72 | |
|
|
73 | if (pango_font_description_get_size (font) != height) |
|
|
74 | { |
|
|
75 | pango_font_description_set_absolute_size (font, height); |
77 | pango_font_description_set_absolute_size (font, |
76 | pango_layout_context_changed (self->pl); |
78 | MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10)); |
77 | } |
79 | |
|
|
80 | pango_layout_set_font_description (self->pl, font); |
78 | } |
81 | } |
79 | |
82 | |
80 | static void |
83 | static void |
81 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
84 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
82 | { |
85 | { |
83 | layout_update (self); |
|
|
84 | |
|
|
85 | pango_layout_get_pixel_size (self->pl, w, h); |
86 | pango_layout_get_pixel_size (self->pl, w, h); |
86 | |
87 | |
87 | *w = (*w + 3) & ~3; |
88 | *w = (*w + 3) & ~3; |
88 | if (!*w) *w = 1; |
89 | if (!*w) *w = 1; |
89 | if (!*h) *h = 1; |
90 | if (!*h) *h = 1; |
… | |
… | |
514 | add_font (char *file) |
515 | add_font (char *file) |
515 | CODE: |
516 | CODE: |
516 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ |
517 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ |
517 | |
518 | |
518 | void |
519 | void |
519 | set_font (char *file) |
|
|
520 | CODE: |
|
|
521 | { |
|
|
522 | int count; |
|
|
523 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)file, 0, 0, &count); |
|
|
524 | PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0); |
|
|
525 | FcPatternDestroy (pattern); |
|
|
526 | pango_context_set_font_description (context, font); |
|
|
527 | } |
|
|
528 | |
|
|
529 | void |
|
|
530 | load_image_inline (SV *image_) |
520 | load_image_inline (SV *image_) |
531 | ALIAS: |
521 | ALIAS: |
532 | load_image_file = 1 |
522 | load_image_file = 1 |
533 | PPCODE: |
523 | PPCODE: |
534 | { |
524 | { |
… | |
… | |
623 | #else |
613 | #else |
624 | fprintf (stderr, "FATAL: %s\n", message); |
614 | fprintf (stderr, "FATAL: %s\n", message); |
625 | #endif |
615 | #endif |
626 | exit (1); |
616 | exit (1); |
627 | |
617 | |
|
|
618 | MODULE = CFClient PACKAGE = CFClient::Font |
|
|
619 | |
|
|
620 | CFClient::Font |
|
|
621 | new_from_file (SV *class, char *path) |
|
|
622 | CODE: |
|
|
623 | { |
|
|
624 | int count; |
|
|
625 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, 0, 0, &count); |
|
|
626 | RETVAL = pango_fc_font_description_from_pattern (pattern, 0); |
|
|
627 | FcPatternDestroy (pattern); |
|
|
628 | } |
|
|
629 | OUTPUT: |
|
|
630 | RETVAL |
|
|
631 | |
|
|
632 | void |
|
|
633 | DESTROY (CFClient::Font self) |
|
|
634 | CODE: |
|
|
635 | pango_font_description_free (self); |
|
|
636 | |
|
|
637 | void |
|
|
638 | make_default (CFClient::Font self) |
|
|
639 | CODE: |
|
|
640 | default_font = self; |
|
|
641 | |
628 | MODULE = CFClient PACKAGE = CFClient::Layout |
642 | MODULE = CFClient PACKAGE = CFClient::Layout |
629 | |
643 | |
630 | CFClient::Layout |
644 | CFClient::Layout |
631 | new (SV *class, int base_height = 10) |
645 | new (SV *class, int base_height = MIN_FONT_HEIGHT) |
632 | CODE: |
646 | CODE: |
633 | New (0, RETVAL, 1, struct cf_layout); |
647 | New (0, RETVAL, 1, struct cf_layout); |
|
|
648 | RETVAL->pl = pango_layout_new (context); |
634 | RETVAL->base_height = base_height; |
649 | RETVAL->base_height = base_height; |
635 | RETVAL->pl = pango_layout_new (context); |
650 | RETVAL->font = 0; |
636 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
651 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
|
|
652 | pango_layout_set_font_description (RETVAL->pl, default_font); |
637 | OUTPUT: |
653 | OUTPUT: |
638 | RETVAL |
654 | RETVAL |
639 | |
655 | |
640 | void |
656 | void |
641 | DESTROY (CFClient::Layout self) |
657 | DESTROY (CFClient::Layout self) |
… | |
… | |
670 | SvUTF8_on (RETVAL); |
686 | SvUTF8_on (RETVAL); |
671 | OUTPUT: |
687 | OUTPUT: |
672 | RETVAL |
688 | RETVAL |
673 | |
689 | |
674 | void |
690 | void |
|
|
691 | set_font (CFClient::Layout self, CFClient::Font font = 0) |
|
|
692 | CODE: |
|
|
693 | if (self->font != font) |
|
|
694 | { |
|
|
695 | self->font = font; |
|
|
696 | layout_update_font (self); |
|
|
697 | } |
|
|
698 | |
|
|
699 | void |
675 | set_height (CFClient::Layout self, int base_height) |
700 | set_height (CFClient::Layout self, int base_height) |
676 | CODE: |
701 | CODE: |
|
|
702 | if (self->base_height != base_height) |
|
|
703 | { |
677 | self->base_height = base_height; |
704 | self->base_height = base_height; |
|
|
705 | layout_update_font (self); |
|
|
706 | } |
678 | |
707 | |
679 | void |
708 | void |
680 | set_width (CFClient::Layout self, int max_width = -1) |
709 | set_width (CFClient::Layout self, int max_width = -1) |
681 | CODE: |
710 | CODE: |
682 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
711 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
… | |
… | |
685 | size (CFClient::Layout self) |
714 | size (CFClient::Layout self) |
686 | PPCODE: |
715 | PPCODE: |
687 | { |
716 | { |
688 | int w, h; |
717 | int w, h; |
689 | |
718 | |
690 | layout_update (self); |
|
|
691 | layout_get_pixel_size (self, &w, &h); |
719 | layout_get_pixel_size (self, &w, &h); |
692 | |
720 | |
693 | EXTEND (SP, 2); |
721 | EXTEND (SP, 2); |
694 | PUSHs (sv_2mortal (newSViv (w))); |
722 | PUSHs (sv_2mortal (newSViv (w))); |
695 | PUSHs (sv_2mortal (newSViv (h))); |
723 | PUSHs (sv_2mortal (newSViv (h))); |
… | |
… | |
698 | int |
726 | int |
699 | xy_to_index (CFClient::Layout self, int x, int y) |
727 | xy_to_index (CFClient::Layout self, int x, int y) |
700 | CODE: |
728 | CODE: |
701 | { |
729 | { |
702 | int index, trailing; |
730 | int index, trailing; |
703 | |
|
|
704 | layout_update (self); |
|
|
705 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
731 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
706 | |
|
|
707 | RETVAL = index; |
732 | RETVAL = index; |
708 | } |
733 | } |
709 | OUTPUT: |
734 | OUTPUT: |
710 | RETVAL |
735 | RETVAL |
711 | |
736 | |
712 | void |
737 | void |
713 | cursor_pos (CFClient::Layout self, int index) |
738 | cursor_pos (CFClient::Layout self, int index) |
714 | PPCODE: |
739 | PPCODE: |
715 | { |
740 | { |
716 | PangoRectangle strong_pos; |
741 | PangoRectangle strong_pos; |
717 | layout_update (self); |
|
|
718 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
742 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
719 | |
743 | |
720 | EXTEND (SP, 3); |
744 | EXTEND (SP, 3); |
721 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
745 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
722 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
746 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
… | |
… | |
729 | { |
753 | { |
730 | SV *retval; |
754 | SV *retval; |
731 | int w, h; |
755 | int w, h; |
732 | FT_Bitmap bitmap; |
756 | FT_Bitmap bitmap; |
733 | |
757 | |
734 | layout_update (self); |
|
|
735 | layout_get_pixel_size (self, &w, &h); |
758 | layout_get_pixel_size (self, &w, &h); |
736 | |
759 | |
737 | retval = newSV (w * h); |
760 | retval = newSV (w * h); |
738 | SvPOK_only (retval); |
761 | SvPOK_only (retval); |
739 | SvCUR_set (retval, w * h); |
762 | SvCUR_set (retval, w * h); |