Merge branch 'text-shaping'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Closes #20
authored by Daniel Eklöf · committed by Daniel Eklöf · parents 3e20f5e, bff1475 · Browse files · 5 files·+66 added−15 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+66 added−15 removed
- other:+66 added−15 removed
Provenance
- Commit
62a753b- Tree
a77534c- Author
Daniel Eklöf <daniel@ekloef.se>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent 1
3e20f5e- Parent 2
bff1475
5 files changed+66 added−15 removed
modified:application.c+2 added
244 unmodified lines245 g_object_unref(app->icon.svg);246 #endif247 break;248 }249+250+ fcft_text_run_destroy(app->shaped);251 }252 free(apps->v);253 free(apps);254 }modified:application.h+3 added
5 unmodified lines6 #if defined(FUZZEL_ENABLE_SVG)7 #include <librsvg/rsvg.h>8 #endif9 10+#include <fcft/fcft.h>11+12 #include "prompt.h"13 14 enum icon_type { ICON_NONE, ICON_PNG, ICON_SVG };15 16 unmodified lines32 wchar_t *title;33 wchar_t *comment;34 struct icon icon;35 unsigned count;36+ struct fcft_text_run *shaped;37 };38 39 bool application_execute(40 const struct application *app, const struct prompt *prompt);8 unmodified linesmodified:CHANGELOG.md+8 added
10 unmodified lines111213141516171819202122232425262797 unmodified lines10 unmodified lines
## Unreleased### Added
* Text shaping support (https://codeberg.org/dnkl/fuzzel/issues/20).
### Changed
* fcft >= 2.4.0 is now required.
### Deprecated### Removed### Fixed### Security97 unmodified linesmodified:meson.build+1 added-1 removed
76 unmodified lines77 add_project_arguments('-DFUZZEL_ENABLE_SVG=1', language: 'c')78 endif79 80 tllist = dependency('tllist', version: '>=1.0.1', fallback: 'tllist')81-fcft = dependency('fcft', version: ['>=2.3.90', '<3.0.0'], fallback: 'fcft')81+fcft = dependency('fcft', version: ['>=2.4.0Q', '<3.0.0'], fallback: 'fcft')82 83 wayland_protocols_datadir = wayland_protocols.get_pkgconfig_variable('pkgdatadir')84 85 wscanner = dependency('wayland-scanner', native: true)75 unmodified linesmodified:render.c+52 added-14 removed
203 unmodified lines204 render_match_text(struct buffer *buf, double *_x, double _y,205 const wchar_t *text, ssize_t start, size_t length,206 struct fcft_font *font, enum fcft_subpixel subpixel,207 int letter_spacing,208- pixman_color_t regular_color, pixman_color_t match_color)208+ pixman_color_t regular_color, pixman_color_t match_color,209+ struct fcft_text_run **run)210 {211 int x = *_x;212 int y = _y;213 213- for (size_t i = 0; i < wcslen(text); i++) {214- const struct fcft_glyph *glyph = fcft_glyph_rasterize(font, text[i], subpixel);215- if (glyph == NULL)216- continue;214+ const struct fcft_glyph **glyphs = NULL;215+ int *clusters = NULL;216+ long *kern = NULL;217+ size_t count = 0;218 218- long x_kern = 0, y_kern = 0;219- if (i > 0)220- fcft_kerning(font, text[i - 1], text[i], &x_kern, &y_kern);219+ if (*run == NULL &&220+ (fcft_capabilities() & FCFT_CAPABILITY_TEXT_RUN_SHAPING))221+ {222+ *run = fcft_text_run_rasterize(font, wcslen(text), text, subpixel);223+ }224 222- bool is_match = start >= 0 && i >= start && i < start + length;223- x += x_kern;224- render_glyph(buf->pix, glyph, x, y + y_kern, is_match ? &match_color : ®ular_color);225- x += glyph->advance.x;226- x += letter_spacing;225+ if (*run != NULL) {226+ glyphs = (*run)->glyphs;227+ clusters = (*run)->cluster;228+ count = (*run)->count;229+ } else {230+ count = wcslen(text);231+ glyphs = malloc(count * sizeof(glyphs[0]));232+ clusters = malloc(count * sizeof(clusters[0]));233+ kern = malloc(count * sizeof(kern[0]));234+235+ for (size_t i = 0; i < count; i++) {236+ const struct fcft_glyph *glyph = fcft_glyph_rasterize(font, text[i], subpixel);237+ if (glyph == NULL) {238+ glyphs[i] = NULL;239+ continue;240+ }241+242+ if (i > 0)243+ fcft_kerning(font, text[i - 1], text[i], &kern[i], NULL);244+ else245+ kern[i] = 0;246+247+ glyphs[i] = glyph;248+ clusters[i] = i;249+ }250 }251 252+ for (size_t i = 0; i < count; i++) {253+ bool is_match = start >= 0 && clusters[i] >= start && clusters[i] < start + length;254+ x += kern != NULL ? kern[i] : 0;255+ render_glyph(buf->pix, glyphs[i], x, y, is_match ? &match_color : ®ular_color);256+ x += glyphs[i]->advance.x + letter_spacing;257+ y += glyphs[i]->advance.y;258+ }259+260+ if (*run == NULL) {261+ free(kern);262+ free(clusters);263+ free(glyphs);264+ }265+266 *_x = x;267 }268 269 void205 unmodified lines475 buf, &cur_x, y,476 match->application->title, match->start_title, wcslen(prompt_text(prompt)),477 font, subpixel,478 pt_or_px_as_pixels(&render->options.letter_spacing, render->dpi),442- render->options.pix_text_color, render->options.pix_match_color);479+ render->options.pix_text_color, render->options.pix_match_color,480+ &match->application->shaped);481 482 y += row_height;483 }484 }97 unmodified lines