mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-10 18:58:10 +00:00
* 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
This commit is contained in:
parent
b056d35db4
commit
493ec52c3f
@ -11,8 +11,6 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include "dimension.h"
|
#include "dimension.h"
|
||||||
#include "frontends/FontMetrics.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
@ -26,22 +24,4 @@ void Dimension::operator+=(Dimension const & dim)
|
|||||||
wid += dim.wid;
|
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
|
} // namespace lyx
|
||||||
|
@ -12,12 +12,8 @@
|
|||||||
#ifndef DIMENSION_H
|
#ifndef DIMENSION_H
|
||||||
#define DIMENSION_H
|
#define DIMENSION_H
|
||||||
|
|
||||||
#include "support/types.h"
|
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
class LyXFont;
|
|
||||||
|
|
||||||
/// Simple wrapper around three ints
|
/// Simple wrapper around three ints
|
||||||
class Dimension {
|
class Dimension {
|
||||||
public:
|
public:
|
||||||
@ -26,8 +22,6 @@ public:
|
|||||||
/// initialize data
|
/// initialize data
|
||||||
Dimension(int w, int a, int d) : wid(w), asc(a), des(d) {}
|
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) {
|
Dimension & operator=(Dimension const & dim) {
|
||||||
wid = dim.wid;
|
wid = dim.wid;
|
||||||
asc = dim.asc;
|
asc = dim.asc;
|
||||||
@ -38,11 +32,6 @@ public:
|
|||||||
void operator+=(Dimension const & dim);
|
void operator+=(Dimension const & dim);
|
||||||
/// set to empty box
|
/// set to empty box
|
||||||
void clear() { wid = asc = des = 0; }
|
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
|
/// get height
|
||||||
int height() const { return asc + des; }
|
int height() const { return asc + des; }
|
||||||
/// get ascent
|
/// get ascent
|
||||||
|
@ -159,13 +159,13 @@ void GuiFontMetrics::buttonText(docstring const & str,
|
|||||||
|
|
||||||
Dimension const GuiFontMetrics::defaultDimension() const
|
Dimension const GuiFontMetrics::defaultDimension() const
|
||||||
{
|
{
|
||||||
return Dimension(maxAscent(), maxDescent(), 0);
|
return Dimension(0, maxAscent(), maxDescent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Dimension const GuiFontMetrics::dimension(char_type c) const
|
Dimension const GuiFontMetrics::dimension(char_type c) const
|
||||||
{
|
{
|
||||||
return Dimension(ascent(c), descent(c), width(c));
|
return Dimension(width(c), ascent(c), descent(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,9 +15,11 @@
|
|||||||
#include "MathStream.h"
|
#include "MathStream.h"
|
||||||
#include "MathSupport.h"
|
#include "MathSupport.h"
|
||||||
#include "LColor.h"
|
#include "LColor.h"
|
||||||
#include "support/std_ostream.h"
|
|
||||||
|
#include "frontends/FontMetrics.h"
|
||||||
#include "frontends/Painter.h"
|
#include "frontends/Painter.h"
|
||||||
|
|
||||||
|
#include "support/std_ostream.h"
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
@ -46,7 +48,7 @@ auto_ptr<InsetBase> InsetMathBrace::doClone() const
|
|||||||
bool InsetMathBrace::metrics(MetricsInfo & mi, Dimension & dim) const
|
bool InsetMathBrace::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||||
{
|
{
|
||||||
cell(0).metrics(mi);
|
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.asc = max(cell(0).ascent(), t.asc);
|
||||||
dim.des = max(cell(0).descent(), t.des);
|
dim.des = max(cell(0).descent(), t.des);
|
||||||
dim.wid = cell(0).width() + 2 * t.wid;
|
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;
|
LyXFont font = pi.base.font;
|
||||||
font.setColor(LColor::latex);
|
font.setColor(LColor::latex);
|
||||||
Dimension t(font, '{');
|
Dimension t = theFontMetrics(font).dimension('{');
|
||||||
pi.pain.text(x, y, '{', font);
|
pi.pain.text(x, y, '{', font);
|
||||||
cell(0).draw(pi, x + t.wid, y);
|
cell(0).draw(pi, x + t.wid, y);
|
||||||
pi.pain.text(x + t.wid + cell(0).width(), y, '}', font);
|
pi.pain.text(x + t.wid + cell(0).width(), y, '}', font);
|
||||||
|
@ -62,15 +62,15 @@ bool InsetMathChar::metrics(MetricsInfo & mi, Dimension & dim) const
|
|||||||
#if 1
|
#if 1
|
||||||
if (char_ == '=' && has_math_fonts) {
|
if (char_ == '=' && has_math_fonts) {
|
||||||
FontSetChanger dummy(mi.base, "cmr");
|
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) {
|
} else if ((char_ == '>' || char_ == '<') && has_math_fonts) {
|
||||||
FontSetChanger dummy(mi.base, "cmm");
|
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") {
|
} else if (!slanted(char_) && mi.base.fontname == "mathnormal") {
|
||||||
ShapeChanger dummy(mi.base.font, LyXFont::UP_SHAPE);
|
ShapeChanger dummy(mi.base.font, LyXFont::UP_SHAPE);
|
||||||
dim.set(mi.base.font, char_);
|
dim = theFontMetrics(mi.base.font).dimension(char_);
|
||||||
} else {
|
} else {
|
||||||
dim.set(mi.base.font, char_);
|
dim = theFontMetrics(mi.base.font).dimension(char_);
|
||||||
}
|
}
|
||||||
int const em = mathed_char_width(mi.base.font, 'M');
|
int const em = mathed_char_width(mi.base.font, 'M');
|
||||||
if (isBinaryOp(char_))
|
if (isBinaryOp(char_))
|
||||||
@ -79,7 +79,7 @@ bool InsetMathChar::metrics(MetricsInfo & mi, Dimension & dim) const
|
|||||||
dim.wid += static_cast<int>(0.1667*em+0.5);
|
dim.wid += static_cast<int>(0.1667*em+0.5);
|
||||||
#else
|
#else
|
||||||
whichFont(font_, code_, mi);
|
whichFont(font_, code_, mi);
|
||||||
dim.set(font_, char_);
|
dim = theFontMetrics(font_).dimension(char_);
|
||||||
if (isBinaryOp(char_, code_))
|
if (isBinaryOp(char_, code_))
|
||||||
width_ += 2 * theFontMetrics(font_).width(' ');
|
width_ += 2 * theFontMetrics(font_).width(' ');
|
||||||
lyxerr << "InsetMathChar::metrics: " << dim << endl;
|
lyxerr << "InsetMathChar::metrics: " << dim << endl;
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "MathStream.h"
|
#include "MathStream.h"
|
||||||
#include "MathSupport.h"
|
#include "MathSupport.h"
|
||||||
|
|
||||||
|
#include "frontends/FontMetrics.h"
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
@ -74,8 +75,7 @@ void InsetMathDelim::normalize(NormalStream & os) const
|
|||||||
bool InsetMathDelim::metrics(MetricsInfo & mi, Dimension & dim) const
|
bool InsetMathDelim::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||||
{
|
{
|
||||||
cell(0).metrics(mi);
|
cell(0).metrics(mi);
|
||||||
Dimension t;
|
Dimension t = theFontMetrics(mi.base.font).dimension('I');
|
||||||
t.set(mi.base.font, 'I');
|
|
||||||
int h0 = (t.asc + t.des) / 2;
|
int h0 = (t.asc + t.des) / 2;
|
||||||
int a0 = max(cell(0).ascent(), t.asc) - h0;
|
int a0 = max(cell(0).ascent(), t.asc) - h0;
|
||||||
int d0 = max(cell(0).descent(), t.des) + h0;
|
int d0 = max(cell(0).descent(), t.des) + h0;
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "MathSupport.h"
|
#include "MathSupport.h"
|
||||||
#include "MathParser.h"
|
#include "MathParser.h"
|
||||||
|
|
||||||
|
#include "frontends/FontMetrics.h"
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ auto_ptr<InsetBase> InsetMathDots::doClone() const
|
|||||||
|
|
||||||
bool InsetMathDots::metrics(MetricsInfo & mi, Dimension & dim) const
|
bool InsetMathDots::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||||
{
|
{
|
||||||
dim.set(mi.base.font, 'M');
|
dim = theFontMetrics(mi.base.font).dimension('M');
|
||||||
dh_ = 0;
|
dh_ = 0;
|
||||||
if (key_->name == "cdots" || key_->name == "dotsb"
|
if (key_->name == "cdots" || key_->name == "dotsb"
|
||||||
|| key_->name == "dotsm" || key_->name == "dotsi")
|
|| key_->name == "dotsm" || key_->name == "dotsi")
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "LColor.h"
|
#include "LColor.h"
|
||||||
|
|
||||||
|
#include "frontends/FontMetrics.h"
|
||||||
#include "frontends/Painter.h"
|
#include "frontends/Painter.h"
|
||||||
|
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
@ -241,7 +242,7 @@ bool isInside(DocIterator const & it, MathArray const & ar,
|
|||||||
|
|
||||||
void MathArray::metrics(MetricsInfo & mi) const
|
void MathArray::metrics(MetricsInfo & mi) const
|
||||||
{
|
{
|
||||||
dim_.set(mi.base.font, 'I');
|
dim_ = theFontMetrics(mi.base.font).dimension('I');
|
||||||
|
|
||||||
if (empty())
|
if (empty())
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user