/* Font driver on Mac OSX Core text.
- Copyright (C) 2009-2013 Free Software Foundation, Inc.
+ Copyright (C) 2009-2014 Free Software Foundation, Inc.
This file is part of GNU Emacs.
#include "composite.h"
#include "fontset.h"
#include "font.h"
+#include "termchar.h"
#include "nsgui.h"
#include "nsterm.h"
#include "macfont.h"
struct macfont_metrics;
-/* The actual structure for Mac font that can be casted to struct font. */
+/* The actual structure for Mac font that can be cast to struct font. */
struct macfont_info
{
struct macfont_cache *cache;
struct macfont_metrics **metrics;
short metrics_nrows;
- unsigned synthetic_italic_p : 1;
- unsigned synthetic_bold_p : 1;
+ bool_bf synthetic_italic_p : 1;
+ bool_bf synthetic_bold_p : 1;
unsigned spacing : 2;
unsigned antialias : 2;
- unsigned color_bitmap_p : 1;
+ bool_bf color_bitmap_p : 1;
};
/* Values for the `spacing' member in `struct macfont_info'. */
unichar characters[] = {0xfffd};
NSString *string =
[NSString stringWithCharacters:characters
- length:(sizeof (characters)
- / sizeof (characters[0]))];
+ length:ARRAYELTS (characters)];
NSGlyphInfo *glyphInfo =
[NSGlyphInfo glyphInfoWithCharacterIdentifier:cid
collection:collection
return cgColor;
}
-#define CG_SET_FILL_COLOR_WITH_GC_FOREGROUND(context, s) \
+#define CG_SET_FILL_COLOR_WITH_FACE_FOREGROUND(context, face, f) \
do { \
- CGColorRef refcol_ = get_cgcolor (NS_FACE_FOREGROUND (s->face), \
- s->f); \
+ CGColorRef refcol_ = get_cgcolor (NS_FACE_FOREGROUND (face), f); \
CGContextSetFillColorWithColor (context, refcol_) ; \
CGColorRelease (refcol_); \
} while (0)
-#define CG_SET_FILL_COLOR_WITH_GC_BACKGROUND(context, s) \
+#define CG_SET_FILL_COLOR_WITH_FACE_BACKGROUND(context, face, f) \
do { \
- CGColorRef refcol_ = get_cgcolor (NS_FACE_BACKGROUND (s->face),\
- s->f); \
+ CGColorRef refcol_ = get_cgcolor (NS_FACE_BACKGROUND (face), f); \
CGContextSetFillColorWithColor (context, refcol_); \
CGColorRelease (refcol_); \
} while (0)
-#define CG_SET_STROKE_COLOR_WITH_GC_FOREGROUND(context, s) \
+#define CG_SET_STROKE_COLOR_WITH_FACE_FOREGROUND(context, face, f) \
do { \
- CGColorRef refcol_ = get_cgcolor (NS_FACE_FOREGROUND (s->face),\
- s->f); \
+ CGColorRef refcol_ = get_cgcolor (NS_FACE_FOREGROUND (face), f); \
CGContextSetStrokeColorWithColor (context, refcol_); \
CGColorRelease (refcol_); \
} while (0)
SInt64 sint64_value;
/* Getting symbolic traits with kCFNumberSInt32Type is lossy on Mac
- OS 10.6 when the value is greater than or equal to 1 << 31. */
+ OS X 10.6 when the value is greater than or equal to 1 << 31. */
if (CFNumberGetValue (number, kCFNumberSInt64Type, &sint64_value))
{
*sym_traits = (FontSymbolicTraits) sint64_value;
{{0, 100}, {1, 200}, {CGFLOAT_MAX, CGFLOAT_MAX}}}};
int i;
- for (i = 0; i < sizeof (numeric_traits) / sizeof (numeric_traits[0]); i++)
+ for (i = 0; i < ARRAYELTS (numeric_traits); i++)
{
num = CFDictionaryGetValue (dict, numeric_traits[i].trait);
if (num && CFNumberGetValue (num, kCFNumberCGFloatType, &floatval))
CTFontCopyCharacterSet nor -[NSFont coveredCharacterSet]
for this font is correct for non-BMP characters on Mac OS
X 10.5, anyway. */
- if (CFStringCompare (key, CFSTR ("LastResort"), 0)
- == kCFCompareEqualTo)
+ if (CFEqual (key, CFSTR ("LastResort")))
{
CFRange range = CFRangeMake (0, MAX_UNICODE_CHAR + 1);
if (! traits)
goto err;
- for (i = 0; i < sizeof (numeric_traits) / sizeof (numeric_traits[0]); i++)
+ for (i = 0; i < ARRAYELTS (numeric_traits); i++)
{
tmp = AREF (spec, numeric_traits[i].index);
if (INTEGERP (tmp))
10.7 returns NULL if pat_desc represents the LastResort font.
So we use CTFontDescriptorCreateMatchingFontDescriptor (no
trailing "s") for such a font. */
- if (CFStringCompare (family_name, CFSTR ("LastResort"), 0)
- != kCFCompareEqualTo)
- descs = mac_font_descriptor_create_matching_font_descriptors (pat_desc,
- NULL);
+ if (!CFEqual (family_name, CFSTR ("LastResort")))
+ descs = mac_font_descriptor_create_matching_font_descriptors (pat_desc,
+ NULL);
else
- {
- FontDescriptorRef lr_desc =
- mac_font_descriptor_create_matching_font_descriptor (pat_desc,
- NULL);
- if (lr_desc)
- {
- descs = CFArrayCreate (NULL, (const void **) &lr_desc, 1,
- &kCFTypeArrayCallBacks);
- CFRelease (lr_desc);
- }
- else
- descs = NULL;
- }
+ {
+ FontDescriptorRef lr_desc =
+ mac_font_descriptor_create_matching_font_descriptor (pat_desc,
+ NULL);
+ if (lr_desc)
+ {
+ descs = CFArrayCreate (NULL, (const void **) &lr_desc, 1,
+ &kCFTypeArrayCallBacks);
+ CFRelease (lr_desc);
+ }
+ else
+ descs = NULL;
+ }
CFRelease (pat_desc);
if (! descs)
- goto err;
+ goto err;
descs_count = CFArrayGetCount (descs);
if (descs_count == 0
family_name = mac_font_copy_family_name (macfont);
if (family_name)
{
- if ((CFStringCompare (family_name, CFSTR ("Courier"), 0)
- == kCFCompareEqualTo)
- || (CFStringCompare (family_name, CFSTR ("Helvetica"), 0)
- == kCFCompareEqualTo)
- || (CFStringCompare (family_name, CFSTR ("Times"), 0)
- == kCFCompareEqualTo))
+ if (CFEqual (family_name, CFSTR ("Courier"))
+ || CFEqual (family_name, CFSTR ("Helvetica"))
+ || CFEqual (family_name, CFSTR ("Times")))
ascent += (ascent + descent) * .15f;
else if (CFStringHasPrefix (family_name, CFSTR ("Hiragino")))
{
{
struct frame * f = s->f;
struct macfont_info *macfont_info = (struct macfont_info *) s->font;
- FontRef macfont = macfont_info->macfont;
+ CGRect background_rect;
+ CGPoint text_position;
+ CGGlyph *glyphs;
+ CGPoint *positions;
+ CGFloat font_size = mac_font_get_size (macfont_info->macfont);
+ bool no_antialias_p =
+ (macfont_info->antialias == MACFONT_ANTIALIAS_OFF
+ || (macfont_info->antialias == MACFONT_ANTIALIAS_DEFAULT
+ && font_size <= macfont_antialias_threshold));
+ int len = to - from;
+ struct face *face = s->face;
CGContextRef context;
- BOOL isComposite = s->first_glyph->type == COMPOSITE_GLYPH;
- int end = isComposite ? s->cmp_to : s->nchars;
- int len = end - s->cmp_from;
- int i;
block_input ();
- context = [[NSGraphicsContext currentContext] graphicsPort];
- CGContextSaveGState (context);
+ if (with_background)
+ background_rect = CGRectMake (x, y - FONT_BASE (s->font),
+ s->width, FONT_HEIGHT (s->font));
+ else
+ background_rect = CGRectNull;
+
+ text_position = CGPointMake (x, -y);
+ glyphs = xmalloc (sizeof (CGGlyph) * len);
+ {
+ CGFloat advance_delta;
+ int i;
+ CGFloat total_width = 0;
-#if 0
- if (s->num_clips > 0)
- {
- CGRect clips[2];
+ positions = xmalloc (sizeof (CGPoint) * len);
+ for (i = 0; i < len; i++)
+ {
+ int width;
+
+ glyphs[i] = s->char2b[from + i];
+ width = (s->padding_p ? 1
+ : macfont_glyph_extents (s->font, glyphs[i],
+ NULL, &advance_delta,
+ no_antialias_p));
+ positions[i].x = total_width + advance_delta;
+ positions[i].y = 0;
+ total_width += width;
+ }
+ }
- for (i = 0; i < s->num_clips; i++)
- clips[i] = mac_rect_make (f, s->clip[i].left, s->clip[i].top,
- s->clip[i].right - s->clip[i].left,
- s->clip[i].bottom - s->clip[i].top);
- CGContextClipToRects (context, clips, s->num_clips);
- }
-#endif
+ context = [[NSGraphicsContext currentContext] graphicsPort];
+ CGContextSaveGState (context);
- if (with_background)
+ if (!CGRectIsNull (background_rect))
{
- CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context, s);
- CGContextFillRect (context,
- CGRectMake (x, y,
- s->width, FONT_HEIGHT (s->font)));
+ if (s->hl == DRAW_MOUSE_FACE)
+ {
+ face = FACE_FROM_ID (s->f, MOUSE_HL_INFO (s->f)->mouse_face_face_id);
+ if (!face)
+ face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
+ }
+ CG_SET_FILL_COLOR_WITH_FACE_BACKGROUND (context, face, f);
+ CGContextFillRects (context, &background_rect, 1);
}
if (macfont_info->cgfont)
{
- CGGlyph *glyphs = alloca (sizeof (CGGlyph) * len);
- CGPoint *positions = alloca (sizeof (CGPoint) * len);
- CGFloat total_width = 0;
- CGFloat font_size = mac_font_get_size (macfont);
CGAffineTransform atfm;
- CGFloat advance_delta = 0;
- int y_draw = -s->ybase;
- int no_antialias_p =
- (macfont_info->antialias == MACFONT_ANTIALIAS_OFF
- || (macfont_info->antialias == MACFONT_ANTIALIAS_DEFAULT
- && font_size <= macfont_antialias_threshold));
-
- for (i = 0; i < len; i++)
- {
- int width;
-
- glyphs[i] = *(s->char2b + s->cmp_from + i);
- width = (s->padding_p ? 1
- : macfont_glyph_extents (s->font, glyphs[i],
- NULL, &advance_delta,
- no_antialias_p));
- positions[i].x = total_width + advance_delta;
- positions[i].y = 0;
- total_width += width;
- }
-
CGContextScaleCTM (context, 1, -1);
- CG_SET_FILL_COLOR_WITH_GC_FOREGROUND (context, s);
+ CG_SET_FILL_COLOR_WITH_FACE_FOREGROUND (context, face, s->f);
if (macfont_info->synthetic_italic_p)
atfm = synthetic_italic_atfm;
else
{
CGContextSetTextDrawingMode (context, kCGTextFillStroke);
CGContextSetLineWidth (context, synthetic_bold_factor * font_size);
- CG_SET_STROKE_COLOR_WITH_GC_FOREGROUND (context, s);
+ CG_SET_STROKE_COLOR_WITH_FACE_FOREGROUND (context, face, f);
}
if (no_antialias_p)
CGContextSetShouldAntialias (context, false);
CGContextSetTextMatrix (context, atfm);
- CGContextSetTextPosition (context, x, y_draw);
+ CGContextSetTextPosition (context, text_position.x, text_position.y);
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
if (macfont_info->color_bitmap_p
{
if (len > 0)
{
- CTFontDrawGlyphs (macfont, glyphs, positions, len, context);
+ CTFontDrawGlyphs (macfont_info->macfont, glyphs, positions, len,
+ context);
}
}
else
}
}
+
+ xfree (glyphs);
+ xfree (positions);
CGContextRestoreGState (context);
unblock_input ();
name2 = CTFontCopyPostScriptName (font2);
if (name2)
{
- result = (CFStringCompare (name1, name2, 0) == kCFCompareEqualTo);
+ result = CFEqual (name1, name2);
CFRelease (name2);
}
CFRelease (name1);
{
attributes = CFDictionaryCreate (NULL, (const void **) keys,
(const void **) values,
- sizeof (keys) / sizeof (keys[0]),
+ ARRAYELTS (keys),
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFRelease (values[1]);
CTLineRef ctline = NULL;
string = CFStringCreateWithCharacters (NULL, characters,
- sizeof (characters)
- / sizeof (characters[0]));
+ ARRAYELTS (characters));
+
if (string)
{
CTGlyphInfoRef glyph_info =
attributes = CFDictionaryCreate (NULL, (const void **) keys,
(const void **) values,
- sizeof (keys) / sizeof (keys[0]),
+ ARRAYELTS (keys),
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFRelease (glyph_info);
for (i = 0; macfont_language_default_font_names[i].language; i++)
{
- if (CFStringCompare (macfont_language_default_font_names[i].language,
- language, 0) == kCFCompareEqualTo)
+ if (CFEqual (macfont_language_default_font_names[i].language,
+ language))
{
CFMutableArrayRef descriptors =
CFArrayCreateMutable (NULL, 0, &kCFTypeArrayCallBacks);
if (family)
{
if (!CFStringHasPrefix (family, CFSTR ("."))
- && (CFStringCompare (family, CFSTR ("LastResort"), 0)
- != kCFCompareEqualTo))
- {
+ && !CFEqual (family, CFSTR ("LastResort")))
+ {
result = family;
break;
}