709 {
710 const double kMinOKFraction = 0.99;
711
712
713 const double kMinWeightedFraction = 0.99995;
714
715 fonts->clear();
716 std::vector<std::vector<bool> > font_flags;
717 std::vector<int> font_scores;
718 std::vector<int> raw_scores;
719 int most_ok_chars = 0;
720 int best_raw_score = 0;
722 for (unsigned i = 0; i < font_names.size(); ++i) {
723 std::vector<bool> ch_flags;
724 int raw_score = 0;
725 int ok_chars =
FontScore(ch_map, font_names[i], &raw_score, &ch_flags);
726 most_ok_chars = std::max(ok_chars, most_ok_chars);
727 best_raw_score = std::max(raw_score, best_raw_score);
728
729 font_flags.push_back(ch_flags);
730 font_scores.push_back(ok_chars);
731 raw_scores.push_back(raw_score);
732 }
733
734
735
736
737
738
739
740
741
742 int least_good_enough = static_cast<int>(most_ok_chars * kMinOKFraction);
743 int least_raw_enough = static_cast<int>(best_raw_score * kMinOKFraction);
744 int override_enough = static_cast<int>(most_ok_chars * kMinWeightedFraction);
745
746 std::string font_list;
747 for (unsigned i = 0; i < font_names.size(); ++i) {
748 int score = font_scores[i];
749 int raw_score = raw_scores[i];
750 if ((score >= least_good_enough && raw_score >= least_raw_enough) ||
751 score >= override_enough) {
752 fonts->push_back(std::make_pair(font_names[i].c_str(), font_flags[i]));
753 tlog(1,
"OK font %s = %.4f%%, raw = %d = %.2f%%\n",
754 font_names[i].c_str(),
755 100.0 * score / most_ok_chars,
756 raw_score, 100.0 * raw_score / best_raw_score);
757 font_list += font_names[i];
758 font_list += "\n";
759 } else if (score >= least_good_enough || raw_score >= least_raw_enough) {
760 tlog(1,
"Runner-up font %s = %.4f%%, raw = %d = %.2f%%\n",
761 font_names[i].c_str(),
762 100.0 * score / most_ok_chars,
763 raw_score, 100.0 * raw_score / best_raw_score);
764 }
765 }
766 return font_list;
767}
static int FontScore(const std::unordered_map< char32, int64_t > &ch_map, const std::string &fontname, int *raw_score, std::vector< bool > *ch_flags)
static const std::vector< std::string > & ListAvailableFonts()