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 & g, std::string const & i,
59 std::string const & name() const { return name_; }
61 std::string const & latexName() const { return latexName_; }
63 std::string const & guiName() const { return guiName_; }
65 std::string const & iconvName() const { return iconvName_; }
67 * Convert \p c to something that LaTeX can understand.
68 * This is either the character itself (if it is representable
69 * in this encoding), or a LaTeX macro.
70 * If the character is not representable in this encoding, but no
71 * LaTeX macro is known, a warning is given of lyxerr, and the
72 * character is returned.
74 docstring latexChar(char_type c) const;
75 /// Which LaTeX package handles this encoding?
76 Package package() const { return package_; }
77 /// A list of all characters usable in this encoding
78 std::vector<char_type> symbolsList() const;
83 std::string latexName_;
87 std::string iconvName_;
88 /// Is this a fixed width encoding?
91 typedef std::set<char_type> CharSet;
92 /// Set of UCS4 characters that we can encode (for singlebyte
94 mutable CharSet encodable_;
95 /// All code points below this are encodable. This helps us to avoid
96 /// lokup of ASCII characters in encodable_ and gives about 1 sec
97 /// speedup on export of the Userguide.
98 mutable char_type start_encodable_;
99 /// Which LaTeX package handles this encoding?
102 * If this is true the stored information about the encoding covers
103 * all encodable characters. We set this to false initially so that
104 * we only need to query iconv for the actually used encodings.
105 * This is needed especially for the multibyte encodings, if we
106 * complete all encoding info on startup it takes 2-3 minutes.
108 mutable bool complete_;
114 typedef std::map<std::string, Encoding> EncodingList;
115 /// iterator to iterate over all encodings.
116 /// We hide the fact that our encoding list is implemented as a map.
117 class const_iterator : public EncodingList::const_iterator {
118 typedef EncodingList::const_iterator base;
120 const_iterator() : base() {}
121 const_iterator(base const & b) : base(b) {}
122 Encoding const & operator*() const { return base::operator*().second; }
123 Encoding const * operator->() const { return &(base::operator*().second); }
127 /// Read the encodings.
128 /// \param encfile encodings definition file
129 /// \param symbolsfile unicode->LaTeX mapping file
130 void read(support::FileName const & encfile,
131 support::FileName const & symbolsfile);
132 /// Get encoding from LyX name \p name
133 Encoding const * fromLyXName(std::string const & name) const;
134 /// Get encoding from LaTeX name \p name
135 Encoding const * fromLaTeXName(std::string const & name) const;
138 const_iterator begin() const { return encodinglist.begin(); }
140 const_iterator end() const { return encodinglist.end(); }
154 static bool isHebrewComposeChar(char_type c);
156 static bool isArabicComposeChar(char_type c);
158 static bool isArabicSpecialChar(char_type c);
160 static bool isArabicChar(char_type c);
162 static char_type transformChar(char_type c, LetterForm form);
163 /// Is this a combining char?
164 static bool isCombiningChar(char_type c);
166 * Is this a known char from some language?
167 * If \p preamble is empty and code point \p c is known to belong
168 * to a supported script, true is returned and \p preamble is set
169 * to the corresponding entry in the unicodesymbols file.
170 * If \p preamble is not empty, a check is made whether code point
171 * \p c is a known character matching the preamble entry.
173 static bool isKnownScriptChar(char_type const c, std::string & preamble);
175 * Do we have to output this character as LaTeX command in any case?
176 * This is true if the "forced" flag is set.
177 * We need this if the inputencoding does not support a certain glyph.
179 static bool isForced(char_type c);
181 * Convert \p c to something that LaTeX can understand in math mode.
182 * \return whether \p command is a math mode command
184 static bool latexMathChar(char_type c, docstring & command);
187 * Convert the LaTeX command in \p cmd to the corresponding unicode
188 * point and set \p combining to true if it is a combining symbol
190 static char_type fromLaTeXCommand(docstring const & cmd, bool & combining);
192 * Convert the LaTeX commands in \p cmd and \return a docstring
193 * of corresponding unicode points. The conversion stops at the
194 * first command which could not be converted, and the remaining
195 * unconverted commands are returned in \p rem
197 static docstring fromLaTeXCommand(docstring const & cmd, docstring & rem);
199 * Add the preamble snippet needed for the output of \p c to
201 * This does not depend on the used encoding, since the inputenc
202 * package only maps the code point \p c to a command, it does not
203 * make this command available.
205 static void validate(char_type c, LaTeXFeatures & features, bool for_mathed = false);
209 EncodingList encodinglist;
212 extern Encodings encodings;