… | |
… | |
168 | XSetForeground (DISPLAY, GC, r->PixColors[color]); |
168 | XSetForeground (DISPLAY, GC, r->PixColors[color]); |
169 | XFillRectangle (DISPLAY, DRAWABLE, GC, x, y, w, h); |
169 | XFillRectangle (DISPLAY, DRAWABLE, GC, x, y, w, h); |
170 | } |
170 | } |
171 | } |
171 | } |
172 | |
172 | |
|
|
173 | static const char *linedraw_cmds[128] = { |
|
|
174 | "1hH", "2hH", "1vV", "2vV", |
|
|
175 | 0, 0, 0, 0, |
|
|
176 | 0, 0, 0, 0, |
|
|
177 | "1HV", "2H1V", "1H2V", "2HV", |
|
|
178 | |
|
|
179 | // 2510 |
|
|
180 | "1hV", "2h1V", "1h2V", "2hV", |
|
|
181 | "1Hv", "2H1v", "1H2v", "2Hv", |
|
|
182 | "1hv", "2h1v", "1h2v", "2hv", |
|
|
183 | "1HvV", "2H1vV", "1HV2v", "1Hv2V", |
|
|
184 | |
|
|
185 | // 2520 |
|
|
186 | "1H2vV", "2Hv1V", "2HV1v", "2HvV", |
|
|
187 | "1hvV", "2h1vV", "1hV2v", "1hv2V", |
|
|
188 | "1h2vV", "2hv1V", "1v2hV", "2hvV", |
|
|
189 | "1hHV", "2h1HV", "2H1hV", "2hH1V", |
|
|
190 | |
|
|
191 | // 2530 |
|
|
192 | "1hH2V", "2hV1H", "1h2HV", "2hHV", |
|
|
193 | "1hHv", "1vH2h", "1hv2H", "1v2hH", |
|
|
194 | "1hH2v", "1H2hv", "1h2Hv", "2hHv", |
|
|
195 | "1hHvV", "1vVH2h", "1hvV2H", "1vV2hH", |
|
|
196 | |
|
|
197 | // 2540 |
|
|
198 | "1hHV2v", "1hHv2V", "1hH2vV", "1HV2hv", |
|
|
199 | "1hV2Hv", "1Hv2hV", "1hv2HV", "1V2hHv", |
|
|
200 | "1v2hHV", "1H2hvV", "1h2HvV", "2hHvV", |
|
|
201 | 0, 0, 0, 0, |
|
|
202 | |
|
|
203 | // 2550 |
|
|
204 | 0, 0, 0, 0, |
|
|
205 | 0, 0, 0, 0, |
|
|
206 | 0, 0, 0, 0, |
|
|
207 | 0, 0, 0, 0, |
|
|
208 | |
|
|
209 | // 2560 |
|
|
210 | 0, 0, 0, 0, |
|
|
211 | 0, 0, 0, 0, |
|
|
212 | 0, 0, 0, 0, |
|
|
213 | 0, 0, 0, 0, |
|
|
214 | |
|
|
215 | // 2570 |
|
|
216 | 0, "1a", "1b", "1ab", |
|
|
217 | "1h", "1v", "1H", "1V", |
|
|
218 | "2h", "2v", "2H", "2V", |
|
|
219 | "1h2H", "1v2V", "1H2h", "1V2v" |
|
|
220 | |
|
|
221 | // to be done |
|
|
222 | }; |
|
|
223 | |
173 | struct rxvt_font_default : rxvt_font { |
224 | struct rxvt_font_default : rxvt_font { |
174 | bool load (int maxheight) |
225 | bool load (int maxheight) |
175 | { |
226 | { |
176 | width = 1; height = 1; |
227 | width = 1; height = 1; |
177 | ascent = 1; descent = 0; |
228 | ascent = 1; descent = 0; |
… | |
… | |
179 | return true; |
230 | return true; |
180 | } |
231 | } |
181 | |
232 | |
182 | bool has_codepoint (uint32_t unicode) |
233 | bool has_codepoint (uint32_t unicode) |
183 | { |
234 | { |
184 | if (unicode <= 0x001f |
235 | if (unicode <= 0x001f) |
|
|
236 | return true; |
185 | || (unicode >= 0x80 && unicode <= 0x9f)) |
237 | if (unicode >= 0x0080 && unicode <= 0x009f) |
|
|
238 | return true; |
|
|
239 | |
|
|
240 | if (unicode >= 0x2500 && unicode <= 0x257f |
|
|
241 | && linedraw_cmds[unicode - 0x2500]) |
186 | return true; |
242 | return true; |
187 | |
243 | |
188 | switch (unicode) |
244 | switch (unicode) |
189 | { |
245 | { |
190 | case ZERO_WIDTH_CHAR: |
246 | case ZERO_WIDTH_CHAR: |
… | |
… | |
204 | const text_t *text, int len, |
260 | const text_t *text, int len, |
205 | int fg, int bg) |
261 | int fg, int bg) |
206 | { |
262 | { |
207 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
263 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
208 | |
264 | |
|
|
265 | XSetForeground (DISPLAY, GC, r->PixColors[fg]); |
|
|
266 | |
209 | while (len--) |
267 | while (len--) |
210 | { |
268 | { |
|
|
269 | text_t t = *text++; |
|
|
270 | |
|
|
271 | if (t >= 0x2500 & t <= 0x2580 && linedraw_cmds[t - 0x2500]) |
|
|
272 | { |
|
|
273 | const char *p = linedraw_cmds[t - 0x2500]; |
|
|
274 | |
|
|
275 | int x0 = x, x1 = x + r->TermWin.fwidth / 2, x2 = x + r->TermWin.fwidth ; |
|
|
276 | int y0 = y, y1 = y + r->TermWin.fheight / 2, y2 = y + r->TermWin.fheight; |
|
|
277 | |
|
|
278 | XGCValues gcv; |
|
|
279 | |
|
|
280 | while (*p) |
|
|
281 | { |
|
|
282 | switch (*p++) |
|
|
283 | { |
|
|
284 | case '1': |
|
|
285 | gcv.line_width = 0; |
|
|
286 | XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
|
|
287 | break; |
|
|
288 | |
|
|
289 | case '2': |
|
|
290 | gcv.line_width = 2; |
|
|
291 | XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
|
|
292 | break; |
|
|
293 | |
|
|
294 | case 'h': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y1, x1, y1); break; |
|
|
295 | case 'H': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y1, x2, y1); break; |
|
|
296 | case 'v': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y0, x1, y1); break; |
|
|
297 | case 'V': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y1, x1, y2); break; |
|
|
298 | case 'a': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y2, x2, y0); break; |
|
|
299 | case 'b': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y0, x2, y2); break; |
|
|
300 | } |
|
|
301 | } |
|
|
302 | |
|
|
303 | gcv.line_width = 0; |
|
|
304 | XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
|
|
305 | } |
|
|
306 | else |
211 | switch (*text++) |
307 | switch (*text++) |
212 | { |
308 | { |
213 | case NOCHAR: |
309 | case NOCHAR: |
214 | case ZERO_WIDTH_CHAR: |
310 | case ZERO_WIDTH_CHAR: |
215 | break; |
311 | break; |
216 | default: |
312 | default: |
217 | XSetForeground (DISPLAY, GC, r->PixColors[fg]); |
|
|
218 | XDrawRectangle (DISPLAY, DRAWABLE, GC, x + 2, y + 2, r->TermWin.fwidth - 5, r->TermWin.fheight - 5); |
313 | XDrawRectangle (DISPLAY, DRAWABLE, GC, x + 2, y + 2, r->TermWin.fwidth - 5, r->TermWin.fheight - 5); |
219 | } |
314 | } |
220 | |
315 | |
221 | x += r->TermWin.fwidth; |
316 | x += r->TermWin.fwidth; |
222 | } |
317 | } |
223 | } |
318 | } |
224 | |
319 | |
… | |
… | |
257 | |
352 | |
258 | bool |
353 | bool |
259 | rxvt_font_x11::load (int maxheight) |
354 | rxvt_font_x11::load (int maxheight) |
260 | { |
355 | { |
261 | clear (); |
356 | clear (); |
|
|
357 | |
|
|
358 | char **list; |
|
|
359 | int count; |
|
|
360 | XFontStruct *info; |
|
|
361 | list = XListFontsWithInfo (DISPLAY, name, 128, &count, &info); |
|
|
362 | |
|
|
363 | if (!list) |
|
|
364 | return false; |
|
|
365 | |
|
|
366 | XFontStruct *best = 0; |
|
|
367 | for (int i = 0; i < count; i++) |
|
|
368 | { |
|
|
369 | XFontStruct *f = info + i; |
|
|
370 | if (f->ascent + f->descent <= maxheight) // weed out too large fonts |
|
|
371 | if (!best // compare against best found so far |
|
|
372 | || best->ascent + best->descent < f->ascent + f->descent) |
|
|
373 | best = f; |
|
|
374 | } |
|
|
375 | |
|
|
376 | set_name (strdup (list[best - info])); |
|
|
377 | |
|
|
378 | XFreeFontInfo (list, info, count); |
262 | |
379 | |
263 | f = XLoadQueryFont (DISPLAY, name); |
380 | f = XLoadQueryFont (DISPLAY, name); |
264 | |
381 | |
265 | if (!f) |
382 | if (!f) |
266 | return false; |
383 | return false; |
… | |
… | |
796 | rxvt_fontset::realize_font (int i) |
913 | rxvt_fontset::realize_font (int i) |
797 | { |
914 | { |
798 | if (fonts[i]->loaded) |
915 | if (fonts[i]->loaded) |
799 | return true; |
916 | return true; |
800 | |
917 | |
|
|
918 | fonts[i]->loaded = true; |
|
|
919 | |
801 | if (fonts[i]->load (height)) |
920 | if (!fonts[i]->load (height)) |
802 | return fonts[i]->loaded = true; |
921 | { |
803 | |
922 | fonts[i]->cs = CS_UNKNOWN; |
804 | delete fonts[i]; |
|
|
805 | fonts.erase (fonts.begin () + i); |
|
|
806 | |
|
|
807 | return false; |
923 | return false; |
|
|
924 | } |
|
|
925 | |
|
|
926 | return true; |
808 | } |
927 | } |
809 | |
928 | |
810 | void |
929 | void |
811 | rxvt_fontset::populate (const char *desc) |
930 | rxvt_fontset::populate (const char *desc) |
812 | { |
931 | { |
… | |
… | |
849 | { |
968 | { |
850 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
969 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
851 | goto next_font; |
970 | goto next_font; |
852 | |
971 | |
853 | if (!realize_font (i)) |
972 | if (!realize_font (i)) |
854 | { |
|
|
855 | --i; |
|
|
856 | goto next_font; |
973 | goto next_font; |
857 | } |
974 | } |
858 | |
975 | |
859 | //printf ("added font %s for %04lx\n", f->name, unicode); |
|
|
860 | } |
|
|
861 | |
|
|
862 | if (f->has_codepoint (unicode)) |
976 | if (f->cs != CS_UNKNOWN && f->has_codepoint (unicode)) |
863 | return i; |
977 | return i; |
864 | |
978 | |
865 | next_font: |
979 | next_font: |
866 | if (i == fonts.size () - 1 && fallback->name) |
980 | if (i == fonts.size () - 1 && fallback->name) |
867 | { |
981 | { |
868 | fonts.push_back (new_font (fallback->name, fallback->cs)); |
982 | fonts.push_back (new_font (fallback->name, fallback->cs)); |
869 | fallback++; |
983 | fallback++; |
|
|
984 | i = 0; |
870 | } |
985 | } |
871 | } |
986 | } |
872 | |
987 | |
873 | return 0; /* we must return SOME font */ |
988 | return 0; /* we must return SOME font */ |
874 | } |
989 | } |