/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// We create a CFDataRef here that we'l hold until we've determined that we // have a valid font. If and only if we can create a font from the data, // we'll store the font data in our map. Whether or not the font is valid, // we'll later release this CFDataRef.
CFDataRef data = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, fontData,
aDataLength, allocator); if (!data) {
free(fontData); return nullptr;
}
// creating the CGFontRef via the CTFont avoids the data being held alive // in a cache.
CTFontRef ctFont = CTFontCreateWithFontDescriptor(ctFontDesc, 0, NULL);
// Creating the CGFont from the CTFont prevents the font data from being // held in the TDescriptorSource cache. This appears to be true even // if we later create a CTFont from the CGFont.
CGFontRef fontRef = CTFontCopyGraphicsFont(ctFont, NULL);
CFRelease(ctFont);
if (!fontRef) { // Not a valid font; release the structures we've been holding.
CFRelease(data);
CFRelease(ctFontDesc); return nullptr;
}
// Determine the font name and store it with the font data in the map.
nsAutoCStringN<FONT_NAME_MAX> fontName;
{ auto fontMap = sWeakFontDataMap.Lock(); void* key = (void*)fontData;
fontMap->insert({key, fontName});
} // It's now safe to release our CFDataRef.
CFRelease(data);
// passes ownership of fontRef to the NativeFontResourceMac instance
RefPtr<NativeFontResourceMac> fontResource = new NativeFontResourceMac(ctFontDesc, fontRef, aDataLength);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.