X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmetricsinfo.C;h=9d6568640c1a1cea9dca85f3aa48e2a0a741b219;hb=9ee46b846e5e84ad40ceda4f4af94aeb86cd90a2;hp=34b504fd3d00f18ce3d7458b14bba62c058e661f;hpb=1829cdef6a34ec623c25ec8967dc048e8f19eee9;p=lyx.git diff --git a/src/metricsinfo.C b/src/metricsinfo.C index 34b504fd3d..9d6568640c 100644 --- a/src/metricsinfo.C +++ b/src/metricsinfo.C @@ -1,31 +1,56 @@ +/** + * \file metricsinfo.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author André Pönitz + * + * Full author contact details are available in file CREDITS. + */ #include +#include "BufferView.h" +#include "LColor.h" #include "metricsinfo.h" + #include "mathed/math_support.h" + #include "frontends/Painter.h" -#include "debug.h" +#include + +using std::string; MetricsBase::MetricsBase() - : font(), style(LM_ST_TEXT), fontname("mathnormal"), - restrictwidth(false), textwidth(0) + : bv(0), font(), style(LM_ST_TEXT), fontname("mathnormal"), + textwidth(0) {} +MetricsBase::MetricsBase(BufferView * b, LyXFont const & f, int w) + : bv(b), font(f), style(LM_ST_TEXT), fontname("mathnormal"), + textwidth(w) +{} + MetricsInfo::MetricsInfo() - : fullredraw(false) {} +MetricsInfo::MetricsInfo(BufferView * bv, LyXFont const & font, int textwidth) + : base(bv, font, textwidth) +{} -PainterInfo::PainterInfo(Painter & p) - : pain(p) -{} + +PainterInfo::PainterInfo(BufferView * bv, Painter & painter) + : pain(painter), ltr_pos(false), erased_(false) +{ + base.bv = bv; +} void PainterInfo::draw(int x, int y, char c) @@ -34,6 +59,12 @@ void PainterInfo::draw(int x, int y, char c) } +void PainterInfo::draw(int x, int y, std::string const & str) +{ + pain.text(x, y, str, base.font); +} + + Styles smallerScriptStyle(Styles st) { switch (st) { @@ -42,11 +73,9 @@ Styles smallerScriptStyle(Styles st) return LM_ST_SCRIPT; case LM_ST_SCRIPT: case LM_ST_SCRIPTSCRIPT: + default: // shut up compiler return LM_ST_SCRIPTSCRIPT; } - // shut up compiler - lyxerr << "should not happen\n"; - return LM_ST_DISPLAY; } ScriptChanger::ScriptChanger(MetricsBase & mb) @@ -64,13 +93,12 @@ Styles smallerFracStyle(Styles st) return LM_ST_SCRIPT; case LM_ST_SCRIPT: case LM_ST_SCRIPTSCRIPT: + default: // shut up compiler return LM_ST_SCRIPTSCRIPT; } - // shut up compiler - lyxerr << "should not happen\n"; - return LM_ST_DISPLAY; } + FracChanger::FracChanger(MetricsBase & mb) : StyleChanger(mb, smallerFracStyle(mb.style)) {} @@ -99,10 +127,11 @@ ShapeChanger::~ShapeChanger() StyleChanger::StyleChanger(MetricsBase & mb, Styles style) : Changer(mb) { - static const int diff[4][4] = { { 0, 0, -3, -5 }, - { 0, 0, -3, -5 }, - { 3, 3, 0, -2 }, - { 5, 5, 2, 0 } }; + static const int diff[4][4] = + { { 0, 0, -3, -5 }, + { 0, 0, -3, -5 }, + { 3, 3, 0, -2 }, + { 5, 5, 2, 0 } }; save_ = mb; int t = diff[mb.style][style]; if (t > 0) @@ -126,10 +155,14 @@ FontSetChanger::FontSetChanger(MetricsBase & mb, char const * name) : Changer(mb) { save_ = mb; + LyXFont::FONT_SIZE oldsize = save_.font.size(); mb.fontname = name; + mb.font = LyXFont(); augmentFont(mb.font, name); + mb.font.setSize(oldsize); } + FontSetChanger::~FontSetChanger() { orig_ = save_; @@ -140,8 +173,7 @@ WidthChanger::WidthChanger(MetricsBase & mb, int w) : Changer(mb) { save_ = mb; - mb.restrictwidth = true; - mb.textwidth = w; + mb.textwidth = w; } @@ -149,3 +181,19 @@ WidthChanger::~WidthChanger() { orig_ = save_; } + + + + +ColorChanger::ColorChanger(LyXFont & font, string const & color) + : Changer(font) +{ + save_ = lcolor.getFromLyXName(color); + font.setColor(lcolor.getFromLyXName(color)); +} + + +ColorChanger::~ColorChanger() +{ + orig_.setColor(lcolor.getFromLyXName(save_)); +}