tiny.filigree.font.model
Defined in font.
API (30)
Actions
Public operations.
GposContextualPairAdjustment.isZeroGposPairAdjustment.addGposPairAdjustment.isZeroGposPairAdjustmentBefore.isZeroGposSingleAdjustment.isZeroGposValueAdjustment.addGposValueAdjustment.isZeroGposValueAdjustment.withVariationsfeatureEnabledfixed16ToFloattag
Types and contracts
Public types and contracts.
FeatureRangeFeatureSettingFontErrorGlyphClassGposContextualPairAdjustmentGposCursiveAttachmentGposPairAdjustmentGposPairAdjustmentBeforeGposSingleAdjustmentGposValueAdjustmentGsubSubstitutionLayoutSelectionLigatureCaretNormalizedVariationTagVariationAxisVariationSetting
Values and defaults
Public values and defaults.
Source
Source: lib/filigree/src/font/model.zig
zig
const std = @import("std");pub const FontError = error{ InvalidFont, MissingTable, UnsupportedCmap, InvalidCmap, InvalidKern, InvalidGsub, InvalidGpos, InvalidGdef, InvalidVariations,};pub const Tag = u32;pub fn tag(comptime name: []const u8) Tag { if (name.len != 4) @compileError("OpenType tags are four bytes"); return (@as(u32, name[0]) << 24) | (@as(u32, name[1]) << 16) | (@as(u32, name[2]) << 8) | @as(u32, name[3]);}pub const GlyphClass = enum { unknown, base, ligature, mark, component,};pub const LigatureCaret = struct { coordinate: i16, synthesized: bool = false,};pub const defaultScriptTag: Tag = tag("DFLT");pub const FeatureRange = struct { start: u32 = 0, end: u32 = std.math.maxInt(u32),};pub const FeatureSetting = struct { tag: Tag, value: u32 = 1, source: ?FeatureRange = null,};pub const VariationAxis = struct { tag: Tag, min_value: i32, default_value: i32, max_value: i32, flags: u16 = 0, name_id: u16 = 0,};pub const VariationSetting = struct { tag: Tag, value: f32,};pub const NormalizedVariation = struct { tag: Tag, value: i16,};pub const LayoutSelection = struct { script: Tag = defaultScriptTag, script_tags: []const Tag = &.{}, language: ?Tag = null, features: []const FeatureSetting = &.{}, variations: []const VariationSetting = &.{}, vertical: bool = false, right_to_left: bool = false,};pub fn featureEnabled(selection: LayoutSelection, feature_tag: Tag, default_on: bool, source: ?FeatureRange) bool { var enabled = default_on; for (selection.features) |setting| { if (setting.tag != feature_tag) continue; if (!featureSettingApplies(setting, source)) continue; enabled = setting.value != 0; } return enabled;}pub fn fixed16ToFloat(value: i32) f32 { return @as(f32, @floatFromInt(value)) / 65536.0;}fn featureSettingApplies(setting: FeatureSetting, source: ?FeatureRange) bool { const setting_source = setting.source orelse return true; const lookup_source = source orelse return false; return setting_source.start < lookup_source.end and lookup_source.start < setting_source.end;}pub const noGposVariationIndex: u32 = std.math.maxInt(u32);pub const GsubSubstitution = struct { glyph_id: u32, component_count: u16, replacement_count: u16 = 1, replacement_glyphs_offset: usize = 0, target_offset: usize = 0, skip_count: usize = 0,};pub const GposValueAdjustment = struct { x_placement: i32 = 0, y_placement: i32 = 0, x_advance: i32 = 0, y_advance: i32 = 0, x_placement_variation: u32 = noGposVariationIndex, y_placement_variation: u32 = noGposVariationIndex, x_advance_variation: u32 = noGposVariationIndex, y_advance_variation: u32 = noGposVariationIndex, pub fn isZero(self: GposValueAdjustment) bool { return self.x_placement == 0 and self.y_placement == 0 and self.x_advance == 0 and self.y_advance == 0 and self.x_placement_variation == noGposVariationIndex and self.y_placement_variation == noGposVariationIndex and self.x_advance_variation == noGposVariationIndex and self.y_advance_variation == noGposVariationIndex; } pub fn withVariations(self: GposValueAdjustment, face: anytype, settings: []const VariationSetting) GposValueAdjustment { return .{ .x_placement = face.gposVariationValue(self.x_placement, settings, self.x_placement_variation), .y_placement = face.gposVariationValue(self.y_placement, settings, self.y_placement_variation), .x_advance = face.gposVariationValue(self.x_advance, settings, self.x_advance_variation), .y_advance = face.gposVariationValue(self.y_advance, settings, self.y_advance_variation), }; } pub fn add(self: *GposValueAdjustment, other: GposValueAdjustment) void { self.x_placement += other.x_placement; self.y_placement += other.y_placement; self.x_advance += other.x_advance; self.y_advance += other.y_advance; self.x_placement_variation = mergeGposVariationIndex(self.x_placement_variation, other.x_placement_variation); self.y_placement_variation = mergeGposVariationIndex(self.y_placement_variation, other.y_placement_variation); self.x_advance_variation = mergeGposVariationIndex(self.x_advance_variation, other.x_advance_variation); self.y_advance_variation = mergeGposVariationIndex(self.y_advance_variation, other.y_advance_variation); }};pub const GposPairAdjustment = struct { left: GposValueAdjustment = .{}, right: GposValueAdjustment = .{}, pub fn isZero(self: GposPairAdjustment) bool { return self.left.isZero() and self.right.isZero(); } pub fn add(self: *GposPairAdjustment, other: GposPairAdjustment) void { self.left.add(other.left); self.right.add(other.right); }};pub const GposPairAdjustmentBefore = struct { adjustment: GposPairAdjustment = .{}, left_offset: usize = 0, pub fn isZero(self: GposPairAdjustmentBefore) bool { return self.adjustment.isZero(); }};pub const GposContextualPairAdjustment = struct { adjustment: GposPairAdjustment = .{}, target_offset: usize = 0, skip_count: usize = 0, pub fn isZero(self: GposContextualPairAdjustment) bool { return self.adjustment.isZero(); }};pub const GposSingleAdjustment = struct { adjustment: GposValueAdjustment = .{}, target_offset: usize = 0, skip_count: usize = 0, pub fn isZero(self: GposSingleAdjustment) bool { return self.adjustment.isZero(); }};pub const GposCursiveAttachment = struct { x_anchor_delta: i32 = 0, y_anchor_delta: i32 = 0,};fn mergeGposVariationIndex(existing: u32, incoming: u32) u32 { if (incoming == noGposVariationIndex) return existing; if (existing == noGposVariationIndex) return incoming; return existing;}test "tag packs OpenType tags" { try std.testing.expectEqual(@as(u32, 0x68656164), tag("head"));}Source: lib/filigree/src/font/root.zig:14
zig
pub const model = @import("model.zig");Audit
| Definitions | 19 |
|---|---|
| Public names | 35 |
| Members | 37 |
| Version | 26.7.0 |
| Revision | daab053ee433 |