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
use std::fmt;
use ffi;

pub type FtResult<T> = Result<T, Error>;

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[repr(i32)]
pub enum Error {
    Ok                          = ffi::FT_Err_Ok,
    CannotOpenResource          = ffi::FT_Err_Cannot_Open_Resource,
    UnknownFileFormat           = ffi::FT_Err_Unknown_File_Format,
    InvalidFileFormat           = ffi::FT_Err_Invalid_File_Format,
    InvalidVersion              = ffi::FT_Err_Invalid_Version,
    LowerModuleVersion          = ffi::FT_Err_Lower_Module_Version,
    InvalidArgument             = ffi::FT_Err_Invalid_Argument,
    UnimplementedFeature        = ffi::FT_Err_Unimplemented_Feature,
    InvalidTable                = ffi::FT_Err_Invalid_Table,
    InvalidOffset               = ffi::FT_Err_Invalid_Offset,
    ArrayTooLarge               = ffi::FT_Err_Array_Too_Large,
    MissingModule               = ffi::FT_Err_Missing_Module,
    MissingProperty             = ffi::FT_Err_Missing_Property,
    InvalidGlyphIndex           = ffi::FT_Err_Invalid_Glyph_Index,
    InvalidCharacterCode        = ffi::FT_Err_Invalid_Character_Code,
    InvalidGlyphFormat          = ffi::FT_Err_Invalid_Glyph_Format,
    CannotRenderGlyph           = ffi::FT_Err_Cannot_Render_Glyph,
    InvalidOutline              = ffi::FT_Err_Invalid_Outline,
    InvalidComposite            = ffi::FT_Err_Invalid_Composite,
    TooManyHints                = ffi::FT_Err_Too_Many_Hints,
    InvalidPixelSize            = ffi::FT_Err_Invalid_Pixel_Size,
    InvalidHandle               = ffi::FT_Err_Invalid_Handle,
    InvalidLibraryHandle        = ffi::FT_Err_Invalid_Library_Handle,
    InvalidDriverHandle         = ffi::FT_Err_Invalid_Driver_Handle,
    InvalidFaceHandle           = ffi::FT_Err_Invalid_Face_Handle,
    InvalidSizeHandle           = ffi::FT_Err_Invalid_Size_Handle,
    InvalidSlotHandle           = ffi::FT_Err_Invalid_Slot_Handle,
    InvalidCharMapHandle        = ffi::FT_Err_Invalid_CharMap_Handle,
    InvalidCacheHandle          = ffi::FT_Err_Invalid_Cache_Handle,
    InvalidStreamHandle         = ffi::FT_Err_Invalid_Stream_Handle,
    TooManyDrivers              = ffi::FT_Err_Too_Many_Drivers,
    TooManyExtensions           = ffi::FT_Err_Too_Many_Extensions,
    OutOfMemory                 = ffi::FT_Err_Out_Of_Memory,
    UnlistedObject              = ffi::FT_Err_Unlisted_Object,
    CannotOpenStream            = ffi::FT_Err_Cannot_Open_Stream,
    InvalidStreamSeek           = ffi::FT_Err_Invalid_Stream_Seek,
    InvalidStreamSkip           = ffi::FT_Err_Invalid_Stream_Skip,
    InvalidStreamRead           = ffi::FT_Err_Invalid_Stream_Read,
    InvalidStreamOperation      = ffi::FT_Err_Invalid_Stream_Operation,
    InvalidFrameOperation       = ffi::FT_Err_Invalid_Frame_Operation,
    NestedFrameAccess           = ffi::FT_Err_Nested_Frame_Access,
    InvalidFrameRead            = ffi::FT_Err_Invalid_Frame_Read,
    RasterUninitialized         = ffi::FT_Err_Raster_Uninitialized,
    RasterCorrupted             = ffi::FT_Err_Raster_Corrupted,
    RasterOverflow              = ffi::FT_Err_Raster_Overflow,
    RasterNegativeHeight        = ffi::FT_Err_Raster_Negative_Height,
    TooManyCaches               = ffi::FT_Err_Too_Many_Caches,
    InvalidOpcode               = ffi::FT_Err_Invalid_Opcode,
    TooFewArguments             = ffi::FT_Err_Too_Few_Arguments,
    StackOverflow               = ffi::FT_Err_Stack_Overflow,
    CodeOverflow                = ffi::FT_Err_Code_Overflow,
    BadArgument                 = ffi::FT_Err_Bad_Argument,
    DivideByZero                = ffi::FT_Err_Divide_By_Zero,
    InvalidReference            = ffi::FT_Err_Invalid_Reference,
    DebugOpCode                 = ffi::FT_Err_Debug_OpCode,
    ENDFInExecStream            = ffi::FT_Err_ENDF_In_Exec_Stream,
    NestedDEFS                  = ffi::FT_Err_Nested_DEFS,
    InvalidCodeRange            = ffi::FT_Err_Invalid_CodeRange,
    ExecutionTooLong            = ffi::FT_Err_Execution_Too_Long,
    TooManyFunctionDefs         = ffi::FT_Err_Too_Many_Function_Defs,
    TooManyInstructionDefs      = ffi::FT_Err_Too_Many_Instruction_Defs,
    TableMissing                = ffi::FT_Err_Table_Missing,
    HorizHeaderMissing          = ffi::FT_Err_Horiz_Header_Missing,
    LocationsMissing            = ffi::FT_Err_Locations_Missing,
    NameTableMissing            = ffi::FT_Err_Name_Table_Missing,
    CMapTableMissing            = ffi::FT_Err_CMap_Table_Missing,
    HmtxTableMissing            = ffi::FT_Err_Hmtx_Table_Missing,
    PostTableMissing            = ffi::FT_Err_Post_Table_Missing,
    InvalidHorizMetrics         = ffi::FT_Err_Invalid_Horiz_Metrics,
    InvalidCharMapFormat        = ffi::FT_Err_Invalid_CharMap_Format,
    InvalidPPem                 = ffi::FT_Err_Invalid_PPem,
    InvalidVertMetrics          = ffi::FT_Err_Invalid_Vert_Metrics,
    CouldNotFindContext         = ffi::FT_Err_Could_Not_Find_Context,
    InvalidPostTableFormat      = ffi::FT_Err_Invalid_Post_Table_Format,
    InvalidPostTable            = ffi::FT_Err_Invalid_Post_Table,
    Syntax                      = ffi::FT_Err_Syntax_Error,
    StackUnderflow              = ffi::FT_Err_Stack_Underflow,
    Ignore                      = ffi::FT_Err_Ignore,
    NoUnicodeGlyphName          = ffi::FT_Err_No_Unicode_Glyph_Name,
    MissingStartfontField       = ffi::FT_Err_Missing_Startfont_Field,
    MissingFontField            = ffi::FT_Err_Missing_Font_Field,
    MissingSizeField            = ffi::FT_Err_Missing_Size_Field,
    MissingFontboundingboxField = ffi::FT_Err_Missing_Fontboundingbox_Field,
    MissingCharsField           = ffi::FT_Err_Missing_Chars_Field,
    MissingStartcharField       = ffi::FT_Err_Missing_Startchar_Field,
    MissingEncodingField        = ffi::FT_Err_Missing_Encoding_Field,
    MissingBbxField             = ffi::FT_Err_Missing_Bbx_Field,
    BbxTooBig                   = ffi::FT_Err_Bbx_Too_Big,
    CorruptedFontHeader         = ffi::FT_Err_Corrupted_Font_Header,
    CorruptedFontGlyphs         = ffi::FT_Err_Corrupted_Font_Glyphs,
    Max                         = ffi::FT_Err_Max,
    UnexpectedPixelMode,
    InvalidPath,
    Unknown
}

impl From<i32> for Error {
    fn from(err: i32) -> Self {
        match err {
            ffi::FT_Err_Ok                            => Error::Ok,
            ffi::FT_Err_Cannot_Open_Resource          => Error::CannotOpenResource,
            ffi::FT_Err_Unknown_File_Format           => Error::UnknownFileFormat,
            ffi::FT_Err_Invalid_File_Format           => Error::InvalidFileFormat,
            ffi::FT_Err_Invalid_Version               => Error::InvalidVersion,
            ffi::FT_Err_Lower_Module_Version          => Error::LowerModuleVersion,
            ffi::FT_Err_Invalid_Argument              => Error::InvalidArgument,
            ffi::FT_Err_Unimplemented_Feature         => Error::UnimplementedFeature,
            ffi::FT_Err_Invalid_Table                 => Error::InvalidTable,
            ffi::FT_Err_Invalid_Offset                => Error::InvalidOffset,
            ffi::FT_Err_Array_Too_Large               => Error::ArrayTooLarge,
            ffi::FT_Err_Missing_Module                => Error::MissingModule,
            ffi::FT_Err_Missing_Property              => Error::MissingProperty,
            ffi::FT_Err_Invalid_Glyph_Index           => Error::InvalidGlyphIndex,
            ffi::FT_Err_Invalid_Character_Code        => Error::InvalidCharacterCode,
            ffi::FT_Err_Invalid_Glyph_Format          => Error::InvalidGlyphFormat,
            ffi::FT_Err_Cannot_Render_Glyph           => Error::CannotRenderGlyph,
            ffi::FT_Err_Invalid_Outline               => Error::InvalidOutline,
            ffi::FT_Err_Invalid_Composite             => Error::InvalidComposite,
            ffi::FT_Err_Too_Many_Hints                => Error::TooManyHints,
            ffi::FT_Err_Invalid_Pixel_Size            => Error::InvalidPixelSize,
            ffi::FT_Err_Invalid_Handle                => Error::InvalidHandle,
            ffi::FT_Err_Invalid_Library_Handle        => Error::InvalidLibraryHandle,
            ffi::FT_Err_Invalid_Driver_Handle         => Error::InvalidDriverHandle,
            ffi::FT_Err_Invalid_Face_Handle           => Error::InvalidFaceHandle,
            ffi::FT_Err_Invalid_Size_Handle           => Error::InvalidSizeHandle,
            ffi::FT_Err_Invalid_Slot_Handle           => Error::InvalidSlotHandle,
            ffi::FT_Err_Invalid_CharMap_Handle        => Error::InvalidCharMapHandle,
            ffi::FT_Err_Invalid_Cache_Handle          => Error::InvalidCacheHandle,
            ffi::FT_Err_Invalid_Stream_Handle         => Error::InvalidStreamHandle,
            ffi::FT_Err_Too_Many_Drivers              => Error::TooManyDrivers,
            ffi::FT_Err_Too_Many_Extensions           => Error::TooManyExtensions,
            ffi::FT_Err_Out_Of_Memory                 => Error::OutOfMemory,
            ffi::FT_Err_Unlisted_Object               => Error::UnlistedObject,
            ffi::FT_Err_Cannot_Open_Stream            => Error::CannotOpenStream,
            ffi::FT_Err_Invalid_Stream_Seek           => Error::InvalidStreamSeek,
            ffi::FT_Err_Invalid_Stream_Skip           => Error::InvalidStreamSkip,
            ffi::FT_Err_Invalid_Stream_Read           => Error::InvalidStreamRead,
            ffi::FT_Err_Invalid_Stream_Operation      => Error::InvalidStreamOperation,
            ffi::FT_Err_Invalid_Frame_Operation       => Error::InvalidFrameOperation,
            ffi::FT_Err_Nested_Frame_Access           => Error::NestedFrameAccess,
            ffi::FT_Err_Invalid_Frame_Read            => Error::InvalidFrameRead,
            ffi::FT_Err_Raster_Uninitialized          => Error::RasterUninitialized,
            ffi::FT_Err_Raster_Corrupted              => Error::RasterCorrupted,
            ffi::FT_Err_Raster_Overflow               => Error::RasterOverflow,
            ffi::FT_Err_Raster_Negative_Height        => Error::RasterNegativeHeight,
            ffi::FT_Err_Too_Many_Caches               => Error::TooManyCaches,
            ffi::FT_Err_Invalid_Opcode                => Error::InvalidOpcode,
            ffi::FT_Err_Too_Few_Arguments             => Error::TooFewArguments,
            ffi::FT_Err_Stack_Overflow                => Error::StackOverflow,
            ffi::FT_Err_Code_Overflow                 => Error::CodeOverflow,
            ffi::FT_Err_Bad_Argument                  => Error::BadArgument,
            ffi::FT_Err_Divide_By_Zero                => Error::DivideByZero,
            ffi::FT_Err_Invalid_Reference             => Error::InvalidReference,
            ffi::FT_Err_Debug_OpCode                  => Error::DebugOpCode,
            ffi::FT_Err_ENDF_In_Exec_Stream           => Error::ENDFInExecStream,
            ffi::FT_Err_Nested_DEFS                   => Error::NestedDEFS,
            ffi::FT_Err_Invalid_CodeRange             => Error::InvalidCodeRange,
            ffi::FT_Err_Execution_Too_Long            => Error::ExecutionTooLong,
            ffi::FT_Err_Too_Many_Function_Defs        => Error::TooManyFunctionDefs,
            ffi::FT_Err_Too_Many_Instruction_Defs     => Error::TooManyInstructionDefs,
            ffi::FT_Err_Table_Missing                 => Error::TableMissing,
            ffi::FT_Err_Horiz_Header_Missing          => Error::HorizHeaderMissing,
            ffi::FT_Err_Locations_Missing             => Error::LocationsMissing,
            ffi::FT_Err_Name_Table_Missing            => Error::NameTableMissing,
            ffi::FT_Err_CMap_Table_Missing            => Error::CMapTableMissing,
            ffi::FT_Err_Hmtx_Table_Missing            => Error::HmtxTableMissing,
            ffi::FT_Err_Post_Table_Missing            => Error::PostTableMissing,
            ffi::FT_Err_Invalid_Horiz_Metrics         => Error::InvalidHorizMetrics,
            ffi::FT_Err_Invalid_CharMap_Format        => Error::InvalidCharMapFormat,
            ffi::FT_Err_Invalid_PPem                  => Error::InvalidPPem,
            ffi::FT_Err_Invalid_Vert_Metrics          => Error::InvalidVertMetrics,
            ffi::FT_Err_Could_Not_Find_Context        => Error::CouldNotFindContext,
            ffi::FT_Err_Invalid_Post_Table_Format     => Error::InvalidPostTableFormat,
            ffi::FT_Err_Invalid_Post_Table            => Error::InvalidPostTable,
            ffi::FT_Err_Syntax_Error                  => Error::Syntax,
            ffi::FT_Err_Stack_Underflow               => Error::StackUnderflow,
            ffi::FT_Err_Ignore                        => Error::Ignore,
            ffi::FT_Err_No_Unicode_Glyph_Name         => Error::NoUnicodeGlyphName,
            ffi::FT_Err_Missing_Startfont_Field       => Error::MissingStartfontField,
            ffi::FT_Err_Missing_Font_Field            => Error::MissingFontField,
            ffi::FT_Err_Missing_Size_Field            => Error::MissingSizeField,
            ffi::FT_Err_Missing_Fontboundingbox_Field => Error::MissingFontboundingboxField,
            ffi::FT_Err_Missing_Chars_Field           => Error::MissingCharsField,
            ffi::FT_Err_Missing_Startchar_Field       => Error::MissingStartcharField,
            ffi::FT_Err_Missing_Encoding_Field        => Error::MissingEncodingField,
            ffi::FT_Err_Missing_Bbx_Field             => Error::MissingBbxField,
            ffi::FT_Err_Bbx_Too_Big                   => Error::BbxTooBig,
            ffi::FT_Err_Corrupted_Font_Header         => Error::CorruptedFontHeader,
            ffi::FT_Err_Corrupted_Font_Glyphs         => Error::CorruptedFontGlyphs,
            ffi::FT_Err_Max                           => Error::Max,
            _                                         => Error::Unknown
        }
    }
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        fmt::Debug::fmt(self, f)
    }
}