~andreafeletto/zig-fcft

3cf9bd470c8106b4ca0c90439de4851e29067b02 — Andrea Feletto 4 months ago
first commit
3 files changed, 154 insertions(+), 0 deletions(-)

A LICENSE
A README.md
A fcft.zig
A  => LICENSE +21 -0
@@ 1,21 @@
MIT License

Copyright (c) 2021 Andrea Feletto

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

A  => README.md +10 -0
@@ 1,10 @@
# zig-fcft

Idiomatic [Zig](https://ziglang.org/) bindings for
[fcft](https://codeberg.org/dnkl/fcft).

## Dependencies

* [zig](https://ziglang.org/) 0.8.0
* [fcft](https://codeberg.org/dnkl/fcft) 2.4.0
* [zig-pixman](https://github.com/ifreund/zig-pixman)

A  => fcft.zig +123 -0
@@ 1,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 c_int, tag_count: usize, tags: [*]const Tag, subpixel: Subpixel) ?*Grapheme;
    pub fn rasterize(font: *Font, grapheme_cluster: []const c_int, tags: []const Tag, subpixel: Subpixel) ?*Grapheme {
        return fcft_grapheme_rasterize(font, grapheme_cluster.len, &grapheme_cluster, tags.len, &tags, subpixel);
    }
};

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

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

    extern fn fcft_text_run_rasterize(font: *Font, len: usize, text: [*]const c_int, subpixel: Subpixel) ?*TextRun;
    pub fn rasterize(font: *Font, text: []const c_int, subpixel: Subpixel) ?*TextRun {
        return fcft_text_run_rasterize(font, text.len, &text, 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;