Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions third_party/txt/src/minikin/FontCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,9 @@ void FontCollection::itemize(const uint16_t* string,
if (!shouldContinueRun) {
const std::shared_ptr<FontFamily>& family = getFamilyForChar(
ch, isVariationSelector(nextCh) ? nextCh : 0, langListId, variant);
if (utf16Pos == 0 || family.get() != lastFamily) {

Comment thread
bwikbs marked this conversation as resolved.
Outdated
if (utf16Pos == 0 || family.get() != lastFamily ||
family.get()->getLastMatchedCodePoint() != ch) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This algorithm tries to reuse the already selected font as much as possible.
I think that using only one codepoint cached causes too much execution.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Maybe I should use map for this.

size_t start = utf16Pos;
// Workaround for combining marks and emoji modifiers until we implement
// per-cluster font selection: if a combining mark or an emoji modifier
Expand All @@ -528,8 +530,8 @@ void FontCollection::itemize(const uint16_t* string,
}
start -= prevChLength;
}
result->push_back(
{family->getClosestMatch(style), static_cast<int>(start), 0});
result->push_back({family->getClosestMatchWithChar(style, ch),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we also use variant to check glyphs?

result = hb_font_get_glyph(hb_font, codepoint, variant, &unusedGlyph);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about variant selector, so I looked it up. I think you're right. 😄

static_cast<int>(start), 0});
run = &result->back();
lastFamily = family.get();
}
Expand Down
40 changes: 40 additions & 0 deletions third_party/txt/src/minikin/FontFamily.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,46 @@ FakedFont FontFamily::getClosestMatch(FontStyle style) const {
return FakedFont{nullptr, FontFakery()};
}

FakedFont FontFamily::getClosestMatchWithChar(FontStyle style,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core algorithm is similar to FakedFont FontFamily::getClosestMatch(FontStyle style)
I think you can make one nice method for these two.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok~ Thanks!

uint32_t codepoint) {
int bestMatch = INT_MAX;
const Font* bestFont = nullptr;
if (mLastMatchedCodePoint == codepoint && style == mLastMatchedFontStyle) {
if (mFonts.size() > mLastMatchedFontIndex) {
bestFont = &mFonts[mLastMatchedFontIndex];
return FakedFont{bestFont->typeface.get(),
computeFakery(style, bestFont->style)};
}
}

for (size_t i = 0; i < mFonts.size(); i++) {
const Font& font = mFonts[i];
int match = computeMatch(font.style, style);
bool result = false;
{
hb_font_t* hb_font = getHbFontLocked(font.typeface.get());
uint32_t unusedGlyph;
Comment thread
bwikbs marked this conversation as resolved.
Outdated
result = hb_font_get_glyph(hb_font, codepoint, 0, &unusedGlyph);
hb_font_destroy(hb_font);
}

if (result) {
if (match < bestMatch) {
bestFont = &font;
bestMatch = match;
mLastMatchedFontIndex = i;
}
}
}
if (bestFont != nullptr) {
mLastMatchedFontStyle = style;
mLastMatchedCodePoint = codepoint;
return FakedFont{bestFont->typeface.get(),
computeFakery(style, bestFont->style)};
}
return FakedFont{nullptr, FontFakery()};
}

bool FontFamily::isColorEmojiFamily() const {
const FontLanguages& languageList = FontLanguageListCache::getById(mLangId);
for (size_t i = 0; i < languageList.size(); ++i) {
Expand Down
7 changes: 7 additions & 0 deletions third_party/txt/src/minikin/FontFamily.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class FontFamily {
int* weight,
bool* italic);
FakedFont getClosestMatch(FontStyle style) const;
FakedFont getClosestMatchWithChar(FontStyle style, uint32_t codepoint);

uint32_t langId() const { return mLangId; }
int variant() const { return mVariant; }
Expand Down Expand Up @@ -173,6 +174,8 @@ class FontFamily {
std::shared_ptr<FontFamily> createFamilyWithVariation(
const std::vector<FontVariation>& variations) const;

uint32_t getLastMatchedCodePoint() { return mLastMatchedCodePoint; }

private:
void computeCoverage();

Expand All @@ -184,6 +187,10 @@ class FontFamily {
SparseBitSet mCoverage;
bool mHasVSTable;

uint mLastMatchedFontIndex;
uint32_t mLastMatchedCodePoint;
FontStyle mLastMatchedFontStyle;

// Forbid copying and assignment.
FontFamily(const FontFamily&) = delete;
void operator=(const FontFamily&) = delete;
Expand Down
6 changes: 5 additions & 1 deletion third_party/txt/src/txt/platform_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
namespace txt {

std::vector<std::string> GetDefaultFontFamilies() {
#ifdef FLUTTER_USE_FONTCONFIG
Comment thread
bbrto21 marked this conversation as resolved.
return {"TizenDefaultFont"};
#else
return {
"SamsungOneUI",
"SamsungOneUIArabic",
Expand Down Expand Up @@ -72,11 +75,12 @@ std::vector<std::string> GetDefaultFontFamilies() {
"BreezeSansFallback",
"BreezeColorEmoji",
};
#endif
}

sk_sp<SkFontMgr> GetDefaultFontManager() {
#ifdef FLUTTER_USE_FONTCONFIG
return SkFontMgr_New_FontConfig(nullptr);
return SkFontMgr::RefDefault();
#else
return SkFontMgr_New_Custom_Directory("/usr/share/fonts");
#endif
Expand Down