From b744b5ded0bc28d2a249c55ce7f9bdb87da21151 Mon Sep 17 00:00:00 2001 From: phunkyfish Date: Mon, 29 Jan 2024 10:24:11 +0000 Subject: [PATCH] [Subtitles] Show font family name's to subtitle fonts list --- src/stream/FFmpegStream.cpp | 15 ++++++++++----- src/utils/FilenameUtils.h | 5 ++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/stream/FFmpegStream.cpp b/src/stream/FFmpegStream.cpp index 97e3143f..94c47be2 100644 --- a/src/stream/FFmpegStream.cpp +++ b/src/stream/FFmpegStream.cpp @@ -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)) { diff --git a/src/utils/FilenameUtils.h b/src/utils/FilenameUtils.h index 837a8790..4ea8dc7a 100644 --- a/src/utils/FilenameUtils.h +++ b/src/utils/FilenameUtils.h @@ -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: @@ -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 \ No newline at end of file