From 5dff478dc04847d0c2b9deefddd721e1f4e26738 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 9 Jan 2015 09:00:53 +0000 Subject: [PATCH] Build fix for GCC/Clang, cannot foward declare a static array? --- imgui.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 5937b87f..410cb15b 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6213,19 +6213,24 @@ const ImWchar* ImFont::GetGlyphRangesJapanese() return &ranges[0]; } -extern const unsigned int proggy_clean_ttf_compressed_size; -extern const unsigned int proggy_clean_ttf_compressed_data[9584/4]; -extern unsigned int stb_decompress_length(unsigned char *input); -extern unsigned int stb_decompress(unsigned char *output, unsigned char *i, unsigned int length); +static void GetDefaultCompressedFontDataTTF(const void** ttf_compressed_data, unsigned int* ttf_compressed_size); +static unsigned int stb_decompress_length(unsigned char *input); +static unsigned int stb_decompress(unsigned char *output, unsigned char *i, unsigned int length); // Load embedded ProggyClean.ttf at size 13 bool ImFont::LoadDefault() { - unsigned int buf_compressed_size = (int)proggy_clean_ttf_compressed_size; - unsigned char* buf_compressed = (unsigned char*)proggy_clean_ttf_compressed_data; - const size_t buf_decompressed_size = stb_decompress_length(buf_compressed); + // Get compressed data + unsigned int ttf_compressed_size; + const void* ttf_compressed; + GetDefaultCompressedFontDataTTF(&ttf_compressed, &ttf_compressed_size); + + // Decompress + const size_t buf_decompressed_size = stb_decompress_length((unsigned char*)ttf_compressed); unsigned char* buf_decompressed = (unsigned char *)ImGui::MemAlloc(buf_decompressed_size); - stb_decompress(buf_decompressed, buf_compressed, buf_compressed_size); + stb_decompress(buf_decompressed, (unsigned char*)ttf_compressed, ttf_compressed_size); + + // Load TTF const bool ret = LoadFromMemoryTTF((void *)buf_decompressed, buf_decompressed_size, 13.0f, ImFont::GetGlyphRangesDefault(), 0); ImGui::MemFree(buf_decompressed); DisplayOffset.y += 1; @@ -8336,6 +8341,12 @@ static const unsigned int proggy_clean_ttf_compressed_data[9584/4] = 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0x00663923, 0x48fa0500, 0x00f762f9, }; +static void GetDefaultCompressedFontDataTTF(const void** ttf_compressed_data, unsigned int* ttf_compressed_size) +{ + *ttf_compressed_data = proggy_clean_ttf_compressed_data; + *ttf_compressed_size = proggy_clean_ttf_compressed_size; +} + //----------------------------------------------------------------------------- //---- Include imgui_user.inl at the end of imgui.cpp