… | |
… | |
46 | |
46 | |
47 | #include <glib/gmacros.h> |
47 | #include <glib/gmacros.h> |
48 | |
48 | |
49 | #include <pango/pango.h> |
49 | #include <pango/pango.h> |
50 | |
50 | |
51 | #if !(defined (PANGO_VERSION_CHECK) && PANGO_VERSION_CHECK (1, 15, 2)) |
51 | #ifndef PANGO_VERSION_CHECK |
|
|
52 | # define PANGO_VERSION_CHECK(a,b,c) 0 |
|
|
53 | #endif |
|
|
54 | |
|
|
55 | #if !PANGO_VERSION_CHECK (1, 15, 2) |
52 | # define pango_layout_get_line_readonly pango_layout_get_line_readonly |
56 | # define pango_layout_get_line_readonly pango_layout_get_line |
53 | # define pango_layout_get_lines_readonly pango_layout_get_lines_readonly |
57 | # define pango_layout_get_lines_readonly pango_layout_get_lines |
54 | # define pango_layout_iter_get_line_readonly pango_layout_iter_get_line_readonly |
58 | # define pango_layout_iter_get_line_readonly pango_layout_iter_get_line |
55 | # define pango_layout_iter_get_run_readonly pango_layout_iter_get_run_readonly |
59 | # define pango_layout_iter_get_run_readonly pango_layout_iter_get_run |
56 | #endif |
60 | #endif |
57 | |
61 | |
58 | #ifndef _WIN32 |
62 | #ifndef _WIN32 |
59 | # include <sys/types.h> |
63 | # include <sys/types.h> |
60 | # include <sys/socket.h> |
64 | # include <sys/socket.h> |
… | |
… | |
70 | #define MAP_EXTEND_X 32 |
74 | #define MAP_EXTEND_X 32 |
71 | #define MAP_EXTEND_Y 512 |
75 | #define MAP_EXTEND_Y 512 |
72 | |
76 | |
73 | #define MIN_FONT_HEIGHT 10 |
77 | #define MIN_FONT_HEIGHT 10 |
74 | |
78 | |
|
|
79 | /* mask out modifiers we are not interested in */ |
|
|
80 | #define MOD_MASK (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_META) |
|
|
81 | |
75 | #if 0 |
82 | #if 0 |
76 | # define PARACHUTE SDL_INIT_NOPARACHUTE |
83 | # define PARACHUTE SDL_INIT_NOPARACHUTE |
77 | #else |
84 | #else |
78 | # define PARACHUTE 0 |
85 | # define PARACHUTE 0 |
79 | #endif |
86 | #endif |
… | |
… | |
178 | |
185 | |
179 | static void |
186 | static void |
180 | layout_update_font (DC__Layout self) |
187 | layout_update_font (DC__Layout self) |
181 | { |
188 | { |
182 | /* use a random scale factor to account for unknown descenders, 0.8 works |
189 | /* use a random scale factor to account for unknown descenders, 0.8 works |
183 | * reasonably well with bitstream vera |
190 | * reasonably well with dejavu/bistream fonts |
184 | */ |
191 | */ |
185 | PangoFontDescription *font = self->font ? self->font : default_font; |
192 | PangoFontDescription *font = self->font ? self->font : default_font; |
186 | |
193 | |
187 | pango_font_description_set_absolute_size (font, |
194 | pango_font_description_set_absolute_size (font, |
188 | MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10)); |
195 | MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10)); |
… | |
… | |
666 | CODE: |
673 | CODE: |
667 | { |
674 | { |
668 | opengl_fontmap = pango_opengl_font_map_new (); |
675 | opengl_fontmap = pango_opengl_font_map_new (); |
669 | pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); |
676 | pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); |
670 | opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); |
677 | opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); |
671 | #if defined (PANGO_VERSION_CHECK) && PANGO_VERSION_CHECK (1, 15, 2) |
678 | /*pango_context_set_font_description (opengl_context, default_font);*/ |
|
|
679 | #if PANGO_VERSION_CHECK (1, 15, 2) |
672 | pango_context_set_language (opengl_context, pango_language_from_string ("en")); |
680 | pango_context_set_language (opengl_context, pango_language_from_string ("en")); |
673 | pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR); |
681 | /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/ |
674 | #endif |
682 | #endif |
675 | } |
683 | } |
676 | |
684 | |
677 | char * |
685 | char * |
678 | SDL_GetError () |
686 | SDL_GetError () |
… | |
… | |
763 | SDL_GetKeyName (int sym) |
771 | SDL_GetKeyName (int sym) |
764 | |
772 | |
765 | int |
773 | int |
766 | SDL_GetAppState () |
774 | SDL_GetAppState () |
767 | |
775 | |
|
|
776 | int |
|
|
777 | SDL_GetModState () |
|
|
778 | |
768 | void |
779 | void |
769 | poll_events () |
780 | poll_events () |
770 | PPCODE: |
781 | PPCODE: |
771 | { |
782 | { |
772 | SDL_Event ev; |
783 | SDL_Event ev; |
… | |
… | |
781 | { |
792 | { |
782 | case SDL_KEYDOWN: |
793 | case SDL_KEYDOWN: |
783 | case SDL_KEYUP: |
794 | case SDL_KEYUP: |
784 | hv_store (hv, "state", 5, newSViv (ev.key.state), 0); |
795 | hv_store (hv, "state", 5, newSViv (ev.key.state), 0); |
785 | hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); |
796 | hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); |
786 | hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0); |
797 | hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod & MOD_MASK), 0); |
787 | hv_store (hv, "cmod", 4, newSViv (SDL_GetModState ()), 0); /* current mode */ |
798 | hv_store (hv, "cmod", 4, newSViv (SDL_GetModState () & MOD_MASK), 0); /* current mode */ |
788 | hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); |
799 | hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); |
789 | break; |
800 | break; |
790 | |
801 | |
791 | case SDL_ACTIVEEVENT: |
802 | case SDL_ACTIVEEVENT: |
792 | hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); |
803 | hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); |
… | |
… | |
810 | x = ev.motion.x; |
821 | x = ev.motion.x; |
811 | y = ev.motion.y; |
822 | y = ev.motion.y; |
812 | SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); |
823 | SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); |
813 | } |
824 | } |
814 | |
825 | |
815 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); |
826 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0); |
816 | hv_store (hv, "state", 5, newSViv (state), 0); |
827 | hv_store (hv, "state", 5, newSViv (state), 0); |
817 | hv_store (hv, "x", 1, newSViv (x), 0); |
828 | hv_store (hv, "x", 1, newSViv (x), 0); |
818 | hv_store (hv, "y", 1, newSViv (y), 0); |
829 | hv_store (hv, "y", 1, newSViv (y), 0); |
819 | hv_store (hv, "xrel", 4, newSViv (xrel), 0); |
830 | hv_store (hv, "xrel", 4, newSViv (xrel), 0); |
820 | hv_store (hv, "yrel", 4, newSViv (yrel), 0); |
831 | hv_store (hv, "yrel", 4, newSViv (yrel), 0); |
821 | } |
832 | } |
822 | break; |
833 | break; |
823 | |
834 | |
824 | case SDL_MOUSEBUTTONDOWN: |
835 | case SDL_MOUSEBUTTONDOWN: |
825 | case SDL_MOUSEBUTTONUP: |
836 | case SDL_MOUSEBUTTONUP: |
826 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); |
837 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0); |
827 | |
838 | |
828 | hv_store (hv, "button", 6, newSViv (ev.button.button), 0); |
839 | hv_store (hv, "button", 6, newSViv (ev.button.button), 0); |
829 | hv_store (hv, "state", 5, newSViv (ev.button.state), 0); |
840 | hv_store (hv, "state", 5, newSViv (ev.button.state), 0); |
830 | hv_store (hv, "x", 1, newSViv (ev.button.x), 0); |
841 | hv_store (hv, "x", 1, newSViv (ev.button.x), 0); |
831 | hv_store (hv, "y", 1, newSViv (ev.button.y), 0); |
842 | hv_store (hv, "y", 1, newSViv (ev.button.y), 0); |
… | |
… | |
905 | } |
916 | } |
906 | } |
917 | } |
907 | #endif |
918 | #endif |
908 | } |
919 | } |
909 | |
920 | |
910 | void |
921 | int |
911 | add_font (char *file) |
922 | add_font (char *file) |
912 | CODE: |
923 | CODE: |
913 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
924 | RETVAL = FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
|
|
925 | OUTPUT: |
|
|
926 | RETVAL |
914 | |
927 | |
915 | void |
928 | void |
916 | load_image_inline (SV *image_) |
929 | load_image_inline (SV *image_) |
917 | ALIAS: |
930 | ALIAS: |
918 | load_image_file = 1 |
931 | load_image_file = 1 |
… | |
… | |
1312 | |
1325 | |
1313 | void |
1326 | void |
1314 | cursor_pos (DC::Layout self, int index) |
1327 | cursor_pos (DC::Layout self, int index) |
1315 | PPCODE: |
1328 | PPCODE: |
1316 | { |
1329 | { |
1317 | PangoRectangle strong_pos; |
1330 | PangoRectangle pos; |
1318 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
1331 | pango_layout_get_cursor_pos (self->pl, index, &pos, 0); |
1319 | |
1332 | |
1320 | EXTEND (SP, 3); |
1333 | EXTEND (SP, 3); |
1321 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
1334 | PUSHs (sv_2mortal (newSViv (pos.x / PANGO_SCALE))); |
1322 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1335 | PUSHs (sv_2mortal (newSViv (pos.y / PANGO_SCALE))); |
1323 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1336 | PUSHs (sv_2mortal (newSViv (pos.height / PANGO_SCALE))); |
1324 | } |
1337 | } |
1325 | |
1338 | |
1326 | void |
1339 | void |
1327 | index_to_line_x (DC::Layout self, int index, int trailing = 0) |
1340 | index_to_line_x (DC::Layout self, int index, int trailing = 0) |
1328 | PPCODE: |
1341 | PPCODE: |
1329 | { |
1342 | { |
1330 | int line, x; |
1343 | int line, x; |
1331 | |
1344 | |
1332 | pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); |
1345 | pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); |
1333 | #if !(defined (PANGO_VERSION_CHECK) && PANGO_VERSION_CHECK (1, 17, 3)) |
1346 | #if !PANGO_VERSION_CHECK (1, 17, 3) |
1334 | /* pango bug: line is between 1..numlines, not 0..numlines-1 */ |
1347 | /* pango bug: line is between 1..numlines, not 0..numlines-1 */ |
1335 | --line; |
1348 | --line; |
1336 | #endif |
1349 | #endif |
1337 | EXTEND (SP, 2); |
1350 | EXTEND (SP, 2); |
1338 | PUSHs (sv_2mortal (newSViv (line))); |
1351 | PUSHs (sv_2mortal (newSViv (line))); |