tesseract  5.0.0
tesseract::FontInfoTable Class Reference

#include <fontinfo.h>

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

Public Member Functions

TESS_API FontInfoTable ()
 
TESS_API ~FontInfoTable ()
 
TESS_API bool Serialize (FILE *fp) const
 
TESS_API bool DeSerialize (TFile *fp)
 
TESS_API bool SetContainsFontProperties (int font_id, const std::vector< ScoredFont > &font_set) const
 
TESS_API bool SetContainsMultipleFontProperties (const std::vector< ScoredFont > &font_set) const
 
TESS_API void MoveSpacingInfoFrom (FontInfoTable *other)
 
TESS_API void MoveTo (UnicityTable< FontInfo > *target)
 
- Public Member Functions inherited from tesseract::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 (int size, const FontInfo &t)
 
void resize_no_init (int size)
 
unsigned size () const
 
size_t unsigned_size () const
 
int size_reserved () const
 
bool empty () const
 
FontInfoat (int index) const
 
FontInfoback () const
 
FontInfooperator[] (int index) const
 
FontInfo pop_back ()
 
int get_index (const FontInfo &object) 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 clear ()
 
void delete_data_pointers ()
 
void move (GenericVector< FontInfo > *from)
 
bool write (FILE *f, std::function< bool(FILE *, const FontInfo &)> cb) const
 
bool read (TFile *f, std::function< bool(TFile *, FontInfo *)> cb)
 
bool Serialize (FILE *fp) const
 
bool Serialize (TFile *fp) const
 
bool DeSerialize (bool swap, FILE *fp)
 
bool DeSerialize (TFile *fp)
 
bool SerializeClasses (FILE *fp) const
 
bool SerializeClasses (TFile *fp) const
 
bool DeSerializeClasses (bool swap, FILE *fp)
 
bool DeSerializeClasses (TFile *fp)
 
void reverse ()
 
void sort ()
 
void sort (int(*comparator)(const void *, const void *))
 
int binary_search (const FontInfo &target) const
 
void swap (int index1, int index2)
 

Additional Inherited Members

- Static Public Member Functions inherited from tesseract::GenericVector< FontInfo >
static FontInfodouble_the_size_memcpy (int current_size, FontInfo *data)
 
- Protected Member Functions inherited from tesseract::GenericVector< FontInfo >
void init (int size)
 
- Protected Attributes inherited from tesseract::GenericVector< FontInfo >
int32_t size_used_
 
int32_t size_reserved_
 
FontInfodata_
 
std::function< void(FontInfo)> clear_cb_
 
- Static Protected Attributes inherited from tesseract::GenericVector< FontInfo >
static const int kDefaultVectorSize
 

Detailed Description

Definition at line 160 of file fontinfo.h.

Constructor & Destructor Documentation

◆ FontInfoTable()

tesseract::FontInfoTable::FontInfoTable ( )

Definition at line 47 of file fontinfo.cpp.

47  {
48  using namespace std::placeholders; // for _1, _2
50 }
void FontInfoDeleteCallback(FontInfo f)
Definition: fontinfo.cpp:129
void set_clear_callback(std::function< void(FontInfo)> cb)

◆ ~FontInfoTable()

tesseract::FontInfoTable::~FontInfoTable ( )
default

Member Function Documentation

◆ DeSerialize()

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

Definition at line 60 of file fontinfo.cpp.

60  {
61  truncate(0);
62  return this->DeSerializeClasses(fp);
63 }
bool DeSerializeClasses(bool swap, FILE *fp)

◆ MoveSpacingInfoFrom()

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

Definition at line 95 of file fontinfo.cpp.

95  {
96  using namespace std::placeholders; // for _1, _2
98  for (unsigned i = 0; i < other->size(); ++i) {
99  std::vector<FontSpacingInfo *> *spacing_vec = other->at(i).spacing_vec;
100  if (spacing_vec != nullptr) {
101  int target_index = get_index(other->at(i));
102  if (target_index < 0) {
103  // Bit copy the FontInfo and steal all the pointers.
104  push_back(other->at(i));
105  other->at(i).name = nullptr;
106  } else {
107  delete at(target_index).spacing_vec;
108  at(target_index).spacing_vec = other->at(i).spacing_vec;
109  }
110  other->at(i).spacing_vec = nullptr;
111  }
112  }
113 }
std::vector< FontSpacingInfo * > * spacing_vec
Definition: fontinfo.h:142
int get_index(const FontInfo &object) const
FontInfo & at(int index) const
Definition: genericvector.h:93

◆ MoveTo()

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

Definition at line 116 of file fontinfo.cpp.

116  {
117  target->clear();
118  using namespace std::placeholders; // for _1, _2
119  target->set_clear_callback(std::bind(FontInfoDeleteCallback, _1));
120  for (unsigned i = 0; i < size(); ++i) {
121  // Bit copy the FontInfo and steal all the pointers.
122  target->push_back(at(i));
123  at(i).name = nullptr;
124  at(i).spacing_vec = nullptr;
125  }
126 }

◆ Serialize()

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

Definition at line 55 of file fontinfo.cpp.

55  {
56  return this->SerializeClasses(fp);
57 }
bool SerializeClasses(FILE *fp) const

◆ SetContainsFontProperties()

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

Definition at line 67 of file fontinfo.cpp.

68  {
69  uint32_t properties = at(font_id).properties;
70  for (auto f : font_set) {
71  if (at(f.fontinfo_id).properties == properties) {
72  return true;
73  }
74  }
75  return false;
76 }
uint32_t properties
Definition: fontinfo.h:135

◆ SetContainsMultipleFontProperties()

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

Definition at line 79 of file fontinfo.cpp.

80  {
81  if (font_set.empty()) {
82  return false;
83  }
84  int first_font = font_set[0].fontinfo_id;
85  uint32_t properties = at(first_font).properties;
86  for (unsigned f = 1; f < font_set.size(); ++f) {
87  if (at(font_set[f].fontinfo_id).properties != properties) {
88  return true;
89  }
90  }
91  return false;
92 }

The documentation for this class was generated from the following files: