tesseract  4.00.00dev
unicharset.h
Go to the documentation of this file.
1 // File: unicharset.h
3 // Description: Unicode character/ligature set class.
4 // Author: Thomas Kielbus
5 // Created: Wed Jun 28 17:05:01 PDT 2006
6 //
7 // (C) Copyright 2006, Google Inc.
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 //
19 
20 #ifndef TESSERACT_CCUTIL_UNICHARSET_H_
21 #define TESSERACT_CCUTIL_UNICHARSET_H_
22 
23 #include "errcode.h"
24 #include "genericvector.h"
25 #include "helpers.h"
26 #include "serialis.h"
27 #include "strngs.h"
28 #include "tesscallback.h"
29 #include "unichar.h"
30 #include "unicharmap.h"
31 
32 // Enum holding special values of unichar_id. Every unicharset has these.
33 // Warning! Keep in sync with kSpecialUnicharCodes.
38 
40 };
41 
42 // Boolean flag for unichar_insert. It's a bit of a double negative to allow
43 // the default value to be false.
44 enum class OldUncleanUnichars {
45  kFalse,
46  kTrue,
47 };
48 
50  public:
51  // Minimum number of characters used for fragment representation.
52  static const int kMinLen = 6;
53  // Maximum number of characters used for fragment representation.
54  static const int kMaxLen = 3 + UNICHAR_LEN + 2;
55  // Maximum number of fragments per character.
56  static const int kMaxChunks = 5;
57 
58  // Setters and Getters.
59  inline void set_all(const char *unichar, int pos, int total, bool natural) {
60  set_unichar(unichar);
61  set_pos(pos);
62  set_total(total);
63  set_natural(natural);
64  }
65  inline void set_unichar(const char *uch) {
66  strncpy(this->unichar, uch, UNICHAR_LEN);
67  this->unichar[UNICHAR_LEN] = '\0';
68  }
69  inline void set_pos(int p) { this->pos = p; }
70  inline void set_total(int t) { this->total = t; }
71  inline const char* get_unichar() const { return this->unichar; }
72  inline int get_pos() const { return this->pos; }
73  inline int get_total() const { return this->total; }
74 
75  // Returns the string that represents a fragment
76  // with the given unichar, pos and total.
77  static STRING to_string(const char *unichar, int pos, int total,
78  bool natural);
79  // Returns the string that represents this fragment.
80  STRING to_string() const {
81  return to_string(unichar, pos, total, natural);
82  }
83 
84  // Checks whether a fragment has the same unichar,
85  // position and total as the given inputs.
86  inline bool equals(const char *other_unichar,
87  int other_pos, int other_total) const {
88  return (strcmp(this->unichar, other_unichar) == 0 &&
89  this->pos == other_pos && this->total == other_total);
90  }
91  inline bool equals(const CHAR_FRAGMENT *other) const {
92  return this->equals(other->get_unichar(),
93  other->get_pos(),
94  other->get_total());
95  }
96 
97  // Checks whether a given fragment is a continuation of this fragment.
98  // Assumes that the given fragment pointer is not NULL.
99  inline bool is_continuation_of(const CHAR_FRAGMENT *fragment) const {
100  return (strcmp(this->unichar, fragment->get_unichar()) == 0 &&
101  this->total == fragment->get_total() &&
102  this->pos == fragment->get_pos() + 1);
103  }
104 
105  // Returns true if this fragment is a beginning fragment.
106  inline bool is_beginning() const { return this->pos == 0; }
107 
108  // Returns true if this fragment is an ending fragment.
109  inline bool is_ending() const { return this->pos == this->total-1; }
110 
111  // Returns true if the fragment was a separate component to begin with,
112  // ie did not need chopping to be isolated, but may have been separated
113  // out from a multi-outline blob.
114  inline bool is_natural() const { return natural; }
115  void set_natural(bool value) { natural = value; }
116 
117  // Parses the string to see whether it represents a character fragment
118  // (rather than a regular character). If so, allocates memory for a new
119  // CHAR_FRAGMENT instance and fills it in with the corresponding fragment
120  // information. Fragments are of the form:
121  // |m|1|2, meaning chunk 1 of 2 of character m, or
122  // |:|1n2, meaning chunk 1 of 2 of character :, and no chopping was needed
123  // to divide the parts, as they were already separate connected components.
124  //
125  // If parsing succeeded returns the pointer to the allocated CHAR_FRAGMENT
126  // instance, otherwise (if the string does not represent a fragment or it
127  // looks like it does, but parsing it as a fragment fails) returns NULL.
128  //
129  // Note: The caller is responsible for deallocating memory
130  // associated with the returned pointer.
131  static CHAR_FRAGMENT *parse_from_string(const char *str);
132 
133  private:
134  char unichar[UNICHAR_LEN + 1];
135  // True if the fragment was a separate component to begin with,
136  // ie did not need chopping to be isolated, but may have been separated
137  // out from a multi-outline blob.
138  bool natural;
139  inT16 pos; // fragment position in the character
140  inT16 total; // total number of fragments in the character
141 };
142 
143 // The UNICHARSET class is an utility class for Tesseract that holds the
144 // set of characters that are used by the engine. Each character is identified
145 // by a unique number, from 0 to (size - 1).
146 class UNICHARSET {
147  public:
148  // Custom list of characters and their ligature forms (UTF8)
149  // These map to unicode values in the private use area (PUC) and are supported
150  // by only few font families (eg. Wyld, Adobe Caslon Pro).
151  static TESS_API const char* kCustomLigatures[][2];
152 
153  // List of strings for the SpecialUnicharCodes. Keep in sync with the enum.
154  static TESS_API const char* kSpecialUnicharCodes[SPECIAL_UNICHAR_CODES_COUNT];
155 
156  // ICU 2.0 UCharDirection enum (from third_party/icu/include/unicode/uchar.h)
157  enum Direction {
158  U_LEFT_TO_RIGHT = 0,
159  U_RIGHT_TO_LEFT = 1,
160  U_EUROPEAN_NUMBER = 2,
161  U_EUROPEAN_NUMBER_SEPARATOR = 3,
162  U_EUROPEAN_NUMBER_TERMINATOR = 4,
163  U_ARABIC_NUMBER = 5,
164  U_COMMON_NUMBER_SEPARATOR = 6,
165  U_BLOCK_SEPARATOR = 7,
166  U_SEGMENT_SEPARATOR = 8,
167  U_WHITE_SPACE_NEUTRAL = 9,
168  U_OTHER_NEUTRAL = 10,
169  U_LEFT_TO_RIGHT_EMBEDDING = 11,
170  U_LEFT_TO_RIGHT_OVERRIDE = 12,
171  U_RIGHT_TO_LEFT_ARABIC = 13,
172  U_RIGHT_TO_LEFT_EMBEDDING = 14,
173  U_RIGHT_TO_LEFT_OVERRIDE = 15,
174  U_POP_DIRECTIONAL_FORMAT = 16,
175  U_DIR_NON_SPACING_MARK = 17,
176  U_BOUNDARY_NEUTRAL = 18,
177  U_CHAR_DIRECTION_COUNT
178  };
179 
180  // Create an empty UNICHARSET
181  UNICHARSET();
182 
183  ~UNICHARSET();
184 
185  // Return the UNICHAR_ID of a given unichar representation within the
186  // UNICHARSET.
187  UNICHAR_ID unichar_to_id(const char* const unichar_repr) const;
188 
189  // Return the UNICHAR_ID of a given unichar representation within the
190  // UNICHARSET. Only the first length characters from unichar_repr are used.
191  UNICHAR_ID unichar_to_id(const char* const unichar_repr, int length) const;
192 
193  // Return the minimum number of bytes that matches a legal UNICHAR_ID,
194  // while leaving the rest of the string encodable. Returns 0 if the
195  // beginning of the string is not encodable.
196  // WARNING: this function now encodes the whole string for precision.
197  // Use encode_string in preference to repeatedly calling step.
198  int step(const char* str) const;
199 
200  // Returns true if the given UTF-8 string is encodable with this UNICHARSET.
201  // If not encodable, write the first byte offset which cannot be converted
202  // into the second (return) argument.
203  bool encodable_string(const char *str, int *first_bad_position) const;
204 
205  // Encodes the given UTF-8 string with this UNICHARSET.
206  // Any part of the string that cannot be encoded (because the utf8 can't
207  // be broken up into pieces that are in the unicharset) then:
208  // if give_up_on_failure, stops and returns a partial encoding,
209  // else continues and inserts an INVALID_UNICHAR_ID in the returned encoding.
210  // Returns true if the encoding succeeds completely, false if there is at
211  // least one failure.
212  // If lengths is not NULL, then it is filled with the corresponding
213  // byte length of each encoded UNICHAR_ID.
214  // If encoded_length is not NULL then on return it contains the length of
215  // str that was encoded. (if give_up_on_failure the location of the first
216  // failure, otherwise strlen(str).)
217  // WARNING: Caller must guarantee that str has already been cleaned of codes
218  // that do not belong in the unicharset, or encoding may fail.
219  // Use CleanupString to perform the cleaning.
220  bool encode_string(const char* str, bool give_up_on_failure,
221  GenericVector<UNICHAR_ID>* encoding,
222  GenericVector<char>* lengths,
223  int* encoded_length) const;
224 
225  // Return the unichar representation corresponding to the given UNICHAR_ID
226  // within the UNICHARSET.
227  const char* id_to_unichar(UNICHAR_ID id) const;
228 
229  // Return the UTF8 representation corresponding to the given UNICHAR_ID after
230  // resolving any private encodings internal to Tesseract. This method is
231  // preferable to id_to_unichar for outputting text that will be visible to
232  // external applications.
233  const char* id_to_unichar_ext(UNICHAR_ID id) const;
234 
235  // Return a STRING that reformats the utf8 str into the str followed
236  // by its hex unicodes.
237  static STRING debug_utf8_str(const char* str);
238 
239  // Removes/replaces content that belongs in rendered text, but not in the
240  // unicharset.
241  static string CleanupString(const char* utf8_str) {
242  return CleanupString(utf8_str, strlen(utf8_str));
243  }
244  static string CleanupString(const char* utf8_str, int length);
245 
246  // Return a STRING containing debug information on the unichar, including
247  // the id_to_unichar, its hex unicodes and the properties.
248  STRING debug_str(UNICHAR_ID id) const;
249  STRING debug_str(const char * unichar_repr) const {
250  return debug_str(unichar_to_id(unichar_repr));
251  }
252 
253  // Adds a unichar representation to the set. If old_style is true, then
254  // TATWEEL characters are kept and n-grams are allowed. Otherwise TATWEEL
255  // characters are ignored/skipped as if they don't exist and n-grams that
256  // can already be encoded are not added.
257  void unichar_insert(const char* const unichar_repr,
258  OldUncleanUnichars old_style);
259  void unichar_insert(const char* const unichar_repr) {
260  unichar_insert(unichar_repr, OldUncleanUnichars::kFalse);
261  }
262  // Adds a unichar representation to the set. Avoids setting old_style to true,
263  // unless it is necessary to make the new unichar get added.
264  void unichar_insert_backwards_compatible(const char* const unichar_repr) {
265  string cleaned = CleanupString(unichar_repr);
266  if (cleaned != unichar_repr) {
267  unichar_insert(unichar_repr, OldUncleanUnichars::kTrue);
268  } else {
269  int old_size = size();
270  unichar_insert(unichar_repr, OldUncleanUnichars::kFalse);
271  if (size() == old_size) {
272  unichar_insert(unichar_repr, OldUncleanUnichars::kTrue);
273  }
274  }
275  }
276 
277  // Return true if the given unichar id exists within the set.
278  // Relies on the fact that unichar ids are contiguous in the unicharset.
279  bool contains_unichar_id(UNICHAR_ID unichar_id) const {
280  return unichar_id != INVALID_UNICHAR_ID && unichar_id < size_used &&
281  unichar_id >= 0;
282  }
283 
284  // Return true if the given unichar representation exists within the set.
285  bool contains_unichar(const char* const unichar_repr) const;
286  bool contains_unichar(const char* const unichar_repr, int length) const;
287 
288  // Return true if the given unichar representation corresponds to the given
289  // UNICHAR_ID within the set.
290  bool eq(UNICHAR_ID unichar_id, const char* const unichar_repr) const;
291 
292  // Delete CHAR_FRAGMENTs stored in properties of unichars array.
294  for (int i = 0; i < size_used; ++i) {
295  if (unichars[i].properties.fragment != NULL) {
296  delete unichars[i].properties.fragment;
297  unichars[i].properties.fragment = NULL;
298  }
299  }
300  }
301 
302  // Clear the UNICHARSET (all the previous data is lost).
303  void clear() {
304  if (script_table != NULL) {
305  for (int i = 0; i < script_table_size_used; ++i)
306  delete[] script_table[i];
307  delete[] script_table;
308  script_table = NULL;
309  script_table_size_used = 0;
310  }
311  if (unichars != NULL) {
312  delete_pointers_in_unichars();
313  delete[] unichars;
314  unichars = NULL;
315  }
316  script_table_size_reserved = 0;
317  size_reserved = 0;
318  size_used = 0;
319  ids.clear();
320  top_bottom_set_ = false;
321  script_has_upper_lower_ = false;
322  script_has_xheight_ = false;
323  old_style_included_ = false;
324  null_sid_ = 0;
325  common_sid_ = 0;
326  latin_sid_ = 0;
327  cyrillic_sid_ = 0;
328  greek_sid_ = 0;
329  han_sid_ = 0;
330  hiragana_sid_ = 0;
331  katakana_sid_ = 0;
332  thai_sid_ = 0;
333  hangul_sid_ = 0;
334  default_sid_ = 0;
335  }
336 
337  // Return the size of the set (the number of different UNICHAR it holds).
338  int size() const {
339  return size_used;
340  }
341 
342  // Reserve enough memory space for the given number of UNICHARS
343  void reserve(int unichars_number);
344 
345  // Opens the file indicated by filename and saves unicharset to that file.
346  // Returns true if the operation is successful.
347  bool save_to_file(const char * const filename) const {
348  FILE* file = fopen(filename, "w+b");
349  if (file == NULL) return false;
350  bool result = save_to_file(file);
351  fclose(file);
352  return result;
353  }
354 
355  // Saves the content of the UNICHARSET to the given file.
356  // Returns true if the operation is successful.
357  bool save_to_file(FILE *file) const {
358  STRING str;
359  if (!save_to_string(&str)) return false;
360  if (fwrite(&str[0], str.length(), 1, file) != 1) return false;
361  return true;
362  }
363  bool save_to_file(tesseract::TFile *file) const {
364  STRING str;
365  if (!save_to_string(&str)) return false;
366  if (file->FWrite(&str[0], str.length(), 1) != 1) return false;
367  return true;
368  }
369 
370  // Saves the content of the UNICHARSET to the given STRING.
371  // Returns true if the operation is successful.
372  bool save_to_string(STRING *str) const;
373 
374  // Load a unicharset from a unicharset file that has been loaded into
375  // the given memory buffer.
376  // Returns true if the operation is successful.
377  bool load_from_inmemory_file(const char* const memory, int mem_size,
378  bool skip_fragments);
379  // Returns true if the operation is successful.
380  bool load_from_inmemory_file(const char* const memory, int mem_size) {
381  return load_from_inmemory_file(memory, mem_size, false);
382  }
383 
384  // Opens the file indicated by filename and loads the UNICHARSET
385  // from the given file. The previous data is lost.
386  // Returns true if the operation is successful.
387  bool load_from_file(const char* const filename, bool skip_fragments) {
388  FILE* file = fopen(filename, "rb");
389  if (file == NULL) return false;
390  bool result = load_from_file(file, skip_fragments);
391  fclose(file);
392  return result;
393  }
394  // returns true if the operation is successful.
395  bool load_from_file(const char* const filename) {
396  return load_from_file(filename, false);
397  }
398 
399  // Loads the UNICHARSET from the given file. The previous data is lost.
400  // Returns true if the operation is successful.
401  bool load_from_file(FILE *file, bool skip_fragments);
402  bool load_from_file(FILE *file) { return load_from_file(file, false); }
403  bool load_from_file(tesseract::TFile *file, bool skip_fragments);
404 
405 
406  // Sets up internal data after loading the file, based on the char
407  // properties. Called from load_from_file, but also needs to be run
408  // during set_unicharset_properties.
409  void post_load_setup();
410 
411  // Returns true if right_to_left scripts are significant in the unicharset,
412  // but without being so sensitive that "universal" unicharsets containing
413  // characters from many scripts, like orientation and script detection,
414  // look like they are right_to_left.
415  bool major_right_to_left() const;
416 
417  // Set a whitelist and/or blacklist of characters to recognize.
418  // An empty or NULL whitelist enables everything (minus any blacklist).
419  // An empty or NULL blacklist disables nothing.
420  // An empty or NULL unblacklist has no effect.
421  // The blacklist overrides the whitelist.
422  // The unblacklist overrides the blacklist.
423  // Each list is a string of utf8 character strings. Boundaries between
424  // unicharset units are worked out automatically, and characters not in
425  // the unicharset are silently ignored.
426  void set_black_and_whitelist(const char* blacklist, const char* whitelist,
427  const char* unblacklist);
428 
429  // Set the isalpha property of the given unichar to the given value.
430  void set_isalpha(UNICHAR_ID unichar_id, bool value) {
431  unichars[unichar_id].properties.isalpha = value;
432  }
433 
434  // Set the islower property of the given unichar to the given value.
435  void set_islower(UNICHAR_ID unichar_id, bool value) {
436  unichars[unichar_id].properties.islower = value;
437  }
438 
439  // Set the isupper property of the given unichar to the given value.
440  void set_isupper(UNICHAR_ID unichar_id, bool value) {
441  unichars[unichar_id].properties.isupper = value;
442  }
443 
444  // Set the isdigit property of the given unichar to the given value.
445  void set_isdigit(UNICHAR_ID unichar_id, bool value) {
446  unichars[unichar_id].properties.isdigit = value;
447  }
448 
449  // Set the ispunctuation property of the given unichar to the given value.
450  void set_ispunctuation(UNICHAR_ID unichar_id, bool value) {
451  unichars[unichar_id].properties.ispunctuation = value;
452  }
453 
454  // Set the isngram property of the given unichar to the given value.
455  void set_isngram(UNICHAR_ID unichar_id, bool value) {
456  unichars[unichar_id].properties.isngram = value;
457  }
458 
459  // Set the script name of the given unichar to the given value.
460  // Value is copied and thus can be a temporary;
461  void set_script(UNICHAR_ID unichar_id, const char* value) {
462  unichars[unichar_id].properties.script_id = add_script(value);
463  }
464 
465  // Set other_case unichar id in the properties for the given unichar id.
466  void set_other_case(UNICHAR_ID unichar_id, UNICHAR_ID other_case) {
467  unichars[unichar_id].properties.other_case = other_case;
468  }
469 
470  // Set the direction property of the given unichar to the given value.
472  unichars[unichar_id].properties.direction = value;
473  }
474 
475  // Set mirror unichar id in the properties for the given unichar id.
476  void set_mirror(UNICHAR_ID unichar_id, UNICHAR_ID mirror) {
477  unichars[unichar_id].properties.mirror = mirror;
478  }
479 
480  // Record normalized version of unichar with the given unichar_id.
481  void set_normed(UNICHAR_ID unichar_id, const char* normed) {
482  unichars[unichar_id].properties.normed = normed;
483  unichars[unichar_id].properties.normed_ids.truncate(0);
484  }
485  // Sets the normed_ids vector from the normed string. normed_ids is not
486  // stored in the file, and needs to be set when the UNICHARSET is loaded.
487  void set_normed_ids(UNICHAR_ID unichar_id);
488 
489  // Return the isalpha property of the given unichar.
490  bool get_isalpha(UNICHAR_ID unichar_id) const {
491  if (INVALID_UNICHAR_ID == unichar_id) return false;
492  ASSERT_HOST(contains_unichar_id(unichar_id));
493  return unichars[unichar_id].properties.isalpha;
494  }
495 
496  // Return the islower property of the given unichar.
497  bool get_islower(UNICHAR_ID unichar_id) const {
498  if (INVALID_UNICHAR_ID == unichar_id) return false;
499  ASSERT_HOST(contains_unichar_id(unichar_id));
500  return unichars[unichar_id].properties.islower;
501  }
502 
503  // Return the isupper property of the given unichar.
504  bool get_isupper(UNICHAR_ID unichar_id) const {
505  if (INVALID_UNICHAR_ID == unichar_id) return false;
506  ASSERT_HOST(contains_unichar_id(unichar_id));
507  return unichars[unichar_id].properties.isupper;
508  }
509 
510  // Return the isdigit property of the given unichar.
511  bool get_isdigit(UNICHAR_ID unichar_id) const {
512  if (INVALID_UNICHAR_ID == unichar_id) return false;
513  ASSERT_HOST(contains_unichar_id(unichar_id));
514  return unichars[unichar_id].properties.isdigit;
515  }
516 
517  // Return the ispunctuation property of the given unichar.
518  bool get_ispunctuation(UNICHAR_ID unichar_id) const {
519  if (INVALID_UNICHAR_ID == unichar_id) return false;
520  ASSERT_HOST(contains_unichar_id(unichar_id));
521  return unichars[unichar_id].properties.ispunctuation;
522  }
523 
524  // Return the isngram property of the given unichar.
525  bool get_isngram(UNICHAR_ID unichar_id) const {
526  if (INVALID_UNICHAR_ID == unichar_id) return false;
527  ASSERT_HOST(contains_unichar_id(unichar_id));
528  return unichars[unichar_id].properties.isngram;
529  }
530 
531  // Returns whether the unichar id represents a unicode value in the private
532  // use area.
533  bool get_isprivate(UNICHAR_ID unichar_id) const;
534 
535  // Returns true if the ids have useful min/max top/bottom values.
536  bool top_bottom_useful() const {
537  return top_bottom_set_;
538  }
539  // Sets all ranges to empty, so they can be expanded to set the values.
540  void set_ranges_empty();
541  // Sets all the properties for this unicharset given a src_unicharset with
542  // everything set. The unicharsets don't have to be the same, and graphemes
543  // are correctly accounted for.
545  PartialSetPropertiesFromOther(0, src);
546  }
547  // Sets properties from Other, starting only at the given index.
548  void PartialSetPropertiesFromOther(int start_index, const UNICHARSET& src);
549  // Expands the tops and bottoms and widths for this unicharset given a
550  // src_unicharset with ranges in it. The unicharsets don't have to be the
551  // same, and graphemes are correctly accounted for.
552  void ExpandRangesFromOther(const UNICHARSET& src);
553  // Makes this a copy of src. Clears this completely first, so the automattic
554  // ids will not be present in this if not in src.
555  void CopyFrom(const UNICHARSET& src);
556  // For each id in src, if it does not occur in this, add it, as in
557  // SetPropertiesFromOther, otherwise expand the ranges, as in
558  // ExpandRangesFromOther.
559  void AppendOtherUnicharset(const UNICHARSET& src);
560  // Returns true if the acceptable ranges of the tops of the characters do
561  // not overlap, making their x-height calculations distinct.
562  bool SizesDistinct(UNICHAR_ID id1, UNICHAR_ID id2) const;
563  // Returns the min and max bottom and top of the given unichar in
564  // baseline-normalized coordinates, ie, where the baseline is
565  // kBlnBaselineOffset and the meanline is kBlnBaselineOffset + kBlnXHeight
566  // (See normalis.h for the definitions).
567  void get_top_bottom(UNICHAR_ID unichar_id,
568  int* min_bottom, int* max_bottom,
569  int* min_top, int* max_top) const {
570  if (INVALID_UNICHAR_ID == unichar_id) {
571  *min_bottom = *min_top = 0;
572  *max_bottom = *max_top = 256; // kBlnCellHeight
573  return;
574  }
575  ASSERT_HOST(contains_unichar_id(unichar_id));
576  *min_bottom = unichars[unichar_id].properties.min_bottom;
577  *max_bottom = unichars[unichar_id].properties.max_bottom;
578  *min_top = unichars[unichar_id].properties.min_top;
579  *max_top = unichars[unichar_id].properties.max_top;
580  }
581  void set_top_bottom(UNICHAR_ID unichar_id,
582  int min_bottom, int max_bottom,
583  int min_top, int max_top) {
584  unichars[unichar_id].properties.min_bottom =
585  static_cast<uinT8>(ClipToRange(min_bottom, 0, MAX_UINT8));
586  unichars[unichar_id].properties.max_bottom =
587  static_cast<uinT8>(ClipToRange(max_bottom, 0, MAX_UINT8));
588  unichars[unichar_id].properties.min_top =
589  static_cast<uinT8>(ClipToRange(min_top, 0, MAX_UINT8));
590  unichars[unichar_id].properties.max_top =
591  static_cast<uinT8>(ClipToRange(max_top, 0, MAX_UINT8));
592  }
593  // Returns the width stats (as mean, sd) of the given unichar relative to the
594  // median advance of all characters in the character set.
595  void get_width_stats(UNICHAR_ID unichar_id,
596  float* width, float* width_sd) const {
597  if (INVALID_UNICHAR_ID == unichar_id) {
598  *width = 0.0f;
599  *width_sd = 0.0f;;
600  return;
601  }
602  ASSERT_HOST(contains_unichar_id(unichar_id));
603  *width = unichars[unichar_id].properties.width;
604  *width_sd = unichars[unichar_id].properties.width_sd;
605  }
606  void set_width_stats(UNICHAR_ID unichar_id, float width, float width_sd) {
607  unichars[unichar_id].properties.width = width;
608  unichars[unichar_id].properties.width_sd = width_sd;
609  }
610  // Returns the stats of the x-bearing (as mean, sd) of the given unichar
611  // relative to the median advance of all characters in the character set.
612  void get_bearing_stats(UNICHAR_ID unichar_id,
613  float* bearing, float* bearing_sd) const {
614  if (INVALID_UNICHAR_ID == unichar_id) {
615  *bearing = *bearing_sd = 0.0f;
616  return;
617  }
618  ASSERT_HOST(contains_unichar_id(unichar_id));
619  *bearing = unichars[unichar_id].properties.bearing;
620  *bearing_sd = unichars[unichar_id].properties.bearing_sd;
621  }
622  void set_bearing_stats(UNICHAR_ID unichar_id,
623  float bearing, float bearing_sd) {
624  unichars[unichar_id].properties.bearing = bearing;
625  unichars[unichar_id].properties.bearing_sd = bearing_sd;
626  }
627  // Returns the stats of the x-advance of the given unichar (as mean, sd)
628  // relative to the median advance of all characters in the character set.
629  void get_advance_stats(UNICHAR_ID unichar_id,
630  float* advance, float* advance_sd) const {
631  if (INVALID_UNICHAR_ID == unichar_id) {
632  *advance = *advance_sd = 0;
633  return;
634  }
635  ASSERT_HOST(contains_unichar_id(unichar_id));
636  *advance = unichars[unichar_id].properties.advance;
637  *advance_sd = unichars[unichar_id].properties.advance_sd;
638  }
639  void set_advance_stats(UNICHAR_ID unichar_id,
640  float advance, float advance_sd) {
641  unichars[unichar_id].properties.advance = advance;
642  unichars[unichar_id].properties.advance_sd = advance_sd;
643  }
644  // Returns true if the font metrics properties are empty.
645  bool PropertiesIncomplete(UNICHAR_ID unichar_id) const {
646  return unichars[unichar_id].properties.AnyRangeEmpty();
647  }
648 
649  // Returns true if the script of the given id is space delimited.
650  // Returns false for Han and Thai scripts.
651  bool IsSpaceDelimited(UNICHAR_ID unichar_id) const {
652  if (INVALID_UNICHAR_ID == unichar_id) return true;
653  int script_id = get_script(unichar_id);
654  return script_id != han_sid_ && script_id != thai_sid_ &&
655  script_id != hangul_sid_ && script_id != hiragana_sid_ &&
656  script_id != katakana_sid_;
657  }
658 
659  // Return the script name of the given unichar.
660  // The returned pointer will always be the same for the same script, it's
661  // managed by unicharset and thus MUST NOT be deleted
662  int get_script(UNICHAR_ID unichar_id) const {
663  if (INVALID_UNICHAR_ID == unichar_id) return null_sid_;
664  ASSERT_HOST(contains_unichar_id(unichar_id));
665  return unichars[unichar_id].properties.script_id;
666  }
667 
668  // Return the character properties, eg. alpha/upper/lower/digit/punct,
669  // as a bit field of unsigned int.
670  unsigned int get_properties(UNICHAR_ID unichar_id) const;
671 
672  // Return the character property as a single char. If a character has
673  // multiple attributes, the main property is defined by the following order:
674  // upper_case : 'A'
675  // lower_case : 'a'
676  // alpha : 'x'
677  // digit : '0'
678  // punctuation: 'p'
679  char get_chartype(UNICHAR_ID unichar_id) const;
680 
681  // Get other_case unichar id in the properties for the given unichar id.
683  if (INVALID_UNICHAR_ID == unichar_id) return INVALID_UNICHAR_ID;
684  ASSERT_HOST(contains_unichar_id(unichar_id));
685  return unichars[unichar_id].properties.other_case;
686  }
687 
688  // Returns the direction property of the given unichar.
689  Direction get_direction(UNICHAR_ID unichar_id) const {
690  if (INVALID_UNICHAR_ID == unichar_id) return UNICHARSET::U_OTHER_NEUTRAL;
691  ASSERT_HOST(contains_unichar_id(unichar_id));
692  return unichars[unichar_id].properties.direction;
693  }
694 
695  // Get mirror unichar id in the properties for the given unichar id.
696  UNICHAR_ID get_mirror(UNICHAR_ID unichar_id) const {
697  if (INVALID_UNICHAR_ID == unichar_id) return INVALID_UNICHAR_ID;
698  ASSERT_HOST(contains_unichar_id(unichar_id));
699  return unichars[unichar_id].properties.mirror;
700  }
701 
702  // Returns UNICHAR_ID of the corresponding lower-case unichar.
703  UNICHAR_ID to_lower(UNICHAR_ID unichar_id) const {
704  if (INVALID_UNICHAR_ID == unichar_id) return INVALID_UNICHAR_ID;
705  ASSERT_HOST(contains_unichar_id(unichar_id));
706  if (unichars[unichar_id].properties.islower) return unichar_id;
707  return unichars[unichar_id].properties.other_case;
708  }
709 
710  // Returns UNICHAR_ID of the corresponding upper-case unichar.
711  UNICHAR_ID to_upper(UNICHAR_ID unichar_id) const {
712  if (INVALID_UNICHAR_ID == unichar_id) return INVALID_UNICHAR_ID;
713  ASSERT_HOST(contains_unichar_id(unichar_id));
714  if (unichars[unichar_id].properties.isupper) return unichar_id;
715  return unichars[unichar_id].properties.other_case;
716  }
717 
718  // Returns true if this UNICHARSET has the special codes in
719  // SpecialUnicharCodes available. If false then there are normal unichars
720  // at these codes and they should not be used.
721  bool has_special_codes() const {
722  return get_fragment(UNICHAR_BROKEN) != NULL &&
723  strcmp(id_to_unichar(UNICHAR_BROKEN),
724  kSpecialUnicharCodes[UNICHAR_BROKEN]) == 0;
725  }
726 
727  // Returns true if there are any repeated unicodes in the normalized
728  // text of any unichar-id in the unicharset.
729  bool AnyRepeatedUnicodes() const;
730 
731  // Return a pointer to the CHAR_FRAGMENT class if the given
732  // unichar id represents a character fragment.
733  const CHAR_FRAGMENT *get_fragment(UNICHAR_ID unichar_id) const {
734  if (INVALID_UNICHAR_ID == unichar_id) return NULL;
735  ASSERT_HOST(contains_unichar_id(unichar_id));
736  return unichars[unichar_id].properties.fragment;
737  }
738 
739  // Return the isalpha property of the given unichar representation.
740  bool get_isalpha(const char* const unichar_repr) const {
741  return get_isalpha(unichar_to_id(unichar_repr));
742  }
743 
744  // Return the islower property of the given unichar representation.
745  bool get_islower(const char* const unichar_repr) const {
746  return get_islower(unichar_to_id(unichar_repr));
747  }
748 
749  // Return the isupper property of the given unichar representation.
750  bool get_isupper(const char* const unichar_repr) const {
751  return get_isupper(unichar_to_id(unichar_repr));
752  }
753 
754  // Return the isdigit property of the given unichar representation.
755  bool get_isdigit(const char* const unichar_repr) const {
756  return get_isdigit(unichar_to_id(unichar_repr));
757  }
758 
759  // Return the ispunctuation property of the given unichar representation.
760  bool get_ispunctuation(const char* const unichar_repr) const {
761  return get_ispunctuation(unichar_to_id(unichar_repr));
762  }
763 
764  // Return the character properties, eg. alpha/upper/lower/digit/punct,
765  // of the given unichar representation
766  unsigned int get_properties(const char* const unichar_repr) const {
767  return get_properties(unichar_to_id(unichar_repr));
768  }
769 
770  char get_chartype(const char* const unichar_repr) const {
771  return get_chartype(unichar_to_id(unichar_repr));
772  }
773 
774  // Return the script name of the given unichar representation.
775  // The returned pointer will always be the same for the same script, it's
776  // managed by unicharset and thus MUST NOT be deleted
777  int get_script(const char* const unichar_repr) const {
778  return get_script(unichar_to_id(unichar_repr));
779  }
780 
781  // Return a pointer to the CHAR_FRAGMENT class struct if the given
782  // unichar representation represents a character fragment.
783  const CHAR_FRAGMENT *get_fragment(const char* const unichar_repr) const {
784  if (unichar_repr == NULL || unichar_repr[0] == '\0' ||
785  !ids.contains(unichar_repr, false)) {
786  return NULL;
787  }
788  return get_fragment(unichar_to_id(unichar_repr));
789  }
790 
791  // Return the isalpha property of the given unichar representation.
792  // Only the first length characters from unichar_repr are used.
793  bool get_isalpha(const char* const unichar_repr,
794  int length) const {
795  return get_isalpha(unichar_to_id(unichar_repr, length));
796  }
797 
798  // Return the islower property of the given unichar representation.
799  // Only the first length characters from unichar_repr are used.
800  bool get_islower(const char* const unichar_repr,
801  int length) const {
802  return get_islower(unichar_to_id(unichar_repr, length));
803  }
804 
805  // Return the isupper property of the given unichar representation.
806  // Only the first length characters from unichar_repr are used.
807  bool get_isupper(const char* const unichar_repr,
808  int length) const {
809  return get_isupper(unichar_to_id(unichar_repr, length));
810  }
811 
812  // Return the isdigit property of the given unichar representation.
813  // Only the first length characters from unichar_repr are used.
814  bool get_isdigit(const char* const unichar_repr,
815  int length) const {
816  return get_isdigit(unichar_to_id(unichar_repr, length));
817  }
818 
819  // Return the ispunctuation property of the given unichar representation.
820  // Only the first length characters from unichar_repr are used.
821  bool get_ispunctuation(const char* const unichar_repr,
822  int length) const {
823  return get_ispunctuation(unichar_to_id(unichar_repr, length));
824  }
825 
826  // Returns normalized version of unichar with the given unichar_id.
827  const char *get_normed_unichar(UNICHAR_ID unichar_id) const {
828  if (unichar_id == UNICHAR_SPACE) return " ";
829  return unichars[unichar_id].properties.normed.string();
830  }
831  // Returns a vector of UNICHAR_IDs that represent the ids of the normalized
832  // version of the given id. There may be more than one UNICHAR_ID in the
833  // vector if unichar_id represents a ligature.
835  return unichars[unichar_id].properties.normed_ids;
836  }
837 
838  // Return the script name of the given unichar representation.
839  // Only the first length characters from unichar_repr are used.
840  // The returned pointer will always be the same for the same script, it's
841  // managed by unicharset and thus MUST NOT be deleted
842  int get_script(const char* const unichar_repr,
843  int length) const {
844  return get_script(unichar_to_id(unichar_repr, length));
845  }
846 
847  // Return the (current) number of scripts in the script table
848  int get_script_table_size() const {
849  return script_table_size_used;
850  }
851 
852  // Return the script string from its id
853  const char* get_script_from_script_id(int id) const {
854  if (id >= script_table_size_used || id < 0)
855  return null_script;
856  return script_table[id];
857  }
858 
859  // Returns the id from the name of the script, or 0 if script is not found.
860  // Note that this is an expensive operation since it involves iteratively
861  // comparing strings in the script table. To avoid dependency on STL, we
862  // won't use a hash. Instead, the calling function can use this to lookup
863  // and save the ID for relevant scripts for fast comparisons later.
864  int get_script_id_from_name(const char* script_name) const;
865 
866  // Return true if the given script is the null script
867  bool is_null_script(const char* script) const {
868  return script == null_script;
869  }
870 
871  // Uniquify the given script. For two scripts a and b, if strcmp(a, b) == 0,
872  // then the returned pointer will be the same.
873  // The script parameter is copied and thus can be a temporary.
874  int add_script(const char* script);
875 
876  // Return the enabled property of the given unichar.
877  bool get_enabled(UNICHAR_ID unichar_id) const {
878  return unichars[unichar_id].properties.enabled;
879  }
880 
881 
882  int null_sid() const { return null_sid_; }
883  int common_sid() const { return common_sid_; }
884  int latin_sid() const { return latin_sid_; }
885  int cyrillic_sid() const { return cyrillic_sid_; }
886  int greek_sid() const { return greek_sid_; }
887  int han_sid() const { return han_sid_; }
888  int hiragana_sid() const { return hiragana_sid_; }
889  int katakana_sid() const { return katakana_sid_; }
890  int thai_sid() const { return thai_sid_; }
891  int hangul_sid() const { return hangul_sid_; }
892  int default_sid() const { return default_sid_; }
893 
894  // Returns true if the unicharset has the concept of upper/lower case.
895  bool script_has_upper_lower() const {
896  return script_has_upper_lower_;
897  }
898  // Returns true if the unicharset has the concept of x-height.
899  // script_has_xheight can be true even if script_has_upper_lower is not,
900  // when the script has a sufficiently predominant top line with ascenders,
901  // such as Devanagari and Thai.
902  bool script_has_xheight() const {
903  return script_has_xheight_;
904  }
905 
906  private:
907 
908  struct UNICHAR_PROPERTIES {
909  UNICHAR_PROPERTIES();
910  // Initializes all properties to sensible default values.
911  void Init();
912  // Sets all ranges wide open. Initialization default in case there are
913  // no useful values available.
914  void SetRangesOpen();
915  // Sets all ranges to empty. Used before expanding with font-based data.
916  void SetRangesEmpty();
917  // Returns true if any of the top/bottom/width/bearing/advance ranges/stats
918  // is emtpy.
919  bool AnyRangeEmpty() const;
920  // Expands the ranges with the ranges from the src properties.
921  void ExpandRangesFrom(const UNICHAR_PROPERTIES& src);
922  // Copies the properties from src into this.
923  void CopyFrom(const UNICHAR_PROPERTIES& src);
924 
925  bool isalpha;
926  bool islower;
927  bool isupper;
928  bool isdigit;
929  bool ispunctuation;
930  bool isngram;
931  bool enabled;
932  // Possible limits of the top and bottom of the bounding box in
933  // baseline-normalized coordinates, ie, where the baseline is
934  // kBlnBaselineOffset and the meanline is kBlnBaselineOffset + kBlnXHeight
935  // (See normalis.h for the definitions).
936  uinT8 min_bottom;
937  uinT8 max_bottom;
938  uinT8 min_top;
939  uinT8 max_top;
940  // Statstics of the widths of bounding box, relative to the median advance.
941  float width;
942  float width_sd;
943  // Stats of the x-bearing and advance, also relative to the median advance.
944  float bearing;
945  float bearing_sd;
946  float advance;
947  float advance_sd;
948  int script_id;
949  UNICHAR_ID other_case; // id of the corresponding upper/lower case unichar
950  Direction direction; // direction of this unichar
951  // Mirror property is useful for reverse DAWG lookup for words in
952  // right-to-left languages (e.g. "(word)" would be in
953  // '[open paren]' 'w' 'o' 'r' 'd' '[close paren]' in a UTF8 string.
954  // However, what we want in our DAWG is
955  // '[open paren]', 'd', 'r', 'o', 'w', '[close paren]' not
956  // '[close paren]', 'd', 'r', 'o', 'w', '[open paren]'.
957  UNICHAR_ID mirror;
958  // A string of unichar_ids that represent the corresponding normed string.
959  // For awkward characters like em-dash, this gives hyphen.
960  // For ligatures, this gives the string of normal unichars.
961  GenericVector<UNICHAR_ID> normed_ids;
962  STRING normed; // normalized version of this unichar
963  // Contains meta information about the fragment if a unichar represents
964  // a fragment of a character, otherwise should be set to NULL.
965  // It is assumed that character fragments are added to the unicharset
966  // after the corresponding 'base' characters.
967  CHAR_FRAGMENT *fragment;
968  };
969 
970  struct UNICHAR_SLOT {
971  char representation[UNICHAR_LEN + 1];
972  UNICHAR_PROPERTIES properties;
973  };
974 
975  // Internal recursive version of encode_string above.
976  // str is the start of the whole string.
977  // str_index is the current position in str.
978  // str_length is the length of str.
979  // encoding is a working encoding of str.
980  // lengths is a working set of lengths of each element of encoding.
981  // best_total_length is the longest length of str that has been successfully
982  // encoded so far.
983  // On return:
984  // best_encoding contains the encoding that used the longest part of str.
985  // best_lengths (may be null) contains the lengths of best_encoding.
986  void encode_string(const char* str, int str_index, int str_length,
987  GenericVector<UNICHAR_ID>* encoding,
988  GenericVector<char>* lengths,
989  int* best_total_length,
990  GenericVector<UNICHAR_ID>* best_encoding,
991  GenericVector<char>* best_lengths) const;
992 
993  // Gets the properties for a grapheme string, combining properties for
994  // multiple characters in a meaningful way where possible.
995  // Returns false if no valid match was found in the unicharset.
996  // NOTE that script_id, mirror, and other_case refer to this unicharset on
997  // return and will need redirecting if the target unicharset is different.
998  bool GetStrProperties(const char* utf8_str,
999  UNICHAR_PROPERTIES* props) const;
1000 
1001  // Load ourselves from a "file" where our only interface to the file is
1002  // an implementation of fgets(). This is the parsing primitive accessed by
1003  // the public routines load_from_file() and load_from_inmemory_file().
1004  bool load_via_fgets(TessResultCallback2<char *, char *, int> *fgets_cb,
1005  bool skip_fragments);
1006 
1007  // List of mappings to make when ingesting strings from the outside.
1008  // The substitutions clean up text that should exists for rendering of
1009  // synthetic data, but not in the recognition set.
1010  static const char* kCleanupMaps[][2];
1011 
1012  UNICHAR_SLOT* unichars;
1013  UNICHARMAP ids;
1014  int size_used;
1015  int size_reserved;
1016  char** script_table;
1017  int script_table_size_used;
1018  int script_table_size_reserved;
1019  const char* null_script;
1020  // True if the unichars have their tops/bottoms set.
1021  bool top_bottom_set_;
1022  // True if the unicharset has significant upper/lower case chars.
1023  bool script_has_upper_lower_;
1024  // True if the unicharset has a significant mean-line with significant
1025  // ascenders above that.
1026  bool script_has_xheight_;
1027  // True if the set contains chars that would be changed by the cleanup.
1028  bool old_style_included_;
1029 
1030  // A few convenient script name-to-id mapping without using hash.
1031  // These are initialized when unicharset file is loaded. Anything
1032  // missing from this list can be looked up using get_script_id_from_name.
1033  int null_sid_;
1034  int common_sid_;
1035  int latin_sid_;
1036  int cyrillic_sid_;
1037  int greek_sid_;
1038  int han_sid_;
1039  int hiragana_sid_;
1040  int katakana_sid_;
1041  int thai_sid_;
1042  int hangul_sid_;
1043  // The most frequently occurring script in the charset.
1044  int default_sid_;
1045 };
1046 
1047 #endif // TESSERACT_CCUTIL_UNICHARSET_H_
void set_ispunctuation(UNICHAR_ID unichar_id, bool value)
Definition: unicharset.h:450
unsigned int get_properties(const char *const unichar_repr) const
Definition: unicharset.h:766
int FWrite(const void *buffer, int size, int count)
Definition: serialis.cpp:148
void delete_pointers_in_unichars()
Definition: unicharset.h:293
void set_bearing_stats(UNICHAR_ID unichar_id, float bearing, float bearing_sd)
Definition: unicharset.h:622
void set_islower(UNICHAR_ID unichar_id, bool value)
Definition: unicharset.h:435
int han_sid() const
Definition: unicharset.h:887
void get_top_bottom(UNICHAR_ID unichar_id, int *min_bottom, int *max_bottom, int *min_top, int *max_top) const
Definition: unicharset.h:567
void set_normed(UNICHAR_ID unichar_id, const char *normed)
Definition: unicharset.h:481
bool get_ispunctuation(UNICHAR_ID unichar_id) const
Definition: unicharset.h:518
void set_direction(UNICHAR_ID unichar_id, UNICHARSET::Direction value)
Definition: unicharset.h:471
bool is_continuation_of(const CHAR_FRAGMENT *fragment) const
Definition: unicharset.h:99
void SetPropertiesFromOther(const UNICHARSET &src)
Definition: unicharset.h:544
void set_isdigit(UNICHAR_ID unichar_id, bool value)
Definition: unicharset.h:445
STRING debug_str(const char *unichar_repr) const
Definition: unicharset.h:249
int get_total() const
Definition: unicharset.h:73
bool script_has_upper_lower() const
Definition: unicharset.h:895
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:511
void set_advance_stats(UNICHAR_ID unichar_id, float advance, float advance_sd)
Definition: unicharset.h:639
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:490
bool load_from_inmemory_file(const char *const memory, int mem_size)
Definition: unicharset.h:380
bool get_isalpha(const char *const unichar_repr) const
Definition: unicharset.h:740
const char * get_script_from_script_id(int id) const
Definition: unicharset.h:853
int greek_sid() const
Definition: unicharset.h:886
char get_chartype(const char *const unichar_repr) const
Definition: unicharset.h:770
int get_script(const char *const unichar_repr, int length) const
Definition: unicharset.h:842
int16_t inT16
Definition: host.h:36
int katakana_sid() const
Definition: unicharset.h:889
SpecialUnicharCodes
Definition: unicharset.h:34
int cyrillic_sid() const
Definition: unicharset.h:885
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:122
bool is_null_script(const char *script) const
Definition: unicharset.h:867
void set_pos(int p)
Definition: unicharset.h:69
#define MAX_UINT8
Definition: host.h:63
void get_advance_stats(UNICHAR_ID unichar_id, float *advance, float *advance_sd) const
Definition: unicharset.h:629
bool get_islower(const char *const unichar_repr, int length) const
Definition: unicharset.h:800
bool save_to_file(tesseract::TFile *file) const
Definition: unicharset.h:363
bool get_isalpha(const char *const unichar_repr, int length) const
Definition: unicharset.h:793
OldUncleanUnichars
Definition: unicharset.h:44
static string CleanupString(const char *utf8_str)
Definition: unicharset.h:241
void set_isngram(UNICHAR_ID unichar_id, bool value)
Definition: unicharset.h:455
bool script_has_xheight() const
Definition: unicharset.h:902
int direction(EDGEPT *point)
Definition: vecfuncs.cpp:43
bool get_enabled(UNICHAR_ID unichar_id) const
Definition: unicharset.h:877
bool get_ispunctuation(const char *const unichar_repr, int length) const
Definition: unicharset.h:821
int hiragana_sid() const
Definition: unicharset.h:888
const CHAR_FRAGMENT * get_fragment(UNICHAR_ID unichar_id) const
Definition: unicharset.h:733
bool save_to_file(const char *const filename) const
Definition: unicharset.h:347
bool IsSpaceDelimited(UNICHAR_ID unichar_id) const
Definition: unicharset.h:651
uint8_t uinT8
Definition: host.h:35
STRING to_string() const
Definition: unicharset.h:80
int common_sid() const
Definition: unicharset.h:883
int get_script(const char *const unichar_repr) const
Definition: unicharset.h:777
bool get_isupper(const char *const unichar_repr) const
Definition: unicharset.h:750
UNICHAR_ID get_other_case(UNICHAR_ID unichar_id) const
Definition: unicharset.h:682
int size() const
Definition: unicharset.h:338
bool has_special_codes() const
Definition: unicharset.h:721
void set_isupper(UNICHAR_ID unichar_id, bool value)
Definition: unicharset.h:440
const char * get_normed_unichar(UNICHAR_ID unichar_id) const
Definition: unicharset.h:827
Direction get_direction(UNICHAR_ID unichar_id) const
Definition: unicharset.h:689
bool get_islower(UNICHAR_ID unichar_id) const
Definition: unicharset.h:497
bool PropertiesIncomplete(UNICHAR_ID unichar_id) const
Definition: unicharset.h:645
int thai_sid() const
Definition: unicharset.h:890
void set_all(const char *unichar, int pos, int total, bool natural)
Definition: unicharset.h:59
void get_width_stats(UNICHAR_ID unichar_id, float *width, float *width_sd) const
Definition: unicharset.h:595
void set_mirror(UNICHAR_ID unichar_id, UNICHAR_ID mirror)
Definition: unicharset.h:476
int get_pos() const
Definition: unicharset.h:72
Definition: strngs.h:45
void unichar_insert_backwards_compatible(const char *const unichar_repr)
Definition: unicharset.h:264
bool get_ispunctuation(const char *const unichar_repr) const
Definition: unicharset.h:760
bool get_isdigit(const char *const unichar_repr, int length) const
Definition: unicharset.h:814
int latin_sid() const
Definition: unicharset.h:884
#define UNICHAR_LEN
Definition: unichar.h:31
bool is_natural() const
Definition: unicharset.h:114
bool get_isupper(UNICHAR_ID unichar_id) const
Definition: unicharset.h:504
bool get_isngram(UNICHAR_ID unichar_id) const
Definition: unicharset.h:525
bool save_to_file(FILE *file) const
Definition: unicharset.h:357
#define ASSERT_HOST(x)
Definition: errcode.h:84
UNICHAR_ID to_lower(UNICHAR_ID unichar_id) const
Definition: unicharset.h:703
bool top_bottom_useful() const
Definition: unicharset.h:536
const CHAR_FRAGMENT * get_fragment(const char *const unichar_repr) const
Definition: unicharset.h:783
int hangul_sid() const
Definition: unicharset.h:891
const char * get_unichar() const
Definition: unicharset.h:71
bool load_from_file(const char *const filename, bool skip_fragments)
Definition: unicharset.h:387
void set_script(UNICHAR_ID unichar_id, const char *value)
Definition: unicharset.h:461
void clear()
Definition: unicharset.h:303
int default_sid() const
Definition: unicharset.h:892
bool get_islower(const char *const unichar_repr) const
Definition: unicharset.h:745
bool equals(const CHAR_FRAGMENT *other) const
Definition: unicharset.h:91
void set_natural(bool value)
Definition: unicharset.h:115
#define TESS_API
Definition: platform.h:87
bool is_ending() const
Definition: unicharset.h:109
bool get_isdigit(const char *const unichar_repr) const
Definition: unicharset.h:755
UNICHAR_ID to_upper(UNICHAR_ID unichar_id) const
Definition: unicharset.h:711
const GenericVector< UNICHAR_ID > & normed_ids(UNICHAR_ID unichar_id) const
Definition: unicharset.h:834
void set_total(int t)
Definition: unicharset.h:70
void set_isalpha(UNICHAR_ID unichar_id, bool value)
Definition: unicharset.h:430
void set_other_case(UNICHAR_ID unichar_id, UNICHAR_ID other_case)
Definition: unicharset.h:466
bool load_from_file(FILE *file)
Definition: unicharset.h:402
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:279
void set_top_bottom(UNICHAR_ID unichar_id, int min_bottom, int max_bottom, int min_top, int max_top)
Definition: unicharset.h:581
int get_script_table_size() const
Definition: unicharset.h:848
bool is_beginning() const
Definition: unicharset.h:106
UNICHAR_ID get_mirror(UNICHAR_ID unichar_id) const
Definition: unicharset.h:696
void unichar_insert(const char *const unichar_repr)
Definition: unicharset.h:259
bool load_from_file(const char *const filename)
Definition: unicharset.h:395
int null_sid() const
Definition: unicharset.h:882
void get_bearing_stats(UNICHAR_ID unichar_id, float *bearing, float *bearing_sd) const
Definition: unicharset.h:612
bool get_isupper(const char *const unichar_repr, int length) const
Definition: unicharset.h:807
inT32 length() const
Definition: strngs.cpp:193
int get_script(UNICHAR_ID unichar_id) const
Definition: unicharset.h:662
int UNICHAR_ID
Definition: unichar.h:35
void set_unichar(const char *uch)
Definition: unicharset.h:65
void set_width_stats(UNICHAR_ID unichar_id, float width, float width_sd)
Definition: unicharset.h:606
bool equals(const char *other_unichar, int other_pos, int other_total) const
Definition: unicharset.h:86