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