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

Fix linux fontconfig #1771

Merged
merged 8 commits into from
Nov 24, 2024
5 changes: 2 additions & 3 deletions rts/Rendering/Fonts/CFontTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class FtLibraryHandler {
return;
}

config = FcConfigCreate();
config = FcInitLoadConfigAndFonts();
if (!config)
return;

Expand Down Expand Up @@ -192,7 +192,6 @@ class FtLibraryHandler {

FcConfigAppFontClear(GetFCConfig());
FcConfigAppFontAddDir(GetFCConfig(), reinterpret_cast<const FcChar8*>("fonts"));
FcConfigAppFontAddDir(GetFCConfig(), reinterpret_cast<const FcChar8*>(osFontsDir));

{
auto dirs = FcConfigGetCacheDirs(GetFCConfig());
Expand Down Expand Up @@ -461,7 +460,7 @@ static std::shared_ptr<FontFace> GetFontForCharacters(const std::vector<char32_t

if (family)
FcPatternAddString(pattern, FC_FAMILY, family);
if (foundry)
if (foundry && strcmp("UKWN", reinterpret_cast<char*>(foundry)) != 0 && strcmp("ukwn", reinterpret_cast<char*>(foundry)) != 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we put something like your comment from the PR description here, perhaps away in some sort of function?

Suggested change
if (foundry && strcmp("UKWN", reinterpret_cast<char*>(foundry)) != 0 && strcmp("ukwn", reinterpret_cast<char*>(foundry)) != 0)
if (foundry && isFoundryOkay(foundry))
static bool isFoundryOkay(const auto *foundry) {
  // guaranteed null-terminated because of blabla
  auto *const foundryString = reinterpret_cast <char*> (foundry);

  /* (FIXME wants better wording, i just copypasted from PR)
   * it's not finding requested glyphs (at least in first matches) when that is set.
   * Imo we could just not filter by foundry at all and would be cleaner but
   * trying to modify behaviour as little as possible. I know fontconfig should
   * be returning matching fonts in order of priority filters, but somehow
   * that's breaking it completely. Those foundries are defaults from some
   * programs and totally not recommended to have inside font files. */
  return strcmp("UKWN", foundryString) != 0 // fixme: consider string_view + starts_with, more idiomatic
      && strcmp("ukwn", foundryString) != 0; // fixme: case sensitivity (can a foundry be "Uknw"?)
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed that.

Regarding UKWN and ukwn case sensitivity, I found this seeming to imply just UKWN and ukwn are possible fonttools/fontbakery#713, also https://github.com/fonttools/fontbakery/blob/c9954809500b6a2fe4b03995594b917167315ecc/Lib/fontbakery/checks/vendorspecific/googlefonts/os2.py#L104 has some other bad codes but not sure we should filter by those too since we're not having any problems related to that and seems complicating the code for nothing atm.

FcPatternAddString(pattern, FC_FOUNDRY, foundry);
}

Expand Down