1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-06-02 07:20:47 +00:00
conky/src/fonts.cc

102 lines
2.7 KiB
C++
Raw Normal View History

/*
*
* Conky, a system monitor, based on torsmo
*
* Any original torsmo code is licensed under the BSD license
*
* All code written since the fork of torsmo is licensed under the GPL
*
* Please see COPYING for details
*
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
2021-02-27 15:14:19 +00:00
* Copyright (c) 2005-2021 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "fonts.h"
2020-12-26 01:37:29 +00:00
#include "display-output.hh"
2022-12-24 14:44:03 +00:00
#include "gui.h"
#include "logging.h"
2018-08-08 15:56:31 +00:00
unsigned int selected_font = 0;
2010-09-08 15:30:04 +00:00
std::vector<font_list> fonts;
char fontloaded = 0;
void font_setting::lua_setter(lua::state &l, bool init) {
lua::stack_sentry s(l, -2);
2010-09-08 15:30:04 +00:00
Base::lua_setter(l, init);
2010-09-08 15:30:04 +00:00
if (init) {
if (fonts.empty()) { fonts.resize(1); }
fonts[0].name = do_convert(l, -1).first;
}
2010-09-08 15:30:04 +00:00
++s;
2010-09-08 15:30:04 +00:00
}
font_setting font;
conky::simple_config_setting<std::string> font_template[10] = {
{"font0", ""}, {"font1", ""}, {"font2", ""}, {"font3", ""}, {"font4", ""},
{"font5", ""}, {"font6", ""}, {"font7", ""}, {"font8", ""}, {"font9", ""}};
void set_font() {
2020-12-26 01:37:29 +00:00
if (selected_font >= fonts.size()) return;
for (auto output : display_outputs()) output->set_font(selected_font);
}
void setup_fonts() {
DBGP2("setting up fonts");
2020-12-26 01:37:29 +00:00
for (auto output : display_outputs()) output->setup_fonts();
set_font();
}
int add_font(const char *data_in) {
if (!out_to_gui(*state)) { return 0; }
fonts.emplace_back();
fonts.rbegin()->name = data_in;
return fonts.size() - 1;
}
2010-11-26 16:59:07 +00:00
void free_fonts(bool utf8) {
2020-12-26 01:37:29 +00:00
for (auto output : display_outputs()) output->free_fonts(utf8);
fonts.clear();
selected_font = 0;
}
2010-11-26 16:59:07 +00:00
void load_fonts(bool utf8) {
DBGP2("loading fonts");
2020-12-26 01:37:29 +00:00
for (auto output : display_outputs()) output->load_fonts(utf8);
}
int font_height() {
assert(selected_font < fonts.size());
2020-12-26 01:37:29 +00:00
return display_output()->font_height(selected_font);
}
int font_ascent() {
assert(selected_font < fonts.size());
2020-12-26 01:37:29 +00:00
return display_output()->font_ascent(selected_font);
}
int font_descent() {
assert(selected_font < fonts.size());
2020-12-26 01:37:29 +00:00
return display_output()->font_descent(selected_font);
}