Skip to content

Commit 9daf04f

Browse files
committed
Take 2: Adjust caption scaling logic, to keep different resolution projects from having dramatically different font sizes. More debug code for Windows.
1 parent 7095e4f commit 9daf04f

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

src/effects/Caption.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ std::shared_ptr<openshot::Frame> Caption::GetFrame(std::shared_ptr<openshot::Fra
110110
// Process regex (if needed)
111111
process_regex();
112112

113-
// Get largest pixel ratio (of screen)
114-
double device_pixel_ratio = qGuiApp->devicePixelRatio();
115-
116113
// Get the Clip and Timeline pointers (if available)
117114
Clip* clip = (Clip*) ParentClip();
118115
Timeline* timeline = NULL;
@@ -146,10 +143,11 @@ std::shared_ptr<openshot::Frame> Caption::GetFrame(std::shared_ptr<openshot::Fra
146143
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
147144

148145
// Font options and metrics for caption text
149-
double font_size_value = font_size.GetValue(frame_number) * device_pixel_ratio * timeline_scale_factor;
146+
double font_size_value = font_size.GetValue(frame_number) * timeline_scale_factor * qGuiApp->devicePixelRatio();
150147
QFont font(QString(font_name.c_str()), int(font_size_value));
151148
font.setPointSizeF(std::max(font_size_value, 1.0));
152149
QFontMetricsF metrics = QFontMetricsF(font);
150+
std::cout << "font_size_value: " << font_size_value << std::endl;
153151

154152
// Get current keyframe values
155153
double left_value = left.GetValue(frame_number);

tests/Caption.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ TEST_CASE( "caption effect", "[libopenshot][caption]" )
5252
CHECK(c1.background_alpha.GetValue(1) == Approx(0.0f).margin(0.00001));
5353
CHECK(c1.left.GetValue(1) == Approx(0.10f).margin(0.00001));
5454
CHECK(c1.right.GetValue(1) == Approx(0.10f).margin(0.00001));
55-
CHECK(c1.top.GetValue(1) == Approx(0.70).margin(0.00001));
55+
CHECK(c1.top.GetValue(1) == Approx(0.72).margin(0.00001));
5656
CHECK(c1.stroke_width.GetValue(1) == Approx(0.5f).margin(0.00001));
5757
CHECK(c1.font_size.GetValue(1) == Approx(20.0f).margin(0.00001));
5858
CHECK(c1.font_alpha.GetValue(1) == Approx(1.0f).margin(0.00001));
@@ -80,11 +80,11 @@ TEST_CASE( "caption effect", "[libopenshot][caption]" )
8080
#ifdef _WIN32
8181
// Windows pixel location
8282
check_col = 300;
83-
check_row = 528;
83+
check_row = 544;
8484
#else
8585
// Linux/Mac pixel location
86-
check_col = 213;
87-
check_row = 528;
86+
check_col = 214;
87+
check_row = 544;
8888
#endif
8989

9090
// Verify pixel values (black background pixels)
@@ -106,11 +106,11 @@ TEST_CASE( "caption effect", "[libopenshot][caption]" )
106106
#ifdef _WIN32
107107
// Windows pixel location
108108
check_col = 300;
109-
check_row = 528;
109+
check_row = 544;
110110
#else
111111
// Linux/Mac pixel location
112112
check_col = 214;
113-
check_row = 528;
113+
check_row = 544;
114114
#endif
115115

116116
// Verify pixel values (black background pixels)
@@ -146,11 +146,11 @@ TEST_CASE( "caption effect", "[libopenshot][caption]" )
146146
#ifdef _WIN32
147147
// Windows pixel location
148148
check_col = 146;
149-
check_row = 361;
149+
check_row = 360;
150150
#else
151151
// Linux/Mac pixel location
152-
check_col = 92;
153-
check_row = 361;
152+
check_col = 118;
153+
check_row = 360;
154154
#endif
155155

156156
// Verify pixel values (black background pixels)
@@ -175,7 +175,7 @@ TEST_CASE( "caption effect", "[libopenshot][caption]" )
175175
check_row = 360;
176176
#else
177177
// Linux/Mac pixel location
178-
check_col = 93;
178+
check_col = 119;
179179
check_row = 360;
180180
#endif
181181

@@ -213,11 +213,11 @@ TEST_CASE( "caption effect", "[libopenshot][caption]" )
213213
#ifdef _WIN32
214214
// Windows pixel location
215215
check_col = 325;
216-
check_row = 527;
216+
check_row = 542;
217217
#else
218218
// Linux/Mac pixel location
219-
check_col = 292;
220-
check_row = 527;
219+
check_col = 291;
220+
check_row = 542;
221221
#endif
222222

223223
// Verify pixel values (black background pixels)

0 commit comments

Comments
 (0)