apple: fix some coretext alignment and rendering issues

This commit is contained in:
Eric Warmenhoven 2025-07-08 23:48:50 -04:00
parent d4fe2055f9
commit 47bc1188ae
No known key found for this signature in database
1 changed files with 5 additions and 9 deletions

View File

@ -209,9 +209,6 @@ static bool coretext_font_renderer_render_glyph(CTFontRef face, ct_font_renderer
CGRect bounds; CGRect bounds;
CGSize advance; CGSize advance;
CGContextRef offscreen; CGContextRef offscreen;
CFDictionaryRef attr;
CFTypeRef values[1] = {face};
CFStringRef keys[1] = {kCTFontAttributeName};
void *bitmapData; void *bitmapData;
UniChar character = (UniChar)charcode; UniChar character = (UniChar)charcode;
CFStringRef glyph_cfstr; CFStringRef glyph_cfstr;
@ -221,7 +218,6 @@ static bool coretext_font_renderer_render_glyph(CTFontRef face, ct_font_renderer
const uint8_t *src; const uint8_t *src;
unsigned r, c; unsigned r, c;
/* Get glyph for character */ /* Get glyph for character */
bool has_glyph = CTFontGetGlyphsForCharacters(face, &character, &glyph, 1); bool has_glyph = CTFontGetGlyphsForCharacters(face, &character, &glyph, 1);
@ -270,10 +266,10 @@ static bool coretext_font_renderer_render_glyph(CTFontRef face, ct_font_renderer
&glyph, &advance, 1); &glyph, &advance, 1);
/* Set up glyph metrics using cached ascent */ /* Set up glyph metrics using cached ascent */
slot->glyph.draw_offset_x = (int)floor(bounds.origin.x); slot->glyph.draw_offset_x = (int)ceil(bounds.origin.x);
slot->glyph.draw_offset_y = (int)floor(-handle->cached_ascent); slot->glyph.draw_offset_y = (int)floor(-bounds.origin.y) - (int)floor(handle->cached_ascent) + 1;
slot->glyph.advance_x = (int)ceil(advance.width); slot->glyph.advance_x = (int)round(advance.width);
slot->glyph.advance_y = (int)ceil(advance.height); slot->glyph.advance_y = (int)round(advance.height);
/* Create bitmap context */ /* Create bitmap context */
bitmapData = calloc(slot->glyph.height, slot->glyph.width); bitmapData = calloc(slot->glyph.height, slot->glyph.width);
@ -296,7 +292,7 @@ static bool coretext_font_renderer_render_glyph(CTFontRef face, ct_font_renderer
CFRelease(attrString); CFRelease(attrString);
/* Render glyph */ /* Render glyph */
CGContextSetTextPosition(offscreen, -bounds.origin.x, CTFontGetDescent(face)); CGContextSetTextPosition(offscreen, -bounds.origin.x, -bounds.origin.y);
CTLineDraw(line, offscreen); CTLineDraw(line, offscreen);
CFRelease(line); CFRelease(line);