tesseract  5.0.0-alpha-619-ge9db
tesseract::FontInfoTable Class Reference

#include <fontinfo.h>

Inheritance diagram for tesseract::FontInfoTable:
GenericVector< FontInfo >

Public Member Functions

 FontInfoTable ()
 
 ~FontInfoTable ()
 
bool Serialize (FILE *fp) const
 
bool DeSerialize (TFile *fp)
 
bool SetContainsFontProperties (int font_id, const GenericVector< ScoredFont > &font_set) const
 
bool SetContainsMultipleFontProperties (const GenericVector< ScoredFont > &font_set) const
 
void MoveSpacingInfoFrom (FontInfoTable *other)
 
void MoveTo (UnicityTable< FontInfo > *target)
 
- Public Member Functions inherited from GenericVector< FontInfo >
 GenericVector ()
 
 GenericVector (int size, const FontInfo &init_val)
 
 GenericVector (const GenericVector &other)
 
GenericVector< FontInfo > & operator+= (const GenericVector &other)
 
void operator+= (const FontInfo &t)
 
GenericVector< FontInfo > & operator= (const GenericVector &other)
 
 ~GenericVector ()
 
void reserve (int size)
 
void double_the_size ()
 
void init_to_size (int size, const FontInfo &t)
 
void resize_no_init (int size)
 
int size () const
 
size_t unsigned_size () const
 
int size_reserved () const
 
bool empty () const
 
FontInfo & get (int index) const
 
FontInfo & back () const
 
FontInfo & operator[] (int index) const
 
FontInfo pop_back ()
 
int get_index (const FontInfo &object) const
 
bool contains (const FontInfo &object) const
 
FontInfo contains_index (int index) const
 
int push_back (FontInfo object)
 
int push_back_new (const FontInfo &object)
 
int push_front (const FontInfo &object)
 
void set (const FontInfo &t, int index)
 
void insert (const FontInfo &t, int index)
 
void remove (int index)
 
void truncate (int size)
 
void set_clear_callback (std::function< void(FontInfo)> cb)
 
void set_compare_callback (std::function< bool(const FontInfo &, const FontInfo &)> cb)
 
void clear ()
 
void delete_data_pointers ()
 
void move (GenericVector< FontInfo > *from)
 
bool write (FILE *f, std::function< bool(FILE *, const FontInfo &)> cb) const
 
bool read (tesseract::TFile *f, std::function< bool(tesseract::TFile *, FontInfo *)> cb)
 
bool Serialize (FILE *fp) const
 
bool Serialize (tesseract::TFile *fp) const
 
bool DeSerialize (bool swap, FILE *fp)
 
bool DeSerialize (tesseract::TFile *fp)
 
bool SerializeClasses (FILE *fp) const
 
bool SerializeClasses (tesseract::TFile *fp) const
 
bool DeSerializeClasses (bool swap, FILE *fp)
 
bool DeSerializeClasses (tesseract::TFile *fp)
 
void reverse ()
 
void sort ()
 
void sort (int(*comparator)(const void *, const void *))
 
bool bool_binary_search (const FontInfo &target) const
 
int binary_search (const FontInfo &target) const
 
void compact_sorted ()
 
int choose_nth_item (int target_index)
 
void swap (int index1, int index2)
 
bool WithinBounds (const FontInfo &rangemin, const FontInfo &rangemax) const
 

Additional Inherited Members

- Static Public Member Functions inherited from GenericVector< FontInfo >
static bool SkipDeSerialize (tesseract::TFile *fp)
 
static bool SkipDeSerializeClasses (tesseract::TFile *fp)
 
static FontInfo * double_the_size_memcpy (int current_size, FontInfo *data)
 
- Protected Member Functions inherited from GenericVector< FontInfo >
int choose_nth_item (int target_index, int start, int end, unsigned int *seed)
 
void init (int size)
 
- Protected Attributes inherited from GenericVector< FontInfo >
int32_t size_used_
 
int32_t size_reserved_
 
FontInfo * data_
 
std::function< void(FontInfo)> clear_cb_
 
std::function< bool(const FontInfo &, const FontInfo &)> compare_cb_
 
- Static Protected Attributes inherited from GenericVector< FontInfo >
static const int kDefaultVectorSize
 

Detailed Description

Definition at line 146 of file fontinfo.h.

Constructor & Destructor Documentation

◆ FontInfoTable()

tesseract::FontInfoTable::FontInfoTable ( )

Definition at line 39 of file fontinfo.cpp.

39  {
40  using namespace std::placeholders; // for _1, _2
41  set_compare_callback(std::bind(CompareFontInfo, _1, _2));
43 }

◆ ~FontInfoTable()

tesseract::FontInfoTable::~FontInfoTable ( )

Definition at line 45 of file fontinfo.cpp.

45  {
46 }

Member Function Documentation

◆ DeSerialize()

bool tesseract::FontInfoTable::DeSerialize ( TFile fp)

Definition at line 54 of file fontinfo.cpp.

54  {
55  truncate(0);
56  return this->DeSerializeClasses(fp);
57 }

◆ MoveSpacingInfoFrom()

void tesseract::FontInfoTable::MoveSpacingInfoFrom ( FontInfoTable other)

Definition at line 85 of file fontinfo.cpp.

85  {
86  using namespace std::placeholders; // for _1, _2
87  set_compare_callback(std::bind(CompareFontInfo, _1, _2));
89  for (int i = 0; i < other->size(); ++i) {
90  GenericVector<FontSpacingInfo*>* spacing_vec = other->get(i).spacing_vec;
91  if (spacing_vec != nullptr) {
92  int target_index = get_index(other->get(i));
93  if (target_index < 0) {
94  // Bit copy the FontInfo and steal all the pointers.
95  push_back(other->get(i));
96  other->get(i).name = nullptr;
97  } else {
98  delete get(target_index).spacing_vec;
99  get(target_index).spacing_vec = other->get(i).spacing_vec;
100  }
101  other->get(i).spacing_vec = nullptr;
102  }
103  }
104 }

◆ MoveTo()

void tesseract::FontInfoTable::MoveTo ( UnicityTable< FontInfo > *  target)

Definition at line 107 of file fontinfo.cpp.

107  {
108  target->clear();
109  using namespace std::placeholders; // for _1, _2
110  target->set_compare_callback(std::bind(CompareFontInfo, _1, _2));
111  target->set_clear_callback(std::bind(FontInfoDeleteCallback, _1));
112  for (int i = 0; i < size(); ++i) {
113  // Bit copy the FontInfo and steal all the pointers.
114  target->push_back(get(i));
115  get(i).name = nullptr;
116  get(i).spacing_vec = nullptr;
117  }
118 }

◆ Serialize()

bool tesseract::FontInfoTable::Serialize ( FILE *  fp) const

Definition at line 49 of file fontinfo.cpp.

49  {
50  return this->SerializeClasses(fp);
51 }

◆ SetContainsFontProperties()

bool tesseract::FontInfoTable::SetContainsFontProperties ( int  font_id,
const GenericVector< ScoredFont > &  font_set 
) const

Definition at line 61 of file fontinfo.cpp.

62  {
63  uint32_t properties = get(font_id).properties;
64  for (int f = 0; f < font_set.size(); ++f) {
65  if (get(font_set[f].fontinfo_id).properties == properties)
66  return true;
67  }
68  return false;
69 }

◆ SetContainsMultipleFontProperties()

bool tesseract::FontInfoTable::SetContainsMultipleFontProperties ( const GenericVector< ScoredFont > &  font_set) const

Definition at line 72 of file fontinfo.cpp.

73  {
74  if (font_set.empty()) return false;
75  int first_font = font_set[0].fontinfo_id;
76  uint32_t properties = get(first_font).properties;
77  for (int f = 1; f < font_set.size(); ++f) {
78  if (get(font_set[f].fontinfo_id).properties != properties)
79  return true;
80  }
81  return false;
82 }

The documentation for this class was generated from the following files:
tesseract::FontInfoDeleteCallback
void FontInfoDeleteCallback(FontInfo f)
Definition: fontinfo.cpp:141
GenericVector< FontInfo >::set_clear_callback
void set_clear_callback(std::function< void(FontInfo)> cb)
Definition: genericvector.h:140
UnicityTable::push_back
int push_back(T object)
Add an element in the table.
Definition: unicity_table.h:168
GenericVector< FontInfo >::DeSerializeClasses
bool DeSerializeClasses(bool swap, FILE *fp)
Definition: genericvector.h:1038
GenericVector< FontInfo >::push_back
int push_back(FontInfo object)
Definition: genericvector.h:799
GenericVector< FontInfo >::SerializeClasses
bool SerializeClasses(FILE *fp) const
Definition: genericvector.h:1008
UnicityTable::set_compare_callback
void set_compare_callback(std::function< bool(const T &, const T &)> cb)
Definition: unicity_table.h:74
GenericVector< FontInfo >::set_compare_callback
void set_compare_callback(std::function< bool(const FontInfo &, const FontInfo &)> cb)
Definition: genericvector.h:146
GenericVector::empty
bool empty() const
Definition: genericvector.h:86
GenericVector< FontInfo >::get_index
int get_index(const FontInfo &object) const
Definition: genericvector.h:781
GenericVector
Definition: baseapi.h:40
UnicityTable::clear
void clear()
Definition: unicity_table.h:178
UnicityTable::set_clear_callback
void set_clear_callback(std::function< void(T)> cb)
Definition: unicity_table.h:68
GenericVector< FontInfo >::truncate
void truncate(int size)
Definition: genericvector.h:132
GenericVector::get
T & get(int index) const
Definition: genericvector.h:716
tesseract::CompareFontInfo
bool CompareFontInfo(const FontInfo &fi1, const FontInfo &fi2)
Definition: fontinfo.cpp:122
GenericVector< FontInfo >::size
int size() const
Definition: genericvector.h:71