xref: /aosp_15_r20/frameworks/minikin/tests/util/FontTestUtils.h (revision 834a2baab5fdfc28e9a428ee87c7ea8f6a06a53d)
1*834a2baaSAndroid Build Coastguard Worker /*
2*834a2baaSAndroid Build Coastguard Worker  * Copyright (C) 2015 The Android Open Source Project
3*834a2baaSAndroid Build Coastguard Worker  *
4*834a2baaSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*834a2baaSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*834a2baaSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*834a2baaSAndroid Build Coastguard Worker  *
8*834a2baaSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*834a2baaSAndroid Build Coastguard Worker  *
10*834a2baaSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*834a2baaSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*834a2baaSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*834a2baaSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*834a2baaSAndroid Build Coastguard Worker  * limitations under the License.
15*834a2baaSAndroid Build Coastguard Worker  */
16*834a2baaSAndroid Build Coastguard Worker 
17*834a2baaSAndroid Build Coastguard Worker #ifndef MINIKIN_FONT_TEST_UTILS_H
18*834a2baaSAndroid Build Coastguard Worker #define MINIKIN_FONT_TEST_UTILS_H
19*834a2baaSAndroid Build Coastguard Worker 
20*834a2baaSAndroid Build Coastguard Worker #include <memory>
21*834a2baaSAndroid Build Coastguard Worker 
22*834a2baaSAndroid Build Coastguard Worker #include "PathUtils.h"
23*834a2baaSAndroid Build Coastguard Worker #include "minikin/FontCollection.h"
24*834a2baaSAndroid Build Coastguard Worker 
25*834a2baaSAndroid Build Coastguard Worker namespace minikin {
26*834a2baaSAndroid Build Coastguard Worker 
27*834a2baaSAndroid Build Coastguard Worker /**
28*834a2baaSAndroid Build Coastguard Worker  * Returns list of FontFamily from installed fonts.
29*834a2baaSAndroid Build Coastguard Worker  *
30*834a2baaSAndroid Build Coastguard Worker  * This function reads an XML file and makes font families.
31*834a2baaSAndroid Build Coastguard Worker  */
32*834a2baaSAndroid Build Coastguard Worker std::vector<std::shared_ptr<FontFamily>> getFontFamilies(const std::string& fontDir,
33*834a2baaSAndroid Build Coastguard Worker                                                          const std::string& xmlAbsPath);
34*834a2baaSAndroid Build Coastguard Worker 
35*834a2baaSAndroid Build Coastguard Worker /**
36*834a2baaSAndroid Build Coastguard Worker  * Returns FontCollection from installed fonts.
37*834a2baaSAndroid Build Coastguard Worker  *
38*834a2baaSAndroid Build Coastguard Worker  * This function reads an XML file and makes font families and collections of them.
39*834a2baaSAndroid Build Coastguard Worker  * The XML path and font files are needed to be in the test data directory.
40*834a2baaSAndroid Build Coastguard Worker  */
buildFontCollectionFromXml(const std::string & xmlPath)41*834a2baaSAndroid Build Coastguard Worker inline std::shared_ptr<FontCollection> buildFontCollectionFromXml(const std::string& xmlPath) {
42*834a2baaSAndroid Build Coastguard Worker     return FontCollection::create(getFontFamilies(getTestDataDir(), getTestDataDir() + xmlPath));
43*834a2baaSAndroid Build Coastguard Worker }
44*834a2baaSAndroid Build Coastguard Worker 
45*834a2baaSAndroid Build Coastguard Worker /**
46*834a2baaSAndroid Build Coastguard Worker  * Build new FontCollection from single file.
47*834a2baaSAndroid Build Coastguard Worker  * The font file needs to be in the test data directory.
48*834a2baaSAndroid Build Coastguard Worker  */
49*834a2baaSAndroid Build Coastguard Worker std::shared_ptr<FontCollection> buildFontCollection(const std::string& filePath);
50*834a2baaSAndroid Build Coastguard Worker 
51*834a2baaSAndroid Build Coastguard Worker /**
52*834a2baaSAndroid Build Coastguard Worker  * Build new FontFamily from single file.
53*834a2baaSAndroid Build Coastguard Worker  * The font file needs to be in the test data directory.
54*834a2baaSAndroid Build Coastguard Worker  */
55*834a2baaSAndroid Build Coastguard Worker std::shared_ptr<FontFamily> buildFontFamily(const std::string& filePath);
56*834a2baaSAndroid Build Coastguard Worker 
57*834a2baaSAndroid Build Coastguard Worker /**
58*834a2baaSAndroid Build Coastguard Worker  * Build new FontFamily from single file with locale.
59*834a2baaSAndroid Build Coastguard Worker  */
60*834a2baaSAndroid Build Coastguard Worker std::shared_ptr<FontFamily> buildFontFamily(const std::string& filePath, const std::string& lang,
61*834a2baaSAndroid Build Coastguard Worker                                             bool isCustomFallback);
62*834a2baaSAndroid Build Coastguard Worker 
63*834a2baaSAndroid Build Coastguard Worker /**
64*834a2baaSAndroid Build Coastguard Worker  * Build new FontFamily from single file with locale.
65*834a2baaSAndroid Build Coastguard Worker  */
buildFontFamily(const std::string & filePath,const std::string & lang)66*834a2baaSAndroid Build Coastguard Worker inline std::shared_ptr<FontFamily> buildFontFamily(const std::string& filePath,
67*834a2baaSAndroid Build Coastguard Worker                                                    const std::string& lang) {
68*834a2baaSAndroid Build Coastguard Worker     return buildFontFamily(filePath, lang, false /* isCustomFallback */);
69*834a2baaSAndroid Build Coastguard Worker }
70*834a2baaSAndroid Build Coastguard Worker 
71*834a2baaSAndroid Build Coastguard Worker }  // namespace minikin
72*834a2baaSAndroid Build Coastguard Worker #endif  // MINIKIN_FONT_TEST_UTILS_H
73