diff options
| author | Kenichi Handa | 2009-05-08 06:22:40 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2009-05-08 06:22:40 +0000 |
| commit | 398dbf2661ead6cca0ee96679a377fbff38d21e2 (patch) | |
| tree | 8484c513f55f88867954d61f10f3cd85c2938fed /src | |
| parent | 777c6e6a7b526e5ea24de3e410e964ca81fa7bf7 (diff) | |
| download | emacs-398dbf2661ead6cca0ee96679a377fbff38d21e2.tar.gz emacs-398dbf2661ead6cca0ee96679a377fbff38d21e2.zip | |
Cancel previous changes.
Diffstat (limited to 'src')
| -rw-r--r-- | src/xfont.c | 174 |
1 files changed, 18 insertions, 156 deletions
diff --git a/src/xfont.c b/src/xfont.c index 987c2ddc210..afafca89c24 100644 --- a/src/xfont.c +++ b/src/xfont.c | |||
| @@ -256,129 +256,13 @@ xfont_encode_coding_xlfd (char *xlfd) | |||
| 256 | return len; | 256 | return len; |
| 257 | } | 257 | } |
| 258 | 258 | ||
| 259 | /* Check if XFONT supports CHARS (cons or vector of characters). If | 259 | static Lisp_Object xfont_list_pattern P_ ((Lisp_Object, Display *, char *)); |
| 260 | yes, return 1. If no, return 0. */ | ||
| 261 | |||
| 262 | static int xfont_check_char_support P_ ((XFontStruct *, Lisp_Object)); | ||
| 263 | |||
| 264 | static int | ||
| 265 | xfont_check_char_support (xfont, chars) | ||
| 266 | XFontStruct *xfont; | ||
| 267 | Lisp_Object chars; | ||
| 268 | { | ||
| 269 | if (CONSP (chars)) | ||
| 270 | { | ||
| 271 | Lisp_Object tail = chars; | ||
| 272 | |||
| 273 | while (CONSP (tail)) | ||
| 274 | { | ||
| 275 | int c = XINT (XCAR (chars)); | ||
| 276 | XChar2b char2b; | ||
| 277 | char2b.byte1 = c >> 16; | ||
| 278 | char2b.byte2 = c & 0xFF; | ||
| 279 | if (! xfont_get_pcm (xfont, &char2b)) | ||
| 280 | return 0; | ||
| 281 | } | ||
| 282 | return 1; | ||
| 283 | } | ||
| 284 | if (VECTORP (chars)) | ||
| 285 | { | ||
| 286 | int i; | ||
| 287 | |||
| 288 | for (i = ASIZE (chars) - 1; i >= 0; i--) | ||
| 289 | { | ||
| 290 | int c = XINT (AREF (chars, i)); | ||
| 291 | XChar2b char2b; | ||
| 292 | char2b.byte1 = c >> 16; | ||
| 293 | char2b.byte2 = c & 0xFF; | ||
| 294 | if (xfont_get_pcm (xfont, &char2b)) | ||
| 295 | return 1; | ||
| 296 | } | ||
| 297 | return 0; | ||
| 298 | } | ||
| 299 | return 0; | ||
| 300 | } | ||
| 301 | |||
| 302 | |||
| 303 | /* Check if a repertory charset correponding to REGISTRY supports | ||
| 304 | CHARS (cons or vector of characters). If yes, return Qt. If no, | ||
| 305 | return Qnil. If not decidable by REGISTRY, return a copy of CHARS | ||
| 306 | but with elements changed to glyph codes. */ | ||
| 307 | |||
| 308 | static Lisp_Object xfont_check_registry_char_support P_ ((Lisp_Object, | ||
| 309 | Lisp_Object)); | ||
| 310 | |||
| 311 | static Lisp_Object | ||
| 312 | xfont_check_registry_char_support (registry, chars) | ||
| 313 | Lisp_Object registry, chars; | ||
| 314 | { | ||
| 315 | struct charset *encoding, *repertory, *charset; | ||
| 316 | |||
| 317 | if (font_registry_charsets (registry, &encoding, &repertory) < 0) | ||
| 318 | return Qnil; | ||
| 319 | if (! repertory) | ||
| 320 | chars = Fcopy_sequence (chars); | ||
| 321 | charset = repertory ? repertory : encoding; | ||
| 322 | if (CONSP (chars)) | ||
| 323 | { | ||
| 324 | Lisp_Object tail = chars; | ||
| 325 | |||
| 326 | while (CONSP (tail)) | ||
| 327 | { | ||
| 328 | int c, code; | ||
| 329 | |||
| 330 | if (! INTEGERP (XCAR (tail))) | ||
| 331 | return Qnil; | ||
| 332 | c = XINT (XCAR (tail)); | ||
| 333 | code = ENCODE_CHAR (charset, c); | ||
| 334 | if (code == CHARSET_INVALID_CODE (charset)) | ||
| 335 | return Qnil; | ||
| 336 | if (! repertory) | ||
| 337 | XSETCAR (tail, make_number (code)); | ||
| 338 | } | ||
| 339 | return repertory ? Qt : chars; | ||
| 340 | } | ||
| 341 | if (VECTORP (chars)) | ||
| 342 | { | ||
| 343 | int i; | ||
| 344 | |||
| 345 | for (i = ASIZE (chars) - 1; i >= 0; i--) | ||
| 346 | { | ||
| 347 | int c, code; | ||
| 348 | |||
| 349 | if (! INTEGERP (AREF (chars, i))) | ||
| 350 | return Qnil; | ||
| 351 | c = XINT (AREF (chars, i)); | ||
| 352 | code = ENCODE_CHAR (charset, c); | ||
| 353 | |||
| 354 | if (code == CHARSET_INVALID_CODE (charset)) | ||
| 355 | { | ||
| 356 | if (! repertory) | ||
| 357 | return Qnil; | ||
| 358 | } | ||
| 359 | else | ||
| 360 | { | ||
| 361 | if (repertory) | ||
| 362 | return Qt; | ||
| 363 | ASET (chars, i, make_number (code)); | ||
| 364 | } | ||
| 365 | } | ||
| 366 | return repertory ? Qnil : chars; | ||
| 367 | } | ||
| 368 | return Qnil; | ||
| 369 | } | ||
| 370 | |||
| 371 | static Lisp_Object xfont_list_pattern P_ ((Display *, char *, Lisp_Object)); | ||
| 372 | |||
| 373 | /* Return a list of font-entities matching with PATTERN available on | ||
| 374 | DISPLAY. If CHARS is non-nil, exclude fonts not supporting | ||
| 375 | CHARS. */ | ||
| 376 | 260 | ||
| 377 | static Lisp_Object | 261 | static Lisp_Object |
| 378 | xfont_list_pattern (display, pattern, chars) | 262 | xfont_list_pattern (frame, display, pattern) |
| 263 | Lisp_Object frame; | ||
| 379 | Display *display; | 264 | Display *display; |
| 380 | char *pattern; | 265 | char *pattern; |
| 381 | Lisp_Object chars; | ||
| 382 | { | 266 | { |
| 383 | Lisp_Object list = Qnil; | 267 | Lisp_Object list = Qnil; |
| 384 | int i, limit, num_fonts; | 268 | int i, limit, num_fonts; |
| @@ -417,21 +301,11 @@ xfont_list_pattern (display, pattern, chars) | |||
| 417 | { | 301 | { |
| 418 | Lisp_Object entity; | 302 | Lisp_Object entity; |
| 419 | int result; | 303 | int result; |
| 420 | XFontStruct *font = NULL; | 304 | char *p; |
| 421 | 305 | ||
| 422 | if (i > 0 && xstrcasecmp (indices[i - 1], indices[i]) == 0) | 306 | if (i > 0 && xstrcasecmp (indices[i - 1], indices[i]) == 0) |
| 423 | continue; | 307 | continue; |
| 424 | if (! NILP (chars)) | 308 | |
| 425 | { | ||
| 426 | font = XLoadQueryFont (display, indices[i]); | ||
| 427 | if (! font) | ||
| 428 | continue; | ||
| 429 | if (! xfont_check_char_support (font, chars)) | ||
| 430 | { | ||
| 431 | XFreeFont (display, font); | ||
| 432 | continue; | ||
| 433 | } | ||
| 434 | } | ||
| 435 | entity = font_make_entity (); | 309 | entity = font_make_entity (); |
| 436 | ASET (entity, FONT_TYPE_INDEX, Qx); | 310 | ASET (entity, FONT_TYPE_INDEX, Qx); |
| 437 | xfont_decode_coding_xlfd (indices[i], -1, buf); | 311 | xfont_decode_coding_xlfd (indices[i], -1, buf); |
| @@ -440,11 +314,10 @@ xfont_list_pattern (display, pattern, chars) | |||
| 440 | { | 314 | { |
| 441 | /* This may be an alias name. Try to get the full XLFD name | 315 | /* This may be an alias name. Try to get the full XLFD name |
| 442 | from XA_FONT property of the font. */ | 316 | from XA_FONT property of the font. */ |
| 317 | XFontStruct *font = XLoadQueryFont (display, indices[i]); | ||
| 443 | unsigned long value; | 318 | unsigned long value; |
| 444 | 319 | ||
| 445 | if (! font) | 320 | if (! font) |
| 446 | font = XLoadQueryFont (display, indices[i]); | ||
| 447 | if (! font) | ||
| 448 | continue; | 321 | continue; |
| 449 | if (XGetFontProperty (font, XA_FONT, &value)) | 322 | if (XGetFontProperty (font, XA_FONT, &value)) |
| 450 | { | 323 | { |
| @@ -461,10 +334,9 @@ xfont_list_pattern (display, pattern, chars) | |||
| 461 | } | 334 | } |
| 462 | XFree (name); | 335 | XFree (name); |
| 463 | } | 336 | } |
| 337 | XFreeFont (display, font); | ||
| 464 | } | 338 | } |
| 465 | 339 | ||
| 466 | if (font) | ||
| 467 | XFreeFont (display, font); | ||
| 468 | if (result == 0 | 340 | if (result == 0 |
| 469 | /* Avoid auto-scaled fonts. */ | 341 | /* Avoid auto-scaled fonts. */ |
| 470 | && (XINT (AREF (entity, FONT_DPI_INDEX)) == 0 | 342 | && (XINT (AREF (entity, FONT_DPI_INDEX)) == 0 |
| @@ -487,7 +359,7 @@ xfont_list (frame, spec) | |||
| 487 | { | 359 | { |
| 488 | FRAME_PTR f = XFRAME (frame); | 360 | FRAME_PTR f = XFRAME (frame); |
| 489 | Display *display = FRAME_X_DISPLAY_INFO (f)->display; | 361 | Display *display = FRAME_X_DISPLAY_INFO (f)->display; |
| 490 | Lisp_Object registry, list, val, extra, chars; | 362 | Lisp_Object registry, list, val, extra; |
| 491 | int len; | 363 | int len; |
| 492 | /* Large enough to contain the longest XLFD (255 bytes) in UTF-8. */ | 364 | /* Large enough to contain the longest XLFD (255 bytes) in UTF-8. */ |
| 493 | char name[512]; | 365 | char name[512]; |
| @@ -498,32 +370,20 @@ xfont_list (frame, spec) | |||
| 498 | val = assq_no_quit (QCotf, extra); | 370 | val = assq_no_quit (QCotf, extra); |
| 499 | if (! NILP (val)) | 371 | if (! NILP (val)) |
| 500 | return Qnil; | 372 | return Qnil; |
| 373 | val = assq_no_quit (QCscript, extra); | ||
| 374 | if (! NILP (val)) | ||
| 375 | return Qnil; | ||
| 501 | val = assq_no_quit (QClang, extra); | 376 | val = assq_no_quit (QClang, extra); |
| 502 | if (! NILP (val)) | 377 | if (! NILP (val)) |
| 503 | return Qnil; | 378 | return Qnil; |
| 504 | } | 379 | } |
| 380 | |||
| 505 | registry = AREF (spec, FONT_REGISTRY_INDEX); | 381 | registry = AREF (spec, FONT_REGISTRY_INDEX); |
| 506 | len = font_unparse_xlfd (spec, 0, name, 512); | 382 | len = font_unparse_xlfd (spec, 0, name, 512); |
| 507 | if (len < 0 || (len = xfont_encode_coding_xlfd (name)) < 0) | 383 | if (len < 0 || (len = xfont_encode_coding_xlfd (name)) < 0) |
| 508 | return Qnil; | 384 | return Qnil; |
| 509 | val = assq_no_quit (QCscript, extra); | ||
| 510 | if (NILP (val)) | ||
| 511 | chars = Qnil; | ||
| 512 | else | ||
| 513 | { | ||
| 514 | chars = assq_no_quit (XCDR (val), Vscript_representative_chars); | ||
| 515 | if (! NILP (chars) && ! NILP (registry)) | ||
| 516 | { | ||
| 517 | chars = xfont_check_registry_char_support (registry, XCDR (chars)); | ||
| 518 | if (NILP (chars)) | ||
| 519 | return Qnil; | ||
| 520 | if (EQ (chars, Qt)) | ||
| 521 | chars = Qnil; | ||
| 522 | } | ||
| 523 | } | ||
| 524 | |||
| 525 | ASET (spec, FONT_REGISTRY_INDEX, registry); | 385 | ASET (spec, FONT_REGISTRY_INDEX, registry); |
| 526 | list = xfont_list_pattern (display, name, chars); | 386 | list = xfont_list_pattern (frame, display, name); |
| 527 | if (NILP (list) && NILP (registry)) | 387 | if (NILP (list) && NILP (registry)) |
| 528 | { | 388 | { |
| 529 | /* Try iso10646-1 */ | 389 | /* Try iso10646-1 */ |
| @@ -532,7 +392,7 @@ xfont_list (frame, spec) | |||
| 532 | if (r - name + 10 < 256) /* 10 == strlen (iso10646-1) */ | 392 | if (r - name + 10 < 256) /* 10 == strlen (iso10646-1) */ |
| 533 | { | 393 | { |
| 534 | strcpy (r, "iso10646-1"); | 394 | strcpy (r, "iso10646-1"); |
| 535 | list = xfont_list_pattern (display, name, chars); | 395 | list = xfont_list_pattern (frame, display, name); |
| 536 | } | 396 | } |
| 537 | } | 397 | } |
| 538 | if (NILP (list) && ! NILP (registry)) | 398 | if (NILP (list) && ! NILP (registry)) |
| @@ -552,7 +412,7 @@ xfont_list (frame, spec) | |||
| 552 | && ((r - name) + SBYTES (XCAR (alter))) < 256) | 412 | && ((r - name) + SBYTES (XCAR (alter))) < 256) |
| 553 | { | 413 | { |
| 554 | strcpy (r, (char *) SDATA (XCAR (alter))); | 414 | strcpy (r, (char *) SDATA (XCAR (alter))); |
| 555 | list = xfont_list_pattern (display, name, chars); | 415 | list = xfont_list_pattern (frame, display, name); |
| 556 | if (! NILP (list)) | 416 | if (! NILP (list)) |
| 557 | break; | 417 | break; |
| 558 | } | 418 | } |
| @@ -567,9 +427,10 @@ xfont_list (frame, spec) | |||
| 567 | bcopy (SDATA (XCDR (val)), name, SBYTES (XCDR (val)) + 1); | 427 | bcopy (SDATA (XCDR (val)), name, SBYTES (XCDR (val)) + 1); |
| 568 | if (xfont_encode_coding_xlfd (name) < 0) | 428 | if (xfont_encode_coding_xlfd (name) < 0) |
| 569 | return Qnil; | 429 | return Qnil; |
| 570 | list = xfont_list_pattern (display, name, chars); | 430 | list = xfont_list_pattern (frame, display, name); |
| 571 | } | 431 | } |
| 572 | } | 432 | } |
| 433 | |||
| 573 | return list; | 434 | return list; |
| 574 | } | 435 | } |
| 575 | 436 | ||
| @@ -708,6 +569,7 @@ xfont_open (f, entity, pixel_size) | |||
| 708 | Lisp_Object font_object, fullname; | 569 | Lisp_Object font_object, fullname; |
| 709 | struct font *font; | 570 | struct font *font; |
| 710 | XFontStruct *xfont; | 571 | XFontStruct *xfont; |
| 572 | int i; | ||
| 711 | 573 | ||
| 712 | /* At first, check if we know how to encode characters for this | 574 | /* At first, check if we know how to encode characters for this |
| 713 | font. */ | 575 | font. */ |