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"
24 namespace support { class FileName; }
28 class EncodingException : public std::exception {
30 EncodingException(char_type c);
31 virtual ~EncodingException() throw() {}
32 virtual const char * what() const throw();
34 char_type failed_char;
43 /// Which LaTeX package handles this encoding?
52 Encoding(std::string const & n, std::string const & l,
53 std::string const & i, bool f, Package p);
57 std::string const & name() const { return Name_; }
59 std::string const & latexName() const { return LatexName_; }
61 std::string const & iconvName() const { return iconvName_; }
63 * Convert \p c to something that LaTeX can understand.
64 * This is either the character itself (if it is representable
65 * in this encoding), or a LaTeX macro.
66 * If the character is not representable in this encoding, but no
67 * LaTeX macro is known, a warning is given of lyxerr, and the
68 * character is returned.
70 docstring const latexChar(char_type c) const;
71 /// Which LaTeX package handles this encoding?
72 Package package() const { return package_; }
77 std::string LatexName_;
79 std::string iconvName_;
80 /// Is this a fixed width encoding?
83 typedef std::set<char_type> CharSet;
84 /// Set of UCS4 characters that we can encode (for singlebyte
86 mutable CharSet encodable_;
87 /// All code points below this are encodable. This helps us to avoid
88 /// lokup of ASCII characters in encodable_ and gives about 1 sec
89 /// speedup on export of the Userguide.
90 mutable char_type start_encodable_;
91 /// Which LaTeX package handles this encoding?
94 * If this is true the stored information about the encoding covers
95 * all encodable characters. We set this to false initially so that
96 * we only need to query iconv for the actually used encodings.
97 * This is needed especially for the multibyte encodings, if we
98 * complete all encoding info on startup it takes 2-3 minutes.
100 mutable bool complete_;
106 typedef std::map<std::string, Encoding> EncodingList;
107 /// iterator to iterate over all encodings.
108 /// We hide the fact that our encoding list is implemented as a map.
109 class const_iterator : public EncodingList::const_iterator {
110 typedef EncodingList::const_iterator base;
112 const_iterator() : base() {}
113 const_iterator(base const & b) : base(b) {}
114 Encoding const & operator*() const { return base::operator*().second; }
115 Encoding const * operator->() const { return &(base::operator*().second); }
119 /// Read the encodings.
120 /// \param encfile encodings definition file
121 /// \param symbolsfile unicode->LaTeX mapping file
122 void read(support::FileName const & encfile,
123 support::FileName const & symbolsfile);
124 /// Get encoding from LyX name \p name
125 Encoding const * getFromLyXName(std::string const & name) const;
126 /// Get encoding from LaTeX name \p name
127 Encoding const * getFromLaTeXName(std::string const & name) const;
130 const_iterator begin() const { return encodinglist.begin(); }
132 const_iterator end() const { return encodinglist.end(); }
146 static bool isComposeChar_hebrew(char_type c);
148 static bool isComposeChar_arabic(char_type c);
150 static bool is_arabic_special(char_type c);
152 static bool is_arabic(char_type c);
154 static char_type transformChar(char_type c, Letter_Form form);
155 /// Is this a combining char?
156 static bool isCombiningChar(char_type c);
158 * Is this a known char from some language?
159 * If \p preamble is empty and code point \p c is known to belong
160 * to a supported script, true is returned and \p preamble is set
161 * to the corresponding entry in the unicodesymbols file.
162 * If \p preamble is not empty, a check is made whether code point
163 * \p c is a known character matching the preamble entry.
165 static bool isKnownScriptChar(char_type const c, std::string & preamble);
167 * Add the preamble snippet needed for the output of \p c to
169 * This does not depend on the used encoding, since the inputenc
170 * package only maps the code point \p c to a command, it does not
171 * make this command available.
173 static void validate(char_type c, LaTeXFeatures & features);
177 EncodingList encodinglist;
180 extern Encodings encodings;