1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "minikin/SystemFonts.h" 18 19 namespace minikin { 20 getInstance()21SystemFonts& SystemFonts::getInstance() { 22 static SystemFonts systemFonts; 23 return systemFonts; 24 } 25 findFontCollectionInternal(const std::string & familyName)26std::shared_ptr<FontCollection> SystemFonts::findFontCollectionInternal( 27 const std::string& familyName) { 28 std::lock_guard<std::mutex> lock(mMutex); 29 auto it = mSystemFallbacks.find(familyName); 30 if (it != mSystemFallbacks.end()) { 31 return it->second; 32 } 33 // TODO: Lookup by PostScript name. 34 return mDefaultFallback; 35 } 36 buildFontSetLocked()37void SystemFonts::buildFontSetLocked() { 38 std::unordered_set<FontFamily*> uniqueFamilies; 39 40 for (const auto& collection : mCollections) { 41 for (size_t i = 0; i < collection->getFamilyCount(); ++i) { 42 const auto& family = collection->getFamilyAt(i); 43 uniqueFamilies.insert(family.get()); 44 } 45 } 46 47 std::vector<std::shared_ptr<Font>> result; 48 for (const auto family : uniqueFamilies) { 49 for (size_t i = 0; i < family->getNumFonts(); ++i) { 50 result.push_back(family->getFontRef(i)); 51 } 52 } 53 mFonts = std::move(result); 54 } 55 56 } // namespace minikin 57