|
| 1 | +diff --git a/src/macfont.m b/src/macfont.m |
| 2 | +index 91ff2f0..fc522f7 100644 |
| 3 | +--- a/src/macfont.m |
| 4 | ++++ b/src/macfont.m |
| 5 | +@@ -2563,6 +2563,12 @@ So we use CTFontDescriptorCreateMatchingFontDescriptor (no |
| 6 | + unblock_input (); |
| 7 | + } |
| 8 | + |
| 9 | ++static short |
| 10 | ++read_short_from_os2_table(const UInt8* p) |
| 11 | ++{ |
| 12 | ++ return (p[0] << 8) | p[1]; |
| 13 | ++} |
| 14 | ++ |
| 15 | + static Lisp_Object |
| 16 | + macfont_open (struct frame * f, Lisp_Object entity, int pixel_size) |
| 17 | + { |
| 18 | +@@ -2711,6 +2717,36 @@ So we use CTFontDescriptorCreateMatchingFontDescriptor (no |
| 19 | + } |
| 20 | + CFRelease (family_name); |
| 21 | + } |
| 22 | ++ |
| 23 | ++ // https://github.com/WebKit/WebKit/blob/4e349ca/Source/WebCore/platform/graphics/coretext/FontCoreText.cpp#L166 |
| 24 | ++ CFDataRef os2Table = CTFontCopyTable (macfont, kCTFontTableOS2, kCTFontTableOptionNoOptions); |
| 25 | ++ if (os2Table) |
| 26 | ++ { |
| 27 | ++ // For the structure of the OS/2 table, see |
| 28 | ++ // https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6OS2.html |
| 29 | ++ const CFIndex fsSelectionOffset = 16 * 2 + 10 + 4 * 4 + 4 * 1; |
| 30 | ++ const CFIndex sTypoAscenderOffset = fsSelectionOffset + 3 * 2; |
| 31 | ++ const CFIndex sTypoDescenderOffset = sTypoAscenderOffset + 2; |
| 32 | ++ const CFIndex sTypoLineGapOffset = sTypoDescenderOffset + 2; |
| 33 | ++ if (CFDataGetLength (os2Table) >= sTypoLineGapOffset + 2) |
| 34 | ++ { |
| 35 | ++ const UInt8* os2Data = CFDataGetBytePtr (os2Table); |
| 36 | ++ // We test the use typo bit on the least significant byte of fsSelection. |
| 37 | ++ //const UInt8 useTypoMetricsMask = 1 << 7; |
| 38 | ++ //if (*(os2Data + fsSelectionOffset + 1) & useTypoMetricsMask) |
| 39 | ++ // -- XXX: often fonts don't set USE_TYPO_METRICS bit, so just ignore it |
| 40 | ++ { |
| 41 | ++ CGFloat unitsPerEm = (CGFloat) CTFontGetUnitsPerEm (macfont); |
| 42 | ++ short sTypoAscender = read_short_from_os2_table (os2Data + sTypoAscenderOffset); |
| 43 | ++ short sTypoDescender = read_short_from_os2_table (os2Data + sTypoDescenderOffset); |
| 44 | ++ short sTypoLineGap = read_short_from_os2_table (os2Data + sTypoLineGapOffset); |
| 45 | ++ ascent = font->pixel_size * sTypoAscender / unitsPerEm; |
| 46 | ++ descent = - font->pixel_size * sTypoDescender / unitsPerEm; |
| 47 | ++ leading = font->pixel_size * sTypoLineGap / unitsPerEm; |
| 48 | ++ } |
| 49 | ++ } |
| 50 | ++ CFRelease(os2Table); |
| 51 | ++ } |
| 52 | + } |
| 53 | + font->ascent = ascent + 0.5f; |
| 54 | + val = assq_no_quit (QCminspace, AREF (entity, FONT_EXTRA_INDEX)); |
0 commit comments