Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Subtitles][ASS] Support both user defined fonts and extracted fonts #19535

Merged
merged 1 commit into from Apr 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions xbmc/Util.cpp
Expand Up @@ -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;
Expand All @@ -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());
}
}

Expand Down
8 changes: 6 additions & 2 deletions xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
Expand Up @@ -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)
Expand All @@ -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))
{
Expand Down
5 changes: 3 additions & 2 deletions xbmc/cores/VideoPlayer/DVDSubtitles/DVDSubtitlesLibass.cpp
Expand Up @@ -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();
Expand Down