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

Code before:
  if (!m_renderer)
  {
    CLog::Log(LOGERROR, "CDVDSubtitlesLibass: Failed to initialize ASS font settings. ASS renderer "
                        "not initialized.");
    return;
  }

  ass_set_margins(m_renderer, 0, 0, 0, 0);
  ass_set_use_margins(m_renderer, 0);

  int fontProvider = ASS_FONTPROVIDER_AUTODETECT;
  std::string fontconfigPath; // Keep string alive for lifetime of fontconfigConfig pointer
  const char* fontconfigConfig = nullptr;

#if defined(TARGET_ANDROID)
  // Libass uses system font provider (like fontconfig) by default on some platforms (e.g. Linux/Windows),
  // but on Android the font provider is currently not supported by libass.
  // Workaround: Use fontconfig with a custom configuration pointing to Android system fonts,
  // enabling automatic font fallback for subtitles with non-Latin scripts.
  // This is a temporary workaround until libass implements native Android font provider support.
  fontProvider = ASS_FONTPROVIDER_FONTCONFIG;

  // Create fontconfig cache directory
  const std::string fontconfigCacheDir =
      CSpecialProtocol::TranslatePath("special://temp/fontconfig");
  XFILE::CDirectory::Create(fontconfigCacheDir);

  // Create fontconfig configuration using XML library
  CXBMCTinyXML2 xmlDoc;
  xmlDoc.InsertEndChild(xmlDoc.NewDeclaration("xml version=\"1.0\""));
  xmlDoc.InsertEndChild(xmlDoc.NewUnknown("DOCTYPE fontconfig SYSTEM \"fonts.dtd\""));

  tinyxml2::XMLElement* eRoot = xmlDoc.NewElement("fontconfig");
  xmlDoc.InsertEndChild(eRoot);

  auto addRootChildText = [&](const char* name, const std::string& value)
  {
    tinyxml2::XMLElement* elem = xmlDoc.NewElement(name);
    elem->SetText(value.c_str());
    eRoot->InsertEndChild(elem);
  };

  // Add Android system font directories
  // Note: USER and SYSTEM dirs are handled by ass_set_fonts_dir below
  const std::vector<std::string> fontDirs = {
      "/system/fonts", // AOSP standard
      "/product/fonts", // AOSP vendor-specific
      "/system_ext/fonts" // OEM-specific (may not exist on all devices)
  };

  for (const auto& dir : fontDirs)

Review comment (performance):
```
if (!XFILE::CDirectory::Exists(fontconfigCacheDir))
  XFILE::CDirectory::Create(fontconfigCacheDir);
```

Code after:
  if (!m_renderer)
  {
    CLog::Log(LOGERROR, "CDVDSubtitlesLibass: Failed to initialize ASS font settings. ASS renderer "
                        "not initialized.");
    return;
  }

  ass_set_margins(m_renderer, 0, 0, 0, 0);
  ass_set_use_margins(m_renderer, 0);

  int fontProvider = ASS_FONTPROVIDER_AUTODETECT;
  std::string fontconfigPath; // Keep string alive for lifetime of fontconfigConfig pointer
  const char* fontconfigConfig = nullptr;

#if defined(TARGET_ANDROID)
  // Libass uses system font provider (like fontconfig) by default on some platforms (e.g. Linux/Windows),
  // but on Android the font provider is currently not supported by libass.
  // Workaround: Use fontconfig with a custom configuration pointing to Android system fonts,
  // enabling automatic font fallback for subtitles with non-Latin scripts.
  // This is a temporary workaround until libass implements native Android font provider support.
  fontProvider = ASS_FONTPROVIDER_FONTCONFIG;

  // Write fontconfig configuration to temp directory
  fontconfigPath = CSpecialProtocol::TranslatePath("special://temp/fonts.conf");

  if (!XFILE::CFile::Exists(fontconfigPath))
  {
    // Create fontconfig cache directory
    const std::string fontconfigCacheDir =
        CSpecialProtocol::TranslatePath("special://temp/fontconfig");
    if (!XFILE::CDirectory::Exists(fontconfigCacheDir))
      XFILE::CDirectory::Create(fontconfigCacheDir);

    // Create fontconfig configuration using XML library
    CXBMCTinyXML2 xmlDoc;
    xmlDoc.InsertEndChild(xmlDoc.NewDeclaration("xml version=\"1.0\""));
    xmlDoc.InsertEndChild(xmlDoc.NewUnknown("DOCTYPE fontconfig SYSTEM \"fonts.dtd\""));

    tinyxml2::XMLElement* eRoot = xmlDoc.NewElement("fontconfig");
    xmlDoc.InsertEndChild(eRoot);

    auto addRootChildText = [&](const char* name, const std::string& value)
    {
      tinyxml2::XMLElement* elem = xmlDoc.NewElement(name);
      elem->SetText(value.c_str());
      eRoot->InsertEndChild(elem);
    };

    // Add Android system font directories
    // Note: USER and SYSTEM dirs are handled by ass_set_fonts_dir below
    const std::vector<std::string> fontDirs = {