dtext.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* See LICENSE file for copyright and license details. */
  2. typedef int32_t dt_error;
  3. typedef struct {
  4. FT_Library ft_lib;
  5. XRenderPictFormat *win_format;
  6. XRenderPictFormat *argb32_format;
  7. Display *dpy;
  8. Picture pic;
  9. Picture fill;
  10. } dt_context;
  11. typedef struct {
  12. wchar_t k;
  13. uint8_t v;
  14. } dt_pair;
  15. typedef struct {
  16. dt_pair *data;
  17. size_t len;
  18. size_t allocated;
  19. } dt_row;
  20. #define DT_HASH_SIZE 128
  21. typedef struct {
  22. FT_Face face;
  23. GlyphSet gs;
  24. dt_row loaded[DT_HASH_SIZE];
  25. } dt_font;
  26. typedef struct {
  27. int32_t x; // Bottom-left of box, relative to point of origin of text
  28. int32_t y;
  29. uint32_t w;
  30. uint32_t h;
  31. } dt_bbox;
  32. typedef struct {
  33. uint8_t red;
  34. uint8_t green;
  35. uint8_t blue;
  36. uint8_t alpha; // 0 means opaque
  37. } dt_style;
  38. dt_error dt_init(dt_context **ctx, Display *dpy, Window win);
  39. dt_error dt_quit(dt_context *ctx);
  40. dt_error dt_load(dt_context *ctx, dt_font **fnt,
  41. uint8_t size, char const *name);
  42. dt_error dt_free(dt_context *ctx, dt_font *fnt);
  43. dt_error dt_box(dt_font *fnt, dt_bbox *bbox, wchar_t const *txt);
  44. dt_error dt_draw(dt_context *ctx, dt_font *fnt, dt_style const *style,
  45. uint32_t x, uint32_t y, wchar_t const *txt);