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