ScaledFontMac::~ScaledFontMac() { if (mCTFont) { CFRelease(mCTFont); } CGFontRelease(mFont); }
void drawTextWithSpacing(GraphicsContext* graphicsContext, const SimpleFontData* font, const wxColour& color, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point) { graphicsContext->save(); wxGCDC* dc = static_cast<wxGCDC*>(graphicsContext->platformContext()); wxFont* wxfont = font->getWxFont(); graphicsContext->setFillColor(graphicsContext->fillColor(), ColorSpaceDeviceRGB); CGContextRef cgContext = static_cast<CGContextRef>(dc->GetGraphicsContext()->GetNativeContext()); CGFontRef cgFont = font->platformData().cgFont(); CGContextSetFont(cgContext, cgFont); CGContextSetFontSize(cgContext, wxfont->GetPointSize()); CGFloat red, green, blue, alpha; graphicsContext->fillColor().getRGBA(red, green, blue, alpha); CGContextSetRGBFillColor(cgContext, red, green, blue, alpha); CGAffineTransform matrix = CGAffineTransformIdentity; matrix.b = -matrix.b; matrix.d = -matrix.d; CGContextSetTextMatrix(cgContext, matrix); CGContextSetTextPosition(cgContext, point.x(), point.y()); CGContextShowGlyphsWithAdvances(cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs); if (cgFont) CGFontRelease(cgFont); graphicsContext->restore(); }
static void _cairo_quartz_font_face_destroy (void *abstract_face) { cairo_quartz_font_face_t *font_face = (cairo_quartz_font_face_t*) abstract_face; CGFontRelease (font_face->cgFont); }
void quartz_draw_layout(void *layout, CGContextRef context, CGPoint position) { CGContextSetTextPosition(context, position.x, position.y); CFArrayRef runs = CTLineGetGlyphRuns((CTLineRef)layout); CFIndex run_count = CFArrayGetCount(runs); CFIndex run_index; for (run_index = 0; run_index < run_count; ++run_index) { CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex(runs, run_index); CTFontRef run_font = CFDictionaryGetValue(CTRunGetAttributes(run), kCTFontAttributeName); CGFontRef glyph_font = CTFontCopyGraphicsFont(run_font, NULL); CFIndex glyph_count = CTRunGetGlyphCount(run); CGGlyph glyphs[glyph_count]; CGPoint positions[glyph_count]; CFRange everything = CFRangeMake(0, 0); CTRunGetGlyphs(run, everything, glyphs); CTRunGetPositions(run, everything, positions); CGContextSetFont(context, glyph_font); CGContextSetFontSize(context, CTFontGetSize(run_font)); CGContextShowGlyphsAtPositions(context, glyphs, positions, glyph_count); CGFontRelease(glyph_font); } }
FontCustomPlatformData::~FontCustomPlatformData() { #if defined(BUILDING_ON_TIGER) || defined(BUILDING_ON_LEOPARD) if (m_atsContainer) ATSFontDeactivate(m_atsContainer, NULL, kATSOptionFlagsDefault); #endif CGFontRelease(m_cgFont); }
FontCustomPlatformData::~FontCustomPlatformData() { #if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) // this construct is intentional to match the one in createFontCustomPlatformData below #else if (m_atsContainer) ATSFontDeactivate(m_atsContainer, NULL, kATSOptionFlagsDefault); #endif CGFontRelease(m_cgFont); }
FontCustomPlatformData::~FontCustomPlatformData() { #ifdef BUILDING_ON_LEOPARD if (m_atsContainer) ATSFontDeactivate(m_atsContainer, NULL, kATSOptionFlagsDefault); #endif #if USE(SKIA_ON_MAC_CHROMIUM) SkSafeUnref(m_typeface); #endif CGFontRelease(m_cgFont); }
FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer) { ASSERT_ARG(buffer, buffer); ASSERT(T2embedLibrary()); // Get CG to create the font. CGDataProviderDirectAccessCallbacks callbacks = { &getData, &releaseData, &getBytesWithOffset, NULL }; RetainPtr<CGDataProviderRef> dataProvider(AdoptCF, CGDataProviderCreateDirectAccess(buffer, buffer->size(), &callbacks)); CGFontRef cgFont = CGFontCreateWithDataProvider(dataProvider.get()); if (!cgFont) return 0; // Introduce the font to GDI. AddFontMemResourceEx cannot be used, because it will pollute the process's // font namespace (Windows has no API for creating an HFONT from data without exposing the font to the // entire process first). TTLoadEmbeddedFont lets us override the font family name, so using a unique name // we avoid namespace collisions. String fontName = createUniqueFontName(); // TTLoadEmbeddedFont works only with Embedded OpenType (.eot) data, so we need to create an EOT header // and prepend it to the font data. Vector<UInt8, 512> eotHeader; if (!getEOTHeader(buffer, eotHeader)) { CGFontRelease(cgFont); return 0; } HANDLE fontReference; ULONG privStatus; ULONG status; EOTStream eotStream(eotHeader, buffer); LONG loadEmbeddedFontResult = TTLoadEmbeddedFont(&fontReference, TTLOAD_PRIVATE, &privStatus, LICENSE_PREVIEWPRINT, &status, readEmbedProc, &eotStream, const_cast<LPWSTR>(fontName.charactersWithNullTermination()), 0, 0); if (loadEmbeddedFontResult != E_NONE) { CGFontRelease(cgFont); return 0; } return new FontCustomPlatformData(cgFont, fontReference); }
/** * cairo_quartz_font_face_create_for_atsu_font_id * @font_id: an ATSUFontID for the font. * * Creates a new font for the Quartz font backend based on an * #ATSUFontID. This font can then be used with * cairo_set_font_face() or cairo_scaled_font_create(). * * Return value: a newly created #cairo_font_face_t. Free with * cairo_font_face_destroy() when you are done using it. * * Since: 1.6 **/ cairo_font_face_t * cairo_quartz_font_face_create_for_atsu_font_id (ATSUFontID font_id) { ATSFontRef atsFont = FMGetATSFontRefFromFont (font_id); CGFontRef cgFont = CGFontCreateWithPlatformFont (&atsFont); cairo_font_face_t *ff; ff = cairo_quartz_font_face_create_for_cgfont (cgFont); CGFontRelease (cgFont); return ff; }
SFFontRef SFFontCreateWithFileName(CFStringRef name, CFStringRef extension, CGFloat size) { CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef url = CFBundleCopyResourceURL(mainBundle, name, (CFStringRef)extension, NULL); CGDataProviderRef dataProvider = CGDataProviderCreateWithURL(url); CGFontRef fnt = CGFontCreateWithDataProvider(dataProvider); SFFontRef sfFont = SFFontCreate(fnt, size); CGFontRelease(fnt); CGDataProviderRelease(dataProvider); CFRelease(url); return sfFont; }
/** * cairo_quartz_font_face_create_for_atsu_font_id: * @font_id: an ATSUFontID for the font. * * Creates a new font for the Quartz font backend based on an * #ATSUFontID. This font can then be used with * cairo_set_font_face() or cairo_scaled_font_create(). * * Return value: a newly created #cairo_font_face_t. Free with * cairo_font_face_destroy() when you are done using it. * * Since: 1.6 **/ cairo_font_face_t * cairo_quartz_font_face_create_for_atsu_font_id (ATSUFontID font_id) { quartz_font_ensure_symbols(); if (FMGetATSFontRefFromFontPtr != NULL) { ATSFontRef atsFont = FMGetATSFontRefFromFontPtr (font_id); CGFontRef cgFont = CGFontCreateWithPlatformFont (&atsFont); cairo_font_face_t *ff; ff = cairo_quartz_font_face_create_for_cgfont (cgFont); CGFontRelease (cgFont); return ff; } else { _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); return (cairo_font_face_t *)&_cairo_font_face_nil; } }
void SFFontRelease(SFFontRef sfFont) { if (!sfFont) { return; } sfFont->_retainCount--; if (sfFont->_retainCount == 0) { #ifdef SF_IOS_CG if (sfFont->_cgFont) { CGFontRelease(sfFont->_cgFont); } #else if (sfFont->_ftFace) { FT_Done_Face(sfFont->_ftFace); } #endif SFFontTablesRelease(sfFont->_tables); free(sfFont); } }
void SFFontRelease(SFFontRef sfFont) { if (!sfFont) return; sfFont->_retainCount--; if (sfFont->_retainCount == 0) { if (sfFont->_parent) SFFontRelease(sfFont->_parent); else { #ifdef SF_IOS_CG CGFontRelease(sfFont->_cgFont); #else if (sfFont->_ftFace) FT_Done_Face(sfFont->_ftFace); if (sfFont->_ftLib) FT_Done_FreeType(sfFont->_ftLib); #endif if (sfFont->_availableFontTables & itCMAP) SFFreeCMAP(&sfFont->_cmap); if (sfFont->_availableFontTables & itGDEF) SFFreeGDEF(&sfFont->_gdef); if (sfFont->_availableFontTables & itGSUB) SFFreeGSUB(&sfFont->_gsub); if (sfFont->_availableFontTables & itGPOS) SFFreeGPOS(&sfFont->_gpos); } free(sfFont); } }
void drawTextWithSpacing(GraphicsContext* graphicsContext, const SimpleFontData* font, const wxColour& color, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point) { graphicsContext->save(); wxGCDC* dc = static_cast<wxGCDC*>(graphicsContext->platformContext()); wxFont* wxfont = font->getWxFont(); graphicsContext->setFillColor(graphicsContext->fillColor(), DeviceColorSpace); CGContextRef cgContext = static_cast<CGContextRef>(dc->GetGraphicsContext()->GetNativeContext()); CGFontRef cgFont; #ifdef wxOSX_USE_CORE_TEXT && wxOSX_USE_CORE_TEXT cgFont = CTFontCopyGraphicsFont((CTFontRef)wxfont->OSXGetCTFont(), NULL); #else ATSFontRef fontRef; fontRef = FMGetATSFontRefFromFont(wxfont->MacGetATSUFontID()); if (fontRef) cgFont = CGFontCreateWithPlatformFont((void*)&fontRef); #endif CGContextSetFont(cgContext, cgFont); CGContextSetFontSize(cgContext, wxfont->GetPointSize()); CGFloat red, green, blue, alpha; graphicsContext->fillColor().getRGBA(red, green, blue, alpha); CGContextSetRGBFillColor(cgContext, red, green, blue, alpha); CGAffineTransform matrix = CGAffineTransformIdentity; matrix.b = -matrix.b; matrix.d = -matrix.d; CGContextSetTextMatrix(cgContext, matrix); CGContextSetTextPosition(cgContext, point.x(), point.y()); const FloatSize* advanceSizes = static_cast<const FloatSize*>(glyphBuffer.advances(from)); int size = glyphBuffer.size() - from; CGSize sizes[size]; CGGlyph glyphs[numGlyphs]; // if the function doesn't exist, we're probably on tiger and need to grab the // function under its old name, CGFontGetGlyphsForUnicodes if (!CGFontGetGlyphsForUnichars) CGFontGetGlyphsForUnichars = (CGFontGetGlyphsForUnicharsPtr)dlsym(RTLD_DEFAULT, "CGFontGetGlyphsForUnicodes"); // Let's make sure we got the function under one name or another! ASSERT(CGFontGetGlyphsForUnichars); CGFontGetGlyphsForUnichars(cgFont, glyphBuffer.glyphs(from), glyphs, numGlyphs); for (int i = 0; i < size; i++) { FloatSize fsize = advanceSizes[i]; sizes[i] = CGSizeMake(fsize.width(), fsize.height()); } CGContextShowGlyphsWithAdvances(cgContext, glyphs, sizes, numGlyphs); if (cgFont) CGFontRelease(cgFont); graphicsContext->restore(); }
void CQuartz2D::DestroyFont(void* pFont) { CGFontRelease((CGFontRef)pFont); }
FontCustomPlatformData::~FontCustomPlatformData() { ATSFontDeactivate(m_atsContainer, NULL, kATSOptionFlagsDefault); CGFontRelease(m_cgFont); }
static cairo_status_t _cairo_quartz_font_face_create_for_toy (cairo_toy_font_face_t *toy_face, cairo_font_face_t **font_face) { const char *family; char *full_name; CFStringRef cgFontName = NULL; CGFontRef cgFont = NULL; int loop; quartz_font_ensure_symbols(); if (! _cairo_quartz_font_symbols_present) return _cairo_error (CAIRO_STATUS_NO_MEMORY); family = toy_face->family; full_name = malloc (strlen (family) + 64); // give us a bit of room to tack on Bold, Oblique, etc. /* handle CSS-ish faces */ if (!strcmp(family, "serif") || !strcmp(family, "Times Roman")) family = "Times"; else if (!strcmp(family, "sans-serif") || !strcmp(family, "sans")) family = "Helvetica"; else if (!strcmp(family, "cursive")) family = "Apple Chancery"; else if (!strcmp(family, "fantasy")) family = "Papyrus"; else if (!strcmp(family, "monospace") || !strcmp(family, "mono")) family = "Courier"; /* Try to build up the full name, e.g. "Helvetica Bold Oblique" first, * then drop the bold, then drop the slant, then drop both.. finally * just use "Helvetica". And if Helvetica doesn't exist, give up. */ for (loop = 0; loop < 5; loop++) { if (loop == 4) family = "Helvetica"; strcpy (full_name, family); if (loop < 3 && (loop & 1) == 0) { if (toy_face->weight == CAIRO_FONT_WEIGHT_BOLD) strcat (full_name, " Bold"); } if (loop < 3 && (loop & 2) == 0) { if (toy_face->slant == CAIRO_FONT_SLANT_ITALIC) strcat (full_name, " Italic"); else if (toy_face->slant == CAIRO_FONT_SLANT_OBLIQUE) strcat (full_name, " Oblique"); } if (CGFontCreateWithFontNamePtr) { cgFontName = CFStringCreateWithCString (NULL, full_name, kCFStringEncodingASCII); cgFont = CGFontCreateWithFontNamePtr (cgFontName); CFRelease (cgFontName); } else { cgFont = CGFontCreateWithNamePtr (full_name); } if (cgFont) break; } if (!cgFont) { /* Give up */ return _cairo_error (CAIRO_STATUS_NO_MEMORY); } *font_face = cairo_quartz_font_face_create_for_cgfont (cgFont); CGFontRelease (cgFont); return CAIRO_STATUS_SUCCESS; }
bool sdl_osd_interface::font_get_bitmap(osd_font font, unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs) { UniChar uni_char; CGGlyph glyph; CTFontRef ct_font = (CTFontRef)font; const CFIndex count = 1; CGRect bounding_rect, success_rect; CGContextRef context_ref; if( chnum == ' ' ) { uni_char = 'n'; CTFontGetGlyphsForCharacters( ct_font, &uni_char, &glyph, count ); success_rect = CTFontGetBoundingRectsForGlyphs( ct_font, kCTFontDefaultOrientation, &glyph, &bounding_rect, count ); uni_char = chnum; CTFontGetGlyphsForCharacters( ct_font, &uni_char, &glyph, count ); } else { uni_char = chnum; CTFontGetGlyphsForCharacters( ct_font, &uni_char, &glyph, count ); success_rect = CTFontGetBoundingRectsForGlyphs( ct_font, kCTFontDefaultOrientation, &glyph, &bounding_rect, count ); } if( CGRectEqualToRect( success_rect, CGRectNull ) == false ) { size_t bitmap_width; size_t bitmap_height; bitmap_width = ceilf(bounding_rect.size.width * EXTRA_WIDTH); bitmap_width = bitmap_width == 0 ? 1 : bitmap_width; bitmap_height = ceilf( (CTFontGetAscent(ct_font) + CTFontGetDescent(ct_font) + CTFontGetLeading(ct_font)) * EXTRA_HEIGHT); xoffs = yoffs = 0; width = bitmap_width; size_t bits_per_component; CGColorSpaceRef color_space; CGBitmapInfo bitmap_info = kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst; color_space = CGColorSpaceCreateDeviceRGB(); bits_per_component = 8; bitmap.allocate(bitmap_width, bitmap_height); context_ref = CGBitmapContextCreate( bitmap.raw_pixptr(0), bitmap_width, bitmap_height, bits_per_component, bitmap.rowpixels()*4, color_space, bitmap_info ); if( context_ref != NULL ) { CGFontRef font_ref; font_ref = CTFontCopyGraphicsFont( ct_font, NULL ); CGContextSetTextPosition(context_ref, -bounding_rect.origin.x*EXTRA_WIDTH, CTFontGetDescent(ct_font)+CTFontGetLeading(ct_font) ); CGContextSetRGBFillColor(context_ref, 1.0, 1.0, 1.0, 1.0); CGContextSetFont( context_ref, font_ref ); CGContextSetFontSize( context_ref, POINT_SIZE ); CGContextShowGlyphs( context_ref, &glyph, count ); CGFontRelease( font_ref ); CGContextRelease( context_ref ); } CGColorSpaceRelease( color_space ); } return bitmap.valid(); }
ScaledFontMac::~ScaledFontMac() { CGFontRelease(mFont); }