X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FFontInfo.C;h=c61d6662bb8ff680209ea98e5ecfb94ac6104245;hb=9e5bd1d609877e602cb697bc695d410e2ab48e0d;hp=ad62c475594f8cc8abfd44a9e1d6d5615fadde7d;hpb=0eccdd1c3613e5170deb77b22174dd0afde833e9;p=lyx.git diff --git a/src/FontInfo.C b/src/FontInfo.C index ad62c47559..c61d6662bb 100644 --- a/src/FontInfo.C +++ b/src/FontInfo.C @@ -1,28 +1,30 @@ // -*- C++ -*- /* This file is part of - * ====================================================== + * ====================================================== * * LyX, The Document Processor * - * Copyright (C) 1997 Asger Alstrup + * Copyright 1997 Asger Alstrup * and the LyX Team. * - *======================================================*/ + * ====================================================== */ #include #include // fabs() #include // atoi() +#include FORMS_H_LOCATION + #ifdef __GNUG__ #pragma implementation "FontInfo.h" #endif #include "FontInfo.h" -#include "error.h" +#include "debug.h" #include "lyxrc.h" // lyxrc.use_scalable_fonts #include "support/lstrings.h" -extern LyXRC * lyxrc; +using std::endl; /// Load font close to this size string FontInfo::getFontname(int size) @@ -33,12 +35,12 @@ string FontInfo::getFontname(int size) int closestind = -1; double error = 100000; - for (int i=0; iuse_scalable_fonts) { + if (scalable && lyxrc.use_scalable_fonts) { // We can use scalable string font = resize(strings[scaleindex], size); - lyxerr.debug("Using scalable font to get\n" - + font, Error::FONT); + lyxerr[Debug::FONT] << "Using scalable font to get\n" + << font << endl; return font; } @@ -61,36 +63,36 @@ string FontInfo::getFontname(int size) } // We use the closest match - lyxerr.debug(string("Using closest font match to get size ") - + tostr(size) - + " with\n" + strings[closestind], Error::FONT); + lyxerr[Debug::FONT] << "Using closest font match to get size " + << size + << " with\n" << strings[closestind] << endl; return strings[closestind]; } + /// Build newly sized font string -string FontInfo::resize(string const & font, int size) const { +string FontInfo::resize(string const & font, int size) const +{ + string ret(font); // Find the position of the size spec -#warning rewrite to use std::string constructs - int cut = 0, before = 0, after = 0; - for (string::size_type i = 0; i < font.length(); ++i) { - if (font[i] == '-') { + int cut = 0; + string::iterator before = string::iterator(0); + string::iterator after = string::iterator(0); + for (string::iterator sit = ret.begin(); + sit != ret.end(); ++sit) + if ((*sit) == '-') { ++cut; - if (cut == 7) { - before = i; - } else if (cut == 8) { - after = i; + if (cut == 7) before = sit + 1; + else if (cut == 8) { + after = sit; break; } } - } - - string head = font; - head.erase(before + 1, string::npos); - string tail = font; - tail.erase(0, after); - return head + tostr(size) + tail; + ret.replace(before, after, tostr(size)); + return ret; } + /// Set new pattern void FontInfo::setPattern(string const & pat) { @@ -99,6 +101,7 @@ void FontInfo::setPattern(string const & pat) pattern = pat; } + /// Query font in X11 void FontInfo::query() { @@ -106,12 +109,15 @@ void FontInfo::query() return; if (pattern.empty()) { - lyxerr.print("Can not use empty font name for font query."); + lyxerr << "Can not 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(fl_display, pattern.c_str(), 100, &matches); if (list == 0) { // No fonts matched @@ -123,9 +129,9 @@ void FontInfo::query() strings = new string[matches]; // We have matches. Run them through - for(int i=0; i