All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tesseract::Shape Class Reference

#include <shapetable.h>

Public Member Functions

 Shape ()
 
bool Serialize (FILE *fp) const
 
bool DeSerialize (bool swap, FILE *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 186 of file shapetable.h.

Constructor & Destructor Documentation

tesseract::Shape::Shape ( )
inline

Definition at line 188 of file shapetable.h.

188 : destination_index_(-1) {}

Member Function Documentation

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

Definition at line 129 of file shapetable.cpp.

129  {
130  for (int c = 0; c < other.unichars_.size(); ++c) {
131  for (int f = 0; f < other.unichars_[c].font_ids.size(); ++f) {
132  AddToShape(other.unichars_[c].unichar_id,
133  other.unichars_[c].font_ids[f]);
134  }
135  }
136  unichars_sorted_ = unichars_.size() <= 1;
137 }
void AddToShape(int unichar_id, int font_id)
Definition: shapetable.cpp:110
void tesseract::Shape::AddToShape ( int  unichar_id,
int  font_id 
)

Definition at line 110 of file shapetable.cpp.

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

Definition at line 166 of file shapetable.cpp.

166  {
167  for (int c = 0; c < unichars_.size(); ++c) {
168  GenericVector<int>& font_list = unichars_[c].font_ids;
169  for (int f = 0; f < font_list.size(); ++f) {
170  if (font_list[f] == font_id)
171  return true;
172  }
173  }
174  return false;
175 }
int size() const
Definition: genericvector.h:72
bool tesseract::Shape::ContainsFontProperties ( const FontInfoTable font_table,
uinT32  properties 
) const

Definition at line 178 of file shapetable.cpp.

179  {
180  for (int c = 0; c < unichars_.size(); ++c) {
181  GenericVector<int>& font_list = unichars_[c].font_ids;
182  for (int f = 0; f < font_list.size(); ++f) {
183  if (font_table.get(font_list[f]).properties == properties)
184  return true;
185  }
186  }
187  return false;
188 }
int size() const
Definition: genericvector.h:72
bool tesseract::Shape::ContainsMultipleFontProperties ( const FontInfoTable font_table) const

Definition at line 191 of file shapetable.cpp.

192  {
193  uinT32 properties = font_table.get(unichars_[0].font_ids[0]).properties;
194  for (int c = 0; c < unichars_.size(); ++c) {
195  GenericVector<int>& font_list = unichars_[c].font_ids;
196  for (int f = 0; f < font_list.size(); ++f) {
197  if (font_table.get(font_list[f]).properties != properties)
198  return true;
199  }
200  }
201  return false;
202 }
int size() const
Definition: genericvector.h:72
unsigned int uinT32
Definition: host.h:103
bool tesseract::Shape::ContainsUnichar ( int  unichar_id) const

Definition at line 156 of file shapetable.cpp.

156  {
157  for (int c = 0; c < unichars_.size(); ++c) {
158  if (unichars_[c].unichar_id == unichar_id) {
159  return true;
160  }
161  }
162  return false;
163 }
bool tesseract::Shape::ContainsUnicharAndFont ( int  unichar_id,
int  font_id 
) const

Definition at line 140 of file shapetable.cpp.

140  {
141  for (int c = 0; c < unichars_.size(); ++c) {
142  if (unichars_[c].unichar_id == unichar_id) {
143  // Found the unichar, so look for the font.
144  GenericVector<int>& font_list = unichars_[c].font_ids;
145  for (int f = 0; f < font_list.size(); ++f) {
146  if (font_list[f] == font_id)
147  return true;
148  }
149  return false;
150  }
151  }
152  return false;
153 }
int size() const
Definition: genericvector.h:72
bool tesseract::Shape::DeSerialize ( bool  swap,
FILE *  fp 
)

Definition at line 99 of file shapetable.cpp.

99  {
100  uinT8 sorted;
101  if (fread(&sorted, sizeof(sorted), 1, fp) != 1)
102  return false;
103  unichars_sorted_ = sorted != 0;
104  if (!unichars_.DeSerializeClasses(swap, fp)) return false;
105  return true;
106 }
unsigned char uinT8
Definition: host.h:99
int tesseract::Shape::destination_index ( ) const
inline

Definition at line 196 of file shapetable.h.

196  {
197  return destination_index_;
198  }
bool tesseract::Shape::IsEqualUnichars ( Shape other)

Definition at line 226 of file shapetable.cpp.

226  {
227  if (unichars_.size() != other->unichars_.size()) return false;
228  if (!unichars_sorted_) SortUnichars();
229  if (!other->unichars_sorted_) other->SortUnichars();
230  for (int c = 0; c < unichars_.size(); ++c) {
231  if (unichars_[c].unichar_id != other->unichars_[c].unichar_id)
232  return false;
233  }
234  return true;
235 }
bool tesseract::Shape::IsSubsetOf ( const Shape other) const

Definition at line 211 of file shapetable.cpp.

211  {
212  for (int c = 0; c < unichars_.size(); ++c) {
213  int unichar_id = unichars_[c].unichar_id;
214  const GenericVector<int>& font_list = unichars_[c].font_ids;
215  for (int f = 0; f < font_list.size(); ++f) {
216  if (!other.ContainsUnicharAndFont(unichar_id, font_list[f]))
217  return false;
218  }
219  }
220  return true;
221 }
int size() const
Definition: genericvector.h:72
bool tesseract::Shape::operator== ( const Shape other) const

Definition at line 206 of file shapetable.cpp.

206  {
207  return IsSubsetOf(other) && other.IsSubsetOf(*this);
208 }
bool IsSubsetOf(const Shape &other) const
Definition: shapetable.cpp:211
const UnicharAndFonts& tesseract::Shape::operator[] ( int  index) const
inline

Definition at line 207 of file shapetable.h.

207  {
208  return unichars_[index];
209  }
bool tesseract::Shape::Serialize ( FILE *  fp) const

Definition at line 90 of file shapetable.cpp.

90  {
91  uinT8 sorted = unichars_sorted_;
92  if (fwrite(&sorted, sizeof(sorted), 1, fp) != 1)
93  return false;
94  if (!unichars_.SerializeClasses(fp)) return false;
95  return true;
96 }
unsigned char uinT8
Definition: host.h:99
void tesseract::Shape::set_destination_index ( int  index)
inline

Definition at line 199 of file shapetable.h.

199  {
200  destination_index_ = index;
201  }
void tesseract::Shape::SetUnicharId ( int  index,
int  unichar_id 
)
inline

Definition at line 211 of file shapetable.h.

211  {
212  unichars_[index].unichar_id = unichar_id;
213  }
int tesseract::Shape::size ( ) const
inline

Definition at line 202 of file shapetable.h.

202  {
203  return unichars_.size();
204  }

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