Skip to content

Commit

Permalink
[Subtitles] Show font family name's to subtitle fonts list
Browse files Browse the repository at this point in the history
  • Loading branch information
phunkyfish committed Jan 29, 2024
1 parent b2f5b16 commit b744b5d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/stream/FFmpegStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2142,11 +2142,16 @@ DemuxStream* FFmpegStream::AddStream(int streamIdx)
}
else
{
// Note: libass only supports a single font directory to look for additional 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." + FilenameUtils::MakeLegalFileName(nameTag->value, LEGAL_WIN32_COMPAT);
// Note: Libass only supports a single additional font directory,
// currently set for user fonts (c.f. ass_set_fonts_dir) therefore
// we will also use this folder to store fonts extracted by the
// demuxer. The extracted fonts will have a prefix in the filename
// for easy identification.
//! @todo: this font file management system on disk could be completely
//! removed, by sending font data to the subtitle renderer and
//! using libass ass_add_font to add the fonts directly in memory.
fileName += FilenameUtils::TEMP_FONT_FILENAME_PREFIX +
FilenameUtils::MakeLegalFileName(nameTag->value, LEGAL_WIN32_COMPAT);
kodi::vfs::CFile file;
if (pStream->codecpar->extradata && file.OpenFileForWrite(fileName))
{
Expand Down
5 changes: 4 additions & 1 deletion src/utils/FilenameUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ namespace ffmpegdirect
static const int LEGAL_WIN32_COMPAT = 1;
static const int LEGAL_FATX = 2;

// Prefix used to store temporary font files in the user fonts folder
constexpr const char* TEMP_FONT_FILENAME_PREFIX = "tmp.font.";

class FilenameUtils
{
public:
Expand All @@ -24,6 +27,6 @@ namespace ffmpegdirect
#else
static std::string MakeLegalFileName(const std::string &strFile, int LegalType=LEGAL_NONE);
static std::string MakeLegalPath(const std::string &strPath, int LegalType=LEGAL_NONE);
#endif
#endif
};
} //namespace ffmpegdirect

0 comments on commit b744b5d

Please sign in to comment.