tesseract  4.0.0-1-g2a2b
tesseract::Shape Class Reference

#include <shapetable.h>

Public Member Functions

 Shape ()
 
bool Serialize (FILE *fp) const
 
bool DeSerialize (TFile *fp)
 
int destination_index () const
 
void set_destination_index (int index)
 
int size () const
 
const UnicharAndFontsoperator[] (int index) const
 
void SetUnicharId (int index, int unichar_id)
 
void AddToShape (int unichar_id, int font_id)
 
void AddShape (const Shape &other)
 
bool ContainsUnicharAndFont (int unichar_id, int font_id) const
 
bool ContainsUnichar (int unichar_id) const
 
bool ContainsFont (int font_id) const
 
bool ContainsFontProperties (const FontInfoTable &font_table, uint32_t properties) const
 
bool ContainsMultipleFontProperties (const FontInfoTable &font_table) const
 
bool operator== (const Shape &other) const
 
bool IsSubsetOf (const Shape &other) const
 
bool IsEqualUnichars (Shape *other)
 

Detailed Description

Definition at line 185 of file shapetable.h.

Constructor & Destructor Documentation

◆ Shape()

tesseract::Shape::Shape ( )
inline

Definition at line 187 of file shapetable.h.

187 : destination_index_(-1) {}

Member Function Documentation

◆ AddShape()

void tesseract::Shape::AddShape ( const Shape other)

Definition at line 120 of file shapetable.cpp.

120  {
121  for (int c = 0; c < other.unichars_.size(); ++c) {
122  for (int f = 0; f < other.unichars_[c].font_ids.size(); ++f) {
123  AddToShape(other.unichars_[c].unichar_id,
124  other.unichars_[c].font_ids[f]);
125  }
126  }
127  unichars_sorted_ = unichars_.size() <= 1;
128 }
void AddToShape(int unichar_id, int font_id)
Definition: shapetable.cpp:101

◆ AddToShape()

void tesseract::Shape::AddToShape ( int  unichar_id,
int  font_id 
)

Definition at line 101 of file shapetable.cpp.

101  {
102  for (int c = 0; c < unichars_.size(); ++c) {
103  if (unichars_[c].unichar_id == unichar_id) {
104  // Found the unichar in the shape table.
105  GenericVector<int>& font_list = unichars_[c].font_ids;
106  for (int f = 0; f < font_list.size(); ++f) {
107  if (font_list[f] == font_id)
108  return; // Font is already there.
109  }
110  font_list.push_back(font_id);
111  return;
112  }
113  }
114  // Unichar_id is not in shape, so add it to shape.
115  unichars_.push_back(UnicharAndFonts(unichar_id, font_id));
116  unichars_sorted_ = unichars_.size() <= 1;
117 }
int size() const
Definition: genericvector.h:71
int push_back(T object)

◆ ContainsFont()

bool tesseract::Shape::ContainsFont ( int  font_id) const

Definition at line 157 of file shapetable.cpp.

157  {
158  for (int c = 0; c < unichars_.size(); ++c) {
159  GenericVector<int>& font_list = unichars_[c].font_ids;
160  for (int f = 0; f < font_list.size(); ++f) {
161  if (font_list[f] == font_id)
162  return true;
163  }
164  }
165  return false;
166 }
int size() const
Definition: genericvector.h:71

◆ ContainsFontProperties()

bool tesseract::Shape::ContainsFontProperties ( const FontInfoTable font_table,
uint32_t  properties 
) const

Definition at line 169 of file shapetable.cpp.

170  {
171  for (int c = 0; c < unichars_.size(); ++c) {
172  GenericVector<int>& font_list = unichars_[c].font_ids;
173  for (int f = 0; f < font_list.size(); ++f) {
174  if (font_table.get(font_list[f]).properties == properties)
175  return true;
176  }
177  }
178  return false;
179 }
int size() const
Definition: genericvector.h:71

◆ ContainsMultipleFontProperties()

bool tesseract::Shape::ContainsMultipleFontProperties ( const FontInfoTable font_table) const

Definition at line 182 of file shapetable.cpp.

183  {
184  uint32_t properties = font_table.get(unichars_[0].font_ids[0]).properties;
185  for (int c = 0; c < unichars_.size(); ++c) {
186  GenericVector<int>& font_list = unichars_[c].font_ids;
187  for (int f = 0; f < font_list.size(); ++f) {
188  if (font_table.get(font_list[f]).properties != properties)
189  return true;
190  }
191  }
192  return false;
193 }
int size() const
Definition: genericvector.h:71

◆ ContainsUnichar()

bool tesseract::Shape::ContainsUnichar ( int  unichar_id) const

Definition at line 147 of file shapetable.cpp.

147  {
148  for (int c = 0; c < unichars_.size(); ++c) {
149  if (unichars_[c].unichar_id == unichar_id) {
150  return true;
151  }
152  }
153  return false;
154 }

◆ ContainsUnicharAndFont()

bool tesseract::Shape::ContainsUnicharAndFont ( int  unichar_id,
int  font_id 
) const

Definition at line 131 of file shapetable.cpp.

131  {
132  for (int c = 0; c < unichars_.size(); ++c) {
133  if (unichars_[c].unichar_id == unichar_id) {
134  // Found the unichar, so look for the font.
135  GenericVector<int>& font_list = unichars_[c].font_ids;
136  for (int f = 0; f < font_list.size(); ++f) {
137  if (font_list[f] == font_id)
138  return true;
139  }
140  return false;
141  }
142  }
143  return false;
144 }
int size() const
Definition: genericvector.h:71

◆ DeSerialize()

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

Definition at line 92 of file shapetable.cpp.

92  {
93  uint8_t sorted;
94  if (!fp->DeSerialize(&sorted)) return false;
95  unichars_sorted_ = sorted != 0;
96  return unichars_.DeSerializeClasses(fp);
97 }

◆ destination_index()

int tesseract::Shape::destination_index ( ) const
inline

Definition at line 194 of file shapetable.h.

194  {
195  return destination_index_;
196  }

◆ IsEqualUnichars()

bool tesseract::Shape::IsEqualUnichars ( Shape other)

Definition at line 217 of file shapetable.cpp.

217  {
218  if (unichars_.size() != other->unichars_.size()) return false;
219  if (!unichars_sorted_) SortUnichars();
220  if (!other->unichars_sorted_) other->SortUnichars();
221  for (int c = 0; c < unichars_.size(); ++c) {
222  if (unichars_[c].unichar_id != other->unichars_[c].unichar_id)
223  return false;
224  }
225  return true;
226 }

◆ IsSubsetOf()

bool tesseract::Shape::IsSubsetOf ( const Shape other) const

Definition at line 202 of file shapetable.cpp.

202  {
203  for (int c = 0; c < unichars_.size(); ++c) {
204  int unichar_id = unichars_[c].unichar_id;
205  const GenericVector<int>& font_list = unichars_[c].font_ids;
206  for (int f = 0; f < font_list.size(); ++f) {
207  if (!other.ContainsUnicharAndFont(unichar_id, font_list[f]))
208  return false;
209  }
210  }
211  return true;
212 }
int size() const
Definition: genericvector.h:71

◆ operator==()

bool tesseract::Shape::operator== ( const Shape other) const

Definition at line 197 of file shapetable.cpp.

197  {
198  return IsSubsetOf(other) && other.IsSubsetOf(*this);
199 }
bool IsSubsetOf(const Shape &other) const
Definition: shapetable.cpp:202

◆ operator[]()

const UnicharAndFonts& tesseract::Shape::operator[] ( int  index) const
inline

Definition at line 205 of file shapetable.h.

205  {
206  return unichars_[index];
207  }

◆ Serialize()

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

Definition at line 86 of file shapetable.cpp.

86  {
87  uint8_t sorted = unichars_sorted_;
88  return tesseract::Serialize(fp, &sorted) && unichars_.SerializeClasses(fp);
89 }
bool Serialize(FILE *fp, const char *data, size_t n)
Definition: serialis.cpp:59

◆ set_destination_index()

void tesseract::Shape::set_destination_index ( int  index)
inline

Definition at line 197 of file shapetable.h.

197  {
198  destination_index_ = index;
199  }

◆ SetUnicharId()

void tesseract::Shape::SetUnicharId ( int  index,
int  unichar_id 
)
inline

Definition at line 209 of file shapetable.h.

209  {
210  unichars_[index].unichar_id = unichar_id;
211  }

◆ size()

int tesseract::Shape::size ( ) const
inline

Definition at line 200 of file shapetable.h.

200  {
201  return unichars_.size();
202  }

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