/* Font back-end driver for the NeXT/Open/GNUstep and MacOSX window system.
See font.h
- Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+ Copyright (C) 2006-2011 Free Software Foundation, Inc.
This file is part of GNU Emacs.
#include "frame.h"
#include "character.h"
#include "font.h"
+#include "termchar.h"
/* TODO: Drop once we can assume gnustep-gui 0.17.1. */
#ifdef NS_IMPL_GNUSTEP
extern Lisp_Object Qns;
extern Lisp_Object Qnormal, Qbold, Qitalic, Qcondensed, Qexpanded;
-static Lisp_Object Vns_reg_to_script;
static Lisp_Object Qapple, Qroman, Qmedium;
extern Lisp_Object Qappend;
-extern Lisp_Object ns_antialias_text;
extern float ns_antialias_threshold;
extern int ns_tmp_flags;
extern struct nsfont_info *ns_tmp_font;
return nil;
else
{
- char *tmp = strdup (SDATA (SYMBOL_NAME (tem)));
+ char *tmp = xstrdup (SDATA (SYMBOL_NAME (tem)));
NSString *family;
ns_unescape_name (tmp);
family = [NSString stringWithUTF8String: tmp];
/* Converts NSFont descriptor to FONT_WEIGHT, FONT_SLANT, FONT_WIDTH, etc.. */
static Lisp_Object
-ns_descriptor_to_entity (NSFontDescriptor *desc, Lisp_Object extra, char *style)
+ns_descriptor_to_entity (NSFontDescriptor *desc,
+ Lisp_Object extra,
+ const char *style)
{
Lisp_Object font_entity = font_make_entity ();
/* NSString *psName = [desc postscriptName]; */
if (family == nil)
family = [[NSFont userFixedPitchFontOfSize: 0] familyName];
- escapedFamily = strdup ([family UTF8String]);
+ escapedFamily = xstrdup ([family UTF8String]);
ns_escape_name (escapedFamily);
ASET (font_entity, FONT_TYPE_INDEX, Qns);
/* Default font entity. */
static Lisp_Object
-ns_fallback_entity ()
+ns_fallback_entity (void)
{
return ns_descriptor_to_entity ([[NSFont userFixedPitchFontOfSize: 0]
fontDescriptor], Qnil, NULL);
const char *fontName = [[nsfont fontName] UTF8String];
int len = strlen (fontName);
+ /* The values specified by fonts are not always exact. For
+ * example, a 6x8 font could specify that the descender is
+ * -2.00000405... (represented by 0xc000000220000000). Without
+ * adjustment, the code below would round the descender to -3,
+ * resulting in a font that would be one pixel higher than
+ * intended. */
+ CGFloat adjusted_descender = [sfont descender] + 0.0001;
+
#ifdef NS_IMPL_GNUSTEP
font_info->nsfont = sfont;
#else
brect = [sfont boundingRectForFont];
full_height = brect.size.height;
- min_height = [sfont ascender] - [sfont descender];
+ min_height = [sfont ascender] - adjusted_descender;
hd = full_height - min_height;
/* standard height, similar to Carbon. Emacs.app: was 0.5 by default. */
/* max bounds */
font_info->max_bounds.ascent =
lrint (hshrink * [sfont ascender] + expand * hd/2);
- /* [sfont descender] is usually negative. Use floor to avoid
+ /* Descender is usually negative. Use floor to avoid
clipping descenders. */
font_info->max_bounds.descent =
- -lrint (floor(hshrink* [sfont descender] - expand*hd/2));
+ -lrint (floor(hshrink* adjusted_descender - expand*hd/2));
font_info->height =
font_info->max_bounds.ascent + font_info->max_bounds.descent;
font_info->max_bounds.width = lrint (font_info->width);
/* set up metrics portion of font struct */
font->ascent = lrint([sfont ascender]);
- font->descent = -lrint(floor([sfont descender]));
+ font->descent = -lrint(floor(adjusted_descender));
font->min_width = ns_char_width(sfont, '|');
font->space_width = lrint (ns_char_width (sfont, ' '));
font->average_width = lrint (font_info->width);
face = s->face;
break;
case NS_DUMPGLYPH_MOUSEFACE:
- face = FACE_FROM_ID (s->f,
- FRAME_NS_DISPLAY_INFO (s->f)->mouse_face_face_id);
+ 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);
break;
DPSstroke (context);
DPSgrestore (context);
- return to-from;
}
#else /* NS_IMPL_COCOA */
}
CGContextRestoreGState (gcontext);
- return;
}
#endif /* NS_IMPL_COCOA */
-
+ return to-from;
}
void
-syms_of_nsfont ()
+syms_of_nsfont (void)
{
nsfont_driver.type = Qns;
register_font_driver (&nsfont_driver, NULL);
DEFSYM (Qapple, "apple");
DEFSYM (Qroman, "roman");
DEFSYM (Qmedium, "medium");
- DEFVAR_LISP ("ns-reg-to-script", &Vns_reg_to_script,
+ DEFVAR_LISP ("ns-reg-to-script", Vns_reg_to_script,
doc: /* Internal use: maps font registry to unicode script. */);
}
-
-// arch-tag: d6c3c6f0-62de-4978-8b1e-b7966fe02cae