-
Notifications
You must be signed in to change notification settings - Fork 3
/
module.c
158 lines (145 loc) · 7.72 KB
/
module.c
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/bug.h>
#include "harfbuzz/src/hb.h"
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Ebrahim Byagowi <[email protected]>");
MODULE_DESCRIPTION("HarfBuzz as a Linux kernel module");
MODULE_VERSION("1");
extern void kernel_fpu_begin(void);
extern void kernel_fpu_end(void);
void abort(void)
{
BUG();
}
/* xxd -i ./examples/Roboto.abc.ttf */
unsigned char __examples_Roboto_abc_ttf[] = {
0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x80, 0x00, 0x03, 0x00, 0x30,
0x4f, 0x53, 0x2f, 0x32, 0x74, 0x68, 0x82, 0x0e, 0x00, 0x00, 0x02, 0x80,
0x00, 0x00, 0x00, 0x60, 0x63, 0x6d, 0x61, 0x70, 0x00, 0x1b, 0x01, 0xef,
0x00, 0x00, 0x02, 0xe0, 0x00, 0x00, 0x00, 0x58, 0x67, 0x61, 0x73, 0x70,
0x00, 0x08, 0x00, 0x13, 0x00, 0x00, 0x03, 0x90, 0x00, 0x00, 0x00, 0x0c,
0x67, 0x6c, 0x79, 0x66, 0xe0, 0x46, 0x1a, 0x71, 0x00, 0x00, 0x00, 0xbc,
0x00, 0x00, 0x01, 0x2c, 0x68, 0x65, 0x61, 0x64, 0xfc, 0x6a, 0xd2, 0x7a,
0x00, 0x00, 0x02, 0x14, 0x00, 0x00, 0x00, 0x36, 0x68, 0x68, 0x65, 0x61,
0x0a, 0xba, 0x05, 0xa4, 0x00, 0x00, 0x02, 0x5c, 0x00, 0x00, 0x00, 0x24,
0x68, 0x6d, 0x74, 0x78, 0x10, 0x93, 0x01, 0xb9, 0x00, 0x00, 0x02, 0x4c,
0x00, 0x00, 0x00, 0x10, 0x6c, 0x6f, 0x63, 0x61, 0x00, 0xd2, 0x00, 0x68,
0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x00, 0x0a, 0x6d, 0x61, 0x78, 0x70,
0x00, 0x26, 0x00, 0xe5, 0x00, 0x00, 0x01, 0xe8, 0x00, 0x00, 0x00, 0x20,
0x6e, 0x61, 0x6d, 0x65, 0x02, 0xb7, 0x0a, 0xf3, 0x00, 0x00, 0x03, 0x38,
0x00, 0x00, 0x00, 0x38, 0x70, 0x6f, 0x73, 0x74, 0xff, 0x6d, 0x00, 0x64,
0x00, 0x00, 0x03, 0x70, 0x00, 0x00, 0x00, 0x20, 0x00, 0x02, 0x00, 0x6d,
0xff, 0xec, 0x03, 0xea, 0x04, 0x4e, 0x00, 0x1e, 0x00, 0x28, 0x00, 0x00,
0x21, 0x26, 0x27, 0x06, 0x23, 0x22, 0x26, 0x35, 0x34, 0x24, 0x33, 0x33,
0x35, 0x34, 0x26, 0x23, 0x22, 0x06, 0x15, 0x23, 0x34, 0x36, 0x36, 0x33,
0x32, 0x16, 0x17, 0x11, 0x14, 0x17, 0x15, 0x25, 0x32, 0x36, 0x37, 0x35,
0x23, 0x20, 0x15, 0x14, 0x16, 0x03, 0x28, 0x10, 0x0a, 0x81, 0xb3, 0xa0,
0xcd, 0x01, 0x01, 0xe9, 0xb4, 0x74, 0x71, 0x63, 0x86, 0xba, 0x73, 0xc5,
0x76, 0xbb, 0xd4, 0x04, 0x26, 0xfe, 0x0b, 0x57, 0x9c, 0x23, 0x91, 0xfe,
0xac, 0x74, 0x20, 0x52, 0x86, 0xb5, 0x8b, 0xa9, 0xbb, 0x55, 0x61, 0x73,
0x64, 0x47, 0x51, 0x97, 0x58, 0xbb, 0xa4, 0xfe, 0x0e, 0x95, 0x58, 0x10,
0x8d, 0x5a, 0x48, 0xde, 0xc7, 0x57, 0x62, 0x00, 0x00, 0x02, 0x00, 0x8c,
0xff, 0xec, 0x04, 0x20, 0x06, 0x00, 0x00, 0x0e, 0x00, 0x19, 0x00, 0x00,
0x01, 0x14, 0x02, 0x23, 0x22, 0x27, 0x07, 0x23, 0x11, 0x33, 0x11, 0x36,
0x20, 0x12, 0x11, 0x27, 0x34, 0x26, 0x23, 0x22, 0x07, 0x11, 0x16, 0x33,
0x32, 0x36, 0x04, 0x20, 0xe4, 0xc0, 0xcd, 0x70, 0x09, 0xaa, 0xb9, 0x70,
0x01, 0x8a, 0xe1, 0xb9, 0x92, 0x89, 0xb7, 0x50, 0x55, 0xb4, 0x85, 0x94,
0x02, 0x11, 0xf8, 0xfe, 0xd3, 0x91, 0x7d, 0x06, 0x00, 0xfd, 0xc3, 0x8b,
0xfe, 0xd6, 0xfe, 0xfd, 0x05, 0xbd, 0xce, 0xaa, 0xfe, 0x2c, 0xaa, 0xce,
0x00, 0x01, 0x00, 0x5c, 0xff, 0xec, 0x03, 0xec, 0x04, 0x4e, 0x00, 0x1d,
0x00, 0x00, 0x25, 0x32, 0x36, 0x37, 0x33, 0x0e, 0x02, 0x23, 0x22, 0x00,
0x11, 0x35, 0x34, 0x36, 0x36, 0x33, 0x32, 0x16, 0x17, 0x23, 0x26, 0x26,
0x23, 0x22, 0x06, 0x15, 0x15, 0x14, 0x16, 0x02, 0x3e, 0x63, 0x94, 0x08,
0xaf, 0x05, 0x76, 0xc5, 0x6e, 0xdd, 0xfe, 0xfb, 0x74, 0xd9, 0x94, 0xb6,
0xf1, 0x08, 0xaf, 0x08, 0x8f, 0x69, 0x8d, 0x9b, 0x9a, 0x83, 0x78, 0x5a,
0x5d, 0xa8, 0x64, 0x01, 0x27, 0x01, 0x00, 0x1f, 0x9e, 0xf6, 0x88, 0xda,
0xae, 0x69, 0x87, 0xcb, 0xc0, 0x23, 0xbb, 0xca, 0x00, 0x01, 0x00, 0x00,
0x00, 0x04, 0x00, 0x8f, 0x00, 0x16, 0x00, 0x54, 0x00, 0x05, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x68,
0x00, 0x96, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x23, 0x12,
0x5e, 0xeb, 0x11, 0xd7, 0x5f, 0x0f, 0x3c, 0xf5, 0x00, 0x19, 0x08, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc4, 0xf0, 0x11, 0x2e, 0x00, 0x00, 0x00, 0x00,
0xd5, 0x01, 0x52, 0xf4, 0xfa, 0x1b, 0xfd, 0xd5, 0x09, 0x30, 0x08, 0x73,
0x00, 0x00, 0x00, 0x09, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0x8c, 0x00, 0x64, 0x04, 0x5a, 0x00, 0x6d, 0x04, 0x7d, 0x00, 0x8c,
0x04, 0x30, 0x00, 0x5c, 0x00, 0x01, 0x00, 0x00, 0x07, 0x6c, 0xfe, 0x0c,
0x00, 0x00, 0x09, 0x49, 0xfa, 0x1b, 0xfe, 0x4a, 0x09, 0x30, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x04, 0x00, 0x03, 0x04, 0x86, 0x01, 0x90, 0x00, 0x05,
0x00, 0x00, 0x05, 0x9a, 0x05, 0x33, 0x00, 0x00, 0x01, 0x1f, 0x05, 0x9a,
0x05, 0x33, 0x00, 0x00, 0x03, 0xd1, 0x00, 0x66, 0x02, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x47, 0x4f, 0x4f, 0x47, 0x00, 0x40, 0x00, 0x61, 0x00, 0x63,
0x06, 0x00, 0xfe, 0x00, 0x00, 0x66, 0x07, 0x9a, 0x02, 0x00, 0x20, 0x00,
0x01, 0x9f, 0x00, 0x00, 0x00, 0x00, 0x04, 0x3a, 0x05, 0xb0, 0x00, 0x20,
0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x1c, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1c,
0x00, 0x03, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x04, 0x00, 0x20,
0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x63,
0xff, 0xff, 0x00, 0x00, 0x00, 0x61, 0xff, 0xff, 0xff, 0xa0, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x61,
0x00, 0x00, 0x00, 0x63, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02,
0x00, 0x1e, 0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 0x00, 0x01, 0x00, 0x0c,
0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 0x00, 0x02, 0x00, 0x0e,
0x00, 0x0c, 0x00, 0x52, 0x00, 0x6f, 0x00, 0x62, 0x00, 0x6f, 0x00, 0x74,
0x00, 0x6f, 0x00, 0x52, 0x00, 0x65, 0x00, 0x67, 0x00, 0x75, 0x00, 0x6c,
0x00, 0x61, 0x00, 0x72, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0x6a, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x02, 0x00, 0x08, 0x00, 0x02, 0xff, 0xff, 0x00, 0x0f
};
unsigned int __examples_Roboto_abc_ttf_len = 924;
static int harfbuzz_init(void)
{
printk(KERN_INFO "harfbuzz: init\n");
kernel_fpu_begin ();
{
unsigned int upem;
unsigned int buffer_length;
hb_face_t *face;
hb_font_t *font;
hb_buffer_t *buffer;
hb_glyph_info_t *info;
hb_glyph_position_t *pos;
unsigned int i;
hb_blob_t *blob = hb_blob_create (
(const char *) __examples_Roboto_abc_ttf,
__examples_Roboto_abc_ttf_len,
HB_MEMORY_MODE_READONLY, NULL, NULL);
face = hb_face_create (blob, 0);
hb_blob_destroy (blob);
font = hb_font_create (face);
upem = hb_face_get_upem (face);
hb_face_destroy (face);
buffer = hb_buffer_create ();
hb_buffer_add_utf8 (buffer, "abc", -1, 0, -1);
hb_buffer_guess_segment_properties (buffer);
hb_shape (font, buffer, NULL, 0);
printk(KERN_INFO "upem: %d", upem);
info = hb_buffer_get_glyph_infos (buffer, &buffer_length);
pos = hb_buffer_get_glyph_positions (buffer, &buffer_length);
printk(KERN_INFO "buffer size: %d", buffer_length);
for (i = 0; i < buffer_length; ++i) {
printk(KERN_INFO "glyph #%d: ax: %d, ay: %d, dx: %d, dy: %d",
info[i].codepoint,
pos[i].x_advance, pos[i].y_advance,
pos[i].x_offset, pos[i].y_offset);
}
hb_font_destroy (font);
hb_buffer_destroy (buffer);
}
kernel_fpu_end ();
return 0;
}
static void harfbuzz_exit(void)
{
printk(KERN_INFO "harfbuzz: exit\n");
}
module_init(harfbuzz_init);
module_exit(harfbuzz_exit);