comparison src/ftfont.c @ 109423:ae5ef13849d8

Merge from mainline.
author Katsumi Yamaoka <yamaoka@jpl.org>
date Sun, 04 Jul 2010 22:11:22 +0000
parents aec1143e8d85
children 750db9f3e6d8
comparison
equal deleted inserted replaced
109422:bcedeeedc5fb 109423:ae5ef13849d8
78 FTFONT_CACHE_FOR_FACE, 78 FTFONT_CACHE_FOR_FACE,
79 FTFONT_CACHE_FOR_CHARSET, 79 FTFONT_CACHE_FOR_CHARSET,
80 FTFONT_CACHE_FOR_ENTITY 80 FTFONT_CACHE_FOR_ENTITY
81 }; 81 };
82 82
83 static Lisp_Object ftfont_pattern_entity P_ ((FcPattern *, Lisp_Object)); 83 static Lisp_Object ftfont_pattern_entity (FcPattern *, Lisp_Object);
84 84
85 static Lisp_Object ftfont_resolve_generic_family P_ ((Lisp_Object, 85 static Lisp_Object ftfont_resolve_generic_family (Lisp_Object,
86 FcPattern *)); 86 FcPattern *);
87 static Lisp_Object ftfont_lookup_cache P_ ((Lisp_Object, 87 static Lisp_Object ftfont_lookup_cache (Lisp_Object,
88 enum ftfont_cache_for)); 88 enum ftfont_cache_for);
89 89
90 static void ftfont_filter_properties P_ ((Lisp_Object font, Lisp_Object alist)); 90 static void ftfont_filter_properties (Lisp_Object font, Lisp_Object alist);
91 91
92 Lisp_Object ftfont_font_format P_ ((FcPattern *, Lisp_Object)); 92 Lisp_Object ftfont_font_format (FcPattern *, Lisp_Object);
93 93
94 #define SYMBOL_FcChar8(SYM) (FcChar8 *) SDATA (SYMBOL_NAME (SYM)) 94 #define SYMBOL_FcChar8(SYM) (FcChar8 *) SDATA (SYMBOL_NAME (SYM))
95 95
96 static struct 96 static struct
97 { 97 {
186 return Qnil; 186 return Qnil;
187 return adstyle; 187 return adstyle;
188 } 188 }
189 189
190 static Lisp_Object 190 static Lisp_Object
191 ftfont_pattern_entity (p, extra) 191 ftfont_pattern_entity (FcPattern *p, Lisp_Object extra)
192 FcPattern *p;
193 Lisp_Object extra;
194 { 192 {
195 Lisp_Object key, cache, entity; 193 Lisp_Object key, cache, entity;
196 char *file, *str; 194 char *file, *str;
197 int index; 195 int index;
198 int numeric; 196 int numeric;
287 285
288 286
289 static Lisp_Object ftfont_generic_family_list; 287 static Lisp_Object ftfont_generic_family_list;
290 288
291 static Lisp_Object 289 static Lisp_Object
292 ftfont_resolve_generic_family (family, pattern) 290 ftfont_resolve_generic_family (Lisp_Object family, FcPattern *pattern)
293 Lisp_Object family;
294 FcPattern *pattern;
295 { 291 {
296 Lisp_Object slot; 292 Lisp_Object slot;
297 FcPattern *match; 293 FcPattern *match;
298 FcResult result; 294 FcResult result;
299 FcLangSet *langset; 295 FcLangSet *langset;
346 FT_Face ft_face; 342 FT_Face ft_face;
347 FcCharSet *fc_charset; 343 FcCharSet *fc_charset;
348 }; 344 };
349 345
350 static Lisp_Object 346 static Lisp_Object
351 ftfont_lookup_cache (key, cache_for) 347 ftfont_lookup_cache (Lisp_Object key, enum ftfont_cache_for cache_for)
352 Lisp_Object key;
353 enum ftfont_cache_for cache_for;
354 { 348 {
355 Lisp_Object cache, val, entity; 349 Lisp_Object cache, val, entity;
356 struct ftfont_cache_data *cache_data; 350 struct ftfont_cache_data *cache_data;
357 351
358 if (FONT_ENTITY_P (key)) 352 if (FONT_ENTITY_P (key))
448 } 442 }
449 return cache; 443 return cache;
450 } 444 }
451 445
452 FcCharSet * 446 FcCharSet *
453 ftfont_get_fc_charset (entity) 447 ftfont_get_fc_charset (Lisp_Object entity)
454 Lisp_Object entity;
455 { 448 {
456 Lisp_Object val, cache; 449 Lisp_Object val, cache;
457 struct ftfont_cache_data *cache_data; 450 struct ftfont_cache_data *cache_data;
458 451
459 cache = ftfont_lookup_cache (entity, FTFONT_CACHE_FOR_CHARSET); 452 cache = ftfont_lookup_cache (entity, FTFONT_CACHE_FOR_CHARSET);
484 ftfont_info->otf = otf; 477 ftfont_info->otf = otf;
485 return otf; 478 return otf;
486 } 479 }
487 #endif /* HAVE_LIBOTF */ 480 #endif /* HAVE_LIBOTF */
488 481
489 static Lisp_Object ftfont_get_cache P_ ((FRAME_PTR)); 482 static Lisp_Object ftfont_get_cache (FRAME_PTR);
490 static Lisp_Object ftfont_list P_ ((Lisp_Object, Lisp_Object)); 483 static Lisp_Object ftfont_list (Lisp_Object, Lisp_Object);
491 static Lisp_Object ftfont_match P_ ((Lisp_Object, Lisp_Object)); 484 static Lisp_Object ftfont_match (Lisp_Object, Lisp_Object);
492 static Lisp_Object ftfont_list_family P_ ((Lisp_Object)); 485 static Lisp_Object ftfont_list_family (Lisp_Object);
493 static Lisp_Object ftfont_open P_ ((FRAME_PTR, Lisp_Object, int)); 486 static Lisp_Object ftfont_open (FRAME_PTR, Lisp_Object, int);
494 static void ftfont_close P_ ((FRAME_PTR, struct font *)); 487 static void ftfont_close (FRAME_PTR, struct font *);
495 static int ftfont_has_char P_ ((Lisp_Object, int)); 488 static int ftfont_has_char (Lisp_Object, int);
496 static unsigned ftfont_encode_char P_ ((struct font *, int)); 489 static unsigned ftfont_encode_char (struct font *, int);
497 static int ftfont_text_extents P_ ((struct font *, unsigned *, int, 490 static int ftfont_text_extents (struct font *, unsigned *, int,
498 struct font_metrics *)); 491 struct font_metrics *);
499 static int ftfont_get_bitmap P_ ((struct font *, unsigned, 492 static int ftfont_get_bitmap (struct font *, unsigned,
500 struct font_bitmap *, int)); 493 struct font_bitmap *, int);
501 static int ftfont_anchor_point P_ ((struct font *, unsigned, int, 494 static int ftfont_anchor_point (struct font *, unsigned, int,
502 int *, int *)); 495 int *, int *);
503 static Lisp_Object ftfont_otf_capability P_ ((struct font *)); 496 static Lisp_Object ftfont_otf_capability (struct font *);
504 static Lisp_Object ftfont_shape P_ ((Lisp_Object)); 497 static Lisp_Object ftfont_shape (Lisp_Object);
505 498
506 #ifdef HAVE_OTF_GET_VARIATION_GLYPHS 499 #ifdef HAVE_OTF_GET_VARIATION_GLYPHS
507 static int ftfont_variation_glyphs P_ ((struct font *, int c, 500 static int ftfont_variation_glyphs (struct font *, int c,
508 unsigned variations[256])); 501 unsigned variations[256]);
509 #endif /* HAVE_OTF_GET_VARIATION_GLYPHS */ 502 #endif /* HAVE_OTF_GET_VARIATION_GLYPHS */
510 503
511 struct font_driver ftfont_driver = 504 struct font_driver ftfont_driver =
512 { 505 {
513 0, /* Qfreetype */ 506 0, /* Qfreetype */
557 }; 550 };
558 551
559 extern Lisp_Object QCname; 552 extern Lisp_Object QCname;
560 553
561 static Lisp_Object 554 static Lisp_Object
562 ftfont_get_cache (f) 555 ftfont_get_cache (FRAME_PTR f)
563 FRAME_PTR f;
564 { 556 {
565 return freetype_font_cache; 557 return freetype_font_cache;
566 } 558 }
567 559
568 static int 560 static int
569 ftfont_get_charset (registry) 561 ftfont_get_charset (Lisp_Object registry)
570 Lisp_Object registry;
571 { 562 {
572 char *str = (char *) SDATA (SYMBOL_NAME (registry)); 563 char *str = (char *) SDATA (SYMBOL_NAME (registry));
573 char *re = alloca (SBYTES (SYMBOL_NAME (registry)) * 2 + 1); 564 char *re = alloca (SBYTES (SYMBOL_NAME (registry)) * 2 + 1);
574 Lisp_Object regexp; 565 Lisp_Object regexp;
575 int i, j; 566 int i, j;
703 spec->nfeatures[i] = j; 694 spec->nfeatures[i] = j;
704 } 695 }
705 return spec; 696 return spec;
706 } 697 }
707 698
708 static FcPattern *ftfont_spec_pattern P_ ((Lisp_Object, char *, 699 static FcPattern *ftfont_spec_pattern (Lisp_Object, char *,
709 struct OpenTypeSpec **, 700 struct OpenTypeSpec **,
710 char **langname)); 701 char **langname);
711 702
712 static FcPattern * 703 static FcPattern *
713 ftfont_spec_pattern (spec, otlayout, otspec, langname) 704 ftfont_spec_pattern (Lisp_Object spec, char *otlayout, struct OpenTypeSpec **otspec, char **langname)
714 Lisp_Object spec;
715 char *otlayout;
716 struct OpenTypeSpec **otspec;
717 char **langname;
718 { 705 {
719 Lisp_Object tmp, extra; 706 Lisp_Object tmp, extra;
720 FcPattern *pattern = NULL; 707 FcPattern *pattern = NULL;
721 FcCharSet *charset = NULL; 708 FcCharSet *charset = NULL;
722 FcLangSet *langset = NULL; 709 FcLangSet *langset = NULL;
869 if (charset && fc_charset_idx < 0) FcCharSetDestroy (charset); 856 if (charset && fc_charset_idx < 0) FcCharSetDestroy (charset);
870 return pattern; 857 return pattern;
871 } 858 }
872 859
873 static Lisp_Object 860 static Lisp_Object
874 ftfont_list (frame, spec) 861 ftfont_list (Lisp_Object frame, Lisp_Object spec)
875 Lisp_Object frame, spec;
876 { 862 {
877 Lisp_Object val = Qnil, family, adstyle; 863 Lisp_Object val = Qnil, family, adstyle;
878 int i; 864 int i;
879 FcPattern *pattern; 865 FcPattern *pattern;
880 FcFontSet *fontset = NULL; 866 FcFontSet *fontset = NULL;
1067 if (pattern) FcPatternDestroy (pattern); 1053 if (pattern) FcPatternDestroy (pattern);
1068 return val; 1054 return val;
1069 } 1055 }
1070 1056
1071 static Lisp_Object 1057 static Lisp_Object
1072 ftfont_match (frame, spec) 1058 ftfont_match (Lisp_Object frame, Lisp_Object spec)
1073 Lisp_Object frame, spec;
1074 { 1059 {
1075 Lisp_Object entity = Qnil; 1060 Lisp_Object entity = Qnil;
1076 FcPattern *pattern, *match = NULL; 1061 FcPattern *pattern, *match = NULL;
1077 FcResult result; 1062 FcResult result;
1078 char otlayout[15]; /* For "otlayout:XXXX" */ 1063 char otlayout[15]; /* For "otlayout:XXXX" */
1118 FONT_ADD_LOG ("ftfont-match", spec, entity); 1103 FONT_ADD_LOG ("ftfont-match", spec, entity);
1119 return entity; 1104 return entity;
1120 } 1105 }
1121 1106
1122 static Lisp_Object 1107 static Lisp_Object
1123 ftfont_list_family (frame) 1108 ftfont_list_family (Lisp_Object frame)
1124 Lisp_Object frame;
1125 { 1109 {
1126 Lisp_Object list = Qnil; 1110 Lisp_Object list = Qnil;
1127 FcPattern *pattern = NULL; 1111 FcPattern *pattern = NULL;
1128 FcFontSet *fontset = NULL; 1112 FcFontSet *fontset = NULL;
1129 FcObjectSet *objset = NULL; 1113 FcObjectSet *objset = NULL;
1162 return list; 1146 return list;
1163 } 1147 }
1164 1148
1165 1149
1166 static Lisp_Object 1150 static Lisp_Object
1167 ftfont_open (f, entity, pixel_size) 1151 ftfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size)
1168 FRAME_PTR f;
1169 Lisp_Object entity;
1170 int pixel_size;
1171 { 1152 {
1172 struct ftfont_info *ftfont_info; 1153 struct ftfont_info *ftfont_info;
1173 struct font *font; 1154 struct font *font;
1174 struct ftfont_cache_data *cache_data; 1155 struct ftfont_cache_data *cache_data;
1175 FT_Face ft_face; 1156 FT_Face ft_face;
1305 1286
1306 return font_object; 1287 return font_object;
1307 } 1288 }
1308 1289
1309 static void 1290 static void
1310 ftfont_close (f, font) 1291 ftfont_close (FRAME_PTR f, struct font *font)
1311 FRAME_PTR f;
1312 struct font *font;
1313 { 1292 {
1314 struct ftfont_info *ftfont_info = (struct ftfont_info *) font; 1293 struct ftfont_info *ftfont_info = (struct ftfont_info *) font;
1315 Lisp_Object val, cache; 1294 Lisp_Object val, cache;
1316 1295
1317 val = Fcons (font->props[FONT_FILE_INDEX], make_number (ftfont_info->index)); 1296 val = Fcons (font->props[FONT_FILE_INDEX], make_number (ftfont_info->index));
1333 else 1312 else
1334 FT_Done_Size (ftfont_info->ft_size); 1313 FT_Done_Size (ftfont_info->ft_size);
1335 } 1314 }
1336 1315
1337 static int 1316 static int
1338 ftfont_has_char (font, c) 1317 ftfont_has_char (Lisp_Object font, int c)
1339 Lisp_Object font;
1340 int c;
1341 { 1318 {
1342 struct charset *cs = NULL; 1319 struct charset *cs = NULL;
1343 1320
1344 if (EQ (AREF (font, FONT_ADSTYLE_INDEX), Qja) 1321 if (EQ (AREF (font, FONT_ADSTYLE_INDEX), Qja)
1345 && charset_jisx0208 >= 0) 1322 && charset_jisx0208 >= 0)
1365 != 0); 1342 != 0);
1366 } 1343 }
1367 } 1344 }
1368 1345
1369 static unsigned 1346 static unsigned
1370 ftfont_encode_char (font, c) 1347 ftfont_encode_char (struct font *font, int c)
1371 struct font *font;
1372 int c;
1373 { 1348 {
1374 struct ftfont_info *ftfont_info = (struct ftfont_info *) font; 1349 struct ftfont_info *ftfont_info = (struct ftfont_info *) font;
1375 FT_Face ft_face = ftfont_info->ft_size->face; 1350 FT_Face ft_face = ftfont_info->ft_size->face;
1376 FT_ULong charcode = c; 1351 FT_ULong charcode = c;
1377 FT_UInt code = FT_Get_Char_Index (ft_face, charcode); 1352 FT_UInt code = FT_Get_Char_Index (ft_face, charcode);
1378 1353
1379 return (code > 0 ? code : FONT_INVALID_CODE); 1354 return (code > 0 ? code : FONT_INVALID_CODE);
1380 } 1355 }
1381 1356
1382 static int 1357 static int
1383 ftfont_text_extents (font, code, nglyphs, metrics) 1358 ftfont_text_extents (struct font *font, unsigned int *code, int nglyphs, struct font_metrics *metrics)
1384 struct font *font;
1385 unsigned *code;
1386 int nglyphs;
1387 struct font_metrics *metrics;
1388 { 1359 {
1389 struct ftfont_info *ftfont_info = (struct ftfont_info *) font; 1360 struct ftfont_info *ftfont_info = (struct ftfont_info *) font;
1390 FT_Face ft_face = ftfont_info->ft_size->face; 1361 FT_Face ft_face = ftfont_info->ft_size->face;
1391 int width = 0; 1362 int width = 0;
1392 int i, first; 1363 int i, first;
1437 1408
1438 return width; 1409 return width;
1439 } 1410 }
1440 1411
1441 static int 1412 static int
1442 ftfont_get_bitmap (font, code, bitmap, bits_per_pixel) 1413 ftfont_get_bitmap (struct font *font, unsigned int code, struct font_bitmap *bitmap, int bits_per_pixel)
1443 struct font *font;
1444 unsigned code;
1445 struct font_bitmap *bitmap;
1446 int bits_per_pixel;
1447 { 1414 {
1448 struct ftfont_info *ftfont_info = (struct ftfont_info *) font; 1415 struct ftfont_info *ftfont_info = (struct ftfont_info *) font;
1449 FT_Face ft_face = ftfont_info->ft_size->face; 1416 FT_Face ft_face = ftfont_info->ft_size->face;
1450 FT_Int32 load_flags = FT_LOAD_RENDER; 1417 FT_Int32 load_flags = FT_LOAD_RENDER;
1451 1418
1485 1452
1486 return 0; 1453 return 0;
1487 } 1454 }
1488 1455
1489 static int 1456 static int
1490 ftfont_anchor_point (font, code, index, x, y) 1457 ftfont_anchor_point (struct font *font, unsigned int code, int index, int *x, int *y)
1491 struct font *font;
1492 unsigned code;
1493 int index;
1494 int *x, *y;
1495 { 1458 {
1496 struct ftfont_info *ftfont_info = (struct ftfont_info *) font; 1459 struct ftfont_info *ftfont_info = (struct ftfont_info *) font;
1497 FT_Face ft_face = ftfont_info->ft_size->face; 1460 FT_Face ft_face = ftfont_info->ft_size->face;
1498 1461
1499 if (ftfont_info->ft_size != ft_face->size) 1462 if (ftfont_info->ft_size != ft_face->size)
2675 ":capability", 2638 ":capability",
2676 NULL, 2639 NULL,
2677 }; 2640 };
2678 2641
2679 static void 2642 static void
2680 ftfont_filter_properties (font, alist) 2643 ftfont_filter_properties (Lisp_Object font, Lisp_Object alist)
2681 Lisp_Object font;
2682 Lisp_Object alist;
2683 { 2644 {
2684 Lisp_Object it; 2645 Lisp_Object it;
2685 int i; 2646 int i;
2686 2647
2687 /* Set boolean values to Qt or Qnil */ 2648 /* Set boolean values to Qt or Qnil */
2719 } 2680 }
2720 } 2681 }
2721 2682
2722 2683
2723 void 2684 void
2724 syms_of_ftfont () 2685 syms_of_ftfont (void)
2725 { 2686 {
2726 DEFSYM (Qfreetype, "freetype"); 2687 DEFSYM (Qfreetype, "freetype");
2727 DEFSYM (Qmonospace, "monospace"); 2688 DEFSYM (Qmonospace, "monospace");
2728 DEFSYM (Qsans_serif, "sans-serif"); 2689 DEFSYM (Qsans_serif, "sans-serif");
2729 DEFSYM (Qserif, "serif"); 2690 DEFSYM (Qserif, "serif");