~andreafeletto/zig-fcft

ref: c819763cccce70d2dc361cb9e8948d461c946f27 zig-fcft/fcft.zig -rw-r--r-- 3.3 KiB
c819763cAndrea Feletto fix pointer types in Graphene and TextRun 4 months ago
                                                                                
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
const pixman = @import("pixman");

pub const Subpixel = extern enum {
    default,
    none,
    horizontal_rgb,
    horizontal_bgr,
    vertical_rgb,
    vertical_bgr,
};

pub const Font = extern struct {
    height: c_int,
    descent: c_int,
    ascent: c_int,

    max_advance: extern struct { x: c_int, y: c_int },
    space_advance: extern struct { x: c_int, y: c_int },
    underline: extern struct { position: c_int, thickness: c_int },
    strikeout: extern struct { position: c_int, thickness: c_int },

    antialias: bool,

    subpixel: Subpixel,

    extern fn fcft_from_name(count: usize, names: [*][*:0]const u8, attributes: ?[*:0]u8) ?*Font;
    pub fn fromName(names: [][*:0]const u8, attributes: ?[*:0]u8) ?*Font {
        return fcft_from_name(names.len, names.ptr, attributes);
    }

    extern fn fcft_clone(self: *const Font) ?*Font;
    pub const clone = fcft_clone;

    extern fn fcft_destroy(self: *Font) void;
    pub const destroy = fcft_destroy;
};

pub const Capabilities = extern enum {
    grapheme_shaping = 0x1,
    text_run_shaping = 0x2,
};

pub const Glyph = extern struct {
    wc: c_int,
    cols: c_int,

    pix: *pixman.Image,

    x: c_int,
    y: c_int,
    width: c_int,
    height: c_int,

    advance: extern struct { x: c_int, y: c_int },

    extern fn fcft_glyph_rasterize(font: *Font, wc: c_int, subpixel: Subpixel) ?*Glyph;
    pub const rasterize = fcft_glyph_rasterize;
};

pub const Grapheme = extern struct {
    cols: c_int,

    count: usize,
    glyphs: [*]const *Glyph,

    extern fn fcft_grapheme_rasterize(font: *Font, len: usize, grapheme_cluster: [*]const u8, tag_count: usize, tags: [*]const Tag, subpixel: Subpixel) ?*Grapheme;
    pub fn rasterize(font: *Font, grapheme_cluster: []const u8, tags: []const Tag, subpixel: Subpixel) ?*Grapheme {
        return fcft_grapheme_rasterize(font, grapheme_cluster.len, grapheme_cluster.ptr, tags.len, tags.ptr, subpixel);
    }
};

pub const Tag = extern struct {
    tag: [4]u8,
    value: c_uint,
};

pub const TextRun = extern struct {
    glyphs: [*]const *Glyph,
    cluster: [*]c_int,
    count: usize,

    extern fn fcft_text_run_rasterize(font: *Font, len: usize, text: [*]const u8, subpixel: Subpixel) ?*TextRun;
    pub fn rasterize(font: *Font, text: []const u8, subpixel: Subpixel) ?*TextRun {
        return fcft_text_run_rasterize(font, text.len, text.ptr, subpixel);
    }

    extern fn fcft_text_run_destroy(run: *TextRun) void;
    pub const destroy = fcft_text_run_destroy;
};

extern fn fcft_kerning(font: *Font, left: c_int, right: c_int, noalias x: *c_long, noalias y: *c_long) bool;
pub const kerning = fcft_kerning;

extern fn fcft_precompose(font: *const Font, base: c_int, comb: c_int, base_is_from_primary: bool, comb_is_from_primary: bool, composed_is_from_primary: bool) c_int;
pub const precompose = fcft_precompose;

pub const ScalingFilter = extern enum {
    none,
    nearest,
    bilinear,
    cubic,
    lanczos3,
};

extern fn fcft_set_scaling_filter(filter: ScalingFilter) bool;
pub const setScalingFilter = fcft_set_scaling_filter;

pub const LogColorize = extern enum {
    never,
    always,
    auto,
};

pub const LogClass = extern enum {
    none,
    err,
    warning,
    info,
    debug,
};

extern fn fcft_log_init(colorize: LogColorize, do_syslog: bool, log_level: LogClass) void;
pub const logInit = fcft_log_init;