Merge "Implement matchFamilyStyleCharacter API"
This commit is contained in:
committed by
Android (Google) Code Review
commit
9b2ca344b7
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user