dtext.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 c; // char
  13. uint16_t adv; // advance
  14. int16_t asc; // ascender
  15. uint16_t h; // height
  16. } dt_pair;
  17. typedef struct {
  18. dt_pair *data;
  19. size_t len;
  20. size_t allocated;
  21. } dt_row;
  22. #define DT_HASH_SIZE 128
  23. typedef struct {
  24. uint16_t height;
  25. uint16_t ascent;
  26. FT_Face *faces;
  27. size_t num_faces;
  28. GlyphSet gs;
  29. dt_row advance[DT_HASH_SIZE];
  30. } dt_font;
  31. typedef struct {
  32. int32_t x; // Bottom-left of box, relative to point of origin of text
  33. int32_t y;
  34. uint32_t w;
  35. uint32_t h;
  36. } dt_bbox;
  37. typedef struct {
  38. uint8_t red;
  39. uint8_t green;
  40. uint8_t blue;
  41. uint8_t alpha; // 0 means opaque
  42. } dt_color;
  43. dt_error dt_init(dt_context **ctx, Display *dpy, Window win);
  44. void dt_quit(dt_context *ctx);
  45. dt_error dt_load(dt_context *ctx, dt_font **fnt, char const *name);
  46. void dt_free(dt_context *ctx, dt_font *fnt);
  47. dt_error dt_box(dt_context *ctx, dt_font *fnt, dt_bbox *bbox,
  48. wchar_t const *txt, size_t len);
  49. dt_error dt_draw(dt_context *ctx, dt_font *fnt, dt_color const *color,
  50. uint32_t x, uint32_t y, wchar_t const *txt, size_t len);