Home | History | Annotate | Download | only in util
      1 /*
      2  * Copyright (C) 2015 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 #ifndef MINIKIN_FONT_TEST_UTILS_H
     18 #define MINIKIN_FONT_TEST_UTILS_H
     19 
     20 #include <memory>
     21 
     22 #include "minikin/FontCollection.h"
     23 
     24 #include "PathUtils.h"
     25 
     26 namespace minikin {
     27 
     28 /**
     29  * Returns list of FontFamily from installed fonts.
     30  *
     31  * This function reads an XML file and makes font families.
     32  */
     33 std::vector<std::shared_ptr<FontFamily>> getFontFamilies(const std::string& fontDir,
     34                                                          const std::string& xmlAbsPath);
     35 
     36 /**
     37  * Returns FontCollection from installed fonts.
     38  *
     39  * This function reads an XML file and makes font families and collections of them.
     40  * The XML path and font files are needed to be in the test data directory.
     41  */
     42 inline std::shared_ptr<FontCollection> buildFontCollectionFromXml(const std::string& xmlPath) {
     43     return std::make_shared<FontCollection>(
     44             getFontFamilies(getTestDataDir(), getTestDataDir() + xmlPath));
     45 }
     46 
     47 /**
     48  * Build new FontCollection from single file.
     49  * The font file needs to be in the test data directory.
     50  */
     51 std::shared_ptr<FontCollection> buildFontCollection(const std::string& filePath);
     52 
     53 /**
     54  * Build new FontFamily from single file.
     55  * The font file needs to be in the test data directory.
     56  */
     57 std::shared_ptr<FontFamily> buildFontFamily(const std::string& filePath);
     58 
     59 /**
     60  * Build new FontFamily from single file with locale.
     61  */
     62 std::shared_ptr<FontFamily> buildFontFamily(const std::string& filePath, const std::string& lang,
     63                                             bool isCustomFallback);
     64 
     65 /**
     66  * Build new FontFamily from single file with locale.
     67  */
     68 inline std::shared_ptr<FontFamily> buildFontFamily(const std::string& filePath,
     69                                                    const std::string& lang) {
     70     return buildFontFamily(filePath, lang, false /* isCustomFallback */);
     71 }
     72 
     73 }  // namespace minikin
     74 #endif  // MINIKIN_FONT_TEST_UTILS_H
     75