⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simplefontdatamac.mm

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 MM
📖 第 1 页 / 共 2 页
字号:
#ifdef BUILDING_ON_TIGER    wkGetFontMetrics(m_font.cgFont(), &iAscent, &iDescent, &iLineGap, &m_unitsPerEm);#else    iAscent = CGFontGetAscent(m_font.cgFont());    iDescent = CGFontGetDescent(m_font.cgFont());    iLineGap = CGFontGetLeading(m_font.cgFont());    m_unitsPerEm = CGFontGetUnitsPerEm(m_font.cgFont());#endif    float pointSize = m_font.m_size;    float fAscent = scaleEmToUnits(iAscent, m_unitsPerEm) * pointSize;    float fDescent = -scaleEmToUnits(iDescent, m_unitsPerEm) * pointSize;    float fLineGap = scaleEmToUnits(iLineGap, m_unitsPerEm) * pointSize;    // We need to adjust Times, Helvetica, and Courier to closely match the    // vertical metrics of their Microsoft counterparts that are the de facto    // web standard. The AppKit adjustment of 20% is too big and is    // incorrectly added to line spacing, so we use a 15% adjustment instead    // and add it to the ascent.    NSString *familyName = [m_font.font() familyName];    if ([familyName isEqualToString:@"Times"] || [familyName isEqualToString:@"Helvetica"] || [familyName isEqualToString:@"Courier"])        fAscent += floorf(((fAscent + fDescent) * 0.15f) + 0.5f);    else if ([familyName isEqualToString:@"Geeza Pro"]) {        // Geeza Pro has glyphs that draw slightly above the ascent or far below the descent. Adjust        // those vertical metrics to better match reality, so that diacritics at the bottom of one line        // do not overlap diacritics at the top of the next line.        fAscent *= 1.08f;        fDescent *= 2.f;    }    m_ascent = lroundf(fAscent);    m_descent = lroundf(fDescent);    m_lineGap = lroundf(fLineGap);    m_lineSpacing = m_ascent + m_descent + m_lineGap;        // Hack Hiragino line metrics to allow room for marked text underlines.    // <rdar://problem/5386183>    if (m_descent < 3 && m_lineGap >= 3 && [familyName hasPrefix:@"Hiragino"]) {        m_lineGap -= 3 - m_descent;        m_descent = 3;    }        // Measure the actual character "x", because AppKit synthesizes X height rather than getting it from the font.    // Unfortunately, NSFont will round this for us so we don't quite get the right value.    GlyphPage* glyphPageZero = GlyphPageTreeNode::getRootChild(this, 0)->page();    NSGlyph xGlyph = glyphPageZero ? glyphPageZero->glyphDataForCharacter('x').glyph : 0;    if (xGlyph) {        NSRect xBox = [m_font.font() boundingRectForGlyph:xGlyph];        // Use the maximum of either width or height because "x" is nearly square        // and web pages that foolishly use this metric for width will be laid out        // poorly if we return an accurate height. Classic case is Times 13 point,        // which has an "x" that is 7x6 pixels.        m_xHeight = MAX(NSMaxX(xBox), NSMaxY(xBox));    } else        m_xHeight = [m_font.font() xHeight];}void SimpleFontData::platformDestroy(){#ifdef BUILDING_ON_TIGER    if (m_styleGroup)        wkReleaseStyleGroup(m_styleGroup);#endif#if USE(ATSUI)    if (m_ATSUStyleInitialized)        ATSUDisposeStyle(m_ATSUStyle);#endif}SimpleFontData* SimpleFontData::smallCapsFontData(const FontDescription& fontDescription) const{    if (!m_smallCapsFontData) {        if (isCustomFont()) {            FontPlatformData smallCapsFontData(m_font);            smallCapsFontData.m_size = smallCapsFontData.m_size * smallCapsFontSizeMultiplier;            m_smallCapsFontData = new SimpleFontData(smallCapsFontData, true, false);        } else {            BEGIN_BLOCK_OBJC_EXCEPTIONS;            float size = [m_font.font() pointSize] * smallCapsFontSizeMultiplier;            FontPlatformData smallCapsFont([[NSFontManager sharedFontManager] convertFont:m_font.font() toSize:size]);                        // AppKit resets the type information (screen/printer) when you convert a font to a different size.            // We have to fix up the font that we're handed back.            smallCapsFont.setFont(fontDescription.usePrinterFont() ? [smallCapsFont.font() printerFont] : [smallCapsFont.font() screenFont]);            if (smallCapsFont.font()) {                NSFontManager *fontManager = [NSFontManager sharedFontManager];                NSFontTraitMask fontTraits = [fontManager traitsOfFont:m_font.font()];                if (m_font.m_syntheticBold)                    fontTraits |= NSBoldFontMask;                if (m_font.m_syntheticOblique)                    fontTraits |= NSItalicFontMask;                NSFontTraitMask smallCapsFontTraits = [fontManager traitsOfFont:smallCapsFont.font()];                smallCapsFont.m_syntheticBold = (fontTraits & NSBoldFontMask) && !(smallCapsFontTraits & NSBoldFontMask);                smallCapsFont.m_syntheticOblique = (fontTraits & NSItalicFontMask) && !(smallCapsFontTraits & NSItalicFontMask);                m_smallCapsFontData = fontCache()->getCachedFontData(&smallCapsFont);            }            END_BLOCK_OBJC_EXCEPTIONS;        }    }    return m_smallCapsFontData;}bool SimpleFontData::containsCharacters(const UChar* characters, int length) const{    NSString *string = [[NSString alloc] initWithCharactersNoCopy:const_cast<unichar*>(characters) length:length freeWhenDone:NO];    NSCharacterSet *set = [[m_font.font() coveredCharacterSet] invertedSet];    bool result = set && [string rangeOfCharacterFromSet:set].location == NSNotFound;    [string release];    return result;}void SimpleFontData::determinePitch(){    NSFont* f = m_font.font();    // Special case Osaka-Mono.    // According to <rdar://problem/3999467>, we should treat Osaka-Mono as fixed pitch.    // Note that the AppKit does not report Osaka-Mono as fixed pitch.    // Special case MS-PGothic.    // According to <rdar://problem/4032938>, we should not treat MS-PGothic as fixed pitch.    // Note that AppKit does report MS-PGothic as fixed pitch.    // Special case MonotypeCorsiva    // According to <rdar://problem/5454704>, we should not treat MonotypeCorsiva as fixed pitch.    // Note that AppKit does report MonotypeCorsiva as fixed pitch.    NSString *name = [f fontName];    m_treatAsFixedPitch = ([f isFixedPitch] || [f _isFakeFixedPitch] ||           [name caseInsensitiveCompare:@"Osaka-Mono"] == NSOrderedSame) &&           [name caseInsensitiveCompare:@"MS-PGothic"] != NSOrderedSame &&           [name caseInsensitiveCompare:@"MonotypeCorsiva"] != NSOrderedSame;}float SimpleFontData::platformWidthForGlyph(Glyph glyph) const{    NSFont* font = m_font.font();    float pointSize = m_font.m_size;    CGAffineTransform m = CGAffineTransformMakeScale(pointSize, pointSize);    CGSize advance;    if (!wkGetGlyphTransformedAdvances(m_font.cgFont(), font, &m, &glyph, &advance)) {        LOG_ERROR("Unable to cache glyph widths for %@ %f", [font displayName], pointSize);        advance.width = 0;    }    return advance.width + m_syntheticBoldOffset;}#if USE(ATSUI)void SimpleFontData::checkShapesArabic() const{    ASSERT(!m_checkedShapesArabic);    m_checkedShapesArabic = true;        ATSUFontID fontID = m_font.m_atsuFontID;    if (!fontID) {        LOG_ERROR("unable to get ATSUFontID for %@", m_font.font());        return;    }    // This function is called only on fonts that contain Arabic glyphs. Our    // heuristic is that if such a font has a glyph metamorphosis table, then    // it includes shaping information for Arabic.    FourCharCode tables[] = { 'morx', 'mort' };    for (unsigned i = 0; i < sizeof(tables) / sizeof(tables[0]); ++i) {        ByteCount tableSize;        OSStatus status = ATSFontGetTable(fontID, tables[i], 0, 0, 0, &tableSize);        if (status == noErr) {            m_shapesArabic = true;            return;        }        if (status != kATSInvalidFontTableAccess)            LOG_ERROR("ATSFontGetTable failed (%d)", status);    }}#endif#if USE(CORE_TEXT)CTFontRef SimpleFontData::getCTFont() const{    if (getNSFont())        return toCTFontRef(getNSFont());    if (!m_CTFont)        m_CTFont.adoptCF(CTFontCreateWithGraphicsFont(m_font.cgFont(), m_font.size(), NULL, NULL));    return m_CTFont.get();}CFDictionaryRef SimpleFontData::getCFStringAttributes() const{    if (m_CFStringAttributes)        return m_CFStringAttributes.get();    static const float kerningAdjustmentValue = 0;    static CFNumberRef kerningAdjustment = CFNumberCreate(kCFAllocatorDefault, kCFNumberFloatType, &kerningAdjustmentValue);    static const int ligaturesNotAllowedValue = 0;    static CFNumberRef ligaturesNotAllowed = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &ligaturesNotAllowedValue);    static const int ligaturesAllowedValue = 1;    static CFNumberRef ligaturesAllowed = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &ligaturesAllowedValue);    static const void* attributeKeys[] = { kCTFontAttributeName, kCTKernAttributeName, kCTLigatureAttributeName };    const void* attributeValues[] = { getCTFont(), kerningAdjustment, platformData().allowsLigatures() ? ligaturesAllowed : ligaturesNotAllowed };    m_CFStringAttributes.adoptCF(CFDictionaryCreate(NULL, attributeKeys, attributeValues, sizeof(attributeKeys) / sizeof(*attributeKeys), &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));    return m_CFStringAttributes.get();}#endif} // namespace WebCore

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -