@@ -29,7 +29,7 @@ class FontCollectionTest : public ::testing::Test {};
2929namespace {
3030// This function does some boilerplate to fill a builder with enough real
3131// font-like data. Otherwise, detach won't actually build an SkTypeface.
32- void PopulateUserTypeface (SkCustomTypefaceBuilder* builder) {
32+ void PopulateUserTypefaceBoilerplate (SkCustomTypefaceBuilder* builder) {
3333 constexpr float upem = 200 ;
3434
3535 {
@@ -75,25 +75,32 @@ TEST(FontCollectionTest, CheckSkTypefacesSorting) {
7575 SkFontStyle::kItalic_Slant ));
7676 // For the purpose of this test, we need to fill this to make the SkTypeface
7777 // build but it doesn't matter. We only care about the SkFontStyle.
78- PopulateUserTypeface (&typefaceBuilder1);
78+ PopulateUserTypefaceBoilerplate (&typefaceBuilder1);
7979 sk_sp<SkTypeface> typeface1{typefaceBuilder1.detach ()};
8080
8181 SkCustomTypefaceBuilder typefaceBuilder2;
8282 typefaceBuilder2.setFontStyle (SkFontStyle (SkFontStyle::kLight_Weight ,
8383 SkFontStyle::kNormal_Width ,
8484 SkFontStyle::kUpright_Slant ));
85- PopulateUserTypeface (&typefaceBuilder2);
85+ PopulateUserTypefaceBoilerplate (&typefaceBuilder2);
8686 sk_sp<SkTypeface> typeface2{typefaceBuilder2.detach ()};
8787
8888 SkCustomTypefaceBuilder typefaceBuilder3;
8989 typefaceBuilder3.setFontStyle (SkFontStyle (SkFontStyle::kNormal_Weight ,
9090 SkFontStyle::kNormal_Width ,
9191 SkFontStyle::kUpright_Slant ));
92- PopulateUserTypeface (&typefaceBuilder3);
92+ PopulateUserTypefaceBoilerplate (&typefaceBuilder3);
9393 sk_sp<SkTypeface> typeface3{typefaceBuilder3.detach ()};
9494
95+ SkCustomTypefaceBuilder typefaceBuilder4;
96+ typefaceBuilder4.setFontStyle (SkFontStyle (SkFontStyle::kThin_Weight ,
97+ SkFontStyle::kCondensed_Width ,
98+ SkFontStyle::kUpright_Slant ));
99+ PopulateUserTypefaceBoilerplate (&typefaceBuilder4);
100+ sk_sp<SkTypeface> typeface4{typefaceBuilder4.detach ()};
101+
95102 std::vector<sk_sp<SkTypeface>> candidateTypefaces = {typeface1, typeface2,
96- typeface3};
103+ typeface3, typeface4 };
97104
98105 // This sorts the vector in-place.
99106 txt::FontCollection::SortSkTypefaces (candidateTypefaces);
@@ -103,8 +110,11 @@ TEST(FontCollectionTest, CheckSkTypefacesSorting) {
103110 ASSERT_EQ (candidateTypefaces[0 ].get (), typeface2.get ());
104111 // Then the most normal width font with normal weight.
105112 ASSERT_EQ (candidateTypefaces[1 ].get (), typeface3.get ());
106- // Then a less normal (expanded) width font.
107- ASSERT_EQ (candidateTypefaces[2 ].get (), typeface1.get ());
113+ // Then a less normal (condensed) width font.
114+ ASSERT_EQ (candidateTypefaces[2 ].get (), typeface4.get ());
115+ // All things equal, 4 came before 1 because we arbitrarily chose to make the
116+ // narrower font come first.
117+ ASSERT_EQ (candidateTypefaces[3 ].get (), typeface1.get ());
108118
109119 // Double check.
110120 ASSERT_EQ (candidateTypefaces[0 ]->fontStyle ().weight (),
@@ -120,6 +130,11 @@ TEST(FontCollectionTest, CheckSkTypefacesSorting) {
120130 ASSERT_EQ (candidateTypefaces[2 ]->fontStyle ().weight (),
121131 SkFontStyle::kThin_Weight );
122132 ASSERT_EQ (candidateTypefaces[2 ]->fontStyle ().width (),
133+ SkFontStyle::kCondensed_Width );
134+
135+ ASSERT_EQ (candidateTypefaces[3 ]->fontStyle ().weight (),
136+ SkFontStyle::kThin_Weight );
137+ ASSERT_EQ (candidateTypefaces[3 ]->fontStyle ().width (),
123138 SkFontStyle::kExpanded_Width );
124139}
125140
0 commit comments