Repository: xbmc/xbmc
File: xbmc/cores/VideoPlayer/DVDSubtitles/DVDSubtitlesLibass.cpp (C++)

Code before:
                              "  <dir>/product/fonts</dir>\n"
                              "  <dir>/system_ext/fonts</dir>\n"
                              "  <dir>/vendor/fonts</dir>\n"
                              "  <cachedir>" +
                              escapedCacheDir +
                              "</cachedir>\n"
                              "</fontconfig>\n";

  // Write fontconfig configuration to temp directory (only if it doesn't exist)
  fontconfigPath = CSpecialProtocol::TranslatePath("special://temp/fonts.conf");

  if (!XFILE::CFile::Exists(fontconfigPath))
  {
    XFILE::CFile fontconfigFile;
    if (fontconfigFile.OpenForWrite(fontconfigPath, true))
    {
      fontconfigFile.Write(fontconfigXml.c_str(), fontconfigXml.length());
      fontconfigFile.Close();
      fontconfigConfig = fontconfigPath.c_str();
      CLog::Log(LOGINFO, "CDVDSubtitlesLibass: Created fontconfig configuration at {}",
                fontconfigPath);
    }
    else
    {
      CLog::Log(LOGERROR, "CDVDSubtitlesLibass: Failed to create fontconfig configuration, falling "
                          "back to AUTODETECT");
      fontProvider = ASS_FONTPROVIDER_AUTODETECT;
      fontconfigConfig = nullptr;
    }
  }
  else
  { 
    fontconfigConfig = fontconfigPath.c_str();
  }
#endif

  // Set additional fonts directory for libass to scan. This provides font lookup
  // on platforms without a font provider, and supplements fontconfig on platforms that use it.
  ass_set_fonts_dir(m_library, fontsDir.c_str());

  // Load additional fonts into Libass memory
  CFileItemList items;
  // Get fonts from system directory
  if (XFILE::CDirectory::Exists(FONT::FONTPATH::SYSTEM))
  {
    XFILE::CDirectory::GetDirectory(FONT::FONTPATH::SYSTEM, items, FONT::SUPPORTED_EXTENSIONS_MASK,
                                    XFILE::DIR_FLAG_NO_FILE_DIRS | XFILE::DIR_FLAG_NO_FILE_INFO);
  }

  const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
  const bool overrideFont = settings->GetBool(CSettings::SETTING_SUBTITLES_OVERRIDEFONTS);

Review comment (bug):
```suggestion
      CLog::LogF(LOGERROR, "Failed to create fontconfig configuration, falling back to ASS_FONTPROVIDER_AUTODETECT");
```

Code after:
    {
      if (XFILE::CDirectory::Exists(dir))
        addRootChildText("dir", dir);
    }

    addRootChildText("cachedir", fontconfigCacheDir);

    if (xmlDoc.SaveFile(fontconfigPath))
    {
      fontconfigConfig = fontconfigPath.c_str();
      CLog::Log(LOGINFO, "CDVDSubtitlesLibass: Created fontconfig configuration at {}",
                fontconfigPath);
    }
    else
    {
      CLog::LogF(LOGERROR, "Failed to create fontconfig configuration, falling back to "
                           "ASS_FONTPROVIDER_AUTODETECT");
      fontProvider = ASS_FONTPROVIDER_AUTODETECT;
      fontconfigConfig = nullptr;
    }
  }
  else
  {
    fontconfigConfig = fontconfigPath.c_str();
  }
#endif

  // Set additional fonts directory for libass to scan. This provides font lookup
  // on platforms without a font provider, and supplements fontconfig on platforms that use it.
  ass_set_fonts_dir(m_library, CSpecialProtocol::TranslatePath(FONT::FONTPATH::USER).c_str());

  // Load additional fonts into Libass memory
  CFileItemList items;
  // Get fonts from system directory
  if (XFILE::CDirectory::Exists(FONT::FONTPATH::SYSTEM))
  {
    XFILE::CDirectory::GetDirectory(FONT::FONTPATH::SYSTEM, items, FONT::SUPPORTED_EXTENSIONS_MASK,
                                    XFILE::DIR_FLAG_NO_FILE_DIRS | XFILE::DIR_FLAG_NO_FILE_INFO);
  }

  const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
  const bool overrideFont = settings->GetBool(CSettings::SETTING_SUBTITLES_OVERRIDEFONTS);
  // Get temporary fonts
  if (!overrideFont && XFILE::CDirectory::Exists(FONT::FONTPATH::TEMP, false))
  {
    XFILE::CDirectory::GetDirectory(FONT::FONTPATH::TEMP, items, FONT::SUPPORTED_EXTENSIONS_MASK,
                                    XFILE::DIR_FLAG_BYPASS_CACHE | XFILE::DIR_FLAG_NO_FILE_DIRS |
                                        XFILE::DIR_FLAG_NO_FILE_INFO);
  }
  for (const auto& item : items)
  {