@@ -299,9 +299,11 @@ static sk_sp<SkData> OpenFixtureAsSkData(const char* fixture_name) {
299299 mapping.release ());
300300}
301301
302- TEST_F (AiksTest, CanRenderTextFrame) {
303- Canvas canvas;
304-
302+ bool RenderTextInCanvas (std::shared_ptr<Context> context,
303+ Canvas& canvas,
304+ const std::string& text,
305+ const std::string& font_fixture,
306+ Scalar font_size = 50.0 ) {
305307 Scalar baseline = 200.0 ;
306308 Point text_position = {100 , baseline};
307309
@@ -314,84 +316,56 @@ TEST_F(AiksTest, CanRenderTextFrame) {
314316 Paint{.color = Color::Red ().WithAlpha (0.25 )});
315317
316318 // Construct the text blob.
317- auto mapping = OpenFixtureAsSkData (" Roboto-Regular.ttf" );
318- ASSERT_TRUE (mapping);
319+ auto mapping = OpenFixtureAsSkData (font_fixture.c_str ());
320+ if (!mapping) {
321+ return false ;
322+ }
319323 SkFont sk_font (SkTypeface::MakeFromData (mapping), 50.0 );
320- auto blob = SkTextBlob::MakeFromString (
321- " the quick brown fox jumped over the lazy dog!.?" , sk_font);
322- ASSERT_TRUE (blob);
324+ auto blob = SkTextBlob::MakeFromString (text.c_str (), sk_font);
325+ if (!blob) {
326+ return false ;
327+ }
323328
324329 // Create the Impeller text frame and draw it at the designated baseline.
325330 auto frame = TextFrameFromTextBlob (blob);
326- TextRenderContextSkia text_context (GetContext ());
327- ASSERT_TRUE (text_context.IsValid ());
331+ TextRenderContextSkia text_context (context);
332+ if (!text_context.IsValid ()) {
333+ return false ;
334+ }
328335 auto atlas = text_context.CreateGlyphAtlas (frame);
329- ASSERT_NE (atlas, nullptr );
330- canvas.DrawTextFrame (std::move (frame), std::move (atlas), text_position);
336+ if (!atlas) {
337+ return false ;
338+ }
339+
340+ Paint text_paint;
341+ text_paint.color = Color::Yellow ();
342+ canvas.DrawTextFrame (std::move (frame), std::move (atlas), text_position,
343+ text_paint);
344+ return true ;
345+ }
346+
347+ TEST_F (AiksTest, CanRenderTextFrame) {
348+ Canvas canvas;
349+ ASSERT_TRUE (RenderTextInCanvas (
350+ GetContext (), canvas, " the quick brown fox jumped over the lazy dog!.?" ,
351+ " Roboto-Regular.ttf" ));
331352 ASSERT_TRUE (OpenPlaygroundHere (canvas.EndRecordingAsPicture ()));
332353}
333354
334355TEST_F (AiksTest, CanRenderItalicizedText) {
335356 Canvas canvas;
336-
337- Scalar baseline = 200.0 ;
338- Point text_position = {100 , baseline};
339-
340- // Draw the baseline.
341- canvas.DrawRect ({50 , baseline, 900 , 10 },
342- Paint{.color = Color::Aqua ().WithAlpha (0.25 )});
343-
344- // Mark the point at which the text is drawn.
345- canvas.DrawCircle (text_position, 5.0 ,
346- Paint{.color = Color::Red ().WithAlpha (0.25 )});
347-
348- // Construct the text blob.
349- auto mapping = OpenFixtureAsSkData (" HomemadeApple.ttf" );
350- ASSERT_TRUE (mapping);
351- SkFont sk_font (SkTypeface::MakeFromData (mapping), 50.0 );
352- auto blob = SkTextBlob::MakeFromString (
353- " the quick brown fox jumped over the lazy dog!.?" , sk_font);
354- ASSERT_TRUE (blob);
355-
356- // Create the Impeller text frame and draw it at the designated baseline.
357- auto frame = TextFrameFromTextBlob (blob);
358- TextRenderContextSkia text_context (GetContext ());
359- ASSERT_TRUE (text_context.IsValid ());
360- auto atlas = text_context.CreateGlyphAtlas (frame);
361- ASSERT_NE (atlas, nullptr );
362- canvas.DrawTextFrame (std::move (frame), std::move (atlas), text_position);
357+ ASSERT_TRUE (RenderTextInCanvas (
358+ GetContext (), canvas, " the quick brown fox jumped over the lazy dog!.?" ,
359+ " HomemadeApple.ttf" ));
363360 ASSERT_TRUE (OpenPlaygroundHere (canvas.EndRecordingAsPicture ()));
364361}
365362
366363TEST_F (AiksTest, CanRenderEmojiTextFrame) {
367364 Canvas canvas;
368-
369- Scalar baseline = 200.0 ;
370- Point text_position = {100 , baseline};
371-
372- // Draw the baseline.
373- canvas.DrawRect ({50 , baseline, 900 , 10 },
374- Paint{.color = Color::Aqua ().WithAlpha (0.25 )});
375-
376- // Mark the point at which the text is drawn.
377- canvas.DrawCircle (text_position, 5.0 ,
378- Paint{.color = Color::Red ().WithAlpha (0.25 )});
379-
380- // Construct the text blob.
381- auto mapping = OpenFixtureAsSkData (" NotoColorEmoji.ttf" );
382- ASSERT_TRUE (mapping);
383- SkFont sk_font (SkTypeface::MakeFromData (mapping), 50.0 );
384- auto blob = SkTextBlob::MakeFromString (
385- " 😀 😃 😄 😁 😆 😅 😂 🤣 🥲 ☺️ 😊" , sk_font);
386- ASSERT_TRUE (blob);
387-
388- // Create the Impeller text frame and draw it at the designated baseline.
389- auto frame = TextFrameFromTextBlob (blob);
390- TextRenderContextSkia text_context (GetContext ());
391- ASSERT_TRUE (text_context.IsValid ());
392- auto atlas = text_context.CreateGlyphAtlas (frame);
393- ASSERT_NE (atlas, nullptr );
394- canvas.DrawTextFrame (std::move (frame), std::move (atlas), text_position);
365+ ASSERT_TRUE (RenderTextInCanvas (
366+ GetContext (), canvas,
367+ " 😀 😃 😄 😁 😆 😅 😂 🤣 🥲 ☺️ 😊" ,
368+ " NotoColorEmoji.ttf" ));
395369 ASSERT_TRUE (OpenPlaygroundHere (canvas.EndRecordingAsPicture ()));
396370}
397371
0 commit comments