20 #ifndef TESSERACT_CCUTIL_UNICHARSET_H__ 21 #define TESSERACT_CCUTIL_UNICHARSET_H__ 52 inline void set_all(
const char *unichar,
int pos,
int total,
bool natural) {
62 inline void set_pos(
int p) { this->pos = p; }
64 inline const char*
get_unichar()
const {
return this->unichar; }
65 inline int get_pos()
const {
return this->pos; }
66 inline int get_total()
const {
return this->total; }
74 return to_string(unichar, pos, total, natural);
79 inline bool equals(
const char *other_unichar,
80 int other_pos,
int other_total)
const {
81 return (strcmp(this->unichar, other_unichar) == 0 &&
82 this->pos == other_pos && this->total == other_total);
93 return (strcmp(this->unichar, fragment->
get_unichar()) == 0 &&
95 this->pos == fragment->
get_pos() + 1);
102 inline bool is_ending()
const {
return this->pos == this->total-1; }
191 int step(
const char* str)
const;
213 int* encoded_length)
const;
242 return unichar_id != INVALID_UNICHAR_ID && unichar_id < size_used &&
252 bool eq(
UNICHAR_ID unichar_id,
const char*
const unichar_repr)
const;
256 for (
int i = 0; i < size_used; ++i) {
257 if (unichars[i].properties.fragment != NULL) {
258 delete unichars[i].properties.fragment;
259 unichars[i].properties.fragment = NULL;
266 if (script_table != NULL) {
267 for (
int i = 0; i < script_table_size_used; ++i)
268 delete[] script_table[i];
269 delete[] script_table;
271 script_table_size_used = 0;
273 if (unichars != NULL) {
278 script_table_size_reserved = 0;
282 top_bottom_set_ =
false;
283 script_has_upper_lower_ =
false;
284 script_has_xheight_ =
false;
302 void reserve(
int unichars_number);
307 FILE* file = fopen(
filename,
"w+b");
308 if (file == NULL)
return false;
319 if (fwrite(&str[0], str.
length(), 1, file) != 1)
return false;
325 if (file->
FWrite(&str[0], str.
length(), 1) != 1)
return false;
337 bool skip_fragments);
348 if (file == NULL)
return false;
386 const char* unblacklist);
390 unichars[unichar_id].properties.isalpha = value;
395 unichars[unichar_id].properties.islower = value;
400 unichars[unichar_id].properties.isupper = value;
405 unichars[unichar_id].properties.isdigit = value;
410 unichars[unichar_id].properties.ispunctuation = value;
415 unichars[unichar_id].properties.isngram = value;
421 unichars[unichar_id].properties.script_id =
add_script(value);
426 unichars[unichar_id].properties.other_case = other_case;
431 unichars[unichar_id].properties.direction = value;
436 unichars[unichar_id].properties.mirror = mirror;
441 unichars[unichar_id].properties.normed = normed;
442 unichars[unichar_id].properties.normed_ids.truncate(0);
450 if (INVALID_UNICHAR_ID == unichar_id)
return false;
452 return unichars[unichar_id].properties.isalpha;
457 if (INVALID_UNICHAR_ID == unichar_id)
return false;
459 return unichars[unichar_id].properties.islower;
464 if (INVALID_UNICHAR_ID == unichar_id)
return false;
466 return unichars[unichar_id].properties.isupper;
471 if (INVALID_UNICHAR_ID == unichar_id)
return false;
473 return unichars[unichar_id].properties.isdigit;
478 if (INVALID_UNICHAR_ID == unichar_id)
return false;
480 return unichars[unichar_id].properties.ispunctuation;
485 if (INVALID_UNICHAR_ID == unichar_id)
return false;
487 return unichars[unichar_id].properties.isngram;
496 return top_bottom_set_;
527 int* min_bottom,
int* max_bottom,
528 int* min_top,
int* max_top)
const {
529 if (INVALID_UNICHAR_ID == unichar_id) {
530 *min_bottom = *min_top = 0;
531 *max_bottom = *max_top = 256;
535 *min_bottom = unichars[unichar_id].properties.min_bottom;
536 *max_bottom = unichars[unichar_id].properties.max_bottom;
537 *min_top = unichars[unichar_id].properties.min_top;
538 *max_top = unichars[unichar_id].properties.max_top;
541 int min_bottom,
int max_bottom,
542 int min_top,
int max_top) {
543 unichars[unichar_id].properties.min_bottom =
545 unichars[unichar_id].properties.max_bottom =
547 unichars[unichar_id].properties.min_top =
549 unichars[unichar_id].properties.max_top =
555 float* width,
float* width_sd)
const {
556 if (INVALID_UNICHAR_ID == unichar_id) {
562 *width = unichars[unichar_id].properties.width;
563 *width_sd = unichars[unichar_id].properties.width_sd;
566 unichars[unichar_id].properties.width = width;
567 unichars[unichar_id].properties.width_sd = width_sd;
572 float* bearing,
float* bearing_sd)
const {
573 if (INVALID_UNICHAR_ID == unichar_id) {
574 *bearing = *bearing_sd = 0.0f;
578 *bearing = unichars[unichar_id].properties.bearing;
579 *bearing_sd = unichars[unichar_id].properties.bearing_sd;
582 float bearing,
float bearing_sd) {
583 unichars[unichar_id].properties.bearing = bearing;
584 unichars[unichar_id].properties.bearing_sd = bearing_sd;
589 float* advance,
float* advance_sd)
const {
590 if (INVALID_UNICHAR_ID == unichar_id) {
591 *advance = *advance_sd = 0;
595 *advance = unichars[unichar_id].properties.advance;
596 *advance_sd = unichars[unichar_id].properties.advance_sd;
599 float advance,
float advance_sd) {
600 unichars[unichar_id].properties.advance = advance;
601 unichars[unichar_id].properties.advance_sd = advance_sd;
605 return unichars[unichar_id].properties.AnyRangeEmpty();
612 if (INVALID_UNICHAR_ID == unichar_id)
return null_sid_;
614 return unichars[unichar_id].properties.script_id;
632 if (INVALID_UNICHAR_ID == unichar_id)
return INVALID_UNICHAR_ID;
634 return unichars[unichar_id].properties.other_case;
641 return unichars[unichar_id].properties.direction;
646 if (INVALID_UNICHAR_ID == unichar_id)
return INVALID_UNICHAR_ID;
648 return unichars[unichar_id].properties.mirror;
653 if (INVALID_UNICHAR_ID == unichar_id)
return INVALID_UNICHAR_ID;
655 if (unichars[unichar_id].properties.islower)
return unichar_id;
656 return unichars[unichar_id].properties.other_case;
661 if (INVALID_UNICHAR_ID == unichar_id)
return INVALID_UNICHAR_ID;
663 if (unichars[unichar_id].properties.isupper)
return unichar_id;
664 return unichars[unichar_id].properties.other_case;
683 if (INVALID_UNICHAR_ID == unichar_id)
return NULL;
685 return unichars[unichar_id].properties.fragment;
733 if (unichar_repr == NULL || unichar_repr[0] ==
'\0' ||
778 return unichars[unichar_id].properties.normed.string();
784 return unichars[unichar_id].properties.normed_ids;
798 return script_table_size_used;
803 if (
id >= script_table_size_used ||
id < 0)
805 return script_table[id];
817 return script == null_script;
827 return unichars[unichar_id].properties.enabled;
843 return script_has_upper_lower_;
850 return script_has_xheight_;
855 struct UNICHAR_PROPERTIES {
856 UNICHAR_PROPERTIES();
861 void SetRangesOpen();
863 void SetRangesEmpty();
866 bool AnyRangeEmpty()
const;
868 void ExpandRangesFrom(
const UNICHAR_PROPERTIES& src);
870 void CopyFrom(
const UNICHAR_PROPERTIES& src);
917 struct UNICHAR_SLOT {
919 UNICHAR_PROPERTIES properties;
933 void encode_string(
const char* str,
int str_index,
int str_length,
936 int* best_total_length,
945 bool GetStrProperties(
const char* utf8_str,
946 UNICHAR_PROPERTIES* props)
const;
952 bool skip_fragments);
954 UNICHAR_SLOT* unichars;
959 int script_table_size_used;
960 int script_table_size_reserved;
961 const char* null_script;
963 bool top_bottom_set_;
965 bool script_has_upper_lower_;
968 bool script_has_xheight_;
985 #endif // TESSERACT_CCUTIL_UNICHARSET_H__
void set_black_and_whitelist(const char *blacklist, const char *whitelist, const char *unblacklist)
bool is_null_script(const char *script) const
void SetPropertiesFromOther(const UNICHARSET &src)
void get_width_stats(UNICHAR_ID unichar_id, float *width, float *width_sd) const
bool eq(UNICHAR_ID unichar_id, const char *const unichar_repr) const
UNICHAR_ID to_upper(UNICHAR_ID unichar_id) const
bool get_isalpha(UNICHAR_ID unichar_id) const
int get_script_id_from_name(const char *script_name) const
void AppendOtherUnicharset(const UNICHARSET &src)
bool top_bottom_useful() const
bool get_ispunctuation(const char *const unichar_repr) const
bool TESS_API contains_unichar(const char *const unichar_repr) const
void set_islower(UNICHAR_ID unichar_id, bool value)
bool load_from_file(FILE *file)
int get_script_table_size() const
int FWrite(const void *buffer, int size, int count)
void reserve(int unichars_number)
void get_top_bottom(UNICHAR_ID unichar_id, int *min_bottom, int *max_bottom, int *min_top, int *max_top) const
void set_normed(UNICHAR_ID unichar_id, const char *normed)
UNICHAR_ID get_mirror(UNICHAR_ID unichar_id) const
Direction get_direction(UNICHAR_ID unichar_id) const
const char * get_normed_unichar(UNICHAR_ID unichar_id) const
bool load_from_file(const char *const filename)
const char * get_script_from_script_id(int id) const
void set_advance_stats(UNICHAR_ID unichar_id, float advance, float advance_sd)
bool encodable_string(const char *str, int *first_bad_position) const
bool get_isalpha(const char *const unichar_repr) const
bool save_to_file(const char *const filename) const
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
char get_chartype(UNICHAR_ID unichar_id) const
const char * id_to_unichar_ext(UNICHAR_ID id) const
bool is_continuation_of(const CHAR_FRAGMENT *fragment) const
void set_other_case(UNICHAR_ID unichar_id, UNICHAR_ID other_case)
UNICHAR_ID get_other_case(UNICHAR_ID unichar_id) const
bool get_isupper(const char *const unichar_repr) const
void PartialSetPropertiesFromOther(int start_index, const UNICHARSET &src)
bool get_ispunctuation(UNICHAR_ID unichar_id) const
bool load_from_inmemory_file(const char *const memory, int mem_size, bool skip_fragments)
bool has_special_codes() const
bool encode_string(const char *str, bool give_up_on_failure, GenericVector< UNICHAR_ID > *encoding, GenericVector< char > *lengths, int *encoded_length) const
bool AnyRepeatedUnicodes() const
void set_isdigit(UNICHAR_ID unichar_id, bool value)
bool get_isalpha(const char *const unichar_repr, int length) const
bool equals(const CHAR_FRAGMENT *other) const
STRING debug_str(const char *unichar_repr) const
void get_advance_stats(UNICHAR_ID unichar_id, float *advance, float *advance_sd) const
void set_isupper(UNICHAR_ID unichar_id, bool value)
bool get_islower(const char *const unichar_repr) const
bool get_isupper(const char *const unichar_repr, int length) const
unsigned int get_properties(UNICHAR_ID unichar_id) const
void set_mirror(UNICHAR_ID unichar_id, UNICHAR_ID mirror)
bool get_ispunctuation(const char *const unichar_repr, int length) const
bool equals(const char *other_unichar, int other_pos, int other_total) const
static const char * kSpecialUnicharCodes[SPECIAL_UNICHAR_CODES_COUNT]
bool get_isdigit(const char *const unichar_repr) const
void set_unichar(const char *uch)
bool major_right_to_left() const
void set_width_stats(UNICHAR_ID unichar_id, float width, float width_sd)
const char * get_unichar() const
bool get_isdigit(const char *const unichar_repr, int length) const
bool get_isupper(UNICHAR_ID unichar_id) const
bool TESS_API save_to_string(STRING *str) const
int get_script(const char *const unichar_repr) const
void set_bearing_stats(UNICHAR_ID unichar_id, float bearing, float bearing_sd)
static TESS_API const char * kCustomLigatures[][2]
STRING debug_str(UNICHAR_ID id) const
bool save_to_file(FILE *file) const
unsigned int get_properties(const char *const unichar_repr) const
void delete_pointers_in_unichars()
void set_direction(UNICHAR_ID unichar_id, UNICHARSET::Direction value)
bool contains(const char *const unichar_repr) const
bool load_from_file(const char *const filename, bool skip_fragments)
void get_bearing_stats(UNICHAR_ID unichar_id, float *bearing, float *bearing_sd) const
void TESS_API unichar_insert(const char *const unichar_repr)
int direction(EDGEPT *point)
int get_script(UNICHAR_ID unichar_id) const
UNICHAR_ID TESS_API unichar_to_id(const char *const unichar_repr) const
const GenericVector< UNICHAR_ID > & normed_ids(UNICHAR_ID unichar_id) const
void set_isalpha(UNICHAR_ID unichar_id, bool value)
void set_normed_ids(UNICHAR_ID unichar_id)
void set_natural(bool value)
void CopyFrom(const UNICHARSET &src)
static STRING debug_utf8_str(const char *str)
bool get_isngram(UNICHAR_ID unichar_id) const
bool is_beginning() const
bool contains_unichar_id(UNICHAR_ID unichar_id) const
void set_all(const char *unichar, int pos, int total, bool natural)
bool PropertiesIncomplete(UNICHAR_ID unichar_id) const
bool get_islower(const char *const unichar_repr, int length) const
int add_script(const char *script)
bool script_has_xheight() const
bool get_isdigit(UNICHAR_ID unichar_id) const
bool get_islower(UNICHAR_ID unichar_id) const
void set_isngram(UNICHAR_ID unichar_id, bool value)
bool load_from_inmemory_file(const char *const memory, int mem_size)
bool script_has_upper_lower() const
void ExpandRangesFromOther(const UNICHARSET &src)
const char * id_to_unichar(UNICHAR_ID id) const
bool get_enabled(UNICHAR_ID unichar_id) const
static const int kMaxChunks
char get_chartype(const char *const unichar_repr) const
void set_ispunctuation(UNICHAR_ID unichar_id, bool value)
UNICHAR_ID to_lower(UNICHAR_ID unichar_id) const
int get_script(const char *const unichar_repr, int length) const
const CHAR_FRAGMENT * get_fragment(UNICHAR_ID unichar_id) const
static CHAR_FRAGMENT * parse_from_string(const char *str)
int step(const char *str) const
const CHAR_FRAGMENT * get_fragment(const char *const unichar_repr) const
void set_script(UNICHAR_ID unichar_id, const char *value)
bool SizesDistinct(UNICHAR_ID id1, UNICHAR_ID id2) const
bool save_to_file(tesseract::TFile *file) const
void set_top_bottom(UNICHAR_ID unichar_id, int min_bottom, int max_bottom, int min_top, int max_top)
bool get_isprivate(UNICHAR_ID unichar_id) const