Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 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
24 changes: 22 additions & 2 deletions third_party/txt/src/minikin/FontCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ void FontCollection::itemize(const uint16_t* string,
if (!shouldContinueRun) {
const std::shared_ptr<FontFamily>& family = getFamilyForChar(
ch, isVariationSelector(nextCh) ? nextCh : 0, langListId, variant);

Comment thread
bwikbs marked this conversation as resolved.
Outdated
if (utf16Pos == 0 || family.get() != lastFamily) {
size_t start = utf16Pos;
// Workaround for combining marks and emoji modifiers until we implement
Expand All @@ -528,8 +529,27 @@ void FontCollection::itemize(const uint16_t* string,
}
start -= prevChLength;
}
result->push_back(
{family->getClosestMatch(style), static_cast<int>(start), 0});
result->push_back({family->getClosestMatch(style, ch, variant),
static_cast<int>(start), 0});
run = &result->back();
lastFamily = family.get();
} else if (family.get() == lastFamily &&
// We need to change this condition to more general logic. And
// when changing the font, it is necessary to check whether the
// existing characters also have glyphs.
Comment thread
bwikbs marked this conversation as resolved.
!(U_GET_GC_MASK(prevCh) & U_GC_L_MASK) &&
(U_GET_GC_MASK(ch) & U_GC_L_MASK)) {
size_t start = utf16Pos;
auto current_font = family->getClosestMatch(style, ch, variant);
if (result->back().fakedFont.font != current_font.font) {
const size_t prevChLength = U16_LENGTH(prevCh);
run->end -= prevChLength;
if (run->start == run->end) {
result->pop_back();
}
start -= prevChLength;
}
result->push_back({current_font, static_cast<int>(start), 0});
run = &result->back();
lastFamily = family.get();
}
Expand Down
22 changes: 17 additions & 5 deletions third_party/txt/src/minikin/FontFamily.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,27 @@ static FontFakery computeFakery(FontStyle wanted, FontStyle actual) {
return FontFakery(isFakeBold, isFakeItalic);
}

FakedFont FontFamily::getClosestMatch(FontStyle style) const {
FakedFont FontFamily::getClosestMatch(FontStyle style,
uint32_t codepoint,
uint32_t variationSelector) const {
Comment thread
bwikbs marked this conversation as resolved.
Outdated
int bestMatch = INT_MAX;
const Font* bestFont = nullptr;
int bestMatch = 0;
for (size_t i = 0; i < mFonts.size(); i++) {
const Font& font = mFonts[i];
int match = computeMatch(font.style, style);
if (i == 0 || match < bestMatch) {
bestFont = &font;
bestMatch = match;
bool result = false;
if (codepoint != 0) {
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, variationSelector,
&unusedGlyph);
hb_font_destroy(hb_font);
}
if (!codepoint || (codepoint && result)) {
if (match < bestMatch) {
bestFont = &font;
bestMatch = match;
}
}
}
if (bestFont != nullptr) {
Expand Down
4 changes: 3 additions & 1 deletion third_party/txt/src/minikin/FontFamily.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ class FontFamily {
static bool analyzeStyle(const std::shared_ptr<MinikinFont>& typeface,
int* weight,
bool* italic);
FakedFont getClosestMatch(FontStyle style) const;
FakedFont getClosestMatch(FontStyle style,
uint32_t codepoint = 0,
uint32_t variationSelector = 0) const;

uint32_t langId() const { return mLangId; }
int variant() const { return mVariant; }
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