]> git.lyx.org Git - lyx.git/blob - src/encoding.h
typos
[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         ///
32         Encoding() {}
33         ///
34         Encoding(std::string const & n, std::string const & l,
35                  std::string const & i);
36         ///
37         std::string const & name() const { return Name_; }
38         ///
39         std::string const & latexName() const { return LatexName_; }
40         ///
41         std::string const & iconvName() const { return iconvName_; }
42         /**
43          * Convert \p c to something that LaTeX can understand.
44          * This is either the character itself (if it is representable
45          * in this encoding), or a LaTeX macro.
46          * If the character is not representable in this encoding, but no
47          * LaTeX macro is known, a warning is given of lyxerr, and the
48          * character is returned.
49          */
50         docstring const latexChar(char_type c) const;
51         /// Add the preamble snippet needed for the output of latexChar(c)
52         /// to \p features.
53         void validate(char_type c, LaTeXFeatures & features) const;
54 private:
55         ///
56         std::string Name_;
57         ///
58         std::string LatexName_;
59         ///
60         std::string iconvName_;
61         ///
62         typedef std::set<char_type> CharSet;
63         /// Set of UCS4 characters that we can encode (for singlebyte
64         /// encodings only)
65         CharSet encodable_;
66         /// All code points below this are encodable. This helps us to avoid
67         /// lokup of ASCII characters in encodable_ and gives about 1 sec
68         /// speedup on export of the Userguide.
69         char_type start_encodable_;
70 };
71
72 class Encodings {
73 public:
74         ///
75         typedef std::map<std::string, Encoding> EncodingList;
76         /// iterator to iterate over all encodings.
77         /// We hide the fact that our encoding list is implemented as a map.
78         class const_iterator : public EncodingList::const_iterator {
79                 typedef EncodingList::const_iterator base;
80         public:
81                 const_iterator() : base() {}
82                 const_iterator(base const & b) : base(b) {}
83                 Encoding const & operator*() const { return base::operator*().second; }
84                 Encoding const * operator->() const { return &(base::operator*().second); }
85         };
86         ///
87         Encodings();
88         /// Read the encodings.
89         /// \param encfile encodings definition file
90         /// \param symbolsfile unicode->LaTeX mapping file
91         void read(support::FileName const & encfile,
92                   support::FileName const & symbolsfile);
93         /// Get encoding from LyX name \p name
94         Encoding const * getFromLyXName(std::string const & name) const;
95         /// Get encoding from LaTeX name \p name
96         Encoding const * getFromLaTeXName(std::string const & name) const;
97
98         ///
99         const_iterator begin() const { return encodinglist.begin(); }
100         ///
101         const_iterator end() const { return encodinglist.end(); }
102
103         ///
104         enum Letter_Form {
105                 ///
106                 FORM_ISOLATED,
107                 ///
108                 FORM_FINAL,
109                 ///
110                 FORM_INITIAL,
111                 ///
112                 FORM_MEDIAL
113         };
114         ///
115         static bool isComposeChar_hebrew(char_type c);
116         ///
117         static bool isComposeChar_arabic(char_type c);
118         ///
119         static bool is_arabic_special(char_type c);
120         ///
121         static bool is_arabic(char_type c);
122         ///
123         static char_type transformChar(char_type c, Letter_Form form);
124         /// Is this a combining char?
125         static bool isCombiningChar(char_type c);
126
127 private:
128         ///
129         EncodingList encodinglist;
130 };
131
132 extern Encodings encodings;
133
134
135 } // namespace lyx
136
137 #endif