api.odin (14696B)
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 import "core:c" 8 9 when ODIN_OS == .Windows { 10 foreign import lib "blend2d.lib" 11 } else when ODIN_OS == .Darwin { 12 foreign import lib "libblend2d.a" 13 } else when ODIN_OS == .Linux { 14 foreign import lib "libblend2d.a" 15 } 16 17 18 BYTE_ORDER :: 1234 19 20 //! \ingroup bl_globals 21 //! 22 //! Result code used by most Blend2D functions (32-bit unsigned integer). 23 //! 24 //! The \ref BLResultCode enumeration contains Blend2D result codes that contain Blend2D specific set of errors 25 //! and an extended set of errors that can come from WIN32 or POSIX APIs. Since the success result code is zero 26 //! it's recommended to use the following check to determine whether a call failed or not: 27 //! 28 //! ``` 29 //! BLResult result = do_something(); 30 //! if (result != BL_SUCCESS) { 31 //! // `do_something()` failed... 32 //! } 33 //! ``` 34 Result :: u32 35 36 //! \ingroup bl_globals 37 //! 38 //! Tag is a 32-bit integer consisting of 4 characters in the following format: 39 //! 40 //! ``` 41 //! tag = ((a << 24) | (b << 16) | (c << 8) | d) 42 //! ``` 43 //! 44 //! Tags are used extensively by OpenType fonts and other binary formats like PNG. In most cases TAGs should only 45 //! contain ASCII letters, digits, and spaces. 46 //! 47 //! Blend2D uses \ref BLTag in public and internal APIs to distinguish between a regular `uint32_t` and tag. 48 Tag :: u32 49 50 //! \ingroup bl_globals 51 //! 52 //! Unique identifier that can be used for caching purposes. 53 //! 54 //! Some objects such as \ref BLImage and \ref BLFontFace have assigned an unique identifier that can be used to 55 //! identify such objects for caching purposes. This identifier is never zero, so zero can be safely used as 56 //! "uncached". 57 //! 58 //! \note Unique identifier is per-process. It's implemented as an increasing global or thread-local counter in 59 //! a way that identifiers would not collide. 60 UniqueId :: u64 61 62 //! \ingroup bl_globals 63 //! 64 //! BLUnknown is `void` - it's used in places that accept pointer to \ref BLVarCore or any \ref BLObjectCore 65 //! compatible object. 66 Unknown :: struct {} 67 68 //! \ingroup bl_globals 69 //! 70 //! A sink that can be used to debug various parts of Blend2D. 71 DebugMessageSinkFunc :: proc "c" (message: cstring, size: c.size_t, user_data: rawptr) 72 73 //! \ingroup bl_globals 74 //! 75 //! Blend2D result code. 76 ResultCode :: enum u32 { 77 //! Successful result code. 78 SUCCESS = 0, 79 ERROR_START_INDEX = 65536, 80 ERROR_OUT_OF_MEMORY = 65536, //!< Out of memory [ENOMEM]. 81 ERROR_INVALID_VALUE = 65537, //!< Invalid value/argument [EINVAL]. 82 ERROR_INVALID_STATE = 65538, //!< Invalid state [EFAULT]. 83 ERROR_INVALID_HANDLE = 65539, //!< Invalid handle or file. [EBADF]. 84 ERROR_INVALID_CONVERSION = 65540, //!< Invalid conversion. 85 ERROR_OVERFLOW = 65541, //!< Overflow or value too large [EOVERFLOW]. 86 ERROR_NOT_INITIALIZED = 65542, //!< Object not initialized. 87 ERROR_NOT_IMPLEMENTED = 65543, //!< Not implemented [ENOSYS]. 88 ERROR_NOT_PERMITTED = 65544, //!< Operation not permitted [EPERM]. 89 ERROR_IO = 65545, //!< IO error [EIO]. 90 ERROR_BUSY = 65546, //!< Device or resource busy [EBUSY]. 91 ERROR_INTERRUPTED = 65547, //!< Operation interrupted [EINTR]. 92 ERROR_TRY_AGAIN = 65548, //!< Try again [EAGAIN]. 93 ERROR_TIMED_OUT = 65549, //!< Timed out [ETIMEDOUT]. 94 ERROR_BROKEN_PIPE = 65550, //!< Broken pipe [EPIPE]. 95 ERROR_INVALID_SEEK = 65551, //!< File is not seekable [ESPIPE]. 96 ERROR_SYMLINK_LOOP = 65552, //!< Too many levels of symlinks [ELOOP]. 97 ERROR_FILE_TOO_LARGE = 65553, //!< File is too large [EFBIG]. 98 ERROR_ALREADY_EXISTS = 65554, //!< File/directory already exists [EEXIST]. 99 ERROR_ACCESS_DENIED = 65555, //!< Access denied [EACCES]. 100 ERROR_MEDIA_CHANGED = 65556, //!< Media changed [Windows::ERROR_MEDIA_CHANGED]. 101 ERROR_READ_ONLY_FS = 65557, //!< The file/FS is read-only [EROFS]. 102 ERROR_NO_DEVICE = 65558, //!< Device doesn't exist [ENXIO]. 103 ERROR_NO_ENTRY = 65559, //!< Not found, no entry (fs) [ENOENT]. 104 ERROR_NO_MEDIA = 65560, //!< No media in drive/device [ENOMEDIUM]. 105 ERROR_NO_MORE_DATA = 65561, //!< No more data / end of file [ENODATA]. 106 ERROR_NO_MORE_FILES = 65562, //!< No more files [ENMFILE]. 107 ERROR_NO_SPACE_LEFT = 65563, //!< No space left on device [ENOSPC]. 108 ERROR_NOT_EMPTY = 65564, //!< Directory is not empty [ENOTEMPTY]. 109 ERROR_NOT_FILE = 65565, //!< Not a file [EISDIR]. 110 ERROR_NOT_DIRECTORY = 65566, //!< Not a directory [ENOTDIR]. 111 ERROR_NOT_SAME_DEVICE = 65567, //!< Not same device [EXDEV]. 112 ERROR_NOT_BLOCK_DEVICE = 65568, //!< Not a block device [ENOTBLK]. 113 ERROR_INVALID_FILE_NAME = 65569, //!< File/path name is invalid [n/a]. 114 ERROR_FILE_NAME_TOO_LONG = 65570, //!< File/path name is too long [ENAMETOOLONG]. 115 ERROR_TOO_MANY_OPEN_FILES = 65571, //!< Too many open files [EMFILE]. 116 ERROR_TOO_MANY_OPEN_FILES_BY_OS = 65572, //!< Too many open files by OS [ENFILE]. 117 ERROR_TOO_MANY_LINKS = 65573, //!< Too many symbolic links on FS [EMLINK]. 118 ERROR_TOO_MANY_THREADS = 65574, //!< Too many threads [EAGAIN]. 119 ERROR_THREAD_POOL_EXHAUSTED = 65575, //!< Thread pool is exhausted and couldn't acquire the requested thread count. 120 ERROR_FILE_EMPTY = 65576, //!< File is empty (not specific to any OS error). 121 ERROR_OPEN_FAILED = 65577, //!< File open failed [Windows::ERROR_OPEN_FAILED]. 122 ERROR_NOT_ROOT_DEVICE = 65578, //!< Not a root device/directory [Windows::ERROR_DIR_NOT_ROOT]. 123 ERROR_UNKNOWN_SYSTEM_ERROR = 65579, //!< Unknown system error that failed to translate to Blend2D result code. 124 ERROR_INVALID_ALIGNMENT = 65580, //!< Invalid data alignment. 125 ERROR_INVALID_SIGNATURE = 65581, //!< Invalid data signature or header. 126 ERROR_INVALID_DATA = 65582, //!< Invalid or corrupted data. 127 ERROR_INVALID_STRING = 65583, //!< Invalid string (invalid data of either UTF8, UTF16, or UTF32). 128 ERROR_INVALID_KEY = 65584, //!< Invalid key or property. 129 ERROR_DATA_TRUNCATED = 65585, //!< Truncated data (more data required than memory/stream provides). 130 ERROR_DATA_TOO_LARGE = 65586, //!< Input data too large to be processed. 131 ERROR_DECOMPRESSION_FAILED = 65587, //!< Decompression failed due to invalid data (RLE, Huffman, etc). 132 ERROR_INVALID_GEOMETRY = 65588, //!< Invalid geometry (invalid path data or shape). 133 ERROR_NO_MATCHING_VERTEX = 65589, //!< Returned when there is no matching vertex in path data. 134 ERROR_INVALID_CREATE_FLAGS = 65590, //!< Invalid create flags (BLContext). 135 ERROR_NO_MATCHING_COOKIE = 65591, //!< No matching cookie (BLContext). 136 ERROR_NO_STATES_TO_RESTORE = 65592, //!< No states to restore (BLContext). 137 ERROR_TOO_MANY_SAVED_STATES = 65593, //!< Cannot save state as the number of saved states reached the limit (BLContext). 138 ERROR_IMAGE_TOO_LARGE = 65594, //!< The size of the image is too large. 139 ERROR_IMAGE_NO_MATCHING_CODEC = 65595, //!< Image codec for a required format doesn't exist. 140 ERROR_IMAGE_UNKNOWN_FILE_FORMAT = 65596, //!< Unknown or invalid file format that cannot be read. 141 ERROR_IMAGE_DECODER_NOT_PROVIDED = 65597, //!< Image codec doesn't support reading the file format. 142 ERROR_IMAGE_ENCODER_NOT_PROVIDED = 65598, //!< Image codec doesn't support writing the file format. 143 ERROR_PNG_MULTIPLE_IHDR = 65599, //!< Multiple IHDR chunks are not allowed (PNG). 144 ERROR_PNG_INVALID_IDAT = 65600, //!< Invalid IDAT chunk (PNG). 145 ERROR_PNG_INVALID_IEND = 65601, //!< Invalid IEND chunk (PNG). 146 ERROR_PNG_INVALID_PLTE = 65602, //!< Invalid PLTE chunk (PNG). 147 ERROR_PNG_INVALID_TRNS = 65603, //!< Invalid tRNS chunk (PNG). 148 ERROR_PNG_INVALID_FILTER = 65604, //!< Invalid filter type (PNG). 149 ERROR_JPEG_UNSUPPORTED_FEATURE = 65605, //!< Unsupported feature (JPEG). 150 ERROR_JPEG_INVALID_SOS = 65606, //!< Invalid SOS marker or header (JPEG). 151 ERROR_JPEG_INVALID_SOF = 65607, //!< Invalid SOF marker (JPEG). 152 ERROR_JPEG_MULTIPLE_SOF = 65608, //!< Multiple SOF markers (JPEG). 153 ERROR_JPEG_UNSUPPORTED_SOF = 65609, //!< Unsupported SOF marker (JPEG). 154 ERROR_FONT_NOT_INITIALIZED = 65610, //!< Font doesn't have any data as it's not initialized. 155 ERROR_FONT_NO_MATCH = 65611, //!< Font or font face was not matched (BLFontManager). 156 ERROR_FONT_NO_CHARACTER_MAPPING = 65612, //!< Font has no character to glyph mapping data. 157 ERROR_FONT_MISSING_IMPORTANT_TABLE = 65613, //!< Font has missing an important table. 158 ERROR_FONT_FEATURE_NOT_AVAILABLE = 65614, //!< Font feature is not available. 159 ERROR_FONT_CFF_INVALID_DATA = 65615, //!< Font has an invalid CFF data. 160 ERROR_FONT_PROGRAM_TERMINATED = 65616, //!< Font program terminated because the execution reached the limit. 161 ERROR_GLYPH_SUBSTITUTION_TOO_LARGE = 65617, //!< Glyph substitution requires too much space and was terminated. 162 ERROR_INVALID_GLYPH = 65618, //!< Invalid glyph identifier. 163 ERROR_FORCE_UINT = 4294967295, 164 } 165 166 //! \ingroup bl_globals 167 //! 168 //! Byte order. 169 ByteOrder :: enum u32 { 170 //! Little endian byte-order. 171 LE = 0, 172 173 //! Big endian byte-order. 174 BE = 1, 175 176 //! Native (host) byte-order. 177 NATIVE = 0, 178 179 //! Swapped byte-order (BE if host is LE and vice versa). 180 SWAPPED = 1, 181 FORCE_UINT = 4294967295, 182 } 183 184 //! \ingroup bl_globals 185 //! 186 //! Data access flags. 187 DataAccessFlags :: enum u32 { 188 //! No data access flags. 189 NO_FLAGS = 0, 190 191 //! Read access. 192 READ = 1, 193 194 //! Write access. 195 WRITE = 2, 196 197 //! Read and write access. 198 RW = 3, 199 FORCE_UINT = 4294967295, 200 } 201 202 //! \ingroup bl_globals 203 //! 204 //! Data source type. 205 DataSourceType :: enum u32 { 206 //! No data source. 207 NONE = 0, 208 209 //! Memory data source. 210 MEMORY = 1, 211 212 //! File data source. 213 FILE = 2, 214 215 //! Custom data source. 216 CUSTOM = 3, 217 218 //! Maximum value `BLDataSourceType`. 219 MAX_VALUE = 3, 220 FORCE_UINT = 4294967295, 221 } 222 223 //! \ingroup bl_globals 224 //! 225 //! Modification operation applied to Blend2D containers. 226 ModifyOp :: enum u32 { 227 //! Assign operation, which reserves space only to fit the requested input. 228 ASSIGN_FIT = 0, 229 230 //! Assign operation, which takes into consideration successive appends. 231 ASSIGN_GROW = 1, 232 233 //! Append operation, which reserves space only to fit the current and appended content. 234 APPEND_FIT = 2, 235 236 //! Append operation, which takes into consideration successive appends. 237 APPEND_GROW = 3, 238 239 //! Maximum value of `BLModifyOp`. 240 MAX_VALUE = 3, 241 FORCE_UINT = 4294967295, 242 } 243 244 //! \ingroup bl_globals 245 //! 246 //! Boolean operator. 247 BooleanOp :: enum u32 { 248 //! Result = B. 249 COPY = 0, 250 251 //! Result = A & B. 252 AND = 1, 253 254 //! Result = A | B. 255 OR = 2, 256 257 //! Result = A ^ B. 258 XOR = 3, 259 260 //! Result = A & ~B. 261 AND_NOT = 4, 262 263 //! Result = ~A & B. 264 NOT_AND = 5, 265 266 //! Maximum value of `BLBooleanOp`. 267 MAX_VALUE = 5, 268 FORCE_UINT = 4294967295, 269 } 270 271 //! \ingroup bl_styling 272 //! 273 //! Extend mode. 274 ExtendMode :: enum u32 { 275 //! Pad extend [default]. 276 PAD = 0, 277 278 //! Repeat extend. 279 REPEAT = 1, 280 281 //! Reflect extend. 282 REFLECT = 2, 283 284 //! Alias of `BL_EXTEND_MODE_PAD`. 285 PAD_X_PAD_Y = 0, 286 287 //! Pad X and repeat Y. 288 PAD_X_REPEAT_Y = 3, 289 290 //! Pad X and reflect Y. 291 PAD_X_REFLECT_Y = 4, 292 293 //! Alias of `BL_EXTEND_MODE_REPEAT`. 294 REPEAT_X_REPEAT_Y = 1, 295 296 //! Repeat X and pad Y. 297 REPEAT_X_PAD_Y = 5, 298 299 //! Repeat X and reflect Y. 300 REPEAT_X_REFLECT_Y = 6, 301 302 //! Alias of `BL_EXTEND_MODE_REFLECT`. 303 REFLECT_X_REFLECT_Y = 2, 304 305 //! Reflect X and pad Y. 306 REFLECT_X_PAD_Y = 7, 307 308 //! Reflect X and repeat Y. 309 REFLECT_X_REPEAT_Y = 8, 310 311 //! Count of simple extend modes (that use the same value for X and Y). 312 SIMPLE_MAX_VALUE = 2, 313 314 //! Count of complex extend modes (that can use independent values for X and Y). 315 COMPLEX_MAX_VALUE = 8, 316 317 //! Maximum value of `BLExtendMode`. 318 MAX_VALUE = 8, 319 FORCE_UINT = 4294967295, 320 } 321 322 //! \ingroup bl_text 323 //! 324 //! Text encoding. 325 TextEncoding :: enum u32 { 326 //! UTF-8 encoding. 327 UTF8 = 0, 328 329 //! UTF-16 encoding (native endian). 330 UTF16 = 1, 331 332 //! UTF-32 encoding (native endian). 333 UTF32 = 2, 334 335 //! LATIN1 encoding (one byte per character). 336 LATIN1 = 3, 337 338 //! Platform native `wchar_t` (or Windows `WCHAR`) encoding, alias to 339 //! either UTF-32, UTF-16, or UTF-8 depending on `sizeof(wchar_t)`. 340 WCHAR = 2, 341 342 //! Maximum value of `BLTextEncoding`. 343 MAX_VALUE = 3, 344 FORCE_UINT = 4294967295, 345 } 346 347 @(default_calling_convention="c", link_prefix="bl_") 348 foreign lib { 349 //! This function is called by Blend2D when an internal assertion failure happens. 350 //! 351 //! Failing an assertion means that there is either a bug in Blend2D or in user code that uses Blend2D and that the 352 //! state of the application is already corrupted and thus irrecoverable. Note that this would be a fatal error if 353 //! this function gets called in production. 354 runtime_assertion_failure :: proc(file: cstring, line: i32, msg: cstring) --- 355 } 356 357 //! Provides start and end indexes. It has the same semantics as Slices in other programming languages - range is 358 //! always within [star, end) internal (start is inclusive, end is exclusive). It's used to specify a range of an 359 //! operation of indexed containers like \ref BLString, \ref BLArray, \ref BLGradient, \ref BLPath, etc... 360 Range :: struct { 361 start: c.size_t, 362 end: c.size_t, 363 } 364 365 ArrayView :: struct { 366 data: rawptr, 367 size: c.size_t, 368 } 369 370 StringView :: struct { 371 data: cstring, 372 size: c.size_t, 373 } 374 375 DataView :: ArrayView 376