mirror of
https://github.com/swaywm/sway.git
synced 2025-10-31 22:25:26 -04:00
Flesh out pango markup implementation
This commit is contained in:
parent
083316c5ce
commit
84fae94ab9
6 changed files with 33 additions and 18 deletions
|
|
@ -4,11 +4,16 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include "log.h"
|
||||
|
||||
PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text) {
|
||||
PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text, bool markup) {
|
||||
PangoLayout *layout = pango_cairo_create_layout(cairo);
|
||||
pango_layout_set_markup(layout, text, -1);
|
||||
if (markup) {
|
||||
pango_layout_set_markup(layout, text, -1);
|
||||
} else {
|
||||
pango_layout_set_text(layout, text, -1);
|
||||
}
|
||||
PangoFontDescription *desc = pango_font_description_from_string(font);
|
||||
pango_layout_set_font_description(layout, desc);
|
||||
pango_layout_set_single_paragraph_mode(layout, 1);
|
||||
|
|
@ -16,7 +21,8 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text
|
|||
return layout;
|
||||
}
|
||||
|
||||
void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, const char *fmt, ...) {
|
||||
void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
|
||||
bool markup, const char *fmt, ...) {
|
||||
char *buf = malloc(2048);
|
||||
|
||||
va_list args;
|
||||
|
|
@ -26,7 +32,7 @@ void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, co
|
|||
}
|
||||
va_end(args);
|
||||
|
||||
PangoLayout *layout = get_pango_layout(cairo, font, buf);
|
||||
PangoLayout *layout = get_pango_layout(cairo, font, buf, markup);
|
||||
pango_cairo_update_layout(cairo, layout);
|
||||
|
||||
pango_layout_get_pixel_size(layout, width, height);
|
||||
|
|
@ -36,7 +42,7 @@ void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, co
|
|||
free(buf);
|
||||
}
|
||||
|
||||
void pango_printf(cairo_t *cairo, const char *font, const char *fmt, ...) {
|
||||
void pango_printf(cairo_t *cairo, const char *font, bool markup, const char *fmt, ...) {
|
||||
char *buf = malloc(2048);
|
||||
|
||||
va_list args;
|
||||
|
|
@ -46,7 +52,7 @@ void pango_printf(cairo_t *cairo, const char *font, const char *fmt, ...) {
|
|||
}
|
||||
va_end(args);
|
||||
|
||||
PangoLayout *layout = get_pango_layout(cairo, font, buf);
|
||||
PangoLayout *layout = get_pango_layout(cairo, font, buf, markup);
|
||||
pango_cairo_update_layout(cairo, layout);
|
||||
|
||||
pango_cairo_show_layout(cairo, layout);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue