tesseract  5.0.0
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 154 of file shapetable.h.

Constructor & Destructor Documentation

◆ Shape()

tesseract::Shape::Shape ( )
inline

Definition at line 156 of file shapetable.h.

156 : destination_index_(-1) {}

Member Function Documentation

◆ AddShape()

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

Definition at line 123 of file shapetable.cpp.

123  {
124  for (const auto &unichar : other.unichars_) {
125  for (unsigned f = 0; f < unichar.font_ids.size(); ++f) {
126  AddToShape(unichar.unichar_id, unichar.font_ids[f]);
127  }
128  }
129  unichars_sorted_ = unichars_.size() <= 1;
130 }
void AddToShape(int unichar_id, int font_id)
Definition: shapetable.cpp:103

◆ AddToShape()

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

Definition at line 103 of file shapetable.cpp.

103  {
104  for (auto &unichar : unichars_) {
105  if (unichar.unichar_id == unichar_id) {
106  // Found the unichar in the shape table.
107  std::vector<int> &font_list = unichar.font_ids;
108  for (int f : font_list) {
109  if (f == font_id) {
110  return; // Font is already there.
111  }
112  }
113  font_list.push_back(font_id);
114  return;
115  }
116  }
117  // Unichar_id is not in shape, so add it to shape.
118  unichars_.emplace_back(unichar_id, font_id);
119  unichars_sorted_ = unichars_.size() <= 1;
120 }

◆ ContainsFont()

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

Definition at line 160 of file shapetable.cpp.

160  {
161  for (const auto &unichar : unichars_) {
162  auto &font_list = unichar.font_ids;
163  for (int f : font_list) {
164  if (f == font_id) {
165  return true;
166  }
167  }
168  }
169  return false;
170 }

◆ ContainsFontProperties()

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

Definition at line 173 of file shapetable.cpp.

173  {
174  for (const auto &unichar : unichars_) {
175  auto &font_list = unichar.font_ids;
176  for (int f : font_list) {
177  if (font_table.at(f).properties == properties) {
178  return true;
179  }
180  }
181  }
182  return false;
183 }

◆ ContainsMultipleFontProperties()

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

Definition at line 186 of file shapetable.cpp.

186  {
187  uint32_t properties = font_table.at(unichars_[0].font_ids[0]).properties;
188  for (const auto &unichar : unichars_) {
189  auto &font_list = unichar.font_ids;
190  for (int f : font_list) {
191  if (font_table.at(f).properties != properties) {
192  return true;
193  }
194  }
195  }
196  return false;
197 }

◆ ContainsUnichar()

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

Definition at line 150 of file shapetable.cpp.

150  {
151  for (const auto &unichar : unichars_) {
152  if (unichar.unichar_id == unichar_id) {
153  return true;
154  }
155  }
156  return false;
157 }

◆ ContainsUnicharAndFont()

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

Definition at line 133 of file shapetable.cpp.

133  {
134  for (const auto &unichar : unichars_) {
135  if (unichar.unichar_id == unichar_id) {
136  // Found the unichar, so look for the font.
137  auto &font_list = unichar.font_ids;
138  for (int f : font_list) {
139  if (f == font_id) {
140  return true;
141  }
142  }
143  return false;
144  }
145  }
146  return false;
147 }

◆ 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)) {
95  return false;
96  }
97  unichars_sorted_ = sorted != 0;
98  return fp->DeSerialize(unichars_);
99 }

◆ destination_index()

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

Definition at line 163 of file shapetable.h.

163  {
164  return destination_index_;
165  }

◆ IsEqualUnichars()

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

Definition at line 222 of file shapetable.cpp.

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

◆ IsSubsetOf()

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

Definition at line 206 of file shapetable.cpp.

206  {
207  for (const auto &unichar : unichars_) {
208  int unichar_id = unichar.unichar_id;
209  const std::vector<int> &font_list = unichar.font_ids;
210  for (int f : font_list) {
211  if (!other.ContainsUnicharAndFont(unichar_id, f)) {
212  return false;
213  }
214  }
215  }
216  return true;
217 }

◆ operator==()

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

Definition at line 201 of file shapetable.cpp.

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

◆ operator[]()

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

Definition at line 174 of file shapetable.h.

174  {
175  return unichars_[index];
176  }

◆ 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) && tesseract::Serialize(fp, unichars_);
89 }
bool Serialize(FILE *fp, const std::vector< T > &data)
Definition: helpers.h:251

◆ set_destination_index()

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

Definition at line 166 of file shapetable.h.

166  {
167  destination_index_ = index;
168  }

◆ SetUnicharId()

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

Definition at line 178 of file shapetable.h.

178  {
179  unichars_[index].unichar_id = unichar_id;
180  }

◆ size()

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

Definition at line 169 of file shapetable.h.

169  {
170  return unichars_.size();
171  }

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