mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 07:20:04 +00:00 
			
		
		
		
	Represent raw font data as char instead of std::uint8_t
This commit is contained in:
		
							parent
							
								
									fe1acb32cf
								
							
						
					
					
						commit
						104227aa42
					
				
					 3 changed files with 18 additions and 19 deletions
				
			
		|  | @ -62,7 +62,7 @@ public: | ||||||
|    void InitializeFontconfig(); |    void InitializeFontconfig(); | ||||||
|    void UpdateImGuiFont(types::FontCategory fontCategory); |    void UpdateImGuiFont(types::FontCategory fontCategory); | ||||||
| 
 | 
 | ||||||
|    const std::vector<std::uint8_t>& GetRawFontData(const std::string& filename); |    const std::vector<char>& GetRawFontData(const std::string& filename); | ||||||
| 
 | 
 | ||||||
|    static FontRecord MatchFontFile(const std::string&              family, |    static FontRecord MatchFontFile(const std::string&              family, | ||||||
|                                    const std::vector<std::string>& styles); |                                    const std::vector<std::string>& styles); | ||||||
|  | @ -81,8 +81,7 @@ public: | ||||||
|                      imguiFonts_ {}; |                      imguiFonts_ {}; | ||||||
|    std::shared_mutex imguiFontsMutex_ {}; |    std::shared_mutex imguiFontsMutex_ {}; | ||||||
| 
 | 
 | ||||||
|    boost::unordered_flat_map<std::string, std::vector<std::uint8_t>> |    boost::unordered_flat_map<std::string, std::vector<char>> rawFontData_ {}; | ||||||
|               rawFontData_ {}; |  | ||||||
|    std::mutex rawFontDataMutex_ {}; |    std::mutex rawFontDataMutex_ {}; | ||||||
| 
 | 
 | ||||||
|    std::shared_ptr<types::ImGuiFont> defaultFont_ {}; |    std::shared_ptr<types::ImGuiFont> defaultFont_ {}; | ||||||
|  | @ -303,7 +302,7 @@ FontManager::LoadImGuiFont(const std::string&               family, | ||||||
|    return imguiFont; |    return imguiFont; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const std::vector<std::uint8_t>& | const std::vector<char>& | ||||||
| FontManager::Impl::GetRawFontData(const std::string& filename) | FontManager::Impl::GetRawFontData(const std::string& filename) | ||||||
| { | { | ||||||
|    std::unique_lock rawFontDataLock {rawFontDataMutex_}; |    std::unique_lock rawFontDataLock {rawFontDataMutex_}; | ||||||
|  | @ -316,16 +315,16 @@ FontManager::Impl::GetRawFontData(const std::string& filename) | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    // Raw font data needs to be loaded
 |    // Raw font data needs to be loaded
 | ||||||
|    std::basic_ifstream<std::uint8_t> ifs {filename, std::ios::binary}; |    std::basic_ifstream<char> ifs {filename, std::ios::binary}; | ||||||
|    ifs.seekg(0, std::ios_base::end); |    ifs.seekg(0, std::ios_base::end); | ||||||
|    std::size_t dataSize = ifs.tellg(); |    std::size_t dataSize = ifs.tellg(); | ||||||
|    ifs.seekg(0, std::ios_base::beg); |    ifs.seekg(0, std::ios_base::beg); | ||||||
| 
 | 
 | ||||||
|    // Store the font data in a buffer
 |    // Store the font data in a buffer
 | ||||||
|    std::vector<std::uint8_t> buffer {}; |    std::vector<char> buffer {}; | ||||||
|    buffer.reserve(dataSize); |    buffer.reserve(dataSize); | ||||||
|    std::copy(std::istreambuf_iterator<std::uint8_t>(ifs), |    std::copy(std::istreambuf_iterator<char>(ifs), | ||||||
|              std::istreambuf_iterator<std::uint8_t>(), |              std::istreambuf_iterator<char>(), | ||||||
|              std::back_inserter(buffer)); |              std::back_inserter(buffer)); | ||||||
| 
 | 
 | ||||||
|    // Place the buffer in the cache
 |    // Place the buffer in the cache
 | ||||||
|  |  | ||||||
|  | @ -24,7 +24,7 @@ class ImGuiFont::Impl | ||||||
| { | { | ||||||
| public: | public: | ||||||
|    explicit Impl(const std::string&            fontName, |    explicit Impl(const std::string&            fontName, | ||||||
|                  const std::vector<std::uint8_t>& fontData, |                  const std::vector<char>&      fontData, | ||||||
|                  units::font_size::pixels<int> size) : |                  units::font_size::pixels<int> size) : | ||||||
|        fontName_ {fontName}, size_ {size} |        fontName_ {fontName}, size_ {size} | ||||||
|    { |    { | ||||||
|  | @ -33,7 +33,7 @@ public: | ||||||
| 
 | 
 | ||||||
|    ~Impl() {} |    ~Impl() {} | ||||||
| 
 | 
 | ||||||
|    void CreateImGuiFont(const std::vector<std::uint8_t>& fontData); |    void CreateImGuiFont(const std::vector<char>& fontData); | ||||||
| 
 | 
 | ||||||
|    const std::string                   fontName_; |    const std::string                   fontName_; | ||||||
|    const units::font_size::pixels<int> size_; |    const units::font_size::pixels<int> size_; | ||||||
|  | @ -42,14 +42,14 @@ public: | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| ImGuiFont::ImGuiFont(const std::string&            fontName, | ImGuiFont::ImGuiFont(const std::string&            fontName, | ||||||
|                      const std::vector<std::uint8_t>& fontData, |                      const std::vector<char>&      fontData, | ||||||
|                      units::font_size::pixels<int> size) : |                      units::font_size::pixels<int> size) : | ||||||
|     p(std::make_unique<Impl>(fontName, fontData, size)) |     p(std::make_unique<Impl>(fontName, fontData, size)) | ||||||
| { | { | ||||||
| } | } | ||||||
| ImGuiFont::~ImGuiFont() = default; | ImGuiFont::~ImGuiFont() = default; | ||||||
| 
 | 
 | ||||||
| void ImGuiFont::Impl::CreateImGuiFont(const std::vector<std::uint8_t>& fontData) | void ImGuiFont::Impl::CreateImGuiFont(const std::vector<char>& fontData) | ||||||
| { | { | ||||||
|    logger_->debug("Creating Font: {}", fontName_); |    logger_->debug("Creating Font: {}", fontName_); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -19,7 +19,7 @@ class ImGuiFont | ||||||
| { | { | ||||||
| public: | public: | ||||||
|    explicit ImGuiFont(const std::string&            fontName, |    explicit ImGuiFont(const std::string&            fontName, | ||||||
|                       const std::vector<std::uint8_t>& fontData, |                       const std::vector<char>&      fontData, | ||||||
|                       units::font_size::pixels<int> size); |                       units::font_size::pixels<int> size); | ||||||
|    ~ImGuiFont(); |    ~ImGuiFont(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat