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