4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
10 * Full author contact details are available in file CREDITS.
16 #include "support/docstring.h"
17 #include "support/types.h"
25 namespace support { class FileName; }
29 class EncodingException : public std::exception {
31 EncodingException(char_type c);
32 virtual ~EncodingException() throw() {}
33 virtual const char * what() const throw();
35 char_type failed_char;
44 /// Which LaTeX package handles this encoding?
53 Encoding(std::string const & n, std::string const & l,
54 std::string const & i, bool f, Package p);
58 std::string const & name() const { return name_; }
60 std::string const & latexName() const { return latexName_; }
62 std::string const & iconvName() const { return iconvName_; }
64 * Convert \p c to something that LaTeX can understand.
65 * This is either the character itself (if it is representable
66 * in this encoding), or a LaTeX macro.
67 * If the character is not representable in this encoding, but no
68 * LaTeX macro is known, a warning is given of lyxerr, and the
69 * character is returned.
71 docstring latexChar(char_type c) const;
72 /// Which LaTeX package handles this encoding?
73 Package package() const { return package_; }
74 /// A list of all characters usable in this encoding
75 std::vector<char_type> symbolsList() const;
80 std::string latexName_;
82 std::string iconvName_;
83 /// Is this a fixed width encoding?
86 typedef std::set<char_type> CharSet;
87 /// Set of UCS4 characters that we can encode (for singlebyte
89 mutable CharSet encodable_;
90 /// All code points below this are encodable. This helps us to avoid
91 /// lokup of ASCII characters in encodable_ and gives about 1 sec
92 /// speedup on export of the Userguide.
93 mutable char_type start_encodable_;
94 /// Which LaTeX package handles this encoding?
97 * If this is true the stored information about the encoding covers
98 * all encodable characters. We set this to false initially so that
99 * we only need to query iconv for the actually used encodings.
100 * This is needed especially for the multibyte encodings, if we
101 * complete all encoding info on startup it takes 2-3 minutes.
103 mutable bool complete_;
109 typedef std::map<std::string, Encoding> EncodingList;
110 /// iterator to iterate over all encodings.
111 /// We hide the fact that our encoding list is implemented as a map.
112 class const_iterator : public EncodingList::const_iterator {
113 typedef EncodingList::const_iterator base;
115 const_iterator() : base() {}
116 const_iterator(base const & b) : base(b) {}
117 Encoding const & operator*() const { return base::operator*().second; }
118 Encoding const * operator->() const { return &(base::operator*().second); }
122 /// Read the encodings.
123 /// \param encfile encodings definition file
124 /// \param symbolsfile unicode->LaTeX mapping file
125 void read(support::FileName const & encfile,
126 support::FileName const & symbolsfile);
127 /// Get encoding from LyX name \p name
128 Encoding const * fromLyXName(std::string const & name) const;
129 /// Get encoding from LaTeX name \p name
130 Encoding const * fromLaTeXName(std::string const & name) const;
133 const_iterator begin() const { return encodinglist.begin(); }
135 const_iterator end() const { return encodinglist.end(); }
149 static bool isHebrewComposeChar(char_type c);
151 static bool isArabicComposeChar(char_type c);
153 static bool isArabicSpecialChar(char_type c);
155 static bool isArabicChar(char_type c);
157 static char_type transformChar(char_type c, LetterForm form);
158 /// Is this a combining char?
159 static bool isCombiningChar(char_type c);
161 * Is this a known char from some language?
162 * If \p preamble is empty and code point \p c is known to belong
163 * to a supported script, true is returned and \p preamble is set
164 * to the corresponding entry in the unicodesymbols file.
165 * If \p preamble is not empty, a check is made whether code point
166 * \p c is a known character matching the preamble entry.
168 static bool isKnownScriptChar(char_type const c, std::string & preamble);
170 * Add the preamble snippet needed for the output of \p c to
172 * This does not depend on the used encoding, since the inputenc
173 * package only maps the code point \p c to a command, it does not
174 * make this command available.
176 static void validate(char_type c, LaTeXFeatures & features);
180 EncodingList encodinglist;
183 extern Encodings encodings;