diff --git a/po/POTFILES.in b/po/POTFILES.in index 1542be87a7..2edfc3058c 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -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 diff --git a/src/ChangeLog b/src/ChangeLog index 9a0aa0fb80..12b51084e6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2001-07-24 Lars Gullik Bjønnes + + * 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 * ToolbarDefaults.C (read): diff --git a/src/PainterBase.C b/src/PainterBase.C index cd29b781aa..f29ef37a2b 100644 --- a/src/PainterBase.C +++ b/src/PainterBase.C @@ -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 diff --git a/src/PainterBase.h b/src/PainterBase.h index df650cd78b..71a39f987f 100644 --- a/src/PainterBase.h +++ b/src/PainterBase.h @@ -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; diff --git a/src/font.C b/src/font.C index 65e2b42766..210d10bd60 100644 --- a/src/font.C +++ b/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 diff --git a/src/font.h b/src/font.h index 7e286e48f1..51d50e93d6 100644 --- a/src/font.h +++ b/src/font.h @@ -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 diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 451e07d328..3ea458ea18 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,9 @@ +2001-07-24 Lars Gullik Bjønnes + + * insetcollapsable.C: adjust + + * insetbutton.C: adjust + 2001-07-23 Juergen Vigna * insetcollapsable.h: removed widthCollapsed variable, LyXFont diff --git a/src/insets/insetbutton.C b/src/insets/insetbutton.C index 8b0d3d6d5f..617b2bf820 100644 --- a/src/insets/insetbutton.C +++ b/src/insets/insetbutton.C @@ -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 } diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 596a8cb39f..a5149e020f 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -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 } diff --git a/src/text.C b/src/text.C index 01349da75c..8d49945013 100644 --- a/src/text.C +++ b/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,