tesseract
3.03
|
#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 UnicharAndFonts & | operator[] (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) |
Definition at line 171 of file shapetable.h.
tesseract::Shape::Shape | ( | ) | [inline] |
Definition at line 173 of file shapetable.h.
: destination_index_(-1) {}
void tesseract::Shape::AddShape | ( | const Shape & | other | ) |
Definition at line 129 of file shapetable.cpp.
{ for (int c = 0; c < other.unichars_.size(); ++c) { for (int f = 0; f < other.unichars_[c].font_ids.size(); ++f) { AddToShape(other.unichars_[c].unichar_id, other.unichars_[c].font_ids[f]); } } unichars_sorted_ = unichars_.size() <= 1; }
void tesseract::Shape::AddToShape | ( | int | unichar_id, |
int | font_id | ||
) |
Definition at line 110 of file shapetable.cpp.
{ for (int c = 0; c < unichars_.size(); ++c) { if (unichars_[c].unichar_id == unichar_id) { // Found the unichar in the shape table. GenericVector<int>& font_list = unichars_[c].font_ids; for (int f = 0; f < font_list.size(); ++f) { if (font_list[f] == font_id) return; // Font is already there. } font_list.push_back(font_id); return; } } // Unichar_id is not in shape, so add it to shape. unichars_.push_back(UnicharAndFonts(unichar_id, font_id)); unichars_sorted_ = unichars_.size() <= 1; }
bool tesseract::Shape::ContainsFont | ( | int | font_id | ) | const |
Definition at line 166 of file shapetable.cpp.
{ for (int c = 0; c < unichars_.size(); ++c) { GenericVector<int>& font_list = unichars_[c].font_ids; for (int f = 0; f < font_list.size(); ++f) { if (font_list[f] == font_id) return true; } } return false; }
bool tesseract::Shape::ContainsFontProperties | ( | const FontInfoTable & | font_table, |
uinT32 | properties | ||
) | const |
Definition at line 178 of file shapetable.cpp.
{ for (int c = 0; c < unichars_.size(); ++c) { GenericVector<int>& font_list = unichars_[c].font_ids; for (int f = 0; f < font_list.size(); ++f) { if (font_table.get(font_list[f]).properties == properties) return true; } } return false; }
bool tesseract::Shape::ContainsMultipleFontProperties | ( | const FontInfoTable & | font_table | ) | const |
Definition at line 191 of file shapetable.cpp.
{ uinT32 properties = font_table.get(unichars_[0].font_ids[0]).properties; for (int c = 0; c < unichars_.size(); ++c) { GenericVector<int>& font_list = unichars_[c].font_ids; for (int f = 0; f < font_list.size(); ++f) { if (font_table.get(font_list[f]).properties != properties) return true; } } return false; }
bool tesseract::Shape::ContainsUnichar | ( | int | unichar_id | ) | const |
Definition at line 156 of file shapetable.cpp.
{ for (int c = 0; c < unichars_.size(); ++c) { if (unichars_[c].unichar_id == unichar_id) { return true; } } return false; }
bool tesseract::Shape::ContainsUnicharAndFont | ( | int | unichar_id, |
int | font_id | ||
) | const |
Definition at line 140 of file shapetable.cpp.
{ for (int c = 0; c < unichars_.size(); ++c) { if (unichars_[c].unichar_id == unichar_id) { // Found the unichar, so look for the font. GenericVector<int>& font_list = unichars_[c].font_ids; for (int f = 0; f < font_list.size(); ++f) { if (font_list[f] == font_id) return true; } return false; } } return false; }
bool tesseract::Shape::DeSerialize | ( | bool | swap, |
FILE * | fp | ||
) |
Definition at line 99 of file shapetable.cpp.
{ uinT8 sorted; if (fread(&sorted, sizeof(sorted), 1, fp) != 1) return false; unichars_sorted_ = sorted != 0; if (!unichars_.DeSerializeClasses(swap, fp)) return false; return true; }
int tesseract::Shape::destination_index | ( | ) | const [inline] |
Definition at line 181 of file shapetable.h.
{
return destination_index_;
}
bool tesseract::Shape::IsEqualUnichars | ( | Shape * | other | ) |
Definition at line 226 of file shapetable.cpp.
bool tesseract::Shape::IsSubsetOf | ( | const Shape & | other | ) | const |
Definition at line 211 of file shapetable.cpp.
{ for (int c = 0; c < unichars_.size(); ++c) { int unichar_id = unichars_[c].unichar_id; const GenericVector<int>& font_list = unichars_[c].font_ids; for (int f = 0; f < font_list.size(); ++f) { if (!other.ContainsUnicharAndFont(unichar_id, font_list[f])) return false; } } return true; }
bool tesseract::Shape::operator== | ( | const Shape & | other | ) | const |
Definition at line 206 of file shapetable.cpp.
{ return IsSubsetOf(other) && other.IsSubsetOf(*this); }
const UnicharAndFonts& tesseract::Shape::operator[] | ( | int | index | ) | const [inline] |
Definition at line 192 of file shapetable.h.
{
return unichars_[index];
}
bool tesseract::Shape::Serialize | ( | FILE * | fp | ) | const |
Definition at line 90 of file shapetable.cpp.
{ uinT8 sorted = unichars_sorted_; if (fwrite(&sorted, sizeof(sorted), 1, fp) != 1) return false; if (!unichars_.SerializeClasses(fp)) return false; return true; }
void tesseract::Shape::set_destination_index | ( | int | index | ) | [inline] |
Definition at line 184 of file shapetable.h.
{ destination_index_ = index; }
void tesseract::Shape::SetUnicharId | ( | int | index, |
int | unichar_id | ||
) | [inline] |
Definition at line 196 of file shapetable.h.
{ unichars_[index].unichar_id = unichar_id; }
int tesseract::Shape::size | ( | ) | const [inline] |
Definition at line 187 of file shapetable.h.
{ return unichars_.size(); }