From 493ec52c3f1b4a3897cac52ca70a4e2c42717236 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Mon, 4 Dec 2006 10:45:43 +0000 Subject: [PATCH] * Dimension is a simple wrapper class again. * other files: use FontMetrics::dimension() method instead of old Dimension interface. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16167 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/dimension.C | 20 -------------------- src/dimension.h | 11 ----------- src/frontends/qt4/GuiFontMetrics.C | 4 ++-- src/mathed/InsetMathBrace.C | 8 +++++--- src/mathed/InsetMathChar.C | 10 +++++----- src/mathed/InsetMathDelim.C | 4 ++-- src/mathed/InsetMathDots.C | 3 ++- src/mathed/MathData.C | 3 ++- 8 files changed, 18 insertions(+), 45 deletions(-) diff --git a/src/dimension.C b/src/dimension.C index 847fdd71f5..c9a51d37e4 100644 --- a/src/dimension.C +++ b/src/dimension.C @@ -11,8 +11,6 @@ #include #include "dimension.h" -#include "frontends/FontMetrics.h" - namespace lyx { @@ -26,22 +24,4 @@ void Dimension::operator+=(Dimension const & dim) wid += dim.wid; } - -void Dimension::clear(LyXFont const & font) -{ - frontend::FontMetrics const & fm = theFontMetrics(font); - asc = fm.maxAscent(); - des = fm.maxDescent(); - wid = 0; -} - - -void Dimension::set(LyXFont const & font, char_type c) -{ - frontend::FontMetrics const & fm = theFontMetrics(font); - des = fm.descent(c); - asc = fm.ascent(c); - wid = fm.width(c); -} - } // namespace lyx diff --git a/src/dimension.h b/src/dimension.h index 26bd71064b..5dd32d3beb 100644 --- a/src/dimension.h +++ b/src/dimension.h @@ -12,12 +12,8 @@ #ifndef DIMENSION_H #define DIMENSION_H -#include "support/types.h" - namespace lyx { -class LyXFont; - /// Simple wrapper around three ints class Dimension { public: @@ -26,8 +22,6 @@ public: /// initialize data Dimension(int w, int a, int d) : wid(w), asc(a), des(d) {} - Dimension(LyXFont const & font, char_type c) { set(font, c); } - Dimension & operator=(Dimension const & dim) { wid = dim.wid; asc = dim.asc; @@ -38,11 +32,6 @@ public: void operator+=(Dimension const & dim); /// set to empty box void clear() { wid = asc = des = 0; } - /// set to empty box suitble for given font. - void clear(LyXFont const & font); - /// set to a char dimensions for a given font. - void set(LyXFont const & font, char_type c); - /// get height int height() const { return asc + des; } /// get ascent diff --git a/src/frontends/qt4/GuiFontMetrics.C b/src/frontends/qt4/GuiFontMetrics.C index 0b0dbaf085..744ccca803 100644 --- a/src/frontends/qt4/GuiFontMetrics.C +++ b/src/frontends/qt4/GuiFontMetrics.C @@ -159,13 +159,13 @@ void GuiFontMetrics::buttonText(docstring const & str, Dimension const GuiFontMetrics::defaultDimension() const { - return Dimension(maxAscent(), maxDescent(), 0); + return Dimension(0, maxAscent(), maxDescent()); } Dimension const GuiFontMetrics::dimension(char_type c) const { - return Dimension(ascent(c), descent(c), width(c)); + return Dimension(width(c), ascent(c), descent(c)); } diff --git a/src/mathed/InsetMathBrace.C b/src/mathed/InsetMathBrace.C index acae12e684..18ce779746 100644 --- a/src/mathed/InsetMathBrace.C +++ b/src/mathed/InsetMathBrace.C @@ -15,9 +15,11 @@ #include "MathStream.h" #include "MathSupport.h" #include "LColor.h" -#include "support/std_ostream.h" + +#include "frontends/FontMetrics.h" #include "frontends/Painter.h" +#include "support/std_ostream.h" namespace lyx { @@ -46,7 +48,7 @@ auto_ptr InsetMathBrace::doClone() const bool InsetMathBrace::metrics(MetricsInfo & mi, Dimension & dim) const { cell(0).metrics(mi); - Dimension t(mi.base.font, '{'); + Dimension t = theFontMetrics(mi.base.font).dimension('{'); dim.asc = max(cell(0).ascent(), t.asc); dim.des = max(cell(0).descent(), t.des); dim.wid = cell(0).width() + 2 * t.wid; @@ -62,7 +64,7 @@ void InsetMathBrace::draw(PainterInfo & pi, int x, int y) const { LyXFont font = pi.base.font; font.setColor(LColor::latex); - Dimension t(font, '{'); + Dimension t = theFontMetrics(font).dimension('{'); pi.pain.text(x, y, '{', font); cell(0).draw(pi, x + t.wid, y); pi.pain.text(x + t.wid + cell(0).width(), y, '}', font); diff --git a/src/mathed/InsetMathChar.C b/src/mathed/InsetMathChar.C index 004fb2283d..3557d2efc4 100644 --- a/src/mathed/InsetMathChar.C +++ b/src/mathed/InsetMathChar.C @@ -62,15 +62,15 @@ bool InsetMathChar::metrics(MetricsInfo & mi, Dimension & dim) const #if 1 if (char_ == '=' && has_math_fonts) { FontSetChanger dummy(mi.base, "cmr"); - dim.set(mi.base.font, char_); + dim = theFontMetrics(mi.base.font).dimension(char_); } else if ((char_ == '>' || char_ == '<') && has_math_fonts) { FontSetChanger dummy(mi.base, "cmm"); - dim.set(mi.base.font, char_); + dim = theFontMetrics(mi.base.font).dimension(char_); } else if (!slanted(char_) && mi.base.fontname == "mathnormal") { ShapeChanger dummy(mi.base.font, LyXFont::UP_SHAPE); - dim.set(mi.base.font, char_); + dim = theFontMetrics(mi.base.font).dimension(char_); } else { - dim.set(mi.base.font, char_); + dim = theFontMetrics(mi.base.font).dimension(char_); } int const em = mathed_char_width(mi.base.font, 'M'); if (isBinaryOp(char_)) @@ -79,7 +79,7 @@ bool InsetMathChar::metrics(MetricsInfo & mi, Dimension & dim) const dim.wid += static_cast(0.1667*em+0.5); #else whichFont(font_, code_, mi); - dim.set(font_, char_); + dim = theFontMetrics(font_).dimension(char_); if (isBinaryOp(char_, code_)) width_ += 2 * theFontMetrics(font_).width(' '); lyxerr << "InsetMathChar::metrics: " << dim << endl; diff --git a/src/mathed/InsetMathDelim.C b/src/mathed/InsetMathDelim.C index 2805ac9863..fd660f025c 100644 --- a/src/mathed/InsetMathDelim.C +++ b/src/mathed/InsetMathDelim.C @@ -17,6 +17,7 @@ #include "MathStream.h" #include "MathSupport.h" +#include "frontends/FontMetrics.h" namespace lyx { @@ -74,8 +75,7 @@ void InsetMathDelim::normalize(NormalStream & os) const bool InsetMathDelim::metrics(MetricsInfo & mi, Dimension & dim) const { cell(0).metrics(mi); - Dimension t; - t.set(mi.base.font, 'I'); + Dimension t = theFontMetrics(mi.base.font).dimension('I'); int h0 = (t.asc + t.des) / 2; int a0 = max(cell(0).ascent(), t.asc) - h0; int d0 = max(cell(0).descent(), t.des) + h0; diff --git a/src/mathed/InsetMathDots.C b/src/mathed/InsetMathDots.C index 3f87f29f53..e45748486e 100644 --- a/src/mathed/InsetMathDots.C +++ b/src/mathed/InsetMathDots.C @@ -16,6 +16,7 @@ #include "MathSupport.h" #include "MathParser.h" +#include "frontends/FontMetrics.h" namespace lyx { @@ -37,7 +38,7 @@ auto_ptr InsetMathDots::doClone() const bool InsetMathDots::metrics(MetricsInfo & mi, Dimension & dim) const { - dim.set(mi.base.font, 'M'); + dim = theFontMetrics(mi.base.font).dimension('M'); dh_ = 0; if (key_->name == "cdots" || key_->name == "dotsb" || key_->name == "dotsm" || key_->name == "dotsi") diff --git a/src/mathed/MathData.C b/src/mathed/MathData.C index 06dd9db4d1..afc5457bbe 100644 --- a/src/mathed/MathData.C +++ b/src/mathed/MathData.C @@ -25,6 +25,7 @@ #include "debug.h" #include "LColor.h" +#include "frontends/FontMetrics.h" #include "frontends/Painter.h" #include @@ -241,7 +242,7 @@ bool isInside(DocIterator const & it, MathArray const & ar, void MathArray::metrics(MetricsInfo & mi) const { - dim_.set(mi.base.font, 'I'); + dim_ = theFontMetrics(mi.base.font).dimension('I'); if (empty()) return; -- 2.39.2