tesseract
5.0.0-alpha-619-ge9db
|
Go to the documentation of this file.
19 #ifndef TESSERACT_CCUTIL_UNICHARSET_H_
20 #define TESSERACT_CCUTIL_UNICHARSET_H_
58 inline void set_all(
const char *unichar,
int pos,
int total,
bool natural) {
65 strncpy(this->unichar, uch,
sizeof(this->unichar));
68 inline void set_pos(
int p) { this->pos = p; }
70 inline const char*
get_unichar()
const {
return this->unichar; }
71 inline int get_pos()
const {
return this->pos; }
72 inline int get_total()
const {
return this->total; }
80 return to_string(unichar, pos, total, natural);
85 inline bool equals(
const char *other_unichar,
86 int other_pos,
int other_total)
const {
87 return (strcmp(this->unichar, other_unichar) == 0 &&
88 this->pos == other_pos && this->total == other_total);
99 return (strcmp(this->unichar, fragment->
get_unichar()) == 0 &&
101 this->pos == fragment->
get_pos() + 1);
108 inline bool is_ending()
const {
return this->pos == this->total-1; }
180 #ifndef U_HIDE_DEPRECATED_API
182 #endif // U_HIDE_DEPRECATED_API
203 int step(
const char* str)
const;
228 int* encoded_length)
const;
271 if (cleaned != unichar_repr) {
274 int old_size =
size();
276 if (
size() == old_size) {
285 return unichar_id != INVALID_UNICHAR_ID && unichar_id < size_used &&
295 bool eq(
UNICHAR_ID unichar_id,
const char*
const unichar_repr)
const;
299 for (
int i = 0; i < size_used; ++i) {
300 delete unichars[i].properties.fragment;
301 unichars[i].properties.fragment =
nullptr;
307 if (script_table !=
nullptr) {
308 for (
int i = 0; i < script_table_size_used; ++i)
309 delete[] script_table[i];
310 delete[] script_table;
311 script_table =
nullptr;
312 script_table_size_used = 0;
314 if (unichars !=
nullptr) {
319 script_table_size_reserved = 0;
323 top_bottom_set_ =
false;
324 script_has_upper_lower_ =
false;
325 script_has_xheight_ =
false;
326 old_style_included_ =
false;
346 void reserve(
int unichars_number);
351 FILE*
file = fopen(filename,
"w+b");
352 if (
file ==
nullptr)
return false;
379 FILE*
file = fopen(filename,
"rb");
380 if (
file ==
nullptr)
return false;
418 const char* unblacklist);
422 unichars[unichar_id].properties.isalpha = value;
427 unichars[unichar_id].properties.islower = value;
432 unichars[unichar_id].properties.isupper = value;
437 unichars[unichar_id].properties.isdigit = value;
442 unichars[unichar_id].properties.ispunctuation = value;
447 unichars[unichar_id].properties.isngram = value;
453 unichars[unichar_id].properties.script_id =
add_script(value);
458 unichars[unichar_id].properties.other_case = other_case;
463 unichars[unichar_id].properties.direction = value;
468 unichars[unichar_id].properties.mirror = mirror;
473 unichars[unichar_id].properties.normed = normed;
474 unichars[unichar_id].properties.normed_ids.truncate(0);
482 if (INVALID_UNICHAR_ID == unichar_id)
return false;
484 return unichars[unichar_id].properties.isalpha;
489 if (INVALID_UNICHAR_ID == unichar_id)
return false;
491 return unichars[unichar_id].properties.islower;
496 if (INVALID_UNICHAR_ID == unichar_id)
return false;
498 return unichars[unichar_id].properties.isupper;
503 if (INVALID_UNICHAR_ID == unichar_id)
return false;
505 return unichars[unichar_id].properties.isdigit;
510 if (INVALID_UNICHAR_ID == unichar_id)
return false;
512 return unichars[unichar_id].properties.ispunctuation;
517 if (INVALID_UNICHAR_ID == unichar_id)
return false;
519 return unichars[unichar_id].properties.isngram;
528 return top_bottom_set_;
559 int* min_bottom,
int* max_bottom,
560 int* min_top,
int* max_top)
const {
561 if (INVALID_UNICHAR_ID == unichar_id) {
562 *min_bottom = *min_top = 0;
563 *max_bottom = *max_top = 256;
567 *min_bottom = unichars[unichar_id].properties.min_bottom;
568 *max_bottom = unichars[unichar_id].properties.max_bottom;
569 *min_top = unichars[unichar_id].properties.min_top;
570 *max_top = unichars[unichar_id].properties.max_top;
573 int min_bottom,
int max_bottom,
574 int min_top,
int max_top) {
575 unichars[unichar_id].properties.min_bottom =
576 ClipToRange<int>(min_bottom, 0, UINT8_MAX);
577 unichars[unichar_id].properties.max_bottom =
578 ClipToRange<int>(max_bottom, 0, UINT8_MAX);
579 unichars[unichar_id].properties.min_top =
580 ClipToRange<int>(min_top, 0, UINT8_MAX);
581 unichars[unichar_id].properties.max_top =
582 ClipToRange<int>(max_top, 0, UINT8_MAX);
587 float* width,
float* width_sd)
const {
588 if (INVALID_UNICHAR_ID == unichar_id) {
594 *width = unichars[unichar_id].properties.width;
595 *width_sd = unichars[unichar_id].properties.width_sd;
598 unichars[unichar_id].properties.width = width;
599 unichars[unichar_id].properties.width_sd = width_sd;
604 float* bearing,
float* bearing_sd)
const {
605 if (INVALID_UNICHAR_ID == unichar_id) {
606 *bearing = *bearing_sd = 0.0f;
610 *bearing = unichars[unichar_id].properties.bearing;
611 *bearing_sd = unichars[unichar_id].properties.bearing_sd;
614 float bearing,
float bearing_sd) {
615 unichars[unichar_id].properties.bearing = bearing;
616 unichars[unichar_id].properties.bearing_sd = bearing_sd;
621 float* advance,
float* advance_sd)
const {
622 if (INVALID_UNICHAR_ID == unichar_id) {
623 *advance = *advance_sd = 0;
627 *advance = unichars[unichar_id].properties.advance;
628 *advance_sd = unichars[unichar_id].properties.advance_sd;
631 float advance,
float advance_sd) {
632 unichars[unichar_id].properties.advance = advance;
633 unichars[unichar_id].properties.advance_sd = advance_sd;
637 return unichars[unichar_id].properties.AnyRangeEmpty();
643 if (INVALID_UNICHAR_ID == unichar_id)
return true;
645 return script_id != han_sid_ && script_id != thai_sid_ &&
646 script_id != hangul_sid_ && script_id != hiragana_sid_ &&
647 script_id != katakana_sid_;
654 if (INVALID_UNICHAR_ID == unichar_id)
return null_sid_;
656 return unichars[unichar_id].properties.script_id;
674 if (INVALID_UNICHAR_ID == unichar_id)
return INVALID_UNICHAR_ID;
676 return unichars[unichar_id].properties.other_case;
683 return unichars[unichar_id].properties.direction;
688 if (INVALID_UNICHAR_ID == unichar_id)
return INVALID_UNICHAR_ID;
690 return unichars[unichar_id].properties.mirror;
695 if (INVALID_UNICHAR_ID == unichar_id)
return INVALID_UNICHAR_ID;
697 if (unichars[unichar_id].properties.islower)
return unichar_id;
698 return unichars[unichar_id].properties.other_case;
703 if (INVALID_UNICHAR_ID == unichar_id)
return INVALID_UNICHAR_ID;
705 if (unichars[unichar_id].properties.isupper)
return unichar_id;
706 return unichars[unichar_id].properties.other_case;
725 if (INVALID_UNICHAR_ID == unichar_id)
return nullptr;
727 return unichars[unichar_id].properties.fragment;
775 if (unichar_repr ==
nullptr || unichar_repr[0] ==
'\0' ||
776 !ids.
contains(unichar_repr,
false)) {
820 return unichars[unichar_id].properties.normed.c_str();
826 return unichars[unichar_id].properties.normed_ids;
840 return script_table_size_used;
845 if (
id >= script_table_size_used ||
id < 0)
847 return script_table[id];
859 return script == null_script;
870 return unichars[unichar_id].properties.enabled;
888 return script_has_upper_lower_;
895 return script_has_xheight_;
900 struct UNICHAR_PROPERTIES {
901 UNICHAR_PROPERTIES();
906 void SetRangesOpen();
908 void SetRangesEmpty();
911 bool AnyRangeEmpty()
const;
913 void ExpandRangesFrom(
const UNICHAR_PROPERTIES& src);
915 void CopyFrom(
const UNICHAR_PROPERTIES& src);
962 struct UNICHAR_SLOT {
964 UNICHAR_PROPERTIES properties;
978 void encode_string(
const char* str,
int str_index,
int str_length,
981 int* best_total_length,
990 bool GetStrProperties(
const char* utf8_str,
991 UNICHAR_PROPERTIES* props)
const;
996 bool load_via_fgets(std::function<
char*(
char*,
int)> fgets_cb,
997 bool skip_fragments);
1002 static const char* kCleanupMaps[][2];
1003 static TESS_API const char* null_script;
1005 UNICHAR_SLOT* unichars;
1009 char** script_table;
1010 int script_table_size_used;
1011 int script_table_size_reserved;
1013 bool top_bottom_set_;
1015 bool script_has_upper_lower_;
1018 bool script_has_xheight_;
1020 bool old_style_included_;
1039 #endif // TESSERACT_CCUTIL_UNICHARSET_H_
bool load_from_file(const char *const filename, bool skip_fragments)
Direction get_direction(UNICHAR_ID unichar_id) const
void set_isupper(UNICHAR_ID unichar_id, bool value)
bool get_islower(UNICHAR_ID unichar_id) const
void AppendOtherUnicharset(const UNICHARSET &src)
bool contains_unichar_id(UNICHAR_ID unichar_id) const
static const int kMaxChunks
bool encode_string(const char *str, bool give_up_on_failure, GenericVector< UNICHAR_ID > *encoding, GenericVector< char > *lengths, int *encoded_length) const
void set_islower(UNICHAR_ID unichar_id, bool value)
const char * id_to_unichar_ext(UNICHAR_ID id) const
bool is_continuation_of(const CHAR_FRAGMENT *fragment) const
void unichar_insert(const char *const unichar_repr)
bool get_isdigit(UNICHAR_ID unichar_id) const
bool get_isalpha(UNICHAR_ID unichar_id) const
int get_script_id_from_name(const char *script_name) const
bool encodable_string(const char *str, int *first_bad_position) const
STRING debug_str(const char *unichar_repr) const
bool get_isalpha(const char *const unichar_repr) const
bool PropertiesIncomplete(UNICHAR_ID unichar_id) const
bool contains(const char *const unichar_repr, int length) const
void set_normed(UNICHAR_ID unichar_id, const char *normed)
const char * get_unichar() const
void set_direction(UNICHAR_ID unichar_id, UNICHARSET::Direction value)
void get_advance_stats(UNICHAR_ID unichar_id, float *advance, float *advance_sd) const
bool equals(const char *other_unichar, int other_pos, int other_total) const
const char * get_script_from_script_id(int id) const
bool is_null_script(const char *script) const
bool get_isngram(UNICHAR_ID unichar_id) const
const CHAR_FRAGMENT * get_fragment(const char *const unichar_repr) const
bool IsSpaceDelimited(UNICHAR_ID unichar_id) const
void set_normed_ids(UNICHAR_ID unichar_id)
void set_top_bottom(UNICHAR_ID unichar_id, int min_bottom, int max_bottom, int min_top, int max_top)
bool eq(UNICHAR_ID unichar_id, const char *const unichar_repr) const
void get_width_stats(UNICHAR_ID unichar_id, float *width, float *width_sd) const
int step(const char *str) const
const char * get_normed_unichar(UNICHAR_ID unichar_id) const
void set_bearing_stats(UNICHAR_ID unichar_id, float bearing, float bearing_sd)
bool get_isdigit(const char *const unichar_repr, int length) const
bool save_to_file(const char *const filename) const
void set_isalpha(UNICHAR_ID unichar_id, bool value)
int get_script(UNICHAR_ID unichar_id) const
static const TESS_API char * kCustomLigatures[][2]
bool get_ispunctuation(UNICHAR_ID unichar_id) const
void SetPropertiesFromOther(const UNICHARSET &src)
void set_width_stats(UNICHAR_ID unichar_id, float width, float width_sd)
bool get_islower(const char *const unichar_repr, int length) const
static CHAR_FRAGMENT * parse_from_string(const char *str)
bool major_right_to_left() const
int add_script(const char *script)
unsigned int get_properties(UNICHAR_ID unichar_id) const
void set_all(const char *unichar, int pos, int total, bool natural)
bool get_isupper(const char *const unichar_repr, int length) const
UNICHAR_ID to_lower(UNICHAR_ID unichar_id) const
STRING debug_str(UNICHAR_ID id) const
void set_advance_stats(UNICHAR_ID unichar_id, float advance, float advance_sd)
void set_black_and_whitelist(const char *blacklist, const char *whitelist, const char *unblacklist)
bool AnyRepeatedUnicodes() const
void get_top_bottom(UNICHAR_ID unichar_id, int *min_bottom, int *max_bottom, int *min_top, int *max_top) const
bool get_enabled(UNICHAR_ID unichar_id) const
void reserve(int unichars_number)
bool load_from_file(FILE *file)
bool get_isprivate(UNICHAR_ID unichar_id) const
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
bool save_to_file(tesseract::TFile *file) const
bool save_to_string(STRING *str) const
unsigned int get_properties(const char *const unichar_repr) const
void set_natural(bool value)
bool top_bottom_useful() const
bool script_has_xheight() const
char get_chartype(UNICHAR_ID unichar_id) const
void set_mirror(UNICHAR_ID unichar_id, UNICHAR_ID mirror)
bool get_ispunctuation(const char *const unichar_repr) const
bool script_has_upper_lower() const
UNICHAR_ID get_mirror(UNICHAR_ID unichar_id) const
UNICHAR_ID to_upper(UNICHAR_ID unichar_id) const
void set_script(UNICHAR_ID unichar_id, const char *value)
static std::string CleanupString(const char *utf8_str)
void set_ispunctuation(UNICHAR_ID unichar_id, bool value)
int get_script(const char *const unichar_repr) const
void unichar_insert_backwards_compatible(const char *const unichar_repr)
bool save_to_file(FILE *file) const
bool has_special_codes() const
static const TESS_API char * kSpecialUnicharCodes[SPECIAL_UNICHAR_CODES_COUNT]
void set_unichar(const char *uch)
int get_script_table_size() const
bool get_isdigit(const char *const unichar_repr) const
bool get_isupper(UNICHAR_ID unichar_id) const
bool equals(const CHAR_FRAGMENT *other) const
void PartialSetPropertiesFromOther(int start_index, const UNICHARSET &src)
bool get_isupper(const char *const unichar_repr) const
bool get_ispunctuation(const char *const unichar_repr, int length) const
void set_isngram(UNICHAR_ID unichar_id, bool value)
bool get_isalpha(const char *const unichar_repr, int length) const
bool contains_unichar(const char *const unichar_repr) const
void get_bearing_stats(UNICHAR_ID unichar_id, float *bearing, float *bearing_sd) const
char get_chartype(const char *const unichar_repr) const
const GenericVector< UNICHAR_ID > & normed_ids(UNICHAR_ID unichar_id) const
const CHAR_FRAGMENT * get_fragment(UNICHAR_ID unichar_id) const
bool SizesDistinct(UNICHAR_ID id1, UNICHAR_ID id2) const
const char * id_to_unichar(UNICHAR_ID id) const
UNICHAR_ID get_other_case(UNICHAR_ID unichar_id) const
bool load_from_file(const char *const filename)
bool is_beginning() const
static STRING debug_utf8_str(const char *str)
void set_isdigit(UNICHAR_ID unichar_id, bool value)
int get_script(const char *const unichar_repr, int length) const
bool Serialize(FILE *fp, const char *data, size_t n=1)
void set_other_case(UNICHAR_ID unichar_id, UNICHAR_ID other_case)
void unichar_insert(const char *const unichar_repr, OldUncleanUnichars old_style)
void ExpandRangesFromOther(const UNICHARSET &src)
void CopyFrom(const UNICHARSET &src)
bool get_islower(const char *const unichar_repr) const
void delete_pointers_in_unichars()