From c40332165fa6dc200ce17a6af2d1d153e5ef5411 Mon Sep 17 00:00:00 2001 From: enen92 <92enen@gmail.com> Date: Wed, 7 Apr 2021 23:33:12 +0100 Subject: [PATCH] [Subtitles][ASS] Support both user defined fonts and extracted fonts --- xbmc/Util.cpp | 6 ++++-- xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp | 8 ++++++-- .../cores/VideoPlayer/DVDSubtitles/DVDSubtitlesLibass.cpp | 5 +++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/xbmc/Util.cpp b/xbmc/Util.cpp index 727dbb09a0dfa..a12aec6b6e085 100644 --- a/xbmc/Util.cpp +++ b/xbmc/Util.cpp @@ -679,7 +679,7 @@ void CUtil::ClearSubtitles() void CUtil::ClearTempFonts() { - std::string searchPath = "special://temp/fonts/"; + const std::string searchPath = "special://home/media/Fonts/"; if (!CDirectory::Exists(searchPath)) return; @@ -691,7 +691,9 @@ void CUtil::ClearTempFonts() { if (item->m_bIsFolder) continue; - CFile::Delete(item->GetPath()); + + if (StringUtils::StartsWithNoCase(URIUtils::GetFileName(item->GetPath()), "tmp.font.")) + CFile::Delete(item->GetPath()); } } diff --git a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp index c6a93a3f60fe3..95043cc57942f 100644 --- a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp +++ b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp @@ -1708,7 +1708,7 @@ CDemuxStream* CDVDDemuxFFmpeg::AddStream(int streamIdx) if (pStream->codecpar->codec_id == AV_CODEC_ID_TTF || pStream->codecpar->codec_id == AV_CODEC_ID_OTF || AttachmentIsFont(attachmentMimetype)) { - std::string fileName = "special://temp/fonts/"; + std::string fileName = "special://home/media/Fonts/"; XFILE::CDirectory::Create(fileName); AVDictionaryEntry* nameTag = av_dict_get(pStream->metadata, "filename", NULL, 0); if (!nameTag) @@ -1717,7 +1717,11 @@ CDemuxStream* CDVDDemuxFFmpeg::AddStream(int streamIdx) } else { - fileName += CUtil::MakeLegalFileName(nameTag->value, LEGAL_WIN32_COMPAT); + // Note: libass only supports a single font directory to look for aditional fonts + // (c.f. ass_set_fonts_dir). To support both user defined fonts (those placed in + // special://home/media/Fonts/) and fonts extracted by the demuxer, make it extract + // fonts to the user directory with a known, easy to identify, prefix (tmp.font.*). + fileName += "tmp.font." + CUtil::MakeLegalFileName(nameTag->value, LEGAL_WIN32_COMPAT); XFILE::CFile file; if (pStream->codecpar->extradata && file.OpenForWrite(fileName)) { diff --git a/xbmc/cores/VideoPlayer/DVDSubtitles/DVDSubtitlesLibass.cpp b/xbmc/cores/VideoPlayer/DVDSubtitles/DVDSubtitlesLibass.cpp index 4efc35dcadfe5..26c2e60a2bad8 100644 --- a/xbmc/cores/VideoPlayer/DVDSubtitles/DVDSubtitlesLibass.cpp +++ b/xbmc/cores/VideoPlayer/DVDSubtitles/DVDSubtitlesLibass.cpp @@ -49,8 +49,9 @@ static void libass_log(int level, const char *fmt, va_list args, void *data) CDVDSubtitlesLibass::CDVDSubtitlesLibass() { - //Setting the font directory to the temp dir(where mkv fonts are extracted to) - std::string strPath = "special://temp/fonts/"; + // Setting the font directory to the user font dir. This is the directory + // where user defined fonts are located (and where mkv fonts are extracted to) + const std::string strPath = "special://home/media/Fonts/"; CLog::Log(LOGINFO, "CDVDSubtitlesLibass: Creating ASS library structure"); m_library = ass_library_init();