mirror of
https://github.com/swaywm/sway.git
synced 2025-10-31 22:25:26 -04:00
Make client/pango.h not depend on client/window.h
This commit is contained in:
parent
da567317ab
commit
cefcce48aa
3 changed files with 26 additions and 28 deletions
|
|
@ -4,21 +4,19 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "client/window.h"
|
||||
#include "client/buffer.h"
|
||||
#include "log.h"
|
||||
|
||||
PangoLayout *get_pango_layout(struct window *window, const char *text) {
|
||||
PangoLayout *layout = pango_cairo_create_layout(window->cairo);
|
||||
PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text) {
|
||||
PangoLayout *layout = pango_cairo_create_layout(cairo);
|
||||
pango_layout_set_text(layout, text, -1);
|
||||
PangoFontDescription *desc = pango_font_description_from_string(window->font);
|
||||
PangoFontDescription *desc = pango_font_description_from_string(font);
|
||||
pango_layout_set_font_description(layout, desc);
|
||||
pango_layout_set_single_paragraph_mode(layout, 1);
|
||||
pango_font_description_free(desc);
|
||||
return layout;
|
||||
}
|
||||
|
||||
void get_text_size(struct window *window, int *width, int *height, const char *fmt, ...) {
|
||||
void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, const char *fmt, ...) {
|
||||
char *buf = malloc(2048);
|
||||
|
||||
va_list args;
|
||||
|
|
@ -28,8 +26,8 @@ void get_text_size(struct window *window, int *width, int *height, const char *f
|
|||
}
|
||||
va_end(args);
|
||||
|
||||
PangoLayout *layout = get_pango_layout(window, buf);
|
||||
pango_cairo_update_layout(window->cairo, layout);
|
||||
PangoLayout *layout = get_pango_layout(cairo, font, buf);
|
||||
pango_cairo_update_layout(cairo, layout);
|
||||
|
||||
pango_layout_get_pixel_size(layout, width, height);
|
||||
|
||||
|
|
@ -38,7 +36,7 @@ void get_text_size(struct window *window, int *width, int *height, const char *f
|
|||
free(buf);
|
||||
}
|
||||
|
||||
void pango_printf(struct window *window, const char *fmt, ...) {
|
||||
void pango_printf(cairo_t *cairo, const char *font, const char *fmt, ...) {
|
||||
char *buf = malloc(2048);
|
||||
|
||||
va_list args;
|
||||
|
|
@ -48,10 +46,10 @@ void pango_printf(struct window *window, const char *fmt, ...) {
|
|||
}
|
||||
va_end(args);
|
||||
|
||||
PangoLayout *layout = get_pango_layout(window, buf);
|
||||
pango_cairo_update_layout(window->cairo, layout);
|
||||
PangoLayout *layout = get_pango_layout(cairo, font, buf);
|
||||
pango_cairo_update_layout(cairo, layout);
|
||||
|
||||
pango_cairo_show_layout(window->cairo, layout);
|
||||
pango_cairo_show_layout(cairo, layout);
|
||||
|
||||
g_object_unref(layout);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue