aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenichi Handa2004-02-06 11:08:43 +0000
committerKenichi Handa2004-02-06 11:08:43 +0000
commiteb36588a97f1bc1e0fe694a52332cfb522adc839 (patch)
treeba40e58cd10464a0099034bcd37d7cba86b5470e /src
parent1c305bc1f58f34d89f5d975a52cfc66b3df7715a (diff)
downloademacs-eb36588a97f1bc1e0fe694a52332cfb522adc839.tar.gz
emacs-eb36588a97f1bc1e0fe694a52332cfb522adc839.zip
(FONTSET_DEFAULT): New macro.
(FONTSET_ADD): Handle the case that range is nil. (fontset_add): Likewise. (Fset_fontset_font): Change the 2nd arg name to TARGET, and handle the case that it is nil. (dump_fontset): Call FONTSET_DEFAULT, not FONTSET_FALLBACK. (syms_of_fontset): Set char-table-extra-slots property of fontset to 9.
Diffstat (limited to 'src')
-rw-r--r--src/fontset.c172
1 files changed, 100 insertions, 72 deletions
diff --git a/src/fontset.c b/src/fontset.c
index db203450927..36c473a33b5 100644
--- a/src/fontset.c
+++ b/src/fontset.c
@@ -116,7 +116,7 @@ EXFUN (Fclear_face_cache, 1);
116 range of characters. 116 range of characters.
117 117
118 118
119 A fontset has 8 extra slots. 119 A fontset has 9 extra slots.
120 120
121 The 1st slot: the ID number of the fontset 121 The 1st slot: the ID number of the fontset
122 122
@@ -151,6 +151,10 @@ EXFUN (Fclear_face_cache, 1);
151 realized: If the base is not the default fontset, a fontset 151 realized: If the base is not the default fontset, a fontset
152 realized from the default fontset, else nil. 152 realized from the default fontset, else nil.
153 153
154 The 9th slot:
155 base: vector of fallback FONT-DEFs.
156 base: vector of fallback font vector.
157
154 All fontsets are recorded in the vector Vfontset_table. 158 All fontsets are recorded in the vector Vfontset_table.
155 159
156 160
@@ -279,7 +283,10 @@ fontset_id_valid_p (id)
279#define FONTSET_FRAME(fontset) XCHAR_TABLE (fontset)->extras[3] 283#define FONTSET_FRAME(fontset) XCHAR_TABLE (fontset)->extras[3]
280#define FONTSET_NOFONT_FACE(fontset) XCHAR_TABLE (fontset)->extras[5] 284#define FONTSET_NOFONT_FACE(fontset) XCHAR_TABLE (fontset)->extras[5]
281#define FONTSET_REPERTORY(fontset) XCHAR_TABLE (fontset)->extras[6] 285#define FONTSET_REPERTORY(fontset) XCHAR_TABLE (fontset)->extras[6]
282#define FONTSET_FALLBACK(fontset) XCHAR_TABLE (fontset)->extras[7] 286#define FONTSET_DEFAULT(fontset) XCHAR_TABLE (fontset)->extras[7]
287
288/* for both base and realized FONTSET */
289#define FONTSET_FALLBACK(fontset) XCHAR_TABLE (fontset)->extras[8]
283 290
284#define BASE_FONTSET_P(fontset) (NILP (FONTSET_BASE (fontset))) 291#define BASE_FONTSET_P(fontset) (NILP (FONTSET_BASE (fontset)))
285 292
@@ -360,42 +367,45 @@ fontset_ref_and_range (fontset, c, from, to)
360 replace with ELT, if ADD is `prepend', prepend ELT, otherwise, 367 replace with ELT, if ADD is `prepend', prepend ELT, otherwise,
361 append ELT. */ 368 append ELT. */
362 369
363#define FONTSET_ADD(fontset, range, elt, add) \ 370#define FONTSET_ADD(fontset, range, elt, add) \
364 (NILP (add) \ 371 (NILP (add) \
365 ? Fset_char_table_range ((fontset), (range), \ 372 ? (NILP (range) \
366 Fmake_vector (make_number (1), (elt))) \ 373 ? FONTSET_FALLBACK (fontset) = Fmake_vector (make_number (1), (elt)) \
374 : Fset_char_table_range ((fontset), (range), \
375 Fmake_vector (make_number (1), (elt)))) \
367 : fontset_add ((fontset), (range), (elt), (add))) 376 : fontset_add ((fontset), (range), (elt), (add)))
368 377
369static Lisp_Object 378static Lisp_Object
370fontset_add (fontset, range, elt, add) 379fontset_add (fontset, range, elt, add)
371 Lisp_Object fontset, range, elt, add; 380 Lisp_Object fontset, range, elt, add;
372{ 381{
373 int from, to, from1, to1; 382 Lisp_Object args[2];
374 Lisp_Object elt1; 383 int idx = (EQ (add, Qappend) ? 0 : 1);
375 384
376 from = XINT (XCAR (range)); 385 args[1 - idx] = Fmake_vector (make_number (1), elt);
377 to = XINT (XCDR (range)); 386
378 do { 387 if (CONSP (range))
379 elt1 = char_table_ref_and_range (fontset, from, &from1, &to1); 388 {
380 if (to < to1) 389 int from = XINT (XCAR (range));
381 to1 = to; 390 int to = XINT (XCDR (range));
382 if (NILP (elt1)) 391 int from1, to1;
383 elt1 = Fmake_vector (make_number (1), elt); 392
384 else 393 do {
385 { 394 args[idx] = char_table_ref_and_range (fontset, from, &from1, &to1);
386 int i, i0 = 1, i1 = ASIZE (elt1) + 1; 395 if (to < to1)
387 Lisp_Object new; 396 to1 = to;
388 397 char_table_set_range (fontset, from, to1,
389 new = Fmake_vector (make_number (i1), elt); 398 NILP (args[idx]) ? args[1 - idx]
390 if (EQ (add, Qappend)) 399 : Fvconcat (2, args));
391 i0--, i1--; 400 from = to1 + 1;
392 for (i = 0; i0 < i1; i++, i0++) 401 } while (from < to);
393 ASET (new, i0, AREF (elt1, i)); 402 }
394 elt1 = new; 403 else
395 } 404 {
396 char_table_set_range (fontset, from, to1, elt1); 405 args[idx] = FONTSET_FALLBACK (fontset);
397 from = to1 + 1; 406 FONTSET_FALLBACK (fontset)
398 } while (from < to); 407 = NILP (args[idx]) ? args[1 - idx] : Fvconcat (2, args);
408 }
399 return Qnil; 409 return Qnil;
400} 410}
401 411
@@ -524,12 +534,21 @@ fontset_face (fontset, c, face, id)
524 return -1; 534 return -1;
525 elt = FONTSET_REF_AND_RANGE (base_fontset, c, from, to); 535 elt = FONTSET_REF_AND_RANGE (base_fontset, c, from, to);
526 range = Fcons (make_number (from), make_number (to)); 536 range = Fcons (make_number (from), make_number (to));
537 vec = Qnil;
527 if (NILP (elt)) 538 if (NILP (elt))
528 { 539 {
529 /* Record that we have no font for characters of this 540 vec = FONTSET_FALLBACK (fontset);
530 range. */ 541 if (! NILP (vec))
531 FONTSET_SET (fontset, range, Qt); 542 goto font_vector_ready;
532 goto try_default; 543 elt = FONTSET_FALLBACK (base_fontset);
544 if (NILP (elt))
545 {
546 /* Record that we have no font for characters of this
547 range. */
548 FONTSET_SET (fontset, range, Qt);
549 goto try_default;
550 }
551 range = Qnil;
533 } 552 }
534 /* Build a vector [ -1 -1 nil NEW-ELT0 NEW-ELT1 NEW-ELT2 ... ], 553 /* Build a vector [ -1 -1 nil NEW-ELT0 NEW-ELT1 NEW-ELT2 ... ],
535 where the first -1 is to force reordering of NEW-ELTn, 554 where the first -1 is to force reordering of NEW-ELTn,
@@ -544,13 +563,16 @@ fontset_face (fontset, c, face, id)
544 ASET (tmp, 2, AREF (elt, i)); 563 ASET (tmp, 2, AREF (elt, i));
545 ASET (vec, 3 + i, tmp); 564 ASET (vec, 3 + i, tmp);
546 } 565 }
547 /* Then store it in the fontset. -1 is to force 566 /* Then store it in the fontset. */
548 reordering of FONT-VECTOR. */ 567 if (CONSP (range))
549 FONTSET_SET (fontset, range, vec); 568 FONTSET_SET (fontset, range, vec);
569 else
570 FONTSET_FALLBACK (fontset) = vec;
550 } 571 }
551 else 572 else
552 vec = elt; 573 vec = elt;
553 574
575 font_vector_ready:
554 if (XINT (AREF (vec, 0)) != charset_ordered_list_tick) 576 if (XINT (AREF (vec, 0)) != charset_ordered_list_tick)
555 /* The priority of charsets is changed after we selected a face 577 /* The priority of charsets is changed after we selected a face
556 for C last time. */ 578 for C last time. */
@@ -660,10 +682,10 @@ fontset_face (fontset, c, face, id)
660 try_default: 682 try_default:
661 if (! EQ (base_fontset, Vdefault_fontset)) 683 if (! EQ (base_fontset, Vdefault_fontset))
662 { 684 {
663 if (NILP (FONTSET_FALLBACK (fontset))) 685 if (NILP (FONTSET_DEFAULT (fontset)))
664 FONTSET_FALLBACK (fontset) 686 FONTSET_DEFAULT (fontset)
665 = make_fontset (FONTSET_FRAME (fontset), Qnil, Vdefault_fontset); 687 = make_fontset (FONTSET_FRAME (fontset), Qnil, Vdefault_fontset);
666 return fontset_face (FONTSET_FALLBACK (fontset), c, face, id); 688 return fontset_face (FONTSET_DEFAULT (fontset), c, face, id);
667 } 689 }
668 690
669 /* We have tried all the fonts for C, but none of them can be opened 691 /* We have tried all the fonts for C, but none of them can be opened
@@ -780,9 +802,9 @@ free_face_fontset (f, face)
780 ASET (Vfontset_table, face->fontset, Qnil); 802 ASET (Vfontset_table, face->fontset, Qnil);
781 if (face->fontset < next_fontset_id) 803 if (face->fontset < next_fontset_id)
782 next_fontset_id = face->fontset; 804 next_fontset_id = face->fontset;
783 if (! NILP (FONTSET_FALLBACK (fontset))) 805 if (! NILP (FONTSET_DEFAULT (fontset)))
784 { 806 {
785 int id = FONTSET_ID (FONTSET_FALLBACK (fontset)); 807 int id = FONTSET_ID (FONTSET_DEFAULT (fontset));
786 808
787 fontset = AREF (Vfontset_table, id); 809 fontset = AREF (Vfontset_table, id);
788 xassert (!NILP (fontset) && ! BASE_FONTSET_P (fontset)); 810 xassert (!NILP (fontset) && ! BASE_FONTSET_P (fontset));
@@ -1252,18 +1274,21 @@ set_fontset_font (arg, range)
1252 1274
1253DEFUN ("set-fontset-font", Fset_fontset_font, Sset_fontset_font, 3, 5, 0, 1275DEFUN ("set-fontset-font", Fset_fontset_font, Sset_fontset_font, 3, 5, 0,
1254 doc: /* 1276 doc: /*
1255Modify fontset NAME to use FONT-SPEC for CHARACTER. 1277Modify fontset NAME to use FONT-SPEC for TARGET characters.
1256 1278
1257CHARACTER may be a cons; (FROM . TO), where FROM and TO are 1279TARGET may be a cons; (FROM . TO), where FROM and TO are characters.
1258characters. In that case, use FONT-SPEC for all characters in the 1280In that case, use FONT-SPEC for all characters in the range FROM and
1259range FROM and TO (inclusive). 1281TO (inclusive).
1260 1282
1261CHARACTER may be a script name symbol. In that case, use FONT-SPEC 1283TARGET may be a script name symbol. In that case, use FONT-SPEC for
1262for all characters that belong to the script. 1284all characters that belong to the script.
1263 1285
1264CHARACTER may be a charset. In that case, use FONT-SPEC for all 1286TARGET may be a charset. In that case, use FONT-SPEC for all
1265characters in the charset. 1287characters in the charset.
1266 1288
1289TARGET may be nil. In that case, use FONT-SPEC for any characters for
1290that no FONT-SPEC is specified.
1291
1267FONT-SPEC may be: 1292FONT-SPEC may be:
1268 * A vector [ FAMILY WEIGHT SLANT WIDTH ADSTYLE REGISTRY ]. 1293 * A vector [ FAMILY WEIGHT SLANT WIDTH ADSTYLE REGISTRY ].
1269 See the documentation of `set-face-attribute' for the detail of 1294 See the documentation of `set-face-attribute' for the detail of
@@ -1276,11 +1301,11 @@ Optional 4th argument FRAME, if non-nil, is a frame. This argument is
1276kept for backward compatibility and has no meaning. 1301kept for backward compatibility and has no meaning.
1277 1302
1278Optional 5th argument ADD, if non-nil, specifies how to add FONT-SPEC 1303Optional 5th argument ADD, if non-nil, specifies how to add FONT-SPEC
1279to the font specifications for RANGE previously set. If it is 1304to the font specifications for TARGET previously set. If it is
1280`prepend', FONT-SPEC is prepended. If it is `append', FONT-SPEC is 1305`prepend', FONT-SPEC is prepended. If it is `append', FONT-SPEC is
1281appended. By default, FONT-SPEC overrides the previous settings. */) 1306appended. By default, FONT-SPEC overrides the previous settings. */)
1282 (name, character, font_spec, frame, add) 1307 (name, target, font_spec, frame, add)
1283 Lisp_Object name, character, font_spec, frame, add; 1308 Lisp_Object name, target, font_spec, frame, add;
1284{ 1309{
1285 Lisp_Object fontset; 1310 Lisp_Object fontset;
1286 Lisp_Object font_def, registry; 1311 Lisp_Object font_def, registry;
@@ -1354,39 +1379,38 @@ appended. By default, FONT-SPEC overrides the previous settings. */)
1354 ASET (font_def, 1, encoding); 1379 ASET (font_def, 1, encoding);
1355 ASET (font_def, 2, repertory); 1380 ASET (font_def, 2, repertory);
1356 1381
1357 if (CHARACTERP (character)) 1382 if (CHARACTERP (target))
1358 range_list = Fcons (Fcons (character, character), Qnil); 1383 range_list = Fcons (Fcons (target, target), Qnil);
1359 else if (CONSP (character)) 1384 else if (CONSP (target))
1360 { 1385 {
1361 Lisp_Object from, to; 1386 Lisp_Object from, to;
1362 1387
1363 from = Fcar (character); 1388 from = Fcar (target);
1364 to = Fcdr (character); 1389 to = Fcdr (target);
1365 CHECK_CHARACTER (from); 1390 CHECK_CHARACTER (from);
1366 CHECK_CHARACTER (to); 1391 CHECK_CHARACTER (to);
1367 range_list = Fcons (character, Qnil); 1392 range_list = Fcons (target, Qnil);
1368 } 1393 }
1369 else 1394 else if (SYMBOLP (target) && !NILP (target))
1370 { 1395 {
1371 Lisp_Object script_list; 1396 Lisp_Object script_list;
1372 Lisp_Object val; 1397 Lisp_Object val;
1373 1398
1374 CHECK_SYMBOL (character);
1375 range_list = Qnil; 1399 range_list = Qnil;
1376 script_list = XCHAR_TABLE (Vchar_script_table)->extras[0]; 1400 script_list = XCHAR_TABLE (Vchar_script_table)->extras[0];
1377 if (! NILP (Fmemq (character, script_list))) 1401 if (! NILP (Fmemq (target, script_list)))
1378 { 1402 {
1379 val = Fcons (character, Qnil); 1403 val = Fcons (target, Qnil);
1380 map_char_table (accumulate_script_ranges, Qnil, Vchar_script_table, 1404 map_char_table (accumulate_script_ranges, Qnil, Vchar_script_table,
1381 val); 1405 val);
1382 range_list = XCDR (val); 1406 range_list = XCDR (val);
1383 } 1407 }
1384 else if (CHARSETP (character)) 1408 else if (CHARSETP (target))
1385 { 1409 {
1386 struct charset *charset; 1410 struct charset *charset;
1387 1411
1388 CHECK_CHARSET_GET_CHARSET (character, charset); 1412 CHECK_CHARSET_GET_CHARSET (target, charset);
1389 if (EQ (character, Qascii)) 1413 if (EQ (target, Qascii))
1390 { 1414 {
1391 if (VECTORP (font_spec)) 1415 if (VECTORP (font_spec))
1392 font_spec = generate_ascii_font_name (FONTSET_NAME (fontset), 1416 font_spec = generate_ascii_font_name (FONTSET_NAME (fontset),
@@ -1407,8 +1431,12 @@ appended. By default, FONT-SPEC overrides the previous settings. */)
1407 1431
1408 if (NILP (range_list)) 1432 if (NILP (range_list))
1409 error ("Invalid script or charset name: %s", 1433 error ("Invalid script or charset name: %s",
1410 SDATA (SYMBOL_NAME (character))); 1434 SDATA (SYMBOL_NAME (target)));
1411 } 1435 }
1436 else if (NILP (target))
1437 range_list = Fcons (Qnil, Qnil);
1438 else
1439 error ("Invalid target for setting a font");
1412 1440
1413 for (; CONSP (range_list); range_list = XCDR (range_list)) 1441 for (; CONSP (range_list); range_list = XCDR (range_list))
1414 FONTSET_ADD (fontset, XCAR (range_list), font_def, add); 1442 FONTSET_ADD (fontset, XCAR (range_list), font_def, add);
@@ -1702,7 +1730,7 @@ fontset. The format is the same as abobe. */)
1702 this_table = XCHAR_TABLE (table)->extras[0]; 1730 this_table = XCHAR_TABLE (table)->extras[0];
1703#if 0 1731#if 0
1704 for (i = 0; i < n_realized; i++) 1732 for (i = 0; i < n_realized; i++)
1705 realized[i] = FONTSET_FALLBACK (realized[i]); 1733 realized[i] = FONTSET_DEFAULT (realized[i]);
1706#endif 1734#endif
1707 } 1735 }
1708 for (c = 0; c <= MAX_5_BYTE_CHAR; ) 1736 for (c = 0; c <= MAX_5_BYTE_CHAR; )
@@ -1827,8 +1855,8 @@ dump_fontset (fontset)
1827 else 1855 else
1828 ASET (vec, 1, Qt); 1856 ASET (vec, 1, Qt);
1829 } 1857 }
1830 if (!NILP (FONTSET_FALLBACK (fontset))) 1858 if (!NILP (FONTSET_DEFAULT (fontset)))
1831 ASET (vec, 2, FONTSET_ID (FONTSET_FALLBACK (fontset))); 1859 ASET (vec, 2, FONTSET_ID (FONTSET_DEFAULT (fontset)));
1832 } 1860 }
1833 return vec; 1861 return vec;
1834} 1862}
@@ -1855,7 +1883,7 @@ syms_of_fontset ()
1855 abort (); 1883 abort ();
1856 1884
1857 DEFSYM (Qfontset, "fontset"); 1885 DEFSYM (Qfontset, "fontset");
1858 Fput (Qfontset, Qchar_table_extra_slots, make_number (8)); 1886 Fput (Qfontset, Qchar_table_extra_slots, make_number (9));
1859 DEFSYM (Qfontset_info, "fontset-info"); 1887 DEFSYM (Qfontset_info, "fontset-info");
1860 Fput (Qfontset_info, Qchar_table_extra_slots, make_number (1)); 1888 Fput (Qfontset_info, Qchar_table_extra_slots, make_number (1));
1861 1889