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

Code before:
  {
    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)
  {
    if (XFILE::CDirectory::Exists(dir))
      addRootChildText("dir", dir);
  }

  addRootChildText("cachedir", fontconfigCacheDir);

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

  if (!XFILE::CFile::Exists(fontconfigPath))
  {
    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());


Review comment (suggestion):
...not like that,
this way the above code related to xml is executed without real use, should be moved

Code after:
    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)
    {
      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());