/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ /* cairo - a vector graphics library with display and print output * * Copyright � 2008 Mozilla Corporation * * This library is free software; you can redistribute it and/or * modify it either under the terms of the GNU Lesser General Public * License version 2.1 as published by the Free Software Foundation * (the "LGPL") or, at your option, under the terms of the Mozilla * Public License Version 1.1 (the "MPL"). If you do not alter this * notice, a recipient may use your version of this file under either * the MPL or the LGPL. * * You should have received a copy of the LGPL along with this library * in the file COPYING-LGPL-2.1; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA * You should have received a copy of the MPL along with this library * in the file COPYING-MPL-1.1 * * The contents of this file are subject to the Mozilla Public License * Version 1.1 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY * OF ANY KIND, either express or implied. See the LGPL or the MPL for * the specific language governing rights and limitations. * * The Original Code is the cairo graphics library. * * The Initial Developer of the Original Code is Mozilla Foundation. * * Contributor(s): * Vladimir Vukicevic <vladimir@mozilla.com>
*/
/** * SECTION:cairo-quartz-fonts * @Title: Quartz (CGFont) Fonts * @Short_Description: Font support via CGFont on OS X * @See_Also: #cairo_font_face_t * * The Quartz font backend is primarily used to render text on Apple * MacOS X systems. The CGFont API is used for the internal * implementation of the font backend methods.
**/
/** * CAIRO_HAS_QUARTZ_FONT: * * Defined if the Quartz font backend is available. * This macro can be used to conditionally compile backend-specific code. * * Since: 1.6
**/
/* CreateWithFontName exists in 10.5, but not in 10.4; CreateWithName isn't public in 10.4 */ static CGFontRef (*CGFontCreateWithFontNamePtr) (CFStringRef) = NULL; static CGFontRef (*CGFontCreateWithNamePtr) (constchar *) = NULL;
/* These aren't public before 10.5, and some have different names in 10.4 */ staticint (*CGFontGetUnitsPerEmPtr) (CGFontRef) = NULL; staticbool (*CGFontGetGlyphAdvancesPtr) (CGFontRef, const CGGlyph[], size_t, int[]) = NULL; staticbool (*CGFontGetGlyphBBoxesPtr) (CGFontRef, const CGGlyph[], size_t, CGRect[]) = NULL; static CGRect (*CGFontGetFontBBoxPtr) (CGFontRef) = NULL;
/* Not public in the least bit */ static CGPathRef (*CGFontGetGlyphPathPtr) (CGFontRef fontRef, CGAffineTransform *textTransform, int unknown, CGGlyph glyph) = NULL;
/* CGFontGetHMetrics isn't public, but the other functions are public/present in 10.5 */ typedefstruct { int ascent; int descent; int leading;
} quartz_CGFontMetrics; static quartz_CGFontMetrics* (*CGFontGetHMetricsPtr) (CGFontRef fontRef) = NULL; staticint (*CGFontGetAscentPtr) (CGFontRef fontRef) = NULL; staticint (*CGFontGetDescentPtr) (CGFontRef fontRef) = NULL; staticint (*CGFontGetLeadingPtr) (CGFontRef fontRef) = NULL;
#ifdef CAIRO_HAS_QUARTZ_ATSUFONTID /* Not public anymore in 64-bits nor in 10.7 */ static ATSFontRef (*FMGetATSFontRefFromFontPtr) (ATSUFontID iFont) = NULL; #endif/* CAIRO_HAS_QUARTZ_ATSUFONTID */
/* Look for the 10.5 versions first */
CGFontGetGlyphBBoxesPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphBBoxes"); if (!CGFontGetGlyphBBoxesPtr)
CGFontGetGlyphBBoxesPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphBoundingBoxes");
CGFontGetGlyphsForUnicharsPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphsForUnichars"); if (!CGFontGetGlyphsForUnicharsPtr)
CGFontGetGlyphsForUnicharsPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphsForUnicodes");
/* We just need one of these two */
CGFontCreateWithFontNamePtr = dlsym(RTLD_DEFAULT, "CGFontCreateWithFontName");
CGFontCreateWithNamePtr = dlsym(RTLD_DEFAULT, "CGFontCreateWithName");
/* These have the same name in 10.4 and 10.5 */
CGFontGetUnitsPerEmPtr = dlsym(RTLD_DEFAULT, "CGFontGetUnitsPerEm");
CGFontGetGlyphAdvancesPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphAdvances");
/* * Some Tiger systems have a partial version of CoreText, which * has incompatible signatures: CTFontCreateWithGraphicsFont * accepts a double for the size argument even on i386 and all * functions omit the CTFontOrientation arguments. Since the 10.4 * CoreText library does not provide the CTFontCreatePathForGlyph * symbol, use it to determine whether to use CoreText at all.
*/
CTFontCreatePathForGlyphPtr = dlsym(RTLD_DEFAULT, "CTFontCreatePathForGlyph"); if (CTFontCreatePathForGlyphPtr) {
CTFontCreateWithGraphicsFontPtr = dlsym(RTLD_DEFAULT, "CTFontCreateWithGraphicsFont");
CTFontGetAdvancesForGlyphsPtr = dlsym(RTLD_DEFAULT, "CTFontGetAdvancesForGlyphs");
CTFontGetBoundingRectsForGlyphsPtr = dlsym(RTLD_DEFAULT, "CTFontGetBoundingRectsForGlyphs");
} else {
CGFontGetGlyphPathPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphPath");
}
quartz_font_ensure_symbols(); if (! _cairo_quartz_font_symbols_present) return _cairo_error (CAIRO_STATUS_NO_MEMORY);
family = toy_face->family;
full_name = _cairo_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"; elseif (!strcmp(family, "sans-serif") || !strcmp(family, "sans"))
family = "Helvetica"; elseif (!strcmp(family, "cursive"))
family = "Apple Chancery"; elseif (!strcmp(family, "fantasy"))
family = "Papyrus"; elseif (!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");
}
/** * cairo_quartz_font_face_create_for_cgfont: * @font: a #CGFontRef obtained through a method external to cairo. * * Creates a new font for the Quartz font backend based on a * #CGFontRef. 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_cgfont (CGFontRef font)
{
cairo_quartz_font_face_t *font_face;
/* Should we want to always integer-align glyph extents, we can do so in this way */ #if 0
{
CGAffineTransform textMatrix;
textMatrix = CGAffineTransformMake (font->base.scale.xx,
-font->base.scale.yx,
-font->base.scale.xy,
font->base.scale.yy,
0.0f, 0.0f);
/* Create blank 2x2 image if we don't have this character. * Maybe we should draw a better missing-glyph slug or something, * but this is ok for now.
*/ if (unlikely (glyph == CGGLYPH_INVALID)) {
surface = (cairo_image_surface_t*) cairo_image_surface_create (CAIRO_FORMAT_A8, 2, 2);
status = cairo_surface_status ((cairo_surface_t *) surface); if (status) return status;
/* Round the rectangle outwards, so that we don't have to deal * with non-integer-pixel origins or dimensions.
*/
glyphRectInt = CGRectIntegral (glyphRect);
/* * compat with old ATSUI backend
*/ #ifdef CAIRO_HAS_QUARTZ_ATSUFONTID
/** * 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();
/* This is the old name for the above function, exported for compat purposes */
cairo_font_face_t *cairo_atsui_font_face_create_for_atsu_font_id (ATSUFontID font_id);
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 und die Messung sind noch experimentell.