Merge branch 'line-height-letter-spacing'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Closes #12
authored by Daniel Eklöf · committed by Daniel Eklöf · parents da6772d, ac374b3 · Browse files · 10 files·+243 added−108 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
10 files+243 added−108 removed
- other:+243 added−108 removed
Provenance
- Commit
a3ea75b- Tree
b1e51af- Author
Daniel Eklöf <daniel@ekloef.se>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent 1
da6772d- Parent 2
ac374b3
10 files changed+243 added−108 removed
modified:completions/zsh/_fuzzel+7 added-3 removed
7 unmodified lines8 '(-f --font)'{-f,--font}'[font name and style in fontconfig format (monospace)]:font:->fonts' \9 '(-i --icon-theme)'{-i,--icon-theme}'[icon theme name (hicolor)]:theme:->icon_theme' \10 '(-I --no-icons)'{-I,--no-icons}'[do not render any icons]' \11 '(-T --terminal)'{-T,--terminal}'[terminal command, with arguments]:terminal:_command_names -e' \12- '(-l,--lines)'{-l,--lines}'[maximum number of matches to display (15)]:()' \13- '(-w,--width)'{-w,--width}'[window width, in characters (30)]:()' \12+ '(-l --lines)'{-l,--lines}'[maximum number of matches to display (15)]:()' \13+ '(-w --width)'{-w,--width}'[window width, in characters (30)]:()' \14+ '(-x --horizontal-pad)'{-x,--horizontal-pad}'[horizontal padding, in pixels (40)]:()' \15+ '(-y --vertical-pad)'{-y,--vertical-pad}'[vertical padding, in pixels (8)]:()' \16 '(-b --background)'{-b,--background}'[background color (fdf6e3dd)]:background:()' \17 '(-t --text-color)'{-t,--text-color}'[text color (657b83ff)]:text-color:()' \18 '(-m --match-color)'{-m,--match-color}'[color of matched substring (cb4b16ff)]:match-color:()' \19 '(-s --selection-color)'{-s,--selection-color}'[background color of selected item (eee8d5ff)]:selection-color:()' \20 '(-B --border-width)'{-B,--border-width}'[width of border, in pixels (1)]:border-width:()' \21 '(-r --border-radius)'{-r,--border-radius}'[amount of corner "roundness" (10)]:border-radius:()' \22 '(-C --border-color)'{-C,--border-color}'[border color (002b36ff)]:border-color:()' \23 '(-d --dmenu)'{-d,--dmenu}'[dmenu compatibility mode; list entries are read from stdin]' \22- '(-R --no-run-if-empty)'{-R,--no-run-if-empty}'[exit immediately without showing the UI if stdin is empty (dmenu mode only)]'24+ '(-R --no-run-if-empty)'{-R,--no-run-if-empty}'[exit immediately without showing the UI if stdin is empty (dmenu mode only)]' \25+ '--line-height[override line height from font metrics, in points or pixels]:()' \26+ '--letter-spacing[additional letter spacing, in points or pixels]:()'27 28 case "${state}" in29 fonts)30 if command -v fc-list > /dev/null; then14 unmodified linesmodified:doc/fuzzel.scd+19 added
41 unmodified lines42 *-w*,*--width*43 Window width, in characters. Margins and borders not44 included. Default: _30_.45 46+*-x*,*--horizontal-pad*=_PAD_47+ Horizontal padding between border and icons and text. In pixels,48+ subject to output scaling. Default: _40_.49+50+*-y*,*--vertical-pad*=_PAD_51+ Vertical padding between border and text. In pixels, subject to52+ output scaling. Default: _8_.53+54 *-b*,*--background*=_HEX_55 Background color. See *COLORS*. Default: _fdf6e3dd_.56 57 *-t*,*--text-color*=_HEX_27 unmodified lines85 *-R*,*--no-run-if-empty*86 Exit immediately, without showing the UI, if stdin is87 empty. **dmenu** mode only.88 89+*--line-height*=_HEIGHT_90+ Override line height from font metrics. In points by default, but91+ can be specified as pixels by appending 'px'92+ (i.e. *--line-height=16px*). Default: _not set_.93+94+*--letter-spacing*=_AMOUNT_95+ Additional space between letters. In points by default, but can be96+ specified as pixels by appending 'px'97+ (i.e. *letter-spacing=5px*). Negative values are98+ supported. Default: _0_.99+100 *-v*,*--version*101 Show the version number and quit102 103 # FONT FORMAT21 unmodified linesmodified:application.c+2 added-2 removed
233 unmodified lines234 break;235 236 case ICON_PNG:237 #if defined(FUZZEL_ENABLE_PNG)238- free(pixman_image_get_data(app->icon.png.pix));239- pixman_image_unref(app->icon.png.pix);238+ free(pixman_image_get_data(app->icon.png));239+ pixman_image_unref(app->icon.png);240 #endif241 break;242 243 case ICON_SVG:9 unmodified linesmodified:application.h+1 added-4 removed
14 unmodified lines15 char *name;16 enum icon_type type;17 union {18 #if defined(FUZZEL_ENABLE_PNG)19- struct {20- pixman_image_t *pix;19+ pixman_image_t *png;21- bool has_scale_transform;22- } png;20 #endif21 #if defined(FUZZEL_ENABLE_SVG)22 RsvgHandle *svg;23 #endif22 unmodified linesmodified:CHANGELOG.md+4 added
19 unmodified lines20212223242526272829303134 unmodified lines19 unmodified lines (https://codeberg.org/dnkl/fuzzel/issues/10).* `-I,--no-icons` command line option; disables all icons (https://codeberg.org/dnkl/fuzzel/issues/12)* FreeBSD port.* `-x,--horizontal-pad` and `-y,--vertical-pad` command line options (https://codeberg.org/dnkl/fuzzel/issues/12).* `--line-height` and `-letter-spacing` command line options (https://codeberg.org/dnkl/fuzzel/issues/12).
### Deprecated### Removed34 unmodified linesmodified:icon.c+8 added-10 removed
277 unmodified lines278 }279 280 #if defined(FUZZEL_ENABLE_PNG)281 static bool282-icon_from_png(struct icon *icon, pixman_image_t *png)282+icon_from_png(struct icon *icon, pixman_image_t *png, int icon_size)283 {284 icon->type = ICON_PNG;285- icon->png.pix = png;286- icon->png.has_scale_transform = false;285+ icon->png = png;286 return true;287 }288 #endif289 15 unmodified lines305 break;306 307 case ICON_PNG:308 #if defined(FUZZEL_ENABLE_PNG)310- free(pixman_image_get_data(icon->png.pix));311- pixman_image_unref(icon->png.pix);312- icon->png.pix = NULL;313- icon->png.has_scale_transform = false;309+ free(pixman_image_get_data(icon->png));310+ pixman_image_unref(icon->png);311+ icon->png = NULL;312 #endif313 break;314 315 case ICON_SVG:29 unmodified lines345 #if defined(FUZZEL_ENABLE_PNG)346 pixman_image_t *png = png_load(name);347 if (png != NULL) {348 LOG_DBG("%s: absolute path PNG", name);351- return icon_from_png(icon, png);349+ return icon_from_png(icon, png, icon_size);350 }351 #endif352 return icon_null(icon);353 }75 unmodified lines429 else430 LOG_DBG("%s: %s: nothing else matched", name, full_path);431 432 free(full_path);435- return icon_from_png(icon, png);433+ return icon_from_png(icon, png, icon_size);434 }435 #endif436 free(full_path);437 }23 unmodified lines461 sprintf(path, "%s/pixmaps/%s.png", it->item, name);462 pixman_image_t *png = png_load(path);463 if (png != NULL) {464 xdg_data_dirs_destroy(dirs);467- return icon_from_png(icon, png);465+ return icon_from_png(icon, png, icon_size);466 }467 #endif468 }469 xdg_data_dirs_destroy(dirs);15 unmodified linesmodified:main.c+98 added-25 removed
1 unmodified line2 #include <stdio.h>3 #include <stdbool.h>4 #include <string.h>5 #include <getopt.h>6+#include <errno.h>7 8 #include <locale.h>9 10 #include <sys/types.h>157 unmodified lines168 printf("Usage: %s [OPTION]...\n", prog_name);169 printf("\n");170 printf("Options:\n");171 printf(" -o,--output=OUTPUT output (monitor) to display on (none)\n"171- " -f,--font=FONT font name and style in fontconfig format (monospace)\n"172+ " -f,--font=FONT font name+style in fontconfig format (monospace)\n"173 " -i,--icon-theme=NAME icon theme name (\"hicolor\")\n"174 " -I,--no-icons do not render any icons\n"174- " -T,--terminal terminal command to use when launching 'terminal' programs, e.g. \"xterm -e\".\n"175- " Not used in dmenu mode. (default: not set)\n"175+ " -T,--terminal terminal command to use when launching 'terminal'\n"176+ " programs, e.g. \"xterm -e\". Not used in dmenu\n"177+ " mode (not set)\n"178 " -l,--lines number of matches to show\n"177- " -w,--width window width, in characters (margins and borders not included)\n"179+ " -w,--width window width, in characters (margins and borders\n"180+ " not included)\n"181+ " -x,--horizontal-pad=PAD horizontal padding, in pixels (40)\n"182+ " -y,--vertical-pad=PAD vertical padding, in pixels (8)\n"183 " -b,--background-color=HEX background color (000000ff)\n"184 " -t,--text-color=HEX text color (ffffffff)\n"185 " -m,--match-color=HEX color of matched substring (cc9393ff)\n"186 " -s,--selection-color=HEX background color of selected item (333333ff)\n"187 " -B,--border-width=INT width of border, in pixels (1)\n"188 " -r,--border-radius=INT amount of corner \"roundness\" (10)\n"189 " -C,--border-color=HEX border color (ffffffff)\n"190 " -d,--dmenu dmenu compatibility mode\n"186- " -R,--no-run-if-empty exit immediately without showing UI if stdin is empty (dmenu mode only)\n"191+ " -R,--no-run-if-empty exit immediately without showing UI if stdin is \n"192+ " empty (dmenu mode only)\n"193+ " --line-height=HEIGHT override line height from font metrics\n"194+ " --letter-spacing=AMOUNT additional letter spacing\n"195 " -v,--version show the version number and quit\n");196 printf("\n");197 printf("Colors must be specified as a 32-bit hexadecimal RGBA quadruple.\n");198 }11 unmodified lines210 if (ctx->icons_enabled)211 icon_reload_application_icons(*ctx->themes, font->height, ctx->apps);212 }213 214+static bool215+pt_or_px_from_string(const char *s, struct pt_or_px *res)216+{217+ const size_t len = strlen(s);218+ if (len >= 2 && s[len - 2] == 'p' && s[len - 1] == 'x') {219+ errno = 0;220+ char *end = NULL;221+222+ long value = strtol(s, &end, 10);223+ if (!(errno == 0 && end == s + len - 2)) {224+ fprintf(stderr, "%s: not a valid pixel value\n", s);225+ return false;226+ }227+228+ res->pt = 0;229+ res->px = value;230+ } else {231+ errno = 0;232+ char *end = NULL;233+234+ float value = strtof(s, &end);235+ if (!(errno == 0 && *end == '\0')) {236+ fprintf(stderr, "%s: not a valid point value\n", s);237+ return false;238+ }239+ res->pt = value;240+ res->px = 0;241+ }242+243+ return true;244+}245+246 int247 main(int argc, char *const *argv)248 {249 static const struct option longopts[] = {210- {"output" , required_argument, 0, 'o'},211- {"font", required_argument, 0, 'f'},212- {"icon-theme", required_argument, 0, 'i'},213- {"no-icons", no_argument, 0, 'I'},214- {"lines", required_argument, 0, 'l'},215- {"width", required_argument, 0, 'w'},216- {"background-color", required_argument, 0, 'b'},217- {"text-color", required_argument, 0, 't'},218- {"match-color", required_argument, 0, 'm'},219- {"selection-color", required_argument, 0, 's'},220- {"border-width", required_argument, 0, 'B'},221- {"border-radius", required_argument, 0, 'r'},222- {"border-color", required_argument, 0, 'C'},223- {"terminal", required_argument, 0, 'T'},224- {"dmenu", no_argument, 0, 'd'},225- {"no-run-if-empty", no_argument, 0, 'R'},226- {"version", no_argument, 0, 'v'},227- {"help", no_argument, 0, 'h'},228- {NULL, no_argument, 0, 0},250+ {"output" , required_argument, 0, 'o'},251+ {"font", required_argument, 0, 'f'},252+ {"icon-theme", required_argument, 0, 'i'},253+ {"no-icons", no_argument, 0, 'I'},254+ {"lines", required_argument, 0, 'l'},255+ {"width", required_argument, 0, 'w'},256+ {"horizontal-pad", required_argument, 0, 'x'},257+ {"vertical-pad", required_argument, 0, 'y'},258+ {"background-color", required_argument, 0, 'b'},259+ {"text-color", required_argument, 0, 't'},260+ {"match-color", required_argument, 0, 'm'},261+ {"selection-color", required_argument, 0, 's'},262+ {"border-width", required_argument, 0, 'B'},263+ {"border-radius", required_argument, 0, 'r'},264+ {"border-color", required_argument, 0, 'C'},265+ {"terminal", required_argument, 0, 'T'},266+ {"dmenu", no_argument, 0, 'd'},267+ {"no-run-if-empty", no_argument, 0, 'R'},268+ {"line-height", required_argument, 0, 'H'},269+ {"letter-spacing", required_argument, 0, 'S'},270+ {"version", no_argument, 0, 'v'},271+ {"help", no_argument, 0, 'h'},272+ {NULL, no_argument, 0, 0},273 };274 275 const char *output_name = NULL;276 const char *font_name = "monospace";7 unmodified lines284 .lines = 15,285 .chars = 30,286 .border_size = 1u,287 .border_radius = 10u,288+ .pad = {.x = 40, .y = 8},289 .background_color = hex_to_rgba(0xfdf6e3dd),290 .border_color = hex_to_rgba(0x002b36ff),291 .text_color = hex_to_rgba(0x657b83ff),292 .match_color = hex_to_rgba(0xcb4b16ff),293 .selection_color = hex_to_rgba(0xeee8d5dd),294+ .line_height = {-1, 0.0}, /* Use font metrics */295+ .letter_spacing = {0},296 };297 298 while (true) {252- int c = getopt_long(argc, argv, ":o:f:i:Il:w:b:t:m:s:B:r:C:T:dRvh", longopts, NULL);299+ int c = getopt_long(argc, argv, ":o:f:i:Il:w:x:y:b:t:m:s:B:r:C:T:dRvh", longopts, NULL);300 if (c == -1)301 break;302 303 switch (c) {30 unmodified lines334 return EXIT_FAILURE;335 }336 break;337 338+ case 'x':339+ if (sscanf(optarg, "%u", &render_options.pad.x) != 1) {340+ fprintf(stderr, "%s: invalid padding\n", optarg);341+ return EXIT_FAILURE;342+ }343+ break;344+345+ case 'y':346+ if (sscanf(optarg, "%u", &render_options.pad.y) != 1) {347+ fprintf(stderr, "%s: invalid padding\n", optarg);348+ return EXIT_FAILURE;349+ }350+ break;351+352 case 'b': {353 uint32_t background;354 if (sscanf(optarg, "%08x", &background) != 1) {355 fprintf(stderr, "%s: invalid color\n", optarg);67 unmodified lines423 case 'R':424 no_run_if_empty = true;425 break;426 427+ case 'H': { /* line-height */428+ if (!pt_or_px_from_string(optarg, &render_options.line_height))429+ return EXIT_FAILURE;430+ break;431+ }432+433+ case 'S': { /* letter-spacing */434+ if (!pt_or_px_from_string(optarg, &render_options.letter_spacing))435+ return EXIT_FAILURE;436+ break;437+ }438+439 case 'v':440 printf("fuzzel version %s\n", FUZZEL_VERSION);441 return EXIT_SUCCESS;442 106 unmodified linesmodified:render.c+90 added-59 removed
7 unmodified lines8 9 #define LOG_MODULE "render"10 #define LOG_ENABLE_DBG 011 #include "log.h"12+#include "stride.h"13 #include "wayland.h"14 15+#define min(x, y) ((x) < (y) ? (x) : (y))16 #define max(x, y) ((x) > (y) ? (x) : (y))17 18 struct render {19 struct render_options options;20 struct fcft_font *font;21 enum fcft_subpixel subpixel;22+ float dpi;23 24 unsigned x_margin;25 unsigned y_margin;26 unsigned border_size;15 unmodified lines42 .alpha = a,43 };44 }45 46+static int47+pt_or_px_as_pixels(const struct pt_or_px *pt_or_px, float dpi)48+{49+ return pt_or_px->px == 050+ ? pt_or_px->pt * dpi / 72.51+ : pt_or_px->px;52+}53+54 void55 render_background(const struct render *render, struct buffer *buf)56 {57 bool use_pixman =111 unmodified lines169 170 x += x_kern;171 render_glyph(buf->pix, glyph, x, y, &render->options.pix_text_color);172 x += glyph->advance.x;173+ if (i >= prompt_len)174+ x += pt_or_px_as_pixels(&render->options.letter_spacing, render->dpi);175 176 /* Cursor */177 if (prompt_cursor(prompt) + prompt_len - 1 == i) {178 pixman_image_fill_rectangles(10 unmodified lines189 static void190 render_match_text(struct buffer *buf, double *_x, double _y,191 const wchar_t *text, ssize_t start, size_t length,192 struct fcft_font *font, enum fcft_subpixel subpixel,193+ int letter_spacing,194 pixman_color_t regular_color, pixman_color_t match_color)195 {196 int x = *_x;197 int y = _y;10 unmodified lines208 bool is_match = start >= 0 && i >= start && i < start + length;209 x += x_kern;210 render_glyph(buf->pix, glyph, x, y + y_kern, is_match ? &match_color : ®ular_color);211 x += glyph->advance.x;212+ x += letter_spacing;213 }214 215 *_x = x;216 }4 unmodified lines221 {222 struct fcft_font *font = render->font;223 assert(font != NULL);224 210- const double x_margin = render->x_margin;211- const double y_margin = render->y_margin;212- const double border_size = render->border_size;225+ const int x_margin = render->x_margin;226+ const int y_margin = render->y_margin;227+ const int border_size = render->border_size;228 const size_t match_count = matches_get_count(matches);229 const size_t selected = matches_get_match_index(matches);230 const enum fcft_subpixel subpixel =231 (render->options.background_color.a == 1. &&1 unmodified line233 ? render->subpixel : FCFT_SUBPIXEL_NONE;234 235 assert(match_count == 0 || selected < match_count);236 222- const double row_height = 2 * y_margin + font->height;223- const double first_row = 1 * border_size + row_height;224- const double sel_margin = x_margin / 3;237+ const int row_height = render->row_height;238+ const int first_row = 1 * border_size + y_margin + row_height;239+ const int sel_margin = x_margin / 3;240 226- double y = first_row + (row_height + font->height) / 2 - font->descent;241+ int y = first_row + (row_height + font->height) / 2 - font->descent;242 243 for (size_t i = 0; i < match_count; i++) {229- if ((int)(y + font->descent + row_height / 2) >230- (int)(buf->height - y_margin - border_size))231- {244+ if (y + font->descent > buf->height - y_margin - border_size) {245 /* Window too small - happens if the compositor doesn't233- * repsect our requested size */246+ * respect our requested size */247 break;248 }249 250 const struct match *match = matches_get(matches, i);65 unmodified lines316 #if defined(FUZZEL_ENABLE_PNG)317 #if defined(FUZZEL_ENABLE_CAIRO)318 cairo_surface_flush(buf->cairo_surface);319 #endif307-308- pixman_image_t *png = icon->png.pix;320+ pixman_image_t *png = icon->png;321+ pixman_format_code_t fmt = pixman_image_get_format(png);322 int height = pixman_image_get_height(png);323 int width = pixman_image_get_width(png);324 312- if (height > row_height) {313- double scale = (double)font->height / height;325+ if (height > min(row_height, font->height)) {326+ double scale = (double)min(row_height, font->height) / height;327 315- if (!icon->png.has_scale_transform) {316- pixman_f_transform_t _scale_transform;317- pixman_f_transform_init_scale(318- &_scale_transform, 1. / scale, 1. / scale);328+ pixman_f_transform_t _scale_transform;329+ pixman_f_transform_init_scale(330+ &_scale_transform, 1. / scale, 1. / scale);331 320- pixman_transform_t scale_transform;321- pixman_transform_from_pixman_f_transform(322- &scale_transform, &_scale_transform);323- pixman_image_set_transform(png, &scale_transform);332+ pixman_transform_t scale_transform;333+ pixman_transform_from_pixman_f_transform(334+ &scale_transform, &_scale_transform);335+ pixman_image_set_transform(png, &scale_transform);336 325- int param_count = 0;326- pixman_kernel_t kernel = PIXMAN_KERNEL_LANCZOS3;327- pixman_fixed_t *params = pixman_filter_create_separable_convolution(328- ¶m_count,329- pixman_double_to_fixed(1. / scale),330- pixman_double_to_fixed(1. / scale),331- kernel, kernel,332- kernel, kernel,333- pixman_int_to_fixed(1),334- pixman_int_to_fixed(1));337+ int param_count = 0;338+ pixman_kernel_t kernel = PIXMAN_KERNEL_LANCZOS3;339+ pixman_fixed_t *params = pixman_filter_create_separable_convolution(340+ ¶m_count,341+ pixman_double_to_fixed(1. / scale),342+ pixman_double_to_fixed(1. / scale),343+ kernel, kernel,344+ kernel, kernel,345+ pixman_int_to_fixed(1),346+ pixman_int_to_fixed(1));347 336- if (params != NULL || param_count == 0) {337- pixman_image_set_filter(338- png, PIXMAN_FILTER_SEPARABLE_CONVOLUTION,339- params, param_count);340- }341-342- free(params);343- icon->png.has_scale_transform = true;348+ if (params != NULL || param_count == 0) {349+ pixman_image_set_filter(350+ png, PIXMAN_FILTER_SEPARABLE_CONVOLUTION,351+ params, param_count);352 }353 346- assert(icon->png.has_scale_transform);354+ free(params);355+356 width *= scale;357 height *= scale;358+359+ int stride = stride_for_format_and_width(fmt, width);360+ uint8_t *data = malloc(height * stride);361+ pixman_image_t *scaled_png = pixman_image_create_bits_no_clear(362+ fmt, width, height, (uint32_t *)data, stride);363+ pixman_image_composite32(364+ PIXMAN_OP_SRC, png, NULL, scaled_png, 0, 0, 0, 0, 0, 0, width, height);365+366+ free(pixman_image_get_data(png));367+ pixman_image_unref(png);368+369+ png = scaled_png;370+ icon->png = png;371 }372 373 pixman_image_composite32(374 PIXMAN_OP_OVER, png, NULL, buf->pix,12 unmodified lines387 #if defined(FUZZEL_ENABLE_SVG)388 RsvgDimensionData dim;389 rsvg_handle_get_dimensions(icon->svg, &dim);390 369- double height = font->height;391+ double height = min(row_height, font->height);392 double scale = height / dim.height;393 394 double img_x = cur_x;395 double img_y = first_row + i * row_height + (row_height - height) / 2;19 unmodified lines415 break;416 }417 }418 397- cur_x += row_height;419+ cur_x += row_height + font->space_advance.x + pt_or_px_as_pixels(420+ &render->options.letter_spacing, render->dpi);421 422 /* Application title */423 render_match_text(424 buf, &cur_x, y,425 match->application->title, match->start_title, wcslen(prompt_text(prompt)),426 font, subpixel,427+ pt_or_px_as_pixels(&render->options.letter_spacing, render->dpi),428 render->options.pix_text_color, render->options.pix_match_color);429 430 y += row_height;431 }6 unmodified lines438 *render = (struct render){439 .options = *options,440 };441 418- /* TODO: the one providing the options should calculate these */442+ /* TODO: the one providing the opti3Dons should calculate these */443 render->options.pix_background_color = rgba2pixman(render->options.background_color);444 render->options.pix_border_color = rgba2pixman(render->options.border_color);445 render->options.pix_text_color = rgba2pixman(render->options.text_color);446 render->options.pix_match_color = rgba2pixman(render->options.match_color);7 unmodified lines454 render->subpixel = subpixel;455 }456 457 bool434-render_set_font(struct render *render, struct fcft_font *font, int scale,458+render_set_font(struct render *render, struct fcft_font *font,459+ int scale, float dpi,460 int *new_width, int *new_height)461 {462 if (font != NULL) {463 fcft_destroy(render->font);2 unmodified lines466 assert(render->font != NULL);467 font = render->font;468 }469 445-#define max(x, y) ((x) > (y) ? (x) : (y))470+ const struct fcft_glyph *W = fcft_glyph_rasterize(471+ font, L'W', render->subpixel);472 447- const unsigned y_margin = max(1, (double)font->height / 10.);448- const unsigned x_margin = font->height * 2;473+ const unsigned x_margin = render->options.pad.x * scale;474+ const unsigned y_margin = render->options.pad.y * scale;475 450-#undef max451-476 const unsigned border_size = render->options.border_size * scale;453- const unsigned row_height = 2 * y_margin + font->height;477 478+ const unsigned row_height = render->options.line_height.px >= 0479+ ? pt_or_px_as_pixels(&render->options.line_height, dpi)480+ : font->height;481+482 const unsigned height =483 border_size + /* Top border */484+ y_margin +485 row_height + /* The prompt */486 render->options.lines * row_height + /* Matches */459- + row_height / 2 + /* Spacing at the bottom */487+ y_margin +488 border_size; /* Bottom border */489 462- const struct fcft_glyph *M = fcft_glyph_rasterize(463- font, L'W', render->subpixel);464-490 const unsigned width =466- border_size + x_margin +467- M->advance.x * render->options.chars +468- x_margin + border_size;491+ border_size +492+ x_margin +493+ (max((W->advance.x + pt_or_px_as_pixels(494+ &render->options.letter_spacing, dpi)), 0)495+ * render->options.chars) +496+ x_margin +497+ border_size;498 499 LOG_DBG("x-margin: %d, y-margin: %d, border: %d, row-height: %d, "500 "height: %d, width: %d, scale: %d",501 x_margin, y_margin, border_size, row_height, height, width, scale);1 unmodified line503 render->y_margin = y_margin;504 render->x_margin = x_margin;505 render->border_size = border_size;506 render->row_height = row_height;507+ render->dpi = dpi;508+509 if (new_width != NULL)510 *new_width = width;511 if (new_height != NULL)512 *new_height = height;13 unmodified linesmodified:render.h+10 added-1 removed
7 unmodified lines8 #include "match.h"9 #include "tllist.h"10 11 struct rgba {double r; double g; double b; double a;};12+struct pt_or_px {int px; float pt;};13 14 struct render_options {15 unsigned lines;16 unsigned chars;17 unsigned border_size;18 unsigned border_radius;19+ struct {20+ unsigned x;21+ unsigned y;22+ } pad;23 24 struct rgba background_color;25 struct rgba border_color;26 struct rgba text_color;27 struct rgba match_color;28 struct rgba selection_color;29 30+ struct pt_or_px line_height;31+ struct pt_or_px letter_spacing;32+33 /* Filled in by render, for now */34 pixman_color_t pix_background_color;35 pixman_color_t pix_border_color;36 pixman_color_t pix_text_color;5 unmodified lines42 struct render *render_init(const struct render_options *options);43 void render_destroy(struct render *render);44 45 void render_set_subpixel(struct render *render, enum fcft_subpixel subpixel);38-bool render_set_font(struct render *render, struct fcft_font *font, int scale,46+bool render_set_font(struct render *render, struct fcft_font *font,47+ int scale, float dpi,48 int *new_width, int *new_height);49 50 void render_background(const struct render *render, struct buffer *buf);51 7 unmodified linesmodified:wayland.c+4 added-4 removed
139 unmodified lines140 struct render *render;141 struct prompt *prompt;142 struct matches *matches;143 144+ const struct render_options *render_options;145+146+ char *font_name;147 struct {148 font_reloaded_t cb;149 void *data;150 } font_reloaded;151 149- const struct render_options *render_options;150- char *font_name;151-152 int width;153 int height;154 int scale;155 float dpi;682 unmodified lines838 wayl->font_reloaded.cb(wayl, font, wayl->font_reloaded.data);839 }840 841 return render_set_font(842- wayl->render, font, new_scale, &wayl->width, &wayl->height);842+ wayl->render, font, new_scale, new_dpi, &wayl->width, &wayl->height);843 }844 845 static float846 wayl_ppi(const struct wayland *wayl)767 unmodified lines