aboutsummaryrefslogtreecommitdiffstats
path: root/src/composite.c
diff options
context:
space:
mode:
authorKenichi Handa2009-02-12 06:06:29 +0000
committerKenichi Handa2009-02-12 06:06:29 +0000
commit895416e35604aeb0d235486835ffb7936ef9df69 (patch)
tree6906c3bdebe81cea75cb44abc3c3aec39122db6a /src/composite.c
parent8b13507ac4236e4e38f44f4cc666c63e7df854bf (diff)
downloademacs-895416e35604aeb0d235486835ffb7936ef9df69.tar.gz
emacs-895416e35604aeb0d235486835ffb7936ef9df69.zip
(MAX_AUTO_COMPOSITION_LOOKBACK): New macro.
(composition_gstring_width): Fix handling of LGLYPH_YOFF. (autocmp_chars): Use fast_looking_at. Don't compose more characters than MAX_COMPOSITION_COMPONENST. (find_automatic_composition): While looking forward and backward, check static composition. Fix where to stop looking forward. (composition_adjust_point): Fix checking of static composition. (Fcomposition_get_gstring): Pay attention to MAX_COMPOSITION_COMPONENST.
Diffstat (limited to 'src/composite.c')
-rw-r--r--src/composite.c95
1 files changed, 62 insertions, 33 deletions
diff --git a/src/composite.c b/src/composite.c
index 44fb9c43a95..252618b2a01 100644
--- a/src/composite.c
+++ b/src/composite.c
@@ -160,6 +160,10 @@ Lisp_Object Vauto_composition_function;
160Lisp_Object Qauto_composition_function; 160Lisp_Object Qauto_composition_function;
161Lisp_Object Vcomposition_function_table; 161Lisp_Object Vcomposition_function_table;
162 162
163/* Maxinum number of characters to lookback to check
164 auto-composition. */
165#define MAX_AUTO_COMPOSITION_LOOKBACK 3
166
163EXFUN (Fremove_list_of_text_properties, 4); 167EXFUN (Fremove_list_of_text_properties, 4);
164 168
165/* Temporary variable used in macros COMPOSITION_XXX. */ 169/* Temporary variable used in macros COMPOSITION_XXX. */
@@ -792,7 +796,7 @@ composition_gstring_width (gstring, from, to, metrics)
792 x = LGLYPH_ASCENT (*glyph) - LGLYPH_YOFF (*glyph); 796 x = LGLYPH_ASCENT (*glyph) - LGLYPH_YOFF (*glyph);
793 if (metrics->ascent < x) 797 if (metrics->ascent < x)
794 metrics->ascent = x; 798 metrics->ascent = x;
795 x = LGLYPH_DESCENT (*glyph) - LGLYPH_YOFF (*glyph); 799 x = LGLYPH_DESCENT (*glyph) + LGLYPH_YOFF (*glyph);
796 if (metrics->descent < x) 800 if (metrics->descent < x)
797 metrics->descent = x; 801 metrics->descent = x;
798 } 802 }
@@ -908,7 +912,6 @@ fill_gstring_body (gstring)
908 LGSTRING_SET_GLYPH (gstring, i, Qnil); 912 LGSTRING_SET_GLYPH (gstring, i, Qnil);
909} 913}
910 914
911EXFUN (Fre_search_forward, 4);
912 915
913/* Try to compose the characters at CHARPOS according to CFT_ELEMENT 916/* Try to compose the characters at CHARPOS according to CFT_ELEMENT
914 which is an element of composition-fucntion-table (which see). 917 which is an element of composition-fucntion-table (which see).
@@ -936,30 +939,40 @@ autocmp_chars (cft_element, charpos, bytepos, limit, win, face, string)
936 Lisp_Object elt = XCAR (cft_element); 939 Lisp_Object elt = XCAR (cft_element);
937 Lisp_Object re; 940 Lisp_Object re;
938 Lisp_Object font_object = Qnil, gstring; 941 Lisp_Object font_object = Qnil, gstring;
939 EMACS_INT to; 942 EMACS_INT len, to;
940 943
941 if (! VECTORP (elt) || ASIZE (elt) != 3) 944 if (! VECTORP (elt) || ASIZE (elt) != 3)
942 continue; 945 continue;
943 if (lookback < 0) 946 if (lookback < 0)
944 lookback = XFASTINT (AREF (elt, 1)); 947 {
948 lookback = XFASTINT (AREF (elt, 1));
949 if (limit > charpos + MAX_COMPOSITION_COMPONENTS)
950 limit = charpos + MAX_COMPOSITION_COMPONENTS;
951 }
945 else if (lookback != XFASTINT (AREF (elt, 1))) 952 else if (lookback != XFASTINT (AREF (elt, 1)))
946 break; 953 break;
947 re = AREF (elt, 0); 954 re = AREF (elt, 0);
948 if (NILP (string)) 955 if (NILP (re))
949 TEMP_SET_PT_BOTH (charpos, bytepos); 956 len = 1;
950 if (NILP (re) 957 else if ((len = fast_looking_at (re, charpos, bytepos, limit, -1, string))
951 || (STRINGP (re) 958 > 0)
952 && (STRINGP (string)
953 ? EQ (Fstring_match (re, string, pos), pos)
954 : (! NILP (Fre_search_forward (re, make_number (limit), Qt, Qnil))
955 && EQ (Fmatch_beginning (make_number (0)), pos)))))
956 { 959 {
957 to = (NILP (re) ? charpos + 1 : XINT (Fmatch_end (make_number (0)))); 960 if (NILP (string))
961 len = BYTE_TO_CHAR (bytepos + len) - charpos;
962 else
963 len = string_byte_to_char (string, bytepos + len) - charpos;
964 }
965 if (len > 0)
966 {
967 limit = to = charpos + len;
958#ifdef HAVE_WINDOW_SYSTEM 968#ifdef HAVE_WINDOW_SYSTEM
959 if (FRAME_WINDOW_P (f)) 969 if (FRAME_WINDOW_P (f))
960 { 970 {
961 font_object = font_range (charpos, &to, win, face, string); 971 font_object = font_range (charpos, &to, win, face, string);
962 if (! FONT_OBJECT_P (font_object)) 972 if (! FONT_OBJECT_P (font_object)
973 || (! NILP (re)
974 && to < limit
975 && (fast_looking_at (re, charpos, bytepos, to, -1, string) <= 0)))
963 { 976 {
964 if (NILP (string)) 977 if (NILP (string))
965 TEMP_SET_PT_BOTH (pt, pt_byte); 978 TEMP_SET_PT_BOTH (pt, pt_byte);
@@ -1271,6 +1284,8 @@ find_automatic_composition (pos, limit, start, end, gstring, string)
1271 Lisp_Object *gstring, string; 1284 Lisp_Object *gstring, string;
1272{ 1285{
1273 EMACS_INT head, tail, stop; 1286 EMACS_INT head, tail, stop;
1287 /* Limit to check a composition after POS. */
1288 EMACS_INT fore_check_limit;
1274 struct position_record orig, cur, check, prev; 1289 struct position_record orig, cur, check, prev;
1275 Lisp_Object check_val, val, elt; 1290 Lisp_Object check_val, val, elt;
1276 int check_lookback; 1291 int check_lookback;
@@ -1297,19 +1312,14 @@ find_automatic_composition (pos, limit, start, end, gstring, string)
1297 orig.p = SDATA (string) + orig.pos_byte; 1312 orig.p = SDATA (string) + orig.pos_byte;
1298 } 1313 }
1299 if (limit < pos) 1314 if (limit < pos)
1300 { 1315 fore_check_limit = min (tail, pos + MAX_AUTO_COMPOSITION_LOOKBACK);
1301 head = max (head, limit);
1302 tail = min (tail, pos + 3);
1303 }
1304 else 1316 else
1305 { 1317 fore_check_limit = min (tail, limit + MAX_AUTO_COMPOSITION_LOOKBACK);
1306 tail = min (tail, limit + 3);
1307 }
1308 cur = orig; 1318 cur = orig;
1309 1319
1310 retry: 1320 retry:
1311 check_val = Qnil; 1321 check_val = Qnil;
1312 /* At first, check if POS is compoable. */ 1322 /* At first, check if POS is composable. */
1313 c = STRING_CHAR (cur.p, 0); 1323 c = STRING_CHAR (cur.p, 0);
1314 if (! CHAR_COMPOSABLE_P (c)) 1324 if (! CHAR_COMPOSABLE_P (c))
1315 { 1325 {
@@ -1324,9 +1334,18 @@ find_automatic_composition (pos, limit, start, end, gstring, string)
1324 if (! NILP (val)) 1334 if (! NILP (val))
1325 check_val = val, check = cur; 1335 check_val = val, check = cur;
1326 else 1336 else
1327 while (cur.pos + 1 < tail) 1337 while (cur.pos + 1 < fore_check_limit)
1328 { 1338 {
1339 EMACS_INT b, e;
1340
1329 FORWARD_CHAR (cur, stop); 1341 FORWARD_CHAR (cur, stop);
1342 if (get_property_and_range (cur.pos, Qcomposition, &val, &b, &e,
1343 Qnil)
1344 && COMPOSITION_VALID_P (b, e, val))
1345 {
1346 fore_check_limit = cur.pos;
1347 break;
1348 }
1330 c = STRING_CHAR (cur.p, 0); 1349 c = STRING_CHAR (cur.p, 0);
1331 if (! CHAR_COMPOSABLE_P (c)) 1350 if (! CHAR_COMPOSABLE_P (c))
1332 break; 1351 break;
@@ -1342,7 +1361,12 @@ find_automatic_composition (pos, limit, start, end, gstring, string)
1342 for compositions. */ 1361 for compositions. */
1343 while (cur.pos > head) 1362 while (cur.pos > head)
1344 { 1363 {
1364 EMACS_INT b, e;
1365
1345 BACKWARD_CHAR (cur, stop); 1366 BACKWARD_CHAR (cur, stop);
1367 if (get_property_and_range (cur.pos, Qcomposition, &val, &b, &e, Qnil)
1368 && COMPOSITION_VALID_P (b, e, val))
1369 break;
1346 c = STRING_CHAR (cur.p, 0); 1370 c = STRING_CHAR (cur.p, 0);
1347 if (! CHAR_COMPOSABLE_P (c)) 1371 if (! CHAR_COMPOSABLE_P (c))
1348 break; 1372 break;
@@ -1360,7 +1384,7 @@ find_automatic_composition (pos, limit, start, end, gstring, string)
1360 cur = orig; 1384 cur = orig;
1361 else 1385 else
1362 cur = check; 1386 cur = check;
1363 while (cur.pos < tail) 1387 while (cur.pos < fore_check_limit)
1364 { 1388 {
1365 int need_adjustment = 0; 1389 int need_adjustment = 0;
1366 1390
@@ -1418,7 +1442,7 @@ find_automatic_composition (pos, limit, start, end, gstring, string)
1418 cur = prev; 1442 cur = prev;
1419 BACKWARD_CHAR (cur, stop); 1443 BACKWARD_CHAR (cur, stop);
1420 orig = cur; 1444 orig = cur;
1421 tail = orig.pos; 1445 fore_check_limit = orig.pos;
1422 goto retry; 1446 goto retry;
1423 } 1447 }
1424 return 0; 1448 return 0;
@@ -1437,10 +1461,13 @@ composition_adjust_point (last_pt)
1437 1461
1438 /* At first check the static composition. */ 1462 /* At first check the static composition. */
1439 if (get_property_and_range (PT, Qcomposition, &val, &beg, &end, Qnil) 1463 if (get_property_and_range (PT, Qcomposition, &val, &beg, &end, Qnil)
1440 && COMPOSITION_VALID_P (beg, end, val) 1464 && COMPOSITION_VALID_P (beg, end, val))
1441 && beg < PT /* && end > PT <- It's always the case. */ 1465 {
1442 && (last_pt <= beg || last_pt >= end)) 1466 if (beg < PT /* && end > PT <- It's always the case. */
1443 return (PT < last_pt ? beg : end); 1467 && (last_pt <= beg || last_pt >= end))
1468 return (PT < last_pt ? beg : end);
1469 return PT;
1470 }
1444 1471
1445 if (NILP (current_buffer->enable_multibyte_characters) 1472 if (NILP (current_buffer->enable_multibyte_characters)
1446 || ! FUNCTIONP (Vauto_composition_function)) 1473 || ! FUNCTIONP (Vauto_composition_function))
@@ -1512,6 +1539,8 @@ should be ignored. */)
1512 1539
1513 CHECK_NATNUM (from); 1540 CHECK_NATNUM (from);
1514 CHECK_NATNUM (to); 1541 CHECK_NATNUM (to);
1542 if (XINT (to) > XINT (from) + MAX_COMPOSITION_COMPONENTS)
1543 to = make_number (XINT (from) + MAX_COMPOSITION_COMPONENTS);
1515 if (! FONT_OBJECT_P (font_object)) 1544 if (! FONT_OBJECT_P (font_object))
1516 { 1545 {
1517 struct coding_system *coding; 1546 struct coding_system *coding;
@@ -1775,10 +1804,10 @@ this form: ([PATTERN PREV-CHARS FUNC] ...)
1775PATTERN is a regular expression which C and the surrounding 1804PATTERN is a regular expression which C and the surrounding
1776characters must match. 1805characters must match.
1777 1806
1778PREV-CHARS is a number of characters before C to check the 1807PREV-CHARS is a non-negative integer (less than 4) specifying how many
1779matching with PATTERN. If it is 0, PATTERN must match C and 1808characters before C to check the matching with PATTERN. If it is 0,
1780the following characters. If it is 1, PATTERN must match a 1809PATTERN must match C and the following characters. If it is 1,
1781character before C and the following characters. 1810PATTERN must match a character before C and the following characters.
1782 1811
1783If PREV-CHARS is 0, PATTERN can be nil, which means that the 1812If PREV-CHARS is 0, PATTERN can be nil, which means that the
1784single character C should be composed. 1813single character C should be composed.