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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
use bitflags::bitflags;

use core::fmt;

use crate::{
    geometry::{BoxD, PointD, PointI},
    Tag,
};

use ffi::BLGlyphItemFlags::*;
bitflags! {
    pub struct GlyphItemFlags: u32 {
        const MARK = BL_GLYPH_ITEM_FLAG_MARK as u32;
    }
}

use ffi::BLGlyphPlacementType::*;
bl_enum! {
    pub enum GlyphPlacementType {
        None          = BL_GLYPH_PLACEMENT_TYPE_NONE,
        AdvanceOffset = BL_GLYPH_PLACEMENT_TYPE_ADVANCE_OFFSET,
        DesignUnits   = BL_GLYPH_PLACEMENT_TYPE_DESIGN_UNITS,
        UserUnits     = BL_GLYPH_PLACEMENT_TYPE_USER_UNITS,
        AbsoluteUnits = BL_GLYPH_PLACEMENT_TYPE_ABSOLUTE_UNITS,
    }
    Default => None
}

use ffi::BLGlyphRunFlags::*;
bitflags! {
    pub struct GlyphRunFlags: u32 {
        const UCS4_CONTENT      = BL_GLYPH_RUN_FLAG_UCS4_CONTENT      as u32;
        const INVALID_TEXT      = BL_GLYPH_RUN_FLAG_INVALID_TEXT      as u32;
        const UNDEFINED_GLYPHS  = BL_GLYPH_RUN_FLAG_UNDEFINED_GLYPHS  as u32;
        const INVALID_FONT_DATA = BL_GLYPH_RUN_FLAG_INVALID_FONT_DATA as u32;
    }
}

use ffi::BLFontFaceType::*;
bl_enum! {
    #[repr(u8)]
    pub enum FontFaceType {
        None     = BL_FONT_FACE_TYPE_NONE,
        OpenType = BL_FONT_FACE_TYPE_OPENTYPE,
    }
    Default => None
}

use ffi::BLFontFaceFlags::*;
bitflags! {
    pub struct FontFaceFlags: u32 {
        const TYPOGRAPHIC_NAMES     = BL_FONT_FACE_FLAG_TYPOGRAPHIC_NAMES     as u32;
        const TYPOGRAPHIC_METRICS   = BL_FONT_FACE_FLAG_TYPOGRAPHIC_METRICS   as u32;
        const CHAR_TO_GLYPH_MAPPING = BL_FONT_FACE_FLAG_CHAR_TO_GLYPH_MAPPING as u32;
        const HORIZONTAL_METIRCS    = BL_FONT_FACE_FLAG_HORIZONTAL_METIRCS    as u32;
        const VERTICAL_METRICS      = BL_FONT_FACE_FLAG_VERTICAL_METRICS      as u32;
        const HORIZONTAL_KERNING    = BL_FONT_FACE_FLAG_HORIZONTAL_KERNING    as u32;
        const VERTICAL_KERNING      = BL_FONT_FACE_FLAG_VERTICAL_KERNING      as u32;
        const OPENTYPE_FEATURES     = BL_FONT_FACE_FLAG_OPENTYPE_FEATURES     as u32;
        const OPENTYPE_VARIATIONS   = BL_FONT_FACE_FLAG_OPENTYPE_VARIATIONS   as u32;
        const PANOSE_DATA           = BL_FONT_FACE_FLAG_PANOSE_DATA           as u32;
        const UNICODE_COVERAGE      = BL_FONT_FACE_FLAG_UNICODE_COVERAGE      as u32;
        const VARIATION_SEQUENCES   = BL_FONT_FACE_FLAG_VARIATION_SEQUENCES   as u32;
        const SYMBOL_FONT           = BL_FONT_FACE_FLAG_SYMBOL_FONT           as u32;
        const LAST_RESORT_FONT      = BL_FONT_FACE_FLAG_LAST_RESORT_FONT      as u32;
    }
}

use ffi::BLFontFaceDiagFlags::*;
bitflags! {
    pub struct FontFaceDiagFlags: u32 {
        const WRONG_NAME_DATA   = BL_FONT_FACE_DIAG_WRONG_NAME_DATA   as u32;
        const FIXED_NAME_DATA   = BL_FONT_FACE_DIAG_FIXED_NAME_DATA   as u32;
        const WRONG_KERN_DATA   = BL_FONT_FACE_DIAG_WRONG_KERN_DATA   as u32;
        const FIXED_KERN_DATA   = BL_FONT_FACE_DIAG_FIXED_KERN_DATA   as u32;
        const WRONG_CMAP_DATA   = BL_FONT_FACE_DIAG_WRONG_CMAP_DATA   as u32;
        const WRONG_CMAP_FORMAT = BL_FONT_FACE_DIAG_WRONG_CMAP_FORMAT as u32;
        const WRONG_GDEF_DATA   = BL_FONT_FACE_DIAG_WRONG_GDEF_DATA   as u32;
        const WRONG_GPOS_DATA   = BL_FONT_FACE_DIAG_WRONG_GPOS_DATA   as u32;
        const WRONG_GSUB_DATA   = BL_FONT_FACE_DIAG_WRONG_GSUB_DATA   as u32;
    }
}

use ffi::BLFontLoaderFlags::*;
bitflags! {
    pub struct FontLoaderFlags: u32 {
        const COLLECTION = BL_FONT_LOADER_FLAG_COLLECTION as u32;
    }
}

use ffi::BLFontOutlineType::*;
bl_enum! {
    #[repr(u8)]
    pub enum FontOutlineType {
        None     = BL_FONT_OUTLINE_TYPE_NONE,
        TrueType = BL_FONT_OUTLINE_TYPE_TRUETYPE,
        Cff      = BL_FONT_OUTLINE_TYPE_CFF,
        Cff2     = BL_FONT_OUTLINE_TYPE_CFF2,
    }
    Default => None
}

use ffi::BLFontStretch::*;
bl_enum! {
    pub enum FontStretch {
        UltraCondensed = BL_FONT_STRETCH_ULTRA_CONDENSED,
        ExtraCondensed = BL_FONT_STRETCH_EXTRA_CONDENSED,
        Condensed      = BL_FONT_STRETCH_CONDENSED,
        SemiCondensed  = BL_FONT_STRETCH_SEMI_CONDENSED,
        Normal         = BL_FONT_STRETCH_NORMAL,
        SemiExpanded   = BL_FONT_STRETCH_SEMI_EXPANDED,
        Expanded       = BL_FONT_STRETCH_EXPANDED,
        ExtraExpanded  = BL_FONT_STRETCH_EXTRA_EXPANDED,
        UltraExpanded  = BL_FONT_STRETCH_ULTRA_EXPANDED,
    }
    Default => Normal
}

use ffi::BLFontStyle::*;
bl_enum! {
    pub enum FontStyle {
        Normal = BL_FONT_STYLE_NORMAL,
        Oblique = BL_FONT_STYLE_OBLIQUE,
        Italic = BL_FONT_STYLE_ITALIC,
    }
    Default => Normal
}

use ffi::BLFontWeight::*;
bl_enum! {
    pub enum FontWeight {
        Thin       = BL_FONT_WEIGHT_THIN,
        ExtraLight = BL_FONT_WEIGHT_EXTRA_LIGHT,
        Light      = BL_FONT_WEIGHT_LIGHT,
        SemiLight  = BL_FONT_WEIGHT_SEMI_LIGHT,
        Normal     = BL_FONT_WEIGHT_NORMAL,
        Medium     = BL_FONT_WEIGHT_MEDIUM,
        SemiBold   = BL_FONT_WEIGHT_SEMI_BOLD,
        Bold       = BL_FONT_WEIGHT_BOLD,
        ExtraBold  = BL_FONT_WEIGHT_EXTRA_BOLD,
        Black      = BL_FONT_WEIGHT_BLACK,
        ExtraBlack = BL_FONT_WEIGHT_EXTRA_BLACK,
    }
    Default => Normal
}

use ffi::BLFontStringId::*;
bl_enum! {
    pub enum FontStringId {
        CopyrightNotice            = BL_FONT_STRING_COPYRIGHT_NOTICE,
        FamilyName                 = BL_FONT_STRING_FAMILY_NAME,
        SubfamilyName              = BL_FONT_STRING_SUBFAMILY_NAME,
        UniqueIdentifier           = BL_FONT_STRING_UNIQUE_IDENTIFIER,
        FullName                   = BL_FONT_STRING_FULL_NAME,
        VersionString              = BL_FONT_STRING_VERSION_STRING,
        PostScriptName             = BL_FONT_STRING_POST_SCRIPT_NAME,
        Trademark                  = BL_FONT_STRING_TRADEMARK,
        ManufacturerName           = BL_FONT_STRING_MANUFACTURER_NAME,
        DesignerName               = BL_FONT_STRING_DESIGNER_NAME,
        Description                = BL_FONT_STRING_DESCRIPTION,
        VendorUrl                  = BL_FONT_STRING_VENDOR_URL,
        DesignerUrl                = BL_FONT_STRING_DESIGNER_URL,
        LicenseDescription         = BL_FONT_STRING_LICENSE_DESCRIPTION,
        LicenseInfoUrl             = BL_FONT_STRING_LICENSE_INFO_URL,
        Reserved                   = BL_FONT_STRING_RESERVED,
        TypographicsFamilyName     = BL_FONT_STRING_TYPOGRAPHIC_FAMILY_NAME,
        TypographicsSubfamilyName  = BL_FONT_STRING_TYPOGRAPHIC_SUBFAMILY_NAME,
        CompatibleFullname         = BL_FONT_STRING_COMPATIBLE_FULL_NAME,
        SampleText                 = BL_FONT_STRING_SAMPLE_TEXT,
        PostScriptCidName          = BL_FONT_STRING_POST_SCRIPT_CID_NAME,
        WwsFamilyName              = BL_FONT_STRING_WWS_FAMILY_NAME,
        WwsSubfamilyName           = BL_FONT_STRING_WWS_SUBFAMILY_NAME,
        LightBackgroundPalette     = BL_FONT_STRING_LIGHT_BACKGROUND_PALETTE,
        DarkBackgroundPalette      = BL_FONT_STRING_DARK_BACKGROUND_PALETTE,
        VariationsPostScriptPrefix = BL_FONT_STRING_VARIATIONS_POST_SCRIPT_PREFIX,
        CommonCount                = BL_FONT_STRING_COMMON_COUNT,
        CustomStartIndex           = BL_FONT_STRING_CUSTOM_START_INDEX,
    }
    Default => Reserved
}

use ffi::BLTextDirection::*;
bl_enum! {
    pub enum TextDirection {
        Ltr = BL_TEXT_DIRECTION_LTR,
        Rtl = BL_TEXT_DIRECTION_RTL,
    }
    Default => Ltr
}

use ffi::BLTextOrientation::*;
bl_enum! {
    pub enum TextOrientation {
        Horizontal = BL_TEXT_ORIENTATION_HORIZONTAL,
        Vertical   = BL_TEXT_ORIENTATION_VERTICAL,
    }
    Default => Horizontal
}

#[cfg(target_endian = "little")]
#[repr(C)]
#[derive(Debug)]
pub struct GlyphItem {
    pub glyph_id: u16,
    reserved: u16,
}

#[cfg(target_endian = "big")]
#[repr(C)]
#[derive(Debug)]
pub struct GlyphItem {
    reserved: u16,
    pub glyph_id: u16,
}

#[allow(dead_code)]
#[repr(C)]
#[derive(Debug)]
pub(in crate) struct GlyphInfo {
    pub cluster: u32,
    reserved: [u32; 2],
}

#[allow(dead_code)]
#[repr(C)]
#[derive(Debug)]
pub(in crate) struct GlyphPlacement {
    pub placement: PointI,
    pub advance: PointI,
}

#[repr(C)]
#[derive(Debug)]
pub struct GlyphMappingState {
    pub glyph_count: usize,
    pub undefined_first: usize,
    pub undefined_count: usize,
}

impl GlyphMappingState {
    pub fn undefined_first(&self) -> Option<usize> {
        if self.undefined_first == !0 {
            None
        } else {
            Some(self.undefined_first)
        }
    }
}

#[allow(dead_code)]
#[repr(C)]
#[derive(Debug)]
pub(in crate) struct GlyphOutlineSinkInfo {
    pub glyph_index: usize,
    pub contour_count: usize,
}

// Fixme figure out what glyph run actually does and expose a proper api
pub struct GlyphRun<'a> {
    pub(in crate) raw: &'a ffi::BLGlyphRun,
}

impl fmt::Debug for GlyphRun<'_> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("GlyphRun").finish()
    }
}

#[repr(C)]
#[derive(Debug)]
pub struct FontFaceInfo {
    pub face_type: FontFaceType,
    pub outline_type: FontOutlineType,
    pub glyph_count: u32,
    pub face_index: u32,
    pub face_flags: FontFaceFlags,
    pub diag_flags: FontFaceDiagFlags,
}

#[allow(dead_code)]
#[repr(C)]
#[derive(Debug)]
pub(in crate) struct FontTable {
    pub data: *const u8,
    pub size: usize,
}
//pub type FontTable<'a> = &'a [u8];

#[repr(C)]
#[derive(Debug)]
pub struct FontFeature {
    pub tag: Tag,
    pub value: u32,
}

#[repr(C)]
#[derive(Debug)]
pub struct FontVariation {
    pub tag: Tag,
    pub value: u32,
}

#[repr(C)]
#[derive(Debug)]
pub struct FontUnicodeCoverage {
    pub data: [u32; 4],
}

#[repr(C)]
#[derive(Debug)]
pub struct FontMatrix(pub [f32; 4]);

#[repr(C)]
#[derive(Debug)]
pub struct FontMetrics {
    pub size: f32,
    pub horizontal_ascent: f32,
    pub vertical_ascent: f32,
    pub horizontal_descent: f32,
    pub vertical_descent: f32,
    pub line_gap: f32,
    pub x_height: f32,
    pub cap_height: f32,
    pub underline_position: f32,
    pub underline_thickness: f32,
    pub strikethrough_position: f32,
    pub strikethrough_thickness: f32,
}

#[repr(C)]
#[derive(Debug, Default)]
pub struct FontDesignMetrics {
    pub units_per_em: i32,
    pub line_gap: i32,
    pub x_height: i32,
    pub cap_height: i32,
    pub horizontal_ascent: i32,
    pub vertical_ascent: i32,
    pub horizontal_descent: i32,
    pub vertical_descent: i32,
    pub horizontal_min_lsb: i32,
    pub vertical_min_lsb: i32,
    pub horizontal_min_tsb: i32,
    pub vertical_min_tsb: i32,
    pub horizontal_max_advance: i32,
    pub vertical_max_advance: i32,
    pub underline_position: i32,
    pub underline_thickness: i32,
    pub strikethrough_position: i32,
    pub strikethrough_thickness: i32,
}

#[repr(C)]
#[derive(Debug, Default)]
pub struct TextMetrics {
    pub advance: PointD,
    pub bounding_box: BoxD,
}