From 5f859adab9c62871513ecaf189374e346eab55eb Mon Sep 17 00:00:00 2001 From: "H. Utku Maden" Date: Sat, 8 Jul 2023 15:32:01 +0300 Subject: [PATCH] Create preliminary bindings for stb libraries. --- Quik.StbImage.redist/quik_stbi.h | 5 + Quik.StbImage/NativeTypeNameAttribute.cs | 12 + Quik.StbImage/Stbi.cs | 177 +++++++ Quik.StbImage/clangsharp.rsp | 30 ++ Quik.StbTrueType/NativeTypeNameAttribute.cs | 12 + Quik.StbTrueType/Stbtt.cs | 495 ++++++++++++++++++++ Quik.StbTrueType/clangsharp.rsp | 30 ++ lib/quik/quik_common.h | 3 - 8 files changed, 761 insertions(+), 3 deletions(-) create mode 100644 Quik.StbImage/NativeTypeNameAttribute.cs create mode 100644 Quik.StbImage/Stbi.cs create mode 100644 Quik.StbImage/clangsharp.rsp create mode 100644 Quik.StbTrueType/NativeTypeNameAttribute.cs create mode 100644 Quik.StbTrueType/Stbtt.cs create mode 100644 Quik.StbTrueType/clangsharp.rsp diff --git a/Quik.StbImage.redist/quik_stbi.h b/Quik.StbImage.redist/quik_stbi.h index 4f9d579..f31558b 100644 --- a/Quik.StbImage.redist/quik_stbi.h +++ b/Quik.StbImage.redist/quik_stbi.h @@ -5,9 +5,14 @@ QUIK_DECLARE_LIB(quik_stbi) +/* TODO: Change this declaration so we can export a DLL properly in windows. */ +#define STBIDEF QEXTERN + #define STBI_ASSERT(EXPR) do { \ if (!(EXPR)) \ quik_stbi_failed_assert(#EXPR, __FILE__, __LINE__ - 2, __QUIK_FUNCTION__); \ } while(0) +#include "stb/stb_image.h" + #endif diff --git a/Quik.StbImage/NativeTypeNameAttribute.cs b/Quik.StbImage/NativeTypeNameAttribute.cs new file mode 100644 index 0000000..becb962 --- /dev/null +++ b/Quik.StbImage/NativeTypeNameAttribute.cs @@ -0,0 +1,12 @@ +using System; + +namespace Quik.Stb.Image +{ + [AttributeUsage(System.AttributeTargets.All, Inherited = false, AllowMultiple = true)] + internal sealed class NativeTypeNameAttribute : System.Attribute + { + public NativeTypeNameAttribute(string typename) + { + } + } +} diff --git a/Quik.StbImage/Stbi.cs b/Quik.StbImage/Stbi.cs new file mode 100644 index 0000000..55cab4b --- /dev/null +++ b/Quik.StbImage/Stbi.cs @@ -0,0 +1,177 @@ +using System; +using System.Runtime.InteropServices; +using Quik.Stb.Image; + +namespace Quik.Stb +{ + [NativeTypeName("unsigned int")] + public enum StbiEnum : uint + { + STBI_default = 0, + STBI_grey = 1, + STBI_grey_alpha = 2, + STBI_rgb = 3, + STBI_rgb_alpha = 4, + } + + public partial struct stbi_io_callbacks + { + [NativeTypeName("int (*)(void *, char *, int)")] + public IntPtr read; + + [NativeTypeName("void (*)(void *, int)")] + public IntPtr skip; + + [NativeTypeName("int (*)(void *)")] + public IntPtr eof; + } + + public static unsafe partial class Stbi + { + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void quik_stbi_failed_assert_store([NativeTypeName("quik_failed_assert_cb_t")] IntPtr cb); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_load_from_memory", ExactSpelling = true)] + [return: NativeTypeName("stbi_uc *")] + public static extern byte* load_from_memory([NativeTypeName("const stbi_uc *")] byte* buffer, int len, int* x, int* y, int* channels_in_file, int desired_channels); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_load_from_callbacks", ExactSpelling = true)] + [return: NativeTypeName("stbi_uc *")] + public static extern byte* load_from_callbacks([NativeTypeName("const stbi_io_callbacks *")] stbi_io_callbacks* clbk, void* user, int* x, int* y, int* channels_in_file, int desired_channels); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_load", ExactSpelling = true)] + [return: NativeTypeName("stbi_uc *")] + public static extern byte* load([NativeTypeName("const char *")] sbyte* filename, int* x, int* y, int* channels_in_file, int desired_channels); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_load_from_file", ExactSpelling = true)] + [return: NativeTypeName("stbi_uc *")] + public static extern byte* load_from_file([NativeTypeName("FILE *")] void* f, int* x, int* y, int* channels_in_file, int desired_channels); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_load_gif_from_memory", ExactSpelling = true)] + [return: NativeTypeName("stbi_uc *")] + public static extern byte* load_gif_from_memory([NativeTypeName("const stbi_uc *")] byte* buffer, int len, int** delays, int* x, int* y, int* z, int* comp, int req_comp); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_load_16_from_memory", ExactSpelling = true)] + [return: NativeTypeName("stbi_us *")] + public static extern ushort* load_16_from_memory([NativeTypeName("const stbi_uc *")] byte* buffer, int len, int* x, int* y, int* channels_in_file, int desired_channels); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_load_16_from_callbacks", ExactSpelling = true)] + [return: NativeTypeName("stbi_us *")] + public static extern ushort* load_16_from_callbacks([NativeTypeName("const stbi_io_callbacks *")] stbi_io_callbacks* clbk, void* user, int* x, int* y, int* channels_in_file, int desired_channels); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_load_16", ExactSpelling = true)] + [return: NativeTypeName("stbi_us *")] + public static extern ushort* load_16([NativeTypeName("const char *")] sbyte* filename, int* x, int* y, int* channels_in_file, int desired_channels); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_load_from_file_16", ExactSpelling = true)] + [return: NativeTypeName("stbi_us *")] + public static extern ushort* load_from_file_16([NativeTypeName("FILE *")] void* f, int* x, int* y, int* channels_in_file, int desired_channels); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_loadf_from_memory", ExactSpelling = true)] + public static extern float* loadf_from_memory([NativeTypeName("const stbi_uc *")] byte* buffer, int len, int* x, int* y, int* channels_in_file, int desired_channels); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_loadf_from_callbacks", ExactSpelling = true)] + public static extern float* loadf_from_callbacks([NativeTypeName("const stbi_io_callbacks *")] stbi_io_callbacks* clbk, void* user, int* x, int* y, int* channels_in_file, int desired_channels); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_loadf", ExactSpelling = true)] + public static extern float* loadf([NativeTypeName("const char *")] sbyte* filename, int* x, int* y, int* channels_in_file, int desired_channels); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_loadf_from_file", ExactSpelling = true)] + public static extern float* loadf_from_file([NativeTypeName("FILE *")] void* f, int* x, int* y, int* channels_in_file, int desired_channels); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_hdr_to_ldr_gamma", ExactSpelling = true)] + public static extern void hdr_to_ldr_gamma(float gamma); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_hdr_to_ldr_scale", ExactSpelling = true)] + public static extern void hdr_to_ldr_scale(float scale); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_ldr_to_hdr_gamma", ExactSpelling = true)] + public static extern void ldr_to_hdr_gamma(float gamma); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_ldr_to_hdr_scale", ExactSpelling = true)] + public static extern void ldr_to_hdr_scale(float scale); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_is_hdr_from_callbacks", ExactSpelling = true)] + public static extern int is_hdr_from_callbacks([NativeTypeName("const stbi_io_callbacks *")] stbi_io_callbacks* clbk, void* user); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_is_hdr_from_memory", ExactSpelling = true)] + public static extern int is_hdr_from_memory([NativeTypeName("const stbi_uc *")] byte* buffer, int len); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_is_hdr", ExactSpelling = true)] + public static extern int is_hdr([NativeTypeName("const char *")] sbyte* filename); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_is_hdr_from_file", ExactSpelling = true)] + public static extern int is_hdr_from_file([NativeTypeName("FILE *")] void* f); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_failure_reason", ExactSpelling = true)] + [return: NativeTypeName("const char *")] + public static extern sbyte* failure_reason(); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_image_free", ExactSpelling = true)] + public static extern void image_free(void* retval_from_stbi_load); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_info_from_memory", ExactSpelling = true)] + public static extern int info_from_memory([NativeTypeName("const stbi_uc *")] byte* buffer, int len, int* x, int* y, int* comp); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_info_from_callbacks", ExactSpelling = true)] + public static extern int info_from_callbacks([NativeTypeName("const stbi_io_callbacks *")] stbi_io_callbacks* clbk, void* user, int* x, int* y, int* comp); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_is_16_bit_from_memory", ExactSpelling = true)] + public static extern int is_16_bit_from_memory([NativeTypeName("const stbi_uc *")] byte* buffer, int len); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_is_16_bit_from_callbacks", ExactSpelling = true)] + public static extern int is_16_bit_from_callbacks([NativeTypeName("const stbi_io_callbacks *")] stbi_io_callbacks* clbk, void* user); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_info", ExactSpelling = true)] + public static extern int info([NativeTypeName("const char *")] sbyte* filename, int* x, int* y, int* comp); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_info_from_file", ExactSpelling = true)] + public static extern int info_from_file([NativeTypeName("FILE *")] void* f, int* x, int* y, int* comp); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_is_16_bit", ExactSpelling = true)] + public static extern int is_16_bit([NativeTypeName("const char *")] sbyte* filename); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_is_16_bit_from_file", ExactSpelling = true)] + public static extern int is_16_bit_from_file([NativeTypeName("FILE *")] void* f); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_set_unpremultiply_on_load", ExactSpelling = true)] + public static extern void set_unpremultiply_on_load(int flag_true_if_should_unpremultiply); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_convert_iphone_png_to_rgb", ExactSpelling = true)] + public static extern void convert_iphone_png_to_rgb(int flag_true_if_should_convert); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_set_flip_vertically_on_load", ExactSpelling = true)] + public static extern void set_flip_vertically_on_load(int flag_true_if_should_flip); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_set_unpremultiply_on_load_thread", ExactSpelling = true)] + public static extern void set_unpremultiply_on_load_thread(int flag_true_if_should_unpremultiply); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_convert_iphone_png_to_rgb_thread", ExactSpelling = true)] + public static extern void convert_iphone_png_to_rgb_thread(int flag_true_if_should_convert); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_set_flip_vertically_on_load_thread", ExactSpelling = true)] + public static extern void set_flip_vertically_on_load_thread(int flag_true_if_should_flip); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_zlib_decode_malloc_guesssize", ExactSpelling = true)] + [return: NativeTypeName("char *")] + public static extern sbyte* zlib_decode_malloc_guesssize([NativeTypeName("const char *")] sbyte* buffer, int len, int initial_size, int* outlen); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_zlib_decode_malloc_guesssize_headerflag", ExactSpelling = true)] + [return: NativeTypeName("char *")] + public static extern sbyte* zlib_decode_malloc_guesssize_headerflag([NativeTypeName("const char *")] sbyte* buffer, int len, int initial_size, int* outlen, int parse_header); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_zlib_decode_malloc", ExactSpelling = true)] + [return: NativeTypeName("char *")] + public static extern sbyte* zlib_decode_malloc([NativeTypeName("const char *")] sbyte* buffer, int len, int* outlen); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_zlib_decode_buffer", ExactSpelling = true)] + public static extern int zlib_decode_buffer([NativeTypeName("char *")] sbyte* obuffer, int olen, [NativeTypeName("const char *")] sbyte* ibuffer, int ilen); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_zlib_decode_noheader_malloc", ExactSpelling = true)] + [return: NativeTypeName("char *")] + public static extern sbyte* zlib_decode_noheader_malloc([NativeTypeName("const char *")] sbyte* buffer, int len, int* outlen); + + [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_zlib_decode_noheader_buffer", ExactSpelling = true)] + public static extern int zlib_decode_noheader_buffer([NativeTypeName("char *")] sbyte* obuffer, int olen, [NativeTypeName("const char *")] sbyte* ibuffer, int ilen); + } +} diff --git a/Quik.StbImage/clangsharp.rsp b/Quik.StbImage/clangsharp.rsp new file mode 100644 index 0000000..d0ebfed --- /dev/null +++ b/Quik.StbImage/clangsharp.rsp @@ -0,0 +1,30 @@ +-x + c +-l + stbi +--config + compatible-codegen + single-file + exclude-fnptr-codegen + generate-aggressive-inlining + generate-setslastsystemerror-attribute + unix-types +--include-directory + ../lib +--include-directory + ../Quik.StbImage +--include-directory + /usr/lib/llvm-14/lib/clang/14.0.6/include +--file + ../Quik.StbImage.redist/quik_stbi.h + ../lib/stb/stb_image.h +--methodClassName + Stbi +--namespace + Quik.Stb +--output + Stbi.cs +--prefixStrip + stbi_ +--with-type + FILE=void diff --git a/Quik.StbTrueType/NativeTypeNameAttribute.cs b/Quik.StbTrueType/NativeTypeNameAttribute.cs new file mode 100644 index 0000000..72d9fb2 --- /dev/null +++ b/Quik.StbTrueType/NativeTypeNameAttribute.cs @@ -0,0 +1,12 @@ +using System; + +namespace Quik.Stb.TrueType +{ + [AttributeUsage(System.AttributeTargets.All, Inherited = false, AllowMultiple = true)] + internal sealed class NativeTypeNameAttribute : System.Attribute + { + public NativeTypeNameAttribute(string typename) + { + } + } +} diff --git a/Quik.StbTrueType/Stbtt.cs b/Quik.StbTrueType/Stbtt.cs new file mode 100644 index 0000000..81e2c0f --- /dev/null +++ b/Quik.StbTrueType/Stbtt.cs @@ -0,0 +1,495 @@ +using System; +using System.Runtime.InteropServices; +using Quik.Stb.TrueType; + +namespace Quik.Stb +{ + public unsafe partial struct stbtt__buf + { + [NativeTypeName("unsigned char *")] + public byte* data; + + public int cursor; + + public int size; + } + + public partial struct stbtt_bakedchar + { + [NativeTypeName("unsigned short")] + public ushort x0; + + [NativeTypeName("unsigned short")] + public ushort y0; + + [NativeTypeName("unsigned short")] + public ushort x1; + + [NativeTypeName("unsigned short")] + public ushort y1; + + public float xoff; + + public float yoff; + + public float xadvance; + } + + public partial struct stbtt_aligned_quad + { + public float x0; + + public float y0; + + public float s0; + + public float t0; + + public float x1; + + public float y1; + + public float s1; + + public float t1; + } + + public partial struct stbtt_packedchar + { + [NativeTypeName("unsigned short")] + public ushort x0; + + [NativeTypeName("unsigned short")] + public ushort y0; + + [NativeTypeName("unsigned short")] + public ushort x1; + + [NativeTypeName("unsigned short")] + public ushort y1; + + public float xoff; + + public float yoff; + + public float xadvance; + + public float xoff2; + + public float yoff2; + } + + public partial struct stbrp_rect + { + } + + public unsafe partial struct stbtt_pack_range + { + public float font_size; + + public int first_unicode_codepoint_in_range; + + public int* array_of_unicode_codepoints; + + public int num_chars; + + public stbtt_packedchar* chardata_for_range; + + [NativeTypeName("unsigned char")] + public byte h_oversample; + + [NativeTypeName("unsigned char")] + public byte v_oversample; + } + + public unsafe partial struct stbtt_pack_context + { + public void* user_allocator_context; + + public void* pack_info; + + public int width; + + public int height; + + public int stride_in_bytes; + + public int padding; + + public int skip_missing; + + [NativeTypeName("unsigned int")] + public uint h_oversample; + + [NativeTypeName("unsigned int")] + public uint v_oversample; + + [NativeTypeName("unsigned char *")] + public byte* pixels; + + public void* nodes; + } + + public unsafe partial struct stbtt_fontinfo + { + public void* userdata; + + [NativeTypeName("unsigned char *")] + public byte* data; + + public int fontstart; + + public int numGlyphs; + + public int loca; + + public int head; + + public int glyf; + + public int hhea; + + public int hmtx; + + public int kern; + + public int gpos; + + public int svg; + + public int index_map; + + public int indexToLocFormat; + + public stbtt__buf cff; + + public stbtt__buf charstrings; + + public stbtt__buf gsubrs; + + public stbtt__buf subrs; + + public stbtt__buf fontdicts; + + public stbtt__buf fdselect; + } + + public partial struct stbtt_kerningentry + { + public int glyph1; + + public int glyph2; + + public int advance; + } + + [NativeTypeName("unsigned int")] + public enum StbttV : uint + { + STBTT_vmove = 1, + STBTT_vline, + STBTT_vcurve, + STBTT_vcubic, + } + + public partial struct stbtt_vertex + { + public short x; + + public short y; + + public short cx; + + public short cy; + + public short cx1; + + public short cy1; + + [NativeTypeName("unsigned char")] + public byte type; + + [NativeTypeName("unsigned char")] + public byte padding; + } + + public unsafe partial struct stbtt__bitmap + { + public int w; + + public int h; + + public int stride; + + [NativeTypeName("unsigned char *")] + public byte* pixels; + } + + [NativeTypeName("unsigned int")] + public enum StbttPlatform : uint + { + STBTT_PLATFORM_ID_UNICODE = 0, + STBTT_PLATFORM_ID_MAC = 1, + STBTT_PLATFORM_ID_ISO = 2, + STBTT_PLATFORM_ID_MICROSOFT = 3, + } + + [NativeTypeName("unsigned int")] + public enum StbttUnicode : uint + { + STBTT_UNICODE_EID_UNICODE_1_0 = 0, + STBTT_UNICODE_EID_UNICODE_1_1 = 1, + STBTT_UNICODE_EID_ISO_10646 = 2, + STBTT_UNICODE_EID_UNICODE_2_0_BMP = 3, + STBTT_UNICODE_EID_UNICODE_2_0_FULL = 4, + } + + [NativeTypeName("unsigned int")] + public enum StbttMs : uint + { + STBTT_MS_EID_SYMBOL = 0, + STBTT_MS_EID_UNICODE_BMP = 1, + STBTT_MS_EID_SHIFTJIS = 2, + STBTT_MS_EID_UNICODE_FULL = 10, + } + + [NativeTypeName("unsigned int")] + public enum StbttMac : uint + { + STBTT_MAC_EID_ROMAN = 0, + STBTT_MAC_EID_ARABIC = 4, + STBTT_MAC_EID_JAPANESE = 1, + STBTT_MAC_EID_HEBREW = 5, + STBTT_MAC_EID_CHINESE_TRAD = 2, + STBTT_MAC_EID_GREEK = 6, + STBTT_MAC_EID_KOREAN = 3, + STBTT_MAC_EID_RUSSIAN = 7, + } + + [NativeTypeName("unsigned int")] + public enum StbttMsLang : uint + { + STBTT_MS_LANG_ENGLISH = 0x0409, + STBTT_MS_LANG_ITALIAN = 0x0410, + STBTT_MS_LANG_CHINESE = 0x0804, + STBTT_MS_LANG_JAPANESE = 0x0411, + STBTT_MS_LANG_DUTCH = 0x0413, + STBTT_MS_LANG_KOREAN = 0x0412, + STBTT_MS_LANG_FRENCH = 0x040c, + STBTT_MS_LANG_RUSSIAN = 0x0419, + STBTT_MS_LANG_GERMAN = 0x0407, + STBTT_MS_LANG_SPANISH = 0x0409, + STBTT_MS_LANG_HEBREW = 0x040d, + STBTT_MS_LANG_SWEDISH = 0x041D, + } + + [NativeTypeName("unsigned int")] + public enum StbttMacLang : uint + { + STBTT_MAC_LANG_ENGLISH = 0, + STBTT_MAC_LANG_JAPANESE = 11, + STBTT_MAC_LANG_ARABIC = 12, + STBTT_MAC_LANG_KOREAN = 23, + STBTT_MAC_LANG_DUTCH = 4, + STBTT_MAC_LANG_RUSSIAN = 32, + STBTT_MAC_LANG_FRENCH = 1, + STBTT_MAC_LANG_SPANISH = 6, + STBTT_MAC_LANG_GERMAN = 2, + STBTT_MAC_LANG_SWEDISH = 5, + STBTT_MAC_LANG_HEBREW = 10, + STBTT_MAC_LANG_CHINESE_SIMPLIFIED = 33, + STBTT_MAC_LANG_ITALIAN = 3, + STBTT_MAC_LANG_CHINESE_TRAD = 19, + } + + public static unsafe partial class Stbtt + { + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void quik_stbtt_failed_assert_store([NativeTypeName("quik_failed_assert_cb_t")] IntPtr cb); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_BakeFontBitmap", ExactSpelling = true)] + public static extern int BakeFontBitmap([NativeTypeName("const unsigned char *")] byte* data, int offset, float pixel_height, [NativeTypeName("unsigned char *")] byte* pixels, int pw, int ph, int first_char, int num_chars, stbtt_bakedchar* chardata); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetBakedQuad", ExactSpelling = true)] + public static extern void GetBakedQuad([NativeTypeName("const stbtt_bakedchar *")] stbtt_bakedchar* chardata, int pw, int ph, int char_index, float* xpos, float* ypos, stbtt_aligned_quad* q, int opengl_fillrule); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetScaledFontVMetrics", ExactSpelling = true)] + public static extern void GetScaledFontVMetrics([NativeTypeName("const unsigned char *")] byte* fontdata, int index, float size, float* ascent, float* descent, float* lineGap); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_PackBegin", ExactSpelling = true)] + public static extern int PackBegin(stbtt_pack_context* spc, [NativeTypeName("unsigned char *")] byte* pixels, int width, int height, int stride_in_bytes, int padding, void* alloc_context); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_PackEnd", ExactSpelling = true)] + public static extern void PackEnd(stbtt_pack_context* spc); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_PackFontRange", ExactSpelling = true)] + public static extern int PackFontRange(stbtt_pack_context* spc, [NativeTypeName("const unsigned char *")] byte* fontdata, int font_index, float font_size, int first_unicode_char_in_range, int num_chars_in_range, stbtt_packedchar* chardata_for_range); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_PackFontRanges", ExactSpelling = true)] + public static extern int PackFontRanges(stbtt_pack_context* spc, [NativeTypeName("const unsigned char *")] byte* fontdata, int font_index, stbtt_pack_range* ranges, int num_ranges); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_PackSetOversampling", ExactSpelling = true)] + public static extern void PackSetOversampling(stbtt_pack_context* spc, [NativeTypeName("unsigned int")] uint h_oversample, [NativeTypeName("unsigned int")] uint v_oversample); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_PackSetSkipMissingCodepoints", ExactSpelling = true)] + public static extern void PackSetSkipMissingCodepoints(stbtt_pack_context* spc, int skip); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetPackedQuad", ExactSpelling = true)] + public static extern void GetPackedQuad([NativeTypeName("const stbtt_packedchar *")] stbtt_packedchar* chardata, int pw, int ph, int char_index, float* xpos, float* ypos, stbtt_aligned_quad* q, int align_to_integer); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_PackFontRangesGatherRects", ExactSpelling = true)] + public static extern int PackFontRangesGatherRects(stbtt_pack_context* spc, [NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, stbtt_pack_range* ranges, int num_ranges, stbrp_rect* rects); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_PackFontRangesPackRects", ExactSpelling = true)] + public static extern void PackFontRangesPackRects(stbtt_pack_context* spc, stbrp_rect* rects, int num_rects); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_PackFontRangesRenderIntoRects", ExactSpelling = true)] + public static extern int PackFontRangesRenderIntoRects(stbtt_pack_context* spc, [NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, stbtt_pack_range* ranges, int num_ranges, stbrp_rect* rects); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetNumberOfFonts", ExactSpelling = true)] + public static extern int GetNumberOfFonts([NativeTypeName("const unsigned char *")] byte* data); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetFontOffsetForIndex", ExactSpelling = true)] + public static extern int GetFontOffsetForIndex([NativeTypeName("const unsigned char *")] byte* data, int index); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_InitFont", ExactSpelling = true)] + public static extern int InitFont(stbtt_fontinfo* info, [NativeTypeName("const unsigned char *")] byte* data, int offset); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_FindGlyphIndex", ExactSpelling = true)] + public static extern int FindGlyphIndex([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, int unicode_codepoint); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_ScaleForPixelHeight", ExactSpelling = true)] + public static extern float ScaleForPixelHeight([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, float pixels); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_ScaleForMappingEmToPixels", ExactSpelling = true)] + public static extern float ScaleForMappingEmToPixels([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, float pixels); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetFontVMetrics", ExactSpelling = true)] + public static extern void GetFontVMetrics([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, int* ascent, int* descent, int* lineGap); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetFontVMetricsOS2", ExactSpelling = true)] + public static extern int GetFontVMetricsOS2([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, int* typoAscent, int* typoDescent, int* typoLineGap); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetFontBoundingBox", ExactSpelling = true)] + public static extern void GetFontBoundingBox([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, int* x0, int* y0, int* x1, int* y1); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetCodepointHMetrics", ExactSpelling = true)] + public static extern void GetCodepointHMetrics([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, int codepoint, int* advanceWidth, int* leftSideBearing); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetCodepointKernAdvance", ExactSpelling = true)] + public static extern int GetCodepointKernAdvance([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, int ch1, int ch2); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetCodepointBox", ExactSpelling = true)] + public static extern int GetCodepointBox([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, int codepoint, int* x0, int* y0, int* x1, int* y1); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetGlyphHMetrics", ExactSpelling = true)] + public static extern void GetGlyphHMetrics([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, int glyph_index, int* advanceWidth, int* leftSideBearing); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetGlyphKernAdvance", ExactSpelling = true)] + public static extern int GetGlyphKernAdvance([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, int glyph1, int glyph2); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetGlyphBox", ExactSpelling = true)] + public static extern int GetGlyphBox([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, int glyph_index, int* x0, int* y0, int* x1, int* y1); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetKerningTableLength", ExactSpelling = true)] + public static extern int GetKerningTableLength([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetKerningTable", ExactSpelling = true)] + public static extern int GetKerningTable([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, stbtt_kerningentry* table, int table_length); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_IsGlyphEmpty", ExactSpelling = true)] + public static extern int IsGlyphEmpty([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, int glyph_index); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetCodepointShape", ExactSpelling = true)] + public static extern int GetCodepointShape([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, int unicode_codepoint, stbtt_vertex** vertices); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetGlyphShape", ExactSpelling = true)] + public static extern int GetGlyphShape([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, int glyph_index, stbtt_vertex** vertices); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_FreeShape", ExactSpelling = true)] + public static extern void FreeShape([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, stbtt_vertex* vertices); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_FindSVGDoc", ExactSpelling = true)] + [return: NativeTypeName("unsigned char *")] + public static extern byte* FindSVGDoc([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, int gl); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetCodepointSVG", ExactSpelling = true)] + public static extern int GetCodepointSVG([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, int unicode_codepoint, [NativeTypeName("const char **")] sbyte** svg); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetGlyphSVG", ExactSpelling = true)] + public static extern int GetGlyphSVG([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, int gl, [NativeTypeName("const char **")] sbyte** svg); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_FreeBitmap", ExactSpelling = true)] + public static extern void FreeBitmap([NativeTypeName("unsigned char *")] byte* bitmap, void* userdata); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetCodepointBitmap", ExactSpelling = true)] + [return: NativeTypeName("unsigned char *")] + public static extern byte* GetCodepointBitmap([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, float scale_x, float scale_y, int codepoint, int* width, int* height, int* xoff, int* yoff); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetCodepointBitmapSubpixel", ExactSpelling = true)] + [return: NativeTypeName("unsigned char *")] + public static extern byte* GetCodepointBitmapSubpixel([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint, int* width, int* height, int* xoff, int* yoff); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_MakeCodepointBitmap", ExactSpelling = true)] + public static extern void MakeCodepointBitmap([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, [NativeTypeName("unsigned char *")] byte* output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_MakeCodepointBitmapSubpixel", ExactSpelling = true)] + public static extern void MakeCodepointBitmapSubpixel([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, [NativeTypeName("unsigned char *")] byte* output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_MakeCodepointBitmapSubpixelPrefilter", ExactSpelling = true)] + public static extern void MakeCodepointBitmapSubpixelPrefilter([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, [NativeTypeName("unsigned char *")] byte* output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int oversample_x, int oversample_y, float* sub_x, float* sub_y, int codepoint); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetCodepointBitmapBox", ExactSpelling = true)] + public static extern void GetCodepointBitmapBox([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* font, int codepoint, float scale_x, float scale_y, int* ix0, int* iy0, int* ix1, int* iy1); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetCodepointBitmapBoxSubpixel", ExactSpelling = true)] + public static extern void GetCodepointBitmapBoxSubpixel([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* font, int codepoint, float scale_x, float scale_y, float shift_x, float shift_y, int* ix0, int* iy0, int* ix1, int* iy1); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetGlyphBitmap", ExactSpelling = true)] + [return: NativeTypeName("unsigned char *")] + public static extern byte* GetGlyphBitmap([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, float scale_x, float scale_y, int glyph, int* width, int* height, int* xoff, int* yoff); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetGlyphBitmapSubpixel", ExactSpelling = true)] + [return: NativeTypeName("unsigned char *")] + public static extern byte* GetGlyphBitmapSubpixel([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, int* width, int* height, int* xoff, int* yoff); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_MakeGlyphBitmap", ExactSpelling = true)] + public static extern void MakeGlyphBitmap([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, [NativeTypeName("unsigned char *")] byte* output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_MakeGlyphBitmapSubpixel", ExactSpelling = true)] + public static extern void MakeGlyphBitmapSubpixel([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, [NativeTypeName("unsigned char *")] byte* output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int glyph); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_MakeGlyphBitmapSubpixelPrefilter", ExactSpelling = true)] + public static extern void MakeGlyphBitmapSubpixelPrefilter([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, [NativeTypeName("unsigned char *")] byte* output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int oversample_x, int oversample_y, float* sub_x, float* sub_y, int glyph); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetGlyphBitmapBox", ExactSpelling = true)] + public static extern void GetGlyphBitmapBox([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* font, int glyph, float scale_x, float scale_y, int* ix0, int* iy0, int* ix1, int* iy1); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetGlyphBitmapBoxSubpixel", ExactSpelling = true)] + public static extern void GetGlyphBitmapBoxSubpixel([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* font, int glyph, float scale_x, float scale_y, float shift_x, float shift_y, int* ix0, int* iy0, int* ix1, int* iy1); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_Rasterize", ExactSpelling = true)] + public static extern void Rasterize(stbtt__bitmap* result, float flatness_in_pixels, stbtt_vertex* vertices, int num_verts, float scale_x, float scale_y, float shift_x, float shift_y, int x_off, int y_off, int invert, void* userdata); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_FreeSDF", ExactSpelling = true)] + public static extern void FreeSDF([NativeTypeName("unsigned char *")] byte* bitmap, void* userdata); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetGlyphSDF", ExactSpelling = true)] + [return: NativeTypeName("unsigned char *")] + public static extern byte* GetGlyphSDF([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, float scale, int glyph, int padding, [NativeTypeName("unsigned char")] byte onedge_value, float pixel_dist_scale, int* width, int* height, int* xoff, int* yoff); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetCodepointSDF", ExactSpelling = true)] + [return: NativeTypeName("unsigned char *")] + public static extern byte* GetCodepointSDF([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* info, float scale, int codepoint, int padding, [NativeTypeName("unsigned char")] byte onedge_value, float pixel_dist_scale, int* width, int* height, int* xoff, int* yoff); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_FindMatchingFont", ExactSpelling = true)] + public static extern int FindMatchingFont([NativeTypeName("const unsigned char *")] byte* fontdata, [NativeTypeName("const char *")] sbyte* name, int flags); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_CompareUTF8toUTF16_bigendian", ExactSpelling = true)] + public static extern int CompareUTF8toUTF16_bigendian([NativeTypeName("const char *")] sbyte* s1, int len1, [NativeTypeName("const char *")] sbyte* s2, int len2); + + [DllImport("stbtt", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbtt_GetFontNameString", ExactSpelling = true)] + [return: NativeTypeName("const char *")] + public static extern sbyte* GetFontNameString([NativeTypeName("const stbtt_fontinfo *")] stbtt_fontinfo* font, int* length, int platformID, int encodingID, int languageID, int nameID); + } +} diff --git a/Quik.StbTrueType/clangsharp.rsp b/Quik.StbTrueType/clangsharp.rsp new file mode 100644 index 0000000..e2f0217 --- /dev/null +++ b/Quik.StbTrueType/clangsharp.rsp @@ -0,0 +1,30 @@ +-x + c +-l + stbtt +--config + compatible-codegen + single-file + exclude-fnptr-codegen + generate-aggressive-inlining + generate-setslastsystemerror-attribute + unix-types +--include-directory + ../lib +--include-directory + ../Quik.StbTrueType.redist +--include-directory + /usr/lib/llvm-14/lib/clang/14.0.6/include +--file + ../Quik.StbTrueType.redist/quik_stbtt.h + ../lib/stb/stb_truetype.h +--methodClassName + Stbtt +--namespace + Quik.Stb +--output + Stbtt.cs +--prefixStrip + stbtt_ +--with-type + FILE=void diff --git a/lib/quik/quik_common.h b/lib/quik/quik_common.h index 1a57d94..1ea86dd 100644 --- a/lib/quik/quik_common.h +++ b/lib/quik/quik_common.h @@ -10,9 +10,6 @@ #define __QUIK_FUNCTION__ NULL #endif -/* TODO: Change this declaration so we can export a DLL properly in windows. */ -#define STBIDEF QEXTERN - /** * @brief Callback for failed assert function for QUIK redist libraries. * @param[in] expr The expression that failed.