Take 2: Adjust caption scaling logic, to keep different resolution projects from having dramatically different font sizes. More debug code for Windows.

This commit is contained in:
Jonathan Thomas
2023-03-26 23:22:12 -05:00
parent 7095e4f8aa
commit 9daf04f14e
2 changed files with 15 additions and 17 deletions

View File

@@ -110,9 +110,6 @@ std::shared_ptr<openshot::Frame> Caption::GetFrame(std::shared_ptr<openshot::Fra
// Process regex (if needed)
process_regex();
// Get largest pixel ratio (of screen)
double device_pixel_ratio = qGuiApp->devicePixelRatio();
// Get the Clip and Timeline pointers (if available)
Clip* clip = (Clip*) ParentClip();
Timeline* timeline = NULL;
@@ -146,10 +143,11 @@ std::shared_ptr<openshot::Frame> Caption::GetFrame(std::shared_ptr<openshot::Fra
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
// Font options and metrics for caption text
double font_size_value = font_size.GetValue(frame_number) * device_pixel_ratio * timeline_scale_factor;
double font_size_value = font_size.GetValue(frame_number) * timeline_scale_factor * qGuiApp->devicePixelRatio();
QFont font(QString(font_name.c_str()), int(font_size_value));
font.setPointSizeF(std::max(font_size_value, 1.0));
QFontMetricsF metrics = QFontMetricsF(font);
std::cout << "font_size_value: " << font_size_value << std::endl;
// Get current keyframe values
double left_value = left.GetValue(frame_number);

View File

@@ -52,7 +52,7 @@ TEST_CASE( "caption effect", "[libopenshot][caption]" )
CHECK(c1.background_alpha.GetValue(1) == Approx(0.0f).margin(0.00001));
CHECK(c1.left.GetValue(1) == Approx(0.10f).margin(0.00001));
CHECK(c1.right.GetValue(1) == Approx(0.10f).margin(0.00001));
CHECK(c1.top.GetValue(1) == Approx(0.70).margin(0.00001));
CHECK(c1.top.GetValue(1) == Approx(0.72).margin(0.00001));
CHECK(c1.stroke_width.GetValue(1) == Approx(0.5f).margin(0.00001));
CHECK(c1.font_size.GetValue(1) == Approx(20.0f).margin(0.00001));
CHECK(c1.font_alpha.GetValue(1) == Approx(1.0f).margin(0.00001));
@@ -80,11 +80,11 @@ TEST_CASE( "caption effect", "[libopenshot][caption]" )
#ifdef _WIN32
// Windows pixel location
check_col = 300;
check_row = 528;
check_row = 544;
#else
// Linux/Mac pixel location
check_col = 213;
check_row = 528;
check_col = 214;
check_row = 544;
#endif
// Verify pixel values (black background pixels)
@@ -106,11 +106,11 @@ TEST_CASE( "caption effect", "[libopenshot][caption]" )
#ifdef _WIN32
// Windows pixel location
check_col = 300;
check_row = 528;
check_row = 544;
#else
// Linux/Mac pixel location
check_col = 214;
check_row = 528;
check_row = 544;
#endif
// Verify pixel values (black background pixels)
@@ -146,11 +146,11 @@ TEST_CASE( "caption effect", "[libopenshot][caption]" )
#ifdef _WIN32
// Windows pixel location
check_col = 146;
check_row = 361;
check_row = 360;
#else
// Linux/Mac pixel location
check_col = 92;
check_row = 361;
check_col = 118;
check_row = 360;
#endif
// Verify pixel values (black background pixels)
@@ -175,7 +175,7 @@ TEST_CASE( "caption effect", "[libopenshot][caption]" )
check_row = 360;
#else
// Linux/Mac pixel location
check_col = 93;
check_col = 119;
check_row = 360;
#endif
@@ -213,11 +213,11 @@ TEST_CASE( "caption effect", "[libopenshot][caption]" )
#ifdef _WIN32
// Windows pixel location
check_col = 325;
check_row = 527;
check_row = 542;
#else
// Linux/Mac pixel location
check_col = 292;
check_row = 527;
check_col = 291;
check_row = 542;
#endif
// Verify pixel values (black background pixels)