diff options
author | enen92 <enen92@users.noreply.github.com> | 2020-11-16 09:22:36 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-16 09:22:36 +0000 |
commit | 190f42c3ad46297ca8b27d6ccd810ce260b3e987 (patch) | |
tree | 84723f856c468695d12ad84a25319eb059e96ee8 | |
parent | 5df6612fa9d29daace7906550387ea3334fa895c (diff) | |
parent | 1c624b38075512245c7b93a8fd4b100a09c901a1 (diff) |
Merge pull request #18794 from enen92/assoverride
[Subtitles][Ass] Fix non-working ASS-Override setting
-rw-r--r-- | xbmc/cores/VideoPlayer/DVDSubtitles/DVDSubtitlesLibass.cpp | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/xbmc/cores/VideoPlayer/DVDSubtitles/DVDSubtitlesLibass.cpp b/xbmc/cores/VideoPlayer/DVDSubtitles/DVDSubtitlesLibass.cpp index ac37f0b4bc..41c824969f 100644 --- a/xbmc/cores/VideoPlayer/DVDSubtitles/DVDSubtitlesLibass.cpp +++ b/xbmc/cores/VideoPlayer/DVDSubtitles/DVDSubtitlesLibass.cpp @@ -20,6 +20,35 @@ #include "utils/log.h" #include "windowing/GraphicContext.h" +namespace +{ +void AppendFont(const std::string& font) +{ + std::string finalFontPath = URIUtils::AddFileToFolder("special://temp/fonts/", font); + if (XFILE::CFile::Exists(finalFontPath)) + { + CLog::Log(LOGDEBUG, + "CDVDSubtitlesLibass: Skipping copy of {} to special://temp/fonts/ (already exists)", + font); + return; + } + + std::string fontSources[]{"special://home/media/Fonts/", "special://xbmc/media/Fonts/"}; + + for (const auto& path : fontSources) + { + auto fontPath = URIUtils::AddFileToFolder(path, font); + if (XFILE::CFile::Exists(fontPath)) + { + XFILE::CFile::Copy(fontPath, finalFontPath); + CLog::Log(LOGDEBUG, "CDVDSubtitlesLibass: Copied {} to {}", fontPath, finalFontPath); + return; + } + CLog::Log(LOGDEBUG, "CDVDSubtitlesLibass: Could not find font {} in font sources", font); + } +} +} // namespace + static void libass_log(int level, const char *fmt, va_list args, void *data) { if(level >= 5) @@ -40,6 +69,13 @@ CDVDSubtitlesLibass::CDVDSubtitlesLibass() ass_set_message_cb(m_library, libass_log, this); + // Add configured subtitle font to special://temp/fonts/. This needs to be done before + // ass_set_fonts_dir. If fontconfig fails it will use the default font. + const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings(); + std::string forcedFont = settings->GetString(CSettings::SETTING_SUBTITLES_FONT); + AppendFont(forcedFont); + strPath = URIUtils::AddFileToFolder(strPath, forcedFont); + CLog::Log(LOGINFO, "CDVDSubtitlesLibass: Initializing ASS library font settings"); // libass uses fontconfig (system lib) which is not wrapped // so translate the path before calling into libass @@ -54,23 +90,17 @@ CDVDSubtitlesLibass::CDVDSubtitlesLibass() if(!m_renderer) return; - //Setting default font to the Arial in \media\fonts (used if FontConfig fails) - const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings(); - strPath = URIUtils::AddFileToFolder("special://home/media/Fonts/", settings->GetString(CSettings::SETTING_SUBTITLES_FONT)); - if (!XFILE::CFile::Exists(strPath)) - strPath = URIUtils::AddFileToFolder("special://xbmc/media/Fonts/", settings->GetString(CSettings::SETTING_SUBTITLES_FONT)); - int fc = !settings->GetBool(CSettings::SETTING_SUBTITLES_OVERRIDEASSFONTS); - ass_set_margins(m_renderer, 0, 0, 0, 0); ass_set_use_margins(m_renderer, 0); ass_set_font_scale(m_renderer, 1); + int fontconfig = settings->GetBool(CSettings::SETTING_SUBTITLES_OVERRIDEASSFONTS) ? 0 : 1; // libass uses fontconfig (system lib) which is not wrapped // so translate the path before calling into libass - ass_set_fonts(m_renderer, CSpecialProtocol::TranslatePath(strPath).c_str(), "Arial", fc, NULL, 1); + ass_set_fonts(m_renderer, CSpecialProtocol::TranslatePath(strPath).c_str(), "Arial", fontconfig, + nullptr, 1); } - CDVDSubtitlesLibass::~CDVDSubtitlesLibass() { if(m_track) @@ -168,4 +198,3 @@ int CDVDSubtitlesLibass::GetNrOfEvents() return 0; return m_track->n_events; } - |