diff --git a/Source/SubtitleProvider.h b/Source/SubtitleProvider.h index cbde87ce2b..056b3ad71e 100644 --- a/Source/SubtitleProvider.h +++ b/Source/SubtitleProvider.h @@ -193,6 +193,11 @@ class SubtitleProvider : int parseHexOrDecimalInt(std::wstring const& str, size_t offset) { + if (offset > 2 && str[offset - 2] == L'H' && str[offset - 1] == L'&') + { + // Fix for cases where colors are specified like: 3cH&H2A4F5D& + offset++; + } if (str.length() > offset + 1 && str[offset] == L'H') { return parseHexInt(str.substr(offset + 1)); diff --git a/Source/SubtitleProviderSsaAss.h b/Source/SubtitleProviderSsaAss.h index fd4996ddff..4246438faa 100644 --- a/Source/SubtitleProviderSsaAss.h +++ b/Source/SubtitleProviderSsaAss.h @@ -67,6 +67,7 @@ class SubtitleProviderSsaAss : public SubtitleProvider if (resy != str.npos && sscanf_s((char*)m_pAvCodecCtx->subtitle_header + resy, "\nPlayResY: %i\n", &h) == 1) { + hasPlayResY = true; height = h; } @@ -293,6 +294,14 @@ class SubtitleProviderSsaAss : public SubtitleProvider subStyle.FontFamily(GetFontFamily(fnName)); } } + else if (checkTag(tag, L"fsc")) + { + // TODO: \fsc x scales horizontally, y scales vertically + } + else if (checkTag(tag, L"fsp")) + { + // TODO: \fsp changes the distance between letters. (default: 0) + } else if (checkTag(tag, L"fs")) { auto size = parseDouble(tag.substr(2)); @@ -301,6 +310,11 @@ class SubtitleProviderSsaAss : public SubtitleProvider subStyle.FontSize(GetFontSize(size)); } } + else if (checkTag(tag, L"clip")) + { + // TODO: \clip(, , , ) Clips any drawing outside the rectangle defined by the parameters. + // \clip([,] ) Clipping against drawn shapes. has the same meaning as in the case of \p + } else if (checkTag(tag, L"c", 2)) { int color = parseHexOrDecimalInt(tag, 2); @@ -425,7 +439,8 @@ class SubtitleProviderSsaAss : public SubtitleProvider } catch (...) { - OutputDebugString(L"Failed to parse tag: "); + std::wstring output = L"Failed to parse tag: " + tag + L"\r\n"; + OutputDebugString(output.c_str()); } } @@ -574,7 +589,7 @@ class SubtitleProviderSsaAss : public SubtitleProvider } else if (result <= 0) { - OutputDebugString(L"Failed to decode subtitle."); + OutputDebugString(L"Failed to decode subtitle.\r\n"); } return nullptr; @@ -601,14 +616,14 @@ class SubtitleProviderSsaAss : public SubtitleProvider int bold, italic, underline, strikeout; float scaleX, scaleY, spacing, angle; int borderStyle; - float outline; - int shadow, alignment; + float outline, shadow; + int alignment; float marginL, marginR, marginV; int encoding; // try with hex colors auto count = sscanf_s((char*)m_pAvCodecCtx->subtitle_header + stylesV4plus, - "%[^,],%[^,],%f,&H%x,&H%x,&H%x,&H%x,%i,%i,%i,%i,%f,%f,%f,%f,%i,%f,%i,%i,%f,%f,%f,%i", + "%[^,],%[^,],%f,&H%x,&H%x,&H%x,&H%x,%i,%i,%i,%i,%f,%f,%f,%f,%i,%f,%f,%i,%f,%f,%f,%i", name, MAX_STYLE_NAME_CHARS, font, MAX_STYLE_NAME_CHARS, &size, &color, &secondaryColor, &outlineColor, &backColor, &bold, &italic, &underline, &strikeout, @@ -620,7 +635,7 @@ class SubtitleProviderSsaAss : public SubtitleProvider { // try with decimal colors count = sscanf_s((char*)m_pAvCodecCtx->subtitle_header + stylesV4plus, - "%[^,],%[^,],%f,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%f,%f,%i,%f,%i,%i,%f,%f,%f,%i", + "%[^,],%[^,],%f,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%f,%f,%i,%f,%f,%i,%f,%f,%f,%i", name, MAX_STYLE_NAME_CHARS, font, MAX_STYLE_NAME_CHARS, &size, &color, &secondaryColor, &outlineColor, &backColor, &bold, &italic, &underline, &strikeout, @@ -976,8 +991,17 @@ class SubtitleProviderSsaAss : public SubtitleProvider TimedTextDouble GetFontSize(double fontSize) { TimedTextDouble size; - size.Unit = TimedTextUnit::Percentage; - size.Value = fontSize * 2.7; + + if (hasPlayResY && videoHeight > 0 && height > 0) + { + size.Unit = TimedTextUnit::Pixels; + size.Value = static_cast(videoHeight) / height * fontSize * 0.85; + } + else + { + size.Unit = TimedTextUnit::Percentage; + size.Value = fontSize * 2.7; + } return size; } @@ -1050,6 +1074,7 @@ class SubtitleProviderSsaAss : public SubtitleProvider int textIndex = 0; int width = 0; int height = 0; + bool hasPlayResY = false; double videoAspectRatio = 0.0; int videoWidth = 0; int videoHeight = 0;