namespace {
/// Inset identifier (above 0x10ffff, for ucs-4)
char_type const META_INSET = 0x200001;
-};
+}
/////////////////////////////////////////////////////////////////////
void setRange(FontSpan const fp, SpellChecker::Result state)
{
- eraseCoveredRanges(fp);
+ Ranges result;
+ RangesIterator et = ranges_.end();
+ RangesIterator it = ranges_.begin();
+ for (; it != et; ++it) {
+ if (!it->covered(fp))
+ result.push_back(SpellResultRange(it->range(), it->result()));
+ else if (state == SpellChecker::WORD_OK) {
+ // trim or split the current misspelled range
+ // store misspelled ranges only
+ FontSpan range = it->range();
+ if (fp.first > range.first) {
+ // misspelled area in front of WORD_OK
+ range.last = fp.first - 1;
+ result.push_back(SpellResultRange(range, it->result()));
+ range = it->range();
+ }
+ if (fp.last < range.last) {
+ // misspelled area after WORD_OK range
+ range.first = fp.last + 1;
+ result.push_back(SpellResultRange(range, it->result()));
+ }
+ }
+ }
+ ranges_ = result;
if (state != SpellChecker::WORD_OK)
ranges_.push_back(SpellResultRange(fp, state));
}
return result;
}
+ FontSpan const & getRange(pos_type pos) const
+ {
+ /// empty span to indicate mismatch
+ static FontSpan empty_;
+ RangesIterator et = ranges_.end();
+ RangesIterator it = ranges_.begin();
+ for (; it != et; ++it) {
+ if(it->inside(pos)) {
+ return it->range();
+ }
+ }
+ return empty_;
+ }
+
bool needsRefresh() const {
return needs_refresh_;
}
if (pos > refresh_.last)
refresh_.last = pos;
} else if (pos != -1) {
- refresh_.first = pos;
- refresh_.last = pos;
+ // init request check for neighbour positions too
+ refresh_.first = pos > 0 ? pos - 1 : 0;
+ // no need for special end of paragraph check
+ refresh_.last = pos + 1;
}
needs_refresh_ = pos != -1;
}
SpellChecker::ChangeNumber current_change_number_;
- void eraseCoveredRanges(FontSpan const fp)
- {
- Ranges result;
- RangesIterator et = ranges_.end();
- RangesIterator it = ranges_.begin();
- for (; it != et; ++it) {
- if (!it->covered(fp))
- result.push_back(SpellResultRange(it->range(), it->result()));
- }
- ranges_ = result;
- }
-
void correctRangesAfterPos(pos_type pos, int offset)
{
RangesIterator et = ranges_.end();
/// Output the surrogate pair formed by \p c and \p next to \p os.
/// \return the number of characters written.
- int latexSurrogatePair(odocstream & os, char_type c, char_type next,
+ int latexSurrogatePair(otexstream & os, char_type c, char_type next,
OutputParams const &);
/// Output a space in appropriate formatting (or a surrogate pair
/// if the next character is a combining character).
/// \return whether a surrogate pair was output.
bool simpleTeXBlanks(OutputParams const &,
- odocstream &, TexRow & texrow,
+ otexstream &, TexRow & texrow,
pos_type i,
unsigned int & column,
Font const & font,
/// Output consecutive unicode chars, belonging to the same script as
/// specified by the latex macro \p ltx, to \p os starting from \p i.
/// \return the number of characters written.
- int writeScriptChars(odocstream & os, docstring const & ltx,
+ int writeScriptChars(otexstream & os, docstring const & ltx,
Change const &, Encoding const &, pos_type & i);
/// This could go to ParagraphParameters if we want to.
- int startTeXParParams(BufferParams const &, odocstream &, TexRow &,
+ int startTeXParParams(BufferParams const &, otexstream &, TexRow &,
OutputParams const &) const;
/// This could go to ParagraphParameters if we want to.
- int endTeXParParams(BufferParams const &, odocstream &, TexRow &,
+ int endTeXParParams(BufferParams const &, otexstream &, TexRow &,
OutputParams const &) const;
///
void latexInset(BufferParams const &,
- odocstream &,
+ otexstream &,
TexRow & texrow, OutputParams &,
Font & running_font,
Font & basefont,
///
void latexSpecialChar(
- odocstream & os,
+ otexstream & os,
OutputParams const & runparams,
Font const & running_font,
Change const & running_change,
///
bool latexSpecialT1(
char_type const c,
- odocstream & os,
+ otexstream & os,
pos_type i,
unsigned int & column);
///
bool latexSpecialTypewriter(
char_type const c,
- odocstream & os,
+ otexstream & os,
pos_type i,
unsigned int & column);
///
bool latexSpecialPhrase(
- odocstream & os,
+ otexstream & os,
pos_type & i,
unsigned int & column,
OutputParams const & runparams);
{
pos_type textsize = owner_->size();
// check for sane arguments
- if (to < from || from >= textsize)
+ if (to <= from || from >= textsize)
return;
- FontSpan fp = FontSpan(from, to);
- // don't mark end of paragraph
- if (fp.last >= textsize)
- fp.last = textsize - 1;
+ FontSpan fp = FontSpan(from, to - 1);
speller_state_.setRange(fp, state);
}
}
-int Paragraph::Private::latexSurrogatePair(odocstream & os, char_type c,
+int Paragraph::Private::latexSurrogatePair(otexstream & os, char_type c,
char_type next, OutputParams const & runparams)
{
// Writing next here may circumvent a possible font change between
bool Paragraph::Private::simpleTeXBlanks(OutputParams const & runparams,
- odocstream & os, TexRow & texrow,
+ otexstream & os, TexRow & texrow,
pos_type i,
unsigned int & column,
Font const & font,
}
-int Paragraph::Private::writeScriptChars(odocstream & os,
+int Paragraph::Private::writeScriptChars(otexstream & os,
docstring const & ltx,
Change const & runningChange,
Encoding const & encoding,
void Paragraph::Private::latexInset(BufferParams const & bparams,
- odocstream & os,
+ otexstream & os,
TexRow & texrow,
OutputParams & runparams,
Font & running_font,
LASSERT(inset, /**/);
if (style.pass_thru) {
- inset->plaintext(os, runparams);
+ inset->plaintext(os.os(), runparams);
return;
}
}
bool close = false;
- odocstream::pos_type const len = os.tellp();
+ odocstream::pos_type const len = os.os().tellp();
if (inset->forceLTR()
&& running_font.isRightToLeft()
texrow.start(owner_->id(), i + 1);
column = 0;
} else {
- column += (unsigned int)(os.tellp() - len);
+ column += (unsigned int)(os.os().tellp() - len);
}
if (owner_->isDeleted(i))
}
-void Paragraph::Private::latexSpecialChar(
- odocstream & os,
- OutputParams const & runparams,
- Font const & running_font,
- Change const & running_change,
- Layout const & style,
- pos_type & i,
- unsigned int & column)
+void Paragraph::Private::latexSpecialChar(otexstream & os,
+ OutputParams const & runparams,
+ Font const & running_font,
+ Change const & running_change,
+ Layout const & style,
+ pos_type & i,
+ unsigned int & column)
{
char_type const c = text_[i];
}
-bool Paragraph::Private::latexSpecialT1(char_type const c, odocstream & os,
+bool Paragraph::Private::latexSpecialT1(char_type const c, otexstream & os,
pos_type i, unsigned int & column)
{
switch (c) {
}
-bool Paragraph::Private::latexSpecialTypewriter(char_type const c, odocstream & os,
+bool Paragraph::Private::latexSpecialTypewriter(char_type const c, otexstream & os,
pos_type i, unsigned int & column)
{
switch (c) {
}
-bool Paragraph::Private::latexSpecialPhrase(odocstream & os, pos_type & i,
+bool Paragraph::Private::latexSpecialPhrase(otexstream & os, pos_type & i,
unsigned int & column, OutputParams const & runparams)
{
// FIXME: if we have "LaTeX" with a font
// output is wrong if this paragraph contains content
// that needs to switch encoding.
odocstringstream ods;
+ otexstream os(ods);
if (is_command) {
ods << '\\' << from_ascii(layout_->latexname());
// we have to provide all the optional arguments here, even though
// the last one is the only one we care about.
// Separate handling of optional argument inset.
if (layout_->optargs != 0 || layout_->reqargs != 0)
- latexArgInsets(*owner_, ods, features.runparams(),
- layout_->reqargs, layout_->optargs);
+ latexArgInsets(*owner_, os, features.runparams(),
+ layout_->reqargs, layout_->optargs);
else
- ods << from_ascii(layout_->latexparam());
+ os << from_ascii(layout_->latexparam());
}
docstring::size_type const length = ods.str().length();
// this will output "{" at the beginning, but not at the end
- owner_->latex(bp, f, ods, tr, features.runparams(), 0, -1, true);
+ owner_->latex(bp, f, os, tr, features.runparams(), 0, -1, true);
if (ods.str().length() > length) {
if (is_command)
ods << '}';
}
+bool Paragraph::isPassThru() const
+{
+ return inInset().getLayout().isPassThru() || d->layout_->pass_thru;
+}
+
namespace {
// paragraphs inside floats need different alignment tags to avoid
int Paragraph::Private::startTeXParParams(BufferParams const & bparams,
- odocstream & os, TexRow & texrow,
+ otexstream & os, TexRow & texrow,
OutputParams const & runparams) const
{
int column = 0;
- if (params_.noindent()) {
+ if (params_.noindent() && !layout_->pass_thru) {
os << "\\noindent ";
column += 10;
}
int Paragraph::Private::endTeXParParams(BufferParams const & bparams,
- odocstream & os, TexRow & texrow,
+ otexstream & os, TexRow & texrow,
OutputParams const & runparams) const
{
int column = 0;
// This one spits out the text of the paragraph
void Paragraph::latex(BufferParams const & bparams,
Font const & outerfont,
- odocstream & os, TexRow & texrow,
+ otexstream & os, TexRow & texrow,
OutputParams const & runparams,
int start_pos, int end_pos, bool force) const
{
if (!runparams.pass_thru && !style.pass_thru &&
runparams.encoding->package() != Encoding::none &&
font.language()->encoding()->package() != Encoding::none) {
- pair<bool, int> const enc_switch = switchEncoding(os, bparams,
- runparams, *(font.language()->encoding()));
+ pair<bool, int> const enc_switch =
+ switchEncoding(os.os(), bparams, runparams,
+ *(font.language()->encoding()));
if (enc_switch.first) {
column += enc_switch.second;
runparams.encoding = font.language()->encoding();
{
if (Inset const * inset = getInset(pos))
return !inset->isLetter();
+ if (pos == size())
+ return true;
char_type const c = d->text_[pos];
// We want to pass the ' and escape chars to the spellchecker
static docstring const quote = from_utf8(lyxrc.spellchecker_esc_chars + '\'');
- return (!isLetterChar(c) && !isDigitASCII(c) && !contains(quote, c))
- || pos == size();
+ return (!isLetterChar(c) && !isDigitASCII(c) && !contains(quote, c));
+}
+
+
+bool Paragraph::isSameSpellRange(pos_type pos1, pos_type pos2) const
+{
+ return pos1 == pos2
+ || d->speller_state_.getRange(pos1) == d->speller_state_.getRange(pos2);
}
}
+void Paragraph::forToc(docstring & os, size_t maxlen) const
+{
+ if (!d->params_.labelString().empty())
+ os += d->params_.labelString() + ' ';
+ for (pos_type i = 0; i < size() && os.length() < maxlen; ++i) {
+ if (isDeleted(i))
+ continue;
+ char_type const c = d->text_[i];
+ if (isPrintable(c))
+ os += c;
+ else if (c == '\t' || c == '\n')
+ os += ' ';
+ else if (c == META_INSET)
+ getInset(i)->forToc(os, maxlen);
+ }
+}
+
+
docstring Paragraph::stringify(pos_type beg, pos_type end, int options, OutputParams & runparams) const
{
odocstringstream os;
if (from == to || from >= size())
return result;
- docstring word = asString(from, to, AS_STR_INSETS + AS_STR_SKIPDELETE);
+ docstring word = asString(from, to, AS_STR_INSETS | AS_STR_SKIPDELETE);
Language * lang = d->getSpellLanguage(from);
wl = WordLangTuple(word, lang);
LYXERR(Debug::GUI, "misspelled word is correct with dot: \"" <<
word << "\" [" <<
from << ".." << to << "]");
+ } else {
+ // spell check with dot appended failed
+ // restore original word/lang value
+ word = asString(from, to, AS_STR_INSETS | AS_STR_SKIPDELETE);
+ wl = WordLangTuple(word, lang);
}
}
}
}
-bool Paragraph::isMisspelled(pos_type pos) const
+bool Paragraph::isMisspelled(pos_type pos, bool check_boundary) const
{
- return SpellChecker::misspelled(d->speller_state_.getState(pos));
+ bool result = SpellChecker::misspelled(d->speller_state_.getState(pos));
+ if (result || pos <= 0 || pos >= size())
+ return result;
+ if (check_boundary && isWordSeparator(pos))
+ result = SpellChecker::misspelled(d->speller_state_.getState(pos - 1));
+ return result;
}