2000-07-04 20:32:37 +00:00
|
|
|
|
// -*- C++ -*-
|
2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
|
* \file Encoding.h
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
2000-07-04 20:32:37 +00:00
|
|
|
|
|
|
|
|
|
#ifndef ENCODING_H
|
|
|
|
|
#define ENCODING_H
|
|
|
|
|
|
Add machinery to output arbitrary unicode characters with LaTeX commands
read from a text file.
* src/encoding.[Ch]
(Encoding::latexChar): New, output a character to LaTeX
(Encoding::validate): New, add needed preamble stuff for a character
(Encodings::read): Read new unicodesymbols file
(Encodings::isCombiningChar): New, is a character a combining char?
* src/paragraph_pimpl.C
(isEncoding): Delete, no longer needed
(getEncoding): New, get the real encoding of a font
(Paragraph::Pimpl::latexSurrogatePair): New, output a surrogate pair
to LaTeX
(Paragraph::Pimpl::simpleTeXBlanks): Use latexSurrogatePair if needed
(Paragraph::Pimpl::simpleTeXSpecialChars): Ditto, and replace several
hardcoded characters with a call of encoding.latexChar()
(Paragraph::Pimpl::validate): replace several hardcoded characters
with a call of encoding.validate()
* src/support/debugstream.h
(basic_debugstream::disable): New, disable the stream completely
(basic_debugstream::enable): New, reenable the stream
* src/lyx_main.[Ch]: Adjust to changes above
* src/paragraph.C: Ditto
* lib/unicodesymbols: New file with UCS4 -> LaTeX command mapping.
It is far from complete yet, but contains most accents on latin
characters.
* lib/Makefile.am: add lib/unicodesymbols
* development/scons/scons_manifest.py: ditto
* development/tools/unicodesymbols.py: Helper script to update
lib/unicodesymbols with new symbols
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16920 a592a061-630c-0410-9148-cb99ea01b6c8
2007-01-28 21:27:45 +00:00
|
|
|
|
#include "support/docstring.h"
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
2007-01-29 08:18:21 +00:00
|
|
|
|
#include <map>
|
Add machinery to output arbitrary unicode characters with LaTeX commands
read from a text file.
* src/encoding.[Ch]
(Encoding::latexChar): New, output a character to LaTeX
(Encoding::validate): New, add needed preamble stuff for a character
(Encodings::read): Read new unicodesymbols file
(Encodings::isCombiningChar): New, is a character a combining char?
* src/paragraph_pimpl.C
(isEncoding): Delete, no longer needed
(getEncoding): New, get the real encoding of a font
(Paragraph::Pimpl::latexSurrogatePair): New, output a surrogate pair
to LaTeX
(Paragraph::Pimpl::simpleTeXBlanks): Use latexSurrogatePair if needed
(Paragraph::Pimpl::simpleTeXSpecialChars): Ditto, and replace several
hardcoded characters with a call of encoding.latexChar()
(Paragraph::Pimpl::validate): replace several hardcoded characters
with a call of encoding.validate()
* src/support/debugstream.h
(basic_debugstream::disable): New, disable the stream completely
(basic_debugstream::enable): New, reenable the stream
* src/lyx_main.[Ch]: Adjust to changes above
* src/paragraph.C: Ditto
* lib/unicodesymbols: New file with UCS4 -> LaTeX command mapping.
It is far from complete yet, but contains most accents on latin
characters.
* lib/Makefile.am: add lib/unicodesymbols
* development/scons/scons_manifest.py: ditto
* development/tools/unicodesymbols.py: Helper script to update
lib/unicodesymbols with new symbols
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16920 a592a061-630c-0410-9148-cb99ea01b6c8
2007-01-28 21:27:45 +00:00
|
|
|
|
#include <set>
|
2003-07-26 23:04:39 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
|
namespace support { class FileName; }
|
|
|
|
|
|
Add machinery to output arbitrary unicode characters with LaTeX commands
read from a text file.
* src/encoding.[Ch]
(Encoding::latexChar): New, output a character to LaTeX
(Encoding::validate): New, add needed preamble stuff for a character
(Encodings::read): Read new unicodesymbols file
(Encodings::isCombiningChar): New, is a character a combining char?
* src/paragraph_pimpl.C
(isEncoding): Delete, no longer needed
(getEncoding): New, get the real encoding of a font
(Paragraph::Pimpl::latexSurrogatePair): New, output a surrogate pair
to LaTeX
(Paragraph::Pimpl::simpleTeXBlanks): Use latexSurrogatePair if needed
(Paragraph::Pimpl::simpleTeXSpecialChars): Ditto, and replace several
hardcoded characters with a call of encoding.latexChar()
(Paragraph::Pimpl::validate): replace several hardcoded characters
with a call of encoding.validate()
* src/support/debugstream.h
(basic_debugstream::disable): New, disable the stream completely
(basic_debugstream::enable): New, reenable the stream
* src/lyx_main.[Ch]: Adjust to changes above
* src/paragraph.C: Ditto
* lib/unicodesymbols: New file with UCS4 -> LaTeX command mapping.
It is far from complete yet, but contains most accents on latin
characters.
* lib/Makefile.am: add lib/unicodesymbols
* development/scons/scons_manifest.py: ditto
* development/tools/unicodesymbols.py: Helper script to update
lib/unicodesymbols with new symbols
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16920 a592a061-630c-0410-9148-cb99ea01b6c8
2007-01-28 21:27:45 +00:00
|
|
|
|
class LaTeXFeatures;
|
|
|
|
|
|
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
|
///
|
2000-07-04 20:32:37 +00:00
|
|
|
|
class Encoding {
|
|
|
|
|
public:
|
2007-05-06 20:26:02 +00:00
|
|
|
|
/// Which LaTeX package handles this encoding?
|
|
|
|
|
enum Package {
|
|
|
|
|
none,
|
|
|
|
|
inputenc,
|
|
|
|
|
CJK
|
|
|
|
|
};
|
2000-10-10 12:36:36 +00:00
|
|
|
|
///
|
|
|
|
|
Encoding() {}
|
|
|
|
|
///
|
2006-10-26 15:01:45 +00:00
|
|
|
|
Encoding(std::string const & n, std::string const & l,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
std::string const & i, bool f, Package p);
|
2007-05-06 20:26:02 +00:00
|
|
|
|
///
|
|
|
|
|
void init() const;
|
2000-10-10 12:36:36 +00:00
|
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
|
std::string const & name() const { return Name_; }
|
2000-10-10 12:36:36 +00:00
|
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
|
std::string const & latexName() const { return LatexName_; }
|
2000-10-10 12:36:36 +00:00
|
|
|
|
///
|
2006-10-26 15:01:45 +00:00
|
|
|
|
std::string const & iconvName() const { return iconvName_; }
|
Add machinery to output arbitrary unicode characters with LaTeX commands
read from a text file.
* src/encoding.[Ch]
(Encoding::latexChar): New, output a character to LaTeX
(Encoding::validate): New, add needed preamble stuff for a character
(Encodings::read): Read new unicodesymbols file
(Encodings::isCombiningChar): New, is a character a combining char?
* src/paragraph_pimpl.C
(isEncoding): Delete, no longer needed
(getEncoding): New, get the real encoding of a font
(Paragraph::Pimpl::latexSurrogatePair): New, output a surrogate pair
to LaTeX
(Paragraph::Pimpl::simpleTeXBlanks): Use latexSurrogatePair if needed
(Paragraph::Pimpl::simpleTeXSpecialChars): Ditto, and replace several
hardcoded characters with a call of encoding.latexChar()
(Paragraph::Pimpl::validate): replace several hardcoded characters
with a call of encoding.validate()
* src/support/debugstream.h
(basic_debugstream::disable): New, disable the stream completely
(basic_debugstream::enable): New, reenable the stream
* src/lyx_main.[Ch]: Adjust to changes above
* src/paragraph.C: Ditto
* lib/unicodesymbols: New file with UCS4 -> LaTeX command mapping.
It is far from complete yet, but contains most accents on latin
characters.
* lib/Makefile.am: add lib/unicodesymbols
* development/scons/scons_manifest.py: ditto
* development/tools/unicodesymbols.py: Helper script to update
lib/unicodesymbols with new symbols
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16920 a592a061-630c-0410-9148-cb99ea01b6c8
2007-01-28 21:27:45 +00:00
|
|
|
|
/**
|
|
|
|
|
* Convert \p c to something that LaTeX can understand.
|
|
|
|
|
* This is either the character itself (if it is representable
|
|
|
|
|
* in this encoding), or a LaTeX macro.
|
|
|
|
|
* If the character is not representable in this encoding, but no
|
|
|
|
|
* LaTeX macro is known, a warning is given of lyxerr, and the
|
|
|
|
|
* character is returned.
|
|
|
|
|
*/
|
|
|
|
|
docstring const latexChar(char_type c) const;
|
2007-05-06 20:26:02 +00:00
|
|
|
|
/// Which LaTeX package handles this encoding?
|
|
|
|
|
Package package() const { return package_; }
|
2000-10-10 12:36:36 +00:00
|
|
|
|
private:
|
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
std::string Name_;
|
2000-10-10 12:36:36 +00:00
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
std::string LatexName_;
|
2000-10-10 12:36:36 +00:00
|
|
|
|
///
|
2006-10-26 15:01:45 +00:00
|
|
|
|
std::string iconvName_;
|
2007-05-06 20:26:02 +00:00
|
|
|
|
/// Is this a fixed width encoding?
|
|
|
|
|
bool fixedwidth_;
|
Add machinery to output arbitrary unicode characters with LaTeX commands
read from a text file.
* src/encoding.[Ch]
(Encoding::latexChar): New, output a character to LaTeX
(Encoding::validate): New, add needed preamble stuff for a character
(Encodings::read): Read new unicodesymbols file
(Encodings::isCombiningChar): New, is a character a combining char?
* src/paragraph_pimpl.C
(isEncoding): Delete, no longer needed
(getEncoding): New, get the real encoding of a font
(Paragraph::Pimpl::latexSurrogatePair): New, output a surrogate pair
to LaTeX
(Paragraph::Pimpl::simpleTeXBlanks): Use latexSurrogatePair if needed
(Paragraph::Pimpl::simpleTeXSpecialChars): Ditto, and replace several
hardcoded characters with a call of encoding.latexChar()
(Paragraph::Pimpl::validate): replace several hardcoded characters
with a call of encoding.validate()
* src/support/debugstream.h
(basic_debugstream::disable): New, disable the stream completely
(basic_debugstream::enable): New, reenable the stream
* src/lyx_main.[Ch]: Adjust to changes above
* src/paragraph.C: Ditto
* lib/unicodesymbols: New file with UCS4 -> LaTeX command mapping.
It is far from complete yet, but contains most accents on latin
characters.
* lib/Makefile.am: add lib/unicodesymbols
* development/scons/scons_manifest.py: ditto
* development/tools/unicodesymbols.py: Helper script to update
lib/unicodesymbols with new symbols
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16920 a592a061-630c-0410-9148-cb99ea01b6c8
2007-01-28 21:27:45 +00:00
|
|
|
|
///
|
|
|
|
|
typedef std::set<char_type> CharSet;
|
|
|
|
|
/// Set of UCS4 characters that we can encode (for singlebyte
|
|
|
|
|
/// encodings only)
|
2007-05-06 20:26:02 +00:00
|
|
|
|
mutable CharSet encodable_;
|
Add machinery to output arbitrary unicode characters with LaTeX commands
read from a text file.
* src/encoding.[Ch]
(Encoding::latexChar): New, output a character to LaTeX
(Encoding::validate): New, add needed preamble stuff for a character
(Encodings::read): Read new unicodesymbols file
(Encodings::isCombiningChar): New, is a character a combining char?
* src/paragraph_pimpl.C
(isEncoding): Delete, no longer needed
(getEncoding): New, get the real encoding of a font
(Paragraph::Pimpl::latexSurrogatePair): New, output a surrogate pair
to LaTeX
(Paragraph::Pimpl::simpleTeXBlanks): Use latexSurrogatePair if needed
(Paragraph::Pimpl::simpleTeXSpecialChars): Ditto, and replace several
hardcoded characters with a call of encoding.latexChar()
(Paragraph::Pimpl::validate): replace several hardcoded characters
with a call of encoding.validate()
* src/support/debugstream.h
(basic_debugstream::disable): New, disable the stream completely
(basic_debugstream::enable): New, reenable the stream
* src/lyx_main.[Ch]: Adjust to changes above
* src/paragraph.C: Ditto
* lib/unicodesymbols: New file with UCS4 -> LaTeX command mapping.
It is far from complete yet, but contains most accents on latin
characters.
* lib/Makefile.am: add lib/unicodesymbols
* development/scons/scons_manifest.py: ditto
* development/tools/unicodesymbols.py: Helper script to update
lib/unicodesymbols with new symbols
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16920 a592a061-630c-0410-9148-cb99ea01b6c8
2007-01-28 21:27:45 +00:00
|
|
|
|
/// All code points below this are encodable. This helps us to avoid
|
|
|
|
|
/// lokup of ASCII characters in encodable_ and gives about 1 sec
|
|
|
|
|
/// speedup on export of the Userguide.
|
2007-05-06 20:26:02 +00:00
|
|
|
|
mutable char_type start_encodable_;
|
|
|
|
|
/// Which LaTeX package handles this encoding?
|
|
|
|
|
Package package_;
|
|
|
|
|
/**
|
|
|
|
|
* If this is true the stored information about the encoding covers
|
|
|
|
|
* all encodable characters. We set this to false initially so that
|
|
|
|
|
* we only need to query iconv for the actually used encodings.
|
|
|
|
|
* This is needed especially for the multibyte encodings, if we
|
|
|
|
|
* complete all encoding info on startup it takes 2-3 minutes.
|
|
|
|
|
*/
|
|
|
|
|
mutable bool complete_;
|
2000-10-10 12:36:36 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Encodings {
|
|
|
|
|
public:
|
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
typedef std::map<std::string, Encoding> EncodingList;
|
2006-12-28 18:15:25 +00:00
|
|
|
|
/// iterator to iterate over all encodings.
|
|
|
|
|
/// We hide the fact that our encoding list is implemented as a map.
|
|
|
|
|
class const_iterator : public EncodingList::const_iterator {
|
|
|
|
|
typedef EncodingList::const_iterator base;
|
|
|
|
|
public:
|
|
|
|
|
const_iterator() : base() {}
|
|
|
|
|
const_iterator(base const & b) : base(b) {}
|
|
|
|
|
Encoding const & operator*() const { return base::operator*().second; }
|
|
|
|
|
Encoding const * operator->() const { return &(base::operator*().second); }
|
|
|
|
|
};
|
2000-10-10 12:36:36 +00:00
|
|
|
|
///
|
|
|
|
|
Encodings();
|
Add machinery to output arbitrary unicode characters with LaTeX commands
read from a text file.
* src/encoding.[Ch]
(Encoding::latexChar): New, output a character to LaTeX
(Encoding::validate): New, add needed preamble stuff for a character
(Encodings::read): Read new unicodesymbols file
(Encodings::isCombiningChar): New, is a character a combining char?
* src/paragraph_pimpl.C
(isEncoding): Delete, no longer needed
(getEncoding): New, get the real encoding of a font
(Paragraph::Pimpl::latexSurrogatePair): New, output a surrogate pair
to LaTeX
(Paragraph::Pimpl::simpleTeXBlanks): Use latexSurrogatePair if needed
(Paragraph::Pimpl::simpleTeXSpecialChars): Ditto, and replace several
hardcoded characters with a call of encoding.latexChar()
(Paragraph::Pimpl::validate): replace several hardcoded characters
with a call of encoding.validate()
* src/support/debugstream.h
(basic_debugstream::disable): New, disable the stream completely
(basic_debugstream::enable): New, reenable the stream
* src/lyx_main.[Ch]: Adjust to changes above
* src/paragraph.C: Ditto
* lib/unicodesymbols: New file with UCS4 -> LaTeX command mapping.
It is far from complete yet, but contains most accents on latin
characters.
* lib/Makefile.am: add lib/unicodesymbols
* development/scons/scons_manifest.py: ditto
* development/tools/unicodesymbols.py: Helper script to update
lib/unicodesymbols with new symbols
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16920 a592a061-630c-0410-9148-cb99ea01b6c8
2007-01-28 21:27:45 +00:00
|
|
|
|
/// Read the encodings.
|
|
|
|
|
/// \param encfile encodings definition file
|
|
|
|
|
/// \param symbolsfile unicode->LaTeX mapping file
|
|
|
|
|
void read(support::FileName const & encfile,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
support::FileName const & symbolsfile);
|
2006-11-03 10:35:41 +00:00
|
|
|
|
/// Get encoding from LyX name \p name
|
|
|
|
|
Encoding const * getFromLyXName(std::string const & name) const;
|
|
|
|
|
/// Get encoding from LaTeX name \p name
|
|
|
|
|
Encoding const * getFromLaTeXName(std::string const & name) const;
|
2000-10-10 12:36:36 +00:00
|
|
|
|
|
2006-12-28 18:15:25 +00:00
|
|
|
|
///
|
|
|
|
|
const_iterator begin() const { return encodinglist.begin(); }
|
|
|
|
|
///
|
|
|
|
|
const_iterator end() const { return encodinglist.end(); }
|
|
|
|
|
|
2000-07-04 20:32:37 +00:00
|
|
|
|
///
|
|
|
|
|
enum Letter_Form {
|
2000-08-07 20:58:24 +00:00
|
|
|
|
///
|
2000-07-04 20:32:37 +00:00
|
|
|
|
FORM_ISOLATED,
|
2000-08-07 20:58:24 +00:00
|
|
|
|
///
|
2000-07-04 20:32:37 +00:00
|
|
|
|
FORM_FINAL,
|
2000-08-07 20:58:24 +00:00
|
|
|
|
///
|
2000-07-04 20:32:37 +00:00
|
|
|
|
FORM_INITIAL,
|
2000-08-07 20:58:24 +00:00
|
|
|
|
///
|
2000-07-04 20:32:37 +00:00
|
|
|
|
FORM_MEDIAL
|
|
|
|
|
};
|
|
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
|
static bool isComposeChar_hebrew(char_type c);
|
2000-07-04 20:32:37 +00:00
|
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
|
static bool isComposeChar_arabic(char_type c);
|
2000-07-04 20:32:37 +00:00
|
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
|
static bool is_arabic_special(char_type c);
|
2002-11-25 21:29:21 +00:00
|
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
|
static bool is_arabic(char_type c);
|
2000-07-04 20:32:37 +00:00
|
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
|
static char_type transformChar(char_type c, Letter_Form form);
|
Add machinery to output arbitrary unicode characters with LaTeX commands
read from a text file.
* src/encoding.[Ch]
(Encoding::latexChar): New, output a character to LaTeX
(Encoding::validate): New, add needed preamble stuff for a character
(Encodings::read): Read new unicodesymbols file
(Encodings::isCombiningChar): New, is a character a combining char?
* src/paragraph_pimpl.C
(isEncoding): Delete, no longer needed
(getEncoding): New, get the real encoding of a font
(Paragraph::Pimpl::latexSurrogatePair): New, output a surrogate pair
to LaTeX
(Paragraph::Pimpl::simpleTeXBlanks): Use latexSurrogatePair if needed
(Paragraph::Pimpl::simpleTeXSpecialChars): Ditto, and replace several
hardcoded characters with a call of encoding.latexChar()
(Paragraph::Pimpl::validate): replace several hardcoded characters
with a call of encoding.validate()
* src/support/debugstream.h
(basic_debugstream::disable): New, disable the stream completely
(basic_debugstream::enable): New, reenable the stream
* src/lyx_main.[Ch]: Adjust to changes above
* src/paragraph.C: Ditto
* lib/unicodesymbols: New file with UCS4 -> LaTeX command mapping.
It is far from complete yet, but contains most accents on latin
characters.
* lib/Makefile.am: add lib/unicodesymbols
* development/scons/scons_manifest.py: ditto
* development/tools/unicodesymbols.py: Helper script to update
lib/unicodesymbols with new symbols
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16920 a592a061-630c-0410-9148-cb99ea01b6c8
2007-01-28 21:27:45 +00:00
|
|
|
|
/// Is this a combining char?
|
|
|
|
|
static bool isCombiningChar(char_type c);
|
2007-10-24 17:24:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* Is this a known char from some script?
|
|
|
|
|
* If \p preamble is empty and code point \p c is known to belong
|
|
|
|
|
* to a supported script, true is returned and \p preamble is set
|
|
|
|
|
* to the corresponding entry in the unicodesymbols file.
|
|
|
|
|
* If \p preamble is not empty, a check is made whether code point
|
|
|
|
|
* \p c is a known character matching the preamble entry.
|
|
|
|
|
*/
|
|
|
|
|
static bool isKnownScriptChar(char_type const c, std::string & preamble);
|
2007-04-16 18:06:01 +00:00
|
|
|
|
/**
|
|
|
|
|
* Add the preamble snippet needed for the output of \p c to
|
|
|
|
|
* \p features.
|
|
|
|
|
* This does not depend on the used encoding, since the inputenc
|
|
|
|
|
* package only maps the code point \p c to a command, it does not
|
|
|
|
|
* make this command available.
|
|
|
|
|
*/
|
|
|
|
|
static void validate(char_type c, LaTeXFeatures & features);
|
2000-10-10 12:36:36 +00:00
|
|
|
|
|
2000-07-04 20:32:37 +00:00
|
|
|
|
private:
|
|
|
|
|
///
|
2000-10-10 12:36:36 +00:00
|
|
|
|
EncodingList encodinglist;
|
2000-07-04 20:32:37 +00:00
|
|
|
|
};
|
|
|
|
|
|
2000-10-10 12:36:36 +00:00
|
|
|
|
extern Encodings encodings;
|
2000-07-04 20:32:37 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
2000-07-04 20:32:37 +00:00
|
|
|
|
#endif
|