… | |
… | |
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 | { |
|
|
47 | layout_update (self); |
|
|
48 | |
30 | pango_layout_get_pixel_size (self->pl, w, h); |
49 | pango_layout_get_pixel_size (self->pl, w, h); |
31 | |
50 | |
32 | *w = (*w + 3) & ~3; |
51 | *w = (*w + 3) & ~3; |
33 | if (!*w) *w = 1; |
52 | if (!*w) *w = 1; |
34 | if (!*h) *h = 1; |
53 | if (!*h) *h = 1; |
… | |
… | |
39 | PROTOTYPES: ENABLE |
58 | PROTOTYPES: ENABLE |
40 | |
59 | |
41 | BOOT: |
60 | BOOT: |
42 | { |
61 | { |
43 | 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); |
44 | context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap); |
64 | context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap); |
45 | } |
65 | } |
46 | |
66 | |
47 | void |
67 | void |
48 | lowdelay (int fd, int val = 1) |
68 | lowdelay (int fd, int val = 1) |
… | |
… | |
106 | |
126 | |
107 | pango_layout_set_markup (self->pl, text, textlen); |
127 | pango_layout_set_markup (self->pl, text, textlen); |
108 | } |
128 | } |
109 | |
129 | |
110 | void |
130 | void |
|
|
131 | set_height (CFClient::Layout self, int base_height) |
|
|
132 | CODE: |
|
|
133 | self->base_height = base_height; |
|
|
134 | |
|
|
135 | void |
111 | set_width (CFClient::Layout self, int max_width = -1) |
136 | set_width (CFClient::Layout self, int max_width = -1) |
112 | CODE: |
137 | CODE: |
113 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
138 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
114 | |
139 | |
115 | void |
140 | void |
116 | size (CFClient::Layout self) |
141 | size (CFClient::Layout self) |
117 | PPCODE: |
142 | PPCODE: |
118 | { |
143 | { |
119 | int w, h; |
144 | int w, h; |
120 | |
145 | |
121 | PangoFontDescription *font = pango_context_get_font_description (context); |
146 | layout_update (self); |
122 | pango_font_description_set_absolute_size (font, self->base_height * PANGO_SCALE); |
|
|
123 | |
|
|
124 | layout_get_pixel_size (self, &w, &h); |
147 | layout_get_pixel_size (self, &w, &h); |
125 | |
148 | |
126 | EXTEND (SP, 2); |
149 | EXTEND (SP, 2); |
127 | PUSHs (sv_2mortal (newSViv (w))); |
150 | PUSHs (sv_2mortal (newSViv (w))); |
128 | PUSHs (sv_2mortal (newSViv (h))); |
151 | PUSHs (sv_2mortal (newSViv (h))); |
129 | } |
152 | } |
130 | |
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 | |
131 | void |
181 | void |
132 | render (CFClient::Layout self) |
182 | render (CFClient::Layout self) |
133 | PPCODE: |
183 | PPCODE: |
134 | { |
184 | { |
135 | SV *retval; |
185 | SV *retval; |
136 | int w, h; |
186 | int w, h; |
137 | FT_Bitmap bitmap; |
187 | FT_Bitmap bitmap; |
138 | |
188 | |
|
|
189 | layout_update (self); |
139 | layout_get_pixel_size (self, &w, &h); |
190 | layout_get_pixel_size (self, &w, &h); |
140 | |
191 | |
141 | retval = newSV (w * h); |
192 | retval = newSV (w * h); |
142 | SvPOK_only (retval); |
193 | SvPOK_only (retval); |
143 | SvCUR_set (retval, w * h); |
194 | SvCUR_set (retval, w * h); |
… | |
… | |
171 | double t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
222 | double t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
172 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
223 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
173 | |
224 | |
174 | if (items < 5) |
225 | if (items < 5) |
175 | { |
226 | { |
176 | w = SvNV (*hv_fetch (hv, "width", 5, 1)); |
227 | w = SvNV (*hv_fetch (hv, "w", 1, 1)); |
177 | h = SvNV (*hv_fetch (hv, "height", 6, 1)); |
228 | h = SvNV (*hv_fetch (hv, "h", 1, 1)); |
178 | } |
229 | } |
179 | |
230 | |
180 | glBindTexture (GL_TEXTURE_2D, name); |
231 | glBindTexture (GL_TEXTURE_2D, name); |
181 | glBegin (GL_QUADS); |
232 | glBegin (GL_QUADS); |
182 | glTexCoord2d (0, 0); glVertex2d (x , y ); |
233 | glTexCoord2d (0, 0); glVertex2d (x , y ); |