… | |
… | |
3 | #include "XSUB.h" |
3 | #include "XSUB.h" |
4 | |
4 | |
5 | #include <string.h> |
5 | #include <string.h> |
6 | |
6 | |
7 | #include <SDL.h> |
7 | #include <SDL.h> |
|
|
8 | #include <SDL_image.h> |
8 | #include <SDL_opengl.h> |
9 | #include <SDL_opengl.h> |
9 | |
10 | |
10 | #include <pango/pango.h> |
11 | #include <pango/pango.h> |
11 | #include <pango/pangofc-fontmap.h> |
12 | #include <pango/pangofc-fontmap.h> |
12 | #include <pango/pangoft2.h> |
13 | #include <pango/pangoft2.h> |
|
|
14 | |
|
|
15 | #include <sys/time.h> |
|
|
16 | #include <sys/types.h> |
|
|
17 | #include <unistd.h> |
13 | |
18 | |
14 | #include <sys/types.h> |
19 | #include <sys/types.h> |
15 | #include <sys/socket.h> |
20 | #include <sys/socket.h> |
16 | #include <netinet/in.h> |
21 | #include <netinet/in.h> |
17 | #include <netinet/tcp.h> |
22 | #include <netinet/tcp.h> |
… | |
… | |
23 | PangoLayout *pl; |
28 | PangoLayout *pl; |
24 | int base_height; |
29 | int base_height; |
25 | } *CFClient__Layout; |
30 | } *CFClient__Layout; |
26 | |
31 | |
27 | static void |
32 | static void |
|
|
33 | substitute_func (FcPattern *pattern, gpointer data) |
|
|
34 | { |
|
|
35 | FcPatternAddBool (pattern, FC_HINTING , 1); |
|
|
36 | FcPatternAddBool (pattern, FC_AUTOHINT, 1); |
|
|
37 | } |
|
|
38 | |
|
|
39 | static void |
28 | layout_update (CFClient__Layout self) |
40 | layout_update (CFClient__Layout self) |
29 | { |
41 | { |
|
|
42 | /* use a random scale factor to account for unknown descenders, 0.8 works |
|
|
43 | * reasonably well with bitstream vera |
|
|
44 | */ |
30 | PangoFontDescription *font = pango_context_get_font_description (context); |
45 | PangoFontDescription *font = pango_context_get_font_description (context); |
31 | pango_font_description_set_absolute_size (font, self->base_height * PANGO_SCALE); |
46 | pango_font_description_set_absolute_size (font, self->base_height * (PANGO_SCALE * 8 / 10)); |
32 | } |
47 | } |
33 | |
48 | |
34 | static void |
49 | static void |
35 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
50 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
36 | { |
51 | { |
37 | PangoFontDescription *font = pango_context_get_font_description (context); |
52 | layout_update (self); |
38 | pango_font_description_set_absolute_size (font, self->base_height * PANGO_SCALE); |
|
|
39 | |
53 | |
40 | pango_layout_get_pixel_size (self->pl, w, h); |
54 | pango_layout_get_pixel_size (self->pl, w, h); |
41 | |
55 | |
42 | *w = (*w + 3) & ~3; |
56 | *w = (*w + 3) & ~3; |
43 | if (!*w) *w = 1; |
57 | if (!*w) *w = 1; |
… | |
… | |
49 | PROTOTYPES: ENABLE |
63 | PROTOTYPES: ENABLE |
50 | |
64 | |
51 | BOOT: |
65 | BOOT: |
52 | { |
66 | { |
53 | fontmap = pango_ft2_font_map_new (); |
67 | fontmap = pango_ft2_font_map_new (); |
|
|
68 | pango_ft2_font_map_set_default_substitute ((PangoFT2FontMap *)fontmap, substitute_func, 0, 0); |
54 | context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap); |
69 | context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap); |
55 | } |
70 | } |
56 | |
71 | |
57 | void |
72 | void |
58 | lowdelay (int fd, int val = 1) |
73 | lowdelay (int fd, int val = 1) |
… | |
… | |
85 | int count; |
100 | int count; |
86 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)file, 0, 0, &count); |
101 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)file, 0, 0, &count); |
87 | PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0); |
102 | PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0); |
88 | FcPatternDestroy (pattern); |
103 | FcPatternDestroy (pattern); |
89 | pango_context_set_font_description (context, font); |
104 | pango_context_set_font_description (context, font); |
|
|
105 | } |
|
|
106 | |
|
|
107 | void |
|
|
108 | load_image_inline (SV *image_) |
|
|
109 | ALIAS: |
|
|
110 | load_image_file = 1 |
|
|
111 | PPCODE: |
|
|
112 | { |
|
|
113 | STRLEN image_len; |
|
|
114 | char *image = (char *)SvPVbyte (image_, image_len); |
|
|
115 | SDL_Surface *surface, *surface2; |
|
|
116 | SDL_PixelFormat fmt; |
|
|
117 | SDL_RWops *rw = ix |
|
|
118 | ? SDL_RWFromFile (image, "r") |
|
|
119 | : SDL_RWFromConstMem (image, image_len); |
|
|
120 | |
|
|
121 | if (!rw) |
|
|
122 | croak ("load_image: unable to open file"); |
|
|
123 | |
|
|
124 | surface = IMG_Load_RW (rw, 1); |
|
|
125 | if (!surface) |
|
|
126 | croak ("load_image: unable to read file"); |
|
|
127 | |
|
|
128 | fmt.palette = NULL; |
|
|
129 | fmt.BitsPerPixel = 32; |
|
|
130 | fmt.BytesPerPixel = 4; |
|
|
131 | fmt.Rmask = 0x000000ff; |
|
|
132 | fmt.Gmask = 0x0000ff00; |
|
|
133 | fmt.Bmask = 0x00ff0000; |
|
|
134 | fmt.Amask = 0xff000000; |
|
|
135 | fmt.Rloss = 0; |
|
|
136 | fmt.Gloss = 0; |
|
|
137 | fmt.Bloss = 0; |
|
|
138 | fmt.Aloss = 0; |
|
|
139 | fmt.Rshift = 0; |
|
|
140 | fmt.Gshift = 8; |
|
|
141 | fmt.Bshift = 16; |
|
|
142 | fmt.Ashift = 24; |
|
|
143 | fmt.colorkey = 0; |
|
|
144 | fmt.alpha = 0; |
|
|
145 | |
|
|
146 | surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); |
|
|
147 | |
|
|
148 | EXTEND (SP, 5); |
|
|
149 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
|
|
150 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
|
|
151 | SDL_LockSurface (surface2); |
|
|
152 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
|
|
153 | SDL_UnlockSurface (surface2); |
|
|
154 | PUSHs (sv_2mortal (newSViv (surface->format->Amask ? GL_RGBA : GL_RGB))); |
|
|
155 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
|
|
156 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_INT_8_8_8_8_REV))); |
|
|
157 | |
|
|
158 | SDL_FreeSurface (surface); |
|
|
159 | SDL_FreeSurface (surface2); |
90 | } |
160 | } |
91 | |
161 | |
92 | MODULE = CFClient PACKAGE = CFClient::Layout |
162 | MODULE = CFClient PACKAGE = CFClient::Layout |
93 | |
163 | |
94 | CFClient::Layout |
164 | CFClient::Layout |
… | |
… | |
212 | double t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
282 | double t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
213 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
283 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
214 | |
284 | |
215 | if (items < 5) |
285 | if (items < 5) |
216 | { |
286 | { |
217 | w = SvNV (*hv_fetch (hv, "width", 5, 1)); |
287 | w = SvNV (*hv_fetch (hv, "w", 1, 1)); |
218 | h = SvNV (*hv_fetch (hv, "height", 6, 1)); |
288 | h = SvNV (*hv_fetch (hv, "h", 1, 1)); |
219 | } |
289 | } |
220 | |
290 | |
221 | glBindTexture (GL_TEXTURE_2D, name); |
291 | glBindTexture (GL_TEXTURE_2D, name); |
222 | glBegin (GL_QUADS); |
292 | glBegin (GL_QUADS); |
223 | glTexCoord2d (0, 0); glVertex2d (x , y ); |
293 | glTexCoord2d (0, 0); glVertex2d (x , y ); |