texrow.newline();
}
- if (inputenc == "auto") {
- string const doc_encoding =
- language->encoding()->latexName();
- Encoding::Package const package =
- language->encoding()->package();
-
- // Create a list with all the input encodings used
- // in the document
- std::set<string> encodings =
- features.getEncodingSet(doc_encoding);
-
- if (!encodings.empty() || package == Encoding::inputenc) {
- os << "\\usepackage[";
- std::set<string>::const_iterator it = encodings.begin();
- std::set<string>::const_iterator const end = encodings.end();
- if (it != end) {
- os << from_ascii(*it);
- ++it;
- }
- for (; it != end; ++it)
- os << ',' << from_ascii(*it);
- if (package == Encoding::inputenc) {
- if (!encodings.empty())
- os << ',';
- os << from_ascii(doc_encoding);
- }
- os << "]{inputenc}\n";
- texrow.newline();
- }
- if (package == Encoding::CJK) {
- os << "\\usepackage{CJK}\n";
- texrow.newline();
- }
- } else if (inputenc != "default") {
- switch (language->encoding()->package()) {
- case Encoding::none:
- break;
- case Encoding::inputenc:
- os << "\\usepackage[" << from_ascii(inputenc)
- << "]{inputenc}\n";
- texrow.newline();
- break;
- case Encoding::CJK:
- os << "\\usepackage{CJK}\n";
- texrow.newline();
- break;
- }
- }
-
- // The encoding "armscii8" is only available when the package "armtex" is loaded.
- // armscii8 is used for Armenian.
- if (language->encoding()->latexName() == "armscii8" || inputenc == "armscii8") {
- os << "\\usepackage{armtex}\n";
- texrow.newline();
- }
+ // handle inputenc etc.
+ os << writeEncodingPreamble(features, texrow);
if (!listings_params.empty()) {
os << "\\usepackage{listings}\n";
}
+docstring const BufferParams::writeEncodingPreamble(LaTeXFeatures & features,
+ TexRow & texrow) const
+{
+ odocstringstream os;
+
+ if (inputenc == "auto") {
+ string const doc_encoding =
+ language->encoding()->latexName();
+ Encoding::Package const package =
+ language->encoding()->package();
+
+ // Create a list with all the input encodings used
+ // in the document
+ std::set<string> encodings =
+ features.getEncodingSet(doc_encoding);
+
+ if (!encodings.empty() || package == Encoding::inputenc) {
+ os << "\\usepackage[";
+ std::set<string>::const_iterator it = encodings.begin();
+ std::set<string>::const_iterator const end = encodings.end();
+ if (it != end) {
+ os << from_ascii(*it);
+ ++it;
+ }
+ for (; it != end; ++it)
+ os << ',' << from_ascii(*it);
+ if (package == Encoding::inputenc) {
+ if (!encodings.empty())
+ os << ',';
+ os << from_ascii(doc_encoding);
+ }
+ os << "]{inputenc}\n";
+ texrow.newline();
+ }
+ if (package == Encoding::CJK) {
+ os << "\\usepackage{CJK}\n";
+ texrow.newline();
+ }
+ } else if (inputenc != "default") {
+ switch (language->encoding()->package()) {
+ case Encoding::none:
+ break;
+ case Encoding::inputenc:
+ os << "\\usepackage[" << from_ascii(inputenc)
+ << "]{inputenc}\n";
+ texrow.newline();
+ break;
+ case Encoding::CJK:
+ os << "\\usepackage{CJK}\n";
+ texrow.newline();
+ break;
+ }
+ }
+
+ // The encoding "armscii8" is only available when the package "armtex" is loaded.
+ // armscii8 is used for Armenian.
+ if (language->encoding()->latexName() == "armscii8" || inputenc == "armscii8") {
+ os << "\\usepackage{armtex}\n";
+ texrow.newline();
+ }
+
+ return os.str();
+}
+
+
string const BufferParams::loadFonts(string const & rm,
string const & sf, string const & tt,
bool const & sc, bool const & osf,
std::string const paperSizeName() const;
/// set up if and how babel is called
std::string const babelCall(std::string const & lang_opts) const;
+ /// handle inputenc etc.
+ docstring const writeEncodingPreamble(LaTeXFeatures & features,
+ TexRow & texrow) const;
/// set up the document fonts
std::string const loadFonts(std::string const & rm,
std::string const & sf, std::string const & tt,
* Licence details can be found in the file COPYING.
*
* \author John Levon
+ * \author Jürgen Spitzmüller
*
* Full author contact details are available in file CREDITS.
*/
#include "Thesaurus.h"
+#include "debug.h"
#include "support/lstrings.h"
+#include "support/unicode.h"
#include <algorithm>
namespace lyx {
-#ifdef HAVE_LIBAIKSAURUS
-
using std::sort;
using std::string;
+using std::endl;
+#ifndef HAVE_LIBMYTHES
+#ifdef HAVE_LIBAIKSAURUS
Thesaurus::Thesaurus()
- : aik_(new Aiksaurus)
+ : thes_(new Aiksaurus)
{}
Thesaurus::~Thesaurus()
{
- delete aik_;
+ delete thes_;
}
return meanings;
string const text = to_ascii(t);
- if (!aik_->find(text.c_str()))
+ if (!thes_->find(text.c_str()))
return meanings;
// weird api, but ...
docstring meaning;
// correct, returns "" at the end
- string ret = aik_->next(cur_meaning);
+ string ret = thes_->next(cur_meaning);
while (!ret.empty()) {
if (cur_meaning != prev_meaning) {
meaning = from_ascii(ret);
- ret = aik_->next(cur_meaning);
+ ret = thes_->next(cur_meaning);
prev_meaning = cur_meaning;
} else {
if (ret != text)
meanings[meaning].push_back(from_ascii(ret));
}
- ret = aik_->next(cur_meaning);
+ ret = thes_->next(cur_meaning);
}
for (Meanings::iterator it = meanings.begin();
return meanings;
}
+#endif // HAVE_LIBAIKSAURUS
+#endif // !HAVE_LIBMYTHES
+
+
+#ifdef HAVE_LIBMYTHES
+
+namespace {
+
+string const to_iconv_encoding(docstring const & s, string const & encoding)
+{
+ std::vector<char> const encoded =
+ ucs4_to_eightbit(s.data(), s.length(), encoding);
+ return string(encoded.begin(), encoded.end());
+}
+
+
+docstring const from_iconv_encoding(string const & s, string const & encoding)
+{
+ std::vector<char_type> const ucs4 =
+ eightbit_to_ucs4(s.data(), s.length(), encoding);
+ return docstring(ucs4.begin(), ucs4.end());
+}
+
+} // namespace anon
+
+
+Thesaurus::Thesaurus()
+{
+ string const idx("/home/juergen/updates/MyThes-1.0/th_de_DE_v2.idx");
+ string const data("/home/juergen/updates/MyThes-1.0/th_de_DE_v2.dat");
+ char const * af = idx.c_str();
+ char const * df = data.c_str();
+ thes_ = new MyThes(af, df);
+}
+
+
+Thesaurus::~Thesaurus()
+{
+ if (thes_)
+ delete thes_;
+}
+
+
+Thesaurus::Meanings Thesaurus::lookup(docstring const & t)
+{
+ Meanings meanings;
+
+ string const encoding = thes_->get_th_encoding();
+
+ mentry * pmean;
+ string const text = to_iconv_encoding(support::lowercase(t), encoding);
+ int len = strlen(text.c_str());
+ int count = thes_->Lookup(text.c_str(), len, &pmean);
+ if (!count)
+ return meanings;
+
+ // don't change value of pmean or count
+ // they are needed for the CleanUpAfterLookup routine
+ mentry * pm = pmean;
+ docstring meaning;
+ docstring ret;
+ for (int i = 0; i < count; i++) {
+ meaning = from_iconv_encoding(string(pm->defn), encoding);
+ // remove silly item
+ if (support::prefixIs(meaning, '-'))
+ meaning = support::ltrim(meaning, "- ");
+ for (int j = 0; j < pm->count; j++) {
+ ret = from_iconv_encoding(string(pm->psyns[j]), encoding);
+ }
+ meanings[meaning].push_back(ret);
+ pm++;
+ }
+ // now clean up all allocated memory
+ thes_->CleanUpAfterLookup(&pmean, count);
+
+ for (Meanings::iterator it = meanings.begin();
+ it != meanings.end(); ++it)
+ sort(it->second.begin(), it->second.end());
+
+ return meanings;
+}
+
#else
Thesaurus::Thesaurus()
return Meanings();
}
-#endif // HAVE_LIBAIKSAURUS
+#endif // HAVE_LIBMYTHES
// Global instance
Thesaurus thesaurus;
#include <vector>
#include <map>
+#ifdef HAVE_LIBMYTHES
+#include MYTHES_H_LOCATION
+#else
#ifdef HAVE_LIBAIKSAURUS
#include AIKSAURUS_H_LOCATION
-#endif
+#endif // HAVE_LIBAIKSAURUS
+#endif // !HAVE_LIBMYTHES
namespace lyx {
Meanings lookup(docstring const & text);
private:
+#ifdef HAVE_LIBMYTHES
+ MyThes * thes_;
+#else
#ifdef HAVE_LIBAIKSAURUS
- Aiksaurus * aik_;
-#endif
+ Aiksaurus * thes_;
+#endif // HAVE_LIBAIKSAURUS
+#endif // !HAVE_LIBMYTHES
};
extern Thesaurus thesaurus;
#include "GraphicsCache.h"
#include "Buffer.h"
+#include "BufferParams.h"
#include "Converter.h"
#include "debug.h"
+#include "Encoding.h"
#include "Format.h"
#include "InsetIterator.h"
#include "Color.h"
+#include "LaTeXFeatures.h"
#include "LyXRC.h"
+#include "output.h"
#include "OutputParams.h"
#include "Paragraph.h"
+#include "TexRow.h"
#include "frontends/Application.h" // hexName
// Output the LaTeX file.
FileName const latexfile(filename_base + ".tex");
- // FIXME UNICODE
- // This creates an utf8 encoded file, but the proper inputenc
- // command is missing.
- odocfstream of(latexfile.toFilesystemEncoding().c_str());
+ // we use the encoding of the buffer
+ Encoding const & enc = buffer_.params().encoding();
+ odocfstream of(enc.iconvName());
+ TexRow texrow;
+ OutputParams runparams(&enc);
+ LaTeXFeatures features(buffer_, buffer_.params(), runparams);
+
+ if (!openFileWrite(of, latexfile))
+ return;
+
if (!of) {
LYXERR(Debug::GRAPHICS) << "PreviewLoader::startLoading()\n"
<< "Unable to create LaTeX file\n"
}
of << "\\batchmode\n";
dumpPreamble(of);
+ // handle inputenc etc.
+ of << buffer_.params().writeEncodingPreamble(features, texrow);
of << "\n\\begin{document}\n";
dumpData(of, inprogress.snippets);
of << "\n\\end{document}\n";
of.close();
+ if (of.fail()) {
+ LYXERR(Debug::GRAPHICS) << "PreviewLoader::startLoading()\n"
+ << "File was not closed properly."
+ << endl;
+ return;
+ }
// The conversion command.
ostringstream cs;