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