697 const double kMinOKFraction = 0.99;
700 const double kMinWeightedFraction = 0.99995;
703 std::vector<std::vector<bool> > font_flags;
704 std::vector<int> font_scores;
705 std::vector<int> raw_scores;
706 int most_ok_chars = 0;
707 int best_raw_score = 0;
709 for (
unsigned i = 0; i < font_names.size(); ++i) {
710 std::vector<bool> ch_flags;
712 int ok_chars =
FontScore(ch_map, font_names[i], &raw_score, &ch_flags);
713 most_ok_chars = std::max(ok_chars, most_ok_chars);
714 best_raw_score = std::max(raw_score, best_raw_score);
716 font_flags.push_back(ch_flags);
717 font_scores.push_back(ok_chars);
718 raw_scores.push_back(raw_score);
729 int least_good_enough =
static_cast<int>(most_ok_chars * kMinOKFraction);
730 int least_raw_enough =
static_cast<int>(best_raw_score * kMinOKFraction);
731 int override_enough =
static_cast<int>(most_ok_chars * kMinWeightedFraction);
733 std::string font_list;
734 for (
unsigned i = 0; i < font_names.size(); ++i) {
735 int score = font_scores[i];
736 int raw_score = raw_scores[i];
737 if ((score >= least_good_enough && raw_score >= least_raw_enough) ||
738 score >= override_enough) {
739 fonts->push_back(std::make_pair(font_names[i].c_str(), font_flags[i]));
740 tlog(1,
"OK font %s = %.4f%%, raw = %d = %.2f%%\n",
741 font_names[i].c_str(),
742 100.0 * score / most_ok_chars,
743 raw_score, 100.0 * raw_score / best_raw_score);
744 font_list += font_names[i];
746 }
else if (score >= least_good_enough || raw_score >= least_raw_enough) {
747 tlog(1,
"Runner-up font %s = %.4f%%, raw = %d = %.2f%%\n",
748 font_names[i].c_str(),
749 100.0 * score / most_ok_chars,
750 raw_score, 100.0 * raw_score / best_raw_score);
static const std::vector< std::string > & ListAvailableFonts()
static int FontScore(const std::unordered_map< char32, int64_t > &ch_map, const std::string &fontname, int *raw_score, std::vector< bool > *ch_flags)