#ifndef DRW_H #define DRW_H #include #include #include FT_FREETYPE_H #include FT_BITMAP_H #include FT_STROKER_H #include FT_CACHE_H #include "wayland.h" #define CACHE_SIZE 4096 /* type definitions */ typedef struct { uint32_t *data; int data_fd; uint32_t *buffer_data; int buffer_data_fd; unsigned width; unsigned height; unsigned stride; unsigned size; struct wl_buffer *buffer; struct wl_shm *shm; struct wl_shm_pool *pool; } Canvas; typedef struct { const char *path; int loaded; FT_Library library; FT_Face face; FT_Stroker stroke; struct { FT_BitmapGlyph normal[CACHE_SIZE]; FT_BitmapGlyph bold[CACHE_SIZE]; } cache; } Font; enum FontType { FONT_NORMAL, FONT_ITALIC, FONT_BOLD, FONT_BOLD_ITALIC, FONT_TYPE_SIZE }; typedef Font FontFamily[FONT_TYPE_SIZE]; typedef char *FontPath[FONT_TYPE_SIZE]; struct FontCacheElement_; typedef struct FontCacheElement_ { FontFamily *family; struct FontCacheElement_ *next; } FontCacheElement; typedef struct { FontCacheElement *first; unsigned fontsize; unsigned fonttype; struct { unsigned width; unsigned height; } box; } FontCache; typedef struct { uint8_t r; uint8_t g; uint8_t b; uint8_t a; } Color; /* exported functions */ Canvas* create_drw(struct wl_shm *shm, unsigned width, unsigned height); void resize_drw(Canvas *canvas, unsigned width, unsigned height); void free_drw(Canvas *canvas); void push_buffer(Canvas *canvas); void draw_rect(Canvas *canvas, unsigned x, unsigned y, unsigned width, unsigned height, uint32_t color); void draw_point(Canvas *canvas, unsigned x, unsigned y, uint32_t color); FontCache *create_font_cache(FontPath *fontpath, int size, unsigned fontsize); void font_cache_generate_box(FontCache *fontcache); void free_font_cache(FontCache *fontcache); void draw_char(Canvas *canvas, FontCache *fontcache, uint_least32_t charcode, unsigned x, unsigned y, uint32_t color); #endif