polybar/include/x11/fonts.hpp

84 lines
1.8 KiB
C++
Raw Normal View History

2016-11-02 19:22:45 +00:00
#pragma once
#include <X11/Xft/Xft.h>
#include <xcb/xcbext.h>
#include "common.hpp"
#include "x11/color.hpp"
#include "x11/types.hpp"
2016-11-19 05:22:44 +00:00
POLYBAR_NS
2016-11-02 19:22:45 +00:00
2016-11-20 22:04:31 +00:00
// fwd
class connection;
2016-12-09 08:02:47 +00:00
class logger;
2016-11-20 22:04:31 +00:00
2016-11-02 19:22:45 +00:00
#define XFT_MAXCHARS (1 << 16)
extern array<char, XFT_MAXCHARS> xft_widths;
extern array<wchar_t, XFT_MAXCHARS> xft_chars;
struct fonttype {
fonttype() {}
XftFont* xft;
xcb_font_t ptr;
int offset_y = 0;
int ascent = 0;
int descent = 0;
int height = 0;
int width = 0;
uint16_t char_max = 0;
uint16_t char_min = 0;
vector<xcb_charinfo_t> width_lut;
};
struct fonttype_deleter {
2016-11-20 22:04:31 +00:00
void operator()(fonttype* f);
2016-11-02 19:22:45 +00:00
};
using font_t = unique_ptr<fonttype, fonttype_deleter>;
2016-11-20 22:04:31 +00:00
class font_manager {
2016-11-02 19:22:45 +00:00
public:
2016-12-09 08:02:47 +00:00
static unique_ptr<font_manager> make();
2016-11-20 22:04:31 +00:00
explicit font_manager(connection& conn, const logger& logger);
~font_manager();
2016-11-02 19:22:45 +00:00
2016-11-25 12:55:15 +00:00
bool load(const string& name, int8_t fontindex = DEFAULT_FONT_INDEX, int8_t offset_y = 0);
2016-11-02 19:22:45 +00:00
2016-11-21 14:07:00 +00:00
void set_preferred_font(int8_t index);
2016-11-02 19:22:45 +00:00
font_t& match_char(uint16_t chr);
2016-11-21 14:07:00 +00:00
uint8_t char_width(font_t& font, uint16_t chr);
2016-11-02 19:22:45 +00:00
XftColor xftcolor();
2016-11-21 14:07:00 +00:00
XftDraw* xftdraw();
XftDraw* create_xftdraw(xcb_pixmap_t pm, xcb_colormap_t cm);
void destroy_xftdraw();
2016-11-02 19:22:45 +00:00
2016-11-21 14:07:00 +00:00
void allocate_color(uint32_t color, bool initial_alloc = false);
2016-11-02 19:22:45 +00:00
void allocate_color(XRenderColor color, bool initial_alloc = false);
2016-11-21 14:07:00 +00:00
void set_gcontext_font(xcb_gcontext_t gc, xcb_font_t font);
2016-11-02 19:22:45 +00:00
protected:
bool open_xcb_font(font_t& fontptr, string fontname);
bool has_glyph(font_t& font, uint16_t chr);
private:
connection& m_connection;
const logger& m_logger;
2016-11-21 14:07:00 +00:00
Display* m_display{nullptr};
Visual* m_visual{nullptr};
Colormap m_colormap{};
2016-12-09 08:02:47 +00:00
std::map<uint8_t, font_t> m_fonts;
int8_t m_fontindex{DEFAULT_FONT_INDEX};
2016-11-02 19:22:45 +00:00
2016-11-21 14:07:00 +00:00
XftColor m_xftcolor{};
XftDraw* m_xftdraw{nullptr};
2016-11-02 19:22:45 +00:00
};
2016-11-19 05:22:44 +00:00
POLYBAR_NS_END