diff options
Diffstat (limited to 'wayland/pango.c')
-rw-r--r-- | wayland/pango.c | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/wayland/pango.c b/wayland/pango.c deleted file mode 100644 index f9eec98c..00000000 --- a/wayland/pango.c +++ /dev/null | |||
@@ -1,73 +0,0 @@ | |||
1 | #include <cairo/cairo.h> | ||
2 | #include <pango/pangocairo.h> | ||
3 | #include <stdarg.h> | ||
4 | #include <stdlib.h> | ||
5 | #include <string.h> | ||
6 | #include <stdio.h> | ||
7 | #include <stdbool.h> | ||
8 | #include <stdint.h> | ||
9 | #include "log.h" | ||
10 | |||
11 | PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text, | ||
12 | int32_t scale, bool markup) { | ||
13 | PangoLayout *layout = pango_cairo_create_layout(cairo); | ||
14 | PangoAttrList *attrs; | ||
15 | if (markup) { | ||
16 | char *buf; | ||
17 | pango_parse_markup(text, -1, 0, &attrs, &buf, NULL, NULL); | ||
18 | pango_layout_set_markup(layout, buf, -1); | ||
19 | free(buf); | ||
20 | } else { | ||
21 | attrs = pango_attr_list_new(); | ||
22 | pango_layout_set_text(layout, text, -1); | ||
23 | } | ||
24 | pango_attr_list_insert(attrs, pango_attr_scale_new(scale)); | ||
25 | PangoFontDescription *desc = pango_font_description_from_string(font); | ||
26 | pango_layout_set_font_description(layout, desc); | ||
27 | pango_layout_set_single_paragraph_mode(layout, 1); | ||
28 | pango_layout_set_attributes(layout, attrs); | ||
29 | pango_attr_list_unref(attrs); | ||
30 | pango_font_description_free(desc); | ||
31 | return layout; | ||
32 | } | ||
33 | |||
34 | void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, | ||
35 | int32_t scale, bool markup, const char *fmt, ...) { | ||
36 | char *buf = malloc(2048); | ||
37 | |||
38 | va_list args; | ||
39 | va_start(args, fmt); | ||
40 | if (vsnprintf(buf, 2048, fmt, args) >= 2048) { | ||
41 | strcpy(buf, "[buffer overflow]"); | ||
42 | } | ||
43 | va_end(args); | ||
44 | |||
45 | PangoLayout *layout = get_pango_layout(cairo, font, buf, scale, markup); | ||
46 | pango_cairo_update_layout(cairo, layout); | ||
47 | |||
48 | pango_layout_get_pixel_size(layout, width, height); | ||
49 | |||
50 | g_object_unref(layout); | ||
51 | |||
52 | free(buf); | ||
53 | } | ||
54 | |||
55 | void pango_printf(cairo_t *cairo, const char *font, int32_t scale, bool markup, const char *fmt, ...) { | ||
56 | char *buf = malloc(2048); | ||
57 | |||
58 | va_list args; | ||
59 | va_start(args, fmt); | ||
60 | if (vsnprintf(buf, 2048, fmt, args) >= 2048) { | ||
61 | strcpy(buf, "[buffer overflow]"); | ||
62 | } | ||
63 | va_end(args); | ||
64 | |||
65 | PangoLayout *layout = get_pango_layout(cairo, font, buf, scale, markup); | ||
66 | pango_cairo_update_layout(cairo, layout); | ||
67 | |||
68 | pango_cairo_show_layout(cairo, layout); | ||
69 | |||
70 | g_object_unref(layout); | ||
71 | |||
72 | free(buf); | ||
73 | } | ||