X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FFontInfo.C;h=e7eb8117c0b70570e380daa8d303e9912a7b7e53;hb=dff2911bda426ad439e6475f62183cedd7044801;hp=cfc7143588d7e832dac823a1b4b9a5d3b1eb77ea;hpb=8dccec5c46a1689fe3ea37144252e952771e1e1c;p=lyx.git diff --git a/src/FontInfo.C b/src/FontInfo.C index cfc7143588..e7eb8117c0 100644 --- a/src/FontInfo.C +++ b/src/FontInfo.C @@ -1,4 +1,3 @@ -// -*- C++ -*- /* This file is part of * ====================================================== * @@ -11,7 +10,6 @@ #include #include // fabs() -#include // atoi() #ifdef __GNUG__ #pragma implementation "FontInfo.h" @@ -21,17 +19,23 @@ #include "debug.h" #include "lyxrc.h" // lyxrc.use_scalable_fonts #include "support/lstrings.h" +#include "support/lyxlib.h" +#include "frontends/GUIRunTime.h" -extern LyXRC * lyxrc; +using std::endl; + +#ifndef CXX_GLOBAL_CSTD +using std::fabs; +#endif /// Load font close to this size -string FontInfo::getFontname(int size) +string const FontInfo::getFontname(int size) { if (!exist()) return string(); int closestind = -1; - double error = 100000; + double error = 100000.0; for (int i = 0; i < matches; ++i) { if (sizes[i] == 0) { @@ -46,9 +50,9 @@ string FontInfo::getFontname(int size) } } - if (scalable && lyxrc->use_scalable_fonts) { + if (scalable && (lyxrc.use_scalable_fonts || closestind == -1)) { // We can use scalable - string font = resize(strings[scaleindex], size); + string const font = resize(strings[scaleindex], size); lyxerr[Debug::FONT] << "Using scalable font to get\n" << font << endl; return font; @@ -56,7 +60,7 @@ string FontInfo::getFontname(int size) // Did any fonts get close? if (closestind == -1) { - // No, and we are not allowed to use scalables, so... + // No, so... return string(); } @@ -69,7 +73,7 @@ string FontInfo::getFontname(int size) /// Build newly sized font string -string FontInfo::resize(string const & font, int size) const +string const FontInfo::resize(string const & font, int size) const { string ret(font); // Find the position of the size spec @@ -107,13 +111,16 @@ void FontInfo::query() return; if (pattern.empty()) { - lyxerr << "Can not use empty font name for font query." + lyxerr << "Cannot use empty font name for font query." << endl; queried = true; return; } - char ** list = XListFonts(fl_display, pattern.c_str(), 100, &matches); + char ** list = 0; + if (lyxrc.use_gui) + list = XListFonts(GUIRunTime::x11Display(), pattern.c_str(), + 100, &matches); if (list == 0) { // No fonts matched @@ -125,9 +132,11 @@ void FontInfo::query() strings = new string[matches]; // We have matches. Run them through - for(int i = 0; i < matches; ++i) { + for (int i = 0; i < matches; ++i) { string name(list[i]); - sizes[i] = atoi(token(name, '-', 7).c_str()); + lyxerr[Debug::FONT] << "match #" << i << " " + << name << endl; + sizes[i] = lyx::atoi(token(name, '-', 7)); strings[i] = name; if (sizes[i] == 0) { if (scaleindex == -1) { @@ -142,6 +151,17 @@ void FontInfo::query() } +void FontInfo::init() +{ + sizes = 0; + strings = 0; + matches = 0; + queried = false; + scalable = false; + scaleindex = -1; +} + + /// Release allocated stuff void FontInfo::release() {