From 27fd1762539f1d4c67fa862e12d65869f07414b4 Mon Sep 17 00:00:00 2001 From: Vyacheslav Karpukhin Date: Tue, 2 Jul 2024 01:48:06 +0200 Subject: [Subtitles][Settings] Add a setting to make subtitles line spacing configurable - The default value is chosen to avoid the overlaps with Box background style - Some of the subtitles settings are moved from Expert to Advanced level --- addons/resource.language.en_gb/resources/strings.po | 14 +++++++++++++- system/settings/settings.xml | 17 +++++++++++------ .../VideoPlayer/DVDSubtitles/DVDSubtitlesLibass.cpp | 10 ++++++---- xbmc/cores/VideoPlayer/DVDSubtitles/SubtitlesStyle.h | 1 + .../VideoPlayer/VideoRenderers/OverlayRenderer.cpp | 1 + xbmc/settings/Settings.h | 1 + xbmc/settings/SubtitlesSettings.cpp | 7 ++++++- xbmc/settings/SubtitlesSettings.h | 6 ++++++ 8 files changed, 45 insertions(+), 12 deletions(-) diff --git a/addons/resource.language.en_gb/resources/strings.po b/addons/resource.language.en_gb/resources/strings.po index 46d1d6174f..5573d28eb6 100644 --- a/addons/resource.language.en_gb/resources/strings.po +++ b/addons/resource.language.en_gb/resources/strings.po @@ -24169,7 +24169,19 @@ msgctxt "#39201" msgid "HDR10+" msgstr "" -#empty strings from id 39202 to 39999 +#. Subtitle line spacing setting +#: system/settings/settings.xml +msgctxt "#39202" +msgid "Line spacing" +msgstr "" + +#. Subtitle line spacing setting help +#: system/settings/settings.xml +msgctxt "#39203" +msgid "Adjust the space between lines of text. Setting a value too low may cause boxes to overlap when the \"Background type\" setting is used." +msgstr "" + +#empty strings from id 39204 to 39999 # 40000 to 40800 are reserved for Video Versions feature diff --git a/system/settings/settings.xml b/system/settings/settings.xml index 7434932d4a..db2375bb0a 100755 --- a/system/settings/settings.xml +++ b/system/settings/settings.xml @@ -605,7 +605,7 @@ - 3 + 2 42 12 @@ -618,7 +618,7 @@ - 3 + 2 0 @@ -631,17 +631,17 @@ - 3 + 2 FFFFFFFF - 3 + 2 100 - 3 + 2 25 2 @@ -649,7 +649,7 @@ - 3 + 2 FF000000 2 @@ -661,6 +661,11 @@ 0 + + 3 + 12 + + 3 0 diff --git a/xbmc/cores/VideoPlayer/DVDSubtitles/DVDSubtitlesLibass.cpp b/xbmc/cores/VideoPlayer/DVDSubtitles/DVDSubtitlesLibass.cpp index 1858a4aa2e..4fcf2dc236 100644 --- a/xbmc/cores/VideoPlayer/DVDSubtitles/DVDSubtitlesLibass.cpp +++ b/xbmc/cores/VideoPlayer/DVDSubtitles/DVDSubtitlesLibass.cpp @@ -420,7 +420,6 @@ void CDVDSubtitlesLibass::ApplyStyle(const std::shared_ptr& subSty style->SecondaryColour = ConvColor(COLOR::BLACK); // Configure the effects - double lineSpacing = 0.0; if (subStyle->borderStyle == BorderType::OUTLINE || subStyle->borderStyle == BorderType::OUTLINE_NO_SHADOW) { @@ -450,8 +449,6 @@ void CDVDSubtitlesLibass::ApplyStyle(const std::shared_ptr& subSty style->BackColour = ConvColor(subStyle->shadowColor, subStyle->shadowOpacity); // Set the box shadow color style->Shadow = (10.00 / 100 * subStyle->shadowSize) * scale; // Set the box shadow size - // By default a box overlaps the other, then we increase a bit the line spacing - lineSpacing = 8.0 * scaleDefault; } else if (subStyle->borderStyle == BorderType::SQUARE_BOX) { @@ -463,9 +460,14 @@ void CDVDSubtitlesLibass::ApplyStyle(const std::shared_ptr& subSty style->Shadow = 4 * scale; // Space between the text and the box edges } + double lineSpacing = (static_cast(subStyle->lineSpacing) * (playResY / 4)) / 100; + if (subStyle->assOverrideFont) + lineSpacing *= scaleDefault; + else + lineSpacing *= scale; // ass_set_line_spacing do not scale, so we have to scale to frame size ass_set_line_spacing(m_renderer, - lineSpacing / playResY * static_cast(opts.frameHeight)); + lineSpacing / playResY * static_cast(opts.frameHeight / 4)); style->Blur = (10.00 / 100 * subStyle->blur); diff --git a/xbmc/cores/VideoPlayer/DVDSubtitles/SubtitlesStyle.h b/xbmc/cores/VideoPlayer/DVDSubtitles/SubtitlesStyle.h index f276012e93..cf0c53d0f2 100644 --- a/xbmc/cores/VideoPlayer/DVDSubtitles/SubtitlesStyle.h +++ b/xbmc/cores/VideoPlayer/DVDSubtitles/SubtitlesStyle.h @@ -101,6 +101,7 @@ struct style // Vertical margin value in pixels scaled for VIEWPORT_HEIGHT int marginVertical = MARGIN_VERTICAL; int blur = 0; // In % + int lineSpacing = 0; }; struct subtitleOpts diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRenderer.cpp b/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRenderer.cpp index 246128003a..aa776c5b5d 100644 --- a/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRenderer.cpp +++ b/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRenderer.cpp @@ -398,6 +398,7 @@ void CRenderer::CreateSubtitlesStyle() static_cast(settings->GetVerticalMarginPerc())); m_overlayStyle->blur = settings->GetBlurSize(); + m_overlayStyle->lineSpacing = settings->GetLineSpacing(); } std::shared_ptr CRenderer::ConvertLibass( diff --git a/xbmc/settings/Settings.h b/xbmc/settings/Settings.h index f600c315f5..203479aaf1 100644 --- a/xbmc/settings/Settings.h +++ b/xbmc/settings/Settings.h @@ -160,6 +160,7 @@ public: static constexpr auto SETTING_SUBTITLES_BORDERCOLOR = "subtitles.bordercolorpick"; static constexpr auto SETTING_SUBTITLES_OPACITY = "subtitles.opacity"; static constexpr auto SETTING_SUBTITLES_BLUR = "subtitles.blur"; + static constexpr auto SETTING_SUBTITLES_LINE_SPACING = "subtitles.linespacing"; static constexpr auto SETTING_SUBTITLES_BACKGROUNDTYPE = "subtitles.backgroundtype"; static constexpr auto SETTING_SUBTITLES_SHADOWCOLOR = "subtitles.shadowcolor"; static constexpr auto SETTING_SUBTITLES_SHADOWOPACITY = "subtitles.shadowopacity"; diff --git a/xbmc/settings/SubtitlesSettings.cpp b/xbmc/settings/SubtitlesSettings.cpp index 66ef6360eb..78c354b67e 100644 --- a/xbmc/settings/SubtitlesSettings.cpp +++ b/xbmc/settings/SubtitlesSettings.cpp @@ -38,7 +38,7 @@ CSubtitlesSettings::CSubtitlesSettings(const std::shared_ptr& setting CSettings::SETTING_SUBTITLES_LANGUAGES, CSettings::SETTING_SUBTITLES_STORAGEMODE, CSettings::SETTING_SUBTITLES_CUSTOMPATH, CSettings::SETTING_SUBTITLES_PAUSEONSEARCH, CSettings::SETTING_SUBTITLES_DOWNLOADFIRST, CSettings::SETTING_SUBTITLES_TV, - CSettings::SETTING_SUBTITLES_MOVIE}); + CSettings::SETTING_SUBTITLES_MOVIE, CSettings::SETTING_SUBTITLES_LINE_SPACING}); } CSubtitlesSettings::~CSubtitlesSettings() @@ -133,6 +133,11 @@ int CSubtitlesSettings::GetBlurSize() return m_settings->GetInt(CSettings::SETTING_SUBTITLES_BLUR); } +int CSubtitlesSettings::GetLineSpacing() +{ + return m_settings->GetInt(CSettings::SETTING_SUBTITLES_LINE_SPACING); +} + BackgroundType CSubtitlesSettings::GetBackgroundType() { return static_cast( diff --git a/xbmc/settings/SubtitlesSettings.h b/xbmc/settings/SubtitlesSettings.h index 3927de1069..831dfaf374 100644 --- a/xbmc/settings/SubtitlesSettings.h +++ b/xbmc/settings/SubtitlesSettings.h @@ -160,6 +160,12 @@ public: */ int GetBlurSize(); + /*! + * \brief Get line spacing + * \return The line spacing + */ + int GetLineSpacing(); + /*! * \brief Get background type * \return The background type -- cgit v1.2.3