#include <stdbool.h>
#include <err.h>
-#if PANGO_SUPPORT
#include <cairo/cairo-xcb.h>
+#if PANGO_SUPPORT
#include <pango/pangocairo.h>
#endif
*
*/
static void draw_text_pango(const char *text, size_t text_len,
- xcb_drawable_t drawable, int x, int y,
- int max_width, bool is_markup) {
+ xcb_drawable_t drawable, xcb_visualtype_t *visual, int x, int y,
+ int max_width, bool pango_markup) {
/* Create the Pango layout */
/* root_visual_type is cached in load_pango_font */
cairo_surface_t *surface = cairo_xcb_surface_create(conn, drawable,
- root_visual_type, x + max_width, y + savedFont->height);
+ visual, x + max_width, y + savedFont->height);
cairo_t *cr = cairo_create(surface);
PangoLayout *layout = create_layout_with_dpi(cr);
gint height;
pango_layout_set_wrap(layout, PANGO_WRAP_CHAR);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
- if (is_markup)
+ if (pango_markup)
pango_layout_set_markup(layout, text, text_len);
else
pango_layout_set_text(layout, text, text_len);
/* Do the drawing */
+ cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
cairo_set_source_rgb(cr, pango_font_red, pango_font_green, pango_font_blue);
pango_cairo_update_layout(cr, layout);
pango_layout_get_pixel_size(layout, NULL, &height);
* Calculate the text width using Pango rendering.
*
*/
-static int predict_text_width_pango(const char *text, size_t text_len, bool is_markup) {
+static int predict_text_width_pango(const char *text, size_t text_len, bool pango_markup) {
/* Create a dummy Pango layout */
/* root_visual_type is cached in load_pango_font */
cairo_surface_t *surface = cairo_xcb_surface_create(conn, root_screen->root, root_visual_type, 1, 1);
gint width;
pango_layout_set_font_description(layout, savedFont->specific.pango_desc);
- if (is_markup)
+ if (pango_markup)
pango_layout_set_markup(layout, text, text_len);
else
pango_layout_set_text(layout, text, text_len);
}
}
+/*
+ * Returns true if and only if the current font is a pango font.
+ *
+ */
+bool font_is_pango(void) {
+#if PANGO_SUPPORT
+ return savedFont->type == FONT_TYPE_PANGO;
+#else
+ return false;
+#endif
+}
+
static int predict_text_width_xcb(const xcb_char2b_t *text, size_t text_len);
static void draw_text_xcb(const xcb_char2b_t *text, size_t text_len, xcb_drawable_t drawable,
* Text must be specified as an i3String.
*
*/
-void draw_text(i3String *text, xcb_drawable_t drawable,
- xcb_gcontext_t gc, int x, int y, int max_width) {
+void draw_text(i3String *text, xcb_drawable_t drawable, xcb_gcontext_t gc,
+ xcb_visualtype_t *visual, int x, int y, int max_width) {
assert(savedFont != NULL);
+ if (visual == NULL) {
+ visual = root_visual_type;
+ }
switch (savedFont->type) {
case FONT_TYPE_NONE:
case FONT_TYPE_PANGO:
/* Render the text using Pango */
draw_text_pango(i3string_as_utf8(text), i3string_get_num_bytes(text),
- drawable, x, y, max_width, i3string_is_markup(text));
+ drawable, visual, x, y, max_width, i3string_is_markup(text));
return;
#endif
default:
if (text_len > 255) {
/* The text is too long to draw it directly to X */
i3String *str = i3string_from_utf8(text);
- draw_text(str, drawable, gc, x, y, max_width);
+ draw_text(str, drawable, gc, NULL, x, y, max_width);
i3string_free(str);
} else {
/* X11 coordinates for fonts start at the baseline */
case FONT_TYPE_PANGO:
/* Render the text using Pango */
draw_text_pango(text, strlen(text),
- drawable, x, y, max_width, false);
+ drawable, root_visual_type, x, y, max_width, false);
return;
#endif
default: