20#ifndef TESSERACT_TRAINING_PANGO_FONT_INFO_H_
21#define TESSERACT_TRAINING_PANGO_FONT_INFO_H_
27#include "pango/pango-font.h"
28#include "pango/pango.h"
29#include "pango/pangocairo.h"
32#include <unordered_map>
67 bool ParseFontDescriptionName(
const std::string &name);
70 bool CoversUTF8Text(
const char *utf8_text,
int byte_length)
const;
73 int DropUncoveredChars(std::string *utf8_text)
const;
80 bool CanRenderString(
const char *utf8_word,
int len, std::vector<std::string> *graphemes)
const;
81 bool CanRenderString(
const char *utf8_word,
int len)
const;
87 bool GetSpacingProperties(
const std::string &utf8_char,
int *x_bearing,
int *x_advance)
const;
92 static void SoftInitFontConfig();
95 static void HardInitFontConfig(
const char *fonts_dir,
const char *cache_dir);
98 std::string DescriptionName()
const;
115 resolution_ = resolution;
121 bool ParseFontDescription(
const PangoFontDescription *desc);
124 PangoFont *ToPangoFont()
const;
127 std::string family_name_;
131 PangoFontDescription *desc_;
141 static std::string fonts_dir_;
144 static std::string cache_dir_;
158 return IsAvailableFont(font_desc,
nullptr);
163 static bool IsAvailableFont(
const char *font_desc, std::string *best_match);
165 static const std::vector<std::string> &ListAvailableFonts();
170 static bool SelectFont(
const char *utf8_word,
const int utf8_len, std::string *font_name,
171 std::vector<std::string> *graphemes);
176 static bool SelectFont(
const char *utf8_word,
const int utf8_len,
177 const std::vector<std::string> &all_fonts, std::string *font_name,
178 std::vector<std::string> *graphemes);
189 static std::string BestFonts(
const std::unordered_map<char32, int64_t> &ch_map,
190 std::vector<std::pair<
const char *, std::vector<bool>>> *font_flag);
197 static int FontScore(
const std::unordered_map<char32, int64_t> &ch_map,
198 const std::string &fontname,
int *raw_score, std::vector<bool> *ch_flags);
201 static void ReInit();
202 static void PangoFontTypeInfo();
205 static std::vector<std::string> available_fonts_;
void set_resolution(const int resolution)
FontTypeEnum font_type() const
const std::string & family_name() const
static bool IsAvailableFont(const char *font_desc)