… | |
… | |
353 | bool |
353 | bool |
354 | rxvt_font_x11::load (int maxheight) |
354 | rxvt_font_x11::load (int maxheight) |
355 | { |
355 | { |
356 | clear (); |
356 | clear (); |
357 | |
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); |
|
|
379 | |
358 | f = XLoadQueryFont (DISPLAY, name); |
380 | f = XLoadQueryFont (DISPLAY, name); |
359 | |
381 | |
360 | if (!f) |
382 | if (!f) |
361 | return false; |
383 | return false; |
362 | |
384 | |
… | |
… | |
891 | rxvt_fontset::realize_font (int i) |
913 | rxvt_fontset::realize_font (int i) |
892 | { |
914 | { |
893 | if (fonts[i]->loaded) |
915 | if (fonts[i]->loaded) |
894 | return true; |
916 | return true; |
895 | |
917 | |
|
|
918 | fonts[i]->loaded = true; |
|
|
919 | |
896 | if (fonts[i]->load (height)) |
920 | if (!fonts[i]->load (height)) |
897 | return fonts[i]->loaded = true; |
921 | { |
898 | |
922 | fonts[i]->cs = CS_UNKNOWN; |
899 | delete fonts[i]; |
|
|
900 | fonts.erase (fonts.begin () + i); |
|
|
901 | |
|
|
902 | return false; |
923 | return false; |
|
|
924 | } |
|
|
925 | |
|
|
926 | return true; |
903 | } |
927 | } |
904 | |
928 | |
905 | void |
929 | void |
906 | rxvt_fontset::populate (const char *desc) |
930 | rxvt_fontset::populate (const char *desc) |
907 | { |
931 | { |
… | |
… | |
944 | { |
968 | { |
945 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
969 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
946 | goto next_font; |
970 | goto next_font; |
947 | |
971 | |
948 | if (!realize_font (i)) |
972 | if (!realize_font (i)) |
949 | { |
|
|
950 | --i; |
|
|
951 | goto next_font; |
973 | goto next_font; |
952 | } |
974 | } |
953 | |
975 | |
954 | //printf ("added font %s for %04lx\n", f->name, unicode); |
|
|
955 | } |
|
|
956 | |
|
|
957 | if (f->has_codepoint (unicode)) |
976 | if (f->cs != CS_UNKNOWN && f->has_codepoint (unicode)) |
958 | return i; |
977 | return i; |
959 | |
978 | |
960 | next_font: |
979 | next_font: |
961 | if (i == fonts.size () - 1 && fallback->name) |
980 | if (i == fonts.size () - 1 && fallback->name) |
962 | { |
981 | { |
963 | fonts.push_back (new_font (fallback->name, fallback->cs)); |
982 | fonts.push_back (new_font (fallback->name, fallback->cs)); |
964 | fallback++; |
983 | fallback++; |
|
|
984 | i = 0; |
965 | } |
985 | } |
966 | } |
986 | } |
967 | |
987 | |
968 | return 0; /* we must return SOME font */ |
988 | return 0; /* we must return SOME font */ |
969 | } |
989 | } |