]> git.lyx.org Git - lyx.git/blob - src/Encoding.h
* some more traces of the signals in CursorSlice
[lyx.git] / src / Encoding.h
1 // -*- C++ -*-
2 /**
3  * \file Encoding.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef ENCODING_H
14 #define ENCODING_H
15
16 #include "support/docstring.h"
17
18 #include <map>
19 #include <set>
20
21 namespace lyx {
22
23 namespace support { class FileName; }
24
25 class LaTeXFeatures;
26
27
28 ///
29 class Encoding {
30 public:
31         /// Which LaTeX package handles this encoding?
32         enum Package {
33                 none,
34                 inputenc,
35                 CJK
36         };
37         ///
38         Encoding() {}
39         ///
40         Encoding(std::string const & n, std::string const & l,
41                  std::string const & i, bool f, Package p);
42         ///
43         void init() const;
44         ///
45         std::string const & name() const { return Name_; }
46         ///
47         std::string const & latexName() const { return LatexName_; }
48         ///
49         std::string const & iconvName() const { return iconvName_; }
50         /**
51          * Convert \p c to something that LaTeX can understand.
52          * This is either the character itself (if it is representable
53          * in this encoding), or a LaTeX macro.
54          * If the character is not representable in this encoding, but no
55          * LaTeX macro is known, a warning is given of lyxerr, and the
56          * character is returned.
57          */
58         docstring const latexChar(char_type c) const;
59         /// Which LaTeX package handles this encoding?
60         Package package() const { return package_; }
61 private:
62         ///
63         std::string Name_;
64         ///
65         std::string LatexName_;
66         ///
67         std::string iconvName_;
68         /// Is this a fixed width encoding?
69         bool fixedwidth_;
70         ///
71         typedef std::set<char_type> CharSet;
72         /// Set of UCS4 characters that we can encode (for singlebyte
73         /// encodings only)
74         mutable CharSet encodable_;
75         /// All code points below this are encodable. This helps us to avoid
76         /// lokup of ASCII characters in encodable_ and gives about 1 sec
77         /// speedup on export of the Userguide.
78         mutable char_type start_encodable_;
79         /// Which LaTeX package handles this encoding?
80         Package package_;
81         /**
82          * If this is true the stored information about the encoding covers
83          * all encodable characters. We set this to false initially so that
84          * we only need to query iconv for the actually used encodings.
85          * This is needed especially for the multibyte encodings, if we
86          * complete all encoding info on startup it takes 2-3 minutes.
87          */
88         mutable bool complete_;
89 };
90
91 class Encodings {
92 public:
93         ///
94         typedef std::map<std::string, Encoding> EncodingList;
95         /// iterator to iterate over all encodings.
96         /// We hide the fact that our encoding list is implemented as a map.
97         class const_iterator : public EncodingList::const_iterator {
98                 typedef EncodingList::const_iterator base;
99         public:
100                 const_iterator() : base() {}
101                 const_iterator(base const & b) : base(b) {}
102                 Encoding const & operator*() const { return base::operator*().second; }
103                 Encoding const * operator->() const { return &(base::operator*().second); }
104         };
105         ///
106         Encodings();
107         /// Read the encodings.
108         /// \param encfile encodings definition file
109         /// \param symbolsfile unicode->LaTeX mapping file
110         void read(support::FileName const & encfile,
111                   support::FileName const & symbolsfile);
112         /// Get encoding from LyX name \p name
113         Encoding const * getFromLyXName(std::string const & name) const;
114         /// Get encoding from LaTeX name \p name
115         Encoding const * getFromLaTeXName(std::string const & name) const;
116
117         ///
118         const_iterator begin() const { return encodinglist.begin(); }
119         ///
120         const_iterator end() const { return encodinglist.end(); }
121
122         ///
123         enum Letter_Form {
124                 ///
125                 FORM_ISOLATED,
126                 ///
127                 FORM_FINAL,
128                 ///
129                 FORM_INITIAL,
130                 ///
131                 FORM_MEDIAL
132         };
133         ///
134         static bool isComposeChar_hebrew(char_type c);
135         ///
136         static bool isComposeChar_arabic(char_type c);
137         ///
138         static bool is_arabic_special(char_type c);
139         ///
140         static bool is_arabic(char_type c);
141         ///
142         static char_type transformChar(char_type c, Letter_Form form);
143         /// Is this a combining char?
144         static bool isCombiningChar(char_type c);
145         /**
146          * Add the preamble snippet needed for the output of \p c to
147          * \p features.
148          * This does not depend on the used encoding, since the inputenc
149          * package only maps the code point \p c to a command, it does not
150          * make this command available.
151          */
152         static void validate(char_type c, LaTeXFeatures & features);
153
154 private:
155         ///
156         EncodingList encodinglist;
157 };
158
159 extern Encodings encodings;
160
161
162 } // namespace lyx
163
164 #endif