All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
UNICHARSET Class Reference

#include <unicharset.h>

Public Types

enum  Direction {
  U_LEFT_TO_RIGHT = 0, U_RIGHT_TO_LEFT = 1, U_EUROPEAN_NUMBER = 2, U_EUROPEAN_NUMBER_SEPARATOR = 3,
  U_EUROPEAN_NUMBER_TERMINATOR = 4, U_ARABIC_NUMBER = 5, U_COMMON_NUMBER_SEPARATOR = 6, U_BLOCK_SEPARATOR = 7,
  U_SEGMENT_SEPARATOR = 8, U_WHITE_SPACE_NEUTRAL = 9, U_OTHER_NEUTRAL = 10, U_LEFT_TO_RIGHT_EMBEDDING = 11,
  U_LEFT_TO_RIGHT_OVERRIDE = 12, U_RIGHT_TO_LEFT_ARABIC = 13, U_RIGHT_TO_LEFT_EMBEDDING = 14, U_RIGHT_TO_LEFT_OVERRIDE = 15,
  U_POP_DIRECTIONAL_FORMAT = 16, U_DIR_NON_SPACING_MARK = 17, U_BOUNDARY_NEUTRAL = 18, U_CHAR_DIRECTION_COUNT
}
 

Public Member Functions

 UNICHARSET ()
 
 ~UNICHARSET ()
 
const UNICHAR_ID unichar_to_id (const char *const unichar_repr) const
 
const UNICHAR_ID unichar_to_id (const char *const unichar_repr, int length) const
 
int step (const char *str) const
 
bool encodable_string (const char *str, int *first_bad_position) const
 
bool encode_string (const char *str, bool give_up_on_failure, GenericVector< UNICHAR_ID > *encoding, GenericVector< char > *lengths, int *encoded_length) const
 
const char *const id_to_unichar (UNICHAR_ID id) const
 
const char *const id_to_unichar_ext (UNICHAR_ID id) const
 
STRING debug_str (UNICHAR_ID id) const
 
STRING debug_str (const char *unichar_repr) const
 
void unichar_insert (const char *const unichar_repr)
 
bool contains_unichar_id (UNICHAR_ID unichar_id) const
 
bool contains_unichar (const char *const unichar_repr) const
 
bool contains_unichar (const char *const unichar_repr, int length) const
 
bool eq (UNICHAR_ID unichar_id, const char *const unichar_repr) const
 
void delete_pointers_in_unichars ()
 
void clear ()
 
int size () const
 
void reserve (int unichars_number)
 
bool save_to_file (const char *const filename) const
 
bool save_to_file (FILE *file) const
 
bool save_to_file (tesseract::TFile *file) const
 
bool save_to_string (STRING *str) const
 
bool load_from_inmemory_file (const char *const memory, int mem_size, bool skip_fragments)
 
bool load_from_inmemory_file (const char *const memory, int mem_size)
 
bool load_from_file (const char *const filename, bool skip_fragments)
 
bool load_from_file (const char *const filename)
 
bool load_from_file (FILE *file, bool skip_fragments)
 
bool load_from_file (FILE *file)
 
bool load_from_file (tesseract::TFile *file, bool skip_fragments)
 
void post_load_setup ()
 
bool major_right_to_left () const
 
void set_black_and_whitelist (const char *blacklist, const char *whitelist, const char *unblacklist)
 
void set_isalpha (UNICHAR_ID unichar_id, bool value)
 
void set_islower (UNICHAR_ID unichar_id, bool value)
 
void set_isupper (UNICHAR_ID unichar_id, bool value)
 
void set_isdigit (UNICHAR_ID unichar_id, bool value)
 
void set_ispunctuation (UNICHAR_ID unichar_id, bool value)
 
void set_isngram (UNICHAR_ID unichar_id, bool value)
 
void set_script (UNICHAR_ID unichar_id, const char *value)
 
void set_other_case (UNICHAR_ID unichar_id, UNICHAR_ID other_case)
 
void set_direction (UNICHAR_ID unichar_id, UNICHARSET::Direction value)
 
void set_mirror (UNICHAR_ID unichar_id, UNICHAR_ID mirror)
 
void set_normed (UNICHAR_ID unichar_id, const char *normed)
 
void set_normed_ids (UNICHAR_ID unichar_id)
 
bool get_isalpha (UNICHAR_ID unichar_id) const
 
bool get_islower (UNICHAR_ID unichar_id) const
 
bool get_isupper (UNICHAR_ID unichar_id) const
 
bool get_isdigit (UNICHAR_ID unichar_id) const
 
bool get_ispunctuation (UNICHAR_ID unichar_id) const
 
bool get_isngram (UNICHAR_ID unichar_id) const
 
bool get_isprivate (UNICHAR_ID unichar_id) const
 
bool top_bottom_useful () const
 
void set_ranges_empty ()
 
void SetPropertiesFromOther (const UNICHARSET &src)
 
void PartialSetPropertiesFromOther (int start_index, const UNICHARSET &src)
 
void ExpandRangesFromOther (const UNICHARSET &src)
 
void CopyFrom (const UNICHARSET &src)
 
void AppendOtherUnicharset (const UNICHARSET &src)
 
bool SizesDistinct (UNICHAR_ID id1, UNICHAR_ID id2) const
 
void get_top_bottom (UNICHAR_ID unichar_id, int *min_bottom, int *max_bottom, int *min_top, int *max_top) const
 
void set_top_bottom (UNICHAR_ID unichar_id, int min_bottom, int max_bottom, int min_top, int max_top)
 
void get_width_stats (UNICHAR_ID unichar_id, float *width, float *width_sd) const
 
void set_width_stats (UNICHAR_ID unichar_id, float width, float width_sd)
 
void get_bearing_stats (UNICHAR_ID unichar_id, float *bearing, float *bearing_sd) const
 
void set_bearing_stats (UNICHAR_ID unichar_id, float bearing, float bearing_sd)
 
void get_advance_stats (UNICHAR_ID unichar_id, float *advance, float *advance_sd) const
 
void set_advance_stats (UNICHAR_ID unichar_id, float advance, float advance_sd)
 
bool PropertiesIncomplete (UNICHAR_ID unichar_id) const
 
int get_script (UNICHAR_ID unichar_id) const
 
unsigned int get_properties (UNICHAR_ID unichar_id) const
 
char get_chartype (UNICHAR_ID unichar_id) const
 
UNICHAR_ID get_other_case (UNICHAR_ID unichar_id) const
 
Direction get_direction (UNICHAR_ID unichar_id) const
 
UNICHAR_ID get_mirror (UNICHAR_ID unichar_id) const
 
UNICHAR_ID to_lower (UNICHAR_ID unichar_id) const
 
UNICHAR_ID to_upper (UNICHAR_ID unichar_id) const
 
bool has_special_codes () const
 
bool AnyRepeatedUnicodes () const
 
const CHAR_FRAGMENTget_fragment (UNICHAR_ID unichar_id) const
 
bool get_isalpha (const char *const unichar_repr) const
 
bool get_islower (const char *const unichar_repr) const
 
bool get_isupper (const char *const unichar_repr) const
 
bool get_isdigit (const char *const unichar_repr) const
 
bool get_ispunctuation (const char *const unichar_repr) const
 
unsigned int get_properties (const char *const unichar_repr) const
 
char get_chartype (const char *const unichar_repr) const
 
int get_script (const char *const unichar_repr) const
 
const CHAR_FRAGMENTget_fragment (const char *const unichar_repr) const
 
bool get_isalpha (const char *const unichar_repr, int length) const
 
bool get_islower (const char *const unichar_repr, int length) const
 
bool get_isupper (const char *const unichar_repr, int length) const
 
bool get_isdigit (const char *const unichar_repr, int length) const
 
bool get_ispunctuation (const char *const unichar_repr, int length) const
 
const char * get_normed_unichar (UNICHAR_ID unichar_id) const
 
const GenericVector< UNICHAR_ID > & normed_ids (UNICHAR_ID unichar_id) const
 
int get_script (const char *const unichar_repr, int length) const
 
int get_script_table_size () const
 
const char * get_script_from_script_id (int id) const
 
int get_script_id_from_name (const char *script_name) const
 
bool is_null_script (const char *script) const
 
int add_script (const char *script)
 
bool get_enabled (UNICHAR_ID unichar_id) const
 
int null_sid () const
 
int common_sid () const
 
int latin_sid () const
 
int cyrillic_sid () const
 
int greek_sid () const
 
int han_sid () const
 
int hiragana_sid () const
 
int katakana_sid () const
 
int default_sid () const
 
bool script_has_upper_lower () const
 
bool script_has_xheight () const
 

Static Public Member Functions

static STRING debug_utf8_str (const char *str)
 

Static Public Attributes

static const char * kCustomLigatures [][2]
 
static const char * kSpecialUnicharCodes [SPECIAL_UNICHAR_CODES_COUNT]
 

Detailed Description

Definition at line 139 of file unicharset.h.

Member Enumeration Documentation

Enumerator
U_LEFT_TO_RIGHT 
U_RIGHT_TO_LEFT 
U_EUROPEAN_NUMBER 
U_EUROPEAN_NUMBER_SEPARATOR 
U_EUROPEAN_NUMBER_TERMINATOR 
U_ARABIC_NUMBER 
U_COMMON_NUMBER_SEPARATOR 
U_BLOCK_SEPARATOR 
U_SEGMENT_SEPARATOR 
U_WHITE_SPACE_NEUTRAL 
U_OTHER_NEUTRAL 
U_LEFT_TO_RIGHT_EMBEDDING 
U_LEFT_TO_RIGHT_OVERRIDE 
U_RIGHT_TO_LEFT_ARABIC 
U_RIGHT_TO_LEFT_EMBEDDING 
U_RIGHT_TO_LEFT_OVERRIDE 
U_POP_DIRECTIONAL_FORMAT 
U_DIR_NON_SPACING_MARK 
U_BOUNDARY_NEUTRAL 
U_CHAR_DIRECTION_COUNT 

Definition at line 150 of file unicharset.h.

150  {
151  U_LEFT_TO_RIGHT = 0,
152  U_RIGHT_TO_LEFT = 1,
153  U_EUROPEAN_NUMBER = 2,
156  U_ARABIC_NUMBER = 5,
158  U_BLOCK_SEPARATOR = 7,
161  U_OTHER_NEUTRAL = 10,
169  U_BOUNDARY_NEUTRAL = 18,
171  };

Constructor & Destructor Documentation

UNICHARSET::UNICHARSET ( )

Definition at line 159 of file unicharset.cpp.

159  :
160  unichars(NULL),
161  ids(),
162  size_used(0),
163  size_reserved(0),
164  script_table(NULL),
165  script_table_size_used(0),
166  null_script("NULL") {
167  clear();
168  for (int i = 0; i < SPECIAL_UNICHAR_CODES_COUNT; ++i) {
170  if (i == UNICHAR_JOINED)
171  set_isngram(i, true);
172  }
173 }
void set_isngram(UNICHAR_ID unichar_id, bool value)
Definition: unicharset.h:414
static const char * kSpecialUnicharCodes[SPECIAL_UNICHAR_CODES_COUNT]
Definition: unicharset.h:147
void unichar_insert(const char *const unichar_repr)
Definition: unicharset.cpp:612
#define NULL
Definition: host.h:144
void clear()
Definition: unicharset.h:266
UNICHARSET::~UNICHARSET ( )

Definition at line 175 of file unicharset.cpp.

175  {
176  clear();
177 }
void clear()
Definition: unicharset.h:266

Member Function Documentation

int UNICHARSET::add_script ( const char *  script)

Definition at line 1002 of file unicharset.cpp.

1002  {
1003  for (int i = 0; i < script_table_size_used; ++i) {
1004  if (strcmp(script, script_table[i]) == 0)
1005  return i;
1006  }
1007  if (script_table_size_reserved == 0) {
1008  script_table_size_reserved = 8;
1009  script_table = new char*[script_table_size_reserved];
1010  }
1011  if (script_table_size_used + 1 >= script_table_size_reserved) {
1012  char** new_script_table = new char*[script_table_size_reserved * 2];
1013  memcpy(new_script_table, script_table, script_table_size_reserved * sizeof(char*));
1014  delete[] script_table;
1015  script_table = new_script_table;
1016  script_table_size_reserved = 2 * script_table_size_reserved;
1017  }
1018  script_table[script_table_size_used] = new char[strlen(script) + 1];
1019  strcpy(script_table[script_table_size_used], script);
1020  return script_table_size_used++;
1021 }
bool UNICHARSET::AnyRepeatedUnicodes ( ) const

Definition at line 986 of file unicharset.cpp.

986  {
987  int start_id = 0;
989  for (int id = start_id; id < size_used; ++id) {
990  // Convert to unicodes.
991  GenericVector<int> unicodes;
992  if (UNICHAR::UTF8ToUnicode(get_normed_unichar(id), &unicodes) &&
993  unicodes.size() > 1) {
994  for (int u = 1; u < unicodes.size(); ++u) {
995  if (unicodes[u - 1] == unicodes[u]) return true;
996  }
997  }
998  }
999  return false;
1000 }
int size() const
Definition: genericvector.h:72
static bool UTF8ToUnicode(const char *utf8_str, GenericVector< int > *unicodes)
Definition: unichar.cpp:211
bool has_special_codes() const
Definition: unicharset.h:670
const char * get_normed_unichar(UNICHAR_ID unichar_id) const
Definition: unicharset.h:776
void UNICHARSET::AppendOtherUnicharset ( const UNICHARSET src)

Definition at line 439 of file unicharset.cpp.

439  {
440  int initial_used = size_used;
441  for (int ch = 0; ch < src.size_used; ++ch) {
442  const UNICHAR_PROPERTIES& src_props = src.unichars[ch].properties;
443  const char* utf8 = src.id_to_unichar(ch);
444  if (ch >= SPECIAL_UNICHAR_CODES_COUNT && src_props.AnyRangeEmpty()) {
445  // Only use fully valid entries.
446  tprintf("Bad properties for index %d, char %s: "
447  "%d,%d %d,%d %g,%g %g,%g %g,%g\n",
448  ch, utf8, src_props.min_bottom, src_props.max_bottom,
449  src_props.min_top, src_props.max_top,
450  src_props.width, src_props.width_sd,
451  src_props.bearing, src_props.bearing_sd,
452  src_props.advance, src_props.advance_sd);
453  continue;
454  }
455  int id = size_used;
456  if (contains_unichar(utf8)) {
457  id = unichar_to_id(utf8);
458  // Just expand current ranges.
459  unichars[id].properties.ExpandRangesFrom(src_props);
460  } else {
461  unichar_insert(utf8);
462  unichars[id].properties.SetRangesEmpty();
463  }
464  }
465  // Set properties, including mirror and other_case, WITHOUT reordering
466  // the unicharset.
467  PartialSetPropertiesFromOther(initial_used, src);
468 }
const UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
#define tprintf(...)
Definition: tprintf.h:31
const char *const id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:266
void unichar_insert(const char *const unichar_repr)
Definition: unicharset.cpp:612
void PartialSetPropertiesFromOther(int start_index, const UNICHARSET &src)
Definition: unicharset.cpp:380
bool contains_unichar(const char *const unichar_repr) const
Definition: unicharset.cpp:644
void UNICHARSET::clear ( )
inline

Definition at line 266 of file unicharset.h.

266  {
267  if (script_table != NULL) {
268  for (int i = 0; i < script_table_size_used; ++i)
269  delete[] script_table[i];
270  delete[] script_table;
271  script_table = NULL;
272  script_table_size_used = 0;
273  }
274  if (unichars != NULL) {
276  delete[] unichars;
277  unichars = NULL;
278  }
279  script_table_size_reserved = 0;
280  size_reserved = 0;
281  size_used = 0;
282  ids.clear();
283  top_bottom_set_ = false;
284  script_has_upper_lower_ = false;
285  script_has_xheight_ = false;
286  null_sid_ = 0;
287  common_sid_ = 0;
288  latin_sid_ = 0;
289  cyrillic_sid_ = 0;
290  greek_sid_ = 0;
291  han_sid_ = 0;
292  hiragana_sid_ = 0;
293  katakana_sid_ = 0;
294  }
void clear()
Definition: unicharmap.cpp:154
void delete_pointers_in_unichars()
Definition: unicharset.h:256
#define NULL
Definition: host.h:144
int UNICHARSET::common_sid ( ) const
inline

Definition at line 832 of file unicharset.h.

832 { return common_sid_; }
bool UNICHARSET::contains_unichar ( const char *const  unichar_repr) const

Definition at line 644 of file unicharset.cpp.

644  {
645  return ids.contains(unichar_repr);
646 }
bool contains(const char *const unichar_repr) const
Definition: unicharmap.cpp:101
bool UNICHARSET::contains_unichar ( const char *const  unichar_repr,
int  length 
) const

Definition at line 648 of file unicharset.cpp.

649  {
650  if (length == 0) {
651  return false;
652  }
653  return ids.contains(unichar_repr, length);
654 }
bool contains(const char *const unichar_repr) const
Definition: unicharmap.cpp:101
bool UNICHARSET::contains_unichar_id ( UNICHAR_ID  unichar_id) const
inline

Definition at line 242 of file unicharset.h.

242  {
243  return unichar_id != INVALID_UNICHAR_ID && unichar_id < size_used &&
244  unichar_id >= 0;
245  }
void UNICHARSET::CopyFrom ( const UNICHARSET src)

Definition at line 423 of file unicharset.cpp.

423  {
424  clear();
425  for (int ch = 0; ch < src.size_used; ++ch) {
426  const UNICHAR_PROPERTIES& src_props = src.unichars[ch].properties;
427  const char* utf8 = src.id_to_unichar(ch);
428  unichar_insert(utf8);
429  unichars[ch].properties.ExpandRangesFrom(src_props);
430  }
431  // Set properties, including mirror and other_case, WITHOUT reordering
432  // the unicharset.
434 }
const char *const id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:266
void unichar_insert(const char *const unichar_repr)
Definition: unicharset.cpp:612
void PartialSetPropertiesFromOther(int start_index, const UNICHARSET &src)
Definition: unicharset.cpp:380
void clear()
Definition: unicharset.h:266
int UNICHARSET::cyrillic_sid ( ) const
inline

Definition at line 834 of file unicharset.h.

834 { return cyrillic_sid_; }
STRING UNICHARSET::debug_str ( UNICHAR_ID  id) const

Definition at line 318 of file unicharset.cpp.

318  {
319  if (id == INVALID_UNICHAR_ID) return STRING(id_to_unichar(id));
320  const CHAR_FRAGMENT *fragment = this->get_fragment(id);
321  if (fragment) {
322  return fragment->to_string();
323  }
324  const char* str = id_to_unichar(id);
325  STRING result = debug_utf8_str(str);
326  // Append a for lower alpha, A for upper alpha, and x if alpha but neither.
327  if (get_isalpha(id)) {
328  if (get_islower(id))
329  result += "a";
330  else if (get_isupper(id))
331  result += "A";
332  else
333  result += "x";
334  }
335  // Append 0 if a digit.
336  if (get_isdigit(id)) {
337  result += "0";
338  }
339  // Append p is a punctuation symbol.
340  if (get_ispunctuation(id)) {
341  result += "p";
342  }
343  return result;
344 }
bool get_isupper(UNICHAR_ID unichar_id) const
Definition: unicharset.h:463
const CHAR_FRAGMENT * get_fragment(UNICHAR_ID unichar_id) const
Definition: unicharset.h:682
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:470
const char *const id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:266
static STRING debug_utf8_str(const char *str)
Definition: unicharset.cpp:294
bool get_islower(UNICHAR_ID unichar_id) const
Definition: unicharset.h:456
bool get_ispunctuation(UNICHAR_ID unichar_id) const
Definition: unicharset.h:477
static STRING to_string(const char *unichar, int pos, int total, bool natural)
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:449
Definition: strngs.h:44
STRING UNICHARSET::debug_str ( const char *  unichar_repr) const
inline

Definition at line 233 of file unicharset.h.

233  {
234  return debug_str(unichar_to_id(unichar_repr));
235  }
STRING debug_str(UNICHAR_ID id) const
Definition: unicharset.cpp:318
const UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
STRING UNICHARSET::debug_utf8_str ( const char *  str)
static

Definition at line 294 of file unicharset.cpp.

294  {
295  STRING result = str;
296  result += " [";
297  int step = 1;
298  // Chop into unicodes and code each as hex.
299  for (int i = 0; str[i] != '\0'; i += step) {
300  char hex[sizeof(int) * 2 + 1];
301  step = UNICHAR::utf8_step(str + i);
302  if (step == 0) {
303  step = 1;
304  sprintf(hex, "%x", str[i]);
305  } else {
306  UNICHAR ch(str + i, step);
307  sprintf(hex, "%x", ch.first_uni());
308  }
309  result += hex;
310  result += " ";
311  }
312  result += "]";
313  return result;
314 }
static int utf8_step(const char *utf8_str)
Definition: unichar.cpp:134
int step(const char *str) const
Definition: unicharset.cpp:211
Definition: strngs.h:44
int UNICHARSET::default_sid ( ) const
inline

Definition at line 839 of file unicharset.h.

839 { return default_sid_; }
void UNICHARSET::delete_pointers_in_unichars ( )
inline

Definition at line 256 of file unicharset.h.

256  {
257  for (int i = 0; i < size_used; ++i) {
258  if (unichars[i].properties.fragment != NULL) {
259  delete unichars[i].properties.fragment;
260  unichars[i].properties.fragment = NULL;
261  }
262  }
263  }
#define NULL
Definition: host.h:144
bool UNICHARSET::encodable_string ( const char *  str,
int *  first_bad_position 
) const

Definition at line 222 of file unicharset.cpp.

223  {
224  GenericVector<UNICHAR_ID> encoding;
225  return encode_string(str, true, &encoding, NULL, first_bad_position);
226 }
bool encode_string(const char *str, bool give_up_on_failure, GenericVector< UNICHAR_ID > *encoding, GenericVector< char > *lengths, int *encoded_length) const
Definition: unicharset.cpp:234
#define NULL
Definition: host.h:144
bool UNICHARSET::encode_string ( const char *  str,
bool  give_up_on_failure,
GenericVector< UNICHAR_ID > *  encoding,
GenericVector< char > *  lengths,
int *  encoded_length 
) const

Definition at line 234 of file unicharset.cpp.

237  {
238  GenericVector<UNICHAR_ID> working_encoding;
239  GenericVector<char> working_lengths;
240  GenericVector<char> best_lengths;
241  encoding->truncate(0); // Just in case str is empty.
242  int str_length = strlen(str);
243  int str_pos = 0;
244  bool perfect = true;
245  while (str_pos < str_length) {
246  encode_string(str, str_pos, str_length, &working_encoding, &working_lengths,
247  &str_pos, encoding, &best_lengths);
248  if (str_pos < str_length) {
249  // This is a non-match. Skip one utf-8 character.
250  perfect = false;
251  if (give_up_on_failure) break;
252  int step = UNICHAR::utf8_step(str + str_pos);
253  if (step == 0) step = 1;
254  encoding->push_back(INVALID_UNICHAR_ID);
255  best_lengths.push_back(step);
256  str_pos += step;
257  working_encoding = *encoding;
258  working_lengths = best_lengths;
259  }
260  }
261  if (lengths != NULL) *lengths = best_lengths;
262  if (encoded_length != NULL) *encoded_length = str_pos;
263  return perfect;
264 }
void truncate(int size)
int push_back(T object)
static int utf8_step(const char *utf8_str)
Definition: unichar.cpp:134
bool encode_string(const char *str, bool give_up_on_failure, GenericVector< UNICHAR_ID > *encoding, GenericVector< char > *lengths, int *encoded_length) const
Definition: unicharset.cpp:234
int step(const char *str) const
Definition: unicharset.cpp:211
#define NULL
Definition: host.h:144
bool UNICHARSET::eq ( UNICHAR_ID  unichar_id,
const char *const  unichar_repr 
) const

Definition at line 656 of file unicharset.cpp.

657  {
658  return strcmp(this->id_to_unichar(unichar_id), unichar_repr) == 0;
659 }
const char *const id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:266
void UNICHARSET::ExpandRangesFromOther ( const UNICHARSET src)

Definition at line 410 of file unicharset.cpp.

410  {
411  for (int ch = 0; ch < size_used; ++ch) {
412  const char* utf8 = id_to_unichar(ch);
413  UNICHAR_PROPERTIES properties;
414  if (src.GetStrProperties(utf8, &properties)) {
415  // Expand just the ranges from properties.
416  unichars[ch].properties.ExpandRangesFrom(properties);
417  }
418  }
419 }
const char *const id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:266
void UNICHARSET::get_advance_stats ( UNICHAR_ID  unichar_id,
float *  advance,
float *  advance_sd 
) const
inline

Definition at line 588 of file unicharset.h.

589  {
590  if (INVALID_UNICHAR_ID == unichar_id) {
591  *advance = *advance_sd = 0;
592  return;
593  }
594  ASSERT_HOST(contains_unichar_id(unichar_id));
595  *advance = unichars[unichar_id].properties.advance;
596  *advance_sd = unichars[unichar_id].properties.advance_sd;
597  }
#define ASSERT_HOST(x)
Definition: errcode.h:84
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:242
void UNICHARSET::get_bearing_stats ( UNICHAR_ID  unichar_id,
float *  bearing,
float *  bearing_sd 
) const
inline

Definition at line 571 of file unicharset.h.

572  {
573  if (INVALID_UNICHAR_ID == unichar_id) {
574  *bearing = *bearing_sd = 0.0f;
575  return;
576  }
577  ASSERT_HOST(contains_unichar_id(unichar_id));
578  *bearing = unichars[unichar_id].properties.bearing;
579  *bearing_sd = unichars[unichar_id].properties.bearing_sd;
580  }
#define ASSERT_HOST(x)
Definition: errcode.h:84
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:242
char UNICHARSET::get_chartype ( UNICHAR_ID  unichar_id) const

Definition at line 603 of file unicharset.cpp.

603  {
604  if (this->get_isupper(id)) return 'A';
605  if (this->get_islower(id)) return 'a';
606  if (this->get_isalpha(id)) return 'x';
607  if (this->get_isdigit(id)) return '0';
608  if (this->get_ispunctuation(id)) return 'p';
609  return 0;
610 }
bool get_isupper(UNICHAR_ID unichar_id) const
Definition: unicharset.h:463
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:470
bool get_islower(UNICHAR_ID unichar_id) const
Definition: unicharset.h:456
bool get_ispunctuation(UNICHAR_ID unichar_id) const
Definition: unicharset.h:477
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:449
char UNICHARSET::get_chartype ( const char *const  unichar_repr) const
inline

Definition at line 719 of file unicharset.h.

719  {
720  return get_chartype(unichar_to_id(unichar_repr));
721  }
const UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
char get_chartype(UNICHAR_ID unichar_id) const
Definition: unicharset.cpp:603
Direction UNICHARSET::get_direction ( UNICHAR_ID  unichar_id) const
inline

Definition at line 638 of file unicharset.h.

638  {
639  if (INVALID_UNICHAR_ID == unichar_id) return UNICHARSET::U_OTHER_NEUTRAL;
640  ASSERT_HOST(contains_unichar_id(unichar_id));
641  return unichars[unichar_id].properties.direction;
642  }
#define ASSERT_HOST(x)
Definition: errcode.h:84
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:242
bool UNICHARSET::get_enabled ( UNICHAR_ID  unichar_id) const
inline

Definition at line 826 of file unicharset.h.

826  {
827  return unichars[unichar_id].properties.enabled;
828  }
const CHAR_FRAGMENT* UNICHARSET::get_fragment ( UNICHAR_ID  unichar_id) const
inline

Definition at line 682 of file unicharset.h.

682  {
683  if (INVALID_UNICHAR_ID == unichar_id) return NULL;
684  ASSERT_HOST(contains_unichar_id(unichar_id));
685  return unichars[unichar_id].properties.fragment;
686  }
#define ASSERT_HOST(x)
Definition: errcode.h:84
#define NULL
Definition: host.h:144
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:242
const CHAR_FRAGMENT* UNICHARSET::get_fragment ( const char *const  unichar_repr) const
inline

Definition at line 732 of file unicharset.h.

732  {
733  if (unichar_repr == NULL || unichar_repr[0] == '\0' ||
734  !ids.contains(unichar_repr)) {
735  return NULL;
736  }
737  return get_fragment(unichar_to_id(unichar_repr));
738  }
const UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
const CHAR_FRAGMENT * get_fragment(UNICHAR_ID unichar_id) const
Definition: unicharset.h:682
bool contains(const char *const unichar_repr) const
Definition: unicharmap.cpp:101
#define NULL
Definition: host.h:144
bool UNICHARSET::get_isalpha ( UNICHAR_ID  unichar_id) const
inline

Definition at line 449 of file unicharset.h.

449  {
450  if (INVALID_UNICHAR_ID == unichar_id) return false;
451  ASSERT_HOST(contains_unichar_id(unichar_id));
452  return unichars[unichar_id].properties.isalpha;
453  }
#define ASSERT_HOST(x)
Definition: errcode.h:84
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:242
bool UNICHARSET::get_isalpha ( const char *const  unichar_repr) const
inline

Definition at line 689 of file unicharset.h.

689  {
690  return get_isalpha(unichar_to_id(unichar_repr));
691  }
const UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:449
bool UNICHARSET::get_isalpha ( const char *const  unichar_repr,
int  length 
) const
inline

Definition at line 742 of file unicharset.h.

743  {
744  return get_isalpha(unichar_to_id(unichar_repr, length));
745  }
const UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:449
bool UNICHARSET::get_isdigit ( UNICHAR_ID  unichar_id) const
inline

Definition at line 470 of file unicharset.h.

470  {
471  if (INVALID_UNICHAR_ID == unichar_id) return false;
472  ASSERT_HOST(contains_unichar_id(unichar_id));
473  return unichars[unichar_id].properties.isdigit;
474  }
#define ASSERT_HOST(x)
Definition: errcode.h:84
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:242
bool UNICHARSET::get_isdigit ( const char *const  unichar_repr) const
inline

Definition at line 704 of file unicharset.h.

704  {
705  return get_isdigit(unichar_to_id(unichar_repr));
706  }
const UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:470
bool UNICHARSET::get_isdigit ( const char *const  unichar_repr,
int  length 
) const
inline

Definition at line 763 of file unicharset.h.

764  {
765  return get_isdigit(unichar_to_id(unichar_repr, length));
766  }
const UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:470
bool UNICHARSET::get_islower ( UNICHAR_ID  unichar_id) const
inline

Definition at line 456 of file unicharset.h.

456  {
457  if (INVALID_UNICHAR_ID == unichar_id) return false;
458  ASSERT_HOST(contains_unichar_id(unichar_id));
459  return unichars[unichar_id].properties.islower;
460  }
#define ASSERT_HOST(x)
Definition: errcode.h:84
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:242
bool UNICHARSET::get_islower ( const char *const  unichar_repr) const
inline

Definition at line 694 of file unicharset.h.

694  {
695  return get_islower(unichar_to_id(unichar_repr));
696  }
const UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
bool get_islower(UNICHAR_ID unichar_id) const
Definition: unicharset.h:456
bool UNICHARSET::get_islower ( const char *const  unichar_repr,
int  length 
) const
inline

Definition at line 749 of file unicharset.h.

750  {
751  return get_islower(unichar_to_id(unichar_repr, length));
752  }
const UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
bool get_islower(UNICHAR_ID unichar_id) const
Definition: unicharset.h:456
bool UNICHARSET::get_isngram ( UNICHAR_ID  unichar_id) const
inline

Definition at line 484 of file unicharset.h.

484  {
485  if (INVALID_UNICHAR_ID == unichar_id) return false;
486  ASSERT_HOST(contains_unichar_id(unichar_id));
487  return unichars[unichar_id].properties.isngram;
488  }
#define ASSERT_HOST(x)
Definition: errcode.h:84
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:242
bool UNICHARSET::get_isprivate ( UNICHAR_ID  unichar_id) const

Definition at line 363 of file unicharset.cpp.

363  {
364  UNICHAR uc(id_to_unichar(unichar_id), -1);
365  int uni = uc.first_uni();
366  return (uni >= 0xE000 && uni <= 0xF8FF);
367 }
const char *const id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:266
bool UNICHARSET::get_ispunctuation ( UNICHAR_ID  unichar_id) const
inline

Definition at line 477 of file unicharset.h.

477  {
478  if (INVALID_UNICHAR_ID == unichar_id) return false;
479  ASSERT_HOST(contains_unichar_id(unichar_id));
480  return unichars[unichar_id].properties.ispunctuation;
481  }
#define ASSERT_HOST(x)
Definition: errcode.h:84
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:242
bool UNICHARSET::get_ispunctuation ( const char *const  unichar_repr) const
inline

Definition at line 709 of file unicharset.h.

709  {
710  return get_ispunctuation(unichar_to_id(unichar_repr));
711  }
const UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
bool get_ispunctuation(UNICHAR_ID unichar_id) const
Definition: unicharset.h:477
bool UNICHARSET::get_ispunctuation ( const char *const  unichar_repr,
int  length 
) const
inline

Definition at line 770 of file unicharset.h.

771  {
772  return get_ispunctuation(unichar_to_id(unichar_repr, length));
773  }
const UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
bool get_ispunctuation(UNICHAR_ID unichar_id) const
Definition: unicharset.h:477
bool UNICHARSET::get_isupper ( UNICHAR_ID  unichar_id) const
inline

Definition at line 463 of file unicharset.h.

463  {
464  if (INVALID_UNICHAR_ID == unichar_id) return false;
465  ASSERT_HOST(contains_unichar_id(unichar_id));
466  return unichars[unichar_id].properties.isupper;
467  }
#define ASSERT_HOST(x)
Definition: errcode.h:84
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:242
bool UNICHARSET::get_isupper ( const char *const  unichar_repr) const
inline

Definition at line 699 of file unicharset.h.

699  {
700  return get_isupper(unichar_to_id(unichar_repr));
701  }
const UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
bool get_isupper(UNICHAR_ID unichar_id) const
Definition: unicharset.h:463
bool UNICHARSET::get_isupper ( const char *const  unichar_repr,
int  length 
) const
inline

Definition at line 756 of file unicharset.h.

757  {
758  return get_isupper(unichar_to_id(unichar_repr, length));
759  }
const UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
bool get_isupper(UNICHAR_ID unichar_id) const
Definition: unicharset.h:463
UNICHAR_ID UNICHARSET::get_mirror ( UNICHAR_ID  unichar_id) const
inline

Definition at line 645 of file unicharset.h.

645  {
646  if (INVALID_UNICHAR_ID == unichar_id) return INVALID_UNICHAR_ID;
647  ASSERT_HOST(contains_unichar_id(unichar_id));
648  return unichars[unichar_id].properties.mirror;
649  }
#define ASSERT_HOST(x)
Definition: errcode.h:84
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:242
const char* UNICHARSET::get_normed_unichar ( UNICHAR_ID  unichar_id) const
inline

Definition at line 776 of file unicharset.h.

776  {
777  if (unichar_id == UNICHAR_SPACE && has_special_codes()) return " ";
778  return unichars[unichar_id].properties.normed.string();
779  }
bool has_special_codes() const
Definition: unicharset.h:670
UNICHAR_ID UNICHARSET::get_other_case ( UNICHAR_ID  unichar_id) const
inline

Definition at line 631 of file unicharset.h.

631  {
632  if (INVALID_UNICHAR_ID == unichar_id) return INVALID_UNICHAR_ID;
633  ASSERT_HOST(contains_unichar_id(unichar_id));
634  return unichars[unichar_id].properties.other_case;
635  }
#define ASSERT_HOST(x)
Definition: errcode.h:84
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:242
unsigned int UNICHARSET::get_properties ( UNICHAR_ID  unichar_id) const

Definition at line 588 of file unicharset.cpp.

588  {
589  unsigned int properties = 0;
590  if (this->get_isalpha(id))
591  properties |= ISALPHA_MASK;
592  if (this->get_islower(id))
593  properties |= ISLOWER_MASK;
594  if (this->get_isupper(id))
595  properties |= ISUPPER_MASK;
596  if (this->get_isdigit(id))
597  properties |= ISDIGIT_MASK;
598  if (this->get_ispunctuation(id))
599  properties |= ISPUNCTUATION_MASK;
600  return properties;
601 }
bool get_isupper(UNICHAR_ID unichar_id) const
Definition: unicharset.h:463
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:470
bool get_islower(UNICHAR_ID unichar_id) const
Definition: unicharset.h:456
bool get_ispunctuation(UNICHAR_ID unichar_id) const
Definition: unicharset.h:477
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:449
unsigned int UNICHARSET::get_properties ( const char *const  unichar_repr) const
inline

Definition at line 715 of file unicharset.h.

715  {
716  return get_properties(unichar_to_id(unichar_repr));
717  }
const UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
unsigned int get_properties(UNICHAR_ID unichar_id) const
Definition: unicharset.cpp:588
int UNICHARSET::get_script ( UNICHAR_ID  unichar_id) const
inline

Definition at line 611 of file unicharset.h.

611  {
612  if (INVALID_UNICHAR_ID == unichar_id) return null_sid_;
613  ASSERT_HOST(contains_unichar_id(unichar_id));
614  return unichars[unichar_id].properties.script_id;
615  }
#define ASSERT_HOST(x)
Definition: errcode.h:84
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:242
int UNICHARSET::get_script ( const char *const  unichar_repr) const
inline

Definition at line 726 of file unicharset.h.

726  {
727  return get_script(unichar_to_id(unichar_repr));
728  }
const UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
int get_script(UNICHAR_ID unichar_id) const
Definition: unicharset.h:611
int UNICHARSET::get_script ( const char *const  unichar_repr,
int  length 
) const
inline

Definition at line 791 of file unicharset.h.

792  {
793  return get_script(unichar_to_id(unichar_repr, length));
794  }
const UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
int get_script(UNICHAR_ID unichar_id) const
Definition: unicharset.h:611
const char* UNICHARSET::get_script_from_script_id ( int  id) const
inline

Definition at line 802 of file unicharset.h.

802  {
803  if (id >= script_table_size_used || id < 0)
804  return null_script;
805  return script_table[id];
806  }
int UNICHARSET::get_script_id_from_name ( const char *  script_name) const

Definition at line 1080 of file unicharset.cpp.

1080  {
1081  for (int i = 0; i < script_table_size_used; ++i) {
1082  if (strcmp(script_name, script_table[i]) == 0)
1083  return i;
1084  }
1085  return 0; // 0 is always the null_script
1086 }
int UNICHARSET::get_script_table_size ( ) const
inline

Definition at line 797 of file unicharset.h.

797  {
798  return script_table_size_used;
799  }
void UNICHARSET::get_top_bottom ( UNICHAR_ID  unichar_id,
int *  min_bottom,
int *  max_bottom,
int *  min_top,
int *  max_top 
) const
inline

Definition at line 526 of file unicharset.h.

528  {
529  if (INVALID_UNICHAR_ID == unichar_id) {
530  *min_bottom = *min_top = 0;
531  *max_bottom = *max_top = 256; // kBlnCellHeight
532  return;
533  }
534  ASSERT_HOST(contains_unichar_id(unichar_id));
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;
539  }
#define ASSERT_HOST(x)
Definition: errcode.h:84
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:242
void UNICHARSET::get_width_stats ( UNICHAR_ID  unichar_id,
float *  width,
float *  width_sd 
) const
inline

Definition at line 554 of file unicharset.h.

555  {
556  if (INVALID_UNICHAR_ID == unichar_id) {
557  *width = 0.0f;
558  *width_sd = 0.0f;;
559  return;
560  }
561  ASSERT_HOST(contains_unichar_id(unichar_id));
562  *width = unichars[unichar_id].properties.width;
563  *width_sd = unichars[unichar_id].properties.width_sd;
564  }
#define ASSERT_HOST(x)
Definition: errcode.h:84
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:242
int UNICHARSET::greek_sid ( ) const
inline

Definition at line 835 of file unicharset.h.

835 { return greek_sid_; }
int UNICHARSET::han_sid ( ) const
inline

Definition at line 836 of file unicharset.h.

836 { return han_sid_; }
bool UNICHARSET::has_special_codes ( ) const
inline

Definition at line 670 of file unicharset.h.

670  {
671  return get_fragment(UNICHAR_BROKEN) != NULL &&
674  }
const CHAR_FRAGMENT * get_fragment(UNICHAR_ID unichar_id) const
Definition: unicharset.h:682
const char *const id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:266
static const char * kSpecialUnicharCodes[SPECIAL_UNICHAR_CODES_COUNT]
Definition: unicharset.h:147
#define NULL
Definition: host.h:144
int UNICHARSET::hiragana_sid ( ) const
inline

Definition at line 837 of file unicharset.h.

837 { return hiragana_sid_; }
const char *const UNICHARSET::id_to_unichar ( UNICHAR_ID  id) const

Definition at line 266 of file unicharset.cpp.

266  {
267  if (id == INVALID_UNICHAR_ID) {
268  return INVALID_UNICHAR;
269  }
270  ASSERT_HOST(id < this->size());
271  return unichars[id].representation;
272 }
#define ASSERT_HOST(x)
Definition: errcode.h:84
int size() const
Definition: unicharset.h:297
const char *const UNICHARSET::id_to_unichar_ext ( UNICHAR_ID  id) const

Definition at line 274 of file unicharset.cpp.

274  {
275  if (id == INVALID_UNICHAR_ID) {
276  return INVALID_UNICHAR;
277  }
278  ASSERT_HOST(id < this->size());
279  // Resolve from the kCustomLigatures table if this is a private encoding.
280  if (get_isprivate(id)) {
281  const char* ch = id_to_unichar(id);
282  for (int i = 0; kCustomLigatures[i][0] != NULL; ++i) {
283  if (!strcmp(ch, kCustomLigatures[i][1])) {
284  return kCustomLigatures[i][0];
285  }
286  }
287  }
288  // Otherwise return the stored representation.
289  return unichars[id].representation;
290 }
#define ASSERT_HOST(x)
Definition: errcode.h:84
const char *const id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:266
bool get_isprivate(UNICHAR_ID unichar_id) const
Definition: unicharset.cpp:363
#define NULL
Definition: host.h:144
static const char * kCustomLigatures[][2]
Definition: unicharset.h:144
int size() const
Definition: unicharset.h:297
bool UNICHARSET::is_null_script ( const char *  script) const
inline

Definition at line 816 of file unicharset.h.

816  {
817  return script == null_script;
818  }
int UNICHARSET::katakana_sid ( ) const
inline

Definition at line 838 of file unicharset.h.

838 { return katakana_sid_; }
int UNICHARSET::latin_sid ( ) const
inline

Definition at line 833 of file unicharset.h.

833 { return latin_sid_; }
bool UNICHARSET::load_from_file ( const char *const  filename,
bool  skip_fragments 
)
inline

Definition at line 346 of file unicharset.h.

346  {
347  FILE* file = fopen(filename, "rb");
348  if (file == NULL) return false;
349  bool result = load_from_file(file, skip_fragments);
350  fclose(file);
351  return result;
352  }
bool load_from_file(const char *const filename, bool skip_fragments)
Definition: unicharset.h:346
#define NULL
Definition: host.h:144
bool UNICHARSET::load_from_file ( const char *const  filename)
inline

Definition at line 354 of file unicharset.h.

354  {
355  return load_from_file(filename, false);
356  }
bool load_from_file(const char *const filename, bool skip_fragments)
Definition: unicharset.h:346
bool UNICHARSET::load_from_file ( FILE *  file,
bool  skip_fragments 
)

Definition at line 744 of file unicharset.cpp.

744  {
745  LocalFilePointer lfp(file);
748  bool success = load_via_fgets(fgets_cb, skip_fragments);
749  delete fgets_cb;
750  return success;
751 }
char * fgets(char *dst, int size)
Definition: unicharset.cpp:737
_ConstTessMemberResultCallback_0_0< false, R, T1 >::base * NewPermanentTessCallback(const T1 *obj, R(T2::*member)() const)
Definition: tesscallback.h:116
bool UNICHARSET::load_from_file ( FILE *  file)
inline

Definition at line 361 of file unicharset.h.

361 { return load_from_file(file, false); }
bool load_from_file(const char *const filename, bool skip_fragments)
Definition: unicharset.h:346
bool UNICHARSET::load_from_file ( tesseract::TFile file,
bool  skip_fragments 
)

Definition at line 753 of file unicharset.cpp.

753  {
756  bool success = load_via_fgets(fgets_cb, skip_fragments);
757  delete fgets_cb;
758  return success;
759 }
_ConstTessMemberResultCallback_0_0< false, R, T1 >::base * NewPermanentTessCallback(const T1 *obj, R(T2::*member)() const)
Definition: tesscallback.h:116
char * FGets(char *buffer, int buffer_size)
Definition: serialis.cpp:80
bool UNICHARSET::load_from_inmemory_file ( const char *const  memory,
int  mem_size,
bool  skip_fragments 
)

Definition at line 724 of file unicharset.cpp.

725  {
726  InMemoryFilePointer mem_fp(memory, mem_size);
729  bool success = load_via_fgets(fgets_cb, skip_fragments);
730  delete fgets_cb;
731  return success;
732 }
char * fgets(char *orig_dst, int size)
Definition: unicharset.cpp:702
_ConstTessMemberResultCallback_0_0< false, R, T1 >::base * NewPermanentTessCallback(const T1 *obj, R(T2::*member)() const)
Definition: tesscallback.h:116
bool UNICHARSET::load_from_inmemory_file ( const char *const  memory,
int  mem_size 
)
inline

Definition at line 339 of file unicharset.h.

339  {
340  return load_from_inmemory_file(memory, mem_size, false);
341  }
bool load_from_inmemory_file(const char *const memory, int mem_size, bool skip_fragments)
Definition: unicharset.cpp:724
bool UNICHARSET::major_right_to_left ( ) const

Definition at line 931 of file unicharset.cpp.

931  {
932  int ltr_count = 0;
933  int rtl_count = 0;
934  for (int id = 0; id < size_used; ++id) {
935  int dir = get_direction(id);
936  if (dir == UNICHARSET::U_LEFT_TO_RIGHT) ltr_count++;
937  if (dir == UNICHARSET::U_RIGHT_TO_LEFT ||
939  dir == UNICHARSET::U_ARABIC_NUMBER) rtl_count++;
940  }
941  return rtl_count > ltr_count;
942 }
Direction get_direction(UNICHAR_ID unichar_id) const
Definition: unicharset.h:638
const GenericVector<UNICHAR_ID>& UNICHARSET::normed_ids ( UNICHAR_ID  unichar_id) const
inline

Definition at line 783 of file unicharset.h.

783  {
784  return unichars[unichar_id].properties.normed_ids;
785  }
int UNICHARSET::null_sid ( ) const
inline

Definition at line 831 of file unicharset.h.

831 { return null_sid_; }
void UNICHARSET::PartialSetPropertiesFromOther ( int  start_index,
const UNICHARSET src 
)

Definition at line 380 of file unicharset.cpp.

381  {
382  for (int ch = start_index; ch < size_used; ++ch) {
383  const char* utf8 = id_to_unichar(ch);
384  UNICHAR_PROPERTIES properties;
385  if (src.GetStrProperties(utf8, &properties)) {
386  // Setup the script_id, other_case, and mirror properly.
387  const char* script = src.get_script_from_script_id(properties.script_id);
388  properties.script_id = add_script(script);
389  const char* other_case = src.id_to_unichar(properties.other_case);
390  if (contains_unichar(other_case)) {
391  properties.other_case = unichar_to_id(other_case);
392  } else {
393  properties.other_case = ch;
394  }
395  const char* mirror_str = src.id_to_unichar(properties.mirror);
396  if (contains_unichar(mirror_str)) {
397  properties.mirror = unichar_to_id(mirror_str);
398  } else {
399  properties.mirror = ch;
400  }
401  unichars[ch].properties.CopyFrom(properties);
402  set_normed_ids(ch);
403  }
404  }
405 }
const UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
const char *const id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:266
int add_script(const char *script)
const char * get_script_from_script_id(int id) const
Definition: unicharset.h:802
void set_normed_ids(UNICHAR_ID unichar_id)
Definition: unicharset.cpp:348
bool contains_unichar(const char *const unichar_repr) const
Definition: unicharset.cpp:644
void UNICHARSET::post_load_setup ( )

Definition at line 867 of file unicharset.cpp.

867  {
868  // Number of alpha chars with the case property minus those without,
869  // in order to determine that half the alpha chars have case.
870  int net_case_alphas = 0;
871  int x_height_alphas = 0;
872  int cap_height_alphas = 0;
873  top_bottom_set_ = false;
874  for (UNICHAR_ID id = 0; id < size_used; ++id) {
875  int min_bottom = 0;
876  int max_bottom = MAX_UINT8;
877  int min_top = 0;
878  int max_top = MAX_UINT8;
879  get_top_bottom(id, &min_bottom, &max_bottom, &min_top, &max_top);
880  if (min_top > 0)
881  top_bottom_set_ = true;
882  if (get_isalpha(id)) {
883  if (get_islower(id) || get_isupper(id))
884  ++net_case_alphas;
885  else
886  --net_case_alphas;
887  if (min_top < kMeanlineThreshold && max_top < kMeanlineThreshold)
888  ++x_height_alphas;
889  else if (min_top > kMeanlineThreshold && max_top > kMeanlineThreshold)
890  ++cap_height_alphas;
891  }
892  set_normed_ids(id);
893  }
894 
895  script_has_upper_lower_ = net_case_alphas > 0;
896  script_has_xheight_ = script_has_upper_lower_ ||
897  (x_height_alphas > cap_height_alphas * kMinXHeightFraction &&
898  cap_height_alphas > x_height_alphas * kMinCapHeightFraction);
899 
900  null_sid_ = get_script_id_from_name(null_script);
901  ASSERT_HOST(null_sid_ == 0);
902  common_sid_ = get_script_id_from_name("Common");
903  latin_sid_ = get_script_id_from_name("Latin");
904  cyrillic_sid_ = get_script_id_from_name("Cyrillic");
905  greek_sid_ = get_script_id_from_name("Greek");
906  han_sid_ = get_script_id_from_name("Han");
907  hiragana_sid_ = get_script_id_from_name("Hiragana");
908  katakana_sid_ = get_script_id_from_name("Katakana");
909 
910  // Compute default script. Use the highest-counting alpha script, that is
911  // not the common script, as that still contains some "alphas".
912  int* script_counts = new int[script_table_size_used];
913  memset(script_counts, 0, sizeof(*script_counts) * script_table_size_used);
914  for (int id = 0; id < size_used; ++id) {
915  if (get_isalpha(id)) {
916  ++script_counts[get_script(id)];
917  }
918  }
919  default_sid_ = 0;
920  for (int s = 1; s < script_table_size_used; ++s) {
921  if (script_counts[s] > script_counts[default_sid_] && s != common_sid_)
922  default_sid_ = s;
923  }
924  delete [] script_counts;
925 }
const double kMinXHeightFraction
Definition: unicharset.cpp:53
bool get_isupper(UNICHAR_ID unichar_id) const
Definition: unicharset.h:463
#define ASSERT_HOST(x)
Definition: errcode.h:84
int get_script_id_from_name(const char *script_name) const
int get_script(UNICHAR_ID unichar_id) const
Definition: unicharset.h:611
#define MAX_UINT8
Definition: host.h:121
void get_top_bottom(UNICHAR_ID unichar_id, int *min_bottom, int *max_bottom, int *min_top, int *max_top) const
Definition: unicharset.h:526
int UNICHAR_ID
Definition: unichar.h:33
bool get_islower(UNICHAR_ID unichar_id) const
Definition: unicharset.h:456
const double kMinCapHeightFraction
Definition: unicharset.cpp:54
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:449
void set_normed_ids(UNICHAR_ID unichar_id)
Definition: unicharset.cpp:348
bool UNICHARSET::PropertiesIncomplete ( UNICHAR_ID  unichar_id) const
inline

Definition at line 604 of file unicharset.h.

604  {
605  return unichars[unichar_id].properties.AnyRangeEmpty();
606  }
void UNICHARSET::reserve ( int  unichars_number)

Definition at line 179 of file unicharset.cpp.

179  {
180  if (unichars_number > size_reserved) {
181  UNICHAR_SLOT* unichars_new = new UNICHAR_SLOT[unichars_number];
182  for (int i = 0; i < size_used; ++i)
183  unichars_new[i] = unichars[i];
184  for (int j = size_used; j < unichars_number; ++j) {
185  unichars_new[j].properties.script_id = add_script(null_script);
186  }
187  delete[] unichars;
188  unichars = unichars_new;
189  size_reserved = unichars_number;
190  }
191 }
int add_script(const char *script)
bool UNICHARSET::save_to_file ( const char *const  filename) const
inline

Definition at line 306 of file unicharset.h.

306  {
307  FILE* file = fopen(filename, "w+b");
308  if (file == NULL) return false;
309  bool result = save_to_file(file);
310  fclose(file);
311  return result;
312  }
bool save_to_file(const char *const filename) const
Definition: unicharset.h:306
#define NULL
Definition: host.h:144
bool UNICHARSET::save_to_file ( FILE *  file) const
inline

Definition at line 316 of file unicharset.h.

316  {
317  STRING str;
318  if (!save_to_string(&str)) return false;
319  if (fwrite(&str[0], str.length(), 1, file) != 1) return false;
320  return true;
321  }
inT32 length() const
Definition: strngs.cpp:188
bool save_to_string(STRING *str) const
Definition: unicharset.cpp:661
Definition: strngs.h:44
bool UNICHARSET::save_to_file ( tesseract::TFile file) const
inline

Definition at line 322 of file unicharset.h.

322  {
323  STRING str;
324  if (!save_to_string(&str)) return false;
325  if (file->FWrite(&str[0], str.length(), 1) != 1) return false;
326  return true;
327  }
inT32 length() const
Definition: strngs.cpp:188
int FWrite(const void *buffer, int size, int count)
Definition: serialis.cpp:131
bool save_to_string(STRING *str) const
Definition: unicharset.cpp:661
Definition: strngs.h:44
bool UNICHARSET::save_to_string ( STRING str) const

Definition at line 661 of file unicharset.cpp.

661  {
662  const int kFileBufSize = 1024;
663  char buffer[kFileBufSize + 1];
664  snprintf(buffer, kFileBufSize, "%d\n", this->size());
665  *str = buffer;
666  for (UNICHAR_ID id = 0; id < this->size(); ++id) {
667  int min_bottom, max_bottom, min_top, max_top;
668  get_top_bottom(id, &min_bottom, &max_bottom, &min_top, &max_top);
669  float width, width_sd;
670  get_width_stats(id, &width, &width_sd);
671  float bearing, bearing_sd;
672  get_bearing_stats(id, &bearing, &bearing_sd);
673  float advance, advance_sd;
674  get_advance_stats(id, &advance, &advance_sd);
675  unsigned int properties = this->get_properties(id);
676  if (strcmp(this->id_to_unichar(id), " ") == 0) {
677  snprintf(buffer, kFileBufSize, "%s %x %s %d\n", "NULL", properties,
678  this->get_script_from_script_id(this->get_script(id)),
679  this->get_other_case(id));
680  } else {
681  snprintf(buffer, kFileBufSize,
682  "%s %x %d,%d,%d,%d,%g,%g,%g,%g,%g,%g %s %d %d %d %s\t# %s\n",
683  this->id_to_unichar(id), properties,
684  min_bottom, max_bottom, min_top, max_top, width, width_sd,
685  bearing, bearing_sd, advance, advance_sd,
686  this->get_script_from_script_id(this->get_script(id)),
687  this->get_other_case(id), this->get_direction(id),
688  this->get_mirror(id), this->get_normed_unichar(id),
689  this->debug_str(id).string());
690  }
691  *str += buffer;
692  }
693  return true;
694 }
STRING debug_str(UNICHAR_ID id) const
Definition: unicharset.cpp:318
UNICHAR_ID get_mirror(UNICHAR_ID unichar_id) const
Definition: unicharset.h:645
int get_script(UNICHAR_ID unichar_id) const
Definition: unicharset.h:611
const char *const id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:266
void get_top_bottom(UNICHAR_ID unichar_id, int *min_bottom, int *max_bottom, int *min_top, int *max_top) const
Definition: unicharset.h:526
unsigned int get_properties(UNICHAR_ID unichar_id) const
Definition: unicharset.cpp:588
int UNICHAR_ID
Definition: unichar.h:33
UNICHAR_ID get_other_case(UNICHAR_ID unichar_id) const
Definition: unicharset.h:631
const char * get_script_from_script_id(int id) const
Definition: unicharset.h:802
Direction get_direction(UNICHAR_ID unichar_id) const
Definition: unicharset.h:638
const char * get_normed_unichar(UNICHAR_ID unichar_id) const
Definition: unicharset.h:776
void get_bearing_stats(UNICHAR_ID unichar_id, float *bearing, float *bearing_sd) const
Definition: unicharset.h:571
int size() const
Definition: unicharset.h:297
void get_width_stats(UNICHAR_ID unichar_id, float *width, float *width_sd) const
Definition: unicharset.h:554
void get_advance_stats(UNICHAR_ID unichar_id, float *advance, float *advance_sd) const
Definition: unicharset.h:588
bool UNICHARSET::script_has_upper_lower ( ) const
inline

Definition at line 842 of file unicharset.h.

842  {
843  return script_has_upper_lower_;
844  }
bool UNICHARSET::script_has_xheight ( ) const
inline

Definition at line 849 of file unicharset.h.

849  {
850  return script_has_xheight_;
851  }
void UNICHARSET::set_advance_stats ( UNICHAR_ID  unichar_id,
float  advance,
float  advance_sd 
)
inline

Definition at line 598 of file unicharset.h.

599  {
600  unichars[unichar_id].properties.advance = advance;
601  unichars[unichar_id].properties.advance_sd = advance_sd;
602  }
void UNICHARSET::set_bearing_stats ( UNICHAR_ID  unichar_id,
float  bearing,
float  bearing_sd 
)
inline

Definition at line 581 of file unicharset.h.

582  {
583  unichars[unichar_id].properties.bearing = bearing;
584  unichars[unichar_id].properties.bearing_sd = bearing_sd;
585  }
void UNICHARSET::set_black_and_whitelist ( const char *  blacklist,
const char *  whitelist,
const char *  unblacklist 
)

Definition at line 948 of file unicharset.cpp.

950  {
951  bool def_enabled = whitelist == NULL || whitelist[0] == '\0';
952  // Set everything to default
953  for (int ch = 0; ch < size_used; ++ch)
954  unichars[ch].properties.enabled = def_enabled;
955  if (!def_enabled) {
956  // Enable the whitelist.
957  GenericVector<UNICHAR_ID> encoding;
958  encode_string(whitelist, false, &encoding, NULL, NULL);
959  for (int i = 0; i < encoding.size(); ++i) {
960  if (encoding[i] != INVALID_UNICHAR_ID)
961  unichars[encoding[i]].properties.enabled = true;
962  }
963  }
964  if (blacklist != NULL && blacklist[0] != '\0') {
965  // Disable the blacklist.
966  GenericVector<UNICHAR_ID> encoding;
967  encode_string(blacklist, false, &encoding, NULL, NULL);
968  for (int i = 0; i < encoding.size(); ++i) {
969  if (encoding[i] != INVALID_UNICHAR_ID)
970  unichars[encoding[i]].properties.enabled = false;
971  }
972  }
973  if (unblacklist != NULL && unblacklist[0] != '\0') {
974  // Re-enable the unblacklist.
975  GenericVector<UNICHAR_ID> encoding;
976  encode_string(unblacklist, false, &encoding, NULL, NULL);
977  for (int i = 0; i < encoding.size(); ++i) {
978  if (encoding[i] != INVALID_UNICHAR_ID)
979  unichars[encoding[i]].properties.enabled = true;
980  }
981  }
982 }
int size() const
Definition: genericvector.h:72
bool encode_string(const char *str, bool give_up_on_failure, GenericVector< UNICHAR_ID > *encoding, GenericVector< char > *lengths, int *encoded_length) const
Definition: unicharset.cpp:234
#define NULL
Definition: host.h:144
void UNICHARSET::set_direction ( UNICHAR_ID  unichar_id,
UNICHARSET::Direction  value 
)
inline

Definition at line 430 of file unicharset.h.

430  {
431  unichars[unichar_id].properties.direction = value;
432  }
void UNICHARSET::set_isalpha ( UNICHAR_ID  unichar_id,
bool  value 
)
inline

Definition at line 389 of file unicharset.h.

389  {
390  unichars[unichar_id].properties.isalpha = value;
391  }
void UNICHARSET::set_isdigit ( UNICHAR_ID  unichar_id,
bool  value 
)
inline

Definition at line 404 of file unicharset.h.

404  {
405  unichars[unichar_id].properties.isdigit = value;
406  }
void UNICHARSET::set_islower ( UNICHAR_ID  unichar_id,
bool  value 
)
inline

Definition at line 394 of file unicharset.h.

394  {
395  unichars[unichar_id].properties.islower = value;
396  }
void UNICHARSET::set_isngram ( UNICHAR_ID  unichar_id,
bool  value 
)
inline

Definition at line 414 of file unicharset.h.

414  {
415  unichars[unichar_id].properties.isngram = value;
416  }
void UNICHARSET::set_ispunctuation ( UNICHAR_ID  unichar_id,
bool  value 
)
inline

Definition at line 409 of file unicharset.h.

409  {
410  unichars[unichar_id].properties.ispunctuation = value;
411  }
void UNICHARSET::set_isupper ( UNICHAR_ID  unichar_id,
bool  value 
)
inline

Definition at line 399 of file unicharset.h.

399  {
400  unichars[unichar_id].properties.isupper = value;
401  }
void UNICHARSET::set_mirror ( UNICHAR_ID  unichar_id,
UNICHAR_ID  mirror 
)
inline

Definition at line 435 of file unicharset.h.

435  {
436  unichars[unichar_id].properties.mirror = mirror;
437  }
void UNICHARSET::set_normed ( UNICHAR_ID  unichar_id,
const char *  normed 
)
inline

Definition at line 440 of file unicharset.h.

440  {
441  unichars[unichar_id].properties.normed = normed;
442  unichars[unichar_id].properties.normed_ids.truncate(0);
443  }
void UNICHARSET::set_normed_ids ( UNICHAR_ID  unichar_id)

Definition at line 348 of file unicharset.cpp.

348  {
349  unichars[unichar_id].properties.normed_ids.truncate(0);
350  if (unichar_id == UNICHAR_SPACE && id_to_unichar(unichar_id)[0] == ' ') {
351  unichars[unichar_id].properties.normed_ids.push_back(UNICHAR_SPACE);
352  } else if (!encode_string(unichars[unichar_id].properties.normed.string(),
353  true, &unichars[unichar_id].properties.normed_ids,
354  NULL, NULL)) {
355  unichars[unichar_id].properties.normed_ids.truncate(0);
356  unichars[unichar_id].properties.normed_ids.push_back(unichar_id);
357  }
358 }
const char *const id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:266
bool encode_string(const char *str, bool give_up_on_failure, GenericVector< UNICHAR_ID > *encoding, GenericVector< char > *lengths, int *encoded_length) const
Definition: unicharset.cpp:234
#define NULL
Definition: host.h:144
void UNICHARSET::set_other_case ( UNICHAR_ID  unichar_id,
UNICHAR_ID  other_case 
)
inline

Definition at line 425 of file unicharset.h.

425  {
426  unichars[unichar_id].properties.other_case = other_case;
427  }
void UNICHARSET::set_ranges_empty ( )

Definition at line 371 of file unicharset.cpp.

371  {
372  for (int id = 0; id < size_used; ++id) {
373  unichars[id].properties.SetRangesEmpty();
374  }
375 }
void UNICHARSET::set_script ( UNICHAR_ID  unichar_id,
const char *  value 
)
inline

Definition at line 420 of file unicharset.h.

420  {
421  unichars[unichar_id].properties.script_id = add_script(value);
422  }
int add_script(const char *script)
void UNICHARSET::set_top_bottom ( UNICHAR_ID  unichar_id,
int  min_bottom,
int  max_bottom,
int  min_top,
int  max_top 
)
inline

Definition at line 540 of file unicharset.h.

542  {
543  unichars[unichar_id].properties.min_bottom =
544  static_cast<uinT8>(ClipToRange(min_bottom, 0, MAX_UINT8));
545  unichars[unichar_id].properties.max_bottom =
546  static_cast<uinT8>(ClipToRange(max_bottom, 0, MAX_UINT8));
547  unichars[unichar_id].properties.min_top =
548  static_cast<uinT8>(ClipToRange(min_top, 0, MAX_UINT8));
549  unichars[unichar_id].properties.max_top =
550  static_cast<uinT8>(ClipToRange(max_top, 0, MAX_UINT8));
551  }
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:115
#define MAX_UINT8
Definition: host.h:121
unsigned char uinT8
Definition: host.h:99
void UNICHARSET::set_width_stats ( UNICHAR_ID  unichar_id,
float  width,
float  width_sd 
)
inline

Definition at line 565 of file unicharset.h.

565  {
566  unichars[unichar_id].properties.width = width;
567  unichars[unichar_id].properties.width_sd = width_sd;
568  }
void UNICHARSET::SetPropertiesFromOther ( const UNICHARSET src)
inline

Definition at line 503 of file unicharset.h.

503  {
505  }
void PartialSetPropertiesFromOther(int start_index, const UNICHARSET &src)
Definition: unicharset.cpp:380
int UNICHARSET::size ( ) const
inline

Definition at line 297 of file unicharset.h.

297  {
298  return size_used;
299  }
bool UNICHARSET::SizesDistinct ( UNICHAR_ID  id1,
UNICHAR_ID  id2 
) const

Definition at line 472 of file unicharset.cpp.

472  {
473  int overlap = MIN(unichars[id1].properties.max_top,
474  unichars[id2].properties.max_top) -
475  MAX(unichars[id1].properties.min_top,
476  unichars[id2].properties.min_top);
477  return overlap <= 0;
478 }
#define MAX(x, y)
Definition: ndminx.h:24
#define MIN(x, y)
Definition: ndminx.h:28
int UNICHARSET::step ( const char *  str) const

Definition at line 211 of file unicharset.cpp.

211  {
212  GenericVector<UNICHAR_ID> encoding;
213  GenericVector<char> lengths;
214  encode_string(str, true, &encoding, &lengths, NULL);
215  if (encoding.empty() || encoding[0] == INVALID_UNICHAR_ID) return 0;
216  return lengths[0];
217 }
bool encode_string(const char *str, bool give_up_on_failure, GenericVector< UNICHAR_ID > *encoding, GenericVector< char > *lengths, int *encoded_length) const
Definition: unicharset.cpp:234
bool empty() const
Definition: genericvector.h:84
#define NULL
Definition: host.h:144
UNICHAR_ID UNICHARSET::to_lower ( UNICHAR_ID  unichar_id) const
inline

Definition at line 652 of file unicharset.h.

652  {
653  if (INVALID_UNICHAR_ID == unichar_id) return INVALID_UNICHAR_ID;
654  ASSERT_HOST(contains_unichar_id(unichar_id));
655  if (unichars[unichar_id].properties.islower) return unichar_id;
656  return unichars[unichar_id].properties.other_case;
657  }
#define ASSERT_HOST(x)
Definition: errcode.h:84
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:242
UNICHAR_ID UNICHARSET::to_upper ( UNICHAR_ID  unichar_id) const
inline

Definition at line 660 of file unicharset.h.

660  {
661  if (INVALID_UNICHAR_ID == unichar_id) return INVALID_UNICHAR_ID;
662  ASSERT_HOST(contains_unichar_id(unichar_id));
663  if (unichars[unichar_id].properties.isupper) return unichar_id;
664  return unichars[unichar_id].properties.other_case;
665  }
#define ASSERT_HOST(x)
Definition: errcode.h:84
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:242
bool UNICHARSET::top_bottom_useful ( ) const
inline

Definition at line 495 of file unicharset.h.

495  {
496  return top_bottom_set_;
497  }
void UNICHARSET::unichar_insert ( const char *const  unichar_repr)

Definition at line 612 of file unicharset.cpp.

612  {
613  if (!ids.contains(unichar_repr)) {
614  if (strlen(unichar_repr) > UNICHAR_LEN) {
615  fprintf(stderr, "Utf8 buffer too big, size=%d for %s\n",
616  int(strlen(unichar_repr)), unichar_repr);
617  return;
618  }
619  if (size_used == size_reserved) {
620  if (size_used == 0)
621  reserve(8);
622  else
623  reserve(2 * size_used);
624  }
625 
626  strcpy(unichars[size_used].representation, unichar_repr);
627  this->set_script(size_used, null_script);
628  // If the given unichar_repr represents a fragmented character, set
629  // fragment property to a pointer to CHAR_FRAGMENT class instance with
630  // information parsed from the unichar representation. Use the script
631  // of the base unichar for the fragmented character if possible.
632  CHAR_FRAGMENT *frag = CHAR_FRAGMENT::parse_from_string(unichar_repr);
633  this->unichars[size_used].properties.fragment = frag;
634  if (frag != NULL && this->contains_unichar(frag->get_unichar())) {
635  this->unichars[size_used].properties.script_id =
636  this->get_script(frag->get_unichar());
637  }
638  this->unichars[size_used].properties.enabled = true;
639  ids.insert(unichar_repr, size_used);
640  ++size_used;
641  }
642 }
static CHAR_FRAGMENT * parse_from_string(const char *str)
int get_script(UNICHAR_ID unichar_id) const
Definition: unicharset.h:611
void reserve(int unichars_number)
Definition: unicharset.cpp:179
bool contains(const char *const unichar_repr) const
Definition: unicharmap.cpp:101
const char * get_unichar() const
Definition: unicharset.h:64
void insert(const char *const unichar_repr, UNICHAR_ID id)
Definition: unicharmap.cpp:76
void set_script(UNICHAR_ID unichar_id, const char *value)
Definition: unicharset.h:420
bool contains_unichar(const char *const unichar_repr) const
Definition: unicharset.cpp:644
#define NULL
Definition: host.h:144
#define UNICHAR_LEN
Definition: unichar.h:30
const UNICHAR_ID UNICHARSET::unichar_to_id ( const char *const  unichar_repr) const

Definition at line 194 of file unicharset.cpp.

194  {
195  return ids.contains(unichar_repr) ?
196  ids.unichar_to_id(unichar_repr) : INVALID_UNICHAR_ID;
197 }
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharmap.cpp:36
bool contains(const char *const unichar_repr) const
Definition: unicharmap.cpp:101
const UNICHAR_ID UNICHARSET::unichar_to_id ( const char *const  unichar_repr,
int  length 
) const

Definition at line 199 of file unicharset.cpp.

200  {
201  assert(length > 0 && length <= UNICHAR_LEN);
202  return ids.contains(unichar_repr, length) ?
203  ids.unichar_to_id(unichar_repr, length) : INVALID_UNICHAR_ID;
204 }
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharmap.cpp:36
bool contains(const char *const unichar_repr) const
Definition: unicharmap.cpp:101
#define UNICHAR_LEN
Definition: unichar.h:30

Member Data Documentation

const char * UNICHARSET::kCustomLigatures
static
Initial value:
= {
{"ct", "\uE003"},
{"ſh", "\uE006"},
{"ſi", "\uE007"},
{"ſl", "\uE008"},
{"ſſ", "\uE009"},
}

Definition at line 144 of file unicharset.h.

const char * UNICHARSET::kSpecialUnicharCodes
static
Initial value:
= {
" ",
"Joined",
"|Broken|0|1"
}

Definition at line 147 of file unicharset.h.


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