tesseract  3.05.02
ligature_table.h
Go to the documentation of this file.
1 /**********************************************************************
2  * File: ligature_table.h
3  * Description: Class for adding and removing optional latin ligatures,
4  * conditional on codepoint support by a specified font
5  * (if specified).
6  * Author: Ranjith Unnikrishnan
7  * Created: Mon Nov 18 2013
8  *
9  * (C) Copyright 2013, Google Inc.
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  * http://www.apache.org/licenses/LICENSE-2.0
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  **********************************************************************/
21 
22 #ifndef TRAININGDATA_LIGATURE_TABLE_H_
23 #define TRAININGDATA_LIGATURE_TABLE_H_
24 
25 #include <string>
26 
27 #include "hashfn.h"
28 #include "util.h"
29 
30 namespace tesseract {
31 
32 class PangoFontInfo; // defined in pango_font_info.h
33 
34 // Map to substitute strings for ligatures.
35 typedef TessHashMap<string, string, StringHash> LigHash;
36 
38  public:
39  // Get a static instance of this class.
40  static LigatureTable* Get();
41 
42  // Convert the utf8 string so that ligaturizable sequences, such as "fi" get
43  // replaced by the (utf8 code for) appropriate ligature characters. Only do so
44  // if the corresponding ligature character is renderable in the current font.
45  string AddLigatures(const string& str, const PangoFontInfo* font) const;
46  // Remove all ligatures.
47  string RemoveLigatures(const string& str) const;
48  // Remove only custom ligatures (eg. "ct") encoded in the private-use-area.
49  string RemoveCustomLigatures(const string& str) const;
50 
51  const LigHash& norm_to_lig_table() const {
52  return norm_to_lig_table_;
53  }
54  const LigHash& lig_to_norm_table() const {
55  return lig_to_norm_table_;
56  }
57 
58  protected:
59  LigatureTable();
60  // Initialize the hash tables mapping between ligature strings and the
61  // corresponding ligature characters.
62  void Init();
63 
71 
72  private:
74  void operator=(const LigatureTable&);
75 };
76 
77 } // namespace tesseract
78 
79 #endif // OCR_TRAININGDATA_TYPESETTING_LIGATURE_TABLE_H_
const LigHash & norm_to_lig_table() const
TessHashMap< string, string, StringHash > LigHash
const LigHash & lig_to_norm_table() const
static SmartPtr< LigatureTable > instance_
string RemoveLigatures(const string &str) const
string AddLigatures(const string &str, const PangoFontInfo *font) const
string RemoveCustomLigatures(const string &str) const
static LigatureTable * Get()