@@ -51,21 +51,20 @@ std::string GetFontLocale(uint32_t langListId) {
5151 return langs.size () ? langs[0 ].getString () : " " ;
5252}
5353
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;
5962}
6063
61- FontCollection::FontCollection (
62- const vector<std::shared_ptr<FontFamily>>& typefaces)
63- : mMaxChar (0 ) {
64- init (typefaces);
65- }
64+ FontCollection::FontCollection () : mMaxChar (0 ) {}
6665
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) {
6968 std::scoped_lock _l (gMinikinLock );
7069 mId = sNextId ++;
7170 vector<uint32_t > lastChar;
@@ -91,10 +90,14 @@ void FontCollection::init(
9190 mSupportedAxes .insert (supportedAxes.begin (), supportedAxes.end ());
9291 }
9392 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+ }
98101 size_t nPages = (mMaxChar + kPageMask ) >> kLogCharsPerPage ;
99102 // TODO: Use variation selector map for mRanges construction.
100103 // A font can have a glyph for a base code point and variation selector pair
@@ -122,9 +125,12 @@ void FontCollection::init(
122125 }
123126 range->end = mFamilyVec .size ();
124127 }
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 ;
128134}
129135
130136// Special scores for the font fallback.
@@ -566,7 +572,7 @@ std::shared_ptr<FontCollection> FontCollection::createCollectionWithVariation(
566572 }
567573 }
568574
569- return std::shared_ptr<FontCollection>( new FontCollection (families));
575+ return FontCollection::Create ( std::move (families));
570576}
571577
572578uint32_t FontCollection::getId () const {
0 commit comments