some reworking to allow Qt to successfully choose a serif default font

with fontconfig


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6655 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Levon 2003-03-31 02:59:34 +00:00
parent 1bd5e00158
commit 22451cf2a8
23 changed files with 190 additions and 86 deletions

View File

@ -1,3 +1,15 @@
2003-03-31 John Levon <levon@movementarian.org>
* lyxrc.h:
* lyxrc.C: moved pdf_mode and use_gui to elsewhere
* lyx_main.C: set default fonts from using lyx_gui funcs
* exporter.C: pdf_mode moved from lyxrc
* lyx_cb.C:
* lyxfunc.C: changes from above
2003-03-31 John Levon <levon@movementarian.org>
* lyx_main.C: fix to the last fix

View File

@ -27,6 +27,8 @@
using std::vector;
using std::find;
bool pdf_mode = false;
bool Exporter::Export(Buffer * buffer, string const & format,
bool put_in_tempdir, string & result_file)
{
@ -51,7 +53,7 @@ bool Exporter::Export(Buffer * buffer, string const & format,
Graph::EdgePath p =
converters.getPath(*it, format);
if (!p.empty()) {
lyxrc.pdf_mode = converters.usePdflatex(p);
pdf_mode = converters.usePdflatex(p);
backend_format = *it;
break;
}

View File

@ -13,7 +13,7 @@
#include "Alert.h"
#include "debug.h"
#include "lyxrc.h"
#include "lyx_gui.h"
#include "Alert_pimpl.h"
@ -25,7 +25,7 @@ int Alert::prompt(string const & title, string const & question,
int default_button,
string const & b1, string const & b2, string const & b3)
{
if (lyxrc.use_gui)
if (lyx_gui::use_gui)
return prompt_pimpl(title, question, default_button, b1, b2, b3);
lyxerr << title << endl;
@ -43,7 +43,7 @@ int Alert::prompt(string const & title, string const & question,
void Alert::warning(string const & title, string const & message)
{
if (lyxrc.use_gui)
if (lyx_gui::use_gui)
return warning_pimpl(title, message);
lyxerr << "Warning: " << title << endl;
@ -54,7 +54,7 @@ void Alert::warning(string const & title, string const & message)
void Alert::error(string const & title, string const & message)
{
if (lyxrc.use_gui)
if (lyx_gui::use_gui)
return error_pimpl(title, message);
lyxerr << "Error: " << title << endl;
@ -65,7 +65,7 @@ void Alert::error(string const & title, string const & message)
void Alert::information(string const & title, string const & message)
{
if (lyxrc.use_gui)
if (lyx_gui::use_gui)
return information_pimpl(title, message);
lyxerr << title << endl;
@ -77,7 +77,7 @@ void Alert::information(string const & title, string const & message)
pair<bool, string> const Alert::askForText(string const & msg,
string const & dflt)
{
if (!lyxrc.use_gui) {
if (!lyx_gui::use_gui) {
lyxerr << "----------------------------------------" << endl
<< msg << endl
<< "Assuming answer is " << dflt

View File

@ -1,3 +1,10 @@
2003-03-31 John Levon <levon@movementarian.org>
* lyx_gui.h: add new font name helpers, move
use_gui to here.
* Alert.C: from above
2003-03-31 John Levon <levon@movementarian.org>
* Alert_pimpl.h:

View File

@ -26,6 +26,18 @@ class FuncRequest;
/// GUI interaction
namespace lyx_gui {
/// are we using the GUI at all
extern bool use_gui;
/// return a suitable serif font name (called from non-gui context too !)
string const roman_font_name();
/// return a suitable sans serif font name (called from non-gui context too !)
string const sans_font_name();
/// return a suitable monospaced font name (called from non-gui context too !)
string const typewriter_font_name();
/// parse command line and do basic initialisation
void parse_init(int & argc, char * argv[]);
@ -46,7 +58,6 @@ void start(string const & batch, std::vector<string> const & files);
*/
void exit();
/**
* return the status flag for a given action. This can be used to tell
* that a given lfun is not implemented by a frontend

View File

@ -1,3 +1,12 @@
2003-03-31 John Levon <levon@movementarian.org>
* lyx_gui.C: return useful default font names, add use_gui
* QPrefs.C: remove some dead font code
* qfont_loader.C: use_gui moved.
* qfont_metrics.C: use_gui moved.
2003-03-31 John Levon <levon@movementarian.org>
* Alert_pimpl.C: remove alert()

View File

@ -346,18 +346,6 @@ void setComboxFont(QComboBox * cb, string const & family,
return;
}
}
// Try the hint
QFont font;
font.setStyleHint(hint);
QFontInfo fi(font);
for (int i = cb->count() - 1; i >= 0; --i) {
if (cb->text(i) == fi.family()) {
cb->setCurrentItem(i);
return;
}
}
}
}

View File

@ -47,6 +47,7 @@
#include <qapplication.h>
#include <qwidget.h>
#include <qpaintdevicemetrics.h>
#include <qfont.h>
#include <fcntl.h>
#include <cstdlib>
@ -74,7 +75,6 @@ map<int, io_callback *> io_callbacks;
} // namespace anon
// FIXME: wrong place !
LyXServer * lyxserver;
@ -105,8 +105,12 @@ LQApplication::LQApplication(int & argc, char ** argv)
LQApplication::~LQApplication()
{}
namespace lyx_gui {
void lyx_gui::parse_init(int & argc, char * argv[])
bool use_gui = true;
void parse_init(int & argc, char * argv[])
{
static LQApplication a(argc, argv);
@ -124,11 +128,11 @@ void lyx_gui::parse_init(int & argc, char * argv[])
}
void lyx_gui::parse_lyxrc()
void parse_lyxrc()
{}
void lyx_gui::start(string const & batch, vector<string> const & files)
void start(string const & batch, vector<string> const & files)
{
// initial geometry
unsigned int width = 690;
@ -171,7 +175,7 @@ void lyx_gui::start(string const & batch, vector<string> const & files)
}
void lyx_gui::exit()
void exit()
{
delete lyxserver;
lyxserver = 0;
@ -185,7 +189,7 @@ void lyx_gui::exit()
}
FuncStatus lyx_gui::getStatus(FuncRequest const & ev)
FuncStatus getStatus(FuncRequest const & ev)
{
FuncStatus flag;
switch (ev.action) {
@ -201,38 +205,38 @@ FuncStatus lyx_gui::getStatus(FuncRequest const & ev)
}
string const lyx_gui::hexname(LColor::color col)
string const hexname(LColor::color col)
{
QColor color(toqstr(lcolor.getX11Name(col)));
return ltrim(fromqstr(color.name()), "#");
}
void lyx_gui::update_color(LColor::color)
void update_color(LColor::color)
{
// no need
}
void lyx_gui::update_fonts()
void update_fonts()
{
fontloader.update();
}
bool lyx_gui::font_available(LyXFont const & font)
bool font_available(LyXFont const & font)
{
return fontloader.available(font);
}
void lyx_gui::set_read_callback(int fd, LyXComm * comm)
void set_read_callback(int fd, LyXComm * comm)
{
io_callbacks[fd] = new io_callback(fd, comm);
}
void lyx_gui::remove_read_callback(int fd)
void remove_read_callback(int fd)
{
map<int, io_callback *>::iterator it = io_callbacks.find(fd);
if (it != io_callbacks.end()) {
@ -240,3 +244,41 @@ void lyx_gui::remove_read_callback(int fd)
io_callbacks.erase(it);
}
}
string const roman_font_name()
{
if (!use_gui)
return "serif";
QFont font;
font.setFamily("serif");
font.setStyleHint(QFont::Serif);
return font.family().latin1();
}
string const sans_font_name()
{
if (!use_gui)
return "sans";
QFont font;
font.setFamily("sans");
font.setStyleHint(QFont::SansSerif);
return font.family().latin1();
}
string const typewriter_font_name()
{
if (!use_gui)
return "monospace";
QFont font;
font.setFamily("monospace");
font.setStyleHint(QFont::TypeWriter);
return font.family().latin1();
}
}; // namespace lyx_gui

View File

@ -24,6 +24,7 @@
#include <qfontdatabase.h>
#include <qstringlist.h>
#include "support/lstrings.h"
#include "frontends/lyx_gui.h"
#include <boost/tuple/tuple.hpp>
@ -292,7 +293,7 @@ qfont_loader::font_info::font_info(LyXFont const & f)
qfont_loader::font_info * qfont_loader::getfontinfo(LyXFont const & f)
{
if (!lyxrc.use_gui) {
if (!lyx_gui::use_gui) {
// FIXME
}
@ -322,7 +323,7 @@ int qfont_loader::charwidth(LyXFont const & f, Uchar val)
bool qfont_loader::available(LyXFont const & f)
{
if (!lyxrc.use_gui)
if (!lyx_gui::use_gui)
return false;
static vector<bool> cache_set(LyXFont::NUM_FAMILIES, false);

View File

@ -11,7 +11,7 @@
#include <config.h>
#include "frontends/lyx_gui.h"
#include "support/lstrings.h"
#include "font_metrics.h"
#include "qfont_loader.h"
@ -32,7 +32,7 @@ QFontMetrics const & metrics(LyXFont const & f)
int charwidth(Uchar val, LyXFont const & f)
{
if (!lyxrc.use_gui)
if (!lyx_gui::use_gui)
return 1;
return fontloader.charwidth(f, val);
}
@ -44,7 +44,7 @@ namespace font_metrics {
int maxAscent(LyXFont const & f)
{
if (!lyxrc.use_gui)
if (!lyx_gui::use_gui)
return 1;
return metrics(f).ascent();
}
@ -52,7 +52,7 @@ int maxAscent(LyXFont const & f)
int maxDescent(LyXFont const & f)
{
if (!lyxrc.use_gui)
if (!lyx_gui::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
@ -62,7 +62,7 @@ int maxDescent(LyXFont const & f)
int ascent(char c, LyXFont const & f)
{
if (!lyxrc.use_gui)
if (!lyx_gui::use_gui)
return 1;
QRect const & r = metrics(f).boundingRect(c);
return -r.top();
@ -71,7 +71,7 @@ int ascent(char c, LyXFont const & f)
int descent(char c, LyXFont const & f)
{
if (!lyxrc.use_gui)
if (!lyx_gui::use_gui)
return 1;
QRect const & r = metrics(f).boundingRect(c);
return r.bottom()+1;
@ -80,7 +80,7 @@ int descent(char c, LyXFont const & f)
int lbearing(char c, LyXFont const & f)
{
if (!lyxrc.use_gui)
if (!lyx_gui::use_gui)
return 1;
return metrics(f).leftBearing(c);
}
@ -88,7 +88,7 @@ int lbearing(char c, LyXFont const & f)
int rbearing(char c, LyXFont const & f)
{
if (!lyxrc.use_gui)
if (!lyx_gui::use_gui)
return 1;
QFontMetrics const & m(metrics(f));
@ -108,7 +108,7 @@ Encoding const * fontencoding(LyXFont const & f)
int smallcapswidth(char const * s, size_t ls, LyXFont const & f)
{
if (!lyxrc.use_gui)
if (!lyx_gui::use_gui)
return 1;
// handle small caps ourselves ...
@ -136,7 +136,7 @@ int smallcapswidth(char const * s, size_t ls, LyXFont const & f)
int width(char const * s, size_t ls, LyXFont const & f)
{
if (!lyxrc.use_gui)
if (!lyx_gui::use_gui)
return ls;
if (f.realShape() == LyXFont::SMALLCAPS_SHAPE) {

View File

@ -1,3 +1,10 @@
2003-03-31 John Levon <levon@movementarian.org>
* FontInfo.C:
* lyx_gui.C:
* xfont_loader.C: add font name helpers, move
use_gui
2003-03-31 John Levon <levon@movementarian.org>
* Alert_pimpl.C: remove alert()

View File

@ -115,7 +115,7 @@ void FontInfo::query()
}
char ** list = 0;
if (lyxrc.use_gui)
if (lyx_gui::use_gui)
list = XListFonts(fl_get_display(), pattern.c_str(),
100, &matches);

View File

@ -128,7 +128,12 @@ char geometry[40];
} // namespace anon
void lyx_gui::parse_init(int & argc, char * argv[])
namespace lyx_gui {
bool use_gui = true;
void parse_init(int & argc, char * argv[])
{
setDefaults();
@ -177,7 +182,7 @@ void lyx_gui::parse_init(int & argc, char * argv[])
}
void lyx_gui::parse_lyxrc()
void parse_lyxrc()
{
XformsColor::read(AddName(user_lyxdir, "preferences.xform"));
@ -228,7 +233,7 @@ void lyx_gui::parse_lyxrc()
}
void lyx_gui::start(string const & batch, vector<string> const & files)
void start(string const & batch, vector<string> const & files)
{
// initial geometry
int xpos = -1;
@ -314,19 +319,19 @@ void lyx_gui::start(string const & batch, vector<string> const & files)
}
void lyx_gui::exit()
void exit()
{
finished = true;
}
FuncStatus lyx_gui::getStatus(FuncRequest const & /*ev*/)
FuncStatus getStatus(FuncRequest const & /*ev*/)
{
// Nothing interesting to do here
return FuncStatus();
}
string const lyx_gui::hexname(LColor::color col)
string const hexname(LColor::color col)
{
unsigned int r, g, b;
bool const success = getRGBColor(col, r, g, b);
@ -347,19 +352,19 @@ string const lyx_gui::hexname(LColor::color col)
}
void lyx_gui::update_color(LColor::color col)
void update_color(LColor::color col)
{
lyxColorHandler->updateColor(col);
}
void lyx_gui::update_fonts()
void update_fonts()
{
fontloader.update();
}
bool lyx_gui::font_available(LyXFont const & font)
bool font_available(LyXFont const & font)
{
return fontloader.available(font);
}
@ -375,13 +380,33 @@ void C_read_callback(int, void * data)
}
void lyx_gui::set_read_callback(int fd, LyXComm * comm)
void set_read_callback(int fd, LyXComm * comm)
{
fl_add_io_callback(fd, FL_READ, C_read_callback, comm);
}
void lyx_gui::remove_read_callback(int fd)
void remove_read_callback(int fd)
{
fl_remove_io_callback(fd, FL_READ, C_read_callback);
}
string const roman_font_name()
{
return "times";
}
string const sans_font_name()
{
return "helvetica";
}
string const typewriter_font_name()
{
return "courier";
}
}; // namespace lyx_gui

View File

@ -304,7 +304,7 @@ XFontStruct * xfont_loader::doLoad(LyXFont::FONT_FAMILY family,
LyXFont::FONT_SHAPE shape,
LyXFont::FONT_SIZE size)
{
if (!lyxrc.use_gui) {
if (!lyx_gui::use_gui) {
if (!dummyXFontStructisGood) {
// no character specific info
dummyXFontStruct.per_char = 0;
@ -366,7 +366,7 @@ XFontStruct * xfont_loader::doLoad(LyXFont::FONT_FAMILY family,
bool xfont_loader::available(LyXFont const & f)
{
if (!lyxrc.use_gui)
if (!lyx_gui::use_gui)
return false;
if (!fontinfo[f.family()][f.series()][f.realShape()])

View File

@ -108,7 +108,7 @@ int rbearing(char c, LyXFont const & f)
int width(char const * s, size_t n, LyXFont const & f)
{
if (!lyxrc.use_gui)
if (!lyx_gui::use_gui)
return n;
if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) {
@ -193,7 +193,7 @@ namespace xfont_metrics {
int width(XChar2b const * s, int n, LyXFont const & f)
{
if (!lyxrc.use_gui)
if (!lyx_gui::use_gui)
return n;
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {

View File

@ -1,3 +1,8 @@
2003-03-31 John Levon <levon@movementarian.org>
* insetgraphics.C:
* insetgraphicsParams.C: use_gui moved to lyx_gui
2003-03-31 John Levon <levon@movementarian.org>
* insettext.C: Alert fix

View File

@ -71,6 +71,7 @@ TODO
#include "LaTeXFeatures.h"
#include "lyxlex.h"
#include "lyxrc.h"
#include "frontends/lyx_gui.h"
#include "frontends/Alert.h"
#include "frontends/Dialogs.h"
@ -94,6 +95,8 @@ TODO
#include <algorithm> // For the std::max
extern string system_tempdir;
// set by Exporters
extern bool pdf_mode;
using std::ostream;
using std::endl;
@ -128,10 +131,10 @@ string const uniqueID()
string findTargetFormat(string const & suffix)
{
// lyxrc.pdf_mode means:
// pdf_mode means:
// Are we creating a PDF or a PS file?
// (Should actually mean, are we using latex or pdflatex).
if (lyxrc.pdf_mode) {
if (pdf_mode) {
lyxerr[Debug::GRAPHICS] << "findTargetFormat: PDF mode\n";
if (contains(suffix, "ps") || suffix == "pdf")
return "pdf";

View File

@ -24,6 +24,7 @@
#include "lyxrc.h"
#include "debug.h"
#include "lyxlex.h"
#include "frontends/lyx_gui.h"
using std::ostream;
@ -306,7 +307,7 @@ grfx::Params InsetGraphicsParams::as_grfxParams(string const & filepath) const
}
// Override the above if we're not using a gui
if (!lyxrc.use_gui) {
if (!lyx_gui::use_gui) {
pars.display = grfx::NoDisplay;
}

View File

@ -63,7 +63,7 @@ void ShowMessage(Buffer const * buf,
string const & msg2,
string const & msg3)
{
if (lyxrc.use_gui
if (lyx_gui::use_gui
&& buf && buf->getUser() && buf->getUser()->owner()) {
string const str = msg1 + ' ' + msg2 + ' ' + msg3;
buf->getUser()->owner()->message(str);
@ -182,7 +182,7 @@ void QuitLyX()
{
lyxerr[Debug::INFO] << "Running QuitLyX." << endl;
if (lyxrc.use_gui) {
if (lyx_gui::use_gui) {
if (!bufferlist.quitWriteAll())
return;

View File

@ -413,23 +413,23 @@ void LyX::init(bool gui)
first_start = false;
}
//
// Shine up lyxrc defaults
//
// Disable gui when easyparse says so
lyx_gui::use_gui = gui;
// Default template path: system_dir/templates
if (lyxrc.template_path.empty()) {
lyxrc.template_path = AddPath(system_lyxdir, "templates");
}
// Default lastfiles file: $HOME/.lyx/lastfiles
if (lyxrc.lastfiles.empty()) {
lyxrc.lastfiles = AddName(user_lyxdir, "lastfiles");
}
// Disable gui when either lyxrc or easyparse says so
if (!gui)
lyxrc.use_gui = false;
if (lyxrc.roman_font_name.empty())
lyxrc.roman_font_name = lyx_gui::roman_font_name();
if (lyxrc.sans_font_name.empty())
lyxrc.sans_font_name = lyx_gui::sans_font_name();
if (lyxrc.typewriter_font_name.empty())
lyxrc.typewriter_font_name = lyx_gui::typewriter_font_name();
//
// Read configuration files

View File

@ -1869,7 +1869,7 @@ void LyXFunc::doImport(string const & argument)
string const lyxfile = ChangeExtension(filename, ".lyx");
// Check if the document already is open
if (lyxrc.use_gui && bufferlist.exists(lyxfile)) {
if (lyx_gui::use_gui && bufferlist.exists(lyxfile)) {
string const file = MakeDisplayPath(lyxfile, 30);
// FIXME: sucky UI !

View File

@ -209,9 +209,9 @@ void LyXRC::setDefaults() {
font_sizes[LyXFont::SIZE_HUGE] = 20.74;
font_sizes[LyXFont::SIZE_HUGER] = 24.88;
use_scalable_fonts = true;
roman_font_name = "times";
sans_font_name = "helvetica";
typewriter_font_name = "courier";
roman_font_name = "";
sans_font_name = "";
typewriter_font_name = "";
popup_bold_font = "-*-helvetica-bold-r";
popup_normal_font = "-*-helvetica-medium-r";
font_norm = "iso8859-1";
@ -257,11 +257,6 @@ void LyXRC::setDefaults() {
preview_hashed_labels = false;
preview_scale_factor = 0.9;
/// These variables are not stored on disk (perhaps they
// should be moved from the LyXRC class).
use_gui = true;
pdf_mode = false;
user_name = lyx::user_name();
user_email = lyx::user_email();

View File

@ -185,8 +185,6 @@ enum LyXRCTags {
string custom_export_command;
///
string custom_export_format;
///
bool pdf_mode;
/// postscript interpreter (in general "gs", if it is installed)
string ps_command;
/// option for telling the dvi viewer about the paper size
@ -330,8 +328,6 @@ enum LyXRCTags {
bool auto_number;
///
bool mark_foreign_language;
/// Do we have to use a GUI?
bool use_gui;
///
string default_language;
///