comparison src/ftfont.c @ 90565:258e759bcffa

(ftfont_driver): Set ftfont_driver.match to ftfont_match. (ftfont_list): Don't check :name property. (ftfont_match): New function.
author Kenichi Handa <handa@m17n.org>
date Tue, 01 Aug 2006 01:31:39 +0000
parents 45553626fa76
children 009accc57d73
comparison
equal deleted inserted replaced
90564:cb3eb6150704 90565:258e759bcffa
245 } 245 }
246 246
247 247
248 static Lisp_Object ftfont_get_cache P_ ((Lisp_Object)); 248 static Lisp_Object ftfont_get_cache P_ ((Lisp_Object));
249 static Lisp_Object ftfont_list P_ ((Lisp_Object, Lisp_Object)); 249 static Lisp_Object ftfont_list P_ ((Lisp_Object, Lisp_Object));
250 static Lisp_Object ftfont_match P_ ((Lisp_Object, Lisp_Object));
250 static Lisp_Object ftfont_list_family P_ ((Lisp_Object)); 251 static Lisp_Object ftfont_list_family P_ ((Lisp_Object));
251 static void ftfont_free_entity P_ ((Lisp_Object)); 252 static void ftfont_free_entity P_ ((Lisp_Object));
252 static struct font *ftfont_open P_ ((FRAME_PTR, Lisp_Object, int)); 253 static struct font *ftfont_open P_ ((FRAME_PTR, Lisp_Object, int));
253 static void ftfont_close P_ ((FRAME_PTR, struct font *)); 254 static void ftfont_close P_ ((FRAME_PTR, struct font *));
254 static int ftfont_has_char P_ ((Lisp_Object, int)); 255 static int ftfont_has_char P_ ((Lisp_Object, int));
263 struct font_driver ftfont_driver = 264 struct font_driver ftfont_driver =
264 { 265 {
265 (Lisp_Object) NULL, /* Qfreetype */ 266 (Lisp_Object) NULL, /* Qfreetype */
266 ftfont_get_cache, 267 ftfont_get_cache,
267 ftfont_list, 268 ftfont_list,
269 ftfont_match,
268 ftfont_list_family, 270 ftfont_list_family,
269 ftfont_free_entity, 271 ftfont_free_entity,
270 ftfont_open, 272 ftfont_open,
271 ftfont_close, 273 ftfont_close,
272 /* We can't draw a text without device dependent functions. */ 274 /* We can't draw a text without device dependent functions. */
304 306
305 static Lisp_Object 307 static Lisp_Object
306 ftfont_list (frame, spec) 308 ftfont_list (frame, spec)
307 Lisp_Object frame, spec; 309 Lisp_Object frame, spec;
308 { 310 {
309 Lisp_Object val, tmp, extra, font_name; 311 Lisp_Object val, tmp, extra;
310 int i; 312 int i;
311 FcPattern *pattern = NULL; 313 FcPattern *pattern = NULL;
312 FcCharSet *charset = NULL; 314 FcCharSet *charset = NULL;
313 FcLangSet *langset = NULL; 315 FcLangSet *langset = NULL;
314 FcFontSet *fontset = NULL; 316 FcFontSet *fontset = NULL;
315 FcObjectSet *objset = NULL; 317 FcObjectSet *objset = NULL;
318 Lisp_Object script;
316 Lisp_Object registry = Qunicode_bmp; 319 Lisp_Object registry = Qunicode_bmp;
317 int weight = 0; 320 int weight = 0;
318 double dpi = -1; 321 double dpi = -1;
319 int spacing = -1; 322 int spacing = -1;
320 int scalable = -1; 323 int scalable = -1;
348 } 351 }
349 else if (! EQ (registry, Qiso10646_1) && ! EQ (registry, Qunicode_bmp)) 352 else if (! EQ (registry, Qiso10646_1) && ! EQ (registry, Qunicode_bmp))
350 return val; 353 return val;
351 } 354 }
352 355
353 extra = AREF (spec, FONT_EXTRA_INDEX);
354 font_name = Qnil;
355 otf_script[0] = '\0'; 356 otf_script[0] = '\0';
356 if (CONSP (extra)) 357 script = Qnil;
357 { 358 for (extra = AREF (spec, FONT_EXTRA_INDEX);
358 Lisp_Object script = Qnil; 359 CONSP (extra); extra = XCDR (extra))
359 360 {
360 tmp = assq_no_quit (QCname, extra); 361 Lisp_Object key, val;
361 if (CONSP (tmp) && STRINGP (XCDR (tmp)) 362
362 && SDATA (XCDR (tmp))[0] == ':') 363 tmp = XCAR (extra);
363 font_name = XCDR (tmp); 364 key = XCAR (tmp), val = XCDR (tmp);
364 tmp = assq_no_quit (QCotf, extra); 365 if (EQ (key, QCotf))
365 if (CONSP (tmp) && SYMBOLP (XCDR (tmp))) 366 {
366 { 367 script = assq_no_quit (val, Votf_script_alist);
367 tmp = XCDR (tmp);
368 script = assq_no_quit (tmp, Votf_script_alist);
369 if (CONSP (script) && SYMBOLP (XCDR (script))) 368 if (CONSP (script) && SYMBOLP (XCDR (script)))
370 script = XCDR (script); 369 script = XCDR (script);
371 tmp = SYMBOL_NAME (tmp); 370 tmp = SYMBOL_NAME (val);
372 sprintf (otf_script, "otlayout:%s", (char *) SDATA (tmp)); 371 sprintf (otf_script, "otlayout:%s", (char *) SDATA (tmp));
373 } 372 }
374 tmp = assq_no_quit (QClanguage, extra); 373 else if (EQ (key, QClanguage))
375 if (CONSP (tmp))
376 { 374 {
377 langset = FcLangSetCreate (); 375 langset = FcLangSetCreate ();
378 if (! langset) 376 if (! langset)
379 goto err; 377 goto err;
380 tmp = XCDR (tmp); 378 if (SYMBOLP (val))
381 if (SYMBOLP (tmp))
382 { 379 {
383 if (! FcLangSetAdd (langset, SYMBOL_FcChar8 (tmp))) 380 if (! FcLangSetAdd (langset, SYMBOL_FcChar8 (val)))
384 goto err; 381 goto err;
385 } 382 }
386 else 383 else
387 while (CONSP (tmp)) 384 for (; CONSP (val); val = XCDR (val))
388 { 385 if (SYMBOLP (XCAR (val))
389 if (SYMBOLP (XCAR (tmp)) 386 && ! FcLangSetAdd (langset, SYMBOL_FcChar8 (XCAR (val))))
390 && ! FcLangSetAdd (langset, SYMBOL_FcChar8 (XCAR (tmp))))
391 goto err;
392 tmp = XCDR (tmp);
393 }
394 }
395 tmp = assq_no_quit (QCscript, extra);
396 if (CONSP (tmp))
397 script = XCDR (tmp);
398 if (! NILP (script) && ! charset)
399 {
400 Lisp_Object chars
401 = assq_no_quit (script, Vscript_representative_chars);
402
403 if (CONSP (chars))
404 {
405 charset = FcCharSetCreate ();
406 if (! charset)
407 goto err; 387 goto err;
408 for (chars = XCDR (chars); CONSP (chars); chars = XCDR (chars)) 388 }
409 if (CHARACTERP (XCAR (chars)) 389 else if (EQ (key, QCscript))
410 && ! FcCharSetAddChar (charset, XUINT (XCAR (chars)))) 390 script = val;
411 goto err; 391 else if (EQ (key, QCdpi))
412 } 392 dpi = XINT (val);
413 } 393 else if (EQ (key, QCspacing))
414 tmp = assq_no_quit (QCdpi, extra); 394 spacing = XINT (val);
415 if (CONSP (tmp)) 395 else if (EQ (key, QCscalable))
416 dpi = XINT (XCDR (tmp)); 396 scalable = ! NILP (val);
417 tmp = assq_no_quit (QCspacing, extra); 397 }
418 if (CONSP (tmp)) 398
419 spacing = XINT (XCDR (tmp)); 399 if (! NILP (script) && ! charset)
420 tmp = assq_no_quit (QCscalable, extra); 400 {
421 if (CONSP (tmp)) 401 Lisp_Object chars = assq_no_quit (script, Vscript_representative_chars);
422 scalable = ! NILP (XCDR (tmp)); 402
423 } 403 if (CONSP (chars))
424 404 {
425 if (STRINGP (font_name)) 405 charset = FcCharSetCreate ();
426 pattern = FcNameParse (SDATA (font_name)); 406 if (! charset)
427 else 407 goto err;
428 pattern = FcPatternCreate (); 408 for (chars = XCDR (chars); CONSP (chars); chars = XCDR (chars))
409 if (CHARACTERP (XCAR (chars))
410 && ! FcCharSetAddChar (charset, XUINT (XCAR (chars))))
411 goto err;
412 }
413 }
414
415 pattern = FcPatternCreate ();
429 if (! pattern) 416 if (! pattern)
430 goto err; 417 goto err;
431
432 tmp = AREF (spec, FONT_FOUNDRY_INDEX); 418 tmp = AREF (spec, FONT_FOUNDRY_INDEX);
433 if (SYMBOLP (tmp) && ! NILP (tmp) 419 if (SYMBOLP (tmp) && ! NILP (tmp)
434 && ! FcPatternAddString (pattern, FC_FOUNDRY, SYMBOL_FcChar8 (tmp))) 420 && ! FcPatternAddString (pattern, FC_FOUNDRY, SYMBOL_FcChar8 (tmp)))
435 goto err; 421 goto err;
436 tmp = AREF (spec, FONT_FAMILY_INDEX); 422 tmp = AREF (spec, FONT_FAMILY_INDEX);
554 if (fontset) FcFontSetDestroy (fontset); 540 if (fontset) FcFontSetDestroy (fontset);
555 if (langset) FcLangSetDestroy (langset); 541 if (langset) FcLangSetDestroy (langset);
556 if (pattern) FcPatternDestroy (pattern); 542 if (pattern) FcPatternDestroy (pattern);
557 543
558 return val; 544 return val;
545 }
546
547 static Lisp_Object
548 ftfont_match (frame, spec)
549 Lisp_Object frame, spec;
550 {
551 Lisp_Object extra, val, entity;
552 FcPattern *pattern = NULL, *match = NULL;
553 FcResult result;
554
555 if (! fc_initialized)
556 {
557 FcInit ();
558 fc_initialized = 1;
559 }
560
561 extra = AREF (spec, FONT_EXTRA_INDEX);
562 val = assq_no_quit (QCname, extra);
563 if (! CONSP (val) || ! STRINGP (XCDR (val)))
564 return Qnil;
565
566 entity = Qnil;
567 pattern = FcNameParse (SDATA (XCDR (val)));
568 if (pattern)
569 {
570 if (FcConfigSubstitute (NULL, pattern, FcMatchPattern) == FcTrue)
571 {
572 FcDefaultSubstitute (pattern);
573 match = FcFontMatch (NULL, pattern, &result);
574 fprintf (stderr, "%s\n", (char *) FcNameUnparse (match));
575 if (match)
576 {
577 entity = ftfont_pattern_entity (match, frame, Qunicode_bmp);
578 FcPatternDestroy (match);
579 }
580 }
581 FcPatternDestroy (pattern);
582 }
583
584 return entity;
559 } 585 }
560 586
561 static Lisp_Object 587 static Lisp_Object
562 ftfont_list_family (frame) 588 ftfont_list_family (frame)
563 Lisp_Object frame; 589 Lisp_Object frame;