/* ftfont.c -- FreeType font driver.
- Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
- Copyright (C) 2006, 2007, 2008, 2009, 2010
+ Copyright (C) 2006-2011 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011
National Institute of Advanced Industrial Science and Technology (AIST)
Registration Number H13PRO009
#include "ftfont.h"
/* Symbolic type of this font-driver. */
-Lisp_Object Qfreetype;
+static Lisp_Object Qfreetype;
/* Fontconfig's generic families and their aliases. */
static Lisp_Object Qmonospace, Qsans_serif, Qserif, Qmono, Qsans, Qsans__serif;
enum ftfont_cache_for);
static void ftfont_filter_properties (Lisp_Object font, Lisp_Object alist);
-
+
Lisp_Object ftfont_font_format (FcPattern *, Lisp_Object);
#define SYMBOL_FcChar8(SYM) (FcChar8 *) SDATA (SYMBOL_NAME (SYM))
static struct
{
/* registry name */
- char *name;
+ const char *name;
/* characters to distinguish the charset from the others */
int uniquifier[6];
/* additional constraint by language */
- char *lang;
+ const char *lang;
/* set on demand */
FcCharSet *fc_charset;
} fc_charset_table[] =
{ NULL }
};
-extern Lisp_Object Qc, Qm, Qp, Qd;
-
/* Dirty hack for handing ADSTYLE property.
Fontconfig (actually the underlying FreeType) gives such ADSTYLE
static Lisp_Object
get_adstyle_property (FcPattern *p)
{
+ FcChar8 *fcstr;
char *str, *end;
Lisp_Object adstyle;
- if (FcPatternGetString (p, FC_STYLE, 0, (FcChar8 **) &str) != FcResultMatch)
+ if (FcPatternGetString (p, FC_STYLE, 0, &fcstr) != FcResultMatch)
return Qnil;
+ str = (char *) fcstr;
for (end = str; *end && *end != ' '; end++);
if (*end)
{
- char *p = alloca (end - str + 1);
- memcpy (p, str, end - str);
- p[end - str] = '\0';
- end = p + (end - str);
- str = p;
+ char *newstr = alloca (end - str + 1);
+ memcpy (newstr, str, end - str);
+ newstr[end - str] = '\0';
+ end = newstr + (end - str);
+ str = newstr;
}
if (xstrcasecmp (str, "Regular") == 0
|| xstrcasecmp (str, "Bold") == 0
ftfont_pattern_entity (FcPattern *p, Lisp_Object extra)
{
Lisp_Object key, cache, entity;
- char *file, *str;
- int index;
+ FcChar8 *str;
+ char *file;
+ int idx;
int numeric;
double dbl;
FcBool b;
- if (FcPatternGetString (p, FC_FILE, 0, (FcChar8 **) &file) != FcResultMatch)
+ if (FcPatternGetString (p, FC_FILE, 0, &str) != FcResultMatch)
return Qnil;
- if (FcPatternGetInteger (p, FC_INDEX, 0, &index) != FcResultMatch)
+ if (FcPatternGetInteger (p, FC_INDEX, 0, &idx) != FcResultMatch)
return Qnil;
- key = Fcons (make_unibyte_string ((char *) file, strlen ((char *) file)),
- make_number (index));
+ file = (char *) str;
+ key = Fcons (make_unibyte_string (file, strlen (file)), make_number (idx));
cache = ftfont_lookup_cache (key, FTFONT_CACHE_FOR_ENTITY);
entity = XCAR (cache);
if (! NILP (entity))
ASET (entity, FONT_TYPE_INDEX, Qfreetype);
ASET (entity, FONT_REGISTRY_INDEX, Qiso10646_1);
- if (FcPatternGetString (p, FC_FOUNDRY, 0, (FcChar8 **) &str) == FcResultMatch)
- ASET (entity, FONT_FOUNDRY_INDEX, font_intern_prop (str, strlen (str), 1));
- if (FcPatternGetString (p, FC_FAMILY, 0, (FcChar8 **) &str) == FcResultMatch)
- ASET (entity, FONT_FAMILY_INDEX, font_intern_prop (str, strlen (str), 1));
+ if (FcPatternGetString (p, FC_FOUNDRY, 0, &str) == FcResultMatch)
+ {
+ char *s = (char *) str;
+ ASET (entity, FONT_FOUNDRY_INDEX, font_intern_prop (s, strlen (s), 1));
+ }
+ if (FcPatternGetString (p, FC_FAMILY, 0, &str) == FcResultMatch)
+ {
+ char *s = (char *) str;
+ ASET (entity, FONT_FAMILY_INDEX, font_intern_prop (s, strlen (s), 1));
+ }
if (FcPatternGetInteger (p, FC_WEIGHT, 0, &numeric) == FcResultMatch)
{
if (numeric >= FC_WEIGHT_REGULAR && numeric < FC_WEIGHT_MEDIUM)
else
{
/* As this font is not scalable, parhaps this is a BDF or PCF
- font. */
+ font. */
FT_Face ft_face;
ASET (entity, FONT_ADSTYLE_INDEX, get_adstyle_property (p));
if ((ft_library || FT_Init_FreeType (&ft_library) == 0)
- && FT_New_Face (ft_library, file, index, &ft_face) == 0)
+ && FT_New_Face (ft_library, file, idx, &ft_face) == 0)
{
BDF_PropertyRec rec;
if (FcPatternGetLangSet (pattern, FC_LANG, 0, &langset) != FcResultMatch)
{
/* This is to avoid the effect of locale. */
+ static const FcChar8 lang[] = "en";
langset = FcLangSetCreate ();
- FcLangSetAdd (langset, "en");
+ FcLangSetAdd (langset, lang);
FcPatternAddLangSet (pattern, FC_LANG, langset);
FcLangSetDestroy (langset);
}
if (cache_for == FTFONT_CACHE_FOR_FACE
? ! cache_data->ft_face : ! cache_data->fc_charset)
{
- char *filename = (char *) SDATA (XCAR (key));
- int index = XINT (XCDR (key));
+ char *filename = SSDATA (XCAR (key));
+ int idx = XINT (XCDR (key));
if (cache_for == FTFONT_CACHE_FOR_FACE)
{
if (! ft_library
&& FT_Init_FreeType (&ft_library) != 0)
return Qnil;
- if (FT_New_Face (ft_library, filename, index, &cache_data->ft_face)
+ if (FT_New_Face (ft_library, filename, idx, &cache_data->ft_face)
!= 0)
return Qnil;
}
FcCharSet *charset = NULL;
pat = FcPatternBuild (0, FC_FILE, FcTypeString, (FcChar8 *) filename,
- FC_INDEX, FcTypeInteger, index, NULL);
+ FC_INDEX, FcTypeInteger, idx, NULL);
if (! pat)
goto finish;
objset = FcObjectSetBuild (FC_CHARSET, FC_STYLE, NULL);
#ifdef HAVE_LIBOTF
static OTF *
-ftfont_get_otf (ftfont_info)
- struct ftfont_info *ftfont_info;
+ftfont_get_otf (struct ftfont_info *ftfont_info)
{
OTF *otf;
struct font_bitmap *, int);
static int ftfont_anchor_point (struct font *, unsigned, int,
int *, int *);
+#ifdef HAVE_LIBOTF
static Lisp_Object ftfont_otf_capability (struct font *);
+# ifdef HAVE_M17N_FLT
static Lisp_Object ftfont_shape (Lisp_Object);
+# endif
+#endif
#ifdef HAVE_OTF_GET_VARIATION_GLYPHS
static int ftfont_variation_glyphs (struct font *, int c,
ftfont_filter_properties, /* filter_properties */
};
-extern Lisp_Object QCname;
-
static Lisp_Object
ftfont_get_cache (FRAME_PTR f)
{
static int
ftfont_get_charset (Lisp_Object registry)
{
- char *str = (char *) SDATA (SYMBOL_NAME (registry));
+ char *str = SSDATA (SYMBOL_NAME (registry));
char *re = alloca (SBYTES (SYMBOL_NAME (registry)) * 2 + 1);
Lisp_Object regexp;
int i, j;
(P)[4] = '\0'; \
} while (0)
+#ifdef HAVE_LIBOTF
#define OTF_TAG_SYM(SYM, TAG) \
do { \
char str[5]; \
OTF_TAG_STR (TAG, str); \
(SYM) = font_intern_prop (str, 4, 1); \
} while (0)
+#endif
static struct OpenTypeSpec *
return spec;
}
-static FcPattern *ftfont_spec_pattern (Lisp_Object, char *,
- struct OpenTypeSpec **,
- char **langname);
-
static FcPattern *
-ftfont_spec_pattern (Lisp_Object spec, char *otlayout, struct OpenTypeSpec **otspec, char **langname)
+ftfont_spec_pattern (Lisp_Object spec, char *otlayout, struct OpenTypeSpec **otspec, const char **langname)
{
Lisp_Object tmp, extra;
FcPattern *pattern = NULL;
key = XCAR (XCAR (extra)), val = XCDR (XCAR (extra));
if (EQ (key, QCdpi))
- dpi = XINT (val);
+ {
+ if (INTEGERP (val))
+ dpi = XINT (val);
+ }
else if (EQ (key, QClang))
{
if (! langset)
}
else if (EQ (key, QCotf))
{
- *otspec = ftfont_get_open_type_spec (val);
- if (! *otspec)
- return NULL;
- strcat (otlayout, "otlayout:");
- OTF_TAG_STR ((*otspec)->script_tag, otlayout + 9);
- script = (*otspec)->script;
+ if (CONSP (val))
+ {
+ *otspec = ftfont_get_open_type_spec (val);
+ if (! *otspec)
+ return NULL;
+ strcat (otlayout, "otlayout:");
+ OTF_TAG_STR ((*otspec)->script_tag, otlayout + 9);
+ script = (*otspec)->script;
+ }
}
else if (EQ (key, QCscript))
script = val;
FcObjectSet *objset = NULL;
FcCharSet *charset;
Lisp_Object chars = Qnil;
- FcResult result;
char otlayout[15]; /* For "otlayout:XXXX" */
struct OpenTypeSpec *otspec = NULL;
int spacing = -1;
- char *langname = NULL;
+ const char *langname = NULL;
if (! fc_initialized)
{
if (! NILP (adstyle)
&& (NILP (this_adstyle)
- || xstrcasecmp (SDATA (SYMBOL_NAME (adstyle)),
- SDATA (SYMBOL_NAME (this_adstyle))) != 0))
+ || xstrcasecmp (SSDATA (SYMBOL_NAME (adstyle)),
+ SSDATA (SYMBOL_NAME (this_adstyle))) != 0))
continue;
if (langname
&& ! NILP (this_adstyle)
- && xstrcasecmp (langname, SDATA (SYMBOL_NAME (this_adstyle))))
+ && xstrcasecmp (langname, SSDATA (SYMBOL_NAME (this_adstyle))))
continue;
}
entity = ftfont_pattern_entity (fontset->fonts[i],
FcResult result;
char otlayout[15]; /* For "otlayout:XXXX" */
struct OpenTypeSpec *otspec = NULL;
- char *langname = NULL;
+ const char *langname = NULL;
if (! fc_initialized)
{
FT_Face ft_face;
FT_Size ft_size;
FT_UInt size;
- Lisp_Object val, filename, index, cache, font_object;
+ Lisp_Object val, filename, idx, cache, font_object;
int scalable;
int spacing;
char name[256];
if (NILP (cache))
return Qnil;
filename = XCAR (val);
- index = XCDR (val);
+ idx = XCDR (val);
val = XCDR (cache);
cache_data = XSAVE_VALUE (XCDR (cache))->pointer;
ft_face = cache_data->ft_face;
font = XFONT_OBJECT (font_object);
ftfont_info = (struct ftfont_info *) font;
ftfont_info->ft_size = ft_face->size;
- ftfont_info->index = XINT (index);
+ ftfont_info->index = XINT (idx);
#ifdef HAVE_LIBOTF
ftfont_info->maybe_otf = ft_face->face_flags & FT_FACE_FLAG_SFNT;
ftfont_info->otf = NULL;
spacing = XINT (AREF (entity, FONT_SPACING_INDEX));
else
spacing = FC_PROPORTIONAL;
- if (spacing != FC_PROPORTIONAL && spacing != FC_DUAL)
+ if (spacing != FC_PROPORTIONAL
+#ifdef FC_DUAL
+ && spacing != FC_DUAL
+#endif /* FC_DUAL */
+ )
font->min_width = font->average_width = font->space_width
= (scalable ? ft_face->max_advance_width * size / upEM
: ft_face->size->metrics.max_advance >> 6);
}
static int
-ftfont_anchor_point (struct font *font, unsigned int code, int index, int *x, int *y)
+ftfont_anchor_point (struct font *font, unsigned int code, int idx,
+ int *x, int *y)
{
struct ftfont_info *ftfont_info = (struct ftfont_info *) font;
FT_Face ft_face = ftfont_info->ft_size->face;
return -1;
if (ft_face->glyph->format != FT_GLYPH_FORMAT_OUTLINE)
return -1;
- if (index >= ft_face->glyph->outline.n_points)
+ if (idx >= ft_face->glyph->outline.n_points)
return -1;
- *x = ft_face->glyph->outline.points[index].x;
- *y = ft_face->glyph->outline.points[index].y;
+ *x = ft_face->glyph->outline.points[idx].x;
+ *y = ft_face->glyph->outline.points[idx].y;
return 0;
}
#ifdef HAVE_LIBOTF
static Lisp_Object
-ftfont_otf_features (gsub_gpos)
- OTF_GSUB_GPOS *gsub_gpos;
+ftfont_otf_features (OTF_GSUB_GPOS *gsub_gpos)
{
Lisp_Object scripts, langsyses, features, sym;
int i, j, k, l;
static Lisp_Object
-ftfont_otf_capability (font)
- struct font *font;
+ftfont_otf_capability (struct font *font)
{
struct ftfont_info *ftfont_info = (struct ftfont_info *) font;
OTF *otf = ftfont_get_otf (ftfont_info);
};
static int
-ftfont_get_glyph_id (font, gstring, from, to)
- MFLTFont *font;
- MFLTGlyphString *gstring;
- int from, to;
+ftfont_get_glyph_id (MFLTFont *font, MFLTGlyphString *gstring,
+ int from, int to)
{
struct MFLTFontFT *flt_font_ft = (struct MFLTFontFT *) font;
FT_Face ft_face = flt_font_ft->ft_face;
#define ROUND(x) (((x)+32) & -64)
static int
-ftfont_get_metrics (font, gstring, from, to)
- MFLTFont *font;
- MFLTGlyphString *gstring;
- int from, to;
+ftfont_get_metrics (MFLTFont *font, MFLTGlyphString *gstring,
+ int from, int to)
{
struct MFLTFontFT *flt_font_ft = (struct MFLTFontFT *) font;
FT_Face ft_face = flt_font_ft->ft_face;
static int
ftfont_check_otf (MFLTFont *font, MFLTOtfSpec *spec)
{
+#define FEATURE_NONE(IDX) (! spec->features[IDX])
+
+#define FEATURE_ANY(IDX) \
+ (spec->features[IDX] \
+ && spec->features[IDX][0] == 0xFFFFFFFF && spec->features[IDX][1] == 0)
+
struct MFLTFontFT *flt_font_ft = (struct MFLTFontFT *) font;
OTF *otf = flt_font_ft->otf;
OTF_Tag *tags;
int i, n, negative;
+ if (FEATURE_ANY (0) && FEATURE_ANY (1))
+ /* Return 1 iff any of GSUB or GPOS support the script (and language). */
+ return (otf
+ && (OTF_check_features (otf, 0, spec->script, spec->langsys,
+ NULL, 0) > 0
+ || OTF_check_features (otf, 1, spec->script, spec->langsys,
+ NULL, 0) > 0));
+
for (i = 0; i < 2; i++)
- {
- if (! spec->features[i])
- continue;
- for (n = 0; spec->features[i][n]; n++);
- tags = alloca (sizeof (OTF_Tag) * n);
- for (n = 0, negative = 0; spec->features[i][n]; n++)
- {
- if (spec->features[i][n] == 0xFFFFFFFF)
- negative = 1;
- else if (negative)
- tags[n - 1] = spec->features[i][n] | 0x80000000;
- else
- tags[n] = spec->features[i][n];
- }
+ if (! FEATURE_ANY (i))
+ {
+ if (FEATURE_NONE (i))
+ {
+ if (otf
+ && OTF_check_features (otf, i == 0, spec->script, spec->langsys,
+ NULL, 0) > 0)
+ return 0;
+ continue;
+ }
+ if (spec->features[i][0] == 0xFFFFFFFF)
+ {
+ if (! otf
+ || OTF_check_features (otf, i == 0, spec->script, spec->langsys,
+ NULL, 0) <= 0)
+ continue;
+ }
+ else if (! otf)
+ return 0;
+ for (n = 1; spec->features[i][n]; n++);
+ tags = alloca (sizeof (OTF_Tag) * n);
+ for (n = 0, negative = 0; spec->features[i][n]; n++)
+ {
+ if (spec->features[i][n] == 0xFFFFFFFF)
+ negative = 1;
+ else if (negative)
+ tags[n - 1] = spec->features[i][n] | 0x80000000;
+ else
+ tags[n] = spec->features[i][n];
+ }
#ifdef M17N_FLT_USE_NEW_FEATURE
- if (OTF_check_features (otf, i == 0, spec->script, spec->langsys,
- tags, n - negative) != 1)
- return 0;
+ if (OTF_check_features (otf, i == 0, spec->script, spec->langsys,
+ tags, n - negative) != 1)
+ return 0;
#else /* not M17N_FLT_USE_NEW_FEATURE */
- if (n - negative > 0
- && OTF_check_features (otf, i == 0, spec->script, spec->langsys,
- tags, n - negative) != 1)
- return 0;
+ if (n - negative > 0
+ && OTF_check_features (otf, i == 0, spec->script, spec->langsys,
+ tags, n - negative) != 1)
+ return 0;
#endif /* not M17N_FLT_USE_NEW_FEATURE */
- }
+ }
return 1;
+#undef FEATURE_NONE
+#undef FEATURE_ANY
}
#define DEVICE_DELTA(table, size) \
position adjustment information in ADJUSTMENT. */
static int
-ftfont_drive_otf (font, spec, in, from, to, out, adjustment)
- MFLTFont *font;
- MFLTOtfSpec *spec;
- MFLTGlyphString *in;
- int from, to;
- MFLTGlyphString *out;
- MFLTGlyphAdjustment *adjustment;
+ftfont_drive_otf (MFLTFont *font,
+ MFLTOtfSpec *spec,
+ MFLTGlyphString *in,
+ int from,
+ int to,
+ MFLTGlyphString *out,
+ MFLTGlyphAdjustment *adjustment)
{
struct MFLTFontFT *flt_font_ft = (struct MFLTFontFT *) font;
FT_Face ft_face = flt_font_ft->ft_face;
return to;
}
-static int
+static int
ftfont_try_otf (MFLTFont *font, MFLTOtfSpec *spec,
MFLTGlyphString *in, int from, int to)
{
#else /* not M17N_FLT_USE_NEW_FEATURE */
static int
-ftfont_drive_otf (font, spec, in, from, to, out, adjustment)
- MFLTFont *font;
- MFLTOtfSpec *spec;
- MFLTGlyphString *in;
- int from, to;
- MFLTGlyphString *out;
- MFLTGlyphAdjustment *adjustment;
+ftfont_drive_otf (MFLTFont *font, MFLTOtfSpec *spec, MFLTGlyphString *in,
+ int from, int to,
+ MFLTGlyphString *out, MFLTGlyphAdjustment *adjustment)
{
struct MFLTFontFT *flt_font_ft = (struct MFLTFontFT *) font;
FT_Face ft_face = flt_font_ft->ft_face;
static int m17n_flt_initialized;
-extern Lisp_Object QCfamily;
-
static Lisp_Object
-ftfont_shape_by_flt (lgstring, font, ft_face, otf, matrix)
- Lisp_Object lgstring;
- struct font *font;
- FT_Face ft_face;
- OTF *otf;
- FT_Matrix *matrix;
+ftfont_shape_by_flt (Lisp_Object lgstring, struct font *font,
+ FT_Face ft_face, OTF *otf, FT_Matrix *matrix)
{
EMACS_UINT len = LGSTRING_GLYPH_LEN (lgstring);
EMACS_UINT i;
flt_font_ft.flt_font.family = Mnil;
else
flt_font_ft.flt_font.family
- = msymbol ((char *) SDATA (Fdowncase (SYMBOL_NAME (family))));
+ = msymbol (SSDATA (Fdowncase (SYMBOL_NAME (family))));
}
flt_font_ft.flt_font.x_ppem = ft_face->size->metrics.x_ppem;
flt_font_ft.flt_font.y_ppem = ft_face->size->metrics.y_ppem;
}
Lisp_Object
-ftfont_shape (lgstring)
- Lisp_Object lgstring;
+ftfont_shape (Lisp_Object lgstring)
{
struct font *font;
struct ftfont_info *ftfont_info;
#ifdef HAVE_OTF_GET_VARIATION_GLYPHS
static int
-ftfont_variation_glyphs (font, c, variations)
- struct font *font;
- int c;
- unsigned variations[256];
+ftfont_variation_glyphs (struct font *font, int c, unsigned variations[256])
{
struct ftfont_info *ftfont_info = (struct ftfont_info *) font;
OTF *otf = ftfont_get_otf (ftfont_info);
return intern ("unknown");
}
-static const char *ftfont_booleans [] = {
+static const char *const ftfont_booleans [] = {
":antialias",
":hinting",
":verticallayout",
NULL,
};
-static const char *ftfont_non_booleans [] = {
+static const char *const ftfont_non_booleans [] = {
":family",
":familylang",
":style",
static void
ftfont_filter_properties (Lisp_Object font, Lisp_Object alist)
{
- Lisp_Object it;
- int i;
-
- /* Set boolean values to Qt or Qnil */
- for (i = 0; ftfont_booleans[i] != NULL; ++i)
- for (it = alist; ! NILP (it); it = XCDR (it))
- {
- Lisp_Object key = XCAR (XCAR (it));
- Lisp_Object val = XCDR (XCAR (it));
- char *keystr = SDATA (SYMBOL_NAME (key));
-
- if (strcmp (ftfont_booleans[i], keystr) == 0)
- {
- char *str = SYMBOLP (val) ? SDATA (SYMBOL_NAME (val)) : NULL;
- if (INTEGERP (val)) str = XINT (val) != 0 ? "true" : "false";
- if (str == NULL) str = "true";
-
- val = Qt;
- if (strcmp ("false", str) == 0 || strcmp ("False", str) == 0
- || strcmp ("FALSE", str) == 0 || strcmp ("FcFalse", str) == 0
- || strcmp ("off", str) == 0 || strcmp ("OFF", str) == 0
- || strcmp ("Off", str) == 0)
- val = Qnil;
- Ffont_put (font, key, val);
- }
- }
-
- for (i = 0; ftfont_non_booleans[i] != NULL; ++i)
- for (it = alist; ! NILP (it); it = XCDR (it))
- {
- Lisp_Object key = XCAR (XCAR (it));
- Lisp_Object val = XCDR (XCAR (it));
- char *keystr = SDATA (SYMBOL_NAME (key));
- if (strcmp (ftfont_non_booleans[i], keystr) == 0)
- Ffont_put (font, key, val);
- }
+ font_filter_properties (font, alist, ftfont_booleans, ftfont_non_booleans);
}
ftfont_driver.type = Qfreetype;
register_font_driver (&ftfont_driver, NULL);
}
-
-/* arch-tag: 7cfa432c-33a6-4988-83d2-a82ed8604aca
- (do not change this comment) */