@@ -366,6 +366,22 @@ int32_t CalculateMaxY(const impeller::testing::Screenshot* img) {
366
366
}
367
367
return max_y;
368
368
}
369
+
370
+ int32_t CalculateSpaceBetweenUI (const impeller::testing::Screenshot* img) {
371
+ const uint32_t * ptr = reinterpret_cast <const uint32_t *>(img->GetBytes ());
372
+ ptr += img->GetWidth () * static_cast <int32_t >(img->GetHeight () / 2.0 );
373
+ std::vector<size_t > boundaries;
374
+ uint32_t value = *ptr++;
375
+ for (size_t i = 1 ; i < img->GetWidth (); ++i) {
376
+ if (((*ptr & 0x00ffffff ) != 0 ) != ((value & 0x00ffffff ) != 0 )) {
377
+ boundaries.push_back (i);
378
+ }
379
+ value = *ptr++;
380
+ }
381
+
382
+ assert (boundaries.size () == 6 );
383
+ return boundaries[4 ] - boundaries[3 ];
384
+ }
369
385
} // namespace
370
386
371
387
TEST_P (DlGoldenTest, BaselineHE) {
@@ -399,5 +415,42 @@ TEST_P(DlGoldenTest, BaselineHE) {
399
415
int32_t y_diff = std::abs (left_max_y - right_max_y);
400
416
EXPECT_TRUE (y_diff <= 2 ) << " y diff: " << y_diff;
401
417
}
418
+
419
+ TEST_P (DlGoldenTest, MaintainsSpace) {
420
+ SetWindowSize (impeller::ISize (1024 , 200 ));
421
+ impeller::Scalar font_size = 300 ;
422
+ auto callback = [&](const char * text,
423
+ impeller::Scalar scale) -> sk_sp<DisplayList> {
424
+ DisplayListBuilder builder;
425
+ DlPaint paint;
426
+ paint.setColor (DlColor::ARGB (1 , 0 , 0 , 0 ));
427
+ builder.DrawPaint (paint);
428
+ builder.Scale (scale, scale);
429
+ RenderTextInCanvasSkia (&builder, text, " Roboto-Regular.ttf" ,
430
+ DlPoint::MakeXY (10 , 300 ),
431
+ TextRenderOptions{
432
+ .font_size = font_size,
433
+ });
434
+ return builder.Build ();
435
+ };
436
+
437
+ std::optional<int32_t > last_space;
438
+ for (int i = 0 ; i <= 100 ; ++i) {
439
+ Scalar scale = 0.440 + i / 1000.0 ;
440
+ std::unique_ptr<impeller::testing::Screenshot> right =
441
+ MakeScreenshot (callback (" ui" , scale));
442
+ if (!right) {
443
+ GTEST_SKIP () << " making screenshots not supported." ;
444
+ }
445
+
446
+ int32_t space = CalculateSpaceBetweenUI (right.get ());
447
+ if (last_space.has_value ()) {
448
+ int32_t diff = abs (space - *last_space);
449
+ EXPECT_TRUE (diff <= 1 )
450
+ << " i:" << i << " space:" << space << " last_space:" << *last_space;
451
+ }
452
+ last_space = space;
453
+ }
454
+ }
402
455
} // namespace testing
403
456
} // namespace flutter
0 commit comments