Skip to content

Commit c250151

Browse files
committed
Adjust Caption margins and fix unit tests, which have changed the text position. Adding Debug output to unit test for Windows troubleshooting.
1 parent 301279a commit c250151

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

src/effects/Caption.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
using namespace openshot;
2828

2929
/// Blank constructor, useful when using Json to load the effect properties
30-
Caption::Caption() : color("#ffffff"), stroke("#a9a9a9"), background("#ff000000"), background_alpha(0.0), left(0.1), top(0.75), right(0.1),
30+
Caption::Caption() : color("#ffffff"), stroke("#a9a9a9"), background("#ff000000"), background_alpha(0.0), left(0.1), top(0.70), right(0.1),
3131
stroke_width(0.5), font_size(20.0), font_alpha(1.0), is_dirty(true), font_name("sans"), font(NULL), metrics(NULL),
3232
fade_in(0.35), fade_out(0.35), background_corner(10.0), background_padding(20.0), line_spacing(1.0)
3333
{
@@ -38,7 +38,7 @@ Caption::Caption() : color("#ffffff"), stroke("#a9a9a9"), background("#ff000000"
3838
// Default constructor
3939
Caption::Caption(std::string captions) :
4040
color("#ffffff"), caption_text(captions), stroke("#a9a9a9"), background("#ff000000"), background_alpha(0.0),
41-
left(0.1), top(0.75), right(0.1), stroke_width(0.5), font_size(20.0), font_alpha(1.0), is_dirty(true), font_name("sans"),
41+
left(0.1), top(0.70), right(0.1), stroke_width(0.5), font_size(20.0), font_alpha(1.0), is_dirty(true), font_name("sans"),
4242
font(NULL), metrics(NULL), fade_in(0.35), fade_out(0.35), background_corner(10.0), background_padding(20.0), line_spacing(1.0)
4343
{
4444
// Init effect properties

tests/Caption.cpp

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ TEST_CASE( "caption effect", "[libopenshot][caption]" )
5050
CHECK(c1.stroke.GetColorHex(1) == "#a9a9a9");
5151
CHECK(c1.background.GetColorHex(1) == "#000000");
5252
CHECK(c1.background_alpha.GetValue(1) == Approx(0.0f).margin(0.00001));
53-
CHECK(c1.left.GetValue(1) == Approx(0.15f).margin(0.00001));
54-
CHECK(c1.right.GetValue(1) == Approx(0.15f).margin(0.00001));
55-
CHECK(c1.top.GetValue(1) == Approx(0.7).margin(0.00001));
53+
CHECK(c1.left.GetValue(1) == Approx(0.10f).margin(0.00001));
54+
CHECK(c1.right.GetValue(1) == Approx(0.10f).margin(0.00001));
55+
CHECK(c1.top.GetValue(1) == Approx(0.70).margin(0.00001));
5656
CHECK(c1.stroke_width.GetValue(1) == Approx(0.5f).margin(0.00001));
57-
CHECK(c1.font_size.GetValue(1) == Approx(30.0f).margin(0.00001));
57+
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));
5959
CHECK(c1.font_name == "sans");
6060
CHECK(c1.fade_in.GetValue(1) == Approx(0.35f).margin(0.00001));
@@ -75,15 +75,16 @@ TEST_CASE( "caption effect", "[libopenshot][caption]" )
7575

7676
// Get frame
7777
std::shared_ptr<openshot::Frame> f = clip1.GetFrame(10);
78+
f->Save("caption-sintel-10.png", 1.0, "PNG");
7879

7980
#ifdef _WIN32
8081
// Windows pixel location
8182
check_col = 300;
82-
check_row = 524;
83+
check_row = 528;
8384
#else
8485
// Linux/Mac pixel location
85-
check_col = 252;
86-
check_row = 523;
86+
check_col = 213;
87+
check_row = 528;
8788
#endif
8889

8990
// Verify pixel values (black background pixels)
@@ -100,15 +101,16 @@ TEST_CASE( "caption effect", "[libopenshot][caption]" )
100101

101102
// Get timeline frame
102103
f = t.GetFrame(10);
104+
f->Save("caption-sintel-10B.png", 1.0, "PNG");
103105

104106
#ifdef _WIN32
105107
// Windows pixel location
106108
check_col = 300;
107-
check_row = 523;
109+
check_row = 528;
108110
#else
109111
// Linux/Mac pixel location
110-
check_col = 252;
111-
check_row = 523;
112+
check_col = 214;
113+
check_row = 528;
112114
#endif
113115

114116
// Verify pixel values (black background pixels)
@@ -139,15 +141,16 @@ TEST_CASE( "caption effect", "[libopenshot][caption]" )
139141

140142
// Get frame
141143
std::shared_ptr<openshot::Frame> f = clip1.GetFrame(10);
144+
f->Save("caption-piano-10.png", 1.0, "PNG");
142145

143146
#ifdef _WIN32
144147
// Windows pixel location
145148
check_col = 146;
146-
check_row = 355;
149+
check_row = 361;
147150
#else
148151
// Linux/Mac pixel location
149-
check_col = 117;
150-
check_row = 355;
152+
check_col = 92;
153+
check_row = 361;
151154
#endif
152155

153156
// Verify pixel values (black background pixels)
@@ -164,15 +167,16 @@ TEST_CASE( "caption effect", "[libopenshot][caption]" )
164167

165168
// Get timeline frame
166169
f = t.GetFrame(10);
170+
f->Save("caption-piano-10B.png", 1.0, "PNG");
167171

168172
#ifdef _WIN32
169173
// Windows pixel location
170174
check_col = 146;
171-
check_row = 355;
175+
check_row = 360;
172176
#else
173177
// Linux/Mac pixel location
174-
check_col = 117;
175-
check_row = 355;
178+
check_col = 93;
179+
check_row = 360;
176180
#endif
177181

178182
// Verify pixel values (black background pixels)
@@ -203,16 +207,17 @@ TEST_CASE( "caption effect", "[libopenshot][caption]" )
203207
clip1.AddEffect(&c1);
204208

205209
// Get frame
206-
std::shared_ptr<openshot::Frame> f = clip1.GetFrame(10);
210+
std::shared_ptr<openshot::Frame> f = clip1.GetFrame(11);
211+
f->Save("caption-sintel-11.png", 1.0, "PNG");
207212

208213
#ifdef _WIN32
209214
// Windows pixel location
210215
check_col = 325;
211-
check_row = 522;
216+
check_row = 527;
212217
#else
213218
// Linux/Mac pixel location
214-
check_col = 318;
215-
check_row = 521;
219+
check_col = 292;
220+
check_row = 527;
216221
#endif
217222

218223
// Verify pixel values (black background pixels)

0 commit comments

Comments
 (0)