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

[UI] Changed default Windows font & Allow loading custom font #2135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Gliniak
Copy link
Member

@Gliniak Gliniak commented Feb 25, 2023

  • Changed font on Windows to tahoma
  • Allowed loading Greek and Cyrillic glyphs
  • Unified font size to 12. This causes default UI to look a bit bigger
  • Set oversample to 2 to make font more readable (especially custom fonts)

@Gliniak Gliniak force-pushed the fontLoader branch 2 times, most recently from cd3180b to bef4e5d Compare February 25, 2023 18:57
@gandalfthewhite19890404

Hello!
Can you add more glyph ranges - not only Latin?

@Gliniak
Copy link
Member Author

Gliniak commented Feb 26, 2023

Sure (at least on windows), do you know font that looks good and support these glyphs?

@gandalfthewhite19890404

SegoeUI, Arial, Times New Roman.
There many of them, if some font does not have needed symbols - there will be a question marks. So adding glyphs to sources is safe change. If I talk wrong things - sorry, make edits.

@Gliniak
Copy link
Member Author

Gliniak commented Feb 27, 2023

Not sure what's a better idea there.
To assume that custom font might include them or to always load another font that will contain them?

@gandalfthewhite19890404

What if bundle with emulator some free nice looking font as default, for example Koruri, it could be big - size is an issue?
And let user to choose his own font if he wants?

@Gliniak
Copy link
Member Author

Gliniak commented Mar 15, 2023

I will suggest similar solution that is used in canary.

Priority of font loading:

  1. Custom font
  2. (on windows only) Tahoma from fonts directory

If no font is loaded then load default font.

  • at the end always load Japanese font

How Tahoma looks like (with font set to 16)
obraz

@gandalfthewhite19890404

Brilliant! Thank you very much!!!

@Gliniak Gliniak changed the title [UI] Allow loading custom font [UI] Changed default Windows font & Allow loading custom font Mar 22, 2023
PWSTR fonts_dir;
HRESULT result = SHGetKnownFolderPath(FOLDERID_Fonts, 0, NULL, &fonts_dir);
if (FAILED(result)) {
CoTaskMemFree(static_cast<void*>(fonts_dir));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fonts_dir would likely (though I'm not entirely sure about this specific case, of course) only be initialized if the function has succeeded, this freeing may cause a crash.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath

The calling process is responsible for freeing this resource once it is no longer needed by calling [CoTaskMemFree](https://learn.microsoft.com/en-us/windows/desktop/api/combaseapi/nf-combaseapi-cotaskmemfree), whether SHGetKnownFolderPath succeeds or not

font_path = std::wstring(fonts_dir);
CoTaskMemFree(static_cast<void*>(fonts_dir));
#endif
font_path.append(font_name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A blank line above this line would make the code visually more structured.

0,
};

const std::filesystem::path ImGuiDrawer::GetWindowsFont(std::string font_name) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might have been more platform-independent as other operating systems also have their own font storages, and possibly accepting the name (family, weight, italic, etc. possibly) of the font with the necessary lookups in the OS rather than directly the file name. The fallback behavior is also pretty non-obvious in this function. On Windows, it returns an empty path if it has failed to obtain the system fonts directory. However, on other platforms, it just silently tries to get the path from the working directory instead.

const std::filesystem::path font_path = GetWindowsFont("tahoma.ttf");
if (!std::filesystem::exists(font_path)) {
XELOGW(
"Unable to find tahoma font in Windows fonts directory. Switching to "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tahoma → Tahoma

- Unified font size to 12. This causes default UI to look a bit bigger
- Set oversample to 2 to make font more readable (especially custom fonts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants