Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added compressed font #14

Merged
merged 1 commit into from
Sep 12, 2024
Merged

Added compressed font #14

merged 1 commit into from
Sep 12, 2024

Conversation

OlegSirenko
Copy link

Hi! I working with ImGui for creating the Portable application. I need to use the minimum number of dependencies in the final application directory. So I decided to add the ability to use a compressed font with ImGuiNotify. I think it will be useful not only for me. I left a couple of links with guides on how to create and use compressed fonts.
To make it clear exactly how I created the compressed font:

  1. Download the binary_to_compressed_c.cpp
  2. Cd to fonts directory (from the example's root):
cd fonts
  1. On linux use g++ to build the executable:
g++ binary_to_compressed_c.cpp
  1. Then run executable:
./a.out ./fa-solid-900.ttf fa_solid_900 > fa-solid-900.h

To use this font with ImGuiNotify:

  1. Include the header file of compressed font in the main.cpp
 #include "./fonts/fa-solid-900.h"
  1. Use the fa_solid_900 compressed font in ImGui:
io.Fonts->AddFontDefault();

float baseFontSize = 16.0f;
float iconFontSize = baseFontSize * 2.0f / 3.0f; // FontAwesome fonts need to have their sizes reduced by 2.0f/3.0f in order to align correctly

static constexpr ImWchar iconsRanges[] = {ICON_MIN_FA, ICON_MAX_16_FA, 0}; // changed to constexpr (common practices)
ImFontConfig iconsConfig;
iconsConfig.MergeMode = true;
iconsConfig.PixelSnapH = true;
iconsConfig.GlyphMinAdvanceX = iconFontSize;
io.Fonts->AddFontFromMemoryCompressedTTF(fa_solid_900_compressed_data, fa_solid_900_compressed_size, iconFontSize, &iconsConfig, iconsRanges);

Hope this would be helpful

@TyomaVader TyomaVader added the enhancement New feature or request label Sep 12, 2024
@TyomaVader TyomaVader self-assigned this Sep 12, 2024
@TyomaVader TyomaVader merged commit bb8b24c into TyomaVader:Dev Sep 12, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants