… | |
… | |
8 | #include <SDL_opengl.h> |
8 | #include <SDL_opengl.h> |
9 | |
9 | |
10 | #include <pango/pango.h> |
10 | #include <pango/pango.h> |
11 | #include <pango/pangofc-fontmap.h> |
11 | #include <pango/pangofc-fontmap.h> |
12 | #include <pango/pangoft2.h> |
12 | #include <pango/pangoft2.h> |
|
|
13 | |
|
|
14 | #include <sys/time.h> |
|
|
15 | #include <sys/types.h> |
|
|
16 | #include <unistd.h> |
13 | |
17 | |
14 | #include <sys/types.h> |
18 | #include <sys/types.h> |
15 | #include <sys/socket.h> |
19 | #include <sys/socket.h> |
16 | #include <netinet/in.h> |
20 | #include <netinet/in.h> |
17 | #include <netinet/tcp.h> |
21 | #include <netinet/tcp.h> |
… | |
… | |
23 | PangoLayout *pl; |
27 | PangoLayout *pl; |
24 | int base_height; |
28 | int base_height; |
25 | } *CFClient__Layout; |
29 | } *CFClient__Layout; |
26 | |
30 | |
27 | static void |
31 | static void |
|
|
32 | substitute_func (FcPattern *pattern, gpointer data) |
|
|
33 | { |
|
|
34 | FcPatternAddBool (pattern, FC_HINTING , 1); |
|
|
35 | FcPatternAddBool (pattern, FC_AUTOHINT, 1); |
|
|
36 | } |
|
|
37 | |
|
|
38 | static void |
|
|
39 | layout_update (CFClient__Layout self) |
|
|
40 | { |
|
|
41 | /* use a random scale factor to account for unknown descenders, 0.8 works |
|
|
42 | * reasonably well with bitstream vera |
|
|
43 | */ |
|
|
44 | PangoFontDescription *font = pango_context_get_font_description (context); |
|
|
45 | pango_font_description_set_absolute_size (font, self->base_height * (PANGO_SCALE * 8 / 10)); |
|
|
46 | } |
|
|
47 | |
|
|
48 | static void |
28 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
49 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
29 | { |
50 | { |
30 | PangoFontDescription *font = pango_context_get_font_description (context); |
51 | layout_update (self); |
31 | pango_font_description_set_absolute_size (font, self->base_height * PANGO_SCALE); |
|
|
32 | |
52 | |
33 | pango_layout_get_pixel_size (self->pl, w, h); |
53 | pango_layout_get_pixel_size (self->pl, w, h); |
34 | |
54 | |
35 | *w = (*w + 3) & ~3; |
55 | *w = (*w + 3) & ~3; |
36 | if (!*w) *w = 1; |
56 | if (!*w) *w = 1; |
… | |
… | |
42 | PROTOTYPES: ENABLE |
62 | PROTOTYPES: ENABLE |
43 | |
63 | |
44 | BOOT: |
64 | BOOT: |
45 | { |
65 | { |
46 | fontmap = pango_ft2_font_map_new (); |
66 | fontmap = pango_ft2_font_map_new (); |
|
|
67 | pango_ft2_font_map_set_default_substitute ((PangoFT2FontMap *)fontmap, substitute_func, 0, 0); |
47 | context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap); |
68 | context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap); |
48 | } |
69 | } |
49 | |
70 | |
50 | void |
71 | void |
51 | lowdelay (int fd, int val = 1) |
72 | lowdelay (int fd, int val = 1) |
… | |
… | |
124 | size (CFClient::Layout self) |
145 | size (CFClient::Layout self) |
125 | PPCODE: |
146 | PPCODE: |
126 | { |
147 | { |
127 | int w, h; |
148 | int w, h; |
128 | |
149 | |
|
|
150 | layout_update (self); |
129 | layout_get_pixel_size (self, &w, &h); |
151 | layout_get_pixel_size (self, &w, &h); |
130 | |
152 | |
131 | EXTEND (SP, 2); |
153 | EXTEND (SP, 2); |
132 | PUSHs (sv_2mortal (newSViv (w))); |
154 | PUSHs (sv_2mortal (newSViv (w))); |
133 | PUSHs (sv_2mortal (newSViv (h))); |
155 | PUSHs (sv_2mortal (newSViv (h))); |
134 | } |
156 | } |
135 | |
157 | |
|
|
158 | int |
|
|
159 | xy_to_index (CFClient::Layout self, int x, int y) |
|
|
160 | CODE: |
|
|
161 | { |
|
|
162 | int index, trailing; |
|
|
163 | |
|
|
164 | layout_update (self); |
|
|
165 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
|
|
166 | |
|
|
167 | RETVAL = index; |
|
|
168 | } |
|
|
169 | OUTPUT: |
|
|
170 | RETVAL |
|
|
171 | |
|
|
172 | void |
|
|
173 | cursor_pos (CFClient::Layout self, int index) |
|
|
174 | PPCODE: |
|
|
175 | { |
|
|
176 | PangoRectangle strong_pos; |
|
|
177 | layout_update (self); |
|
|
178 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
|
|
179 | EXTEND (SP, 3); |
|
|
180 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
|
|
181 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
|
|
182 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
|
|
183 | } |
|
|
184 | |
136 | void |
185 | void |
137 | render (CFClient::Layout self) |
186 | render (CFClient::Layout self) |
138 | PPCODE: |
187 | PPCODE: |
139 | { |
188 | { |
140 | SV *retval; |
189 | SV *retval; |
141 | int w, h; |
190 | int w, h; |
142 | FT_Bitmap bitmap; |
191 | FT_Bitmap bitmap; |
143 | |
192 | |
|
|
193 | layout_update (self); |
144 | layout_get_pixel_size (self, &w, &h); |
194 | layout_get_pixel_size (self, &w, &h); |
145 | |
195 | |
146 | retval = newSV (w * h); |
196 | retval = newSV (w * h); |
147 | SvPOK_only (retval); |
197 | SvPOK_only (retval); |
148 | SvCUR_set (retval, w * h); |
198 | SvCUR_set (retval, w * h); |
… | |
… | |
176 | double t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
226 | double t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
177 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
227 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
178 | |
228 | |
179 | if (items < 5) |
229 | if (items < 5) |
180 | { |
230 | { |
181 | w = SvNV (*hv_fetch (hv, "width", 5, 1)); |
231 | w = SvNV (*hv_fetch (hv, "w", 1, 1)); |
182 | h = SvNV (*hv_fetch (hv, "height", 6, 1)); |
232 | h = SvNV (*hv_fetch (hv, "h", 1, 1)); |
183 | } |
233 | } |
184 | |
234 | |
185 | glBindTexture (GL_TEXTURE_2D, name); |
235 | glBindTexture (GL_TEXTURE_2D, name); |
186 | glBegin (GL_QUADS); |
236 | glBegin (GL_QUADS); |
187 | glTexCoord2d (0, 0); glVertex2d (x , y ); |
237 | glTexCoord2d (0, 0); glVertex2d (x , y ); |