dtext.h 1.3 KB

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