]> git.lyx.org Git - lyx.git/commitdiff
This commit saves the need to check for lyx::use_gui in a number of places.
authorAbdelrazak Younes <younes@lyx.org>
Sun, 15 Oct 2006 21:47:29 +0000 (21:47 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sun, 15 Oct 2006 21:47:29 +0000 (21:47 +0000)
* 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

17 files changed:
development/scons/scons_manifest.py
src/frontends/Alert.C
src/frontends/Application.C
src/frontends/Makefile.am
src/frontends/NoGuiFontLoader.h [new file with mode: 0644]
src/frontends/NoGuiFontMetrics.h [new file with mode: 0644]
src/frontends/gtk/xftFontLoader.C
src/frontends/qt3/GuiFontMetrics.C
src/frontends/qt3/qfont_loader.C
src/frontends/qt4/GuiFontLoader.C
src/frontends/qt4/GuiFontMetrics.C
src/insets/insetexternal.C
src/insets/insetgraphicsParams.C
src/lyx_cb.C
src/lyx_main.h
src/lyxfunc.C
src/mathed/MathFactory.C

index 21066102039a6ac19837b18d58c097e32ebc81c6..01692de31e50db8d1e58f2109573d7f403779fa4 100644 (file)
@@ -431,7 +431,9 @@ src_frontends_header_files = Split('''
     Alert.h
     Alert_pimpl.h
     Application.h
-    Clipboard.h
+    Clipboard.h\r
+    NoGuiFontLoader.h\r
+    NoGuiFontMetrics.h\r
     Dialogs.h
     FileDialog.h
     FontLoader.h
index 1f482ddf8dc828b2e454c20cc3579ab15f9b97b0..0bb83d181af560a00d488e5a3c426cb3794d2491 100644 (file)
@@ -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,
index 852dcdb5b1d29ec97ec09a9e41a63eb54e8586d8..741099670b38a284884e315cceacbc43f05cd395 100644 (file)
@@ -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);
 }
index c07ad1c533a2cc0e1074fcc4199762f1aae21592..0455b2264f758154cfb40cc6f754fe2b3c022386 100644 (file)
@@ -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 (file)
index 0000000..15b9522
--- /dev/null
@@ -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 (file)
index 0000000..fe618a7
--- /dev/null
@@ -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
index ec86a0c8a08aaa9078961ceed455cbe29118e838..582c77e2c875944b94d1e6be82e14a6a9ee92181 100644 (file)
 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<bool> cache_set(LyXFont::NUM_FAMILIES, false);
        static std::vector<bool> cache(LyXFont::NUM_FAMILIES, false);
 
index 166ff65e5bd6f0aecd2a99a7112f9b738820b5f1..9d05c3415ab5e5e17d216580ef2c13f41a1777ab 100644 (file)
@@ -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_)
index 8ed07531eb8156391d9ec3626e02e2ec62d78e5c..d3b42217dd94f94d5eaa378864bd67241c18afe9 100644 (file)
@@ -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<int> cache_set(LyXFont::NUM_FAMILIES, false);
        static vector<int> cache(LyXFont::NUM_FAMILIES, false);
 
index 7b464125399e8f60b7aa0b3244245b4fa240728b..cc05789aeb91021368ac9060f637dc887d39c33d 100644 (file)
@@ -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<int> cache_set(LyXFont::NUM_FAMILIES, false);
        static vector<int> cache(LyXFont::NUM_FAMILIES, false);
 
index a898e6ae3cd36908c7d9596c5426647b05b394aa..f2aca33e49e706aeaf7d2be4434dc987d0b1c7cd 100644 (file)
@@ -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);
 
index ce2e6fff8faa8632d5ff1fa9cbb74ddc4a0279b5..586b46cfd894339886d6ee9f76adb35fb328d29f 100644 (file)
@@ -57,9 +57,6 @@ using std::ostream;
 using std::ostringstream;
 using std::vector;
 
-namespace lyx {
-extern bool use_gui;
-}
 
 namespace {
 
index 875b332223e37ec35126b36b2029058bd7bfc16e..802531f059bc799f76046b015c2cb0e2db8060c5 100644 (file)
@@ -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();
index f1226535ddb754976aecd9374221f441a8520e00..d849b4b380746a9700d1b02e786501807e1e63bf 100644 (file)
@@ -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
 //
index 8f51d818b2d645bdbc38539a460d16e4dfd0f316..7ea348c4417e315dfb7f3beb21a6df33efbe25b0 100644 (file)
@@ -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:
index 5e09adac344417d7c0f8f6b2643f18cf71ac3362..6207884bb8a30348c1266d4d0341462cb86b8522 100644 (file)
@@ -146,9 +146,6 @@ extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
 // (alkis)
 extern tex_accent_struct get_accent(kb_action action);
 
-namespace lyx {
-extern bool use_gui;
-}
 
 namespace {
 
index 85cf61c0c8843fd68eea1b652b8283da2d7d4b71..6bc40bbea90b7e012d284e83ecf55ed00e8be955 100644 (file)
@@ -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);