My dmenu build
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

37 lines
1.1 KiB

  1. /* See LICENSE file for copyright and license details. */
  2. #include <X11/Xlib.h>
  3. #include "draw.h"
  4. #define MAX(a, b) ((a) > (b) ? (a) : (b))
  5. void
  6. initfont(DC *dc, const char *fontstr) {
  7. char *def, **missing = NULL;
  8. int i, n;
  9. if(!fontstr || !*fontstr)
  10. eprint("cannot load null font\n");
  11. dc->font.set = XCreateFontSet(dc->dpy, fontstr, &missing, &n, &def);
  12. if(missing)
  13. XFreeStringList(missing);
  14. if(dc->font.set) {
  15. XFontStruct **xfonts;
  16. char **font_names;
  17. dc->font.ascent = dc->font.descent = 0;
  18. n = XFontsOfFontSet(dc->font.set, &xfonts, &font_names);
  19. for(i = 0; i < n; i++) {
  20. dc->font.ascent = MAX(dc->font.ascent, (*xfonts)->ascent);
  21. dc->font.descent = MAX(dc->font.descent, (*xfonts)->descent);
  22. xfonts++;
  23. }
  24. }
  25. else {
  26. if(!(dc->font.xfont = XLoadQueryFont(dc->dpy, fontstr))
  27. && !(dc->font.xfont = XLoadQueryFont(dc->dpy, "fixed")))
  28. eprint("cannot load font '%s'\n", fontstr);
  29. dc->font.ascent = dc->font.xfont->ascent;
  30. dc->font.descent = dc->font.xfont->descent;
  31. }
  32. dc->font.height = dc->font.ascent + dc->font.descent;
  33. }