/* ftfont.c -- FreeType font driver.
- Copyright (C) 2006-2011 Free Software Foundation, Inc.
+ Copyright (C) 2006-2012 Free Software Foundation, Inc.
Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011
National Institute of Advanced Industrial Science and Technology (AIST)
Registration Number H13PRO009
char *str, *end;
Lisp_Object adstyle;
+#ifdef FC_FONTFORMAT
+ if ((FcPatternGetString (p, FC_FONTFORMAT, 0, &fcstr) == FcResultMatch)
+ && xstrcasecmp ((char *) fcstr, "bdf") != 0
+ && xstrcasecmp ((char *) fcstr, "pcf") != 0)
+ /* Not a BDF nor PCF font. */
+ return Qnil;
+#endif
if (FcPatternGetString (p, FC_STYLE, 0, &fcstr) != FcResultMatch)
return Qnil;
str = (char *) fcstr;
}
else
{
- /* As this font is not scalable, parhaps this is a BDF or PCF
+ /* As this font is not scalable, perhaps this is a BDF or PCF
font. */
FT_Face ft_face;
struct font_driver ftfont_driver =
{
- 0, /* Qfreetype */
+ LISP_INITIALLY_ZERO, /* Qfreetype */
0, /* case insensitive */
ftfont_get_cache,
ftfont_list,
if (NILP (val))
continue;
len = Flength (val);
- spec->features[i] = malloc (sizeof (int) * XINT (len));
+ spec->features[i] =
+ (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (int) < XINT (len)
+ ? 0
+ : malloc (sizeof (int) * XINT (len)));
if (! spec->features[i])
{
if (i > 0 && spec->features[0])
if ((n = FONT_SLANT_NUMERIC (spec)) >= 0
&& n < 100)
- /* Fontconfig doesn't support reverse-italic/obligue. */
+ /* Fontconfig doesn't support reverse-italic/oblique. */
return NULL;
if (INTEGERP (AREF (spec, FONT_DPI_INDEX)))
/* Need fix because this finds any fonts. */
if (fontset->nfont == 0 && ! NILP (family))
{
- /* Try maching with configuration. For instance, the
+ /* Try matching with configuration. For instance, the
configuration may specify "Nimbus Mono L" as an alias of
"Courier". */
FcPattern *pat = FcPatternBuild (0, FC_FAMILY, FcTypeString,
#endif /* HAVE_LIBOTF */
if (VECTORP (chars))
{
- int j;
+ ptrdiff_t j;
if (FcPatternGetCharSet (fontset->fonts[i], FC_CHARSET, 0, &charset)
!= FcResultMatch)
continue;
for (j = 0; j < ASIZE (chars); j++)
- if (NATNUMP (AREF (chars, j))
+ if (TYPE_RANGED_INTEGERP (FcChar32, AREF (chars, j))
&& FcCharSetHasChar (charset, XFASTINT (AREF (chars, j))))
break;
if (j == ASIZE (chars))
: ft_face->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD_V ? 8
: -1);
if (bitmap->bits_per_pixel < 0)
- /* We don't suport that kind of pixel mode. */
+ /* We don't support that kind of pixel mode. */
return -1;
bitmap->rows = ft_face->glyph->bitmap.rows;
bitmap->width = ft_face->glyph->bitmap.width;
static void
setup_otf_gstring (int size)
{
- if (otf_gstring.size == 0)
+ if (otf_gstring.size < size)
{
- otf_gstring.glyphs = (OTF_Glyph *) xmalloc (sizeof (OTF_Glyph) * size);
- otf_gstring.size = size;
- }
- else if (otf_gstring.size < size)
- {
- otf_gstring.glyphs = xrealloc (otf_gstring.glyphs,
- sizeof (OTF_Glyph) * size);
+ otf_gstring.glyphs = xnrealloc (otf_gstring.glyphs,
+ size, sizeof (OTF_Glyph));
otf_gstring.size = size;
}
otf_gstring.used = size;
setup_otf_gstring (len);
for (i = 0; i < len; i++)
{
- otf_gstring.glyphs[i].c = in->glyphs[from + i].c;
+ otf_gstring.glyphs[i].c = in->glyphs[from + i].c & 0x11FFFF;
otf_gstring.glyphs[i].glyph_id = in->glyphs[from + i].code;
}
ftfont_shape_by_flt (Lisp_Object lgstring, struct font *font,
FT_Face ft_face, OTF *otf, FT_Matrix *matrix)
{
- EMACS_INT len = LGSTRING_GLYPH_LEN (lgstring);
- EMACS_INT i;
+ ptrdiff_t len = LGSTRING_GLYPH_LEN (lgstring);
+ ptrdiff_t i;
struct MFLTFontFT flt_font_ft;
MFLT *flt = NULL;
int with_variation_selector = 0;
}
len = i;
- lint_assume (len <= TYPE_MAXIMUM (EMACS_INT) - 2);
+ lint_assume (len <= STRING_BYTES_BOUND);
if (with_variation_selector)
{
}
}
+ if (INT_MAX / 2 < len)
+ memory_full (SIZE_MAX);
+
if (gstring.allocated == 0)
{
- gstring.allocated = len * 2;
gstring.glyph_size = sizeof (MFLTGlyph);
- gstring.glyphs = xmalloc (sizeof (MFLTGlyph) * gstring.allocated);
+ gstring.glyphs = xnmalloc (len * 2, sizeof (MFLTGlyph));
+ gstring.allocated = len * 2;
}
else if (gstring.allocated < len * 2)
{
+ gstring.glyphs = xnrealloc (gstring.glyphs, len * 2, sizeof (MFLTGlyph));
gstring.allocated = len * 2;
- gstring.glyphs = xrealloc (gstring.glyphs,
- sizeof (MFLTGlyph) * gstring.allocated);
}
memset (gstring.glyphs, 0, sizeof (MFLTGlyph) * len);
for (i = 0; i < len; i++)
int result = mflt_run (&gstring, 0, len, &flt_font_ft.flt_font, flt);
if (result != -2)
break;
- gstring.allocated += gstring.allocated;
- gstring.glyphs = xrealloc (gstring.glyphs,
- sizeof (MFLTGlyph) * gstring.allocated);
+ if (INT_MAX / 2 < gstring.allocated)
+ memory_full (SIZE_MAX);
+ gstring.glyphs = xnrealloc (gstring.glyphs,
+ gstring.allocated, 2 * sizeof (MFLTGlyph));
+ gstring.allocated *= 2;
}
if (gstring.used > LGSTRING_GLYPH_LEN (lgstring))
return Qnil;