Hello,
This patch saves the need to check for lyx::use_gui in a number of
place. I will commit tomorrow if there's no objection.
* lyx_main.h: define "extern bool lyx::use_gui" here.
* ConsoleFontMetrics.h: new class for command-line LyX
* ConsoleFontLoader.h: new class for command-line LyX
Index: development/scons/scons_manifest.py
===================================================================
--- development/scons/scons_manifest.py (revision 15322)
+++ development/scons/scons_manifest.py (working copy)
@@ -431,7 +431,9 @@
Alert.h
Alert_pimpl.h
Application.h
- Clipboard.h
+ Clipboard.h
+ ConsoleFontLoader.h
+ ConsoleFontMetrics.h
Dialogs.h
FileDialog.h
FontLoader.h
Index: src/frontends/Alert.C
===================================================================
--- src/frontends/Alert.C (revision 15322)
+++ src/frontends/Alert.C (working copy)
@@ -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 @@
namespace lyx {
-extern bool use_gui;
-
namespace frontend {
int Alert::prompt(docstring const & title, docstring const & question,
Index: src/frontends/Application.C
===================================================================
--- src/frontends/Application.C (revision 15330)
+++ src/frontends/Application.C (working copy)
@@ -12,6 +12,8 @@
#include "frontends/Application.h"
+#include "frontends/ConsoleFontLoader.h"
+#include "frontends/ConsoleFontMetrics.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 @@
lyx::frontend::FontLoader & theFontLoader()
{
+ static lyx::frontend::ConsoleFontLoader console_font_loader;
+
+ if (!lyx::use_gui)
+ return console_font_loader;
+
BOOST_ASSERT(theApp);
return theApp->fontLoader();
}
@@ -174,6 +182,11 @@
lyx::frontend::FontMetrics const & theFontMetrics(LyXFont const & f)
{
+ static lyx::frontend::ConsoleFontMetrics console_font_metrics;
+
+ if (!lyx::use_gui)
+ return console_font_metrics;
+
BOOST_ASSERT(theApp);
return theApp->fontLoader().metrics(f);
}
Index: src/frontends/ConsoleFontLoader.h
===================================================================
--- src/frontends/ConsoleFontLoader.h (revision 0)
+++ src/frontends/ConsoleFontLoader.h (revision 0)
@@ -0,0 +1,48 @@
+// -*- C++ -*-
+/**
+ * \file ConsoleFontLoader.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_CONSOLE_FONTLOADER_H
+#define LYX_CONSOLE_FONTLOADER_H
+
+#include "frontends/FontLoader.h"
+
+#include "frontends/ConsoleFontMetrics.h"
+
+namespace lyx {
+namespace frontend {
+
+/// Dummy FontLoader for command-line output.
+class ConsoleFontLoader: public FontLoader
+{
+public:
+ ///
+ ConsoleFontLoader() {}
+ ///
+ virtual ~ConsoleFontLoader() {}
+
+ /// 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:
+ ///
+ ConsoleFontMetrics metrics_;
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // LYX_CONSOLE_FONTLOADER_H
Property changes on: src\frontends\ConsoleFontLoader.h
___________________________________________________________________
Name: svn:eol-style
+ native
Index: src/frontends/ConsoleFontMetrics.h
===================================================================
--- src/frontends/ConsoleFontMetrics.h (revision 0)
+++ src/frontends/ConsoleFontMetrics.h (revision 0)
@@ -0,0 +1,66 @@
+// -*- C++ -*-
+/**
+ * \file ConsoleFontMetrics.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 CONSOLE_FONT_METRICS_H
+#define CONSOLE_FONT_METRICS_H
+
+#include "frontends/FontMetrics.h"
+
+#include "support/docstring.h"
+
+namespace lyx {
+namespace frontend {
+
+class ConsoleFontMetrics: public FontMetrics
+{
+public:
+
+ ConsoleFontMetrics() {}
+
+ virtual ~ConsoleFontMetrics() {}
+
+ 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 // QT4_FONT_METRICS_H
Property changes on: src\frontends\ConsoleFontMetrics.h
___________________________________________________________________
Name: svn:eol-style
+ native
Index: src/frontends/gtk/xftFontLoader.C
===================================================================
--- src/frontends/gtk/xftFontLoader.C (revision 15322)
+++ src/frontends/gtk/xftFontLoader.C (working copy)
@@ -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 @@
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: src/frontends/Makefile.am
===================================================================
--- src/frontends/Makefile.am (revision 15322)
+++ src/frontends/Makefile.am (working copy)
@@ -18,6 +18,8 @@
Alert_pimpl.h \
Application.C \
Application.h \
+ ConsoleFontLoader.h \
+ ConsoleFontMetrics.h \
Dialogs.C \
Dialogs.h \
FileDialog.h \
Index: src/frontends/qt3/GuiFontMetrics.C
===================================================================
--- src/frontends/qt3/GuiFontMetrics.C (revision 15322)
+++ src/frontends/qt3/GuiFontMetrics.C (working copy)
@@ -26,9 +26,6 @@
namespace lyx {
-
-extern bool use_gui;
-
namespace frontend {
@@ -46,16 +43,12 @@
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::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::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::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::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::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: src/frontends/qt3/qfont_loader.C
===================================================================
--- src/frontends/qt3/qfont_loader.C (revision 15322)
+++ src/frontends/qt3/qfont_loader.C (working copy)
@@ -44,11 +44,7 @@
using std::vector;
using std::string;
-namespace lyx {
-extern bool use_gui;
-}
-
GuiFontLoader::~GuiFontLoader() {
}
@@ -292,9 +288,6 @@
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: src/frontends/qt4/GuiFontLoader.C
===================================================================
--- src/frontends/qt4/GuiFontLoader.C (revision 15322)
+++ src/frontends/qt4/GuiFontLoader.C (working copy)
@@ -43,9 +43,6 @@
namespace lyx {
-
-extern bool use_gui;
-
namespace frontend {
GuiFontLoader::~GuiFontLoader() {
@@ -304,9 +301,6 @@
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: src/frontends/qt4/GuiFontMetrics.C
===================================================================
--- src/frontends/qt4/GuiFontMetrics.C (revision 15322)
+++ src/frontends/qt4/GuiFontMetrics.C (working copy)
@@ -25,9 +25,6 @@
using std::string;
namespace lyx {
-
-extern bool use_gui;
-
namespace frontend {
@@ -45,16 +42,12 @@
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::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::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::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::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::width(char_type const * s, size_t ls) const
{
- if (!lyx::use_gui)
- return ls;
-
QString ucs2;
ucs4_to_qstring(s, ls, ucs2);
Index: src/insets/insetexternal.C
===================================================================
--- src/insets/insetexternal.C (revision 15322)
+++ src/insets/insetexternal.C (working copy)
@@ -57,9 +57,6 @@
using std::ostringstream;
using std::vector;
-namespace lyx {
-extern bool use_gui;
-}
namespace {
Index: src/insets/insetgraphicsParams.C
===================================================================
--- src/insets/insetgraphicsParams.C (revision 15322)
+++ src/insets/insetgraphicsParams.C (working copy)
@@ -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::ostream;
-namespace lyx {
-extern bool use_gui;
-}
-
InsetGraphicsParams::InsetGraphicsParams()
{
init();
Index: src/lyx_cb.C
===================================================================
--- src/lyx_cb.C (revision 15322)
+++ src/lyx_cb.C (working copy)
@@ -93,10 +93,6 @@
// 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: src/lyx_main.h
===================================================================
--- src/lyx_main.h (revision 15322)
+++ src/lyx_main.h (working copy)
@@ -29,13 +29,13 @@
class kb_keymap;
namespace lyx {
+extern bool use_gui;
class Session;
namespace frontend {
class Application;
}
}
-
/// initial startup
class LyX : boost::noncopyable {
public:
Index: src/lyxfunc.C
===================================================================
--- src/lyxfunc.C (revision 15322)
+++ src/lyxfunc.C (working copy)
@@ -146,9 +146,6 @@
// (alkis)
extern tex_accent_struct get_accent(kb_action action);
-namespace lyx {
-extern bool use_gui;
-}
namespace {
Index: src/mathed/MathFactory.C
===================================================================
--- src/mathed/MathFactory.C (revision 15331)
+++ src/mathed/MathFactory.C (working copy)
@@ -74,9 +74,6 @@
bool has_math_fonts;
-namespace lyx {
-extern bool use_gui;
-}
namespace {
@@ -87,9 +84,6 @@
bool math_font_available(string & name)
{
- if (!lyx::use_gui)
- return false;
-
LyXFont f;
augmentFont(f, name);