… | |
… | |
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 * PANGO_SCALE |
45 | #define MIN_FONT_HEIGHT 8 |
46 | |
46 | |
47 | typedef Mix_Chunk *CFClient__MixChunk; |
47 | typedef Mix_Chunk *CFClient__MixChunk; |
48 | typedef Mix_Music *CFClient__MixMusic; |
48 | typedef Mix_Music *CFClient__MixMusic; |
49 | |
49 | |
50 | static PangoContext *context; |
50 | typedef PangoFontDescription *CFClient__Font; |
51 | static PangoFontMap *fontmap; |
|
|
52 | |
51 | |
53 | typedef struct cf_layout { |
52 | typedef struct cf_layout { |
54 | PangoLayout *pl; |
53 | PangoLayout *pl; |
55 | int base_height; |
54 | int base_height; |
|
|
55 | CFClient__Font font; |
56 | } *CFClient__Layout; |
56 | } *CFClient__Layout; |
|
|
57 | |
|
|
58 | static CFClient__Font default_font; |
|
|
59 | static PangoContext *context; |
|
|
60 | static PangoFontMap *fontmap; |
57 | |
61 | |
58 | static void |
62 | static void |
59 | substitute_func (FcPattern *pattern, gpointer data) |
63 | substitute_func (FcPattern *pattern, gpointer data) |
60 | { |
64 | { |
61 | FcPatternAddBool (pattern, FC_HINTING , 1); |
65 | FcPatternAddBool (pattern, FC_HINTING , 1); |
62 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
66 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
63 | } |
67 | } |
64 | |
68 | |
65 | static void |
69 | static void |
66 | layout_update (CFClient__Layout self) |
70 | layout_update_font (CFClient__Layout self) |
67 | { |
71 | { |
68 | /* 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 |
69 | * reasonably well with bitstream vera |
73 | * reasonably well with bitstream vera |
70 | */ |
74 | */ |
71 | PangoFontDescription *font = pango_layout_get_font_description (self->pl); |
75 | PangoFontDescription *font = self->font ? self->font : default_font; |
72 | |
76 | |
73 | int height = self->base_height * (PANGO_SCALE * 8 / 10); |
|
|
74 | |
|
|
75 | if (height < MIN_FONT_HEIGHT) |
|
|
76 | height = MIN_FONT_HEIGHT; |
|
|
77 | |
|
|
78 | if (pango_font_description_get_size (font) != height) |
|
|
79 | { |
|
|
80 | font = pango_font_description_copy (font); |
|
|
81 | pango_font_description_set_absolute_size (font, height); |
77 | pango_font_description_set_absolute_size (font, |
|
|
78 | MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10)); |
|
|
79 | |
82 | pango_layout_set_font_description (self->pl, font); |
80 | pango_layout_set_font_description (self->pl, font); |
83 | } |
|
|
84 | } |
81 | } |
85 | |
82 | |
86 | static void |
83 | static void |
87 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
84 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
88 | { |
85 | { |
89 | layout_update (self); |
|
|
90 | |
|
|
91 | pango_layout_get_pixel_size (self->pl, w, h); |
86 | pango_layout_get_pixel_size (self->pl, w, h); |
92 | |
87 | |
93 | *w = (*w + 3) & ~3; |
88 | *w = (*w + 3) & ~3; |
94 | if (!*w) *w = 1; |
89 | if (!*w) *w = 1; |
95 | if (!*h) *h = 1; |
90 | if (!*h) *h = 1; |
… | |
… | |
520 | add_font (char *file) |
515 | add_font (char *file) |
521 | CODE: |
516 | CODE: |
522 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ |
517 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ |
523 | |
518 | |
524 | void |
519 | void |
525 | set_font (char *file) |
|
|
526 | CODE: |
|
|
527 | { |
|
|
528 | int count; |
|
|
529 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)file, 0, 0, &count); |
|
|
530 | PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0); |
|
|
531 | FcPatternDestroy (pattern); |
|
|
532 | pango_font_description_set_absolute_size (font, MIN_FONT_HEIGHT); |
|
|
533 | pango_context_set_font_description (context, font); |
|
|
534 | } |
|
|
535 | |
|
|
536 | void |
|
|
537 | load_image_inline (SV *image_) |
520 | load_image_inline (SV *image_) |
538 | ALIAS: |
521 | ALIAS: |
539 | load_image_file = 1 |
522 | load_image_file = 1 |
540 | PPCODE: |
523 | PPCODE: |
541 | { |
524 | { |
… | |
… | |
630 | #else |
613 | #else |
631 | fprintf (stderr, "FATAL: %s\n", message); |
614 | fprintf (stderr, "FATAL: %s\n", message); |
632 | #endif |
615 | #endif |
633 | exit (1); |
616 | exit (1); |
634 | |
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 | |
635 | MODULE = CFClient PACKAGE = CFClient::Layout |
642 | MODULE = CFClient PACKAGE = CFClient::Layout |
636 | |
643 | |
637 | CFClient::Layout |
644 | CFClient::Layout |
638 | new (SV *class, int base_height = 10) |
645 | new (SV *class, int base_height = MIN_FONT_HEIGHT) |
639 | CODE: |
646 | CODE: |
640 | New (0, RETVAL, 1, struct cf_layout); |
647 | New (0, RETVAL, 1, struct cf_layout); |
|
|
648 | RETVAL->pl = pango_layout_new (context); |
641 | RETVAL->base_height = base_height; |
649 | RETVAL->base_height = base_height; |
642 | RETVAL->pl = pango_layout_new (context); |
650 | RETVAL->font = 0; |
643 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
651 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
644 | pango_layout_set_font_description (RETVAL->pl, |
652 | pango_layout_set_font_description (RETVAL->pl, default_font); |
645 | pango_font_description_copy ( |
|
|
646 | pango_context_get_font_description (context))); |
|
|
647 | OUTPUT: |
653 | OUTPUT: |
648 | RETVAL |
654 | RETVAL |
649 | |
655 | |
650 | void |
656 | void |
651 | DESTROY (CFClient::Layout self) |
657 | DESTROY (CFClient::Layout self) |
… | |
… | |
680 | SvUTF8_on (RETVAL); |
686 | SvUTF8_on (RETVAL); |
681 | OUTPUT: |
687 | OUTPUT: |
682 | RETVAL |
688 | RETVAL |
683 | |
689 | |
684 | 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 |
685 | set_height (CFClient::Layout self, int base_height) |
700 | set_height (CFClient::Layout self, int base_height) |
686 | CODE: |
701 | CODE: |
|
|
702 | if (self->base_height != base_height) |
|
|
703 | { |
687 | self->base_height = base_height; |
704 | self->base_height = base_height; |
|
|
705 | layout_update_font (self); |
|
|
706 | } |
688 | |
707 | |
689 | void |
708 | void |
690 | set_width (CFClient::Layout self, int max_width = -1) |
709 | set_width (CFClient::Layout self, int max_width = -1) |
691 | CODE: |
710 | CODE: |
692 | 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); |
… | |
… | |
695 | size (CFClient::Layout self) |
714 | size (CFClient::Layout self) |
696 | PPCODE: |
715 | PPCODE: |
697 | { |
716 | { |
698 | int w, h; |
717 | int w, h; |
699 | |
718 | |
700 | layout_update (self); |
|
|
701 | layout_get_pixel_size (self, &w, &h); |
719 | layout_get_pixel_size (self, &w, &h); |
702 | |
720 | |
703 | EXTEND (SP, 2); |
721 | EXTEND (SP, 2); |
704 | PUSHs (sv_2mortal (newSViv (w))); |
722 | PUSHs (sv_2mortal (newSViv (w))); |
705 | PUSHs (sv_2mortal (newSViv (h))); |
723 | PUSHs (sv_2mortal (newSViv (h))); |
… | |
… | |
708 | int |
726 | int |
709 | xy_to_index (CFClient::Layout self, int x, int y) |
727 | xy_to_index (CFClient::Layout self, int x, int y) |
710 | CODE: |
728 | CODE: |
711 | { |
729 | { |
712 | int index, trailing; |
730 | int index, trailing; |
713 | |
|
|
714 | layout_update (self); |
|
|
715 | 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); |
716 | |
|
|
717 | RETVAL = index; |
732 | RETVAL = index; |
718 | } |
733 | } |
719 | OUTPUT: |
734 | OUTPUT: |
720 | RETVAL |
735 | RETVAL |
721 | |
736 | |
722 | void |
737 | void |
723 | cursor_pos (CFClient::Layout self, int index) |
738 | cursor_pos (CFClient::Layout self, int index) |
724 | PPCODE: |
739 | PPCODE: |
725 | { |
740 | { |
726 | PangoRectangle strong_pos; |
741 | PangoRectangle strong_pos; |
727 | layout_update (self); |
|
|
728 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
742 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
729 | |
743 | |
730 | EXTEND (SP, 3); |
744 | EXTEND (SP, 3); |
731 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
745 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
732 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
746 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
… | |
… | |
739 | { |
753 | { |
740 | SV *retval; |
754 | SV *retval; |
741 | int w, h; |
755 | int w, h; |
742 | FT_Bitmap bitmap; |
756 | FT_Bitmap bitmap; |
743 | |
757 | |
744 | layout_update (self); |
|
|
745 | layout_get_pixel_size (self, &w, &h); |
758 | layout_get_pixel_size (self, &w, &h); |
746 | |
759 | |
747 | retval = newSV (w * h); |
760 | retval = newSV (w * h); |
748 | SvPOK_only (retval); |
761 | SvPOK_only (retval); |
749 | SvCUR_set (retval, w * h); |
762 | SvCUR_set (retval, w * h); |
… | |
… | |
1397 | |
1410 | |
1398 | void glTranslate (float x, float y, float z = 0.) |
1411 | void glTranslate (float x, float y, float z = 0.) |
1399 | CODE: |
1412 | CODE: |
1400 | glTranslatef (x, y, z); |
1413 | glTranslatef (x, y, z); |
1401 | |
1414 | |
1402 | void glScale (float x, float y, float z) |
1415 | void glScale (float x, float y, float z = 1.) |
1403 | CODE: |
1416 | CODE: |
1404 | glScalef (x, y, z); |
1417 | glScalef (x, y, z); |
1405 | |
1418 | |
1406 | void glRotate (float angle, float x, float y, float z) |
1419 | void glRotate (float angle, float x, float y, float z) |
1407 | CODE: |
1420 | CODE: |