dtext.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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; // char
  13. uint16_t v; // advance
  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 *faces;
  23. size_t num_faces;
  24. GlyphSet gs;
  25. dt_row advance[DT_HASH_SIZE];
  26. } dt_font;
  27. typedef struct {
  28. int32_t x; // Bottom-left of box, relative to point of origin of text
  29. int32_t y;
  30. uint32_t w;
  31. uint32_t h;
  32. } dt_bbox;
  33. typedef struct {
  34. uint8_t red;
  35. uint8_t green;
  36. uint8_t blue;
  37. uint8_t alpha; // 0 means opaque
  38. } dt_style;
  39. dt_error dt_init(dt_context **ctx, Display *dpy, Window win);
  40. dt_error dt_quit(dt_context *ctx);
  41. dt_error dt_load(dt_context *ctx, dt_font **fnt, char const *name);
  42. dt_error dt_free(dt_context *ctx, dt_font *fnt);
  43. dt_error dt_box(dt_context *ctx, dt_font *fnt, dt_bbox *bbox,
  44. wchar_t const *txt);
  45. dt_error dt_draw(dt_context *ctx, dt_font *fnt, dt_style const *style,
  46. uint32_t x, uint32_t y, wchar_t const *txt);