Coder Social home page Coder Social logo

aiekick / imguifontstudio Goto Github PK

View Code? Open in Web Editor NEW
364.0 11.0 33.0 28.65 MB

Embedded Font Helper Gui Tool for programming

License: Apache License 2.0

CMake 0.60% C++ 98.29% C 1.11%
imgui font subset-font embedded theme font-icons font-awesome tool software font-merge

imguifontstudio's Introduction

Backend Win Linux Osx
Opengl 3
Vulkan

Vulkan versions :

  • on windows its working fine, here, just not found a way for install Vulkan SDk with github action
  • on OSX, we must use Molten-Vk, and its not tested for now. if someone want to help :)

ImGuiFontStudio is a tool for Subset font and extract glyph names for use embbeded or not in a software, especially for use with ImGui for embedded way.

Greatly inspired / based on the project IconFontCppHeaders

This is my first big opensource software.

As a self learning man i always developped my softs in solo.

So maybe you will found some weird things, bad design pattern, bad optimization, or others bullshits :)

Please send me your feedback. I enjoy all constructive comments and help is welcome.

Succesfully tested on my side :

  • On Win 7 x64 (in version x86/x64 OpenGl3/Vulkan)
  • On Linux Debian/Ubuntu (in version x64 OpenGl3/Vulkan)
  • On Linux Debian/RaspberryOs (in version x86/x64 OpenGl3/Vulkan)
  • MacOs Mojave (in exe version x86 OpenGl3)

The features :

  • can open ttf or otf font file
  • can subset font file (one file same time or by batch)
  • can translate or rescale glyphs
  • can generate header with corresponding glyph names and codepoint
  • can generate a card picture file who show the content (icon + name of the header)
  • can generate src (C/C++/C#) file with compressed data for embedded (incorparated in binary) use
  • can merge many font file in one (the glyphs will be resized)
  • can edit codepoint and glyph names
  • have a project file
  • many tool available for select glyphs (by zone, by line, by codepoint range)
  • Cross Platform, tested on Win/Osx/Linux
  • Change / define ImGui app Theme

For more information how to use the generated files, see this project : https://github.com/juliettef/IconFontCppHeaders

My soft do the same job and more but easier for user :)

How to Build :

You need to use cMake. For the 3 Os (Win, Linux, MacOs), the cMake usage is exactly the same,

  1. Choose a build directory. (called here my_build_directory for instance) and
  2. Choose a Build Mode : "Release" / "MinSizeRel" / "RelWithDebInfo" / "Debug" (called here BuildMode for instance)
  3. Run cMake in console : (the first for generate cmake build files, the second for build the binary)
cmake -B my_build_directory -DCMAKE_BUILD_TYPE=BuildMode
cmake --build my_build_directory --config BuildMode

Some cMake version need Build mode define via the directive CMAKE_BUILD_TYPE or via --Config when we launch the build. This is why i put the boths possibilities

By the way you need before, to make sure, you have needed dependencies.

On Windows :

You need to have the opengl library installed

On Linux :

You need many lib : (X11, xrandr, xinerama, xcursor, mesa)

If you are on debian you can run :

sudo apt-get update 
sudo apt-get install libgl1-mesa-dev libx11-dev libxi-dev libxrandr-dev libxinerama-dev libxcursor-dev

On MacOs :

you need many lib : opengl and cocoa framework

How to use generated font

ImGuiFontStudio will generate, 4 file types, depending of your needs.

File Type Description
Font file TTF Vector Font File needed for external mode
Source Code .c/.cpp/.cs for c/c++/c# with conpressed font data for embedded mode
Header code .h/.cs for c/c++/c# with infos like (glyph labels/codepoint min/max ranges)]
Card .png this card is a picture file who show each glyph and the corresponding labels
  1. If you want to have no external dependencie, the embedded mode is for you, but your binary file can have a bigger size if you have a big font.
  2. If you want to have a external font file and more compact binary file, the external mode is for you.

For loading that in ImGui, you need to merge the font icon into the current main font used in your ImGui App. But we just need to load some codepoints, not all the unicode table. This is why you have in the header file the min/max range infos.

External Font File Use :

for instance here in this example for load embedded font, we have (with font Prefix IGFS) :

  • ICON_MIN_IGFS => min range
  • ICON_MAX_IGFS => max range
  • FONT_ICON_FILE_NAME_IGFS => the font file name to load (ex: fontawesome.ttf)

For C (CImGui)

ImGuiIO* ioptr = igGetIO();
ImFontAtlas_AddFontDefault(ioptr->Fonts, NULL);
const ImWchar icons_ranges[3] = { ICON_MIN_IGFS, ICON_MAX_IGFS, 0 };
ImFontConfig* icons_config = ImFontConfig_ImFontConfig();
icons_config->MergeMode = true; 
icons_config->PixelSnapH = true;
ImFontAtlas_AddFontFromFileTTF(ioptr->Fonts, FONT_ICON_FILE_NAME_IGFS, 15.0f, icons_config, icons_ranges);
ImFontConfig_destroy(icons_config);

For C++

ImGui::GetIO().Fonts->AddFontDefault();
static const ImWchar icons_ranges[] = { ICON_MIN_IGFS, ICON_MAX_IGFS, 0 };
ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
ImGui::GetIO().Fonts->AddFontFromFileTTF(FONT_ICON_FILE_NAME_IGFS, 15.0f, &icons_config, icons_ranges);

For C# (ImGui.NET)

ImGui.GetIO().Fonts.AddFontDefault();
unsafe
{
	ImFontConfigPtr config = ImGuiNative.ImFontConfig_ImFontConfig(); config.MergeMode = true; config.PixelSnapH = true;
	GCHandle rangeHandle = GCHandle.Alloc(new ushort[]{IconFonts.IGFS_Labels.ICON_MIN, IconFonts.IGFS_Labels.ICON_MAX,0}, GCHandleType.Pinned);
	ImGui.GetIO().Fonts.AddFontFromFileTTF(IconFonts.IGFS_Labels.FONT_ICON_FILE_NAME, 15, config, rangeHandle.AddrOfPinnedObject());
}

Embedded Font File Use :

for instance here in this example for load embedded font, we have (with font Prefxi IGFS) :

  • ICON_MIN_IGFS => min range
  • ICON_MAX_IGFS => max range
  • FONT_ICON_BUFFER_NAME_IGFS => the compressed buffer name you have in your_embedded_font.cpp to load (ex: IGFS_compressed_data_base85)

For C (CImGui)

ImGuiIO* ioptr = igGetIO();
ImFontAtlas_AddFontDefault(ioptr->Fonts, NULL);
const ImWchar icons_ranges[3] = { ICON_MIN_IGFS, ICON_MAX_IGFS, 0 };
ImFontConfig* icons_config = ImFontConfig_ImFontConfig();
icons_config->MergeMode = true; 
icons_config->PixelSnapH = true;
ImFontAtlas_AddFontFromMemoryCompressedBase85TTF(ioptr->Fonts, FONT_ICON_FILE_NAME_IGFS, 15.0f, icons_config, icons_ranges);
ImFontConfig_destroy(icons_config);

For C++

ImGui::GetIO().Fonts->AddFontDefault();
static const ImWchar icons_ranges[] = { ICON_MIN_IGFS, ICON_MAX_IGFS, 0 };
ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
ImGui::GetIO().Fonts->AddFontFromMemoryCompressedBase85TTF(FONT_ICON_BUFFER_NAME_IGFS, 15.0f, &icons_config, icons_ranges);

For C# (ImGui.NET)

ImGui.GetIO().Fonts.AddFontDefault();
unsafe
{
	ImFontConfigPtr config = ImGuiNative.ImFontConfig_ImFontConfig(); config.MergeMode = true; config.PixelSnapH = true;
	GCHandle rangeHandle = GCHandle.Alloc(new ushort[]{IconFonts.IGFS_Labels.ICON_MIN, IconFonts.IGFS_Labels.ICON_MAX,0}, GCHandleType.Pinned);
	ImGui.GetIO().Fonts.AddFontFromMemoryCompressedBase85TTF(IconFonts.IGFS_Bytes.compressed_data_base85, 15, config, rangeHandle.AddrOfPinnedObject());
}

Boths cases :

In both cases, the use in code is the same :

After that step, when you have a ImGui widget to test, you just need to put in the label field, the glyph you want, defined in the header file for labels :

For C/C++

ImGui::Button(ICON_IGFS_FOLDER_OPEN " Open Font");

For C# (ImGui.NET)

ImGui::Button(IconFonts.IGFS_Labels.FOLDER_OPEN + " Open Font");

and you will have this result : Button_With_Icons

Contributions / Issues / Features request

You can use the issue tab for report issues or for features request. Or you can also contribute with discuss via issues tabs, or/and Pull Requests :)

License :

ImGuiFontStudio is an open source software under license apache 2.0

Library used :

Screenshots (with the default theme)

Main View : Source pane Source pane

Main View : Final pane with two fonts Final pane with two fonts

Main View : Final pane for edition Final pane for edition

Sample of a Card : Card

Projects who are using this font tool :

Let me know your project wiht a pciture and i can add it here :

For the moment (as i know), there is :

imguifontstudio's People

Contributors

aiekick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

imguifontstudio's Issues

Not a valid font file ttf error (using Windows release binary)

Describe the bug
Opening the generated ttf is giving an error.
.h file look fine.
That happened using one only font or/and merging/picking from many fonts.

Screenshots
fonts

Desktop (please complete the following information):
Windows 10

Additional context
Thats the binary that I used:
https://github.com/aiekick/ImGuiFontStudio/releases/download/b0.5/ImGuiFontStudio_Msvc_Win32.exe

Should I compile a new version from the repo by myself?

Thanks!

Can't compile on Fedora

Describe the bug
The ImGuiFileDialog.cmake script did not work! After fixing it finnished.
All went fine until the compiler hit ImWidgets.cpp, there where to many
errors to fix so I give up.

Desktop (please complete the following information):

  • OS: [Linux, Fedora 36]

Bug: font studio generates broken fonts

Hi! You created an awersome tool. Thank you! But it doesn't work for me.
I get an error after generating a font:
image
As far as I understand, it tries to load just generated font, but it can't because the font is broken. Also, I tried to manually open generated font using OS font viewer and font studio, both give an error.

How I have compiled it:

  • Cloned master branch with submodules
  • Executed terminal command cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
  • Then cmake --build build --config Release
    And it was built successfully.

Then I just created a new project, opened just downloaded FontAwersome font, selected all glyphs, and pressed generate. I didn't change any settings.
Font studio opened header file (ok), png (ok), but the font generated by the studio was broken, so, I got this error message.
Also, I tried different fonts.

OS: Linux 5.10
Compiler: GCC (10.2)
CMake: latest (3.19)

Screenshot:
image

I hope for your help! Thanks in advance!

Merged mode; glyph downscale look bad

Describe the bug
when a high res font is merged in a low res font, the glyphs downscale cause deformed glyphs and outside of bounding box
the inverse from low scale to high scale look nice without issues

Header is not generated in merge mode after app start

Describe the bug
When open ImGuiFontStudio.ifs project file
Set Merged mode + Header + font + + by Name and generate
the ttf is generated bu the header cuase an error in console.
header file in .h not found
error seen in Osw and Linux only

Any help to compile on Windows?

Trying to compile here.
I am very newbie out of Visual Studio...

Any help is appreciated.


  1. I am trying to compile on the command prompt but I am getting this error:
PS D:\_CODE\_C\ImGuiFontStudio> cmake -B my_build_directory -DCMAKE_BUILD_TYPE=BuildMode
CMake Error: The current CMakeCache.txt directory D:/_CODE/_C/ImGuiFontStudio/my_build_directory/CMakeCache.txt is different than the directory /d/_CODE/_C/ImGuiFontStudio/my_build_directory where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt
CMake Error: The source "D:/_CODE/_C/ImGuiFontStudio/CMakeLists.txt" does not match the source "/d/_CODE/_C/ImGuiFontStudio/CMakeLists.txt" used to generate cache.  Re-run cmake with a different source directory.
PS D:\_CODE\_C\ImGuiFontStudio> cmake --build my_build_directory --config BuildMode
CMake Error: The current CMakeCache.txt directory D:/_CODE/_C/ImGuiFontStudio/my_build_directory/CMakeCache.txt is different than the directory /d/_CODE/_C/ImGuiFontStudio/my_build_directory where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt
The system cannot find the file specified
CMake Error: Generator: execution of make failed. Make command was: /usr/bin/make.exe -f Makefile &&
PS D:\_CODE\_C\ImGuiFontStudio>

  1. I also tried on MSYS1 32/64 but I am having errors... OpenGL looks that is installed...
moebiussurfing@surfingMachine MINGW64 /d/_CODE/_C/ImGuiFontStudio
$ pacman -Ss glew
mingw32/mingw-w64-i686-glew 2.2.0-2 [installed]
    GLEW, The OpenGL Extension Wrangler Library (mingw-w64)
mingw64/mingw-w64-x86_64-glew 2.2.0-2 [installed]
    GLEW, The OpenGL Extension Wrangler Library (mingw-w64)
ucrt64/mingw-w64-ucrt-x86_64-glew 2.2.0-2
    GLEW, The OpenGL Extension Wrangler Library (mingw-w64)
clang32/mingw-w64-clang-i686-glew 2.2.0-2
    GLEW, The OpenGL Extension Wrangler Library (mingw-w64)
clang64/mingw-w64-clang-x86_64-glew 2.2.0-2
    GLEW, The OpenGL Extension Wrangler Library (mingw-w64)

moebiussurfing@surfingMachine MINGW64 /d/_CODE/_C/ImGuiFontStudio
$ cmake -B my_build_directory -DCMAKE_BUILD_TYPE=BuildMode
System is unknown to cmake, create:
Platform/MINGW64_NT-10.0-19044 to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
Your CMakeCache.txt file was copied to CopyOfCMakeCache.txt. Please post that file on discourse.cmake.org.
CMake Error at /usr/share/cmake-3.22.1/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find OpenGL (missing: OPENGL_opengl_LIBRARY OPENGL_glx_LIBRARY)
Call Stack (most recent call first):
  /usr/share/cmake-3.22.1/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-3.22.1/Modules/FindOpenGL.cmake:443 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  cmake/3rdparty.cmake:14 (find_package)
  CMakeLists.txt:22 (include)

-- Configuring incomplete, errors occurred!
See also "/d/_CODE/_C/ImGuiFontStudio/my_build_directory/CMakeFiles/CMakeOutput.log".

Wrong font size

First of all this is a great tool, I love it, thank you very much.

I have a stupid problem about the font sizes. But I 'm not sure why this is happening or what is wrong. I'll be glad if you can point me to the right direction.

Here is my font icon result. As you can see only (blue area) more than half of them is active. Looks like their size is wrong. This also cause a problem MainMenuBar's size(height) and those icons are not at the center of it.
2020-05-11 14-14-50 2020-05-11 14_16_54

My settings:

Screen Shot 2020-05-11 at 14 21 49

I guess merging fonts cause this problem. When I disable merging, it works

 // ImGui::GetIO().Fonts->AddFontDefault();
    static const ImWchar icons_ranges[] = {ICON_MIN_FileMenu, ICON_MAX_FileMenu, 0};
    ImFontConfig icons_config;
    // icons_config.MergeMode = true;
    icons_config.PixelSnapH = true;
    ImGui::GetIO().Fonts->AddFontFromMemoryCompressedBase85TTF(FONT_ICON_BUFFER_NAME_FileMenu, 22.0f, &icons_config, icons_ranges);

Screen Shot 2020-05-11 at 15 11 51

Is there a way to fix this? Any suggestions?

Thank you

Build on Visual Studio "lose some const-volatile qualifiers"

Describe the bug
Build error related to sfntly:

Errors:

  • ...\14.26.28720\include\xtree(1708,1): error C3848: expression having type 'const sfntly::HeaderComparatorByOffset' would lose some const-volatile qualifiers in order to call 'bool sfntly::HeaderComparatorByOffset::operator ()(sfntly::HeaderPtr,sfntly::HeaderPtr)' [...\ImGuiFontStudio\sfntly.vcxproj]
  • ...\14.26.28720\include\xtree(1698,1): error C3848: expression having type 'const sfntly::HeaderComparatorByOffset' would lose some const-volatile qualifiers in order to call 'bool sfntly::HeaderComparatorByOffset::operator ()(sfntly::HeaderPtr,sfntly::HeaderPtr)' [...\ImGuiFontStudio\sfntly.vcxproj]

To Reproduce

  1. CMake
  2. Build Solution

Visual Studio 2019 - 14.26.28720 (tested \c++lastest)

Expected behavior
Built project.

Screenshots

Desktop (please complete the following information):

  • OS: Windows
  • Browser [e.g. chrome, safari]
  • Version [master - head]

Development help?

Hi @aiekick,

When I was working on ImGuiFontDialog this morning I have to admit I didn't fully understand what ImGuiFontStudio was. When I mentioned ImGuiCppIcons there I didn't realize that you had this project that does the same thing and so much more. When I saw you had edited that section to mention this project, I took a closer look and wow, this is a really neat project.

I'm sorry I neglected your project with my edits there! I'm going to send you a fix for that with a better nod to this repo.

Would you mind if hacked around a bit and dropped in some PRs on this project?

I'd also like to do some work on the file dialog if you're ok with that.

Cheers,

Dan

Merged fonts not working

I did merge two different font files. Fonts from second file(tasks.ttf) is not working from generated as header+cpp. Files are attached below.

Screen Shot 2020-05-11 at 22 08 12

Header + CPP files: Archive.zip

 ImGui::MenuItem(ICON_FileMenu_ROOT); // Not showing
 ImGui::MenuItem(ICON_FileMenu_OPEN);

Screen Shot 2020-05-11 at 22 10 58

Im Merge mode, some glyphs of the resulting font are very small

If the two fonts have different Height, the resulting font will use the height of the first font.
so many glyph can be very small.

we need to scale each contours of each glyph.
so we need to inspect and modify each glyph.

for the moment, the soft copy the whole glyph data. not modify nothing inside the glyph

How to merge all final glyphs to a new file

Hi Aiekick,

Thank you for such a cool tool!

I'm testing a feature to save all final selected fonts to a single .ttf file and generate a header for all the glyph.
In this case, no matter if a source font file in the project is used (i.e. has its glyph(s) selected), since it is a candidate and I may use it next time, a final .ttf should be exported.

I'm not sure if the "Merge" mode is the correct mode in this use case, but the Generator::GenerateFontFile_Merged function returned with error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.