Skip to content

Commit

Permalink
[Subtitles][ASS] Support both user defined fonts and extracted fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
enen92 committed Apr 8, 2021
1 parent 87fc997 commit c403321
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
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

0 comments on commit c403321

Please sign in to comment.