font: freetype supports font variation settings

This commit is contained in:
Mitchell Hashimoto
2023-08-27 19:58:25 -07:00
parent 906852976b
commit 1ee5b7f91c
6 changed files with 125 additions and 5 deletions

View File

@@ -57,6 +57,11 @@ pub fn initMemoryFace(self: Library, data: []const u8, index: i32) Error!Face {
return face;
}
/// Call when you're done with a loaded MM var.
pub fn doneMMVar(self: Library, mm: *c.FT_MM_Var) void {
_ = c.FT_Done_MM_Var(self.handle, mm);
}
pub const Version = struct {
major: i32,
minor: i32,

View File

@@ -24,6 +24,12 @@ pub const Face = struct {
return c.FT_HAS_COLOR(self.handle);
}
/// A macro that returns true whenever a face object contains some
/// multiple masters.
pub fn hasMultipleMasters(self: Face) bool {
return c.FT_HAS_MULTIPLE_MASTERS(self.handle);
}
/// A macro that returns true whenever a face object contains a scalable
/// font face (true for TrueType, Type 1, Type 42, CID, OpenType/CFF,
/// and PFR font formats).
@@ -95,6 +101,33 @@ pub const Face = struct {
const res = c.FT_Get_Sfnt_Name(self.handle, @intCast(i), &name);
return if (intToError(res)) |_| name else |err| err;
}
/// Retrieve the font variation descriptor for a font.
pub fn getMMVar(self: Face) Error!*c.FT_MM_Var {
var result: *c.FT_MM_Var = undefined;
const res = c.FT_Get_MM_Var(self.handle, @ptrCast(&result));
return if (intToError(res)) |_| result else |err| err;
}
/// Get the design coordinates of the currently selected interpolated font.
pub fn getVarDesignCoordinates(self: Face, coords: []c.FT_Fixed) Error!void {
const res = c.FT_Get_Var_Design_Coordinates(
self.handle,
@intCast(coords.len),
coords.ptr,
);
return intToError(res);
}
/// Choose an interpolated font design through design coordinates.
pub fn setVarDesignCoordinates(self: Face, coords: []c.FT_Fixed) Error!void {
const res = c.FT_Set_Var_Design_Coordinates(
self.handle,
@intCast(coords.len),
coords.ptr,
);
return intToError(res);
}
};
/// An enumeration to specify indices of SFNT tables loaded and parsed by

View File

@@ -1,5 +1,6 @@
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_TRUETYPE_TABLES_H
#include <freetype/ftmm.h>
#include <freetype/ftsnames.h>
#include <freetype/ttnameid.h>