2017-01-19 04:38:42 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-01-25 22:30:41 +00:00
|
|
|
#include <cairo/cairo-ft.h>
|
2017-01-24 05:59:58 +00:00
|
|
|
#include <list>
|
2017-01-19 04:38:42 +00:00
|
|
|
|
|
|
|
#include "common.hpp"
|
|
|
|
|
|
|
|
POLYBAR_NS
|
|
|
|
|
|
|
|
namespace cairo {
|
|
|
|
namespace utils {
|
2017-01-24 05:59:58 +00:00
|
|
|
/**
|
|
|
|
* @brief RAII wrapper used acquire cairo_device_t
|
|
|
|
*/
|
|
|
|
class device_lock {
|
|
|
|
public:
|
2017-01-25 22:30:41 +00:00
|
|
|
explicit device_lock(cairo_device_t* device);
|
|
|
|
~device_lock();
|
|
|
|
operator bool() const;
|
|
|
|
operator cairo_device_t*() const;
|
2017-01-24 05:59:58 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
cairo_device_t* m_device{nullptr};
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief RAII wrapper used to access the underlying
|
|
|
|
* FT_Face of a scaled font face
|
|
|
|
*/
|
|
|
|
class ft_face_lock {
|
|
|
|
public:
|
2017-01-25 22:30:41 +00:00
|
|
|
explicit ft_face_lock(cairo_scaled_font_t* font);
|
|
|
|
~ft_face_lock();
|
|
|
|
operator FT_Face() const;
|
2017-01-24 05:59:58 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
cairo_scaled_font_t* m_font;
|
|
|
|
FT_Face m_face;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Unicode character containing converted codepoint
|
|
|
|
* and details on where its position in the source string
|
|
|
|
*/
|
|
|
|
struct unicode_character {
|
2017-01-25 22:30:41 +00:00
|
|
|
explicit unicode_character();
|
2017-01-24 05:59:58 +00:00
|
|
|
unsigned long codepoint;
|
|
|
|
int offset;
|
|
|
|
int length;
|
|
|
|
};
|
|
|
|
using unicode_charlist = std::list<unicode_character>;
|
|
|
|
|
2017-01-19 04:38:42 +00:00
|
|
|
/**
|
|
|
|
* @see <cairo/cairo.h>
|
|
|
|
*/
|
2017-01-25 22:30:41 +00:00
|
|
|
cairo_operator_t str2operator(const string& mode, cairo_operator_t fallback);
|
2017-01-19 04:38:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Create a UCS-4 codepoint from a utf-8 encoded string
|
|
|
|
*/
|
2017-01-25 22:30:41 +00:00
|
|
|
bool utf8_to_ucs4(const unsigned char* src, unicode_charlist& result_list);
|
2017-01-19 04:38:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Convert a UCS-4 codepoint to a utf-8 encoded string
|
|
|
|
*/
|
2017-01-25 22:30:41 +00:00
|
|
|
size_t ucs4_to_utf8(char* utf8, unsigned int ucs);
|
2017-01-19 04:38:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
POLYBAR_NS_END
|