Skip to content

Commit

Permalink
Fix broken line spacing with some fonts.
Browse files Browse the repository at this point in the history
I had misunderstood the purpose of the OpenType line gap field 'hlgp'. I
thought this was a suggested total line spacing, but it's actually extra
spacing to be added to (ascender - descender).
  • Loading branch information
philj56 committed Apr 10, 2023
1 parent 2f29475 commit ae8c8e3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/entry_backend/harfbuzz.c
Original file line number Diff line number Diff line change
Expand Up @@ -601,9 +601,10 @@ void entry_backend_harfbuzz_init(

}

if (hb->hb_font_extents.line_gap == 0) {
hb->hb_font_extents.line_gap = (hb->hb_font_extents.ascender - hb->hb_font_extents.descender);
}
hb->line_spacing =
hb->hb_font_extents.ascender
- hb->hb_font_extents.descender
+ hb->hb_font_extents.line_gap;

log_debug("Creating Harfbuzz buffer.\n");
hb->hb_buffer = hb_buffer_create();
Expand Down Expand Up @@ -734,7 +735,7 @@ void entry_backend_harfbuzz_update(struct entry *entry)
if (entry->horizontal) {
cairo_translate(cr, extents.x_advance + entry->result_spacing, 0);
} else {
cairo_translate(cr, 0, entry->harfbuzz.hb_font_extents.line_gap / 64.0 + entry->result_spacing);
cairo_translate(cr, 0, entry->harfbuzz.line_spacing / 64.0 + entry->result_spacing);
}
if (entry->num_results == 0) {
if (size_overflows(entry, 0, 0)) {
Expand Down Expand Up @@ -780,7 +781,7 @@ void entry_backend_harfbuzz_update(struct entry *entry)
* The height of the text doesn't change, so
* we don't need to re-measure it each time.
*/
if (size_overflows(entry, 0, entry->harfbuzz.hb_font_extents.line_gap / 64.0)) {
if (size_overflows(entry, 0, entry->harfbuzz.line_spacing / 64.0)) {
break;
} else {
extents = render_text_themed(cr, entry, result, theme);
Expand Down
1 change: 1 addition & 0 deletions src/entry_backend/harfbuzz.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct entry_backend_harfbuzz {
uint8_t num_variations;
uint8_t num_features;

double line_spacing;
double scale;

bool disable_hinting;
Expand Down

0 comments on commit ae8c8e3

Please sign in to comment.