Skip to content

Commit 5e90772

Browse files
committed
Check the presence of glyphs when selecting font
Signed-off-by: MuHong Byun <mh.byun@samsung.com>
1 parent ddd5fb6 commit 5e90772

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

third_party/txt/src/minikin/FontCollection.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ void FontCollection::itemize(const uint16_t* string,
509509
if (!shouldContinueRun) {
510510
const std::shared_ptr<FontFamily>& family = getFamilyForChar(
511511
ch, isVariationSelector(nextCh) ? nextCh : 0, langListId, variant);
512+
512513
if (utf16Pos == 0 || family.get() != lastFamily) {
513514
size_t start = utf16Pos;
514515
// Workaround for combining marks and emoji modifiers until we implement
@@ -529,7 +530,7 @@ void FontCollection::itemize(const uint16_t* string,
529530
start -= prevChLength;
530531
}
531532
result->push_back(
532-
{family->getClosestMatch(style), static_cast<int>(start), 0});
533+
{family->getClosestMatchWithChar(style,ch), static_cast<int>(start), 0});
533534
run = &result->back();
534535
lastFamily = family.get();
535536
}

third_party/txt/src/minikin/FontFamily.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,38 @@ FakedFont FontFamily::getClosestMatch(FontStyle style) const {
164164
return FakedFont{nullptr, FontFakery()};
165165
}
166166

167+
FakedFont FontFamily::getClosestMatchWithChar(FontStyle style,uint32_t codepoint) const {
168+
const Font* bestFont = nullptr;
169+
int bestMatch = 0;
170+
for (size_t i = 0; i < mFonts.size(); i++) {
171+
const Font& font = mFonts[i];
172+
int match = computeMatch(font.style, style);
173+
bool result = false;
174+
{
175+
hb_font_t* hb_font = getHbFontLocked(font.typeface.get());
176+
uint32_t unusedGlyph;
177+
result =
178+
hb_font_get_glyph(hb_font, codepoint, 0, &unusedGlyph);
179+
hb_font_destroy(hb_font);
180+
}
181+
182+
if(result){
183+
if (i == 0 || match < bestMatch) {
184+
bestFont = &font;
185+
bestMatch = match;
186+
}
187+
}
188+
if(bestMatch==0){
189+
bestMatch = match;
190+
}
191+
}
192+
if (bestFont != nullptr) {
193+
return FakedFont{bestFont->typeface.get(),
194+
computeFakery(style, bestFont->style)};
195+
}
196+
return FakedFont{nullptr, FontFakery()};
197+
}
198+
167199
bool FontFamily::isColorEmojiFamily() const {
168200
const FontLanguages& languageList = FontLanguageListCache::getById(mLangId);
169201
for (size_t i = 0; i < languageList.size(); ++i) {

third_party/txt/src/minikin/FontFamily.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ class FontFamily {
141141
int* weight,
142142
bool* italic);
143143
FakedFont getClosestMatch(FontStyle style) const;
144+
FakedFont getClosestMatchWithChar(FontStyle style, uint32_t codepoint) const;
144145

145146
uint32_t langId() const { return mLangId; }
146147
int variant() const { return mVariant; }

0 commit comments

Comments
 (0)