@@ -51,21 +51,20 @@ std::string GetFontLocale(uint32_t langListId) {
51
51
return langs.size () ? langs[0 ].getString () : " " ;
52
52
}
53
53
54
- FontCollection::FontCollection (std::shared_ptr<FontFamily>&& typeface)
55
- : mMaxChar (0 ) {
56
- std::vector<std::shared_ptr<FontFamily>> typefaces;
57
- typefaces.push_back (typeface);
58
- init (typefaces);
54
+ std::shared_ptr<minikin::FontCollection> FontCollection::Create (
55
+ const std::vector<std::shared_ptr<FontFamily>>& typefaces) {
56
+ std::shared_ptr<minikin::FontCollection> font_collection (
57
+ new minikin::FontCollection ());
58
+ if (!font_collection || !font_collection->init (typefaces)) {
59
+ return nullptr ;
60
+ }
61
+ return font_collection;
59
62
}
60
63
61
- FontCollection::FontCollection (
62
- const vector<std::shared_ptr<FontFamily>>& typefaces)
63
- : mMaxChar (0 ) {
64
- init (typefaces);
65
- }
64
+ FontCollection::FontCollection () : mMaxChar (0 ) {}
66
65
67
- void FontCollection::init (
68
- const vector<std::shared_ptr<FontFamily>>& typefaces) {
66
+ bool FontCollection::init (
67
+ const std:: vector<std::shared_ptr<FontFamily>>& typefaces) {
69
68
std::scoped_lock _l (gMinikinLock );
70
69
mId = sNextId ++;
71
70
vector<uint32_t > lastChar;
@@ -91,10 +90,14 @@ void FontCollection::init(
91
90
mSupportedAxes .insert (supportedAxes.begin (), supportedAxes.end ());
92
91
}
93
92
nTypefaces = mFamilies .size ();
94
- LOG_ALWAYS_FATAL_IF (nTypefaces == 0 ,
95
- " Font collection must have at least one valid typeface" );
96
- LOG_ALWAYS_FATAL_IF (nTypefaces > 254 ,
97
- " Font collection may only have up to 254 font families." );
93
+ if (nTypefaces == 0 ) {
94
+ ALOGE (" Font collection must have at least one valid typeface." );
95
+ return false ;
96
+ }
97
+ if (nTypefaces > 254 ) {
98
+ ALOGE (" Font collection may only have up to 254 font families." );
99
+ return false ;
100
+ }
98
101
size_t nPages = (mMaxChar + kPageMask ) >> kLogCharsPerPage ;
99
102
// TODO: Use variation selector map for mRanges construction.
100
103
// A font can have a glyph for a base code point and variation selector pair
@@ -122,9 +125,12 @@ void FontCollection::init(
122
125
}
123
126
range->end = mFamilyVec .size ();
124
127
}
125
- // See the comment in Range for more details.
126
- LOG_ALWAYS_FATAL_IF (mFamilyVec .size () >= 0xFFFF ,
127
- " Exceeded the maximum indexable cmap coverage." );
128
+
129
+ if (mFamilyVec .size () >= 0xFFFF ) {
130
+ ALOGE (" Exceeded the maximum indexable cmap coverage." );
131
+ return false ;
132
+ }
133
+ return true ;
128
134
}
129
135
130
136
// Special scores for the font fallback.
@@ -566,7 +572,7 @@ std::shared_ptr<FontCollection> FontCollection::createCollectionWithVariation(
566
572
}
567
573
}
568
574
569
- return std::shared_ptr<FontCollection>( new FontCollection (families));
575
+ return FontCollection::Create ( std::move (families));
570
576
}
571
577
572
578
uint32_t FontCollection::getId () const {
0 commit comments