diff options
Diffstat (limited to 'src/ftfont.c')
| -rw-r--r-- | src/ftfont.c | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/src/ftfont.c b/src/ftfont.c index 4e313a89021..131465b4f85 100644 --- a/src/ftfont.c +++ b/src/ftfont.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* ftfont.c -- FreeType font driver. | 1 | /* ftfont.c -- FreeType font driver. |
| 2 | Copyright (C) 2006-2011 Free Software Foundation, Inc. | 2 | Copyright (C) 2006-2012 Free Software Foundation, Inc. |
| 3 | Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 | 3 | Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 |
| 4 | National Institute of Advanced Industrial Science and Technology (AIST) | 4 | National Institute of Advanced Industrial Science and Technology (AIST) |
| 5 | Registration Number H13PRO009 | 5 | Registration Number H13PRO009 |
| @@ -164,6 +164,13 @@ get_adstyle_property (FcPattern *p) | |||
| 164 | char *str, *end; | 164 | char *str, *end; |
| 165 | Lisp_Object adstyle; | 165 | Lisp_Object adstyle; |
| 166 | 166 | ||
| 167 | #ifdef FC_FONTFORMAT | ||
| 168 | if ((FcPatternGetString (p, FC_FONTFORMAT, 0, &fcstr) == FcResultMatch) | ||
| 169 | && xstrcasecmp ((char *) fcstr, "bdf") != 0 | ||
| 170 | && xstrcasecmp ((char *) fcstr, "pcf") != 0) | ||
| 171 | /* Not a BDF nor PCF font. */ | ||
| 172 | return Qnil; | ||
| 173 | #endif | ||
| 167 | if (FcPatternGetString (p, FC_STYLE, 0, &fcstr) != FcResultMatch) | 174 | if (FcPatternGetString (p, FC_STYLE, 0, &fcstr) != FcResultMatch) |
| 168 | return Qnil; | 175 | return Qnil; |
| 169 | str = (char *) fcstr; | 176 | str = (char *) fcstr; |
| @@ -214,6 +221,10 @@ ftfont_pattern_entity (FcPattern *p, Lisp_Object extra) | |||
| 214 | 221 | ||
| 215 | for (i = 0; i < FONT_OBJLIST_INDEX; i++) | 222 | for (i = 0; i < FONT_OBJLIST_INDEX; i++) |
| 216 | ASET (val, i, AREF (entity, i)); | 223 | ASET (val, i, AREF (entity, i)); |
| 224 | |||
| 225 | ASET (val, FONT_EXTRA_INDEX, Fcopy_sequence (extra)); | ||
| 226 | font_put_extra (val, QCfont_entity, key); | ||
| 227 | |||
| 217 | return val; | 228 | return val; |
| 218 | } | 229 | } |
| 219 | entity = font_make_entity (); | 230 | entity = font_make_entity (); |
| @@ -268,7 +279,7 @@ ftfont_pattern_entity (FcPattern *p, Lisp_Object extra) | |||
| 268 | } | 279 | } |
| 269 | else | 280 | else |
| 270 | { | 281 | { |
| 271 | /* As this font is not scalable, parhaps this is a BDF or PCF | 282 | /* As this font is not scalable, perhaps this is a BDF or PCF |
| 272 | font. */ | 283 | font. */ |
| 273 | FT_Face ft_face; | 284 | FT_Face ft_face; |
| 274 | 285 | ||
| @@ -682,7 +693,10 @@ ftfont_get_open_type_spec (Lisp_Object otf_spec) | |||
| 682 | if (NILP (val)) | 693 | if (NILP (val)) |
| 683 | continue; | 694 | continue; |
| 684 | len = Flength (val); | 695 | len = Flength (val); |
| 685 | spec->features[i] = malloc (sizeof (int) * XINT (len)); | 696 | spec->features[i] = |
| 697 | (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (int) < XINT (len) | ||
| 698 | ? 0 | ||
| 699 | : malloc (sizeof (int) * XINT (len))); | ||
| 686 | if (! spec->features[i]) | 700 | if (! spec->features[i]) |
| 687 | { | 701 | { |
| 688 | if (i > 0 && spec->features[0]) | 702 | if (i > 0 && spec->features[0]) |
| @@ -723,7 +737,7 @@ ftfont_spec_pattern (Lisp_Object spec, char *otlayout, struct OpenTypeSpec **ots | |||
| 723 | 737 | ||
| 724 | if ((n = FONT_SLANT_NUMERIC (spec)) >= 0 | 738 | if ((n = FONT_SLANT_NUMERIC (spec)) >= 0 |
| 725 | && n < 100) | 739 | && n < 100) |
| 726 | /* Fontconfig doesn't support reverse-italic/obligue. */ | 740 | /* Fontconfig doesn't support reverse-italic/oblique. */ |
| 727 | return NULL; | 741 | return NULL; |
| 728 | 742 | ||
| 729 | if (INTEGERP (AREF (spec, FONT_DPI_INDEX))) | 743 | if (INTEGERP (AREF (spec, FONT_DPI_INDEX))) |
| @@ -946,7 +960,7 @@ ftfont_list (Lisp_Object frame, Lisp_Object spec) | |||
| 946 | /* Need fix because this finds any fonts. */ | 960 | /* Need fix because this finds any fonts. */ |
| 947 | if (fontset->nfont == 0 && ! NILP (family)) | 961 | if (fontset->nfont == 0 && ! NILP (family)) |
| 948 | { | 962 | { |
| 949 | /* Try maching with configuration. For instance, the | 963 | /* Try matching with configuration. For instance, the |
| 950 | configuration may specify "Nimbus Mono L" as an alias of | 964 | configuration may specify "Nimbus Mono L" as an alias of |
| 951 | "Courier". */ | 965 | "Courier". */ |
| 952 | FcPattern *pat = FcPatternBuild (0, FC_FAMILY, FcTypeString, | 966 | FcPattern *pat = FcPatternBuild (0, FC_FAMILY, FcTypeString, |
| @@ -1455,7 +1469,7 @@ ftfont_get_bitmap (struct font *font, unsigned int code, struct font_bitmap *bit | |||
| 1455 | : ft_face->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD_V ? 8 | 1469 | : ft_face->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD_V ? 8 |
| 1456 | : -1); | 1470 | : -1); |
| 1457 | if (bitmap->bits_per_pixel < 0) | 1471 | if (bitmap->bits_per_pixel < 0) |
| 1458 | /* We don't suport that kind of pixel mode. */ | 1472 | /* We don't support that kind of pixel mode. */ |
| 1459 | return -1; | 1473 | return -1; |
| 1460 | bitmap->rows = ft_face->glyph->bitmap.rows; | 1474 | bitmap->rows = ft_face->glyph->bitmap.rows; |
| 1461 | bitmap->width = ft_face->glyph->bitmap.width; | 1475 | bitmap->width = ft_face->glyph->bitmap.width; |
| @@ -1761,15 +1775,10 @@ static OTF_GlyphString otf_gstring; | |||
| 1761 | static void | 1775 | static void |
| 1762 | setup_otf_gstring (int size) | 1776 | setup_otf_gstring (int size) |
| 1763 | { | 1777 | { |
| 1764 | if (otf_gstring.size == 0) | 1778 | if (otf_gstring.size < size) |
| 1765 | { | ||
| 1766 | otf_gstring.glyphs = (OTF_Glyph *) xmalloc (sizeof (OTF_Glyph) * size); | ||
| 1767 | otf_gstring.size = size; | ||
| 1768 | } | ||
| 1769 | else if (otf_gstring.size < size) | ||
| 1770 | { | 1779 | { |
| 1771 | otf_gstring.glyphs = xrealloc (otf_gstring.glyphs, | 1780 | otf_gstring.glyphs = xnrealloc (otf_gstring.glyphs, |
| 1772 | sizeof (OTF_Glyph) * size); | 1781 | size, sizeof (OTF_Glyph)); |
| 1773 | otf_gstring.size = size; | 1782 | otf_gstring.size = size; |
| 1774 | } | 1783 | } |
| 1775 | otf_gstring.used = size; | 1784 | otf_gstring.used = size; |
| @@ -1847,7 +1856,7 @@ ftfont_drive_otf (MFLTFont *font, | |||
| 1847 | setup_otf_gstring (len); | 1856 | setup_otf_gstring (len); |
| 1848 | for (i = 0; i < len; i++) | 1857 | for (i = 0; i < len; i++) |
| 1849 | { | 1858 | { |
| 1850 | otf_gstring.glyphs[i].c = in->glyphs[from + i].c; | 1859 | otf_gstring.glyphs[i].c = in->glyphs[from + i].c & 0x11FFFF; |
| 1851 | otf_gstring.glyphs[i].glyph_id = in->glyphs[from + i].code; | 1860 | otf_gstring.glyphs[i].glyph_id = in->glyphs[from + i].code; |
| 1852 | } | 1861 | } |
| 1853 | 1862 | ||
| @@ -2445,17 +2454,19 @@ ftfont_shape_by_flt (Lisp_Object lgstring, struct font *font, | |||
| 2445 | } | 2454 | } |
| 2446 | } | 2455 | } |
| 2447 | 2456 | ||
| 2457 | if (INT_MAX / 2 < len) | ||
| 2458 | memory_full (SIZE_MAX); | ||
| 2459 | |||
| 2448 | if (gstring.allocated == 0) | 2460 | if (gstring.allocated == 0) |
| 2449 | { | 2461 | { |
| 2450 | gstring.allocated = len * 2; | ||
| 2451 | gstring.glyph_size = sizeof (MFLTGlyph); | 2462 | gstring.glyph_size = sizeof (MFLTGlyph); |
| 2452 | gstring.glyphs = xmalloc (sizeof (MFLTGlyph) * gstring.allocated); | 2463 | gstring.glyphs = xnmalloc (len * 2, sizeof (MFLTGlyph)); |
| 2464 | gstring.allocated = len * 2; | ||
| 2453 | } | 2465 | } |
| 2454 | else if (gstring.allocated < len * 2) | 2466 | else if (gstring.allocated < len * 2) |
| 2455 | { | 2467 | { |
| 2468 | gstring.glyphs = xnrealloc (gstring.glyphs, len * 2, sizeof (MFLTGlyph)); | ||
| 2456 | gstring.allocated = len * 2; | 2469 | gstring.allocated = len * 2; |
| 2457 | gstring.glyphs = xrealloc (gstring.glyphs, | ||
| 2458 | sizeof (MFLTGlyph) * gstring.allocated); | ||
| 2459 | } | 2470 | } |
| 2460 | memset (gstring.glyphs, 0, sizeof (MFLTGlyph) * len); | 2471 | memset (gstring.glyphs, 0, sizeof (MFLTGlyph) * len); |
| 2461 | for (i = 0; i < len; i++) | 2472 | for (i = 0; i < len; i++) |
| @@ -2504,9 +2515,11 @@ ftfont_shape_by_flt (Lisp_Object lgstring, struct font *font, | |||
| 2504 | int result = mflt_run (&gstring, 0, len, &flt_font_ft.flt_font, flt); | 2515 | int result = mflt_run (&gstring, 0, len, &flt_font_ft.flt_font, flt); |
| 2505 | if (result != -2) | 2516 | if (result != -2) |
| 2506 | break; | 2517 | break; |
| 2507 | gstring.allocated += gstring.allocated; | 2518 | if (INT_MAX / 2 < gstring.allocated) |
| 2508 | gstring.glyphs = xrealloc (gstring.glyphs, | 2519 | memory_full (SIZE_MAX); |
| 2509 | sizeof (MFLTGlyph) * gstring.allocated); | 2520 | gstring.glyphs = xnrealloc (gstring.glyphs, |
| 2521 | gstring.allocated, 2 * sizeof (MFLTGlyph)); | ||
| 2522 | gstring.allocated *= 2; | ||
| 2510 | } | 2523 | } |
| 2511 | if (gstring.used > LGSTRING_GLYPH_LEN (lgstring)) | 2524 | if (gstring.used > LGSTRING_GLYPH_LEN (lgstring)) |
| 2512 | return Qnil; | 2525 | return Qnil; |