代码片段
class FontCoverage
{
public:
using SP = std::shared_ptr<FontCoverage>;
virtual ~FontCoverage() = default;
virtual void set(int index, FontTypes::CoverageLevel level) = 0;
virtual FontTypes::CoverageLevel get(int index) = 0;
virtual FontCoverage::SP clone() = 0;
};
freetype:
FTCoverage::SP coverage = std::make_shared<FTCoverage>();
FT_CharMap *charMap = (*m_face)->charmaps;
for (int i = 0; i < (*m_face)->num_charmaps; i++) {
FT_Select_Charmap((*m_face), charMap[i]->encoding);
FT_UInt gIndex;
for (auto charCode = FT_Get_First_Char((*m_face), &gIndex); gIndex != 0;
charCode = FT_Get_Next_Char((*m_face), charCode, &gIndex)) {
coverage->set(charCode, FontTypes::CoverageLevel::COVERAGE_EXACT);
}
}
harfbuzz:
FontCoverage::SP coverage = std::make_shared<HBCoverage>();
hb_set_t *chars = hb_set_create();
hb_codepoint_t ch = HB_SET_VALUE_INVALID;
hb_face_collect_unicodes(m_face, chars);
while (hb_set_next(chars, &ch))
coverage->set(ch, FontTypes::CoverageLevel::COVERAGE_EXACT);
hb_set_destroy(chars);
关键点
1.字体解析需包含完整的unicode范围
2.根据unicode,字体名,大小等最优匹配得到回退列表