Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 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 IsSubsetOf (const Shape &other) const
 
bool IsEqualUnichars (Shape *other)
 

Detailed Description

Definition at line 62 of file shapetable.h.

Constructor & Destructor Documentation

tesseract::Shape::Shape ( )
inline

Definition at line 64 of file shapetable.h.

64 : destination_index_(-1) {}

Member Function Documentation

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

Definition at line 94 of file shapetable.cpp.

94  {
95  for (int c = 0; c < other.unichars_.size(); ++c) {
96  for (int f = 0; f < other.unichars_[c].font_ids.size(); ++f) {
97  AddToShape(other.unichars_[c].unichar_id,
98  other.unichars_[c].font_ids[f]);
99  }
100  }
101  unichars_sorted_ = unichars_.size() <= 1;
102 }
#define f(xc, yc)
Definition: imgscale.cpp:39
void AddToShape(int unichar_id, int font_id)
Definition: shapetable.cpp:75
void tesseract::Shape::AddToShape ( int  unichar_id,
int  font_id 
)

Definition at line 75 of file shapetable.cpp.

75  {
76  for (int c = 0; c < unichars_.size(); ++c) {
77  if (unichars_[c].unichar_id == unichar_id) {
78  // Found the unichar in the shape table.
79  GenericVector<int>& font_list = unichars_[c].font_ids;
80  for (int f = 0; f < font_list.size(); ++f) {
81  if (font_list[f] == font_id)
82  return; // Font is already there.
83  }
84  font_list.push_back(font_id);
85  return;
86  }
87  }
88  // Unichar_id is not in shape, so add it to shape.
89  unichars_.push_back(UnicharAndFonts(unichar_id, font_id));
90  unichars_sorted_ = unichars_.size() <= 1;
91 }
#define f(xc, yc)
Definition: imgscale.cpp:39
int push_back(T object)
int size() const
Definition: genericvector.h:59
bool tesseract::Shape::ContainsFont ( int  font_id) const

Definition at line 131 of file shapetable.cpp.

131  {
132  for (int c = 0; c < unichars_.size(); ++c) {
133  GenericVector<int>& font_list = unichars_[c].font_ids;
134  for (int f = 0; f < font_list.size(); ++f) {
135  if (font_list[f] == font_id)
136  return true;
137  }
138  }
139  return false;
140 }
#define f(xc, yc)
Definition: imgscale.cpp:39
int size() const
Definition: genericvector.h:59
bool tesseract::Shape::ContainsUnichar ( int  unichar_id) const

Definition at line 121 of file shapetable.cpp.

121  {
122  for (int c = 0; c < unichars_.size(); ++c) {
123  if (unichars_[c].unichar_id == unichar_id) {
124  return true;
125  }
126  }
127  return false;
128 }
bool tesseract::Shape::ContainsUnicharAndFont ( int  unichar_id,
int  font_id 
) const

Definition at line 105 of file shapetable.cpp.

105  {
106  for (int c = 0; c < unichars_.size(); ++c) {
107  if (unichars_[c].unichar_id == unichar_id) {
108  // Found the unichar, so look for the font.
109  GenericVector<int>& font_list = unichars_[c].font_ids;
110  for (int f = 0; f < font_list.size(); ++f) {
111  if (font_list[f] == font_id)
112  return true;
113  }
114  return false;
115  }
116  }
117  return false;
118 }
#define f(xc, yc)
Definition: imgscale.cpp:39
int size() const
Definition: genericvector.h:59
bool tesseract::Shape::DeSerialize ( bool  swap,
FILE *  fp 
)

Definition at line 64 of file shapetable.cpp.

64  {
65  uinT8 sorted;
66  if (fread(&sorted, sizeof(sorted), 1, fp) != 1)
67  return false;
68  unichars_sorted_ = sorted != 0;
69  if (!unichars_.DeSerializeClasses(swap, fp)) return false;
70  return true;
71 }
unsigned char uinT8
Definition: host.h:99
int tesseract::Shape::destination_index ( ) const
inline

Definition at line 72 of file shapetable.h.

72  {
73  return destination_index_;
74  }
bool tesseract::Shape::IsEqualUnichars ( Shape other)

Definition at line 158 of file shapetable.cpp.

158  {
159  if (unichars_.size() != other->unichars_.size()) return false;
160  if (!unichars_sorted_) SortUnichars();
161  if (!other->unichars_sorted_) other->SortUnichars();
162  for (int c = 0; c < unichars_.size(); ++c) {
163  if (unichars_[c].unichar_id != other->unichars_[c].unichar_id)
164  return false;
165  }
166  return true;
167 }
bool tesseract::Shape::IsSubsetOf ( const Shape other) const

Definition at line 143 of file shapetable.cpp.

143  {
144  for (int c = 0; c < unichars_.size(); ++c) {
145  int unichar_id = unichars_[c].unichar_id;
146  const GenericVector<int>& font_list = unichars_[c].font_ids;
147  for (int f = 0; f < font_list.size(); ++f) {
148  if (!other.ContainsUnicharAndFont(unichar_id, font_list[f]))
149  return false;
150  }
151  }
152  return true;
153 }
#define f(xc, yc)
Definition: imgscale.cpp:39
int size() const
Definition: genericvector.h:59
const UnicharAndFonts& tesseract::Shape::operator[] ( int  index) const
inline

Definition at line 83 of file shapetable.h.

83  {
84  return unichars_[index];
85  }
bool tesseract::Shape::Serialize ( FILE *  fp) const

Definition at line 55 of file shapetable.cpp.

55  {
56  uinT8 sorted = unichars_sorted_;
57  if (fwrite(&sorted, sizeof(sorted), 1, fp) != 1)
58  return false;
59  if (!unichars_.SerializeClasses(fp)) return false;
60  return true;
61 }
unsigned char uinT8
Definition: host.h:99
void tesseract::Shape::set_destination_index ( int  index)
inline

Definition at line 75 of file shapetable.h.

75  {
76  destination_index_ = index;
77  }
int tesseract::Shape::size ( ) const
inline

Definition at line 78 of file shapetable.h.

78  {
79  return unichars_.size();
80  }

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