X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetQuotes.cpp;h=98ed950521898f1e8b1f5df9f1de8b755759574c;hb=2c357c1d23b7b83839a9beb8225d4f1ae4f793b4;hp=e2cd014433129e052534883ece33a339a7c0fb49;hpb=237c132c1e6fc720b87f2fea6deb18a8395cbe0a;p=lyx.git diff --git a/src/insets/InsetQuotes.cpp b/src/insets/InsetQuotes.cpp index e2cd014433..98ed950521 100644 --- a/src/insets/InsetQuotes.cpp +++ b/src/insets/InsetQuotes.cpp @@ -14,7 +14,8 @@ #include "Buffer.h" #include "BufferParams.h" -#include "debug.h" +#include "BufferView.h" +#include "Dimension.h" #include "Language.h" #include "LaTeXFeatures.h" #include "Lexer.h" @@ -25,18 +26,16 @@ #include "frontends/FontMetrics.h" #include "frontends/Painter.h" +#include "support/debug.h" +#include "support/docstring.h" +#include "support/docstream.h" #include "support/lstrings.h" +using namespace std; +using namespace lyx::support; namespace lyx { -using support::prefixIs; - -using std::endl; -using std::string; -using std::ostream; - - namespace { /* codes used to read/write quotes to LyX files @@ -58,23 +57,27 @@ char const * const quote_char = ",'`<>"; // Index of chars used for the quote. Index is [side, language] int quote_index[2][6] = { { 2, 1, 0, 0, 3, 4 }, // "'',,<>" - { 1, 1, 2, 1, 4, 3 } }; // "`'`'><" + { 1, 1, 2, 1, 4, 3 } // "`'`'><" +}; // Corresponding LaTeX code, for double and single quotes. -char const * const latex_quote_t1[2][5] = -{ { "\\quotesinglbase ", "'", "`", +char const * const latex_quote_t1[2][5] = { + { "\\quotesinglbase ", "'", "`", "\\guilsinglleft{}", "\\guilsinglright{}" }, - { ",,", "''", "``", "<<", ">>" } }; + { ",,", "''", "``", "<<", ">>" } +}; -char const * const latex_quote_ot1[2][5] = -{ { "\\quotesinglbase ", "'", "`", +char const * const latex_quote_ot1[2][5] = { + { "\\quotesinglbase ", "'", "`", "\\guilsinglleft{}", "\\guilsinglright{}" }, { "\\quotedblbase ", "''", "``", - "\\guillemotleft{}", "\\guillemotright{}" } }; + "\\guillemotleft{}", "\\guillemotright{}" } +}; -char const * const latex_quote_babel[2][5] = -{ { "\\glq ", "'", "`", "\\flq{}", "\\frq{}" }, - { "\\glqq ", "''", "``", "\\flqq{}", "\\frqq{}" } }; +char const * const latex_quote_babel[2][5] = { + { "\\glq ", "'", "`", "\\flq{}", "\\frq{}" }, + { "\\glqq ", "''", "``", "\\flqq{}", "\\frqq{}" } +}; } // namespace anon @@ -105,11 +108,19 @@ InsetQuotes::InsetQuotes(char_type c, quote_language l, quote_times t) } +docstring InsetQuotes::name() const +{ + return from_ascii("Quotes"); +} + + void InsetQuotes::getPosition(char_type c) { // Decide whether left or right switch (c) { - case ' ': case '(': case '[': + case ' ': + case '(': + case '[': side_ = LeftQ; // left quote break; default: @@ -120,7 +131,7 @@ void InsetQuotes::getPosition(char_type c) void InsetQuotes::parseString(string const & s) { - string str(s); + string str = s; if (str.length() != 3) { lyxerr << "ERROR (InsetQuotes::InsetQuotes):" " bad string length." << endl; @@ -200,14 +211,14 @@ docstring const InsetQuotes::dispString(Language const * loclang) const retdisp = docstring(1, 0x2018); #endif else - retdisp = lyx::from_ascii(disp); + retdisp = from_ascii(disp); // in french, spaces are added inside double quotes if (times_ == DoubleQ && prefixIs(loclang->code(), "fr")) { if (side_ == LeftQ) retdisp += ' '; else - retdisp.insert(docstring::size_type(0), 1, ' '); + retdisp.insert(size_t(0), 1, ' '); } return retdisp; @@ -216,14 +227,16 @@ docstring const InsetQuotes::dispString(Language const * loclang) const void InsetQuotes::metrics(MetricsInfo & mi, Dimension & dim) const { - Font & font = mi.base.font; + FontInfo & font = mi.base.font; frontend::FontMetrics const & fm = theFontMetrics(font); dim.asc = fm.maxAscent(); dim.des = fm.maxDescent(); dim.wid = 0; - docstring const text = dispString(font.language()); + // FIXME: should we add a language or a font parameter member? + docstring const text = dispString( + mi.base.bv->buffer().params().language); for (string::size_type i = 0; i < text.length(); ++i) { if (text[i] == ' ') dim.wid += fm.width('i'); @@ -235,22 +248,11 @@ void InsetQuotes::metrics(MetricsInfo & mi, Dimension & dim) const } -#if 0 -Font const InsetQuotes::convertFont(Font const & f) const -{ -#if 1 - return f; -#else - Font font(f); - return font; -#endif -} -#endif - - void InsetQuotes::draw(PainterInfo & pi, int x, int y) const { - docstring const text = dispString(pi.base.font.language()); + // FIXME: should we add a language or a font parameter member? + docstring const text = dispString( + pi.base.bv->buffer().params().language); if (text.length() == 2 && text[0] == text[1]) { pi.pain.text(x, y, text[0], pi.base.font); @@ -363,7 +365,7 @@ void InsetQuotes::validate(LaTeXFeatures & features) const && lyxrc.fontenc != "T1") { if (times_ == SingleQ) switch (type) { - case ',': features.require("quotesinglbase"); break; + case ',': features.require("quotesinglbase"); break; case '<': features.require("guilsinglleft"); break; case '>': features.require("guilsinglright"); break; default: break; @@ -385,10 +387,4 @@ Inset * InsetQuotes::clone() const } -Inset::Code InsetQuotes::lyxCode() const -{ - return Inset::QUOTE_CODE; -} - - } // namespace lyx