2019-06-19 17:32:01 +00:00
|
|
|
// Copyright 2019 Google LLC.
|
2019-07-25 14:00:52 +00:00
|
|
|
#include "modules/skparagraph/src/ParagraphImpl.h"
|
2019-06-19 17:32:01 +00:00
|
|
|
#include "modules/skparagraph/utils/TestFontCollection.h"
|
|
|
|
#include "src/core/SkOSFile.h"
|
|
|
|
#include "src/utils/SkUTF.h"
|
|
|
|
#include "tools/Resources.h"
|
|
|
|
|
|
|
|
namespace skia {
|
|
|
|
namespace textlayout {
|
2019-06-21 16:22:32 +00:00
|
|
|
|
2019-06-19 17:32:01 +00:00
|
|
|
TestFontCollection::TestFontCollection(const std::string& resourceDir)
|
|
|
|
: fResourceDir(resourceDir)
|
|
|
|
, fFontsFound(0) {
|
2019-06-21 16:22:32 +00:00
|
|
|
if (fDirs == resourceDir) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fFontProvider = sk_make_sp<TypefaceFontProvider>();
|
2019-06-19 17:32:01 +00:00
|
|
|
|
|
|
|
SkOSFile::Iter iter(fResourceDir.c_str());
|
|
|
|
SkString path;
|
|
|
|
while (iter.next(&path)) {
|
|
|
|
SkString file_path;
|
|
|
|
file_path.printf("%s/%s", fResourceDir.c_str(), path.c_str());
|
2019-06-21 16:22:32 +00:00
|
|
|
// fonts from data are faster (skips file overhead), so we use them here for testing
|
|
|
|
auto data = SkData::MakeFromFileName(file_path.c_str());
|
|
|
|
if (data) {
|
|
|
|
fFontProvider->registerTypeface(SkTypeface::MakeFromData(data));
|
|
|
|
}
|
2019-06-19 17:32:01 +00:00
|
|
|
}
|
2019-06-21 16:22:32 +00:00
|
|
|
|
|
|
|
fFontsFound = fFontProvider->countFamilies();
|
|
|
|
this->setTestFontManager(fFontProvider);
|
2019-06-19 17:32:01 +00:00
|
|
|
this->disableFontFallback();
|
2019-06-21 16:22:32 +00:00
|
|
|
fDirs = resourceDir;
|
2019-06-19 17:32:01 +00:00
|
|
|
}
|
|
|
|
} // namespace textlayout
|
2019-06-21 16:22:32 +00:00
|
|
|
} // namespace skia
|