diff options
| author | Kenichi Handa | 2001-01-19 05:22:21 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2001-01-19 05:22:21 +0000 |
| commit | beeedaada9bb25dcea2695fd8a9f586d3071fda7 (patch) | |
| tree | b5e89148c3be37ed5cfe8d27cd027421aad6fdb0 /src/charset.c | |
| parent | 200ecca2d2157fd7b0f2a5a97e66ec2f4941663a (diff) | |
| download | emacs-beeedaada9bb25dcea2695fd8a9f586d3071fda7.tar.gz emacs-beeedaada9bb25dcea2695fd8a9f586d3071fda7.zip | |
(strwidth): Use c_string_width.
(c_string_width): New function.
(lisp_string_width): New arguments PRECISION, NCHARS, NBYTES.
Caller changed.
Diffstat (limited to 'src/charset.c')
| -rw-r--r-- | src/charset.c | 147 |
1 files changed, 110 insertions, 37 deletions
diff --git a/src/charset.c b/src/charset.c index 38683dc5c0f..54edddd47a6 100644 --- a/src/charset.c +++ b/src/charset.c | |||
| @@ -1233,67 +1233,140 @@ strwidth (str, len) | |||
| 1233 | unsigned char *str; | 1233 | unsigned char *str; |
| 1234 | int len; | 1234 | int len; |
| 1235 | { | 1235 | { |
| 1236 | unsigned char *endp = str + len; | 1236 | return c_string_width (str, len, -1, NULL, NULL); |
| 1237 | } | ||
| 1238 | |||
| 1239 | /* Return width of string STR of length LEN when displayed in the | ||
| 1240 | current buffer. The width is measured by how many columns it | ||
| 1241 | occupies on the screen. If PRECISION > 0, return the width of | ||
| 1242 | longest substring that doesn't exceed PRECISION, and set number of | ||
| 1243 | characters and bytes of the substring in *NCHARS and *NBYTES | ||
| 1244 | respectively. */ | ||
| 1245 | |||
| 1246 | int | ||
| 1247 | c_string_width (str, len, precision, nchars, nbytes) | ||
| 1248 | unsigned char *str; | ||
| 1249 | int precision, *nchars, *nbytes; | ||
| 1250 | { | ||
| 1251 | int i = 0, i_byte = 0; | ||
| 1237 | int width = 0; | 1252 | int width = 0; |
| 1253 | int chars; | ||
| 1238 | struct Lisp_Char_Table *dp = buffer_display_table (); | 1254 | struct Lisp_Char_Table *dp = buffer_display_table (); |
| 1239 | 1255 | ||
| 1240 | while (str < endp) | 1256 | while (i_byte < len) |
| 1241 | { | 1257 | { |
| 1242 | Lisp_Object disp; | 1258 | int bytes, thiswidth; |
| 1243 | int thislen; | 1259 | Lisp_Object val; |
| 1244 | int c = STRING_CHAR_AND_LENGTH (str, endp - str, thislen); | ||
| 1245 | 1260 | ||
| 1246 | /* Get the way the display table would display it. */ | ||
| 1247 | if (dp) | 1261 | if (dp) |
| 1248 | disp = DISP_CHAR_VECTOR (dp, c); | 1262 | { |
| 1263 | int c = STRING_CHAR_AND_LENGTH (str + i_byte, len - i_byte, bytes); | ||
| 1264 | |||
| 1265 | chars = 1; | ||
| 1266 | val = DISP_CHAR_VECTOR (dp, c); | ||
| 1267 | if (VECTORP (val)) | ||
| 1268 | thiswidth = XVECTOR (val)->size; | ||
| 1269 | else | ||
| 1270 | thiswidth = ONE_BYTE_CHAR_WIDTH (str[i_byte]); | ||
| 1271 | } | ||
| 1249 | else | 1272 | else |
| 1250 | disp = Qnil; | 1273 | { |
| 1274 | chars = 1; | ||
| 1275 | PARSE_MULTIBYTE_SEQ (str + i_byte, len - i_byte, bytes); | ||
| 1276 | thiswidth = ONE_BYTE_CHAR_WIDTH (str[i_byte]); | ||
| 1277 | } | ||
| 1251 | 1278 | ||
| 1252 | if (VECTORP (disp)) | 1279 | if (precision > 0 |
| 1253 | width += XVECTOR (disp)->size; | 1280 | && (width + thiswidth > precision)) |
| 1254 | else | 1281 | { |
| 1255 | width += ONE_BYTE_CHAR_WIDTH (*str); | 1282 | *nchars = i; |
| 1283 | *nbytes = i_byte; | ||
| 1284 | return width; | ||
| 1285 | } | ||
| 1286 | i++; | ||
| 1287 | i_byte += bytes; | ||
| 1288 | width += thiswidth; | ||
| 1289 | } | ||
| 1256 | 1290 | ||
| 1257 | str += thislen; | 1291 | if (precision > 0) |
| 1292 | { | ||
| 1293 | *nchars = i; | ||
| 1294 | *nbytes = i_byte; | ||
| 1258 | } | 1295 | } |
| 1296 | |||
| 1259 | return width; | 1297 | return width; |
| 1260 | } | 1298 | } |
| 1261 | 1299 | ||
| 1300 | /* Return width of Lisp string STRING when displayed in the current | ||
| 1301 | buffer. The width is measured by how many columns it occupies on | ||
| 1302 | the screen while paying attention to compositions. If PRECISION > | ||
| 1303 | 0, return the width of longest substring that doesn't exceed | ||
| 1304 | PRECISION, and set number of characters and bytes of the substring | ||
| 1305 | in *NCHARS and *NBYTES respectively. */ | ||
| 1306 | |||
| 1262 | int | 1307 | int |
| 1263 | lisp_string_width (str) | 1308 | lisp_string_width (string, precision, nchars, nbytes) |
| 1264 | Lisp_Object str; | 1309 | Lisp_Object string; |
| 1310 | int precision, *nchars, *nbytes; | ||
| 1265 | { | 1311 | { |
| 1266 | int len = XSTRING (str)->size, len_byte = STRING_BYTES (XSTRING (str)); | 1312 | int len = XSTRING (string)->size; |
| 1267 | int i = 0, i_byte; | 1313 | int len_byte = STRING_BYTES (XSTRING (string)); |
| 1314 | unsigned char *str = XSTRING (string)->data; | ||
| 1315 | int i = 0, i_byte = 0; | ||
| 1268 | int width = 0; | 1316 | int width = 0; |
| 1269 | int start, end, start_byte; | 1317 | struct Lisp_Char_Table *dp = buffer_display_table (); |
| 1270 | Lisp_Object prop; | ||
| 1271 | int cmp_id; | ||
| 1272 | 1318 | ||
| 1273 | while (i < len) | 1319 | while (i < len) |
| 1274 | { | 1320 | { |
| 1275 | if (find_composition (i, len, &start, &end, &prop, str)) | 1321 | int chars, bytes, thiswidth; |
| 1322 | Lisp_Object val; | ||
| 1323 | int cmp_id; | ||
| 1324 | int ignore, end; | ||
| 1325 | |||
| 1326 | if (find_composition (i, -1, &ignore, &end, &val, string) | ||
| 1327 | && ((cmp_id = get_composition_id (i, i_byte, end - i, val, string)) | ||
| 1328 | >= 0)) | ||
| 1276 | { | 1329 | { |
| 1277 | start_byte = string_char_to_byte (str, start); | 1330 | thiswidth = composition_table[cmp_id]->width; |
| 1278 | if (i < start) | 1331 | chars = end - i; |
| 1279 | { | 1332 | bytes = string_char_to_byte (string, end) - i_byte; |
| 1280 | i_byte = string_char_to_byte (str, i); | 1333 | } |
| 1281 | width += strwidth (XSTRING (str)->data + i_byte, | 1334 | else if (dp) |
| 1282 | start_byte - i_byte); | 1335 | { |
| 1283 | } | 1336 | int c = STRING_CHAR_AND_LENGTH (str + i_byte, len - i_byte, bytes); |
| 1284 | cmp_id | 1337 | |
| 1285 | = get_composition_id (start, start_byte, end - start, prop, str); | 1338 | chars = 1; |
| 1286 | if (cmp_id >= 0) | 1339 | val = DISP_CHAR_VECTOR (dp, c); |
| 1287 | width += composition_table[cmp_id]->width; | 1340 | if (VECTORP (val)) |
| 1288 | i = end; | 1341 | thiswidth = XVECTOR (val)->size; |
| 1342 | else | ||
| 1343 | thiswidth = ONE_BYTE_CHAR_WIDTH (str[i_byte]); | ||
| 1289 | } | 1344 | } |
| 1290 | else | 1345 | else |
| 1291 | { | 1346 | { |
| 1292 | i_byte = string_char_to_byte (str, i); | 1347 | chars = 1; |
| 1293 | width += strwidth (XSTRING (str)->data + i_byte, len_byte - i_byte); | 1348 | PARSE_MULTIBYTE_SEQ (str + i_byte, len_byte - i_byte, bytes); |
| 1294 | i = len; | 1349 | thiswidth = ONE_BYTE_CHAR_WIDTH (str[i_byte]); |
| 1350 | } | ||
| 1351 | |||
| 1352 | if (precision > 0 | ||
| 1353 | && (width + thiswidth > precision)) | ||
| 1354 | { | ||
| 1355 | *nchars = i; | ||
| 1356 | *nbytes = i_byte; | ||
| 1357 | return width; | ||
| 1295 | } | 1358 | } |
| 1359 | i += chars; | ||
| 1360 | i_byte += bytes; | ||
| 1361 | width += thiswidth; | ||
| 1362 | } | ||
| 1363 | |||
| 1364 | if (precision > 0) | ||
| 1365 | { | ||
| 1366 | *nchars = i; | ||
| 1367 | *nbytes = i_byte; | ||
| 1296 | } | 1368 | } |
| 1369 | |||
| 1297 | return width; | 1370 | return width; |
| 1298 | } | 1371 | } |
| 1299 | 1372 | ||
| @@ -1310,7 +1383,7 @@ taken to occupy `tab-width' columns.") | |||
| 1310 | Lisp_Object val; | 1383 | Lisp_Object val; |
| 1311 | 1384 | ||
| 1312 | CHECK_STRING (str, 0); | 1385 | CHECK_STRING (str, 0); |
| 1313 | XSETFASTINT (val, lisp_string_width (str)); | 1386 | XSETFASTINT (val, lisp_string_width (str, -1, NULL, NULL)); |
| 1314 | return val; | 1387 | return val; |
| 1315 | } | 1388 | } |
| 1316 | 1389 | ||