Skip to content

Commit

Permalink
Merge branch 'draft_ft': add support for freetype and colored fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Jan 3, 2024
2 parents 3ab7b90 + b2a551c commit f879aae
Show file tree
Hide file tree
Showing 38 changed files with 817 additions and 266 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Vulkan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ jobs:
run: |
mkdir build
cd build
cmake .. -DHELLOIMGUI_USE_GLFW_VULKAN=ON -DHELLOIMGUI_USE_SDL_VULKAN=ON -DCMAKE_BUILD_TYPE=Release;
cmake .. -DHELLOIMGUI_USE_GLFW_VULKAN=ON -DHELLOIMGUI_USE_SDL_VULKAN=ON -DCMAKE_BUILD_TYPE=Release -DHELLOIMGUI_DOWNLOAD_FREETYPE_IF_NEEDED=ON
cmake --build . -j 3
2 changes: 1 addition & 1 deletion .github/workflows/ci_automation_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
cd .github/ci_automation_tests
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DHELLOIMGUI_WIN32_NO_CONSOLE=OFF -DHELLOIMGUI_WIN32_AUTO_WINMAIN=OFF
cmake .. -DCMAKE_BUILD_TYPE=Release -DHELLOIMGUI_WIN32_NO_CONSOLE=OFF -DHELLOIMGUI_WIN32_AUTO_WINMAIN=OFF -DHELLOIMGUI_DOWNLOAD_FREETYPE_IF_NEEDED=ON
cmake --build . -j 3 --config Release
- name: install mesa OpenGL software renderer (windows only)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cpp_lib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ jobs:
run: |
mkdir build
cd build
cmake .. -DHELLOIMGUI_USE_GLFW_OPENGL3=ON -DHELLOIMGUI_USE_SDL_OPENGL3=ON -DCMAKE_BUILD_TYPE=Release
cmake .. -DHELLOIMGUI_USE_GLFW_OPENGL3=ON -DHELLOIMGUI_USE_SDL_OPENGL3=ON -DCMAKE_BUILD_TYPE=Release -DHELLOIMGUI_DOWNLOAD_FREETYPE_IF_NEEDED=ON
cmake --build . --config Release -j 3
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Support for Application Icon: the file `assets/app_settings/icon.png` will be used to generate the window icon (C++, Python), and app icon (C++ only) for any platform. See assets structure below:
```
assets/
├── world.jpg # A custom asset
├── world.png # A custom asset
├── app_settings/ # Application settings
│ ├── icon.png # This will be the app icon, it should be square
│ │ # and at least 512x512. It will be converted
Expand Down
25 changes: 20 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,21 @@ else()
set(IMGUI_BUNDLE_WITH_TEST_ENGINE OFF)
endif()

#------------------------------------------------------------------------------
# Options / Freetype (this is an option for hello_imgui, reproduced here for convenience)
#------------------------------------------------------------------------------
set(freetype_default ON)
if(ANDROID OR MINGW)
# Freetype is not available on Android. The mix SDL + Freetype cause issues (cannot find SDL.h)
# Freetype currently fails to build on MinGW
set(freetype_default OFF)
endif()
# Note: to reduce wasm size, you may want to disable freetype on emscripten.
option(HELLOIMGUI_USE_FREETYPE "Use freetype for text rendering" ${freetype_default})
# For python bindings, we force the usage of a static version of freetype
if(IMGUI_BUNDLE_BUILD_PYTHON AND HELLOIMGUI_USE_FREETYPE)
set(HELLOIMGUI_FREETYPE_STATIC ON CACHE BOOL "" FORCE)
endif()

# IMGUI_BUNDLE_BUILD_DEMOS: Build demos
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -386,12 +401,12 @@ endif()
if (NOT IMGUI_BUNDLE_WITH_IMMVISION)
set(IMGUI_BUNDLE_WITH_IMMVISION OFF)
endif()
him_get_active_backends(selected_backends)
message(STATUS "imgui_bundle build options:
Backends: ${selected_backends}
==================
him_log_configuration()
message(STATUS "
Dear ImGui Bundle build options:
===========================================================================
Options:
==================
---------------------------------------------------------------------------
IMGUI_BUNDLE_WITH_IMMVISION: ${IMGUI_BUNDLE_WITH_IMMVISION} (IMMVISION_FETCH_OPENCV: ${IMMVISION_FETCH_OPENCV})
IMGUI_BUNDLE_WITH_TEST_ENGINE: ${IMGUI_BUNDLE_WITH_TEST_ENGINE}
IMGUI_BUNDLE_BUILD_PYTHON: ${IMGUI_BUNDLE_BUILD_PYTHON}
Expand Down
2 changes: 1 addition & 1 deletion _example_integration
Binary file removed bindings/imgui_bundle/assets/images/world.jpg
Binary file not shown.
Binary file added bindings/imgui_bundle/assets/images/world.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Love them or hate them but font licenses can clear your mind when it comes to using fonts.

This license details what you are allowed - and not allowed - to do with the color font that was provided to you for free, thanks to the generosity of its designer: Matt Lyon www.c8six.com



** End-User License Agreement **

By downloading and/or installing this font delivered by Fontself during the #ColorFontWeek, you agree to this license. Please take 3 minutes to read it entirely, as it will help you get the best out of this awesome font for your next projects.

In case of any doubt, please contact Fontself at [email protected]


** What is allowed **

- Use for personal and commercial work
- Use for yourself and on behalf of a client
- Use for desktop, print, web, ebook, video and film projects (this will practically be limited due to the novelty of color fonts, see recommendations below)
- Use for physical/digital products/services, distributed for free or a fee, only if the font file or the original typeface design are not the main elements of the product (ie. T-shirts, posters, cards, etc.)
- Embed in a PDF document
- Embed in a web page, only if you credit its designer
- It is ok to temporarily handle the font file to your local printer if needed
- But you cannot give the font to your clients for their logos or communications. You should embed the font in PDFs or flatten the designs if you want to share it with third-parties.


** What is NOT allowed **
(Unless you get an explicit & written permission from its designer)

- Modify the font
- Sell or share it (even for free)
- All other forms of distribution: resell, sublicense, transfer, redistribute, repackage with any other product or service
- Upload, host or include in any online or offline archive, website or collection
- Install, deliver or provide access to use the font in any app, website or service allowing other people to use or share the font (i.e. online design editors, print on demand services, etc.)


** What is recommended **

- Credit the font designer whenever you can (we all appreciate some recognition, don't we ;)
- Test & validate your production & distribution chains to ensure color fonts will properly be displayed in your projects. Since color font technologies are pretty new, many apps, operating systems, browsers and printers will not display or render the colored glyphs, instead showing black vector shapes or even nothing at all. Color fonts may contain fallback vector glyphs for backward compatibility, so if you want to use color fonts for production projects, do your homework first.
- Show what you have created with this font: designers love to see what other creatives make with their fonts, so feel free to ping the font designer or even tag your projects with a #ColorFontWeek hashtag so we can all enjoy your cool designs.
- And if you are a project commissionner, contact the designer, your business will really benefit from extra creativity & talent!


** One more thing(s) **

- Except for your right to use this font, all other rights are owned and retained by the font designer
- Neither the designer nor Fontself guarantee that the font is compatible or fully functional under any production workflow
- Neither the designer nor Fontself are liable for any damages resulting from the installation or use of the font
- For more informations on color fonts, their technologies and support across apps, visit www.colorfonts.com
- To learn about the font creation tool used to craft this font, check Fontself Maker on www.fontself.com
- And to discover more about the #ColorFontWeek initiative from Adobe and Fontself, read http://blogs.adobe.com/creativecloud/color-font-week-design-in-color/ and visit https://colorfontweek.fontself.com


That's about it, if anything is not clear enough or you have any questions please contact Fontself via [email protected]

Enjoy!
Binary file not shown.
Binary file removed bindings/imgui_bundle/demos_assets/images/world.jpg
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion bindings/imgui_bundle/demos_cpp/demo_imgui_md.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ std::string exampleMarkdownString()
# Markdown example
Hello World! <br>
![World](images/world.jpg)
![World](images/world.png)
## Acknowledgments
This markdown renderer is based on [imgui_md](https://github.com/mekhontsev/imgui_md), by Dmitry Mekhontsev.
Expand Down
2 changes: 1 addition & 1 deletion bindings/imgui_bundle/demos_cpp/demo_immapp_launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ std::function<void()> makeGui()
DemoApp{"demo_assets_addons", "How to use assets, and how to use add-ons (Markdown and ImPlot)"},
DemoApp{
"demo_docking",
"""How to build complex applications layouts, with dockable panels, that can even become independent windows. How to customize the theme.""",
"Full Demo: complex docking layout, additional fonts (including colored fonts and emojis), log window, status bar, user settings, etc."
},
DemoApp{"demo_custom_background", "How to use a custom 3D background"},
DemoApp{
Expand Down
4 changes: 2 additions & 2 deletions bindings/imgui_bundle/demos_cpp/demos_immapp/demo_assets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ void show_gui()
{
// Display Markdown text
ImGuiMd::Render("Hello, _World_");
// Display a static image, taken from assets/images/world.jpg
// Display a static image, taken from assets/images/world.png
// Notes:
// * we use EmToVec2 to make sure the Gui render identically on high and low dpi monitors
// * we can specify only one dimension, and the image will be scaled proportionally to its size:
// in this example, the image height will correspond to 10 text lines
HelloImGui::ImageFromAsset("images/world.jpg", ImmApp::EmToVec2(0.f, 10.f));
HelloImGui::ImageFromAsset("images/world.png", ImmApp::EmToVec2(0.f, 10.f));

// Display a button
if (ImGui::Button("Bye"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void DemoAssets(AppState& appState)
// Prefer to specify sizes using the "em" unit: see https://en.wikipedia.org/wiki/Em_(typography)
// Below, imageSize is equivalent to the size of 3 lines of text
ImVec2 imageSize = HelloImGui::EmToVec2(3.f, 3.f);
HelloImGui::ImageFromAsset("images/world.jpg", imageSize);
HelloImGui::ImageFromAsset("images/world.png", imageSize);

ImGuiMd::Render("**Read the [documentation about assets](https://pthom.github.io/imgui_bundle/quickstart.html#quickstart_about_assets)**");

Expand Down Expand Up @@ -183,14 +183,14 @@ std::string GetDoc(const std::string& whichDoc)
```cpp
ImGui::Text(ICON_FA_INFO " " ICON_FA_EXCLAMATION_TRIANGLE " " ICON_FA_SAVE);
ImVec2 imageSize = HelloImGui::EmToVec2(3.f, 3.f);
HelloImGui::ImageFromAsset("images/world.jpg", imageSize);
HelloImGui::ImageFromAsset("images/world.png", imageSize);
```
Python
```python
imgui.text(icons_fontawesome.ICON_FA_INFO + " " + icons_fontawesome.ICON_FA_EXCLAMATION_TRIANGLE + " " + icons_fontawesome.ICON_FA_SAVE)
image_size = hello_imgui.em_to_vec2(3.0, 3.0)
hello_imgui.image_from_asset("images/world.jpg", image_size)
hello_imgui.image_from_asset("images/world.png", image_size)
```
*Note: In this code, imageSize is equivalent to the size of 3 lines of text, using the [em unit](https://en.wikipedia.org/wiki/Em_(typography))*
Expand Down
Loading

0 comments on commit f879aae

Please sign in to comment.