X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2Finsetspecialchar.C;h=7ed1ea8489cbae9250b301601e10480647e119c3;hb=e28331ed63062dea10d0a21b9ec12034b4b17b9a;hp=e5f2536ca8865a61c7ee42fa912ffad55d716b77;hpb=cfead520932505dfe0582a034e1b4dbf0dc925e4;p=lyx.git diff --git a/src/insets/insetspecialchar.C b/src/insets/insetspecialchar.C index e5f2536ca8..7ed1ea8489 100644 --- a/src/insets/insetspecialchar.C +++ b/src/insets/insetspecialchar.C @@ -7,7 +7,7 @@ * \author Jean-Marc Lasgouttes * \author Lars Gullik Bjønnes * - * Full author contact details are available in file CREDITS + * Full author contact details are available in file CREDITS. */ #include @@ -15,16 +15,20 @@ #include "insetspecialchar.h" #include "debug.h" -#include "dimension.h" #include "LaTeXFeatures.h" -#include "BufferView.h" -#include "frontends/Painter.h" -#include "frontends/font_metrics.h" +#include "LColor.h" #include "lyxlex.h" -#include "lyxfont.h" +#include "metricsinfo.h" + +#include "frontends/FontMetrics.h" +#include "frontends/Painter.h" + +namespace lyx { + +using std::string; +using std::auto_ptr; using std::ostream; -using std::max; InsetSpecialChar::InsetSpecialChar(Kind k) @@ -38,11 +42,12 @@ InsetSpecialChar::Kind InsetSpecialChar::kind() const } -void InsetSpecialChar::dimension(BufferView *, LyXFont const & font, - Dimension & dim) const +bool InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const { - dim.a = font_metrics::maxAscent(font); - dim.d = font_metrics::maxDescent(font); + frontend::FontMetrics const & fm = + theFontMetrics(mi.base.font); + dim.asc = fm.maxAscent(); + dim.des = fm.maxDescent(); string s; switch (kind_) { @@ -52,62 +57,64 @@ void InsetSpecialChar::dimension(BufferView *, LyXFont const & font, case MENU_SEPARATOR: s = " x "; break; case HYPHENATION: s = "-"; break; } - dim.w = font_metrics::width(s, font); - if (kind_ == HYPHENATION && dim.w > 5) - dim.w -= 2; // to make it look shorter + docstring ds(s.begin(), s.end()); + dim.wid = fm.width(ds); + if (kind_ == HYPHENATION && dim.wid > 5) + dim.wid -= 2; // to make it look shorter + bool const changed = dim_ != dim; + dim_ = dim; + return changed; } -void InsetSpecialChar::draw(BufferView * bv, LyXFont const & f, - int baseline, float & x) const +void InsetSpecialChar::draw(PainterInfo & pi, int x, int y) const { - Painter & pain = bv->painter(); - LyXFont font(f); + LyXFont font = pi.base.font; switch (kind_) { case HYPHENATION: { font.setColor(LColor::special); - pain.text(int(x), baseline, '-', font); - x += width(bv, font); + pi.pain.text(x, y, char_type('-'), font); break; } case LIGATURE_BREAK: { font.setColor(LColor::special); - pain.text(int(x), baseline, '|', font); - x += width(bv, font); + pi.pain.text(x, y, char_type('|'), font); break; } case END_OF_SENTENCE: { font.setColor(LColor::special); - pain.text(int(x), baseline, '.', font); - x += width(bv, font); + pi.pain.text(x, y, char_type('.'), font); break; } case LDOTS: { font.setColor(LColor::special); - pain.text(int(x), baseline, ". . .", font); - x += width(bv, font); + string ell = ". . . "; + docstring dell(ell.begin(), ell.end()); + pi.pain.text(x, y, dell, font); break; } case MENU_SEPARATOR: { + frontend::FontMetrics const & fm = + theFontMetrics(font); + // A triangle the width and height of an 'x' - int w = font_metrics::width('x', font); - int ox = font_metrics::width(' ', font) + int(x); - int h = font_metrics::ascent('x', font); + int w = fm.width(char_type('x')); + int ox = fm.width(char_type(' ')) + x; + int h = fm.ascent(char_type('x')); int xp[4], yp[4]; - xp[0] = ox; yp[0] = baseline; - xp[1] = ox; yp[1] = baseline - h; - xp[2] = ox + w; yp[2] = baseline - h/2; - xp[3] = ox; yp[3] = baseline; + xp[0] = ox; yp[0] = y; + xp[1] = ox; yp[1] = y - h; + xp[2] = ox + w; yp[2] = y - h/2; + xp[3] = ox; yp[3] = y; - pain.lines(xp, yp, 4, LColor::special); - x += width(bv, font); + pi.pain.lines(xp, yp, 4, LColor::special); break; } } @@ -115,7 +122,7 @@ void InsetSpecialChar::draw(BufferView * bv, LyXFont const & f, // In lyxf3 this will be just LaTeX -void InsetSpecialChar::write(Buffer const *, ostream & os) const +void InsetSpecialChar::write(Buffer const &, ostream & os) const { string command; switch (kind_) { @@ -140,9 +147,9 @@ void InsetSpecialChar::write(Buffer const *, ostream & os) const // This function will not be necessary when lyx3 -void InsetSpecialChar::read(Buffer const *, LyXLex & lex) +void InsetSpecialChar::read(Buffer const &, LyXLex & lex) { - lex.nextToken(); + lex.next(); string const command = lex.getString(); if (command == "\\-") @@ -160,8 +167,8 @@ void InsetSpecialChar::read(Buffer const *, LyXLex & lex) } -int InsetSpecialChar::latex(Buffer const *, ostream & os, LatexRunParams const &, - bool /*fragile*/, bool free_space) const +int InsetSpecialChar::latex(Buffer const &, odocstream & os, + OutputParams const &) const { switch (kind_) { case HYPHENATION: @@ -184,7 +191,8 @@ int InsetSpecialChar::latex(Buffer const *, ostream & os, LatexRunParams const & } -int InsetSpecialChar::ascii(Buffer const *, ostream & os, int) const +int InsetSpecialChar::plaintext(Buffer const &, odocstream & os, + OutputParams const &) const { switch (kind_) { case HYPHENATION: @@ -204,7 +212,8 @@ int InsetSpecialChar::ascii(Buffer const *, ostream & os, int) const } -int InsetSpecialChar::linuxdoc(Buffer const *, ostream & os) const +int InsetSpecialChar::docbook(Buffer const &, odocstream & os, + OutputParams const &) const { switch (kind_) { case HYPHENATION: @@ -224,29 +233,16 @@ int InsetSpecialChar::linuxdoc(Buffer const *, ostream & os) const } -int InsetSpecialChar::docbook(Buffer const *, ostream & os, bool) const +int InsetSpecialChar::textString(Buffer const & buf, odocstream & os, + OutputParams const & op) const { - switch (kind_) { - case HYPHENATION: - case LIGATURE_BREAK: - break; - case END_OF_SENTENCE: - os << '.'; - break; - case LDOTS: - os << "..."; - break; - case MENU_SEPARATOR: - os << "&lyxarrow;"; - break; - } - return 0; + return plaintext(buf, os, op); } -Inset * InsetSpecialChar::clone(Buffer const &, bool) const +auto_ptr InsetSpecialChar::doClone() const { - return new InsetSpecialChar(kind_); + return auto_ptr(new InsetSpecialChar(kind_)); } @@ -270,12 +266,6 @@ bool InsetSpecialChar::isLetter() const } -bool InsetSpecialChar::isSpace() const -{ - return false; -} - - bool InsetSpecialChar::isLineSeparator() const { #if 0 @@ -288,3 +278,6 @@ bool InsetSpecialChar::isLineSeparator() const return false; #endif } + + +} // namespace lyx