1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#ifndef DRW_H
#define DRW_H
#include <stdint.h>
#include <ft2build.h>
#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
|