tesseract  4.00.00dev
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 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 125 of file shapetable.cpp.

125  {
126  for (int c = 0; c < other.unichars_.size(); ++c) {
127  for (int f = 0; f < other.unichars_[c].font_ids.size(); ++f) {
128  AddToShape(other.unichars_[c].unichar_id,
129  other.unichars_[c].font_ids[f]);
130  }
131  }
132  unichars_sorted_ = unichars_.size() <= 1;
133 }
void AddToShape(int unichar_id, int font_id)
Definition: shapetable.cpp:106

◆ AddToShape()

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

Definition at line 106 of file shapetable.cpp.

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

◆ ContainsFont()

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

Definition at line 162 of file shapetable.cpp.

162  {
163  for (int c = 0; c < unichars_.size(); ++c) {
164  GenericVector<int>& font_list = unichars_[c].font_ids;
165  for (int f = 0; f < font_list.size(); ++f) {
166  if (font_list[f] == font_id)
167  return true;
168  }
169  }
170  return false;
171 }
int size() const
Definition: genericvector.h:72

◆ ContainsFontProperties()

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

Definition at line 174 of file shapetable.cpp.

175  {
176  for (int c = 0; c < unichars_.size(); ++c) {
177  GenericVector<int>& font_list = unichars_[c].font_ids;
178  for (int f = 0; f < font_list.size(); ++f) {
179  if (font_table.get(font_list[f]).properties == properties)
180  return true;
181  }
182  }
183  return false;
184 }
int size() const
Definition: genericvector.h:72

◆ ContainsMultipleFontProperties()

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

Definition at line 187 of file shapetable.cpp.

188  {
189  uinT32 properties = font_table.get(unichars_[0].font_ids[0]).properties;
190  for (int c = 0; c < unichars_.size(); ++c) {
191  GenericVector<int>& font_list = unichars_[c].font_ids;
192  for (int f = 0; f < font_list.size(); ++f) {
193  if (font_table.get(font_list[f]).properties != properties)
194  return true;
195  }
196  }
197  return false;
198 }
int size() const
Definition: genericvector.h:72
uint32_t uinT32
Definition: host.h:39

◆ ContainsUnichar()

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

Definition at line 152 of file shapetable.cpp.

152  {
153  for (int c = 0; c < unichars_.size(); ++c) {
154  if (unichars_[c].unichar_id == unichar_id) {
155  return true;
156  }
157  }
158  return false;
159 }

◆ ContainsUnicharAndFont()

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

Definition at line 136 of file shapetable.cpp.

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

◆ DeSerialize()

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

Definition at line 97 of file shapetable.cpp.

97  {
98  uinT8 sorted;
99  if (fp->FRead(&sorted, sizeof(sorted), 1) != 1) return false;
100  unichars_sorted_ = sorted != 0;
101  return unichars_.DeSerializeClasses(fp);
102 }
uint8_t uinT8
Definition: host.h:35

◆ 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 222 of file shapetable.cpp.

222  {
223  if (unichars_.size() != other->unichars_.size()) return false;
224  if (!unichars_sorted_) SortUnichars();
225  if (!other->unichars_sorted_) other->SortUnichars();
226  for (int c = 0; c < unichars_.size(); ++c) {
227  if (unichars_[c].unichar_id != other->unichars_[c].unichar_id)
228  return false;
229  }
230  return true;
231 }

◆ IsSubsetOf()

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

Definition at line 207 of file shapetable.cpp.

207  {
208  for (int c = 0; c < unichars_.size(); ++c) {
209  int unichar_id = unichars_[c].unichar_id;
210  const GenericVector<int>& font_list = unichars_[c].font_ids;
211  for (int f = 0; f < font_list.size(); ++f) {
212  if (!other.ContainsUnicharAndFont(unichar_id, font_list[f]))
213  return false;
214  }
215  }
216  return true;
217 }
int size() const
Definition: genericvector.h:72

◆ operator==()

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

Definition at line 202 of file shapetable.cpp.

202  {
203  return IsSubsetOf(other) && other.IsSubsetOf(*this);
204 }
bool IsSubsetOf(const Shape &other) const
Definition: shapetable.cpp:207

◆ 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 88 of file shapetable.cpp.

88  {
89  uinT8 sorted = unichars_sorted_;
90  if (fwrite(&sorted, sizeof(sorted), 1, fp) != 1)
91  return false;
92  if (!unichars_.SerializeClasses(fp)) return false;
93  return true;
94 }
uint8_t uinT8
Definition: host.h:35

◆ 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: