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 #define LOG_TAG "Minikin" 18 19 #include "minikin/SystemFonts.h" 20 21 namespace minikin { 22 getInstance()23SystemFonts& SystemFonts::getInstance() { 24 static SystemFonts systemFonts; 25 return systemFonts; 26 } 27 findFontCollectionInternal(const std::string & familyName)28std::shared_ptr<FontCollection> SystemFonts::findFontCollectionInternal( 29 const std::string& familyName) { 30 std::lock_guard<std::mutex> lock(mMutex); 31 auto it = mSystemFallbacks.find(familyName); 32 if (it != mSystemFallbacks.end()) { 33 return it->second; 34 } 35 // TODO: Lookup by PostScript name. 36 return mDefaultFallback; 37 } 38 buildFontSetLocked()39void SystemFonts::buildFontSetLocked() { 40 std::unordered_set<FontFamily*> uniqueFamilies; 41 42 for (const auto& collection : mCollections) { 43 for (size_t i = 0; i < collection->getFamilyCount(); ++i) { 44 const auto& family = collection->getFamilyAt(i); 45 uniqueFamilies.insert(family.get()); 46 } 47 } 48 49 std::vector<std::shared_ptr<Font>> result; 50 for (const auto family : uniqueFamilies) { 51 for (size_t i = 0; i < family->getNumFonts(); ++i) { 52 result.push_back(family->getFontRef(i)); 53 } 54 } 55 mFonts = std::move(result); 56 } 57 58 } // namespace minikin 59