mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
simplify rectText and buttonText add separate metric methods for these
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2314 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
c06a45c6e4
commit
94c00c08a8
@ -9,7 +9,6 @@ src/converter.C
|
||||
src/CutAndPaste.C
|
||||
src/debug.C
|
||||
src/exporter.C
|
||||
src/ext_l10n.h
|
||||
src/figure_form.C
|
||||
src/figureForm.C
|
||||
src/FontLoader.C
|
||||
|
@ -1,3 +1,13 @@
|
||||
2001-07-24 Lars Gullik Bjønnes <larsbj@birdstep.com>
|
||||
|
||||
* text.C (getVisibleRow): adjust
|
||||
|
||||
* font.[Ch] (rectText): new method, metrics
|
||||
(buttonText): new method, metrics
|
||||
|
||||
* PainterBase.[hC]: make rectText and buttonText always draw and take
|
||||
fewer paramteres.
|
||||
|
||||
2001-07-22 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
|
||||
|
||||
* ToolbarDefaults.C (read):
|
||||
|
@ -90,6 +90,7 @@ PainterBase & PainterBase::buttonFrame(int x, int y, int w, int h)
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
PainterBase & PainterBase::rectText(int x, int baseline,
|
||||
string const & str,
|
||||
LyXFont const & font,
|
||||
@ -97,17 +98,24 @@ PainterBase & PainterBase::rectText(int x, int baseline,
|
||||
LColor::color frame, bool draw,
|
||||
int & width, int & ascent, int & descent)
|
||||
{
|
||||
#if 0
|
||||
static int const d = 2;
|
||||
width = lyxfont::width(str, font) + d * 2 + 2;
|
||||
ascent = lyxfont::maxAscent(font) + d;
|
||||
descent = lyxfont::maxDescent(font) + d;
|
||||
|
||||
#else
|
||||
lyxfont::rectText(str, font, width, axcent, descent);
|
||||
#endif
|
||||
if (!draw) return *this;
|
||||
|
||||
rectangle(x, baseline - ascent, width, ascent + descent, frame);
|
||||
fillRectangle(x + 1, baseline - ascent + 1, width - 1,
|
||||
ascent + descent - 1, back);
|
||||
#if 0
|
||||
text(x + d, baseline, str, font);
|
||||
#else
|
||||
text(x + 2, baseline, str, font);
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -117,13 +125,50 @@ PainterBase & PainterBase::buttonText(int x, int baseline,
|
||||
LyXFont const & font, bool draw,
|
||||
int & width, int & ascent, int & descent)
|
||||
{
|
||||
#if 0
|
||||
width = lyxfont::width(str, font) + 8;
|
||||
ascent = lyxfont::maxAscent(font) + 3;
|
||||
descent = lyxfont::maxDescent(font) + 3;
|
||||
|
||||
#else
|
||||
lyxfont::buttonText(str, font, width, ascent, descent);
|
||||
#endif
|
||||
if (!draw) return *this;
|
||||
|
||||
button(x, baseline - ascent, width, descent + ascent);
|
||||
text(x + 4, baseline, str, font);
|
||||
return *this;
|
||||
}
|
||||
#else
|
||||
PainterBase & PainterBase::rectText(int x, int baseline,
|
||||
string const & str,
|
||||
LyXFont const & font,
|
||||
LColor::color back,
|
||||
LColor::color frame)
|
||||
{
|
||||
int width;
|
||||
int ascent;
|
||||
int descent;
|
||||
|
||||
lyxfont::rectText(str, font, width, ascent, descent);
|
||||
rectangle(x, baseline - ascent, width, ascent + descent, frame);
|
||||
fillRectangle(x + 1, baseline - ascent + 1, width - 1,
|
||||
ascent + descent - 1, back);
|
||||
text(x + 2, baseline, str, font);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PainterBase & PainterBase::buttonText(int x, int baseline,
|
||||
string const & str,
|
||||
LyXFont const & font)
|
||||
{
|
||||
int width;
|
||||
int ascent;
|
||||
int descent;
|
||||
|
||||
lyxfont::buttonText(str, font, width, ascent, descent);
|
||||
button(x, baseline - ascent, width, descent + ascent);
|
||||
text(x + 4, baseline, str, font);
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
@ -161,7 +161,8 @@ public:
|
||||
|
||||
/// Draw a char at position x, y (y is the baseline)
|
||||
virtual PainterBase & text(int x, int y, char c, LyXFont const & f)=0;
|
||||
|
||||
|
||||
#if 0
|
||||
/** Draws a string and encloses it inside a rectangle. Returns
|
||||
the size of the rectangle. If draw is false, we only calculate
|
||||
the size. */
|
||||
@ -182,6 +183,22 @@ public:
|
||||
int & width = PainterBase::dummy1,
|
||||
int & ascent = PainterBase::dummy2,
|
||||
int & descent = PainterBase::dummy3);
|
||||
#else
|
||||
/** Draws a string and encloses it inside a rectangle. Returns
|
||||
the size of the rectangle. If draw is false, we only calculate
|
||||
the size. */
|
||||
PainterBase & rectText(int x, int baseline,
|
||||
string const & string,
|
||||
LyXFont const & font,
|
||||
LColor::color back,
|
||||
LColor::color frame);
|
||||
|
||||
/** Draw a string and encloses it inside a button frame. Returns
|
||||
the size of the frame. If draw is false, we only calculate
|
||||
the size. */
|
||||
PainterBase & buttonText(int x, int baseline, string const & s,
|
||||
LyXFont const & font);
|
||||
#endif
|
||||
protected:
|
||||
///
|
||||
WorkArea & owner;
|
||||
|
23
src/font.C
23
src/font.C
@ -186,7 +186,7 @@ int lyxfont::width(XChar2b const * s, int n, LyXFont const & f)
|
||||
result += ::XTextWidth16(getXFontstruct(smallfont), &c, 1);
|
||||
} else {
|
||||
result += ::XTextWidth16(getXFontstruct(f), &s[i], 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -209,5 +209,26 @@ void lyxfont::XSetFont(Display * display, GC gc, LyXFont const & f)
|
||||
::XSetFont(display, gc, getFontID(f));
|
||||
}
|
||||
|
||||
|
||||
void lyxfont::rectText(string const & str, LyXFont const & font,
|
||||
int & width, int & ascent, int & descent)
|
||||
{
|
||||
static int const d = 2;
|
||||
width = lyxfont::width(str, font) + d * 2 + 2;
|
||||
ascent = lyxfont::maxAscent(font) + d;
|
||||
descent = lyxfont::maxDescent(font) + d;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void lyxfont::buttonText(string const & str, LyXFont const & font,
|
||||
int & width, int & ascent, int & descent)
|
||||
{
|
||||
width = lyxfont::width(str, font) + 8;
|
||||
ascent = lyxfont::maxAscent(font) + 3;
|
||||
descent = lyxfont::maxDescent(font) + 3;
|
||||
}
|
||||
|
||||
|
||||
//} // end of namespace font
|
||||
//} // end of namespace lyx
|
||||
|
@ -78,6 +78,15 @@ struct lyxfont {
|
||||
///
|
||||
static
|
||||
void XSetFont(Display * display, GC gc, LyXFont const & f);
|
||||
// A couple of more high-level metrics
|
||||
///
|
||||
static
|
||||
void rectText(string const & str, LyXFont const & font,
|
||||
int & width, int & ascent, int & descent);
|
||||
///
|
||||
static
|
||||
void buttonText(string const & str, LyXFont const & font,
|
||||
int & width, int & ascent, int & descent);
|
||||
};
|
||||
|
||||
//} // end of namespace font
|
||||
|
@ -1,3 +1,9 @@
|
||||
2001-07-24 Lars Gullik Bjønnes <larsbj@birdstep.com>
|
||||
|
||||
* insetcollapsable.C: adjust
|
||||
|
||||
* insetbutton.C: adjust
|
||||
|
||||
2001-07-23 Juergen Vigna <jug@sad.it>
|
||||
|
||||
* insetcollapsable.h: removed widthCollapsed variable, LyXFont
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "Painter.h"
|
||||
#include "support/LAssert.h"
|
||||
#include "lyxfont.h"
|
||||
#include "font.h"
|
||||
|
||||
using std::ostream;
|
||||
using std::endl;
|
||||
@ -36,7 +37,8 @@ int InsetButton::ascent(BufferView * bv, LyXFont const &) const
|
||||
int ascent;
|
||||
int descent;
|
||||
string const s = getScreenLabel();
|
||||
|
||||
|
||||
#if 0
|
||||
if (editable()) {
|
||||
bv->painter().buttonText(0, 0, s, font,
|
||||
false, width, ascent, descent);
|
||||
@ -45,6 +47,13 @@ int InsetButton::ascent(BufferView * bv, LyXFont const &) const
|
||||
LColor::commandbg, LColor::commandframe,
|
||||
false, width, ascent, descent);
|
||||
}
|
||||
#else
|
||||
if (editable()) {
|
||||
lyxfont::buttonText(s, font, width, ascent, descent);
|
||||
} else {
|
||||
lyxfont::rectText(s, font, width, ascent, descent);
|
||||
}
|
||||
#endif
|
||||
return ascent;
|
||||
}
|
||||
|
||||
@ -60,7 +69,8 @@ int InsetButton::descent(BufferView * bv, LyXFont const &) const
|
||||
int ascent;
|
||||
int descent;
|
||||
string const s = getScreenLabel();
|
||||
|
||||
|
||||
#if 0
|
||||
if (editable()) {
|
||||
bv->painter().buttonText(0, 0, s, font,
|
||||
false, width, ascent, descent);
|
||||
@ -69,6 +79,13 @@ int InsetButton::descent(BufferView * bv, LyXFont const &) const
|
||||
LColor::commandbg, LColor::commandframe,
|
||||
false, width, ascent, descent);
|
||||
}
|
||||
#else
|
||||
if (editable()) {
|
||||
lyxfont::buttonText(s, font, width, ascent, descent);
|
||||
} else {
|
||||
lyxfont::rectText(s, font, width, ascent, descent);
|
||||
}
|
||||
#endif
|
||||
return descent;
|
||||
}
|
||||
|
||||
@ -84,7 +101,8 @@ int InsetButton::width(BufferView * bv, LyXFont const &) const
|
||||
int ascent;
|
||||
int descent;
|
||||
string const s = getScreenLabel();
|
||||
|
||||
|
||||
#if 0
|
||||
if (editable()) {
|
||||
bv->painter().buttonText(0, 0, s, font,
|
||||
false, width, ascent, descent);
|
||||
@ -93,6 +111,13 @@ int InsetButton::width(BufferView * bv, LyXFont const &) const
|
||||
LColor::commandbg, LColor::commandframe,
|
||||
false, width, ascent, descent);
|
||||
}
|
||||
#else
|
||||
if (editable()) {
|
||||
lyxfont::buttonText(s, font, width, ascent, descent);
|
||||
} else {
|
||||
lyxfont::rectText(s, font, width, ascent, descent);
|
||||
}
|
||||
#endif
|
||||
return width + 4;
|
||||
}
|
||||
|
||||
@ -107,9 +132,10 @@ void InsetButton::draw(BufferView * bv, LyXFont const &,
|
||||
LyXFont font(LyXFont::ALL_SANE);
|
||||
font.setColor(LColor::command).decSize();
|
||||
|
||||
int width;
|
||||
string const s = getScreenLabel();
|
||||
|
||||
#if 0
|
||||
int width;
|
||||
if (editable()) {
|
||||
pain.buttonText(int(x) + 2, baseline, s, font, true, width);
|
||||
} else {
|
||||
@ -117,6 +143,18 @@ void InsetButton::draw(BufferView * bv, LyXFont const &,
|
||||
LColor::commandbg, LColor::commandframe,
|
||||
true, width);
|
||||
}
|
||||
#else
|
||||
if (editable()) {
|
||||
pain.buttonText(int(x) + 2, baseline, s, font);
|
||||
} else {
|
||||
pain.rectText(int(x) + 2, baseline, s, font,
|
||||
LColor::commandbg, LColor::commandframe);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
x += width + 4;
|
||||
#else
|
||||
x += width(bv, font);
|
||||
#endif
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "support/lstrings.h"
|
||||
#include "debug.h"
|
||||
#include "lyxtext.h"
|
||||
#include "font.h"
|
||||
|
||||
class LyXText;
|
||||
|
||||
@ -90,35 +91,50 @@ void InsetCollapsable::read(Buffer const * buf, LyXLex & lex)
|
||||
}
|
||||
|
||||
|
||||
int InsetCollapsable::ascent_collapsed(Painter & pain) const
|
||||
//int InsetCollapsable::ascent_collapsed(Painter & pain) const
|
||||
int InsetCollapsable::ascent_collapsed(Painter & /*pain*/) const
|
||||
{
|
||||
int width = 0;
|
||||
int ascent = 0;
|
||||
int descent = 0;
|
||||
#if 0
|
||||
pain.buttonText(0, 0, draw_label, labelfont, false,
|
||||
width, ascent, descent);
|
||||
#else
|
||||
lyxfont::buttonText(draw_label, labelfont, width, ascent, descent);
|
||||
#endif
|
||||
return ascent;
|
||||
}
|
||||
|
||||
|
||||
int InsetCollapsable::descent_collapsed(Painter & pain) const
|
||||
//int InsetCollapsable::descent_collapsed(Painter & pain) const
|
||||
int InsetCollapsable::descent_collapsed(Painter & /*pain*/) const
|
||||
{
|
||||
int width = 0;
|
||||
int ascent = 0;
|
||||
int descent = 0;
|
||||
#if 0
|
||||
pain.buttonText(0, 0, draw_label, labelfont, false,
|
||||
width, ascent, descent);
|
||||
#else
|
||||
lyxfont::buttonText(draw_label, labelfont, width, ascent, descent);
|
||||
#endif
|
||||
return descent;
|
||||
}
|
||||
|
||||
|
||||
int InsetCollapsable::width_collapsed(Painter & pain) const
|
||||
//int InsetCollapsable::width_collapsed(Painter & pain) const
|
||||
int InsetCollapsable::width_collapsed(Painter & /*pain*/) const
|
||||
{
|
||||
int width;
|
||||
int ascent;
|
||||
int descent;
|
||||
#if 0
|
||||
pain.buttonText(TEXT_TO_INSET_OFFSET, 0, draw_label, labelfont, false,
|
||||
width, ascent, descent);
|
||||
#else
|
||||
lyxfont::buttonText(draw_label, labelfont, width, ascent, descent);
|
||||
#endif
|
||||
return width + (2*TEXT_TO_INSET_OFFSET);
|
||||
}
|
||||
|
||||
@ -155,10 +171,19 @@ int InsetCollapsable::width(BufferView * bv, LyXFont const & font) const
|
||||
|
||||
void InsetCollapsable::draw_collapsed(Painter & pain, int baseline, float & x) const
|
||||
{
|
||||
#if 0
|
||||
int width = 0;
|
||||
pain.buttonText(int(x) + TEXT_TO_INSET_OFFSET,
|
||||
baseline, draw_label, labelfont, true, width);
|
||||
#else
|
||||
pain.buttonText(int(x) + TEXT_TO_INSET_OFFSET,
|
||||
baseline, draw_label, labelfont);
|
||||
#endif
|
||||
#if 0
|
||||
x += width + TEXT_TO_INSET_OFFSET;
|
||||
#else
|
||||
x += width_collapsed(pain) + TEXT_TO_INSET_OFFSET;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
13
src/text.C
13
src/text.C
@ -37,6 +37,7 @@
|
||||
#include "language.h"
|
||||
#include "ParagraphParameters.h"
|
||||
#include "undo_funcs.h"
|
||||
#include "font.h"
|
||||
|
||||
using std::max;
|
||||
using std::min;
|
||||
@ -3152,12 +3153,18 @@ void LyXText::getVisibleRow(BufferView * bview, int y_offset, int x_offset,
|
||||
y_offset + y_top + 2 * defaultHeight(),
|
||||
LColor::pagebreak,
|
||||
Painter::line_onoffdash)
|
||||
#if 0
|
||||
.rectText(0,
|
||||
0,
|
||||
_("Page Break (top)"),
|
||||
pb_font,
|
||||
LColor::background,
|
||||
LColor::background, false, w, a, d);
|
||||
#else
|
||||
;
|
||||
lyxfont::rectText(_("Page Break (top)"), pb_font,
|
||||
w, a, d);
|
||||
#endif
|
||||
pain.rectText((ww - w)/2,
|
||||
y_offset + y_top + 2 * defaultHeight() + d,
|
||||
_("Page Break (top)"),
|
||||
@ -3343,11 +3350,17 @@ void LyXText::getVisibleRow(BufferView * bview, int y_offset, int x_offset,
|
||||
.line(0, y_place, ww, y_place,
|
||||
LColor::pagebreak,
|
||||
Painter::line_onoffdash)
|
||||
#if 0
|
||||
.rectText(0, 0,
|
||||
_("Page Break (bottom)"),
|
||||
pb_font,
|
||||
LColor::background,
|
||||
LColor::background, false, w, a, d);
|
||||
#else
|
||||
;
|
||||
lyxfont::rectText(_("Page Break (bottom)"), pb_font,
|
||||
w, a, d);
|
||||
#endif
|
||||
pain.rectText((ww - w) / 2, y_place + d,
|
||||
_("Page Break (bottom)"),
|
||||
pb_font,
|
||||
|
Loading…
Reference in New Issue
Block a user