macOS: Fix wide characters having their right edges slightly truncated
This commit is contained in:
parent
678bd97e1f
commit
ddcd4daede
@ -123,14 +123,13 @@ cell_size(Face *self) {
|
|||||||
#define count (128 - 32)
|
#define count (128 - 32)
|
||||||
unichar chars[count+1] = {0};
|
unichar chars[count+1] = {0};
|
||||||
CGGlyph glyphs[count+1] = {0};
|
CGGlyph glyphs[count+1] = {0};
|
||||||
for (int i = 0; i < count; i++) chars[i] = 32 + i;
|
unsigned int width = 0, w, i;
|
||||||
|
for (i = 0; i < count; i++) chars[i] = 32 + i;
|
||||||
CTFontGetGlyphsForCharacters(self->font, chars, glyphs, count);
|
CTFontGetGlyphsForCharacters(self->font, chars, glyphs, count);
|
||||||
CGSize advances[1] = {0};
|
for (i = 0; i < count; i++) {
|
||||||
unsigned int width = 0, w;
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
if (glyphs[i]) {
|
if (glyphs[i]) {
|
||||||
CTFontGetAdvancesForGlyphs(self->font, kCTFontOrientationHorizontal, glyphs+1, advances, 1);
|
w = (unsigned int)(ceilf(
|
||||||
w = (unsigned int)(ceilf(advances[0].width));
|
CTFontGetAdvancesForGlyphs(self->font, kCTFontOrientationHorizontal, glyphs+i, NULL, 1)));
|
||||||
if (w > width) width = w;
|
if (w > width) width = w;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -177,9 +176,8 @@ render_char(Face *self, PyObject *args) {
|
|||||||
// TODO: Scale the glyph if its bbox is larger than the image by using a non-identity transform
|
// TODO: Scale the glyph if its bbox is larger than the image by using a non-identity transform
|
||||||
/* CGRect rect = CTFontGetBoundingRectsForGlyphs(font, kCTFontOrientationHorizontal, glyphs, 0, 1); */
|
/* CGRect rect = CTFontGetBoundingRectsForGlyphs(font, kCTFontOrientationHorizontal, glyphs, 0, 1); */
|
||||||
CGContextSetTextMatrix(ctx, transform);
|
CGContextSetTextMatrix(ctx, transform);
|
||||||
CGFloat leading = self->leading > 0 ? self->leading : 1; // Ensure at least one pixel of leading so that antialiasing works at the left edge
|
CGFloat pos_y = height - self->ascent;
|
||||||
CGFloat pos_x = leading, pos_y = height - self->ascent;
|
CGContextSetTextPosition(ctx, 0, pos_y);
|
||||||
CGContextSetTextPosition(ctx, pos_x, pos_y);
|
|
||||||
CTFontDrawGlyphs(font, &glyph, &CGPointZero, 1, ctx);
|
CTFontDrawGlyphs(font, &glyph, &CGPointZero, 1, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user