polybar-dwm/include/x11/fonts.hpp

99 lines
2.6 KiB
C++
Raw Normal View History

2016-11-02 19:22:45 +00:00
#pragma once
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_OUTLINE_H
#include FT_GLYPH_H
2016-11-02 19:22:45 +00:00
#include <X11/Xft/Xft.h>
#include <xcb/xcbext.h>
#include <unordered_map>
2016-11-02 19:22:45 +00:00
#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
using std::map;
using std::unordered_map;
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
struct font_ref {
explicit font_ref() = default;
font_ref(const font_ref& o) = delete;
font_ref& operator=(const font_ref& o) = delete;
2016-12-14 04:13:59 +00:00
XftFont* xft{nullptr};
xcb_font_t ptr{XCB_NONE};
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{};
unordered_map<uint16_t, wchar_t> glyph_widths{};
2016-11-02 19:22:45 +00:00
static struct _deleter {
void operator()(font_ref* font);
} deleter;
2016-11-02 19:22:45 +00:00
};
2016-11-20 22:04:31 +00:00
class font_manager {
2016-11-02 19:22:45 +00:00
public:
2016-12-09 08:40:46 +00:00
using make_type = unique_ptr<font_manager>;
static make_type make();
2016-12-09 08:02:47 +00:00
explicit font_manager(
connection& conn, const logger& logger, shared_ptr<Display>&& dsp, shared_ptr<Visual>&& vis, Colormap&& cm);
2016-11-20 22:04:31 +00:00
~font_manager();
2016-11-02 19:22:45 +00:00
font_manager(const font_manager& o) = delete;
font_manager& operator=(const font_manager& o) = delete;
2016-11-02 19:22:45 +00:00
void set_visual(shared_ptr<Visual>&& v);
void cleanup();
bool load(const string& name, int8_t fontindex = DEFAULT_FONT_INDEX, int8_t offset_y = 0);
2016-11-21 14:07:00 +00:00
void set_preferred_font(int8_t index);
shared_ptr<font_ref> match_char(const uint16_t chr);
uint8_t glyph_width(const shared_ptr<font_ref>& font, const uint16_t chr);
void drawtext(const shared_ptr<font_ref>& font, xcb_pixmap_t pm, xcb_gcontext_t gc, int16_t x, int16_t y,
const uint16_t* chars, size_t num_chars);
2016-11-02 19:22:45 +00:00
2016-12-14 04:13:59 +00:00
void allocate_color(uint32_t color);
void allocate_color(XRenderColor color);
2016-11-02 19:22:45 +00:00
void set_gcontext_font(const shared_ptr<font_ref>& font, xcb_gcontext_t, xcb_font_t*);
2016-11-02 19:22:45 +00:00
protected:
bool open_xcb_font(const shared_ptr<font_ref>& font, string fontname);
uint8_t glyph_width_xft(const shared_ptr<font_ref>& font, const uint16_t chr);
uint8_t glyph_width_xcb(const shared_ptr<font_ref>& font, const uint16_t chr);
bool has_glyph_xft(const shared_ptr<font_ref>& font, const uint16_t chr);
bool has_glyph_xcb(const shared_ptr<font_ref>& font, const uint16_t chr);
2016-11-02 19:22:45 +00:00
private:
connection& m_connection;
const logger& m_logger;
shared_ptr<Display> m_display;
shared_ptr<Visual> m_visual;
Colormap m_colormap;
2016-11-21 14:07:00 +00:00
map<uint8_t, shared_ptr<font_ref>> 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
XftDraw* m_xftdraw{nullptr};
XftColor m_xftcolor{};
bool m_xftcolor_allocated{false};
2016-11-02 19:22:45 +00:00
};
2016-11-19 05:22:44 +00:00
POLYBAR_NS_END