From c7e365365e74237149c960b9ecaa77bc7c93e608 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Sun, 15 Oct 2006 21:47:29 +0000 Subject: [PATCH] This commit saves the need to check for lyx::use_gui in a number of places. * lyx_main.h: define "extern bool lyx::use_gui" here. * NoGuiFontMetrics.h: new class for command-line LyX * NoGuiFontLoader.h: new class for command-line LyX * Application.C: - theFontMetrics(): returns the above dummy FontMetrics when use_gui is false. - theFontLoader(): returns the above dummy FontLoader when use_gui is false. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15339 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/scons/scons_manifest.py | 4 +- src/frontends/Alert.C | 3 +- src/frontends/Application.C | 13 ++++++ src/frontends/Makefile.am | 2 + src/frontends/NoGuiFontLoader.h | 48 +++++++++++++++++++++ src/frontends/NoGuiFontMetrics.h | 66 +++++++++++++++++++++++++++++ src/frontends/gtk/xftFontLoader.C | 7 --- src/frontends/qt3/GuiFontMetrics.C | 22 ---------- src/frontends/qt3/qfont_loader.C | 7 --- src/frontends/qt4/GuiFontLoader.C | 6 --- src/frontends/qt4/GuiFontMetrics.C | 22 ---------- src/insets/insetexternal.C | 3 -- src/insets/insetgraphicsParams.C | 5 +-- src/lyx_cb.C | 4 -- src/lyx_main.h | 2 +- src/lyxfunc.C | 3 -- src/mathed/MathFactory.C | 6 --- 17 files changed, 135 insertions(+), 88 deletions(-) create mode 100644 src/frontends/NoGuiFontLoader.h create mode 100644 src/frontends/NoGuiFontMetrics.h diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index 2106610203..01692de31e 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -431,7 +431,9 @@ src_frontends_header_files = Split(''' Alert.h Alert_pimpl.h Application.h - Clipboard.h + Clipboard.h + NoGuiFontLoader.h + NoGuiFontMetrics.h Dialogs.h FileDialog.h FontLoader.h diff --git a/src/frontends/Alert.C b/src/frontends/Alert.C index 1f482ddf8d..0bb83d181a 100644 --- a/src/frontends/Alert.C +++ b/src/frontends/Alert.C @@ -14,6 +14,7 @@ #include "Alert_pimpl.h" #include "debug.h" +#include "lyx_main.h" // for lyx::use_gui using lyx::docstring; @@ -25,8 +26,6 @@ using std::string; namespace lyx { -extern bool use_gui; - namespace frontend { int Alert::prompt(docstring const & title, docstring const & question, diff --git a/src/frontends/Application.C b/src/frontends/Application.C index 852dcdb5b1..741099670b 100644 --- a/src/frontends/Application.C +++ b/src/frontends/Application.C @@ -12,6 +12,8 @@ #include "frontends/Application.h" +#include "frontends/NoGuiFontLoader.h" +#include "frontends/NoGuiFontMetrics.h" #include "frontends/FontLoader.h" #include "frontends/FontMetrics.h" #include "frontends/Gui.h" @@ -21,6 +23,7 @@ #include "bufferlist.h" #include "funcrequest.h" #include "FuncStatus.h" +#include "lyx_main.h" #include "LyXAction.h" #include "lyxfont.h" #include "lyxfunc.h" @@ -167,6 +170,11 @@ LyXFunc & theLyXFunc() lyx::frontend::FontLoader & theFontLoader() { + static lyx::frontend::NoGuiFontLoader no_gui_font_loader; + + if (!lyx::use_gui) + return no_gui_font_loader; + BOOST_ASSERT(theApp); return theApp->fontLoader(); } @@ -174,6 +182,11 @@ lyx::frontend::FontLoader & theFontLoader() lyx::frontend::FontMetrics const & theFontMetrics(LyXFont const & f) { + static lyx::frontend::NoGuiFontMetrics no_gui_font_metrics; + + if (!lyx::use_gui) + return no_gui_font_metrics; + BOOST_ASSERT(theApp); return theApp->fontLoader().metrics(f); } diff --git a/src/frontends/Makefile.am b/src/frontends/Makefile.am index c07ad1c533..0455b2264f 100644 --- a/src/frontends/Makefile.am +++ b/src/frontends/Makefile.am @@ -18,6 +18,8 @@ libfrontends_la_SOURCES = \ Alert_pimpl.h \ Application.C \ Application.h \ + NoGuiFontLoader.h \ + NoGuiFontMetrics.h \ Dialogs.C \ Dialogs.h \ FileDialog.h \ diff --git a/src/frontends/NoGuiFontLoader.h b/src/frontends/NoGuiFontLoader.h new file mode 100644 index 0000000000..15b9522a0d --- /dev/null +++ b/src/frontends/NoGuiFontLoader.h @@ -0,0 +1,48 @@ +// -*- C++ -*- +/** + * \file NoGuiFontLoader.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Abdelrazak Younes + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef LYX_NO_GUI_FONTLOADER_H +#define LYX_NO_GUI_FONTLOADER_H + +#include "frontends/FontLoader.h" + +#include "frontends/NoGuiFontMetrics.h" + +namespace lyx { +namespace frontend { + +/// Dummy FontLoader for command-line output. +class NoGuiFontLoader: public FontLoader +{ +public: + /// + NoGuiFontLoader() {} + /// + virtual ~NoGuiFontLoader() {} + + /// Update fonts after zoom, dpi, font names, or norm change + virtual void update() {}; + + /// Is the given font available ? + virtual bool available(LyXFont const & f) { return false; }; + + /// Get the Font metrics for this LyXFont + virtual FontMetrics const & metrics(LyXFont const & f) { return metrics_; } + +private: + /// + NoGuiFontMetrics metrics_; +}; + +} // namespace frontend +} // namespace lyx + +#endif // LYX_NO_GUI_FONTLOADER_H diff --git a/src/frontends/NoGuiFontMetrics.h b/src/frontends/NoGuiFontMetrics.h new file mode 100644 index 0000000000..fe618a7e30 --- /dev/null +++ b/src/frontends/NoGuiFontMetrics.h @@ -0,0 +1,66 @@ +// -*- C++ -*- +/** + * \file NoGuiFontMetrics.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Abdelrazak Younes + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef LYX_NO_GUI_FONT_METRICS_H +#define LYX_NO_GUI_FONT_METRICS_H + +#include "frontends/FontMetrics.h" + +#include "support/docstring.h" + +namespace lyx { +namespace frontend { + +class NoGuiFontMetrics: public FontMetrics +{ +public: + + NoGuiFontMetrics() {} + + virtual ~NoGuiFontMetrics() {} + + virtual int maxAscent() const { return 1; } + + virtual int maxDescent() const { return 1; } + + virtual int ascent(lyx::char_type c) const { return 1; } + + int descent(lyx::char_type c) const { return 1; } + + virtual int lbearing(lyx::char_type c) const { return 1; } + + virtual int rbearing(lyx::char_type c) const { return 1; } + + virtual int width(lyx::char_type const * s, size_t n) const { return n; } + + virtual int signedWidth(lyx::docstring const & s) const + { + if (s[0] == '-') + return -FontMetrics::width(s.substr(1, s.length() - 1)); + else + return FontMetrics::width(s); + } + + virtual void rectText(lyx::docstring const & str, + int & width, + int & ascent, + int & descent) const {}; + + virtual void buttonText(lyx::docstring const & str, + int & width, + int & ascent, + int & descent) const {}; +}; + +} // namespace frontend +} // namespace lyx + +#endif // LYX_NO_GUI_FONT_METRICS_H diff --git a/src/frontends/gtk/xftFontLoader.C b/src/frontends/gtk/xftFontLoader.C index ec86a0c8a0..582c77e2c8 100644 --- a/src/frontends/gtk/xftFontLoader.C +++ b/src/frontends/gtk/xftFontLoader.C @@ -38,10 +38,6 @@ using std::endl; using std::string; -namespace lyx { -extern bool use_gui; -} - // The global fontLoader xftFontLoader fontLoader; @@ -192,9 +188,6 @@ XftFont * xftFontLoader::doLoad(LyXFont::FONT_FAMILY family, bool xftFontLoader::available(LyXFont const & f) { - if (!lyx::use_gui) - return false; - static std::vector cache_set(LyXFont::NUM_FAMILIES, false); static std::vector cache(LyXFont::NUM_FAMILIES, false); diff --git a/src/frontends/qt3/GuiFontMetrics.C b/src/frontends/qt3/GuiFontMetrics.C index 166ff65e5b..9d05c3415a 100644 --- a/src/frontends/qt3/GuiFontMetrics.C +++ b/src/frontends/qt3/GuiFontMetrics.C @@ -26,9 +26,6 @@ using std::string; namespace lyx { - -extern bool use_gui; - namespace frontend { @@ -46,16 +43,12 @@ GuiFontMetrics::GuiFontMetrics(QFont const & font, QFont const & smallcaps_font) int GuiFontMetrics::maxAscent() const { - if (!lyx::use_gui) - return 1; return metrics_.ascent(); } int GuiFontMetrics::maxDescent() const { - if (!lyx::use_gui) - return 1; // We add 1 as the value returned by QT is different than X // See http://doc.trolltech.com/2.3/qfontmetrics.html#200b74 return metrics_.descent() + 1; @@ -64,8 +57,6 @@ int GuiFontMetrics::maxDescent() const int GuiFontMetrics::ascent(char_type c) const { - if (!lyx::use_gui) - return 1; QRect const & r = metrics_.boundingRect(ucs4_to_qchar(c)); // Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y // value by the height: (x, -y-height, width, height). @@ -80,8 +71,6 @@ int GuiFontMetrics::ascent(char_type c) const int GuiFontMetrics::descent(char_type c) const { - if (!lyx::use_gui) - return 1; QRect const & r = metrics_.boundingRect(ucs4_to_qchar(c)); // Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y // value by the height: (x, -y-height, width, height). @@ -96,17 +85,12 @@ int GuiFontMetrics::descent(char_type c) const int GuiFontMetrics::lbearing(char_type c) const { - if (!lyx::use_gui) - return 1; return metrics_.leftBearing(ucs4_to_qchar(c)); } int GuiFontMetrics::rbearing(char_type c) const { - if (!lyx::use_gui) - return 1; - // Qt rbearing is from the right edge of the char's width(). QChar sc = ucs4_to_qchar(c); return metrics_.width(sc) - metrics_.rightBearing(sc); @@ -115,9 +99,6 @@ int GuiFontMetrics::rbearing(char_type c) const int GuiFontMetrics::smallcapsWidth(QString const & s) const { - if (!lyx::use_gui) - return 1; - int w = 0; int const ls = s.length(); @@ -135,9 +116,6 @@ int GuiFontMetrics::smallcapsWidth(QString const & s) const int GuiFontMetrics::width(char_type const * s, size_t ls) const { - if (!lyx::use_gui) - return ls; - QString const ucs2 = toqstr(s, ls); if (smallcaps_shape_) diff --git a/src/frontends/qt3/qfont_loader.C b/src/frontends/qt3/qfont_loader.C index 8ed07531eb..d3b42217dd 100644 --- a/src/frontends/qt3/qfont_loader.C +++ b/src/frontends/qt3/qfont_loader.C @@ -44,10 +44,6 @@ using std::pair; using std::vector; using std::string; -namespace lyx { -extern bool use_gui; -} - GuiFontLoader::~GuiFontLoader() { } @@ -292,9 +288,6 @@ QLFontInfo::QLFontInfo(LyXFont const & f) bool GuiFontLoader::available(LyXFont const & f) { - if (!lyx::use_gui) - return false; - static vector cache_set(LyXFont::NUM_FAMILIES, false); static vector cache(LyXFont::NUM_FAMILIES, false); diff --git a/src/frontends/qt4/GuiFontLoader.C b/src/frontends/qt4/GuiFontLoader.C index 7b46412539..cc05789aeb 100644 --- a/src/frontends/qt4/GuiFontLoader.C +++ b/src/frontends/qt4/GuiFontLoader.C @@ -43,9 +43,6 @@ using std::string; namespace lyx { - -extern bool use_gui; - namespace frontend { GuiFontLoader::~GuiFontLoader() { @@ -304,9 +301,6 @@ QLFontInfo::QLFontInfo(LyXFont const & f) bool GuiFontLoader::available(LyXFont const & f) { - if (!lyx::use_gui) - return false; - static vector cache_set(LyXFont::NUM_FAMILIES, false); static vector cache(LyXFont::NUM_FAMILIES, false); diff --git a/src/frontends/qt4/GuiFontMetrics.C b/src/frontends/qt4/GuiFontMetrics.C index a898e6ae3c..f2aca33e49 100644 --- a/src/frontends/qt4/GuiFontMetrics.C +++ b/src/frontends/qt4/GuiFontMetrics.C @@ -25,9 +25,6 @@ using lyx::docstring; using std::string; namespace lyx { - -extern bool use_gui; - namespace frontend { @@ -45,16 +42,12 @@ GuiFontMetrics::GuiFontMetrics(QFont const & font, QFont const & smallcaps_font) int GuiFontMetrics::maxAscent() const { - if (!lyx::use_gui) - return 1; return metrics_.ascent(); } int GuiFontMetrics::maxDescent() const { - if (!lyx::use_gui) - return 1; // We add 1 as the value returned by QT is different than X // See http://doc.trolltech.com/2.3/qfontmetrics.html#200b74 return metrics_.descent() + 1; @@ -63,8 +56,6 @@ int GuiFontMetrics::maxDescent() const int GuiFontMetrics::ascent(char_type c) const { - if (!lyx::use_gui) - return 1; QRect const & r = metrics_.boundingRect(ucs4_to_qchar(c)); // Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y // value by the height: (x, -y-height, width, height). @@ -79,8 +70,6 @@ int GuiFontMetrics::ascent(char_type c) const int GuiFontMetrics::descent(char_type c) const { - if (!lyx::use_gui) - return 1; QRect const & r = metrics_.boundingRect(ucs4_to_qchar(c)); // Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y // value by the height: (x, -y-height, width, height). @@ -95,17 +84,12 @@ int GuiFontMetrics::descent(char_type c) const int GuiFontMetrics::lbearing(char_type c) const { - if (!lyx::use_gui) - return 1; return metrics_.leftBearing(ucs4_to_qchar(c)); } int GuiFontMetrics::rbearing(char_type c) const { - if (!lyx::use_gui) - return 1; - // Qt rbearing is from the right edge of the char's width(). QChar sc = ucs4_to_qchar(c); return metrics_.width(sc) - metrics_.rightBearing(sc); @@ -114,9 +98,6 @@ int GuiFontMetrics::rbearing(char_type c) const int GuiFontMetrics::smallcapsWidth(QString const & s) const { - if (!lyx::use_gui) - return 1; - int w = 0; int const ls = s.size(); @@ -134,9 +115,6 @@ int GuiFontMetrics::smallcapsWidth(QString const & s) const int GuiFontMetrics::width(char_type const * s, size_t ls) const { - if (!lyx::use_gui) - return ls; - QString ucs2; ucs4_to_qstring(s, ls, ucs2); diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index ce2e6fff8f..586b46cfd8 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -57,9 +57,6 @@ using std::ostream; using std::ostringstream; using std::vector; -namespace lyx { -extern bool use_gui; -} namespace { diff --git a/src/insets/insetgraphicsParams.C b/src/insets/insetgraphicsParams.C index 875b332223..802531f059 100644 --- a/src/insets/insetgraphicsParams.C +++ b/src/insets/insetgraphicsParams.C @@ -14,6 +14,7 @@ #include "insetgraphicsParams.h" #include "debug.h" +#include "lyx_main.h" // for lyx::use_gui #include "lyxlex.h" #include "lyxrc.h" @@ -33,10 +34,6 @@ using std::string; using std::ostream; -namespace lyx { -extern bool use_gui; -} - InsetGraphicsParams::InsetGraphicsParams() { init(); diff --git a/src/lyx_cb.C b/src/lyx_cb.C index f1226535dd..d849b4b380 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -93,10 +93,6 @@ using std::istream_iterator; // this should be static, but I need it in buffer.C bool quitting; // flag, that we are quitting the program -namespace lyx { -extern bool use_gui; -} - // // Menu callbacks // diff --git a/src/lyx_main.h b/src/lyx_main.h index 8f51d818b2..7ea348c441 100644 --- a/src/lyx_main.h +++ b/src/lyx_main.h @@ -29,13 +29,13 @@ class LyXView; class kb_keymap; namespace lyx { +extern bool use_gui; class Session; namespace frontend { class Application; } } - /// initial startup class LyX : boost::noncopyable { public: diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 5e09adac34..6207884bb8 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -146,9 +146,6 @@ extern boost::scoped_ptr toplevel_keymap; // (alkis) extern tex_accent_struct get_accent(kb_action action); -namespace lyx { -extern bool use_gui; -} namespace { diff --git a/src/mathed/MathFactory.C b/src/mathed/MathFactory.C index 85cf61c0c8..6bc40bbea9 100644 --- a/src/mathed/MathFactory.C +++ b/src/mathed/MathFactory.C @@ -74,9 +74,6 @@ using std::istringstream; bool has_math_fonts; -namespace lyx { -extern bool use_gui; -} namespace { @@ -87,9 +84,6 @@ WordList theWordList; bool math_font_available(string & name) { - if (!lyx::use_gui) - return false; - LyXFont f; augmentFont(f, name); -- 2.39.2