… | |
… | |
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> |
… | |
… | |
181 | |
185 | |
182 | static void |
186 | static void |
183 | layout_update_font (DC__Layout self) |
187 | layout_update_font (DC__Layout self) |
184 | { |
188 | { |
185 | /* 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 |
186 | * reasonably well with bitstream vera |
190 | * reasonably well with dejavu/bistream fonts |
187 | */ |
191 | */ |
188 | PangoFontDescription *font = self->font ? self->font : default_font; |
192 | PangoFontDescription *font = self->font ? self->font : default_font; |
189 | |
193 | |
190 | pango_font_description_set_absolute_size (font, |
194 | pango_font_description_set_absolute_size (font, |
191 | MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10)); |
195 | MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10)); |
… | |
… | |
669 | CODE: |
673 | CODE: |
670 | { |
674 | { |
671 | opengl_fontmap = pango_opengl_font_map_new (); |
675 | opengl_fontmap = pango_opengl_font_map_new (); |
672 | 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); |
673 | opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); |
677 | opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); |
674 | #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) |
675 | pango_context_set_language (opengl_context, pango_language_from_string ("en")); |
680 | pango_context_set_language (opengl_context, pango_language_from_string ("en")); |
676 | /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/ |
681 | /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/ |
677 | #endif |
682 | #endif |
678 | } |
683 | } |
679 | |
684 | |
… | |
… | |
766 | SDL_GetKeyName (int sym) |
771 | SDL_GetKeyName (int sym) |
767 | |
772 | |
768 | int |
773 | int |
769 | SDL_GetAppState () |
774 | SDL_GetAppState () |
770 | |
775 | |
|
|
776 | int |
|
|
777 | SDL_GetModState () |
|
|
778 | |
771 | void |
779 | void |
772 | poll_events () |
780 | poll_events () |
773 | PPCODE: |
781 | PPCODE: |
774 | { |
782 | { |
775 | SDL_Event ev; |
783 | SDL_Event ev; |
… | |
… | |
908 | } |
916 | } |
909 | } |
917 | } |
910 | #endif |
918 | #endif |
911 | } |
919 | } |
912 | |
920 | |
913 | void |
921 | int |
914 | add_font (char *file) |
922 | add_font (char *file) |
915 | CODE: |
923 | CODE: |
916 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
924 | RETVAL = FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
|
|
925 | OUTPUT: |
|
|
926 | RETVAL |
917 | |
927 | |
918 | void |
928 | void |
919 | load_image_inline (SV *image_) |
929 | load_image_inline (SV *image_) |
920 | ALIAS: |
930 | ALIAS: |
921 | load_image_file = 1 |
931 | load_image_file = 1 |
… | |
… | |
1331 | PPCODE: |
1341 | PPCODE: |
1332 | { |
1342 | { |
1333 | int line, x; |
1343 | int line, x; |
1334 | |
1344 | |
1335 | 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); |
1336 | #if !(defined (PANGO_VERSION_CHECK) && PANGO_VERSION_CHECK (1, 17, 3)) |
1346 | #if !PANGO_VERSION_CHECK (1, 17, 3) |
1337 | /* pango bug: line is between 1..numlines, not 0..numlines-1 */ |
1347 | /* pango bug: line is between 1..numlines, not 0..numlines-1 */ |
1338 | --line; |
1348 | --line; |
1339 | #endif |
1349 | #endif |
1340 | EXTEND (SP, 2); |
1350 | EXTEND (SP, 2); |
1341 | PUSHs (sv_2mortal (newSViv (line))); |
1351 | PUSHs (sv_2mortal (newSViv (line))); |
… | |
… | |
2282 | else |
2292 | else |
2283 | *data++ = 0; |
2293 | *data++ = 0; |
2284 | } |
2294 | } |
2285 | } |
2295 | } |
2286 | |
2296 | |
|
|
2297 | /* if size is w*h + 5 then no data has been found */ |
|
|
2298 | if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) |
|
|
2299 | { |
2287 | SvPOK_only (data_sv); |
2300 | SvPOK_only (data_sv); |
2288 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
2301 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
|
|
2302 | } |
|
|
2303 | |
2289 | RETVAL = data_sv; |
2304 | RETVAL = data_sv; |
2290 | } |
2305 | } |
2291 | OUTPUT: |
2306 | OUTPUT: |
2292 | RETVAL |
2307 | RETVAL |
2293 | |
2308 | |
2294 | void |
2309 | void |
2295 | set_rect (DC::Map self, int x0, int y0, uint8_t *data) |
2310 | set_rect (DC::Map self, int x0, int y0, SV *data_sv) |
2296 | PPCODE: |
2311 | PPCODE: |
2297 | { |
2312 | { |
2298 | int x, y, z; |
2313 | int x, y, z; |
2299 | int w, h; |
2314 | int w, h; |
2300 | int x1, y1; |
2315 | int x1, y1; |
|
|
2316 | STRLEN len; |
|
|
2317 | uint8_t *data, *end; |
|
|
2318 | |
|
|
2319 | len = SvLEN (data_sv); |
|
|
2320 | SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more |
|
|
2321 | data = SvPVbyte_nolen (data_sv); |
|
|
2322 | end = data + len + 8; |
|
|
2323 | |
|
|
2324 | if (len < 5) |
|
|
2325 | XSRETURN_EMPTY; |
2301 | |
2326 | |
2302 | if (*data++ != 0) |
2327 | if (*data++ != 0) |
2303 | XSRETURN_EMPTY; /* version mismatch */ |
2328 | XSRETURN_EMPTY; /* version mismatch */ |
2304 | |
2329 | |
2305 | w = *data++ << 8; w |= *data++; |
2330 | w = *data++ << 8; w |= *data++; |
… | |
… | |
2320 | { |
2345 | { |
2321 | maprow *row = map_get_row (self, y); |
2346 | maprow *row = map_get_row (self, y); |
2322 | |
2347 | |
2323 | for (x = x0; x < x1; x++) |
2348 | for (x = x0; x < x1; x++) |
2324 | { |
2349 | { |
|
|
2350 | uint8_t flags; |
|
|
2351 | |
|
|
2352 | if (data + 7 >= end) |
|
|
2353 | XSRETURN_EMPTY; |
|
|
2354 | |
2325 | uint8_t flags = *data++; |
2355 | flags = *data++; |
2326 | |
2356 | |
2327 | if (flags) |
2357 | if (flags) |
2328 | { |
2358 | { |
2329 | mapcell *cell = row_get_cell (row, x); |
2359 | mapcell *cell = row_get_cell (row, x); |
2330 | tileid tile[3] = { 0, 0, 0 }; |
2360 | tileid tile[3] = { 0, 0, 0 }; |
… | |
… | |
2333 | if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; } |
2363 | if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; } |
2334 | if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; } |
2364 | if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; } |
2335 | |
2365 | |
2336 | if (cell->darkness == 0) |
2366 | if (cell->darkness == 0) |
2337 | { |
2367 | { |
2338 | cell->darkness = 0; |
2368 | /*cell->darkness = 0;*/ |
|
|
2369 | EXTEND (SP, 3); |
2339 | |
2370 | |
2340 | for (z = 0; z <= 2; z++) |
2371 | for (z = 0; z <= 2; z++) |
2341 | { |
2372 | { |
2342 | tileid t = tile [z]; |
2373 | tileid t = tile [z]; |
2343 | |
2374 | |
2344 | if (t >= self->texs || (t && !self->tex [t].name)) |
2375 | if (t >= self->texs || (t && !self->tex [t].name)) |
2345 | { |
2376 | { |
2346 | XPUSHs (sv_2mortal (newSViv (t))); |
2377 | PUSHs (sv_2mortal (newSViv (t))); |
2347 | need_texid (self, t); |
2378 | need_texid (self, t); |
2348 | } |
2379 | } |
2349 | |
2380 | |
2350 | cell->tile [z] = t; |
2381 | cell->tile [z] = t; |
2351 | } |
2382 | } |