#include "InsetList.h"
#include "Language.h"
#include "LaTeXFeatures.h"
-#include "Color.h"
#include "Layout.h"
#include "Length.h"
#include "Font.h"
using support::prefixIs;
using support::suffixIs;
using support::rsplit;
-using support::rtrim;
using support::uppercase;
namespace {
/// 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(Encoding const &,
+ bool simpleTeXBlanks(OutputParams const &,
odocstream &, TexRow & texrow,
pos_type i,
unsigned int & column,
Font const & font,
Layout const & style);
- /// Output consecutive known unicode chars, belonging to the same
- /// language as specified by \p preamble, to \p os starting from \p c.
+ /// 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 knownLangChars(odocstream & os, char_type c, string & preamble,
- Change &, Encoding const &, pos_type &);
+ int writeScriptChars(odocstream & os, docstring const & ltx,
+ Change &, Encoding const &, pos_type & i);
/// This could go to ParagraphParameters if we want to.
int startTeXParParams(BufferParams const &, odocstream &, TexRow &,
// This is actually very common when parsing buffers (and
// maybe inserting ascii text)
- if (pos == text_.size()) {
+ if (pos == pos_type(text_.size())) {
// when appending characters, no need to update tables
text_.push_back(c);
return;
}
-bool Paragraph::Private::simpleTeXBlanks(Encoding const & encoding,
+bool Paragraph::Private::simpleTeXBlanks(OutputParams const & runparams,
odocstream & os, TexRow & texrow,
pos_type i,
unsigned int & column,
Font const & font,
Layout const & style)
{
- if (style.pass_thru)
+ if (style.pass_thru || runparams.verbatim)
return false;
if (i + 1 < int(text_.size())) {
char_type next = text_[i + 1];
if (Encodings::isCombiningChar(next)) {
+ Encoding const & encoding = *(runparams.encoding);
// This space has an accent, so we must always output it.
column += latexSurrogatePair(os, ' ', next, encoding) - 1;
return true;
&& !owner_->isFreeSpacing()
// In typewriter mode, we want to avoid
// ! . ? : at the end of a line
- && !(font.family() == Font::TYPEWRITER_FAMILY
+ && !(font.fontInfo().family() == TYPEWRITER_FAMILY
&& (text_[i - 1] == '.'
|| text_[i - 1] == '?'
|| text_[i - 1] == ':'
}
-int Paragraph::Private::knownLangChars(odocstream & os,
- char_type c,
- string & preamble,
- Change & runningChange,
- Encoding const & encoding,
- pos_type & i)
-{
- // When the character is marked by the proper language, we simply
- // get its code point in some encoding, otherwise we get the
- // translation specified in the unicodesymbols file, which is
- // something like "\textLANG{<spec>}". So, we have to retain
- // "\textLANG{<spec>" for the first char but only "<spec>" for
- // all subsequent chars.
- docstring const latex1 = rtrim(encoding.latexChar(c), "}");
- int length = latex1.length();
- os << latex1;
+int Paragraph::Private::writeScriptChars(odocstream & os,
+ docstring const & ltx,
+ Change & runningChange,
+ Encoding const & encoding,
+ pos_type & i)
+{
+ // FIXME: modifying i here is not very nice...
+
+ // We only arrive here when a proper language for character text_[i] has
+ // not been specified (i.e., it could not be translated in the current
+ // latex encoding) and it belongs to a known script.
+ // Parameter ltx contains the latex translation of text_[i] as specified in
+ // the unicodesymbols file and is something like "\textXXX{<spec>}".
+ // The latex macro name "textXXX" specifies the script to which text_[i]
+ // belongs and we use it in order to check whether characters from the
+ // same script immediately follow, such that we can collect them in a
+ // single "\textXXX" macro. So, we have to retain "\textXXX{<spec>"
+ // for the first char but only "<spec>" for all subsequent chars.
+ docstring::size_type const brace1 = ltx.find_first_of(from_ascii("{"));
+ docstring::size_type const brace2 = ltx.find_last_of(from_ascii("}"));
+ string script = to_ascii(ltx.substr(1, brace1 - 1));
+ int length = ltx.substr(0, brace2).length();
+ os << ltx.substr(0, brace2);
int size = text_.size();
while (i + 1 < size) {
- char_type next = text_[i + 1];
- // Stop here if next character belongs to another
- // language or there is a change tracking status.
- if (!Encodings::isKnownLangChar(next, preamble) ||
+ char_type const next = text_[i + 1];
+ // Stop here if next character belongs to another script
+ // or there is a change in change tracking status.
+ if (!Encodings::isKnownScriptChar(next, script) ||
runningChange != owner_->lookupChange(i + 1))
break;
Font prev_font;
if (cit->pos() >= i + 1)
break;
}
- // Stop here if there is a font attribute change.
+ // Stop here if there is a font attribute or encoding change.
if (found && cit != end && prev_font != cit->font())
break;
- docstring const latex = rtrim(encoding.latexChar(next), "}");
- docstring::size_type const j =
+ docstring const latex = encoding.latexChar(next);
+ docstring::size_type const b1 =
latex.find_first_of(from_ascii("{"));
- if (j == docstring::npos) {
- os << latex;
- length += latex.length();
- } else {
- os << latex.substr(j + 1);
- length += latex.substr(j + 1).length();
- }
+ docstring::size_type const b2 =
+ latex.find_last_of(from_ascii("}"));
+ int const len = b2 - b1 - 1;
+ os << latex.substr(b1 + 1, len);
+ length += len;
++i;
}
- // When the proper language is set, we are simply passed a code
- // point, so we should not try to close the \textLANG command.
- if (prefixIs(latex1, from_ascii("\\" + preamble))) {
- os << '}';
- ++length;
- }
+ os << '}';
+ ++length;
return length;
}
open_font = false;
}
- if (running_font.family() == Font::TYPEWRITER_FAMILY)
+ if (running_font.fontInfo().family() == TYPEWRITER_FAMILY)
os << '~';
basefont = owner_->getLayoutFont(bparams, outerfont);
if (lyxrc.fontenc == "T1" && latexSpecialT1(c, os, i, column))
return;
- if (running_font.family() == Font::TYPEWRITER_FAMILY
+ if (running_font.fontInfo().family() == TYPEWRITER_FAMILY
&& latexSpecialTypewriter(c, os, i, column))
return;
break;
}
}
- string preamble;
- if (Encodings::isKnownLangChar(c, preamble)) {
- column += knownLangChars(os, c, preamble, running_change,
- encoding, i) - 1;
- break;
- }
+ string script;
docstring const latex = encoding.latexChar(c);
- if (latex.length() > 1 && latex[latex.length() - 1] != '}') {
+ if (Encodings::isKnownScriptChar(c, script)
+ && prefixIs(latex, from_ascii("\\" + script)))
+ column += writeScriptChars(os, latex,
+ running_change, encoding, i) - 1;
+ else if (latex.length() > 1 && latex[latex.length() - 1] != '}') {
// Prevent eating of a following
// space or command corruption by
// following characters
params().write(os);
- Font font1(Font::ALL_INHERIT, bparams.language);
+ Font font1(inherit_font, bparams.language);
Change running_change = Change(Change::UNCHANGED);
void Paragraph::appendString(docstring const & s, Font const & font,
Change const & change)
{
- size_t end = s.size();
+ pos_type end = s.size();
size_t oldsize = d->text_.size();
size_t newsize = oldsize + end;
size_t capacity = d->text_.capacity();
// track change
d->changes_.insert(change, i);
}
- d->fontlist_.setRange(oldsize, newsize, font);
+ d->fontlist_.set(oldsize, font);
+ d->fontlist_.set(newsize - 1, font);
}
}
+void Paragraph::resetFonts(Font const & font)
+{
+ d->fontlist_.clear();
+ d->fontlist_.set(0, font);
+ d->fontlist_.set(d->text_.size() - 1, font);
+}
+
// Gets uninstantiated font setting at position.
Font const Paragraph::getFontSettings(BufferParams const & bparams,
pos_type pos) const
if (pos == size() && !empty())
return getFontSettings(bparams, pos - 1);
- return Font(Font::ALL_INHERIT, getParLanguage(bparams));
+ return Font(inherit_font, getParLanguage(bparams));
}
if (!empty() && !d->fontlist_.empty())
return d->fontlist_.begin()->font();
- return Font(Font::ALL_INHERIT, bparams.language);
+ return Font(inherit_font, bparams.language);
}
pos_type const body_pos = beginOfBody();
if (pos < body_pos)
- font.realize(d->layout_->labelfont);
+ font.fontInfo().realize(d->layout_->labelfont);
else
- font.realize(d->layout_->font);
+ font.fontInfo().realize(d->layout_->font);
- font.realize(outerfont);
- font.realize(bparams.getFont());
+ font.fontInfo().realize(outerfont.fontInfo());
+ font.fontInfo().realize(bparams.getFont().fontInfo());
return font;
}
Font const Paragraph::getLabelFont
(BufferParams const & bparams, Font const & outerfont) const
{
- Font tmpfont = layout()->labelfont;
- tmpfont.setLanguage(getParLanguage(bparams));
- tmpfont.realize(outerfont);
- tmpfont.realize(bparams.getFont());
- return tmpfont;
+ FontInfo tmpfont = layout()->labelfont;
+ tmpfont.realize(outerfont.fontInfo());
+ tmpfont.realize(bparams.getFont().fontInfo());
+ return Font(tmpfont, getParLanguage(bparams));
}
Font const Paragraph::getLayoutFont
(BufferParams const & bparams, Font const & outerfont) const
{
- Font tmpfont = layout()->font;
- tmpfont.setLanguage(getParLanguage(bparams));
- tmpfont.realize(outerfont);
- tmpfont.realize(bparams.getFont());
- return tmpfont;
+ FontInfo tmpfont = layout()->font;
+ tmpfont.realize(outerfont.fontInfo());
+ tmpfont.realize(bparams.getFont().fontInfo());
+ return Font(tmpfont, getParLanguage(bparams));
}
/// Returns the height of the highest font in range
-Font_size Paragraph::highestFontInRange
- (pos_type startpos, pos_type endpos, Font_size def_size) const
+FontSize Paragraph::highestFontInRange
+ (pos_type startpos, pos_type endpos, FontSize def_size) const
{
return d->fontlist_.highestInRange(startpos, endpos, def_size);
}
// style->pass_thru is false.
if (i != body_pos - 1) {
if (d->simpleTeXBlanks(
- *(runparams.encoding), os, texrow,
+ runparams, os, texrow,
i, column, font, *style)) {
// A surrogate pair was output. We
// must not call latexSpecialChar
bool emph_flag = false;
LayoutPtr const & style = layout();
- Font font_old =
+ FontInfo font_old =
style->labeltype == LABEL_MANUAL ? style->labelfont : style->font;
if (style->pass_thru && !d->onlyText(buf, outerfont, initial))
Font font = getFont(buf.params(), i, outerfont);
// handle <emphasis> tag
- if (font_old.emph() != font.emph()) {
- if (font.emph() == Font::ON) {
+ if (font_old.emph() != font.fontInfo().emph()) {
+ if (font.fontInfo().emph() == FONT_ON) {
os << "<emphasis>";
emph_flag = true;
} else if (i != initial) {
else
os << sgml::escapeChar(c);
}
- font_old = font;
+ font_old = font.fontInfo();
}
if (emph_flag) {
{
if (layout()->free_spacing)
return true;
-
- // for now we just need this, later should we need this in some
- // other way we can always add a function to Inset too.
- return ownerCode() == ERT_CODE || ownerCode() == LISTINGS_CODE;
+ return d->inset_owner_ && d->inset_owner_->isFreeSpacing();
}
{
if (layout()->keepempty)
return true;
- return ownerCode() == ERT_CODE || ownerCode() == LISTINGS_CODE;
+ return d->inset_owner_ && d->inset_owner_->allowEmpty();
}