odin-blend2d

Odin bindings to Blend2D
Log | Files | Refs | README | LICENSE

fontface.odin (7420B)


      1 // This file is part of Blend2D project <https://blend2d.com>
      2 //
      3 // See blend2d.h or LICENSE.md for license and copyright information
      4 // SPDX-License-Identifier: Zlib
      5 package blend2d
      6 
      7 when ODIN_OS == .Windows {
      8 	foreign import lib "blend2d.lib"
      9 } else when ODIN_OS == .Darwin {
     10 	foreign import lib "libblend2d.a"
     11 } else when ODIN_OS == .Linux {
     12 	foreign import lib "libblend2d.a"
     13 }
     14 
     15 
     16 //! Flags used by \ref BLFontFace (or \ref BLFontFaceCore)
     17 FontFaceFlags :: enum u32 {
     18 	//! No flags.
     19 	NO_FLAGS                   = 0,
     20 
     21 	//! Font uses typographic family and subfamily names.
     22 	FLAG_TYPOGRAPHIC_NAMES     = 1,
     23 
     24 	//! Font uses typographic metrics.
     25 	FLAG_TYPOGRAPHIC_METRICS   = 2,
     26 
     27 	//! Character to glyph mapping is available.
     28 	FLAG_CHAR_TO_GLYPH_MAPPING = 4,
     29 
     30 	//! Horizontal glyph metrics (advances, side bearings) is available.
     31 	FLAG_HORIZONTAL_METRICS    = 16,
     32 
     33 	//! Vertical glyph metrics (advances, side bearings) is available.
     34 	FLAG_VERTICAL_METRICS      = 32,
     35 
     36 	//! Legacy horizontal kerning feature ('kern' table with horizontal kerning data).
     37 	FLAG_HORIZONTAL_KERNING    = 64,
     38 
     39 	//! Legacy vertical kerning feature ('kern' table with vertical kerning data).
     40 	FLAG_VERTICAL_KERNING      = 128,
     41 
     42 	//! OpenType features (GDEF, GPOS, GSUB) are available.
     43 	FLAG_OPENTYPE_FEATURES     = 256,
     44 
     45 	//! Panose classification is available.
     46 	FLAG_PANOSE_INFO           = 512,
     47 
     48 	//! Unicode coverage information is available.
     49 	FLAG_COVERAGE_INFO         = 1024,
     50 
     51 	//! Baseline for font at `y` equals 0.
     52 	FLAG_BASELINE_Y_EQUALS_0   = 4096,
     53 
     54 	//! Left sidebearing point at `x == 0` (TT only).
     55 	FLAG_LSB_POINT_X_EQUALS_0  = 8192,
     56 
     57 	//! Unicode variation sequences feature is available.
     58 	FLAG_VARIATION_SEQUENCES   = 268435456,
     59 
     60 	//! OpenType Font Variations feature is available.
     61 	FLAG_OPENTYPE_VARIATIONS   = 536870912,
     62 
     63 	//! This is a symbol font.
     64 	FLAG_SYMBOL_FONT           = 1073741824,
     65 
     66 	//! This is a last resort font.
     67 	FLAG_LAST_RESORT_FONT      = 2147483648,
     68 	FLAG_FORCE_UINT            = 4294967295,
     69 }
     70 
     71 //! Diagnostic flags offered by \ref BLFontFace (or \ref BLFontFaceCore).
     72 FontFaceDiagFlags :: enum u32 {
     73 	//! No flags.
     74 	NO_FLAGS          = 0,
     75 
     76 	//! Wrong data in 'name' table.
     77 	WRONG_NAME_DATA   = 1,
     78 
     79 	//! Fixed data read from 'name' table and possibly fixed font family/subfamily name.
     80 	FIXED_NAME_DATA   = 2,
     81 
     82 	//! Wrong data in 'kern' table [kerning disabled].
     83 	WRONG_KERN_DATA   = 4,
     84 
     85 	//! Fixed data read from 'kern' table so it can be used.
     86 	FIXED_KERN_DATA   = 8,
     87 
     88 	//! Wrong data in 'cmap' table.
     89 	WRONG_CMAP_DATA   = 16,
     90 
     91 	//! Wrong format in 'cmap' (sub)table.
     92 	WRONG_CMAP_FORMAT = 32,
     93 	FORCE_UINT        = 4294967295,
     94 }
     95 
     96 //! Format of an outline stored in a font.
     97 FontOutlineType :: enum u32 {
     98 	//! None.
     99 	NONE       = 0,
    100 
    101 	//! Truetype outlines.
    102 	TRUETYPE   = 1,
    103 
    104 	//! OpenType (CFF) outlines.
    105 	CFF        = 2,
    106 
    107 	//! OpenType (CFF2) outlines with font variations support.
    108 	CFF2       = 3,
    109 
    110 	//! Maximum value of `BLFontOutlineType`.
    111 	MAX_VALUE  = 3,
    112 	FORCE_UINT = 4294967295,
    113 }
    114 
    115 //! Information of \ref BLFontFace.
    116 FontFaceInfo :: struct {
    117 	//! \name Members
    118 	//! \{
    119 	
    120 	//! Font face type, see \ref BLFontFaceType.
    121 	face_type: u8,
    122 
    123 	//! Type of outlines used by the font face, see \ref BLFontOutlineType.
    124 	outline_type: u8,
    125 
    126 	//! Reserved fields.
    127 	reserved8: [2]u8,
    128 
    129 	//! Number of glyphs provided by this font face.
    130 	glyph_count: u32,
    131 
    132 	//! Revision (read from 'head' table, represented as 16.16 fixed point).
    133 	revision: u32,
    134 
    135 	//! Face face index in a TTF/OTF collection or zero if not part of a collection.
    136 	face_index: u32,
    137 
    138 	//! Font face flags, see \ref BLFontFaceFlags
    139 	face_flags: u32,
    140 
    141 	//! Font face diagnostic flags, see \ref BLFontFaceDiagFlags.
    142 	diag_flags: u32,
    143 
    144 	//! Reserved for future use, set to zero.
    145 	reserved: [2]u32,
    146 }
    147 
    148 @(default_calling_convention="c", link_prefix="bl_")
    149 foreign lib {
    150 	//! \name BLFontFace - C API
    151 	//! \{
    152 	font_face_init                   :: proc(self: ^FontFaceCore) -> Result ---
    153 	font_face_init_move              :: proc(self: ^FontFaceCore, other: ^FontFaceCore) -> Result ---
    154 	font_face_init_weak              :: proc(self: ^FontFaceCore, other: ^FontFaceCore) -> Result ---
    155 	font_face_destroy                :: proc(self: ^FontFaceCore) -> Result ---
    156 	font_face_reset                  :: proc(self: ^FontFaceCore) -> Result ---
    157 	font_face_assign_move            :: proc(self: ^FontFaceCore, other: ^FontFaceCore) -> Result ---
    158 	font_face_assign_weak            :: proc(self: ^FontFaceCore, other: ^FontFaceCore) -> Result ---
    159 	font_face_equals                 :: proc(a: ^FontFaceCore, b: ^FontFaceCore) -> i32 ---
    160 	font_face_create_from_file       :: proc(self: ^FontFaceCore, file_name: cstring, read_flags: FileReadFlags) -> Result ---
    161 	font_face_create_from_data       :: proc(self: ^FontFaceCore, font_data: ^FontDataCore, face_index: u32) -> Result ---
    162 	font_face_get_full_name          :: proc(self: ^FontFaceCore, out: ^StringCore) -> Result ---
    163 	font_face_get_family_name        :: proc(self: ^FontFaceCore, out: ^StringCore) -> Result ---
    164 	font_face_get_subfamily_name     :: proc(self: ^FontFaceCore, out: ^StringCore) -> Result ---
    165 	font_face_get_post_script_name   :: proc(self: ^FontFaceCore, out: ^StringCore) -> Result ---
    166 	font_face_get_face_info          :: proc(self: ^FontFaceCore, out: ^FontFaceInfo) -> Result ---
    167 	font_face_get_design_metrics     :: proc(self: ^FontFaceCore, out: ^FontDesignMetrics) -> Result ---
    168 	font_face_get_coverage_info      :: proc(self: ^FontFaceCore, out: ^FontCoverageInfo) -> Result ---
    169 	font_face_get_panose_info        :: proc(self: ^FontFaceCore, out: ^FontPanoseInfo) -> Result ---
    170 	font_face_get_character_coverage :: proc(self: ^FontFaceCore, out: ^BitSetCore) -> Result ---
    171 	font_face_has_script_tag         :: proc(self: ^FontFaceCore, script_tag: Tag) -> i32 ---
    172 	font_face_has_feature_tag        :: proc(self: ^FontFaceCore, feature_tag: Tag) -> i32 ---
    173 	font_face_has_variation_tag      :: proc(self: ^FontFaceCore, variation_tag: Tag) -> i32 ---
    174 	font_face_get_script_tags        :: proc(self: ^FontFaceCore, out: ^ArrayCore) -> Result ---
    175 	font_face_get_feature_tags       :: proc(self: ^FontFaceCore, out: ^ArrayCore) -> Result ---
    176 	font_face_get_variation_tags     :: proc(self: ^FontFaceCore, out: ^ArrayCore) -> Result ---
    177 }
    178 
    179 //! Font face [C API].
    180 FontFaceCore :: struct {
    181 	_d: ObjectDetail,
    182 }
    183 
    184 //! \cond INTERNAL
    185 //! Font face [C API Virtual Function Table].
    186 FontFaceVirt :: struct {
    187 	base: ObjectVirtBase,
    188 }
    189 
    190 //! Font face [C API Impl].
    191 FontFaceImpl :: struct {
    192 	//! Virtual function table.
    193 	virt: ^FontFaceVirt,
    194 
    195 	//! Font face default weight (1..1000) [0 if font face is not initialized].
    196 	weight: u16,
    197 
    198 	//! Font face default stretch (1..9) [0 if font face is not initialized].
    199 	stretch: u8,
    200 
    201 	//! Font face default style.
    202 	style: u8,
    203 
    204 	//! Font face information.
    205 	face_info: FontFaceInfo,
    206 
    207 	//! Unique identifier assigned by Blend2D that can be used for caching.
    208 	unique_id: UniqueId,
    209 
    210 	//! Font data.
    211 	data: FontDataCore,
    212 
    213 	//! Full name.
    214 	full_name: StringCore,
    215 
    216 	//! Family name.
    217 	family_name: StringCore,
    218 
    219 	//! Subfamily name.
    220 	subfamily_name: StringCore,
    221 
    222 	//! PostScript name.
    223 	post_script_name: StringCore,
    224 
    225 	//! Font face metrics in design units.
    226 	design_metrics: FontDesignMetrics,
    227 
    228 	//! Font face unicode coverage information as specified in the "OS/2" header.
    229 	coverage_info: FontCoverageInfo,
    230 
    231 	//! Font face panose classification.
    232 	panose_info: FontPanoseInfo,
    233 }
    234