the ascent/descent/width -> dimensions() change

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6979 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-05-19 17:03:12 +00:00
parent 61861c8c89
commit 723ee136ba
56 changed files with 340 additions and 610 deletions

View File

@ -12,7 +12,6 @@
#include "BufferView.h" #include "BufferView.h"
#include "BufferView_pimpl.h" #include "BufferView_pimpl.h"
#include "BufferView_pimpl.h"
#include "LaTeX.h" #include "LaTeX.h"
#include "ParagraphParameters.h" #include "ParagraphParameters.h"
#include "WordLangTuple.h" #include "WordLangTuple.h"

View File

@ -1,4 +1,17 @@
2003-05-19 André Pönitz <poenitz@gmx.net>
* dimension.[Ch]: promote from mathed/dimension.[Ch]
* Makefile.am:
* BufferView.C:
* DepTable.h:
* LaTeXFeatures.C:
* buffer.C:
* lyxfont.C:
* lyxlex.h:
* paragraph_funcs.C: dimensions() instead of ascend/descend/width
2003-05-19 André Pönitz <poenitz@gmx.net> 2003-05-19 André Pönitz <poenitz@gmx.net>
* buffer.C: * buffer.C:

View File

@ -25,8 +25,7 @@ public:
/** This one is a little bit harder since we need the absolute /** This one is a little bit harder since we need the absolute
filename. Should we insert files with .sty .cls etc as filename. Should we insert files with .sty .cls etc as
extension? */ extension? */
void insert(string const & f, void insert(string const & f, bool upd = false);
bool upd = false);
/// ///
void update(); void update();

View File

@ -176,12 +176,12 @@ int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *);
} }
string const LaTeXFeatures::getPackages() const string const LaTeXFeatures::getPackages() const
{ {
ostringstream packages; ostringstream packages;
LyXTextClass const & tclass = params.getLyXTextClass(); LyXTextClass const & tclass = params.getLyXTextClass();
// //
// These are all the 'simple' includes. i.e // These are all the 'simple' includes. i.e
// packages which we just \usepackage{package} // packages which we just \usepackage{package}

View File

@ -121,6 +121,8 @@ lyx_SOURCES = \
counters.h \ counters.h \
debug.C \ debug.C \
debug.h \ debug.h \
dimension.C \
dimension.h \
encoding.C \ encoding.C \
encoding.h \ encoding.h \
exporter.C \ exporter.C \

View File

@ -161,10 +161,7 @@ Buffer::~Buffer()
string const Buffer::getLatexName(bool no_path) const string const Buffer::getLatexName(bool no_path) const
{ {
string const name = ChangeExtension(MakeLatexName(fileName()), ".tex"); string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
if (no_path) return no_path ? OnlyFilename(name) : name;
return OnlyFilename(name);
else
return name;
} }

View File

@ -10,10 +10,9 @@
#include <config.h> #include <config.h>
#include "dimension.h"
#include "math_support.h"
#include <iostream> #include "dimension.h"
#include "frontends/font_metrics.h"
void Dimension::operator+=(Dimension const & dim) void Dimension::operator+=(Dimension const & dim)
@ -26,15 +25,9 @@ void Dimension::operator+=(Dimension const & dim)
} }
std::ostream & operator<<(std::ostream & os, Dimension const & dim)
{
os << " (" << dim.w << 'x' << dim.a << '-' << dim.d << ") ";
return os;
}
void Dimension::clear(LyXFont const & font) void Dimension::clear(LyXFont const & font)
{ {
math_font_max_dim(font, a, d); a = font_metrics::maxAscent(font);
d = font_metrics::maxDescent(font);
w = 0; w = 0;
} }

View File

@ -15,12 +15,10 @@
#define DIMENSION_H #define DIMENSION_H
#include <iosfwd>
class LyXFont; class LyXFont;
/// Simple wrapper around three ints /// Simple wrapper around three ints
class Dimension { struct Dimension {
public: public:
/// constructor /// constructor
Dimension() : w(0), a(0), d(0) {} Dimension() : w(0), a(0), d(0) {}
@ -43,6 +41,15 @@ public:
int width() const { return w; } int width() const { return w; }
public: public:
/// these are intentionally public as things like
///
/// dim.a += 20;
///
/// are used all over the place and "hiding" those behind
///
/// dim.ascent(dim.ascent() + 20);
///
/// makes the code neither faster nor clearer
/// width /// width
int w; int w;
/// ascent /// ascent
@ -51,6 +58,4 @@ public:
int d; int d;
}; };
std::ostream & operator<<(std::ostream & os, Dimension const & dim);
#endif #endif

View File

@ -62,7 +62,6 @@ void ControlDocument::apply()
if (!bufferIsAvailable()) if (!bufferIsAvailable())
return; return;
classApply(); classApply();
view().apply(); view().apply();

View File

@ -10,7 +10,6 @@
#include <config.h> #include <config.h>
#include <qmessagebox.h> #include <qmessagebox.h>
#include <qlabel.h> #include <qlabel.h>
#include <qlineedit.h> #include <qlineedit.h>

View File

@ -10,7 +10,6 @@
#include <config.h> #include <config.h>
#include "xformsImage.h" #include "xformsImage.h"
#include "graphics/GraphicsParams.h" #include "graphics/GraphicsParams.h"
#include "Color.h" #include "Color.h"

View File

@ -21,6 +21,7 @@
#include "support/LAssert.h" #include "support/LAssert.h"
#include "support/FileInfo.h" #include "support/FileInfo.h"
#include "support/filetools.h" #include "support/filetools.h"
#include "support/tostr.h"
#include "support/lstrings.h" // frontStrip, strip #include "support/lstrings.h" // frontStrip, strip
#include "lyx_forms.h" #include "lyx_forms.h"
@ -196,9 +197,7 @@ void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice,
fl_set_input(input, ""); fl_set_input(input, "");
fl_set_choice_text(choice, default_unit.c_str()); fl_set_choice_text(choice, default_unit.c_str());
} else { } else {
ostringstream buffer; fl_set_input(input, tostr(len.value()).c_str());
buffer << len.value();
fl_set_input(input, buffer.str().c_str());
// Set the choice to the desired unit, if present in the choice. // Set the choice to the desired unit, if present in the choice.
// Else set the choice to the default unit. // Else set the choice to the default unit.
@ -220,7 +219,8 @@ void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice,
string formatted(string const & sin, int w, int size, int style) string formatted(string const & sin, int w, int size, int style)
{ {
string sout; string sout;
if (sin.empty()) return sout; if (sin.empty())
return sout;
string::size_type curpos = 0; string::size_type curpos = 0;
string line; string line;

View File

@ -1,4 +1,22 @@
2003-05-19 André Pönitz <poenitz@gmx.net>
* inset.[Ch]:
* insetbutton.[Ch]:
* insetcollapsable.[Ch]:
* inseterror.[Ch]:
* insetert.[Ch]:
* insetfoot.[Ch]:
* insetgraphics.[Ch]:
* insetgraphicsParams.[Ch]:
* insetlatexaccent.[Ch]:
* insetminipage.[Ch]:
* insetnewline.[Ch]:
* insetquotes.[Ch]:
* insetspecialchar.[Ch]:
* insettabular.[Ch]:
* insettext.[Ch]: dimensions() instead of ascend/descend/width
2003-05-19 André Pönitz <poenitz@gmx.net> 2003-05-19 André Pönitz <poenitz@gmx.net>
* insetenv.[Ch]: * insetenv.[Ch]:

View File

@ -13,14 +13,13 @@
#include <config.h> #include <config.h>
#include "inset.h" #include "inset.h"
#include "BufferView.h" #include "BufferView.h"
#include "funcrequest.h" #include "funcrequest.h"
#include "gettext.h" #include "gettext.h"
#include "lyxfont.h" #include "lyxfont.h"
#include "lyxtext.h" #include "lyxtext.h"
#include "dimension.h"
#include "frontends/Painter.h" #include "frontends/Painter.h"
#include "frontends/mouse_state.h" #include "frontends/mouse_state.h"
@ -148,3 +147,27 @@ int Inset::latexTextWidth(BufferView * bv) const
return bv->workWidth(); return bv->workWidth();
} }
int Inset::ascent(BufferView * bv, LyXFont const & font) const
{
Dimension dim;
dimension(bv, font, dim);
return dim.ascent();
}
int Inset::descent(BufferView * bv, LyXFont const & font) const
{
Dimension dim;
dimension(bv, font, dim);
return dim.descent();
}
int Inset::width(BufferView * bv, LyXFont const & font) const
{
Dimension dim;
dimension(bv, font, dim);
return dim.width();
}

View File

@ -18,12 +18,12 @@
#include "LString.h" #include "LString.h"
#include "LColor.h" #include "LColor.h"
#include "insetbase.h" #include "insetbase.h"
#include "frontends/mouse_state.h"
#include "support/types.h" #include "support/types.h"
#include <vector> #include <vector>
class LyXFont; class LyXFont;
class Dimension;
class Buffer; class Buffer;
class Painter; class Painter;
class LyXText; class LyXText;
@ -157,11 +157,13 @@ public:
/// ///
Inset(Inset const & in, bool same_id = false); Inset(Inset const & in, bool same_id = false);
/// ///
virtual int ascent(BufferView *, LyXFont const &) const = 0; virtual void dimension(BufferView *, LyXFont const &, Dimension &) const = 0;
/// ///
virtual int descent(BufferView *, LyXFont const &) const = 0; int ascent(BufferView *, LyXFont const &) const;
/// ///
virtual int width(BufferView *, LyXFont const &) const = 0; int descent(BufferView *, LyXFont const &) const;
///
int width(BufferView *, LyXFont const &) const;
/// ///
virtual void draw(BufferView *, LyXFont const &, int baseline, float & x) const = 0; virtual void draw(BufferView *, LyXFont const &, int baseline, float & x) const = 0;
/// update the inset representation /// update the inset representation

View File

@ -1,4 +1,3 @@
#include "insetbase.h" #include "insetbase.h"

View File

@ -12,9 +12,9 @@
#include <config.h> #include <config.h>
#include "insetbutton.h" #include "insetbutton.h"
#include "debug.h" #include "debug.h"
#include "dimension.h"
#include "BufferView.h" #include "BufferView.h"
#include "funcrequest.h" #include "funcrequest.h"
#include "frontends/LyXView.h" #include "frontends/LyXView.h"
@ -27,69 +27,22 @@ using std::ostream;
using std::endl; using std::endl;
int InsetButton::ascent(BufferView * bv, LyXFont const &) const void InsetButton::dimension(BufferView * bv, LyXFont const &,
Dimension & dim) const
{ {
lyx::Assert(bv); lyx::Assert(bv);
LyXFont font(LyXFont::ALL_SANE); LyXFont font(LyXFont::ALL_SANE);
font.decSize(); font.decSize();
int width;
int ascent;
int descent;
string const s = getScreenLabel(bv->buffer()); string const s = getScreenLabel(bv->buffer());
if (editable()) { if (editable())
font_metrics::buttonText(s, font, width, ascent, descent); font_metrics::buttonText(s, font, dim.w, dim.a, dim.d);
} else { else
font_metrics::rectText(s, font, width, ascent, descent); font_metrics::rectText(s, font, dim.w, dim.a, dim.d);
}
dim.w += 4;
return ascent;
}
int InsetButton::descent(BufferView * bv, LyXFont const &) const
{
lyx::Assert(bv);
LyXFont font(LyXFont::ALL_SANE);
font.decSize();
int width;
int ascent;
int descent;
string const s = getScreenLabel(bv->buffer());
if (editable()) {
font_metrics::buttonText(s, font, width, ascent, descent);
} else {
font_metrics::rectText(s, font, width, ascent, descent);
}
return descent;
}
int InsetButton::width(BufferView * bv, LyXFont const &) const
{
lyx::Assert(bv);
LyXFont font(LyXFont::ALL_SANE);
font.decSize();
int width;
int ascent;
int descent;
string const s = getScreenLabel(bv->buffer());
if (editable()) {
font_metrics::buttonText(s, font, width, ascent, descent);
} else {
font_metrics::rectText(s, font, width, ascent, descent);
}
return width + 4;
} }

View File

@ -24,11 +24,7 @@
class InsetButton: public Inset { class InsetButton: public Inset {
public: public:
/// ///
int ascent(BufferView *, LyXFont const &) const; void dimension(BufferView *, LyXFont const &, Dimension &) const;
///
int descent(BufferView *, LyXFont const &) const;
///
int width(BufferView *, LyXFont const &) const;
/// ///
void draw(BufferView *, LyXFont const &, int, float &) const; void draw(BufferView *, LyXFont const &, int, float &) const;
/// ///

View File

@ -26,33 +26,23 @@ public:
/// ///
void read(Buffer const * buf, LyXLex & lex); void read(Buffer const * buf, LyXLex & lex);
/// ///
virtual virtual bool display() const;
bool display() const;
/// ///
virtual virtual bool needFullRow() const;
bool needFullRow() const;
/// ///
virtual virtual Inset::Code lyxCode() const;
Inset::Code lyxCode() const;
/// ///
virtual virtual string const editMessage() const;
string const editMessage() const;
/// ///
virtual virtual void draw(BufferView * bv, LyXFont const & f,
void draw(BufferView * bv, LyXFont const & f,
int baseline, float & x) const; int baseline, float & x) const;
/// ///
virtual virtual int latex(Buffer const * buf, std::ostream & os,
int latex(Buffer const * buf, std::ostream & os,
bool fragile, bool free_spc) const; bool fragile, bool free_spc) const;
/// ///
virtual
int ascii(Buffer const * buf, std::ostream & os, int linelen) const; int ascii(Buffer const * buf, std::ostream & os, int linelen) const;
/// ///
virtual
int docbook(Buffer const * buf, std::ostream & os, bool mixcont) const; int docbook(Buffer const * buf, std::ostream & os, bool mixcont) const;
protected:
private:
}; };
@ -75,4 +65,5 @@ Inset::Code InsetCaption::lyxCode() const
{ {
return CAPTION_CODE; return CAPTION_CODE;
} }
#endif #endif

View File

@ -17,6 +17,7 @@
#include "BufferView.h" #include "BufferView.h"
#include "debug.h" #include "debug.h"
#include "dimension.h"
#include "gettext.h" #include "gettext.h"
#include "lyxfont.h" #include "lyxfont.h"
#include "lyxlex.h" #include "lyxlex.h"
@ -88,7 +89,6 @@ void InsetCollapsable::write(Buffer const * buf, ostream & os) const
} }
void InsetCollapsable::read(Buffer const * buf, LyXLex & lex) void InsetCollapsable::read(Buffer const * buf, LyXLex & lex)
{ {
if (lex.isOK()) { if (lex.isOK()) {
@ -108,64 +108,31 @@ void InsetCollapsable::read(Buffer const * buf, LyXLex & lex)
} }
int InsetCollapsable::ascent_collapsed() const void InsetCollapsable::dimension_collapsed(Dimension & dim) const
{ {
int width = 0; font_metrics::buttonText(label, labelfont, dim.w, dim.a, dim.d);
int ascent = 0; dim.w += 2 * TEXT_TO_INSET_OFFSET;
int descent = 0;
font_metrics::buttonText(label, labelfont, width, ascent, descent);
return ascent;
} }
int InsetCollapsable::descent_collapsed() const int InsetCollapsable::height_collapsed() const
{ {
int width = 0; Dimension dim;
int ascent = 0; font_metrics::buttonText(label, labelfont, dim.w, dim.a, dim.d);
int descent = 0; return dim.a + dim.d;
font_metrics::buttonText(label, labelfont, width, ascent, descent);
return descent;
} }
//int InsetCollapsable::width_collapsed(Painter & pain) const void InsetCollapsable::dimension(BufferView * bv, LyXFont const & font,
int InsetCollapsable::width_collapsed() const Dimension & dim) const
{ {
int width; dimension_collapsed(dim);
int ascent; if (collapsed_)
int descent; return;
font_metrics::buttonText(label, labelfont, width, ascent, descent); Dimension insetdim;
return width + 2 * TEXT_TO_INSET_OFFSET; inset.dimension(bv, font, insetdim);
} dim.d += insetdim.height() + TEXT_TO_BOTTOM_OFFSET;
dim.w = max(dim.w, insetdim.width());
int InsetCollapsable::ascent(BufferView * /*bv*/, LyXFont const &) const
{
return ascent_collapsed();
}
int InsetCollapsable::descent(BufferView * bv, LyXFont const & font) const
{
if (collapsed_)
return descent_collapsed();
return descent_collapsed()
+ inset.descent(bv, font)
+ inset.ascent(bv, font)
+ TEXT_TO_BOTTOM_OFFSET;
}
int InsetCollapsable::width(BufferView * bv, LyXFont const & font) const
{
if (collapsed_)
return width_collapsed();
int const collapsed_width = width_collapsed();
int const contents_width = inset.width(bv, font);
return max(collapsed_width, contents_width);
} }
@ -174,7 +141,9 @@ void InsetCollapsable::draw_collapsed(Painter & pain,
{ {
pain.buttonText(int(x) + TEXT_TO_INSET_OFFSET, pain.buttonText(int(x) + TEXT_TO_INSET_OFFSET,
baseline, label, labelfont); baseline, label, labelfont);
x += width_collapsed(); Dimension dim;
dimension_collapsed(dim);
x += dim.w;
} }
@ -187,12 +156,14 @@ void InsetCollapsable::draw(BufferView * bv, LyXFont const & f,
if (nodraw()) if (nodraw())
return; return;
Dimension dim_collapsed;
dimension_collapsed(dim_collapsed);
Painter & pain = bv->painter(); Painter & pain = bv->painter();
button_length = width_collapsed(); button_length = dim_collapsed.width();
button_top_y = -ascent(bv, f); button_top_y = -ascent(bv, f);
button_bottom_y = -ascent(bv, f) + ascent_collapsed() + button_bottom_y = -ascent(bv, f) + dim_collapsed.height();
descent_collapsed();
if (!isOpen()) { if (!isOpen()) {
draw_collapsed(pain, baseline, x); draw_collapsed(pain, baseline, x);
@ -207,15 +178,16 @@ void InsetCollapsable::draw(BufferView * bv, LyXFont const & f,
top_x = int(x); top_x = int(x);
top_baseline = baseline; top_baseline = baseline;
int const bl = baseline - ascent(bv, f) + ascent_collapsed(); int const bl = baseline - ascent(bv, f) + dim_collapsed.ascent();
if (inlined) { if (inlined) {
inset.draw(bv, f, baseline, x); inset.draw(bv, f, baseline, x);
} else { } else {
draw_collapsed(pain, bl, old_x); draw_collapsed(pain, bl, old_x);
inset.draw(bv, f, bl + descent_collapsed() + inset.ascent(bv, f), x); int const yy = bl + dim_collapsed.descent() + inset.ascent(bv, f);
inset.draw(bv, f, yy, x);
// contained inset may be shorter than the button // contained inset may be shorter than the button
if (x < (top_x + button_length + TEXT_TO_INSET_OFFSET)) if (x < top_x + button_length + TEXT_TO_INSET_OFFSET)
x = top_x + button_length + TEXT_TO_INSET_OFFSET; x = top_x + button_length + TEXT_TO_INSET_OFFSET;
} }
} }
@ -259,9 +231,7 @@ FuncRequest InsetCollapsable::adjustCommand(FuncRequest const & cmd)
LyXFont font(LyXFont::ALL_SANE); LyXFont font(LyXFont::ALL_SANE);
FuncRequest cmd1 = cmd; FuncRequest cmd1 = cmd;
cmd1.y = ascent(cmd.view(), font) + cmd.y - cmd1.y = ascent(cmd.view(), font) + cmd.y -
(ascent_collapsed() + (height_collapsed() + inset.ascent(cmd.view(), font));
descent_collapsed() +
inset.ascent(cmd.view(), font));
return cmd1; return cmd1;
} }
@ -394,9 +364,7 @@ Inset::RESULT InsetCollapsable::localDispatch(FuncRequest const & cmd)
} else { } else {
LyXFont font(LyXFont::ALL_SANE); LyXFont font(LyXFont::ALL_SANE);
cmd1.y = ascent(bv, font) + cmd.y - cmd1.y = ascent(bv, font) + cmd.y -
(ascent_collapsed() + (height_collapsed() + inset.ascent(bv, font));
descent_collapsed() +
inset.ascent(bv, font));
} }
inset.localDispatch(cmd); inset.localDispatch(cmd);
} }

View File

@ -45,18 +45,14 @@ public:
/// ///
void write(Buffer const *, std::ostream &) const; void write(Buffer const *, std::ostream &) const;
/// ///
int ascent(BufferView *, LyXFont const &) const; void dimension(BufferView *, LyXFont const &, Dimension &) const;
/// ///
int descent(BufferView *, LyXFont const &) const; void draw(BufferView *, const LyXFont &, int, float &) const;
///
int width(BufferView *, LyXFont const &) const;
///
void draw(BufferView *, const LyXFont &, int , float &) const;
/// draw, either inlined (no button) or collapsed/open /// draw, either inlined (no button) or collapsed/open
void draw(BufferView * bv, LyXFont const & f, void draw(BufferView * bv, LyXFont const & f,
int baseline, float & x, bool inlined) const; int baseline, float & x, bool inlined) const;
/// ///
void update(BufferView *, bool =false); void update(BufferView *, bool = false);
/// ///
EDITABLE editable() const; EDITABLE editable() const;
/// ///
@ -181,13 +177,11 @@ protected:
virtual BufferView * view() const; virtual BufferView * view() const;
/// ///
int ascent_collapsed() const; void dimension_collapsed(Dimension &) const;
/// ///
int descent_collapsed() const; int height_collapsed() const;
/// ///
int width_collapsed() const; void draw_collapsed(Painter & pain, int, float &) const;
///
void draw_collapsed(Painter & pain, int , float &) const;
/// ///
int getMaxTextWidth(Painter & pain, UpdatableInset const *) const; int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;

View File

@ -13,6 +13,7 @@
#include "inseterror.h" #include "inseterror.h"
#include "BufferView.h" #include "BufferView.h"
#include "dimension.h"
#include "funcrequest.h" #include "funcrequest.h"
#include "gettext.h" #include "gettext.h"
#include "lyxfont.h" #include "lyxfont.h"
@ -54,27 +55,14 @@ dispatch_result InsetError::localDispatch(FuncRequest const & cmd)
} }
int InsetError::ascent(BufferView *, LyXFont const & font) const void InsetError::dimension(BufferView *, LyXFont const & font,
Dimension & dim) const
{ {
LyXFont efont; LyXFont efont;
efont.setSize(font.size()).decSize(); efont.setSize(font.size()).decSize();
return font_metrics::maxAscent(efont) + 1; dim.a = font_metrics::maxAscent(efont) + 1;
} dim.d = font_metrics::maxDescent(efont) + 1;
dim.w = 6 + font_metrics::width(_("Error"), efont);
int InsetError::descent(BufferView *, LyXFont const & font) const
{
LyXFont efont;
efont.setSize(font.size()).decSize();
return font_metrics::maxDescent(efont) + 1;
}
int InsetError::width(BufferView *, LyXFont const & font) const
{
LyXFont efont;
efont.setSize(font.size()).decSize();
return 6 + font_metrics::width(_("Error"), efont);
} }

View File

@ -30,11 +30,7 @@ public:
/// ///
virtual dispatch_result localDispatch(FuncRequest const & cmd); virtual dispatch_result localDispatch(FuncRequest const & cmd);
/// ///
int ascent(BufferView *, LyXFont const &) const; void dimension(BufferView *, LyXFont const &, Dimension &) const;
///
int descent(BufferView *, LyXFont const &) const;
///
int width(BufferView *, LyXFont const &) const;
/// ///
void draw(BufferView *, LyXFont const &, int, float &) const; void draw(BufferView *, LyXFont const &, int, float &) const;
/// ///

View File

@ -306,7 +306,7 @@ bool InsetERT::lfunMouseRelease(FuncRequest const & cmd)
if (status_ == Inlined) if (status_ == Inlined)
inset.localDispatch(cmd1); inset.localDispatch(cmd1);
else if (!collapsed_ && (cmd.y > button_bottom_y)) { else if (!collapsed_ && (cmd.y > button_bottom_y)) {
cmd1.y -= ascent_collapsed() + descent_collapsed(); cmd1.y -= height_collapsed();
inset.localDispatch(cmd1); inset.localDispatch(cmd1);
} }
} }
@ -552,30 +552,13 @@ bool InsetERT::checkInsertChar(LyXFont & /* font */)
} }
int InsetERT::ascent(BufferView * bv, LyXFont const & font) const void InsetERT::dimension(BufferView * bv, LyXFont const & font,
Dimension & dim) const
{ {
if (!inlined()) if (inlined())
return InsetCollapsable::ascent(bv, font); inset.dimension(bv, font, dim);
else
return inset.ascent(bv, font); InsetCollapsable::dimension(bv, font, dim);
}
int InsetERT::descent(BufferView * bv, LyXFont const & font) const
{
if (!inlined())
return InsetCollapsable::descent(bv, font);
return inset.descent(bv, font);
}
int InsetERT::width(BufferView * bv, LyXFont const & font) const
{
if (!inlined())
return InsetCollapsable::width(bv, font);
return inset.width(bv, font);
} }

View File

@ -99,11 +99,7 @@ public:
WordLangTuple const WordLangTuple const
selectNextWordToSpellcheck(BufferView *, float &) const; selectNextWordToSpellcheck(BufferView *, float &) const;
/// ///
int ascent(BufferView *, LyXFont const &) const; void dimension(BufferView *, LyXFont const &, Dimension &) const;
///
int descent(BufferView *, LyXFont const &) const;
///
int width(BufferView *, LyXFont const &) const;
/// ///
void draw(BufferView *, const LyXFont &, int , float &) const; void draw(BufferView *, const LyXFont &, int , float &) const;
/// set the status of the inset /// set the status of the inset

View File

@ -11,7 +11,6 @@
#include <config.h> #include <config.h>
#include "insetfoot.h" #include "insetfoot.h"
#include "gettext.h" #include "gettext.h"
#include "lyxfont.h" #include "lyxfont.h"

View File

@ -12,14 +12,11 @@
#ifndef INSETFOOTLIKE_H #ifndef INSETFOOTLIKE_H
#define INSETFOOTLIKE_H #define INSETFOOTLIKE_H
#include "insetcollapsable.h" #include "insetcollapsable.h"
// To have this class is probably a bit overkill... (Lgb) // To have this class is probably a bit overkill... (Lgb)
/** The footnote inset // The footnote inset
*/
class InsetFootlike : public InsetCollapsable { class InsetFootlike : public InsetCollapsable {
public: public:
/// ///

View File

@ -60,6 +60,7 @@ TODO
#include "graphics/GraphicsParams.h" #include "graphics/GraphicsParams.h"
#include "lyxtext.h" #include "lyxtext.h"
#include "dimension.h"
#include "buffer.h" #include "buffer.h"
#include "BufferView.h" #include "BufferView.h"
#include "converter.h" #include "converter.h"
@ -88,11 +89,11 @@ TODO
#include "support/tostr.h" #include "support/tostr.h"
#include "support/systemcall.h" #include "support/systemcall.h"
#include "support/os.h" #include "support/os.h"
#include "support/lstrings.h"
#include <boost/weak_ptr.hpp> #include <boost/weak_ptr.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/signals/trackable.hpp> #include <boost/signals/trackable.hpp>
#include "support/BoostFormat.h"
#include <algorithm> // For the std::max #include <algorithm> // For the std::max
@ -287,45 +288,36 @@ bool InsetGraphics::imageIsDrawable() const
} }
int InsetGraphics::ascent(BufferView *, LyXFont const &) const void InsetGraphics::dimension(BufferView *, LyXFont const & font,
Dimension & dim) const
{ {
cache_->old_ascent = 50; cache_->old_ascent = 50;
if (imageIsDrawable()) if (imageIsDrawable())
cache_->old_ascent = cache_->loader.image()->getHeight(); cache_->old_ascent = cache_->loader.image()->getHeight();
return cache_->old_ascent; dim.a = cache_->old_ascent;
} dim.d = 0;
int InsetGraphics::descent(BufferView *, LyXFont const &) const
{
return 0;
}
int InsetGraphics::width(BufferView *, LyXFont const & font) const
{
if (imageIsDrawable()) if (imageIsDrawable())
return cache_->loader.image()->getWidth() + 2 * TEXT_TO_INSET_OFFSET; dim.w = cache_->loader.image()->getWidth() + 2 * TEXT_TO_INSET_OFFSET;
else {
int font_width = 0;
int font_width = 0; LyXFont msgFont(font);
msgFont.setFamily(LyXFont::SANS_FAMILY);
LyXFont msgFont(font); string const justname = OnlyFilename(params().filename);
msgFont.setFamily(LyXFont::SANS_FAMILY); if (!justname.empty()) {
msgFont.setSize(LyXFont::SIZE_FOOTNOTE);
font_width = font_metrics::width(justname, msgFont);
}
string const justname = OnlyFilename (params().filename); string const msg = statusMessage();
if (!justname.empty()) { if (!msg.empty()) {
msgFont.setSize(LyXFont::SIZE_FOOTNOTE); msgFont.setSize(LyXFont::SIZE_TINY);
font_width = font_metrics::width(justname, msgFont); font_width = std::max(font_width, font_metrics::width(msg, msgFont));
}
dim.w = std::max(50, font_width + 15);
} }
string const msg = statusMessage();
if (!msg.empty()) {
msgFont.setSize(LyXFont::SIZE_TINY);
int const msg_width = font_metrics::width(msg, msgFont);
font_width = std::max(font_width, msg_width);
}
return std::max(50, font_width + 15);
} }
@ -633,15 +625,8 @@ string const InsetGraphics::prepareFile(Buffer const * buf) const
<< temp_file << temp_file
<< (success ? " succeeded\n" : " failed\n"); << (success ? " succeeded\n" : " failed\n");
if (!success) { if (!success) {
#if USE_BOOST_FORMAT string str = bformat(_("Could not copy the file\n%1$s\n"
boost::format fmt(_("Could not copy the file\n%1$s\ninto the temporary directory.")); "into the temporary directory."), orig_file_with_path);
fmt % orig_file_with_path;
string str = fmt.str();
#else
string str = _("Could not copy the file\n");
str += orig_file_with_path;
str += _("\ninto the temporary directory.");
#endif
Alert::error(_("Graphics display failed"), str); Alert::error(_("Graphics display failed"), str);
return orig_file; return orig_file;
} }
@ -677,16 +662,9 @@ string const InsetGraphics::prepareFile(Buffer const * buf) const
Systemcall one; Systemcall one;
one.startscript(Systemcall::Wait, command); one.startscript(Systemcall::Wait, command);
if (!IsFileReadable(ChangeExtension(outfile_base, to))) { if (!IsFileReadable(ChangeExtension(outfile_base, to))) {
#if USE_BOOST_FORMAT string str = bformat(_("No information for converting %1$s "
boost::format fmt(_("No information for converting %1$s format files to %1$s.\n" "format files to %1$s.\n"
"Try defining a convertor in the preferences.")); "Try defining a convertor in the preferences."), from, to);
fmt % from % to;
string str = fmt.str();
#else
string str = _("No information for converting ");
str += from + _(" format files to ") + to;
str += _(".\nTry defining a convertor in the preferences.");
#endif
Alert::error(_("Could not convert image"), str); Alert::error(_("Could not convert image"), str);
} }
} }

View File

@ -35,11 +35,7 @@ public:
/// ///
virtual dispatch_result localDispatch(FuncRequest const & cmd); virtual dispatch_result localDispatch(FuncRequest const & cmd);
/// ///
int ascent(BufferView *, LyXFont const &) const; void dimension(BufferView *, LyXFont const &, Dimension &) const;
///
int descent(BufferView *, LyXFont const &) const;
///
int width(BufferView *, LyXFont const &) const;
/// ///
void draw(BufferView *, LyXFont const &, int, float &) const; void draw(BufferView *, LyXFont const &, int, float &) const;
/// ///

View File

@ -28,11 +28,13 @@
using std::ostream; using std::ostream;
InsetGraphicsParams::InsetGraphicsParams() InsetGraphicsParams::InsetGraphicsParams()
{ {
init(); init();
} }
InsetGraphicsParams::InsetGraphicsParams(InsetGraphicsParams const & igp) InsetGraphicsParams::InsetGraphicsParams(InsetGraphicsParams const & igp)
{ {
// I decided to skip the initialization since the copy will overwrite // I decided to skip the initialization since the copy will overwrite
@ -41,6 +43,7 @@ InsetGraphicsParams::InsetGraphicsParams(InsetGraphicsParams const & igp)
copy(igp); copy(igp);
} }
InsetGraphicsParams & InsetGraphicsParams &
InsetGraphicsParams::operator=(InsetGraphicsParams const & params) InsetGraphicsParams::operator=(InsetGraphicsParams const & params)
{ {
@ -51,6 +54,7 @@ InsetGraphicsParams::operator=(InsetGraphicsParams const & params)
return *this; return *this;
} }
void InsetGraphicsParams::init() void InsetGraphicsParams::init()
{ {
filename.erase(); filename.erase();
@ -73,6 +77,7 @@ void InsetGraphicsParams::init()
special.erase(); // additional userdefined stuff special.erase(); // additional userdefined stuff
} }
void InsetGraphicsParams::copy(InsetGraphicsParams const & igp) void InsetGraphicsParams::copy(InsetGraphicsParams const & igp)
{ {
filename = igp.filename; filename = igp.filename;
@ -95,6 +100,7 @@ void InsetGraphicsParams::copy(InsetGraphicsParams const & igp)
special = igp.special; special = igp.special;
} }
bool operator==(InsetGraphicsParams const & left, bool operator==(InsetGraphicsParams const & left,
InsetGraphicsParams const & right) InsetGraphicsParams const & right)
{ {
@ -123,12 +129,14 @@ bool operator==(InsetGraphicsParams const & left,
return false; return false;
} }
bool operator!=(InsetGraphicsParams const & left, bool operator!=(InsetGraphicsParams const & left,
InsetGraphicsParams const & right) InsetGraphicsParams const & right)
{ {
return !(left == right); return !(left == right);
} }
void InsetGraphicsParams::Write(ostream & os) const void InsetGraphicsParams::Write(ostream & os) const
{ {
// Do not write the default values // Do not write the default values

View File

@ -13,6 +13,7 @@
#include "insetlatexaccent.h" #include "insetlatexaccent.h"
#include "debug.h" #include "debug.h"
#include "dimension.h"
#include "lyxrc.h" #include "lyxrc.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include "BufferView.h" #include "BufferView.h"
@ -262,48 +263,34 @@ void InsetLatexAccent::checkContents()
} }
int InsetLatexAccent::ascent(BufferView *, LyXFont const & font) const void InsetLatexAccent::dimension(BufferView *, LyXFont const & font,
Dimension & dim) const
{ {
// This function is a bit too simplistix and is just a // This function is a bit too simplistic and is just a
// "try to make a fit for all accents" approach, to // "try to make a fit for all accents" approach, to
// make it better we need to know what kind of accent is // make it better we need to know what kind of accent is
// used and add to max based on that. // used and add to max based on that.
int max;
if (candisp) { if (candisp) {
if (ic == ' ') if (ic == ' ')
max = font_metrics::ascent('a', font); dim.a = font_metrics::ascent('a', font);
else else
max = font_metrics::ascent(ic, font); dim.a = font_metrics::ascent(ic, font);
if (plusasc) if (plusasc)
max += (font_metrics::maxAscent(font) + 3) / 3; dim.a += (font_metrics::maxAscent(font) + 3) / 3;
} else
max = font_metrics::maxAscent(font) + 4;
return max;
}
int InsetLatexAccent::descent(BufferView *, LyXFont const & font) const
{
int max;
if (candisp) {
if (ic == ' ') if (ic == ' ')
max = font_metrics::descent('a', font); dim.d = font_metrics::descent('a', font);
else else
max = font_metrics::descent(ic, font); dim.d = font_metrics::descent(ic, font);
if (plusdesc) if (plusdesc)
max += 3; dim.d += 3;
} else
max = font_metrics::maxDescent(font) + 4;
return max;
}
dim.w = font_metrics::width(ic, font);
int InsetLatexAccent::width(BufferView *, LyXFont const & font) const } else {
{ dim.a = font_metrics::maxAscent(font) + 4;
if (candisp) dim.d = font_metrics::maxDescent(font) + 4;
return font_metrics::width(ic, font); dim.w = font_metrics::width(contents, font) + 4;
else }
return font_metrics::width(contents, font) + 4;
} }

View File

@ -34,11 +34,7 @@ public:
explicit explicit
InsetLatexAccent(string const & string); InsetLatexAccent(string const & string);
/// ///
int ascent(BufferView *, LyXFont const &) const; void dimension(BufferView *, LyXFont const &, Dimension &) const;
///
int descent(BufferView *, LyXFont const &) const;
///
int width(BufferView *, LyXFont const &) const;
/// ///
void draw(BufferView *, LyXFont const &, int, float &) const; void draw(BufferView *, LyXFont const &, int, float &) const;
/// ///

View File

@ -9,8 +9,8 @@
* Full author contact details are available in file CREDITS * Full author contact details are available in file CREDITS
*/ */
#ifndef InsetList_H #ifndef INSETLIST_H
#define InsetList_H #define INSETLIST_H
#include "insetcollapsable.h" #include "insetcollapsable.h"

View File

@ -16,8 +16,10 @@
#include "BufferView.h" #include "BufferView.h"
#include "debug.h" #include "debug.h"
#include "dimension.h"
#include "funcrequest.h" #include "funcrequest.h"
#include "gettext.h" #include "gettext.h"
#include "Lsstream.h"
#include "lyxfont.h" #include "lyxfont.h"
#include "lyxlex.h" #include "lyxlex.h"
#include "lyxtext.h" #include "lyxtext.h"
@ -27,7 +29,6 @@
#include "frontends/Dialogs.h" #include "frontends/Dialogs.h"
#include "support/LOstream.h" #include "support/LOstream.h"
#include "support/lstrings.h"
using std::ostream; using std::ostream;
using std::endl; using std::endl;
@ -217,50 +218,28 @@ void InsetMinipage::read(Buffer const * buf, LyXLex & lex)
} }
int InsetMinipage::ascent(BufferView * bv, LyXFont const & font) const void InsetMinipage::dimension(BufferView * bv, LyXFont const & font,
Dimension & dim) const
{ {
if (collapsed_) if (collapsed_)
return ascent_collapsed(); dimension_collapsed(dim);
else { else {
// Take placement into account. Dimension d;
int i = 0; InsetCollapsable::dimension(bv, font, dim);
switch (params_.pos) { switch (params_.pos) {
case top: case top:
i = InsetCollapsable::ascent(bv, font); dim.a = d.a;
dim.d = d.d;
break; break;
case center: case center:
i = (InsetCollapsable::ascent(bv, font) dim.a = d.height() / 2;
+ InsetCollapsable::descent(bv, font)) / 2; dim.d = dim.a;
break; break;
case bottom: case bottom:
i = InsetCollapsable::descent(bv, font); dim.a = d.d;
dim.d = d.a;
break; break;
} }
return i;
}
}
int InsetMinipage::descent(BufferView * bv, LyXFont const & font) const
{
if (collapsed_)
return descent_collapsed();
else {
// Take placement into account.
int i = 0;
switch (params_.pos) {
case top:
i = InsetCollapsable::descent(bv, font);
break;
case center:
i = (InsetCollapsable::ascent(bv, font)
+ InsetCollapsable::descent(bv, font)) / 2;
break;
case bottom:
i = InsetCollapsable::ascent(bv, font);
break;
}
return i;
} }
} }

View File

@ -68,9 +68,7 @@ public:
/// ///
Inset * clone(Buffer const &, bool same_id = false) const; Inset * clone(Buffer const &, bool same_id = false) const;
/// ///
int ascent(BufferView *, LyXFont const &) const; void dimension(BufferView *, LyXFont const &, Dimension &) const;
///
int descent(BufferView *, LyXFont const &) const;
/// ///
Inset::Code lyxCode() const { return Inset::MINIPAGE_CODE; } Inset::Code lyxCode() const { return Inset::MINIPAGE_CODE; }
/// ///

View File

@ -10,24 +10,20 @@
#include <config.h> #include <config.h>
#include "insetnewline.h"
#include "BufferView.h" #include "BufferView.h"
#include "debug.h"
#include "dimension.h"
#include "paragraph.h" #include "paragraph.h"
#include "lyxtext.h" #include "lyxtext.h"
#include "insetnewline.h"
#include "support/LOstream.h" #include "support/LOstream.h"
#include "frontends/Painter.h" #include "frontends/Painter.h"
#include "frontends/font_metrics.h" #include "frontends/font_metrics.h"
#include "debug.h"
using std::ostream; using std::ostream;
using std::endl; using std::endl;
InsetNewline::InsetNewline()
: Inset()
{}
void InsetNewline::read(Buffer const *, LyXLex &) void InsetNewline::read(Buffer const *, LyXLex &)
{ {
@ -41,21 +37,12 @@ void InsetNewline::write(Buffer const *, ostream & os) const
} }
int InsetNewline::ascent(BufferView *, LyXFont const & font) const void InsetNewline::dimension(BufferView *, LyXFont const & font,
Dimension & dim) const
{ {
return font_metrics::maxAscent(font); dim.a = font_metrics::maxAscent(font);
} dim.d = font_metrics::maxDescent(font);
dim.w = font_metrics::width('n', font);
int InsetNewline::descent(BufferView *, LyXFont const & font) const
{
return font_metrics::maxDescent(font);
}
int InsetNewline::width(BufferView *, LyXFont const & font) const
{
return font_metrics::width('n', font);
} }

View File

@ -18,7 +18,7 @@
class InsetNewline : public Inset { class InsetNewline : public Inset {
public: public:
InsetNewline(); InsetNewline() {}
virtual Inset * clone(Buffer const &, bool = false) const { virtual Inset * clone(Buffer const &, bool = false) const {
return new InsetNewline; return new InsetNewline;
@ -26,11 +26,7 @@ public:
Inset::Code lyxCode() const { return Inset::NEWLINE_CODE; } Inset::Code lyxCode() const { return Inset::NEWLINE_CODE; }
virtual int ascent(BufferView *, LyXFont const &) const; void dimension(BufferView *, LyXFont const &, Dimension &) const;
virtual int descent(BufferView *, LyXFont const &) const;
virtual int width(BufferView *, LyXFont const &) const;
virtual void draw(BufferView *, LyXFont const &, virtual void draw(BufferView *, LyXFont const &,
int baseline, float & x) const; int baseline, float & x) const;

View File

@ -10,29 +10,26 @@
#include <config.h> #include <config.h>
#include "insetquotes.h" #include "insetquotes.h"
#include "support/LAssert.h"
#include "support/lstrings.h"
#include "BufferView.h" #include "BufferView.h"
#include "LaTeXFeatures.h" #include "LaTeXFeatures.h"
#include "frontends/Painter.h" #include "frontends/Painter.h"
#include "buffer.h" #include "buffer.h"
#include "debug.h" #include "debug.h"
#include "dimension.h"
#include "frontends/font_metrics.h" #include "frontends/font_metrics.h"
#include "language.h" #include "language.h"
#include "lyxfont.h" #include "lyxfont.h"
#include "lyxrc.h" #include "lyxrc.h"
#include "paragraph.h" #include "paragraph.h"
#include "lyxlex.h" #include "lyxlex.h"
#include "support/LAssert.h"
#include "support/lstrings.h"
using std::ostream; using std::ostream;
using std::endl; using std::endl;
// Quotes. Used for the various quotes. German, English, French,
// Danish, Polish, all either double or single.
namespace { namespace {
// codes used to read/write quotes to LyX files // codes used to read/write quotes to LyX files
@ -73,9 +70,7 @@ InsetQuotes::InsetQuotes(string const & str)
} }
InsetQuotes::InsetQuotes(quote_language l, InsetQuotes::InsetQuotes(quote_language l, quote_side s, quote_times t)
quote_side s,
quote_times t)
: language_(l), side_(s), times_(t) : language_(l), side_(s), times_(t)
{} {}
@ -174,33 +169,22 @@ string const InsetQuotes::dispString(Language const * loclang) const
} }
int InsetQuotes::ascent(BufferView *, LyXFont const & font) const void InsetQuotes::dimension(BufferView *, LyXFont const & font,
Dimension & dim) const
{ {
return font_metrics::maxAscent(font); dim.a = font_metrics::maxAscent(font);
} dim.d = font_metrics::maxDescent(font);
dim.w = 0;
int InsetQuotes::descent(BufferView *, LyXFont const & font) const
{
return font_metrics::maxDescent(font);
}
int InsetQuotes::width(BufferView *, LyXFont const & font) const
{
string const text = dispString(font.language()); string const text = dispString(font.language());
int w = 0;
for (string::size_type i = 0; i < text.length(); ++i) { for (string::size_type i = 0; i < text.length(); ++i) {
if (text[i] == ' ') if (text[i] == ' ')
w += font_metrics::width('i', font); dim.w += font_metrics::width('i', font);
else if (i == 0 || text[i] != text[i - 1]) else if (i == 0 || text[i] != text[i - 1])
w += font_metrics::width(text[i], font); dim.w += font_metrics::width(text[i], font);
else else
w += font_metrics::width(',', font); dim.w += font_metrics::width(',', font);
} }
return w;
} }

View File

@ -22,7 +22,6 @@ struct LaTeXFeatures;
/** Quotes. /** Quotes.
Used for the various quotes. German, English, French, all either Used for the various quotes. German, English, French, all either
double or single **/ double or single **/
class InsetQuotes : public Inset { class InsetQuotes : public Inset {
@ -68,13 +67,11 @@ public:
InsetQuotes(string const & str = "eld"); InsetQuotes(string const & str = "eld");
/// Create the right quote inset after character c /// Create the right quote inset after character c
InsetQuotes(char c, BufferParams const & params); InsetQuotes(char c, BufferParams const & params);
///
Inset * clone(Buffer const &, bool same_id = false) const;
/// ///
int ascent(BufferView *, LyXFont const &) const; void dimension(BufferView *, LyXFont const &, Dimension &) const;
///
int descent(BufferView *, LyXFont const &) const;
///
int width(BufferView *, LyXFont const &) const;
/// ///
void draw(BufferView *, LyXFont const &, int, float &) const; void draw(BufferView *, LyXFont const &, int, float &) const;
#if 0 #if 0
@ -97,8 +94,6 @@ public:
/// ///
void validate(LaTeXFeatures &) const; void validate(LaTeXFeatures &) const;
/// ///
virtual Inset * clone(Buffer const &, bool same_id = false) const;
///
Inset::Code lyxCode() const; Inset::Code lyxCode() const;
// should this inset be handled like a normal charater // should this inset be handled like a normal charater
bool isChar() const { return true; } bool isChar() const { return true; }

View File

@ -12,9 +12,10 @@
#include <config.h> #include <config.h>
#include "insetspecialchar.h" #include "insetspecialchar.h"
#include "debug.h" #include "debug.h"
#include "dimension.h"
#include "LaTeXFeatures.h" #include "LaTeXFeatures.h"
#include "BufferView.h" #include "BufferView.h"
#include "frontends/Painter.h" #include "frontends/Painter.h"
@ -25,6 +26,7 @@
using std::ostream; using std::ostream;
using std::max; using std::max;
InsetSpecialChar::InsetSpecialChar(Kind k) InsetSpecialChar::InsetSpecialChar(Kind k)
: kind_(k) : kind_(k)
{} {}
@ -36,51 +38,23 @@ InsetSpecialChar::Kind InsetSpecialChar::kind() const
} }
int InsetSpecialChar::ascent(BufferView *, LyXFont const & font) const void InsetSpecialChar::dimension(BufferView *, LyXFont const & font,
Dimension & dim) const
{ {
return font_metrics::maxAscent(font); dim.a = font_metrics::maxAscent(font);
} dim.d = font_metrics::maxDescent(font);
char const * s = 0;
int InsetSpecialChar::descent(BufferView *, LyXFont const & font) const
{
return font_metrics::maxDescent(font);
}
int InsetSpecialChar::width(BufferView *, LyXFont const & font) const
{
switch (kind_) { switch (kind_) {
case HYPHENATION: case LIGATURE_BREAK: s = "|"; break;
{ case END_OF_SENTENCE: s = "."; break;
int w = font_metrics::width('-', font); case LDOTS: s = ". . ."; break;
if (w > 5) case MENU_SEPARATOR: s = " x "; break;
w -= 2; // to make it look shorter case PROTECTED_SEPARATOR: s = "x"; break;
return w;
} }
case LIGATURE_BREAK: dim.w = font_metrics::width('x', font);
{ if (kind_ == HYPHENATION && dim.w > 5)
return font_metrics::width('|', font); dim.w -= 2; // to make it look shorter
}
case END_OF_SENTENCE:
{
return font_metrics::width('.', font);
}
case LDOTS:
{
return font_metrics::width(". . .", font);
}
case MENU_SEPARATOR:
{
return font_metrics::width(" x ", font);
}
case PROTECTED_SEPARATOR:
{
return font_metrics::width('x', font);
}
}
return 1; // To shut up gcc
} }

View File

@ -48,11 +48,7 @@ public:
/// ///
Kind kind() const; Kind kind() const;
/// ///
int ascent(BufferView *, LyXFont const &) const; void dimension(BufferView *, LyXFont const &, Dimension &) const;
///
int descent(BufferView *, LyXFont const &) const;
///
int width(BufferView *, LyXFont const &) const;
/// ///
void draw(BufferView *, LyXFont const &, int, float &) const; void draw(BufferView *, LyXFont const &, int, float &) const;
/// ///

View File

@ -17,10 +17,12 @@
#include "BufferView.h" #include "BufferView.h"
#include "lfuns.h" #include "lfuns.h"
#include "debug.h" #include "debug.h"
#include "dimension.h"
#include "funcrequest.h" #include "funcrequest.h"
#include "gettext.h" #include "gettext.h"
#include "language.h" #include "language.h"
#include "LaTeXFeatures.h" #include "LaTeXFeatures.h"
#include "Lsstream.h"
#include "lyx_cb.h" #include "lyx_cb.h"
#include "lyxfunc.h" #include "lyxfunc.h"
#include "lyxlength.h" #include "lyxlength.h"
@ -242,21 +244,12 @@ void InsetTabular::read(Buffer const * buf, LyXLex & lex)
} }
int InsetTabular::ascent(BufferView *, LyXFont const &) const void InsetTabular::dimension(BufferView *, LyXFont const &,
Dimension & dim) const
{ {
return tabular->GetAscentOfRow(0); dim.a = tabular->GetAscentOfRow(0);
} dim.d = tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
dim.w = tabular->GetWidthOfTabular() + 2 * ADD_TO_TABULAR_WIDTH;
int InsetTabular::descent(BufferView *, LyXFont const &) const
{
return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
}
int InsetTabular::width(BufferView *, LyXFont const &) const
{
return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
} }

View File

@ -50,6 +50,7 @@
#include "LString.h" #include "LString.h"
#include "lyxcursor.h" #include "lyxcursor.h"
#include "FuncStatus.h" #include "FuncStatus.h"
#include "frontends/mouse_state.h"
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
#include <boost/weak_ptr.hpp> #include <boost/weak_ptr.hpp>
@ -85,11 +86,7 @@ public:
/// ///
void write(Buffer const *, std::ostream &) const; void write(Buffer const *, std::ostream &) const;
/// ///
int ascent(BufferView *, LyXFont const &) const; void dimension(BufferView *, LyXFont const &, Dimension &) const;
///
int descent(BufferView *, LyXFont const &) const;
///
int width(BufferView *, LyXFont const & f) const;
/// ///
void draw(BufferView *, const LyXFont &, int , float &) const; void draw(BufferView *, const LyXFont &, int , float &) const;
/// ///

View File

@ -16,11 +16,13 @@
#include "BufferView.h" #include "BufferView.h"
#include "CutAndPaste.h" #include "CutAndPaste.h"
#include "debug.h" #include "debug.h"
#include "dimension.h"
#include "funcrequest.h" #include "funcrequest.h"
#include "gettext.h" #include "gettext.h"
#include "intl.h" #include "intl.h"
#include "LaTeXFeatures.h" #include "LaTeXFeatures.h"
#include "LColor.h" #include "LColor.h"
#include "Lsstream.h"
#include "lyxfont.h" #include "lyxfont.h"
#include "lyxcursor.h" #include "lyxcursor.h"
#include "lyxfind.h" #include "lyxfind.h"
@ -296,47 +298,29 @@ void InsetText::read(Buffer const * buf, LyXLex & lex)
} }
int InsetText::ascent(BufferView * bv, LyXFont const &) const void InsetText::dimension(BufferView * bv, LyXFont const &,
Dimension & dim) const
{ {
insetAscent = getLyXText(bv)->rows().begin()->ascent_of_text() + LyXText * text = getLyXText(bv);
TEXT_TO_INSET_OFFSET; dim.a = text->rows().begin()->ascent_of_text() + TEXT_TO_INSET_OFFSET;
return insetAscent; dim.d = text->height - dim.a + TEXT_TO_INSET_OFFSET;
} dim.w = max(textWidth(bv), int(text->width)) + 2 * TEXT_TO_INSET_OFFSET;
dim.w = max(dim.w, 10);
int InsetText::descent(BufferView * bv, LyXFont const &) const
{
LyXText * llt = getLyXText(bv);
insetDescent = llt->height - llt->rows().begin()->ascent_of_text() +
TEXT_TO_INSET_OFFSET;
return insetDescent;
}
int InsetText::width(BufferView * bv, LyXFont const &) const
{
insetWidth = max(textWidth(bv), (int)getLyXText(bv)->width) +
(2 * TEXT_TO_INSET_OFFSET);
insetWidth = max(insetWidth, 10);
return insetWidth;
} }
int InsetText::textWidth(BufferView * bv, bool fordraw) const int InsetText::textWidth(BufferView * bv, bool fordraw) const
{ {
int w; int w = autoBreakRows ? getMaxWidth(bv, this) : -1;
if (!autoBreakRows) {
w = -1; if (fordraw)
} else { return max(w - 2 * TEXT_TO_INSET_OFFSET,
w = getMaxWidth(bv, this);
}
if (fordraw) {
return max(w - (2 * TEXT_TO_INSET_OFFSET),
(int)getLyXText(bv)->width); (int)getLyXText(bv)->width);
} else if (w < 0) {
return -1; if (w < 0)
} return -1;
return w - (2 * TEXT_TO_INSET_OFFSET);
return w - 2 * TEXT_TO_INSET_OFFSET;
} }
@ -2626,14 +2610,13 @@ void InsetText::getDrawFont(LyXFont & font) const
} }
void InsetText::appendParagraphs(Buffer * buffer, void InsetText::appendParagraphs(Buffer * buffer, ParagraphList & plist)
ParagraphList & plist)
{ {
#warning FIXME Check if Changes stuff needs changing here. (Lgb) #warning FIXME Check if Changes stuff needs changing here. (Lgb)
// And it probably does. You have to take a look at this John. (Lgb) // And it probably does. You have to take a look at this John. (Lgb)
#warning John, have a look here. (Lgb) #warning John, have a look here. (Lgb)
BufferParams const & bparams = buffer->params;
#if 0 #if 0
BufferParams const & bparams = buffer->params;
Paragraph * buf; Paragraph * buf;
Paragraph * tmpbuf = newpar; Paragraph * tmpbuf = newpar;
Paragraph * lastbuffer = buf = new Paragraph(*tmpbuf, false); Paragraph * lastbuffer = buf = new Paragraph(*tmpbuf, false);

View File

@ -86,11 +86,7 @@ public:
/// ///
void write(Buffer const *, std::ostream &) const; void write(Buffer const *, std::ostream &) const;
/// ///
int ascent(BufferView *, LyXFont const &) const; void dimension(BufferView *, LyXFont const &, Dimension &) const;
///
int descent(BufferView *, LyXFont const &) const;
///
int width(BufferView *, LyXFont const & f) const;
/// ///
int textWidth(BufferView *, bool fordraw = false) const; int textWidth(BufferView *, bool fordraw = false) const;
/// ///

View File

@ -542,10 +542,11 @@ LyXFont & LyXFont::setLyXFamily(string const & fam)
string const s = ascii_lowercase(fam); string const s = ascii_lowercase(fam);
int i = 0; int i = 0;
while (s != LyXFamilyNames[i] && LyXFamilyNames[i] != "error") ++i; while (s != LyXFamilyNames[i] && LyXFamilyNames[i] != "error")
if (s == LyXFamilyNames[i]) { ++i;
if (s == LyXFamilyNames[i])
setFamily(LyXFont::FONT_FAMILY(i)); setFamily(LyXFont::FONT_FAMILY(i));
} else else
lyxerr << "LyXFont::setLyXFamily: Unknown family `" lyxerr << "LyXFont::setLyXFamily: Unknown family `"
<< s << '\'' << endl; << s << '\'' << endl;
return *this; return *this;

View File

@ -28,7 +28,7 @@ struct keyword_item {
class LyXLex : boost::noncopyable { class LyXLex : boost::noncopyable {
public: public:
/// ///
LyXLex (keyword_item *, int); LyXLex(keyword_item *, int);
/// ///
~LyXLex(); ~LyXLex();

View File

@ -1,4 +1,14 @@
2003-05-19 André Pönitz <poenitz@gmx.net>
* Makefile.am:
* dimension.[Ch]: promote files to src/dimension.[Ch[
* formula.[Ch]:
* formulamacro.[Ch]:
* formulamacro.h:
* math_inset.h: replace ascents/descent/witdh with dimension()
2003-05-14 André Pönitz <poenitz@gmx.net> 2003-05-14 André Pönitz <poenitz@gmx.net>
* math_substack.[Ch]: add markers * math_substack.[Ch]: add markers

View File

@ -5,8 +5,6 @@ noinst_LTLIBRARIES = libmathed.la
INCLUDES = -I$(srcdir)/../ $(BOOST_INCLUDES) INCLUDES = -I$(srcdir)/../ $(BOOST_INCLUDES)
libmathed_la_SOURCES = \ libmathed_la_SOURCES = \
dimension.C \
dimension.h \
textpainter.C \ textpainter.C \
textpainter.h \ textpainter.h \
formulabase.C \ formulabase.C \

View File

@ -34,6 +34,7 @@
#include "debug.h" #include "debug.h"
#include "lyxrc.h" #include "lyxrc.h"
#include "funcrequest.h" #include "funcrequest.h"
#include "Lsstream.h"
#include "support/LOstream.h" #include "support/LOstream.h"
#include "support/LAssert.h" #include "support/LAssert.h"
@ -275,29 +276,21 @@ bool InsetFormula::insetAllowed(Inset::Code code) const
} }
int InsetFormula::ascent(BufferView *, LyXFont const &) const void InsetFormula::dimension(BufferView * bv, LyXFont const & font,
{ Dimension & dim) const
return preview_->previewReady() ?
preview_->pimage()->ascent() : 1 + par_->ascent();
}
int InsetFormula::descent(BufferView *, LyXFont const &) const
{
if (!preview_->previewReady())
return 1 + par_->descent();
int const descent = preview_->pimage()->descent();
return display() ? descent + 12 : descent;
}
int InsetFormula::width(BufferView * bv, LyXFont const & font) const
{ {
metrics(bv, font); metrics(bv, font);
return preview_->previewReady() ? if (preview_->previewReady()) {
1 + preview_->pimage()->width() : par_->width(); dim.a = preview_->pimage()->ascent();
int const descent = preview_->pimage()->descent();
dim.d = display() ? descent + 12 : descent;
// insert a one pixel gap in front of the formula // insert a one pixel gap in front of the formula
dim.w = 1 + preview_->pimage()->width();
} else {
dim = par_->dimensions();
dim.a += 1;
dim.d += 1;
}
} }

View File

@ -35,11 +35,7 @@ public:
/// ///
~InsetFormula(); ~InsetFormula();
/// ///
int ascent(BufferView *, LyXFont const &) const; void dimension(BufferView *, LyXFont const &, Dimension &) const;
///
int descent(BufferView *, LyXFont const &) const;
///
int width(BufferView *, LyXFont const &) const;
/// ///
void draw(BufferView *, LyXFont const &, int, float &) const; void draw(BufferView *, LyXFont const &, int, float &) const;

View File

@ -13,9 +13,7 @@
#ifndef INSET_FORMULABASE_H #ifndef INSET_FORMULABASE_H
#define INSET_FORMULABASE_H #define INSET_FORMULABASE_H
#include "insets/updatableinset.h" #include "insets/updatableinset.h"
#include "frontends/mouse_state.h"
#include "lyxfont.h" #include "lyxfont.h"
#include <boost/weak_ptr.hpp> #include <boost/weak_ptr.hpp>
@ -25,17 +23,14 @@ class Buffer;
class BufferView; class BufferView;
class MathAtom; class MathAtom;
/// An abstract base class for all math related LyX insets /// An abstract base class for all math related LyX insets
class InsetFormulaBase : public UpdatableInset { class InsetFormulaBase : public UpdatableInset {
public: public:
/// ///
InsetFormulaBase(); InsetFormulaBase();
/// ///
virtual int ascent(BufferView *, LyXFont const &) const = 0; Inset * clone(Buffer const &, bool same_id = false) const = 0;
///
virtual int descent(BufferView *, LyXFont const &) const = 0;
///
virtual int width(BufferView *, LyXFont const &) const = 0;
/// ///
virtual void draw(BufferView *,LyXFont const &, int, float &) const = 0; virtual void draw(BufferView *,LyXFont const &, int, float &) const = 0;
/// lowest x coordinate /// lowest x coordinate
@ -53,8 +48,6 @@ public:
// user-accessible way to override "false positives" // user-accessible way to override "false positives"
virtual void validate(LaTeXFeatures &) const; virtual void validate(LaTeXFeatures &) const;
/// ///
virtual Inset * clone(Buffer const &, bool same_id = false) const = 0;
///
virtual Inset::Code lyxCode() const; virtual Inset::Code lyxCode() const;
/// what appears in the minibuffer when opening /// what appears in the minibuffer when opening
virtual string const editMessage() const; virtual string const editMessage() const;

View File

@ -126,29 +126,22 @@ void InsetFormulaMacro::read(std::istream & is)
string InsetFormulaMacro::prefix() const string InsetFormulaMacro::prefix() const
{ {
#if USE_BOOST_FORMAT #if USE_BOOST_FORMAT
return boost::io::str(boost::format(_(" Macro: %s: ")) % getInsetName()); return STRCONV(boost::io::str(boost::format(_(" Macro: %s: ")) %
STRCONV(getInsetName())));
#else #else
return _(" Macro: ") + getInsetName() + ": "; return _(" Macro: ") + getInsetName() + ": ";
#endif #endif
} }
int InsetFormulaMacro::ascent(BufferView *, LyXFont const &) const void InsetFormulaMacro::dimension(BufferView * bv, LyXFont const & font,
Dimension & dim) const
{ {
return par()->ascent() + 5; metrics(bv, font);
} dim = par()->dimensions();
dim.a += 5;
dim.d += 5;
int InsetFormulaMacro::descent(BufferView *, LyXFont const &) const dim.w += 10 + font_metrics::width(prefix(), font);
{
return par()->descent() + 5;
}
int InsetFormulaMacro::width(BufferView * bv, LyXFont const & f) const
{
metrics(bv, f);
return 10 + font_metrics::width(prefix(), f) + par()->width();
} }

View File

@ -33,11 +33,7 @@ public:
/// constructs a mocro from its LaTeX definition /// constructs a mocro from its LaTeX definition
explicit InsetFormulaMacro(string const & s); explicit InsetFormulaMacro(string const & s);
/// ///
int ascent(BufferView *, LyXFont const &) const; void dimension(BufferView *, LyXFont const &, Dimension &) const;
///
int descent(BufferView *, LyXFont const &) const;
///
int width(BufferView *, LyXFont const &) const;
/// ///
void draw(BufferView *, LyXFont const &, int, float &) const; void draw(BufferView *, LyXFont const &, int, float &) const;

View File

@ -22,11 +22,9 @@
#ifndef MATH_INSET_H #ifndef MATH_INSET_H
#define MATH_INSET_H #define MATH_INSET_H
#include <config.h> #include <config.h>
#include "LString.h" #include "LString.h"
#include "frontends/mouse_state.h"
#include "insets/insetbase.h" #include "insets/insetbase.h"
#include "math_data.h" #include "math_data.h"

View File

@ -41,6 +41,7 @@ using lyx::pos_type;
using std::endl; using std::endl;
using std::ostream; using std::ostream;
void breakParagraph(BufferParams const & bparams, void breakParagraph(BufferParams const & bparams,
ParagraphList & paragraphs, ParagraphList & paragraphs,
ParagraphList::iterator par, ParagraphList::iterator par,