• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 Google LLC.
2 #include "modules/skparagraph/src/ParagraphImpl.h"
3 #include "modules/skparagraph/utils/TestFontCollection.h"
4 #include "src/core/SkOSFile.h"
5 #include "src/utils/SkUTF.h"
6 #include "tools/Resources.h"
7 
8 namespace skia {
9 namespace textlayout {
10 
TestFontCollection(const std::string & resourceDir)11 TestFontCollection::TestFontCollection(const std::string& resourceDir)
12   : fResourceDir(resourceDir)
13   , fFontsFound(0) {
14     if (fDirs == resourceDir) {
15       return;
16     }
17 
18     fFontProvider = sk_make_sp<TypefaceFontProvider>();
19 
20     SkOSFile::Iter iter(fResourceDir.c_str());
21     SkString path;
22     while (iter.next(&path)) {
23         SkString file_path;
24         file_path.printf("%s/%s", fResourceDir.c_str(), path.c_str());
25         // fonts from data are faster (skips file overhead), so we use them here for testing
26         auto data = SkData::MakeFromFileName(file_path.c_str());
27         if (data) {
28             fFontProvider->registerTypeface(SkTypeface::MakeFromData(data));
29         }
30     }
31 
32     fFontsFound = fFontProvider->countFamilies();
33     this->setTestFontManager(fFontProvider);
34     this->disableFontFallback();
35     fDirs = resourceDir;
36 }
37 }  // namespace textlayout
38 }  // namespace skia
39