/* Composite sequence support.
- Copyright (C) 2001-2013 Free Software Foundation, Inc.
+ Copyright (C) 2001-2016 Free Software Foundation, Inc.
Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
National Institute of Advanced Industrial Science and Technology (AIST)
Registration Number H14PRO021
GNU Emacs is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
+the Free Software Foundation, either version 3 of the License, or (at
+your option) any later version.
GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
#include <config.h>
-#define COMPOSITE_INLINE EXTERN_INLINE
-
#include "lisp.h"
#include "character.h"
+#include "composite.h"
#include "buffer.h"
#include "coding.h"
#include "intervals.h"
-#include "window.h"
#include "frame.h"
#include "dispextern.h"
-#include "font.h"
#include "termhooks.h"
*/
-Lisp_Object Qcomposition;
-
/* Table of pointers to the structure `composition' indexed by
COMPOSITION-ID. This structure is for storing information about
each composition except for COMPONENTS-VEC. */
COMPOSITION-ID. */
Lisp_Object composition_hash_table;
-static Lisp_Object Qauto_composed;
-static Lisp_Object Qauto_composition_function;
/* Maximum number of characters to look back for
auto-compositions. */
#define MAX_AUTO_COMPOSITION_LOOKBACK 3
-/* Temporary variable used in macros COMPOSITION_XXX. */
-Lisp_Object composition_temp;
-
-\f
/* Return COMPOSITION-ID of a composition at buffer position
CHARPOS/BYTEPOS and length NCHARS. The `composition' property of
the sequence is PROP. STRING, if non-nil, is a string that
valid too. */
if (from > BEGV
&& find_composition (from - 1, -1, &start, &end, &prop, Qnil)
- && !COMPOSITION_VALID_P (start, end, prop))
+ && !composition_valid_p (start, end, prop))
from = start;
if (to < ZV
&& find_composition (to, -1, &start, &end, &prop, Qnil)
- && !COMPOSITION_VALID_P (start, end, prop))
+ && !composition_valid_p (start, end, prop))
to = end;
if (!NILP (Ffboundp (func)))
call2 (func, make_number (from), make_number (to));
latter to the copy of it. */
if (from > BEGV
&& find_composition (from - 1, -1, &start, &end, &prop, Qnil)
- && COMPOSITION_VALID_P (start, end, prop))
+ && composition_valid_p (start, end, prop))
{
min_pos = start;
if (end > to)
}
else if (from < ZV
&& find_composition (from, -1, &start, &from, &prop, Qnil)
- && COMPOSITION_VALID_P (start, from, prop))
+ && composition_valid_p (start, from, prop))
{
if (from > to)
max_pos = from;
(to - 1). */
while (from < to - 1
&& find_composition (from, to, &start, &from, &prop, Qnil)
- && COMPOSITION_VALID_P (start, from, prop)
+ && composition_valid_p (start, from, prop)
&& from < to - 1)
run_composition_function (start, from, prop);
}
{
if (from < to
&& find_composition (to - 1, -1, &start, &end, &prop, Qnil)
- && COMPOSITION_VALID_P (start, end, prop))
+ && composition_valid_p (start, end, prop))
{
/* TO should be also at composition boundary. But,
insertion or deletion will make two compositions adjacent
}
else if (to < ZV
&& find_composition (to, -1, &start, &end, &prop, Qnil)
- && COMPOSITION_VALID_P (start, end, prop))
+ && composition_valid_p (start, end, prop))
{
run_composition_function (start, end, prop);
max_pos = end;
specbind (Qinhibit_point_motion_hooks, Qt);
Fremove_list_of_text_properties (make_number (min_pos),
make_number (max_pos),
- Fcons (Qauto_composed, Qnil), Qnil);
+ list1 (Qauto_composed), Qnil);
unbind_to (count, Qnil);
}
}
len = j;
}
- lint_assume (len <= TYPE_MAXIMUM (ptrdiff_t) - 2);
copy = Fmake_vector (make_number (len + 2), Qnil);
LGSTRING_SET_HEADER (copy, Fcopy_sequence (header));
for (i = 0; i < len; i++)
if (FONT_OBJECT_P (font_object))
{
struct font *font = XFONT_OBJECT (font_object);
+ int font_ascent, font_descent;
- metrics->ascent = font->ascent;
- metrics->descent = font->descent;
+ get_font_ascent_descent (font, &font_ascent, &font_descent);
+ metrics->ascent = font_ascent;
+ metrics->descent = font_descent;
}
else
{
static Lisp_Object gstring_work_headers;
static Lisp_Object
-fill_gstring_header (Lisp_Object header, Lisp_Object start, Lisp_Object end,
- Lisp_Object font_object, Lisp_Object string)
+fill_gstring_header (Lisp_Object header, ptrdiff_t from, ptrdiff_t from_byte,
+ ptrdiff_t to, Lisp_Object font_object, Lisp_Object string)
{
- ptrdiff_t from, to, from_byte;
- ptrdiff_t len, i;
-
- if (NILP (string))
- {
- if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
- error ("Attempt to shape unibyte text");
- validate_region (&start, &end);
- from = XFASTINT (start);
- to = XFASTINT (end);
- from_byte = CHAR_TO_BYTE (from);
- }
- else
- {
- CHECK_STRING (string);
- if (! STRING_MULTIBYTE (string))
- error ("Attempt to shape unibyte text");
- /* The caller checks that START and END are nonnegative integers. */
- if (! (XINT (start) <= XINT (end) && XINT (end) <= SCHARS (string)))
- args_out_of_range_3 (string, start, end);
- from = XINT (start);
- to = XINT (end);
- from_byte = string_char_to_byte (string, from);
- }
+ ptrdiff_t len = to - from, i;
- len = to - from;
if (len == 0)
error ("Attempt to shape zero-length text");
if (VECTORP (header))
Lisp_Object string)
{
ptrdiff_t count = SPECPDL_INDEX ();
- FRAME_PTR f = XFRAME (win->frame);
+ struct frame *f = XFRAME (win->frame);
Lisp_Object pos = make_number (charpos);
ptrdiff_t to;
ptrdiff_t pt = PT, pt_byte = PT_BYTE;
return unbind_to (count, lgstring);
}
-static Lisp_Object _work_val;
-
/* 1 iff the character C is composable. Characters of general
category Z? or C? are not composable except for ZWNJ and ZWJ. */
-#define CHAR_COMPOSABLE_P(C) \
- ((C) > ' ' \
- && ((C) == 0x200C || (C) == 0x200D \
- || (_work_val = CHAR_TABLE_REF (Vunicode_category_table, (C)), \
- (INTEGERP (_work_val) \
- && (XINT (_work_val) <= UNICODE_CATEGORY_So)))))
+static bool
+char_composable_p (int c)
+{
+ Lisp_Object val;
+ return (c > ' '
+ && (c == ZERO_WIDTH_NON_JOINER || c == ZERO_WIDTH_JOINER
+ || (val = CHAR_TABLE_REF (Vunicode_category_table, c),
+ (INTEGERP (val) && (XINT (val) <= UNICODE_CATEGORY_So)))));
+}
/* Update cmp_it->stop_pos to the next position after CHARPOS (and
BYTEPOS) where character composition may happen. If BYTEPOS is
if (charpos < endpos
&& find_composition (charpos, endpos, &start, &end, &prop, string)
&& start >= charpos
- && COMPOSITION_VALID_P (start, end, prop))
+ && composition_valid_p (start, end, prop))
{
cmp_it->stop_pos = endpos = start;
cmp_it->ch = -1;
val = CHAR_TABLE_REF (Vcomposition_function_table, c);
if (! NILP (val))
{
- Lisp_Object elt;
- int ridx;
-
- for (ridx = 0; CONSP (val); val = XCDR (val), ridx++)
+ for (int ridx = 0; CONSP (val); val = XCDR (val), ridx++)
{
- elt = XCAR (val);
+ Lisp_Object elt = XCAR (val);
if (VECTORP (elt) && ASIZE (elt) == 3
&& NATNUMP (AREF (elt, 1))
&& charpos - 1 - XFASTINT (AREF (elt, 1)) >= start)
- break;
- }
- if (CONSP (val))
- {
- cmp_it->rule_idx = ridx;
- cmp_it->lookback = XFASTINT (AREF (elt, 1));
- cmp_it->stop_pos = charpos - 1 - cmp_it->lookback;
- cmp_it->ch = c;
- return;
+ {
+ cmp_it->rule_idx = ridx;
+ cmp_it->lookback = XFASTINT (AREF (elt, 1));
+ cmp_it->stop_pos = charpos - 1 - cmp_it->lookback;
+ cmp_it->ch = c;
+ return;
+ }
}
}
}
- if (charpos == endpos)
+ if (charpos == endpos
+ && !(STRINGP (string) && endpos == SCHARS (string)))
{
/* We couldn't find a composition point before ENDPOS. But,
some character after ENDPOS may be composed with
p = SDATA (string) + bytepos;
c = STRING_CHAR_AND_LENGTH (p, len);
limit = bytepos + len;
- while (CHAR_COMPOSABLE_P (c))
+ while (char_composable_p (c))
{
val = CHAR_TABLE_REF (Vcomposition_function_table, c);
if (! NILP (val))
/* Skip all uncomposable characters. */
if (NILP (string))
{
- while (charpos - 1 > endpos && ! CHAR_COMPOSABLE_P (c))
+ while (charpos - 1 > endpos && ! char_composable_p (c))
{
DEC_BOTH (charpos, bytepos);
c = FETCH_MULTIBYTE_CHAR (bytepos);
}
else
{
- while (charpos - 1 > endpos && ! CHAR_COMPOSABLE_P (c))
+ while (charpos - 1 > endpos && ! char_composable_p (c))
{
p--;
while (! CHAR_HEAD_P (*p))
/* Check if the character at CHARPOS (and BYTEPOS) is composed
(possibly with the following characters) on window W. ENDPOS limits
- characters to be composed. FACE, in non-NULL, is a base face of
+ characters to be composed. FACE, if non-NULL, is a base face of
the character. If STRING is not nil, it is a string containing the
character to check, and CHARPOS and BYTEPOS are indices in the
string. In that case, FACE must not be NULL.
cmp_it->width = 0;
for (i = cmp_it->nchars - 1; i >= 0; i--)
{
- c = XINT (LGSTRING_CHAR (gstring, i));
+ c = XINT (LGSTRING_CHAR (gstring, from + i));
cmp_it->nbytes += CHAR_BYTES (c);
cmp_it->width += CHAR_WIDTH (c);
}
|-B-|-C-|--D--|
Here, it is known that characters after positions 1 and 9 can
- never be composed (i.e. ! CHAR_COMPOSABLE_P (CH)), and
+ never be composed (i.e. ! char_composable_p (CH)), and
composition A is an invalid one because it's partially covered by
the valid composition C. And to know whether a composition is
valid or not, the only way is to start searching forward from a
while (1)
{
c = STRING_CHAR (cur.p);
- if (! CHAR_COMPOSABLE_P (c))
+ if (! char_composable_p (c))
{
if (limit <= pos) /* case (1) */
{
return 0;
BACKWARD_CHAR (cur, stop);
c = STRING_CHAR (cur.p);
- } while (! CHAR_COMPOSABLE_P (c));
+ } while (! char_composable_p (c));
fore_check_limit = cur.pos + 1;
}
else /* case (2) */
prev = cur;
BACKWARD_CHAR (cur, stop);
c = STRING_CHAR (cur.p);
- if (! CHAR_COMPOSABLE_P (c))
+ if (! char_composable_p (c))
{
cur = prev;
break;
/* At first check the static composition. */
if (get_property_and_range (new_pt, Qcomposition, &val, &beg, &end, Qnil)
- && COMPOSITION_VALID_P (beg, end, val))
+ && composition_valid_p (beg, end, val))
{
if (beg < new_pt /* && end > new_pt <- It's always the case. */
&& (last_pt <= beg || last_pt >= end))
frame, or nil for the selected frame's terminal device.
If the optional 4th argument STRING is not nil, it is a string
-containing the target characters between indices FROM and TO.
+containing the target characters between indices FROM and TO,
+which are treated as in `substring'. Otherwise FROM and TO are
+character positions in current buffer; they can be in either order,
+and can be integers or markers.
A glyph-string is a vector containing information about how to display
a specific character sequence. The format is:
(Lisp_Object from, Lisp_Object to, Lisp_Object font_object, Lisp_Object string)
{
Lisp_Object gstring, header;
- ptrdiff_t frompos, topos;
+ ptrdiff_t frompos, frombyte, topos;
- CHECK_NATNUM (from);
- CHECK_NATNUM (to);
if (! FONT_OBJECT_P (font_object))
{
struct coding_system *coding;
- struct terminal *terminal = get_terminal (font_object, 1);
+ struct terminal *terminal = decode_live_terminal (font_object);
coding = ((TERMINAL_TERMINAL_CODING (terminal)->common_flags
& CODING_REQUIRE_ENCODING_MASK)
font_object = CODING_ID_NAME (coding->id);
}
- header = fill_gstring_header (Qnil, from, to, font_object, string);
+ if (NILP (string))
+ {
+ if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
+ error ("Attempt to shape unibyte text");
+ validate_region (&from, &to);
+ frompos = XFASTINT (from);
+ topos = XFASTINT (to);
+ frombyte = CHAR_TO_BYTE (frompos);
+ }
+ else
+ {
+ CHECK_STRING (string);
+ validate_subarray (string, from, to, SCHARS (string), &frompos, &topos);
+ if (! STRING_MULTIBYTE (string))
+ error ("Attempt to shape unibyte text");
+ frombyte = string_char_to_byte (string, frompos);
+ }
+
+ header = fill_gstring_header (Qnil, frompos, frombyte,
+ topos, font_object, string);
gstring = gstring_lookup_cache (header);
if (! NILP (gstring))
return gstring;
- frompos = XINT (from);
- topos = XINT (to);
if (LGSTRING_GLYPH_LEN (gstring_work) < topos - frompos)
gstring_work = Fmake_vector (make_number (topos - frompos + 2), Qnil);
LGSTRING_SET_HEADER (gstring_work, header);
Scompose_string_internal, 3, 5, 0,
doc: /* Internal use only.
-Compose text between indices START and END of STRING.
-Optional 4th and 5th arguments are COMPONENTS and MODIFICATION-FUNC
+Compose text between indices START and END of STRING, where
+START and END are treated as in `substring'. Optional 4th
+and 5th arguments are COMPONENTS and MODIFICATION-FUNC
for the composition. See `compose-string' for more details. */)
- (Lisp_Object string, Lisp_Object start, Lisp_Object end, Lisp_Object components, Lisp_Object modification_func)
+ (Lisp_Object string, Lisp_Object start, Lisp_Object end,
+ Lisp_Object components, Lisp_Object modification_func)
{
- CHECK_STRING (string);
- CHECK_NUMBER (start);
- CHECK_NUMBER (end);
+ ptrdiff_t from, to;
- if (XINT (start) < 0 ||
- XINT (start) > XINT (end)
- || XINT (end) > SCHARS (string))
- args_out_of_range (start, end);
-
- compose_text (XINT (start), XINT (end), components, modification_func, string);
+ CHECK_STRING (string);
+ validate_subarray (string, start, end, SCHARS (string), &from, &to);
+ compose_text (from, to, components, modification_func, string);
return string;
}
&& (e <= XINT (pos) ? e > end : s < start))
return list3 (make_number (s), make_number (e), gstring);
}
- if (!COMPOSITION_VALID_P (start, end, prop))
- return Fcons (make_number (start), Fcons (make_number (end),
- Fcons (Qnil, Qnil)));
+ if (!composition_valid_p (start, end, prop))
+ return list3 (make_number (start), make_number (end), Qnil);
if (NILP (detail_p))
- return Fcons (make_number (start), Fcons (make_number (end),
- Fcons (Qt, Qnil)));
+ return list3 (make_number (start), make_number (end), Qt);
- if (COMPOSITION_REGISTERD_P (prop))
+ if (composition_registered_p (prop))
id = COMPOSITION_ID (prop);
else
{
if (id >= 0)
{
Lisp_Object components, relative_p, mod_func;
- enum composition_method method = COMPOSITION_METHOD (prop);
+ enum composition_method method = composition_method (prop);
int width = composition_table[id]->width;
components = Fcopy_sequence (COMPOSITION_COMPONENTS (prop));
relative_p = (method == COMPOSITION_WITH_RULE_ALTCHARS
? Qnil : Qt);
mod_func = COMPOSITION_MODIFICATION_FUNC (prop);
- tail = Fcons (components,
- Fcons (relative_p,
- Fcons (mod_func,
- Fcons (make_number (width), Qnil))));
+ tail = list4 (components, relative_p, mod_func, make_number (width));
}
else
tail = Qnil;
DEFSYM (Qcomposition, "composition");
/* Make a hash table for static composition. */
- {
- Lisp_Object args[6];
-
- args[0] = QCtest;
- args[1] = Qequal;
- args[2] = QCweakness;
- /* We used to make the hash table weak so that unreferenced
- compositions can be garbage-collected. But, usually once
- created compositions are repeatedly used in an Emacs session,
- and thus it's not worth to save memory in such a way. So, we
- make the table not weak. */
- args[3] = Qnil;
- args[4] = QCsize;
- args[5] = make_number (311);
- composition_hash_table = Fmake_hash_table (6, args);
- staticpro (&composition_hash_table);
- }
+ /* We used to make the hash table weak so that unreferenced
+ compositions can be garbage-collected. But, usually once
+ created compositions are repeatedly used in an Emacs session,
+ and thus it's not worth to save memory in such a way. So, we
+ make the table not weak. */
+ Lisp_Object args[] = {QCtest, Qequal, QCsize, make_number (311)};
+ composition_hash_table = CALLMANY (Fmake_hash_table, args);
+ staticpro (&composition_hash_table);
/* Make a hash table for glyph-string. */
- {
- Lisp_Object args[6];
- args[0] = QCtest;
- args[1] = Qequal;
- args[2] = QCweakness;
- args[3] = Qnil;
- args[4] = QCsize;
- args[5] = make_number (311);
- gstring_hash_table = Fmake_hash_table (6, args);
- staticpro (&gstring_hash_table);
- }
+ gstring_hash_table = CALLMANY (Fmake_hash_table, args);
+ staticpro (&gstring_hash_table);
staticpro (&gstring_work_headers);
gstring_work_headers = make_uninit_vector (8);
Vcompose_chars_after_function = intern_c_string ("compose-chars-after");
DEFSYM (Qauto_composed, "auto-composed");
- DEFSYM (Qauto_composition_function, "auto-composition-function");
DEFVAR_LISP ("auto-composition-mode", Vauto_composition_mode,
doc: /* Non-nil if Auto-Composition mode is enabled.