aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <ddevault@linode.com>2016-09-05 11:52:52 -0400
committerLibravatar Drew DeVault <ddevault@linode.com>2016-09-05 11:52:52 -0400
commitaf441541197a102d67048b8af920d63d1af37a2f (patch)
treeb9331b05cad8aa11539540c5c8942dac90e43da5
parentAdd client support for HiDPI (diff)
downloadsway-af441541197a102d67048b8af920d63d1af37a2f.tar.gz
sway-af441541197a102d67048b8af920d63d1af37a2f.tar.zst
sway-af441541197a102d67048b8af920d63d1af37a2f.zip
Fix constant scale factor in font code
-rw-r--r--include/client/pango.h8
-rw-r--r--sway/border.c4
-rw-r--r--swaybar/render.c32
-rw-r--r--wayland/pango.c14
4 files changed, 36 insertions, 22 deletions
diff --git a/include/client/pango.h b/include/client/pango.h
index 66843041..dd2f53c3 100644
--- a/include/client/pango.h
+++ b/include/client/pango.h
@@ -5,10 +5,12 @@
5#include <pango/pangocairo.h> 5#include <pango/pangocairo.h>
6#include <stdarg.h> 6#include <stdarg.h>
7#include <stdbool.h> 7#include <stdbool.h>
8#include <stdint.h>
8 9
9PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text, bool markup); 10PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text,
11 int32_t scale, bool markup);
10void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, 12void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
11 bool markup, const char *fmt, ...); 13 int32_t scale, bool markup, const char *fmt, ...);
12void pango_printf(cairo_t *cairo, const char *font, bool markup, const char *fmt, ...); 14void pango_printf(cairo_t *cairo, const char *font, int32_t scale, bool markup, const char *fmt, ...);
13 15
14#endif 16#endif
diff --git a/sway/border.c b/sway/border.c
index 65f69411..09bf05e9 100644
--- a/sway/border.c
+++ b/sway/border.c
@@ -92,7 +92,7 @@ int get_font_text_height(const char *font) {
92 cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 200, 200); 92 cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 200, 200);
93 cairo_t *cr = cairo_create(surface); 93 cairo_t *cr = cairo_create(surface);
94 int width, height; 94 int width, height;
95 get_text_size(cr, font, &width, &height, false, "Gg"); 95 get_text_size(cr, font, &width, &height, 1, false, "Gg");
96 cairo_surface_destroy(surface); 96 cairo_surface_destroy(surface);
97 cairo_destroy(cr); 97 cairo_destroy(cr);
98 return height; 98 return height;
@@ -180,7 +180,7 @@ static void render_title_bar(swayc_t *view, cairo_t *cr, struct wlc_geometry *b,
180 get_text_size(cr, config->font, &width, &height, false, "%s", view->name); 180 get_text_size(cr, config->font, &width, &height, false, "%s", view->name);
181 cairo_move_to(cr, x + 2, y + 2); 181 cairo_move_to(cr, x + 2, y + 2);
182 cairo_set_source_u32(cr, colors->text); 182 cairo_set_source_u32(cr, colors->text);
183 pango_printf(cr, config->font, false, "%s", view->name); 183 pango_printf(cr, config->font, 1, false, "%s", view->name);
184 } 184 }
185 185
186 // titlebars has a border all around for tabbed layouts 186 // titlebars has a border all around for tabbed layouts
diff --git a/swaybar/render.c b/swaybar/render.c
index 58325050..7bc060d5 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -51,7 +51,8 @@ static void render_sharp_line(cairo_t *cairo, uint32_t color, double x, double y
51 51
52static void render_block(struct window *window, struct config *config, struct status_block *block, double *x, bool edge) { 52static void render_block(struct window *window, struct config *config, struct status_block *block, double *x, bool edge) {
53 int width, height, sep_width; 53 int width, height, sep_width;
54 get_text_size(window->cairo, window->font, &width, &height, block->markup, "%s", block->full_text); 54 get_text_size(window->cairo, window->font, &width, &height,
55 window->scale, block->markup, "%s", block->full_text);
55 56
56 int textwidth = width; 57 int textwidth = width;
57 double block_width = width; 58 double block_width = width;
@@ -75,7 +76,8 @@ static void render_block(struct window *window, struct config *config, struct st
75 // Add separator 76 // Add separator
76 if (!edge) { 77 if (!edge) {
77 if (config->sep_symbol) { 78 if (config->sep_symbol) {
78 get_text_size(window->cairo, window->font, &sep_width, &height, false, "%s", config->sep_symbol); 79 get_text_size(window->cairo, window->font, &sep_width, &height,
80 window->scale, false, "%s", config->sep_symbol);
79 if (sep_width > block->separator_block_width) { 81 if (sep_width > block->separator_block_width) {
80 block->separator_block_width = sep_width + margin * 2; 82 block->separator_block_width = sep_width + margin * 2;
81 } 83 }
@@ -137,7 +139,8 @@ static void render_block(struct window *window, struct config *config, struct st
137 139
138 cairo_move_to(window->cairo, offset, margin); 140 cairo_move_to(window->cairo, offset, margin);
139 cairo_set_source_u32(window->cairo, block->color); 141 cairo_set_source_u32(window->cairo, block->color);
140 pango_printf(window->cairo, window->font, block->markup, "%s", block->full_text); 142 pango_printf(window->cairo, window->font, window->scale,
143 block->markup, "%s", block->full_text);
141 144
142 pos += width; 145 pos += width;
143 146
@@ -160,7 +163,8 @@ static void render_block(struct window *window, struct config *config, struct st
160 if (config->sep_symbol) { 163 if (config->sep_symbol) {
161 offset = pos + (block->separator_block_width - sep_width) / 2; 164 offset = pos + (block->separator_block_width - sep_width) / 2;
162 cairo_move_to(window->cairo, offset, margin); 165 cairo_move_to(window->cairo, offset, margin);
163 pango_printf(window->cairo, window->font, false, "%s", config->sep_symbol); 166 pango_printf(window->cairo, window->font, window->scale,
167 false, "%s", config->sep_symbol);
164 } else { 168 } else {
165 cairo_set_line_width(window->cairo, 1); 169 cairo_set_line_width(window->cairo, 1);
166 cairo_move_to(window->cairo, pos + block->separator_block_width/2, 170 cairo_move_to(window->cairo, pos + block->separator_block_width/2,
@@ -200,7 +204,8 @@ static const char *strip_workspace_name(bool strip_num, const char *ws_name) {
200void workspace_button_size(struct window *window, const char *workspace_name, int *width, int *height) { 204void workspace_button_size(struct window *window, const char *workspace_name, int *width, int *height) {
201 const char *stripped_name = strip_workspace_name(swaybar.config->strip_workspace_numbers, workspace_name); 205 const char *stripped_name = strip_workspace_name(swaybar.config->strip_workspace_numbers, workspace_name);
202 206
203 get_text_size(window->cairo, window->font, width, height, false, "%s", stripped_name); 207 get_text_size(window->cairo, window->font, width, height,
208 window->scale, false, "%s", stripped_name);
204 *width += 2 * ws_horizontal_padding; 209 *width += 2 * ws_horizontal_padding;
205 *height += 2 * ws_vertical_padding; 210 *height += 2 * ws_vertical_padding;
206} 211}
@@ -235,14 +240,16 @@ static void render_workspace_button(struct window *window, struct config *config
235 // text 240 // text
236 cairo_set_source_u32(window->cairo, box_colors.text); 241 cairo_set_source_u32(window->cairo, box_colors.text);
237 cairo_move_to(window->cairo, (int)*x + ws_horizontal_padding, margin); 242 cairo_move_to(window->cairo, (int)*x + ws_horizontal_padding, margin);
238 pango_printf(window->cairo, window->font, false, "%s", stripped_name); 243 pango_printf(window->cairo, window->font, window->scale,
244 false, "%s", stripped_name);
239 245
240 *x += width + ws_spacing; 246 *x += width + ws_spacing;
241} 247}
242 248
243static void render_binding_mode_indicator(struct window *window, struct config *config, double pos) { 249static void render_binding_mode_indicator(struct window *window, struct config *config, double pos) {
244 int width, height; 250 int width, height;
245 get_text_size(window->cairo, window->font, &width, &height, false, "%s", config->mode); 251 get_text_size(window->cairo, window->font, &width, &height,
252 window->scale, false, "%s", config->mode);
246 253
247 // background 254 // background
248 cairo_set_source_u32(window->cairo, config->colors.binding_mode.background); 255 cairo_set_source_u32(window->cairo, config->colors.binding_mode.background);
@@ -259,7 +266,8 @@ static void render_binding_mode_indicator(struct window *window, struct config *
259 // text 266 // text
260 cairo_set_source_u32(window->cairo, config->colors.binding_mode.text); 267 cairo_set_source_u32(window->cairo, config->colors.binding_mode.text);
261 cairo_move_to(window->cairo, (int)pos + ws_horizontal_padding, margin); 268 cairo_move_to(window->cairo, (int)pos + ws_horizontal_padding, margin);
262 pango_printf(window->cairo, window->font, false, "%s", config->mode); 269 pango_printf(window->cairo, window->font, window->scale,
270 false, "%s", config->mode);
263} 271}
264 272
265void render(struct output *output, struct config *config, struct status_line *line) { 273void render(struct output *output, struct config *config, struct status_line *line) {
@@ -283,10 +291,12 @@ void render(struct output *output, struct config *config, struct status_line *li
283 int width, height; 291 int width, height;
284 292
285 if (line->protocol == TEXT) { 293 if (line->protocol == TEXT) {
286 get_text_size(window->cairo, window->font, &width, &height, config->pango_markup, "%s", line->text_line); 294 get_text_size(window->cairo, window->font, &width, &height,
295 window->scale, config->pango_markup, "%s", line->text_line);
287 cairo_move_to(cairo, (window->width * window->scale) 296 cairo_move_to(cairo, (window->width * window->scale)
288 - margin - width, margin); 297 - margin - width, margin);
289 pango_printf(window->cairo, window->font, config->pango_markup, "%s", line->text_line); 298 pango_printf(window->cairo, window->font, window->scale,
299 config->pango_markup, "%s", line->text_line);
290 } else if (line->protocol == I3BAR && line->block_line) { 300 } else if (line->protocol == I3BAR && line->block_line) {
291 double pos = window->width - 0.5; 301 double pos = window->width - 0.5;
292 bool edge = true; 302 bool edge = true;
@@ -319,7 +329,7 @@ void render(struct output *output, struct config *config, struct status_line *li
319void set_window_height(struct window *window, int height) { 329void set_window_height(struct window *window, int height) {
320 int text_width, text_height; 330 int text_width, text_height;
321 get_text_size(window->cairo, window->font, 331 get_text_size(window->cairo, window->font,
322 &text_width, &text_height, false, 332 &text_width, &text_height, window->scale, false,
323 "Test string for measuring purposes"); 333 "Test string for measuring purposes");
324 if (height > 0) { 334 if (height > 0) {
325 margin = (height - text_height) / 2; 335 margin = (height - text_height) / 2;
diff --git a/wayland/pango.c b/wayland/pango.c
index d601021f..1dbc81f4 100644
--- a/wayland/pango.c
+++ b/wayland/pango.c
@@ -7,10 +7,12 @@
7#include <stdbool.h> 7#include <stdbool.h>
8#include "log.h" 8#include "log.h"
9 9
10PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text, bool markup) { 10PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text,
11 int32_t scale, bool markup) {
11 PangoLayout *layout = pango_cairo_create_layout(cairo); 12 PangoLayout *layout = pango_cairo_create_layout(cairo);
12 PangoAttrList *attrs = pango_attr_list_new(); 13 PangoAttrList *attrs = pango_attr_list_new();
13 pango_attr_list_insert(attrs, pango_attr_scale_new(2)); 14 sway_log(L_DEBUG, "Font scale: %d", scale);
15 pango_attr_list_insert(attrs, pango_attr_scale_new(scale));
14 if (markup) { 16 if (markup) {
15 pango_layout_set_markup(layout, text, -1); 17 pango_layout_set_markup(layout, text, -1);
16 } else { 18 } else {
@@ -26,7 +28,7 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text
26} 28}
27 29
28void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, 30void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
29 bool markup, const char *fmt, ...) { 31 int32_t scale, bool markup, const char *fmt, ...) {
30 char *buf = malloc(2048); 32 char *buf = malloc(2048);
31 33
32 va_list args; 34 va_list args;
@@ -36,7 +38,7 @@ void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
36 } 38 }
37 va_end(args); 39 va_end(args);
38 40
39 PangoLayout *layout = get_pango_layout(cairo, font, buf, markup); 41 PangoLayout *layout = get_pango_layout(cairo, font, buf, scale, markup);
40 pango_cairo_update_layout(cairo, layout); 42 pango_cairo_update_layout(cairo, layout);
41 43
42 pango_layout_get_pixel_size(layout, width, height); 44 pango_layout_get_pixel_size(layout, width, height);
@@ -46,7 +48,7 @@ void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
46 free(buf); 48 free(buf);
47} 49}
48 50
49void pango_printf(cairo_t *cairo, const char *font, bool markup, const char *fmt, ...) { 51void pango_printf(cairo_t *cairo, const char *font, int32_t scale, bool markup, const char *fmt, ...) {
50 char *buf = malloc(2048); 52 char *buf = malloc(2048);
51 53
52 va_list args; 54 va_list args;
@@ -56,7 +58,7 @@ void pango_printf(cairo_t *cairo, const char *font, bool markup, const char *fmt
56 } 58 }
57 va_end(args); 59 va_end(args);
58 60
59 PangoLayout *layout = get_pango_layout(cairo, font, buf, markup); 61 PangoLayout *layout = get_pango_layout(cairo, font, buf, scale, markup);
60 pango_cairo_update_layout(cairo, layout); 62 pango_cairo_update_layout(cairo, layout);
61 63
62 pango_cairo_show_layout(cairo, layout); 64 pango_cairo_show_layout(cairo, layout);