A better (I hope) cell height calculation on OS X

See #42
This commit is contained in:
Kovid Goyal
2017-01-24 08:01:36 +05:30
parent 9f3d6fe0e9
commit 598c5d313b
2 changed files with 7 additions and 3 deletions

View File

@@ -134,7 +134,12 @@ cell_size(Face *self) {
if (w > width) width = w;
}
}
return Py_BuildValue("I", width);
// See https://stackoverflow.com/questions/5511830/how-does-line-spacing-work-in-core-text-and-why-is-it-different-from-nslayoutm
CGFloat leading = MAX(0, self->leading);
leading = floor(leading + 0.5);
CGFloat line_height = floor(self->ascent + 0.5) + floor(self->descent + 0.5) + leading;
CGFloat ascender_delta = (leading > 0) ? 0 : floor(0.2 * line_height + 0.5);
return Py_BuildValue("II", width, (unsigned int)(line_height + ascender_delta));
#undef count
}