Merge "Implement matchFamilyStyleCharacter API"

This commit is contained in:
TreeHugger Robot
2018-11-01 23:53:12 +00:00
committed by Android (Google) Code Review
3 changed files with 43 additions and 0 deletions

View File

@@ -62,8 +62,10 @@ cc_library_shared {
"libbinder",
"libui",
"libgui",
"libharfbuzz_ng", // Only for including hb.h via minikin
"libsensor",
"libandroid_runtime",
"libminikin",
"libnetd_client",
"libhwui",
"libxml2",

View File

@@ -224,6 +224,7 @@ LIBANDROID {
ASystemFont_getAxisCount; # introduced=29
ASystemFont_getAxisTag; # introduced=29
ASystemFont_getAxisValue; # introduced=29
ASystemFont_matchFamilyStyleCharacter; # introduced=29
ATrace_beginSection; # introduced=23
ATrace_endSection; # introduced=23
ATrace_isEnabled; # introduced=23

View File

@@ -29,6 +29,11 @@
#include <sys/stat.h>
#include <unistd.h>
#include <hwui/MinikinSkia.h>
#include <minikin/FontCollection.h>
#include <minikin/LocaleList.h>
#include <minikin/SystemFonts.h>
struct XmlCharDeleter {
void operator()(xmlChar* b) { xmlFree(b); }
};
@@ -192,6 +197,41 @@ void ASystemFontIterator_close(ASystemFontIterator* ite) {
delete ite;
}
ASystemFont* ASystemFont_matchFamilyStyleCharacter(
const char* _Nonnull familyName,
uint16_t weight,
bool italic,
const char* _Nonnull languageTags,
const uint16_t* _Nonnull text,
uint32_t textLength,
uint32_t* _Nullable runLength) {
std::shared_ptr<minikin::FontCollection> fc =
minikin::SystemFonts::findFontCollection(familyName);
std::vector<minikin::FontCollection::Run> runs =
fc->itemize(minikin::U16StringPiece(text, textLength),
minikin::FontStyle(weight, static_cast<minikin::FontStyle::Slant>(italic)),
minikin::registerLocaleList(languageTags),
minikin::FamilyVariant::DEFAULT);
const minikin::Font* font = runs[0].fakedFont.font;
std::unique_ptr<ASystemFont> result = std::make_unique<ASystemFont>();
const android::MinikinFontSkia* minikinFontSkia =
reinterpret_cast<android::MinikinFontSkia*>(font->typeface().get());
result->mFilePath = minikinFontSkia->getFilePath();
result->mWeight = font->style().weight();
result->mItalic = font->style().slant() == minikin::FontStyle::Slant::ITALIC;
result->mCollectionIndex = minikinFontSkia->GetFontIndex();
const std::vector<minikin::FontVariation>& axes = minikinFontSkia->GetAxes();
result->mAxes.reserve(axes.size());
for (auto axis : axes) {
result->mAxes.push_back(std::make_pair(axis.axisTag, axis.value));
}
if (runLength != nullptr) {
*runLength = runs[0].end;
}
return result.release();
}
xmlNode* findNextFontNode(const XmlDocUniquePtr& xmlDoc, xmlNode* fontNode) {
if (fontNode == nullptr) {
if (!xmlDoc) {