]> git.lyx.org Git - lyx.git/blob - src/encoding.h
Fix bug 2474; partial fix for 1777. Added last_reference_ member to QRef class and...
[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 private:
52         ///
53         std::string Name_;
54         ///
55         std::string LatexName_;
56         ///
57         std::string iconvName_;
58         ///
59         typedef std::set<char_type> CharSet;
60         /// Set of UCS4 characters that we can encode (for singlebyte
61         /// encodings only)
62         CharSet encodable_;
63         /// All code points below this are encodable. This helps us to avoid
64         /// lokup of ASCII characters in encodable_ and gives about 1 sec
65         /// speedup on export of the Userguide.
66         char_type start_encodable_;
67 };
68
69 class Encodings {
70 public:
71         ///
72         typedef std::map<std::string, Encoding> EncodingList;
73         /// iterator to iterate over all encodings.
74         /// We hide the fact that our encoding list is implemented as a map.
75         class const_iterator : public EncodingList::const_iterator {
76                 typedef EncodingList::const_iterator base;
77         public:
78                 const_iterator() : base() {}
79                 const_iterator(base const & b) : base(b) {}
80                 Encoding const & operator*() const { return base::operator*().second; }
81                 Encoding const * operator->() const { return &(base::operator*().second); }
82         };
83         ///
84         Encodings();
85         /// Read the encodings.
86         /// \param encfile encodings definition file
87         /// \param symbolsfile unicode->LaTeX mapping file
88         void read(support::FileName const & encfile,
89                   support::FileName const & symbolsfile);
90         /// Get encoding from LyX name \p name
91         Encoding const * getFromLyXName(std::string const & name) const;
92         /// Get encoding from LaTeX name \p name
93         Encoding const * getFromLaTeXName(std::string const & name) const;
94
95         ///
96         const_iterator begin() const { return encodinglist.begin(); }
97         ///
98         const_iterator end() const { return encodinglist.end(); }
99
100         ///
101         enum Letter_Form {
102                 ///
103                 FORM_ISOLATED,
104                 ///
105                 FORM_FINAL,
106                 ///
107                 FORM_INITIAL,
108                 ///
109                 FORM_MEDIAL
110         };
111         ///
112         static bool isComposeChar_hebrew(char_type c);
113         ///
114         static bool isComposeChar_arabic(char_type c);
115         ///
116         static bool is_arabic_special(char_type c);
117         ///
118         static bool is_arabic(char_type c);
119         ///
120         static char_type transformChar(char_type c, Letter_Form form);
121         /// Is this a combining char?
122         static bool isCombiningChar(char_type c);
123         /**
124          * Add the preamble snippet needed for the output of \p c to
125          * \p features.
126          * This does not depend on the used encoding, since the inputenc
127          * package only maps the code point \p c to a command, it does not
128          * make this command available.
129          */
130         static void validate(char_type c, LaTeXFeatures & features);
131
132 private:
133         ///
134         EncodingList encodinglist;
135 };
136
137 extern Encodings encodings;
138
139
140 } // namespace lyx
141
142 #endif