2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file paragraph_pimpl.C
|
|
|
|
|
* 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
|
|
|
|
|
* \author John Levon
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
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.
|
|
|
|
|
*/
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "paragraph_pimpl.h"
|
2006-04-13 16:47:57 +00:00
|
|
|
|
#include "paragraph.h"
|
2003-05-22 22:44:30 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "bufferparams.h"
|
2003-05-22 22:44:30 +00:00
|
|
|
|
#include "debug.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "encoding.h"
|
2003-05-22 22:44:30 +00:00
|
|
|
|
#include "language.h"
|
|
|
|
|
#include "LaTeXFeatures.h"
|
2003-09-16 09:44:34 +00:00
|
|
|
|
#include "LColor.h"
|
2003-09-09 17:00:19 +00:00
|
|
|
|
#include "lyxlength.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "lyxrc.h"
|
2003-11-05 12:06:20 +00:00
|
|
|
|
#include "outputparams.h"
|
2003-05-22 22:44:30 +00:00
|
|
|
|
#include "texrow.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2004-09-26 08:24:08 +00:00
|
|
|
|
#include <boost/next_prior.hpp>
|
2003-09-08 00:33:41 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
2003-09-08 00:33:41 +00:00
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
using std::endl;
|
|
|
|
|
using std::upper_bound;
|
2003-10-07 06:45:25 +00:00
|
|
|
|
using std::lower_bound;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
|
2001-11-27 10:34:16 +00:00
|
|
|
|
|
2001-11-27 11:57:57 +00:00
|
|
|
|
// Initialization of the counter for the paragraph id's,
|
|
|
|
|
unsigned int Paragraph::Pimpl::paragraph_id = 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2001-11-27 11:57:57 +00:00
|
|
|
|
namespace {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-07-20 16:42:15 +00:00
|
|
|
|
struct special_phrase {
|
|
|
|
|
string phrase;
|
2006-10-19 16:51:30 +00:00
|
|
|
|
docstring macro;
|
2002-07-20 16:42:15 +00:00
|
|
|
|
bool builtin;
|
|
|
|
|
};
|
2002-08-10 15:21:07 +00:00
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
special_phrase const special_phrases[] = {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
{ "LyX", from_ascii("\\LyX{}"), false },
|
|
|
|
|
{ "TeX", from_ascii("\\TeX{}"), true },
|
|
|
|
|
{ "LaTeX2e", from_ascii("\\LaTeXe{}"), true },
|
|
|
|
|
{ "LaTeX", from_ascii("\\LaTeX{}"), true },
|
2002-07-20 16:42:15 +00:00
|
|
|
|
};
|
|
|
|
|
|
2002-07-20 17:27:03 +00:00
|
|
|
|
size_t const phrases_nr = sizeof(special_phrases)/sizeof(special_phrase);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-11-27 11:57:57 +00:00
|
|
|
|
} // namespace anon
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
|
|
Paragraph::Pimpl::Pimpl(Paragraph * owner)
|
|
|
|
|
: owner_(owner)
|
|
|
|
|
{
|
|
|
|
|
inset_owner = 0;
|
|
|
|
|
id_ = paragraph_id++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-25 08:49:48 +00:00
|
|
|
|
Paragraph::Pimpl::Pimpl(Pimpl const & p, Paragraph * owner)
|
2006-10-21 12:20:39 +00:00
|
|
|
|
: params(p.params), changes_(p.changes_), owner_(owner)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
|
|
|
|
inset_owner = p.inset_owner;
|
|
|
|
|
fontlist = p.fontlist;
|
2003-05-25 08:49:48 +00:00
|
|
|
|
id_ = paragraph_id++;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
bool Paragraph::Pimpl::isChanged(pos_type start, pos_type end) const
|
|
|
|
|
{
|
2006-10-24 21:38:47 +00:00
|
|
|
|
BOOST_ASSERT(start >= 0 && start <= size());
|
|
|
|
|
BOOST_ASSERT(end > start && end <= size() + 1);
|
|
|
|
|
|
2006-10-21 12:20:39 +00:00
|
|
|
|
return changes_.isChanged(start, end);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-24 21:16:46 +00:00
|
|
|
|
bool Paragraph::Pimpl::isMergedOnEndOfParDeletion(bool trackChanges) const {
|
|
|
|
|
// keep the logic here in sync with the logic of eraseChars()
|
|
|
|
|
|
|
|
|
|
if (!trackChanges) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Change change = changes_.lookup(size());
|
|
|
|
|
|
|
|
|
|
return change.type == Change::INSERTED && change.author == 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 07:12:48 +00:00
|
|
|
|
void Paragraph::Pimpl::setChange(Change const & change)
|
|
|
|
|
{
|
2006-10-26 20:19:45 +00:00
|
|
|
|
// beware of the imaginary end-of-par character!
|
|
|
|
|
changes_.set(change, 0, size() + 1);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Propagate the change recursively - but not in case of DELETED!
|
|
|
|
|
*
|
|
|
|
|
* Imagine that your co-author makes changes in an existing inset. He
|
|
|
|
|
* sends your document to you and you come to the conclusion that the
|
|
|
|
|
* inset should go completely. If you erase it, LyX must not delete all
|
|
|
|
|
* text within the inset. Otherwise, the change tracked insertions of
|
|
|
|
|
* your co-author get lost and there is no way to restore them later.
|
|
|
|
|
*
|
|
|
|
|
* Conclusion: An inset's content should remain untouched if you delete it
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (change.type != Change::DELETED) {
|
|
|
|
|
for (pos_type pos = 0; pos < size(); ++pos) {
|
|
|
|
|
if (owner_->isInset(pos)) {
|
|
|
|
|
owner_->getInset(pos)->setChange(change);
|
2006-10-19 07:12:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Paragraph::Pimpl::setChange(pos_type pos, Change const & change)
|
2006-03-11 13:31:41 +00:00
|
|
|
|
{
|
2006-10-24 21:38:47 +00:00
|
|
|
|
BOOST_ASSERT(pos >= 0 && pos <= size());
|
|
|
|
|
|
2006-10-21 12:20:39 +00:00
|
|
|
|
changes_.set(change, pos);
|
2006-10-22 10:48:09 +00:00
|
|
|
|
|
2006-10-26 20:19:45 +00:00
|
|
|
|
// see comment in setChange(Change const &) above
|
|
|
|
|
|
|
|
|
|
if (change.type != Change::DELETED &&
|
|
|
|
|
pos < size() && owner_->isInset(pos)) {
|
2006-10-22 10:48:09 +00:00
|
|
|
|
owner_->getInset(pos)->setChange(change);
|
|
|
|
|
}
|
2006-03-11 13:31:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
2007-01-08 22:25:59 +00:00
|
|
|
|
Change const & Paragraph::Pimpl::lookupChange(pos_type pos) const
|
2003-02-08 19:18:01 +00:00
|
|
|
|
{
|
2006-10-24 21:38:47 +00:00
|
|
|
|
BOOST_ASSERT(pos >= 0 && pos <= size());
|
|
|
|
|
|
2006-10-21 12:20:39 +00:00
|
|
|
|
return changes_.lookup(pos);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
2003-03-03 21:15:49 +00:00
|
|
|
|
|
|
|
|
|
|
2007-01-23 21:53:16 +00:00
|
|
|
|
void Paragraph::Pimpl::acceptChanges(BufferParams const & bparams, pos_type start, pos_type end)
|
2003-02-08 19:18:01 +00:00
|
|
|
|
{
|
2006-10-24 21:38:47 +00:00
|
|
|
|
BOOST_ASSERT(start >= 0 && start <= size());
|
|
|
|
|
BOOST_ASSERT(end > start && end <= size() + 1);
|
2006-12-17 15:09:32 +00:00
|
|
|
|
|
2006-10-24 06:11:45 +00:00
|
|
|
|
for (pos_type pos = start; pos < end; ++pos) {
|
|
|
|
|
switch (lookupChange(pos).type) {
|
2003-02-08 19:18:01 +00:00
|
|
|
|
case Change::UNCHANGED:
|
2006-12-17 15:09:32 +00:00
|
|
|
|
// accept changes in nested inset
|
|
|
|
|
if (pos < size() && owner_->isInset(pos)) {
|
2007-01-23 21:53:16 +00:00
|
|
|
|
owner_->getInset(pos)->acceptChanges(bparams);
|
2006-12-17 15:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Change::INSERTED:
|
2006-10-24 06:11:45 +00:00
|
|
|
|
changes_.set(Change(Change::UNCHANGED), pos);
|
2006-12-17 15:09:32 +00:00
|
|
|
|
// also accept changes in nested inset
|
|
|
|
|
if (pos < size() && owner_->isInset(pos)) {
|
2007-01-23 21:53:16 +00:00
|
|
|
|
owner_->getInset(pos)->acceptChanges(bparams);
|
2006-12-17 15:09:32 +00:00
|
|
|
|
}
|
2003-02-08 19:18:01 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Change::DELETED:
|
2006-10-24 21:38:47 +00:00
|
|
|
|
// Suppress access to non-existent
|
|
|
|
|
// "end-of-paragraph char"
|
2006-10-24 06:11:45 +00:00
|
|
|
|
if (pos < size()) {
|
|
|
|
|
eraseChar(pos, false);
|
2006-03-11 13:31:41 +00:00
|
|
|
|
--end;
|
2006-10-24 06:11:45 +00:00
|
|
|
|
--pos;
|
2006-03-11 13:31:41 +00:00
|
|
|
|
}
|
2003-02-08 19:18:01 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-24 06:11:45 +00:00
|
|
|
|
}
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-01-23 21:53:16 +00:00
|
|
|
|
void Paragraph::Pimpl::rejectChanges(BufferParams const & bparams, pos_type start, pos_type end)
|
2003-02-08 19:18:01 +00:00
|
|
|
|
{
|
2006-10-24 21:38:47 +00:00
|
|
|
|
BOOST_ASSERT(start >= 0 && start <= size());
|
|
|
|
|
BOOST_ASSERT(end > start && end <= size() + 1);
|
2003-03-03 21:15:49 +00:00
|
|
|
|
|
2006-10-24 21:38:47 +00:00
|
|
|
|
for (pos_type pos = start; pos < end; ++pos) {
|
|
|
|
|
switch (lookupChange(pos).type) {
|
2003-02-08 19:18:01 +00:00
|
|
|
|
case Change::UNCHANGED:
|
2006-12-17 15:09:32 +00:00
|
|
|
|
// reject changes in nested inset
|
2006-10-26 20:44:00 +00:00
|
|
|
|
if (pos < size() && owner_->isInset(pos)) {
|
2007-01-23 21:53:16 +00:00
|
|
|
|
owner_->getInset(pos)->rejectChanges(bparams);
|
2006-10-26 20:44:00 +00:00
|
|
|
|
}
|
2003-02-08 19:18:01 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Change::INSERTED:
|
2006-10-24 21:38:47 +00:00
|
|
|
|
// Suppress access to non-existent
|
|
|
|
|
// "end-of-paragraph char"
|
|
|
|
|
if (pos < size()) {
|
|
|
|
|
eraseChar(pos, false);
|
2006-03-11 13:31:41 +00:00
|
|
|
|
--end;
|
2006-10-24 21:38:47 +00:00
|
|
|
|
--pos;
|
2006-03-11 13:31:41 +00:00
|
|
|
|
}
|
2003-02-08 19:18:01 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Change::DELETED:
|
2006-10-24 21:38:47 +00:00
|
|
|
|
changes_.set(Change(Change::UNCHANGED), pos);
|
|
|
|
|
|
2006-10-26 20:44:00 +00:00
|
|
|
|
// Do NOT reject changes within a deleted inset!
|
|
|
|
|
// There may be insertions of a co-author inside of it!
|
|
|
|
|
|
|
|
|
|
break;
|
2006-10-24 21:38:47 +00:00
|
|
|
|
}
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-03 21:15:49 +00:00
|
|
|
|
|
2001-11-26 16:42:04 +00:00
|
|
|
|
Paragraph::value_type Paragraph::Pimpl::getChar(pos_type pos) const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2006-10-24 21:38:47 +00:00
|
|
|
|
BOOST_ASSERT(pos >= 0 && pos <= size());
|
|
|
|
|
|
2003-09-16 14:08:05 +00:00
|
|
|
|
return owner_->getChar(pos);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 07:12:48 +00:00
|
|
|
|
void Paragraph::Pimpl::insertChar(pos_type pos, value_type c, Change const & change)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2006-10-24 21:38:47 +00:00
|
|
|
|
BOOST_ASSERT(pos >= 0 && pos <= size());
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2006-10-22 10:48:09 +00:00
|
|
|
|
// track change
|
|
|
|
|
changes_.insert(change, pos);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
2002-05-29 14:32:11 +00:00
|
|
|
|
// This is actually very common when parsing buffers (and
|
|
|
|
|
// maybe inserting ascii text)
|
|
|
|
|
if (pos == size()) {
|
|
|
|
|
// when appending characters, no need to update tables
|
2003-09-16 14:08:05 +00:00
|
|
|
|
owner_->text_.push_back(c);
|
2002-05-29 14:32:11 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-16 14:08:05 +00:00
|
|
|
|
owner_->text_.insert(owner_->text_.begin() + pos, c);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
|
|
// Update the font table.
|
|
|
|
|
FontTable search_font(pos, LyXFont());
|
2006-10-22 10:48:09 +00:00
|
|
|
|
for (FontList::iterator it
|
|
|
|
|
= lower_bound(fontlist.begin(), fontlist.end(), search_font, matchFT());
|
2001-06-25 00:06:33 +00:00
|
|
|
|
it != fontlist.end(); ++it)
|
2001-10-19 15:40:01 +00:00
|
|
|
|
{
|
2001-07-12 11:11:10 +00:00
|
|
|
|
it->pos(it->pos() + 1);
|
2001-10-19 15:40:01 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-08-11 15:03:52 +00:00
|
|
|
|
// Update the insets
|
|
|
|
|
owner_->insetlist.increasePosAfterPos(pos);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:48:09 +00:00
|
|
|
|
void Paragraph::Pimpl::insertInset(pos_type pos, InsetBase * inset,
|
|
|
|
|
Change const & change)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(inset);
|
2006-10-24 21:38:47 +00:00
|
|
|
|
BOOST_ASSERT(pos >= 0 && pos <= size());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-08-05 15:14:29 +00:00
|
|
|
|
insertChar(pos, META_INSET, change);
|
2003-09-16 14:08:05 +00:00
|
|
|
|
BOOST_ASSERT(owner_->text_[pos] == META_INSET);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-08-11 15:03:52 +00:00
|
|
|
|
// Add a new entry in the insetlist.
|
|
|
|
|
owner_->insetlist.insert(inset, pos);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 14:36:08 +00:00
|
|
|
|
bool Paragraph::Pimpl::eraseChar(pos_type pos, bool trackChanges)
|
2003-02-08 19:18:01 +00:00
|
|
|
|
{
|
2006-10-24 21:38:47 +00:00
|
|
|
|
BOOST_ASSERT(pos >= 0 && pos <= size());
|
2006-10-22 14:36:08 +00:00
|
|
|
|
|
2006-11-24 21:16:46 +00:00
|
|
|
|
// keep the logic here in sync with the logic of isMergedOnEndOfParDeletion()
|
|
|
|
|
|
2006-10-22 14:36:08 +00:00
|
|
|
|
if (trackChanges) {
|
2006-10-26 21:06:55 +00:00
|
|
|
|
Change change = changes_.lookup(pos);
|
2006-10-22 14:36:08 +00:00
|
|
|
|
|
2006-10-26 21:06:55 +00:00
|
|
|
|
// set the character to DELETED if
|
|
|
|
|
// a) it was previously unchanged or
|
|
|
|
|
// b) it was inserted by a co-author
|
|
|
|
|
|
|
|
|
|
if (change.type == Change::UNCHANGED ||
|
|
|
|
|
(change.type == Change::INSERTED && change.author != 0)) {
|
2006-10-22 14:36:08 +00:00
|
|
|
|
setChange(pos, Change(Change::DELETED));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-26 21:06:55 +00:00
|
|
|
|
if (change.type == Change::DELETED)
|
2006-10-22 14:36:08 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-10 21:49:37 +00:00
|
|
|
|
// Don't physically access the imaginary end-of-paragraph character.
|
|
|
|
|
// eraseChar() can only mark it as DELETED. A physical deletion of
|
|
|
|
|
// end-of-par must be handled externally.
|
2006-10-22 14:36:08 +00:00
|
|
|
|
if (pos == size()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-22 10:48:09 +00:00
|
|
|
|
// track change
|
|
|
|
|
changes_.erase(pos);
|
2006-10-19 17:46:50 +00:00
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
// if it is an inset, delete the inset entry
|
2003-09-16 14:08:05 +00:00
|
|
|
|
if (owner_->text_[pos] == Paragraph::META_INSET) {
|
2002-08-11 15:03:52 +00:00
|
|
|
|
owner_->insetlist.erase(pos);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-09-16 14:08:05 +00:00
|
|
|
|
owner_->text_.erase(owner_->text_.begin() + pos);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// Erase entries in the tables.
|
|
|
|
|
FontTable search_font(pos, LyXFont());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
FontList::iterator it =
|
2002-02-16 15:59:55 +00:00
|
|
|
|
lower_bound(fontlist.begin(),
|
2001-06-25 00:06:33 +00:00
|
|
|
|
fontlist.end(),
|
|
|
|
|
search_font, matchFT());
|
2001-07-12 11:11:10 +00:00
|
|
|
|
if (it != fontlist.end() && it->pos() == pos &&
|
2002-03-21 17:27:08 +00:00
|
|
|
|
(pos == 0 ||
|
|
|
|
|
(it != fontlist.begin()
|
2001-07-12 11:11:10 +00:00
|
|
|
|
&& boost::prior(it)->pos() == pos - 1))) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// If it is a multi-character font
|
|
|
|
|
// entry, we just make it smaller
|
|
|
|
|
// (see update below), otherwise we
|
|
|
|
|
// should delete it.
|
|
|
|
|
unsigned int const i = it - fontlist.begin();
|
|
|
|
|
fontlist.erase(fontlist.begin() + i);
|
|
|
|
|
it = fontlist.begin() + i;
|
|
|
|
|
if (i > 0 && i < fontlist.size() &&
|
|
|
|
|
fontlist[i - 1].font() == fontlist[i].font()) {
|
|
|
|
|
fontlist.erase(fontlist.begin() + i - 1);
|
|
|
|
|
it = fontlist.begin() + i - 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2006-10-19 17:46:50 +00:00
|
|
|
|
// Update all other entries
|
2001-06-25 00:06:33 +00:00
|
|
|
|
FontList::iterator fend = fontlist.end();
|
|
|
|
|
for (; it != fend; ++it)
|
2001-07-12 11:11:10 +00:00
|
|
|
|
it->pos(it->pos() - 1);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2006-10-19 17:46:50 +00:00
|
|
|
|
// Update the insetlist
|
2002-08-11 15:03:52 +00:00
|
|
|
|
owner_->insetlist.decreasePosAfterPos(pos);
|
2006-03-11 13:31:41 +00:00
|
|
|
|
|
2006-10-22 14:36:08 +00:00
|
|
|
|
return true;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-03-03 21:15:49 +00:00
|
|
|
|
|
2006-10-22 14:36:08 +00:00
|
|
|
|
int Paragraph::Pimpl::eraseChars(pos_type start, pos_type end, bool trackChanges)
|
2003-02-08 19:18:01 +00:00
|
|
|
|
{
|
2006-10-24 21:38:47 +00:00
|
|
|
|
BOOST_ASSERT(start >= 0 && start <= size());
|
2006-11-11 14:50:21 +00:00
|
|
|
|
BOOST_ASSERT(end >= start && end <= size() + 1);
|
2006-10-24 21:38:47 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
pos_type i = start;
|
2003-11-25 11:17:27 +00:00
|
|
|
|
for (pos_type count = end - start; count; --count) {
|
2006-10-21 17:05:20 +00:00
|
|
|
|
if (!eraseChar(i, trackChanges))
|
2003-02-08 19:18:01 +00:00
|
|
|
|
++i;
|
|
|
|
|
}
|
2003-04-29 09:40:49 +00:00
|
|
|
|
return end - i;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-03-03 21:15:49 +00:00
|
|
|
|
|
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
|
|
|
|
int Paragraph::Pimpl::latexSurrogatePair(odocstream & os, value_type c,
|
|
|
|
|
value_type next, Encoding const & encoding)
|
|
|
|
|
{
|
|
|
|
|
// Writing next here may circumvent a possible font change between
|
|
|
|
|
// c and next. Since next is only output if it forms a surrogate pair
|
|
|
|
|
// with c we can ignore this:
|
|
|
|
|
// A font change inside a surrogate pair does not make sense and is
|
|
|
|
|
// hopefully impossible to input.
|
|
|
|
|
// FIXME: change tracking
|
|
|
|
|
// Is this correct WRT change tracking?
|
|
|
|
|
docstring const latex1 = encoding.latexChar(next);
|
|
|
|
|
docstring const latex2 = encoding.latexChar(c);
|
|
|
|
|
os << latex1 << '{' << latex2 << '}';
|
|
|
|
|
return latex1.length() + latex2.length() + 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-16 18:20:49 +00:00
|
|
|
|
bool Paragraph::Pimpl::simpleTeXBlanks(Encoding const & encoding,
|
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
|
|
|
|
odocstream & os, TexRow & texrow,
|
|
|
|
|
pos_type & i,
|
2003-01-08 09:03:32 +00:00
|
|
|
|
unsigned int & column,
|
|
|
|
|
LyXFont const & font,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
LyXLayout const & style)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2003-03-15 15:56:07 +00:00
|
|
|
|
if (style.pass_thru)
|
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
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (i < size() - 1) {
|
|
|
|
|
char_type next = getChar(i + 1);
|
|
|
|
|
if (Encodings::isCombiningChar(next)) {
|
|
|
|
|
// This space has an accent, so we must always output it.
|
|
|
|
|
column += latexSurrogatePair(os, ' ', next, encoding) - 1;
|
|
|
|
|
++i;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-03-15 15:56:07 +00:00
|
|
|
|
|
2007-01-20 15:07:20 +00:00
|
|
|
|
if (lyxrc.plaintext_linelen > 0
|
|
|
|
|
&& column > lyxrc.plaintext_linelen
|
2002-03-21 17:27:08 +00:00
|
|
|
|
&& i
|
2001-07-06 19:56:32 +00:00
|
|
|
|
&& getChar(i - 1) != ' '
|
|
|
|
|
&& (i < size() - 1)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// same in FreeSpacing mode
|
2003-06-07 17:45:43 +00:00
|
|
|
|
&& !owner_->isFreeSpacing()
|
2002-03-21 17:27:08 +00:00
|
|
|
|
// In typewriter mode, we want to avoid
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// ! . ? : at the end of a line
|
|
|
|
|
&& !(font.family() == LyXFont::TYPEWRITER_FAMILY
|
2001-07-06 19:56:32 +00:00
|
|
|
|
&& (getChar(i - 1) == '.'
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|| getChar(i - 1) == '?'
|
2001-07-06 19:56:32 +00:00
|
|
|
|
|| getChar(i - 1) == ':'
|
|
|
|
|
|| getChar(i - 1) == '!'))) {
|
2002-08-09 00:42:12 +00:00
|
|
|
|
os << '\n';
|
2001-06-25 00:06:33 +00:00
|
|
|
|
texrow.newline();
|
2003-05-07 21:27:29 +00:00
|
|
|
|
texrow.start(owner_->id(), i + 1);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
column = 0;
|
2001-08-03 18:28:11 +00:00
|
|
|
|
} else if (style.free_spacing) {
|
|
|
|
|
os << '~';
|
|
|
|
|
} else {
|
|
|
|
|
os << ' ';
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
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
|
|
|
|
return false;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-20 16:42:15 +00:00
|
|
|
|
bool Paragraph::Pimpl::isTextAt(string const & str, pos_type pos) const
|
2001-11-23 09:59:01 +00:00
|
|
|
|
{
|
2002-05-29 22:07:59 +00:00
|
|
|
|
pos_type const len = str.length();
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2002-05-29 22:07:59 +00:00
|
|
|
|
// is the paragraph large enough?
|
|
|
|
|
if (pos + len > size())
|
|
|
|
|
return false;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-05-29 22:07:59 +00:00
|
|
|
|
// does the wanted text start at point?
|
2001-11-27 11:57:57 +00:00
|
|
|
|
for (string::size_type i = 0; i < str.length(); ++i) {
|
2007-01-25 21:02:08 +00:00
|
|
|
|
// Caution: direct comparison of characters works only
|
|
|
|
|
// because str is pure ASCII.
|
2003-09-16 14:08:05 +00:00
|
|
|
|
if (str[i] != owner_->text_[pos + i])
|
2001-11-27 11:57:57 +00:00
|
|
|
|
return false;
|
2001-11-23 09:59:01 +00:00
|
|
|
|
}
|
2002-05-29 22:07:59 +00:00
|
|
|
|
|
|
|
|
|
// is there a font change in middle of the word?
|
|
|
|
|
FontList::const_iterator cit = fontlist.begin();
|
|
|
|
|
FontList::const_iterator end = fontlist.end();
|
|
|
|
|
for (; cit != end; ++cit) {
|
|
|
|
|
if (cit->pos() >= pos)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (cit != end && pos + len - 1 > cit->pos())
|
|
|
|
|
return false;
|
|
|
|
|
|
2001-11-23 09:59:01 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-03 21:15:49 +00:00
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
BufferParams const & bparams,
|
2006-10-19 16:51:30 +00:00
|
|
|
|
odocstream & os,
|
2001-06-27 15:33:55 +00:00
|
|
|
|
TexRow & texrow,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const & runparams,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
LyXFont & running_font,
|
|
|
|
|
LyXFont & basefont,
|
2003-04-15 00:49:11 +00:00
|
|
|
|
LyXFont const & outerfont,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
bool & open_font,
|
2003-02-08 19:18:01 +00:00
|
|
|
|
Change::Type & running_change,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
LyXLayout const & style,
|
2001-11-26 16:42:04 +00:00
|
|
|
|
pos_type & i,
|
2003-01-08 09:03:32 +00:00
|
|
|
|
unsigned int & column,
|
2001-11-26 16:42:04 +00:00
|
|
|
|
value_type const c)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2001-07-17 09:41:34 +00:00
|
|
|
|
if (style.pass_thru) {
|
2003-03-15 15:56:07 +00:00
|
|
|
|
if (c != Paragraph::META_INSET) {
|
|
|
|
|
if (c != '\0')
|
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
|
|
|
|
// FIXME UNICODE: This can fail if c cannot
|
|
|
|
|
// be encoded in the current encoding.
|
2006-10-19 16:51:30 +00:00
|
|
|
|
os.put(c);
|
|
|
|
|
} else
|
|
|
|
|
owner_->getInset(i)->plaintext(buf, os, runparams);
|
2001-07-17 09:41:34 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2003-03-11 15:01:29 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// Two major modes: LaTeX or plain
|
|
|
|
|
// Handle here those cases common to both modes
|
|
|
|
|
// and then split to handle the two modes separately.
|
|
|
|
|
switch (c) {
|
|
|
|
|
case Paragraph::META_INSET: {
|
2004-01-26 10:13:15 +00:00
|
|
|
|
InsetBase * inset = owner_->getInset(i);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
|
|
|
|
// FIXME: remove this check
|
|
|
|
|
if (!inset)
|
|
|
|
|
break;
|
2003-03-03 21:15:49 +00:00
|
|
|
|
|
2003-03-12 19:16:42 +00:00
|
|
|
|
// FIXME: move this to InsetNewline::latex
|
2004-01-26 10:13:15 +00:00
|
|
|
|
if (inset->lyxCode() == InsetBase::NEWLINE_CODE) {
|
2003-03-12 19:16:42 +00:00
|
|
|
|
// newlines are handled differently here than
|
|
|
|
|
// the default in simpleTeXSpecialChars().
|
|
|
|
|
if (!style.newline_allowed) {
|
|
|
|
|
os << '\n';
|
|
|
|
|
} else {
|
|
|
|
|
if (open_font) {
|
2007-01-09 19:25:40 +00:00
|
|
|
|
column += running_font.latexWriteEndChanges(
|
2007-03-18 10:59:16 +00:00
|
|
|
|
os, basefont, basefont);
|
2003-03-12 19:16:42 +00:00
|
|
|
|
open_font = false;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-13 19:46:56 +00:00
|
|
|
|
if (running_font.family() == LyXFont::TYPEWRITER_FAMILY)
|
2003-03-12 19:16:42 +00:00
|
|
|
|
os << '~';
|
|
|
|
|
|
2007-03-13 19:46:56 +00:00
|
|
|
|
basefont = owner_->getLayoutFont(bparams, outerfont);
|
|
|
|
|
running_font = basefont;
|
|
|
|
|
|
2003-05-23 09:23:03 +00:00
|
|
|
|
if (runparams.moving_arg)
|
2003-03-12 19:16:42 +00:00
|
|
|
|
os << "\\protect ";
|
|
|
|
|
|
|
|
|
|
os << "\\\\\n";
|
|
|
|
|
}
|
|
|
|
|
texrow.newline();
|
2003-05-07 21:27:29 +00:00
|
|
|
|
texrow.start(owner_->id(), i + 1);
|
2003-03-12 19:16:42 +00:00
|
|
|
|
column = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-24 17:12:19 +00:00
|
|
|
|
// output change tracking marks only if desired,
|
|
|
|
|
// if dvipost is installed,
|
|
|
|
|
// and with dvi/ps (other formats don't work)
|
2006-03-28 18:49:46 +00:00
|
|
|
|
LaTeXFeatures features(buf, bparams, runparams);
|
2006-10-06 18:53:35 +00:00
|
|
|
|
bool const output = bparams.outputChanges
|
2005-01-24 17:12:19 +00:00
|
|
|
|
&& runparams.flavor == OutputParams::LATEX
|
|
|
|
|
&& features.isAvailable("dvipost");
|
|
|
|
|
|
2006-03-17 19:45:28 +00:00
|
|
|
|
if (inset->canTrackChanges()) {
|
2003-02-08 19:18:01 +00:00
|
|
|
|
column += Changes::latexMarkChange(os, running_change,
|
2005-01-24 17:12:19 +00:00
|
|
|
|
Change::UNCHANGED, output);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
running_change = Change::UNCHANGED;
|
|
|
|
|
}
|
2003-03-03 21:15:49 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
bool close = false;
|
2006-10-19 16:51:30 +00:00
|
|
|
|
odocstream::pos_type const len = os.tellp();
|
2003-10-22 22:22:55 +00:00
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
if ((inset->lyxCode() == InsetBase::GRAPHICS_CODE
|
|
|
|
|
|| inset->lyxCode() == InsetBase::MATH_CODE
|
|
|
|
|
|| inset->lyxCode() == InsetBase::URL_CODE)
|
2003-02-08 19:18:01 +00:00
|
|
|
|
&& running_font.isRightToLeft()) {
|
|
|
|
|
os << "\\L{";
|
|
|
|
|
close = true;
|
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2002-07-23 21:03:38 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
|
#warning Bug: we can have an empty font change here!
|
|
|
|
|
// if there has just been a font change, we are going to close it
|
|
|
|
|
// right now, which means stupid latex code like \textsf{}. AFAIK,
|
|
|
|
|
// this does not harm dvi output. A minor bug, thus (JMarc)
|
|
|
|
|
#endif
|
2003-02-08 19:18:01 +00:00
|
|
|
|
// some insets cannot be inside a font change command
|
|
|
|
|
if (open_font && inset->noFontChange()) {
|
2007-01-09 19:25:40 +00:00
|
|
|
|
column += running_font.latexWriteEndChanges(
|
2007-03-18 10:59:16 +00:00
|
|
|
|
os, basefont, basefont);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
open_font = false;
|
2003-04-15 00:49:11 +00:00
|
|
|
|
basefont = owner_->getLayoutFont(bparams, outerfont);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
running_font = basefont;
|
|
|
|
|
}
|
2002-07-23 21:03:38 +00:00
|
|
|
|
|
2003-05-23 08:59:47 +00:00
|
|
|
|
int tmp = inset->latex(buf, os, runparams);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
if (close)
|
|
|
|
|
os << '}';
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
if (tmp) {
|
|
|
|
|
for (int j = 0; j < tmp; ++j) {
|
|
|
|
|
texrow.newline();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
2003-05-07 21:27:29 +00:00
|
|
|
|
texrow.start(owner_->id(), i + 1);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
column = 0;
|
|
|
|
|
} else {
|
2003-10-22 22:22:55 +00:00
|
|
|
|
column += os.tellp() - len;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
// And now for the special cases within each mode
|
2001-08-03 18:28:11 +00:00
|
|
|
|
|
|
|
|
|
switch (c) {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
case '\\':
|
2001-08-03 18:28:11 +00:00
|
|
|
|
os << "\\textbackslash{}";
|
|
|
|
|
column += 15;
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2006-10-21 15:03:21 +00:00
|
|
|
|
// The following characters could be written literally in latin1, but they
|
|
|
|
|
// would be wrongly converted on systems where char is signed, so we give
|
|
|
|
|
// the code points.
|
|
|
|
|
// This also makes us independant from the encoding of this source file.
|
2001-08-03 18:28:11 +00:00
|
|
|
|
case '|': case '<': case '>':
|
|
|
|
|
// In T1 encoding, these characters exist
|
|
|
|
|
if (lyxrc.fontenc == "T1") {
|
2006-10-19 20:01:02 +00:00
|
|
|
|
os.put(c);
|
2001-08-03 18:28:11 +00:00
|
|
|
|
//... but we should avoid ligatures
|
|
|
|
|
if ((c == '>' || c == '<')
|
|
|
|
|
&& i <= size() - 2
|
|
|
|
|
&& getChar(i + 1) == c) {
|
|
|
|
|
//os << "\\textcompwordmark{}";
|
2007-01-20 17:21:52 +00:00
|
|
|
|
//column += 19;
|
2001-08-03 18:28:11 +00:00
|
|
|
|
// Jean-Marc, have a look at
|
|
|
|
|
// this. I<>think this works
|
|
|
|
|
// equally well:
|
|
|
|
|
os << "\\,{}";
|
|
|
|
|
// Lgb
|
2007-01-20 17:21:52 +00:00
|
|
|
|
column += 3;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2001-08-03 18:28:11 +00:00
|
|
|
|
// Typewriter font also has them
|
2007-03-13 19:46:56 +00:00
|
|
|
|
if (running_font.family() == LyXFont::TYPEWRITER_FAMILY) {
|
2006-10-19 20:01:02 +00:00
|
|
|
|
os.put(c);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
}
|
2001-08-03 18:28:11 +00:00
|
|
|
|
// Otherwise, we use what LaTeX
|
|
|
|
|
// provides us.
|
|
|
|
|
switch (c) {
|
|
|
|
|
case '<':
|
|
|
|
|
os << "\\textless{}";
|
|
|
|
|
column += 10;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
break;
|
2001-08-03 18:28:11 +00:00
|
|
|
|
case '>':
|
|
|
|
|
os << "\\textgreater{}";
|
|
|
|
|
column += 13;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
break;
|
2001-08-03 18:28:11 +00:00
|
|
|
|
case '|':
|
|
|
|
|
os << "\\textbar{}";
|
2001-06-25 00:06:33 +00:00
|
|
|
|
column += 9;
|
|
|
|
|
break;
|
2001-08-03 18:28:11 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
case '-': // "--" in Typewriter mode -> "-{}-"
|
2007-03-13 19:46:56 +00:00
|
|
|
|
if (i <= size() - 2 &&
|
|
|
|
|
getChar(i + 1) == '-' &&
|
|
|
|
|
running_font.family() == LyXFont::TYPEWRITER_FAMILY) {
|
2001-08-03 18:28:11 +00:00
|
|
|
|
os << "-{}";
|
2001-06-25 00:06:33 +00:00
|
|
|
|
column += 2;
|
2001-08-03 18:28:11 +00:00
|
|
|
|
} else {
|
|
|
|
|
os << '-';
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
2001-08-03 18:28:11 +00:00
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
|
|
|
|
case '\"':
|
2001-08-03 18:28:11 +00:00
|
|
|
|
os << "\\char`\\\"{}";
|
|
|
|
|
column += 9;
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
case '$': case '&':
|
|
|
|
|
case '%': case '#': case '{':
|
|
|
|
|
case '}': case '_':
|
2006-10-19 20:01:02 +00:00
|
|
|
|
os << '\\';
|
|
|
|
|
os.put(c);
|
2001-08-03 18:28:11 +00:00
|
|
|
|
column += 1;
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
case '~':
|
|
|
|
|
os << "\\textasciitilde{}";
|
|
|
|
|
column += 16;
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
case '^':
|
|
|
|
|
os << "\\textasciicircum{}";
|
|
|
|
|
column += 17;
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-09-26 08:24:08 +00:00
|
|
|
|
case '*': case '[':
|
2001-08-03 18:28:11 +00:00
|
|
|
|
// avoid being mistaken for optional arguments
|
2006-10-20 08:06:14 +00:00
|
|
|
|
os << '{';
|
|
|
|
|
os.put(c);
|
|
|
|
|
os << '}';
|
2001-08-03 18:28:11 +00:00
|
|
|
|
column += 2;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ' ':
|
|
|
|
|
// Blanks are printed before font switching.
|
|
|
|
|
// Sure? I am not! (try nice-latex)
|
2002-03-21 17:27:08 +00:00
|
|
|
|
// I am sure it's correct. LyX might be smarter
|
|
|
|
|
// in the future, but for now, nothing wrong is
|
|
|
|
|
// written. (Asger)
|
2001-08-03 18:28:11 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-11-23 09:59:01 +00:00
|
|
|
|
// I assume this is hack treating typewriter as verbatim
|
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
|
|
|
|
// FIXME UNICODE: This can fail if c cannot be encoded
|
|
|
|
|
// in the current encoding.
|
2007-03-13 19:46:56 +00:00
|
|
|
|
if (running_font.family() == LyXFont::TYPEWRITER_FAMILY) {
|
2001-11-23 09:59:01 +00:00
|
|
|
|
if (c != '\0') {
|
2006-10-19 19:28:27 +00:00
|
|
|
|
os.put(c);
|
2001-11-23 09:59:01 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-11-27 11:57:57 +00:00
|
|
|
|
// LyX, LaTeX etc.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-07-20 16:42:15 +00:00
|
|
|
|
// FIXME: if we have "LaTeX" with a font
|
|
|
|
|
// change in the middle (before the 'T', then
|
|
|
|
|
// the "TeX" part is still special cased.
|
|
|
|
|
// Really we should only operate this on
|
|
|
|
|
// "words" for some definition of word
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-11-27 11:57:57 +00:00
|
|
|
|
size_t pnr = 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-11-27 11:57:57 +00:00
|
|
|
|
for (; pnr < phrases_nr; ++pnr) {
|
2002-07-20 16:42:15 +00:00
|
|
|
|
if (isTextAt(special_phrases[pnr].phrase, i)) {
|
|
|
|
|
os << special_phrases[pnr].macro;
|
|
|
|
|
i += special_phrases[pnr].phrase.length() - 1;
|
|
|
|
|
column += special_phrases[pnr].macro.length() - 1;
|
2001-11-27 11:57:57 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pnr == phrases_nr && c != '\0') {
|
2007-04-16 18:06:01 +00:00
|
|
|
|
Encoding const & encoding = *(runparams.encoding);
|
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
|
|
|
|
if (i < size() - 1) {
|
|
|
|
|
char_type next = getChar(i + 1);
|
|
|
|
|
if (Encodings::isCombiningChar(next)) {
|
|
|
|
|
column += latexSurrogatePair(os, c, next, encoding) - 1;
|
|
|
|
|
++i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
docstring const latex = encoding.latexChar(c);
|
|
|
|
|
if (latex.length() > 1 &&
|
|
|
|
|
latex[latex.length() - 1] != '}') {
|
|
|
|
|
// Prevent eating of a following
|
|
|
|
|
// space or command corruption by
|
|
|
|
|
// following characters
|
|
|
|
|
column += latex.length() + 1;
|
|
|
|
|
os << latex << "{}";
|
|
|
|
|
} else {
|
|
|
|
|
column += latex.length() - 1;
|
|
|
|
|
os << latex;
|
|
|
|
|
}
|
2001-08-03 18:28:11 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-20 16:42:15 +00:00
|
|
|
|
void Paragraph::Pimpl::validate(LaTeXFeatures & features,
|
|
|
|
|
LyXLayout const & layout) const
|
|
|
|
|
{
|
|
|
|
|
BufferParams const & bparams = features.bufferParams();
|
|
|
|
|
|
|
|
|
|
// check the params.
|
|
|
|
|
if (!params.spacing().isDefault())
|
|
|
|
|
features.require("setspace");
|
|
|
|
|
|
|
|
|
|
// then the layouts
|
|
|
|
|
features.useLayout(layout.name());
|
|
|
|
|
|
|
|
|
|
// then the fonts
|
|
|
|
|
Language const * doc_language = bparams.language;
|
|
|
|
|
|
|
|
|
|
FontList::const_iterator fcit = fontlist.begin();
|
|
|
|
|
FontList::const_iterator fend = fontlist.end();
|
|
|
|
|
for (; fcit != fend; ++fcit) {
|
|
|
|
|
if (fcit->font().noun() == LyXFont::ON) {
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::LATEX) << "font.noun: "
|
2002-07-20 16:42:15 +00:00
|
|
|
|
<< fcit->font().noun()
|
|
|
|
|
<< endl;
|
|
|
|
|
features.require("noun");
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::LATEX) << "Noun enabled. Font: "
|
2006-12-21 14:31:19 +00:00
|
|
|
|
<< to_utf8(fcit->font().stateText(0))
|
2002-07-20 16:42:15 +00:00
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
switch (fcit->font().color()) {
|
|
|
|
|
case LColor::none:
|
|
|
|
|
case LColor::inherit:
|
|
|
|
|
case LColor::ignore:
|
|
|
|
|
// probably we should put here all interface colors used for
|
|
|
|
|
// font displaying! For now I just add this ones I know of (Jug)
|
|
|
|
|
case LColor::latex:
|
|
|
|
|
case LColor::note:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
features.require("color");
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::LATEX) << "Color enabled. Font: "
|
2006-12-21 14:31:19 +00:00
|
|
|
|
<< to_utf8(fcit->font().stateText(0))
|
2002-07-20 16:42:15 +00:00
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Language const * language = fcit->font().language();
|
|
|
|
|
if (language->babel() != doc_language->babel() &&
|
|
|
|
|
language != ignore_language &&
|
|
|
|
|
language != latex_language)
|
|
|
|
|
{
|
|
|
|
|
features.useLanguage(language);
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::LATEX) << "Found language "
|
2002-07-20 16:42:15 +00:00
|
|
|
|
<< language->babel() << endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!params.leftIndent().zero())
|
|
|
|
|
features.require("ParagraphLeftIndent");
|
|
|
|
|
|
|
|
|
|
// then the insets
|
2004-05-17 11:28:31 +00:00
|
|
|
|
InsetList::const_iterator icit = owner_->insetlist.begin();
|
|
|
|
|
InsetList::const_iterator iend = owner_->insetlist.end();
|
2002-07-20 16:42:15 +00:00
|
|
|
|
for (; icit != iend; ++icit) {
|
2003-05-29 01:13:18 +00:00
|
|
|
|
if (icit->inset) {
|
|
|
|
|
icit->inset->validate(features);
|
2002-07-20 16:42:15 +00:00
|
|
|
|
if (layout.needprotect &&
|
2004-01-26 10:13:15 +00:00
|
|
|
|
icit->inset->lyxCode() == InsetBase::FOOT_CODE)
|
2002-07-20 16:42:15 +00:00
|
|
|
|
features.require("NeedLyXFootnoteCode");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// then the contents
|
|
|
|
|
for (pos_type i = 0; i < size() ; ++i) {
|
|
|
|
|
for (size_t pnr = 0; pnr < phrases_nr; ++pnr) {
|
|
|
|
|
if (!special_phrases[pnr].builtin
|
|
|
|
|
&& isTextAt(special_phrases[pnr].phrase, i)) {
|
|
|
|
|
features.require(special_phrases[pnr].phrase);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-04-16 18:06:01 +00:00
|
|
|
|
Encodings::validate(getChar(i), features);
|
2002-08-10 15:21:07 +00:00
|
|
|
|
}
|
2002-07-20 16:42:15 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|