aboutsummaryrefslogtreecommitdiffstats
path: root/src/xterm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/xterm.c')
-rw-r--r--src/xterm.c200
1 files changed, 155 insertions, 45 deletions
diff --git a/src/xterm.c b/src/xterm.c
index 5463ce8e192..e22e06a107e 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -68,6 +68,7 @@ Boston, MA 02111-1307, USA. */
68/* #include <sys/param.h> */ 68/* #include <sys/param.h> */
69 69
70#include "charset.h" 70#include "charset.h"
71#include "character.h"
71#include "coding.h" 72#include "coding.h"
72#include "ccl.h" 73#include "ccl.h"
73#include "frame.h" 74#include "frame.h"
@@ -765,7 +766,8 @@ XTreset_terminal_modes ()
765 766
766/* Function prototypes of this page. */ 767/* Function prototypes of this page. */
767 768
768static int x_encode_char P_ ((int, XChar2b *, struct font_info *, int *)); 769static int x_encode_char P_ ((int, XChar2b *, struct font_info *,
770 struct charset *, int *));
769 771
770 772
771/* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B 773/* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
@@ -844,13 +846,13 @@ x_per_char_metric (font, char2b, font_type)
844 the two-byte form of C. Encoding is returned in *CHAR2B. */ 846 the two-byte form of C. Encoding is returned in *CHAR2B. */
845 847
846static int 848static int
847x_encode_char (c, char2b, font_info, two_byte_p) 849x_encode_char (c, char2b, font_info, charset, two_byte_p)
848 int c; 850 int c;
849 XChar2b *char2b; 851 XChar2b *char2b;
850 struct font_info *font_info; 852 struct font_info *font_info;
853 struct charset *charset;
851 int *two_byte_p; 854 int *two_byte_p;
852{ 855{
853 int charset = CHAR_CHARSET (c);
854 XFontStruct *font = font_info->font; 856 XFontStruct *font = font_info->font;
855 857
856 /* FONT_INFO may define a scheme by which to encode byte1 and byte2. 858 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
@@ -863,31 +865,31 @@ x_encode_char (c, char2b, font_info, two_byte_p)
863 865
864 if (CHARSET_DIMENSION (charset) == 1) 866 if (CHARSET_DIMENSION (charset) == 1)
865 { 867 {
866 ccl->reg[0] = charset; 868 ccl->reg[0] = CHARSET_ID (charset);
867 ccl->reg[1] = char2b->byte2; 869 ccl->reg[1] = char2b->byte2;
868 ccl->reg[2] = -1; 870 ccl->reg[2] = -1;
869 } 871 }
870 else 872 else
871 { 873 {
872 ccl->reg[0] = charset; 874 ccl->reg[0] = CHARSET_ID (charset);
873 ccl->reg[1] = char2b->byte1; 875 ccl->reg[1] = char2b->byte1;
874 ccl->reg[2] = char2b->byte2; 876 ccl->reg[2] = char2b->byte2;
875 } 877 }
876 878
877 ccl_driver (ccl, NULL, NULL, 0, 0, NULL); 879 ccl_driver (ccl, NULL, NULL, 0, 0, Qnil);
878 880
879 /* We assume that MSBs are appropriately set/reset by CCL 881 /* We assume that MSBs are appropriately set/reset by CCL
880 program. */ 882 program. */
881 if (font->max_byte1 == 0) /* 1-byte font */ 883 if (font->max_byte1 == 0) /* 1-byte font */
882 char2b->byte1 = 0, char2b->byte2 = ccl->reg[1]; 884 STORE_XCHAR2B (char2b, 0, ccl->reg[1]);
883 else 885 else
884 char2b->byte1 = ccl->reg[1], char2b->byte2 = ccl->reg[2]; 886 STORE_XCHAR2B (char2b, ccl->reg[1], ccl->reg[2]);
885 } 887 }
886 else if (font_info->encoding[charset]) 888 else if (font_info->encoding_type)
887 { 889 {
888 /* Fixed encoding scheme. See fontset.h for the meaning of the 890 /* Fixed encoding scheme. See fontset.h for the meaning of the
889 encoding numbers. */ 891 encoding numbers. */
890 int enc = font_info->encoding[charset]; 892 unsigned char enc = font_info->encoding_type;
891 893
892 if ((enc == 1 || enc == 2) 894 if ((enc == 1 || enc == 2)
893 && CHARSET_DIMENSION (charset) == 2) 895 && CHARSET_DIMENSION (charset) == 2)
@@ -6440,7 +6442,7 @@ handle_one_xevent (dpyinfo, eventp, bufp_r, numcharsp, finish)
6440 /* The input is converted to events, thus we can't 6442 /* The input is converted to events, thus we can't
6441 handle composition. Anyway, there's no XIM that 6443 handle composition. Anyway, there's no XIM that
6442 gives us composition information. */ 6444 gives us composition information. */
6443 coding.composing = COMPOSITION_DISABLED; 6445 coding.common_flags &= ~CODING_ANNOTATION_MASK;
6444 6446
6445 for (i = 0; i < nbytes; i++) 6447 for (i = 0; i < nbytes; i++)
6446 { 6448 {
@@ -6452,22 +6454,22 @@ handle_one_xevent (dpyinfo, eventp, bufp_r, numcharsp, finish)
6452 6454
6453 { 6455 {
6454 /* Decode the input data. */ 6456 /* Decode the input data. */
6455 int require; 6457 coding.destination = (unsigned char *) malloc (nbytes);
6456 unsigned char *p; 6458 if (! coding.destination)
6457 6459 break;
6458 require = decoding_buffer_size (&coding, nbytes); 6460 coding.dst_bytes = nbytes;
6459 p = (unsigned char *) alloca (require); 6461 coding.mode |= CODING_MODE_LAST_BLOCK;
6460 coding.mode |= CODING_MODE_LAST_BLOCK; 6462 decode_coding_c_string (&coding, copy_bufptr,
6461 /* We explicitly disable composition 6463 nbytes, Qnil);
6462 handling because key data should 6464 nbytes = coding.produced;
6463 not contain any composition 6465 nchars = coding.produced_char;
6464 sequence. */ 6466 if (copy_bufsiz < nbytes)
6465 coding.composing = COMPOSITION_DISABLED; 6467 {
6466 decode_coding (&coding, copy_bufptr, p, 6468 copy_bufsiz = nbytes;
6467 nbytes, require); 6469 copy_bufptr = (char *) alloca (nbytes);
6468 nbytes = coding.produced; 6470 }
6469 nchars = coding.produced_char; 6471 bcopy (coding.destination, copy_bufptr, nbytes);
6470 copy_bufptr = p; 6472 free (coding.destination);
6471 } 6473 }
6472 6474
6473 /* Convert the input data to a sequence of 6475 /* Convert the input data to a sequence of
@@ -6480,7 +6482,7 @@ handle_one_xevent (dpyinfo, eventp, bufp_r, numcharsp, finish)
6480 c = STRING_CHAR_AND_LENGTH (copy_bufptr + i, 6482 c = STRING_CHAR_AND_LENGTH (copy_bufptr + i,
6481 nbytes - i, len); 6483 nbytes - i, len);
6482 6484
6483 bufp->kind = (SINGLE_BYTE_CHAR_P (c) 6485 bufp->kind = (ASCII_CHAR_P (c)
6484 ? ASCII_KEYSTROKE_EVENT 6486 ? ASCII_KEYSTROKE_EVENT
6485 : MULTIBYTE_CHAR_KEYSTROKE_EVENT); 6487 : MULTIBYTE_CHAR_KEYSTROKE_EVENT);
6486 bufp->code = c; 6488 bufp->code = c;
@@ -7876,11 +7878,16 @@ x_new_font (f, fontname)
7876 register char *fontname; 7878 register char *fontname;
7877{ 7879{
7878 struct font_info *fontp 7880 struct font_info *fontp
7879 = FS_LOAD_FONT (f, 0, fontname, -1); 7881 = FS_LOAD_FONT (f, fontname);
7880 7882
7881 if (!fontp) 7883 if (!fontp)
7882 return Qnil; 7884 return Qnil;
7883 7885
7886 if (FRAME_FONT (f) == (XFontStruct *) (fontp->font))
7887 /* This font is already set in frame F. There's nothing more to
7888 do. */
7889 return build_string (fontp->full_name);
7890
7884 FRAME_FONT (f) = (XFontStruct *) (fontp->font); 7891 FRAME_FONT (f) = (XFontStruct *) (fontp->font);
7885 FRAME_BASELINE_OFFSET (f) = fontp->baseline_offset; 7892 FRAME_BASELINE_OFFSET (f) = fontp->baseline_offset;
7886 FRAME_FONTSET (f) = -1; 7893 FRAME_FONTSET (f) = -1;
@@ -7923,33 +7930,45 @@ x_new_font (f, fontname)
7923 return build_string (fontp->full_name); 7930 return build_string (fontp->full_name);
7924} 7931}
7925 7932
7926/* Give frame F the fontset named FONTSETNAME as its default font, and 7933/* Give frame F the fontset named FONTSETNAME as its default fontset,
7927 return the full name of that fontset. FONTSETNAME may be a wildcard 7934 and return the full name of that fontset. FONTSETNAME may be a
7928 pattern; in that case, we choose some fontset that fits the pattern. 7935 wildcard pattern; in that case, we choose some fontset that fits
7929 The return value shows which fontset we chose. */ 7936 the pattern. FONTSETNAME may be a font name for ASCII characters;
7937 in that case, we create a fontset from that font name.
7938
7939 The return value shows which fontset we chose.
7940 If FONTSETNAME specifies the default fontset, return Qt.
7941 If an ASCII font in the specified fontset can't be loaded, return
7942 Qnil. */
7930 7943
7931Lisp_Object 7944Lisp_Object
7932x_new_fontset (f, fontsetname) 7945x_new_fontset (f, fontsetname)
7933 struct frame *f; 7946 struct frame *f;
7934 char *fontsetname; 7947 Lisp_Object fontsetname;
7935{ 7948{
7936 int fontset = fs_query_fontset (build_string (fontsetname), 0); 7949 int fontset = fs_query_fontset (fontsetname, 0);
7937 Lisp_Object result; 7950 Lisp_Object result;
7938 7951
7939 if (fontset < 0) 7952 if (fontset > 0 && f->output_data.x->fontset == fontset)
7940 return Qnil;
7941
7942 if (FRAME_FONTSET (f) == fontset)
7943 /* This fontset is already set in frame F. There's nothing more 7953 /* This fontset is already set in frame F. There's nothing more
7944 to do. */ 7954 to do. */
7945 return fontset_name (fontset); 7955 return fontset_name (fontset);
7956 else if (fontset == 0)
7957 /* The default fontset can't be the default font. */
7958 return Qt;
7946 7959
7947 result = x_new_font (f, (SDATA (fontset_ascii (fontset)))); 7960 if (fontset > 0)
7961 result = x_new_font (f, (SDATA (fontset_ascii (fontset))));
7962 else
7963 result = x_new_font (f, SDATA (fontsetname));
7948 7964
7949 if (!STRINGP (result)) 7965 if (!STRINGP (result))
7950 /* Can't load ASCII font. */ 7966 /* Can't load ASCII font. */
7951 return Qnil; 7967 return Qnil;
7952 7968
7969 if (fontset < 0)
7970 fontset = new_fontset_from_font_name (result);
7971
7953 /* Since x_new_font doesn't update any fontset information, do it now. */ 7972 /* Since x_new_font doesn't update any fontset information, do it now. */
7954 FRAME_FONTSET (f) = fontset; 7973 FRAME_FONTSET (f) = fontset;
7955 7974
@@ -7959,7 +7978,7 @@ x_new_fontset (f, fontsetname)
7959 xic_set_xfontset (f, SDATA (fontset_ascii (fontset))); 7978 xic_set_xfontset (f, SDATA (fontset_ascii (fontset)));
7960#endif 7979#endif
7961 7980
7962 return build_string (fontsetname); 7981 return fontset_name (fontset);
7963} 7982}
7964 7983
7965 7984
@@ -9868,6 +9887,7 @@ x_load_font (f, fontname, size)
9868 BLOCK_INPUT; 9887 BLOCK_INPUT;
9869 fontp->font = font; 9888 fontp->font = font;
9870 fontp->font_idx = i; 9889 fontp->font_idx = i;
9890 fontp->charset = -1; /* fs_load_font sets it. */
9871 fontp->name = (char *) xmalloc (strlen (fontname) + 1); 9891 fontp->name = (char *) xmalloc (strlen (fontname) + 1);
9872 bcopy (fontname, fontp->name, strlen (fontname) + 1); 9892 bcopy (fontname, fontp->name, strlen (fontname) + 1);
9873 9893
@@ -9942,10 +9962,10 @@ x_load_font (f, fontname, size)
9942 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or 9962 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
9943 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF, 9963 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
9944 2:0xA020..0xFF7F). For the moment, we don't know which charset 9964 2:0xA020..0xFF7F). For the moment, we don't know which charset
9945 uses this font. So, we set information in fontp->encoding[1] 9965 uses this font. So, we set information in fontp->encoding_type
9946 which is never used by any charset. If mapping can't be 9966 which is never used by any charset. If mapping can't be
9947 decided, set FONT_ENCODING_NOT_DECIDED. */ 9967 decided, set FONT_ENCODING_NOT_DECIDED. */
9948 fontp->encoding[1] 9968 fontp->encoding_type
9949 = (font->max_byte1 == 0 9969 = (font->max_byte1 == 0
9950 /* 1-byte font */ 9970 /* 1-byte font */
9951 ? (font->min_char_or_byte2 < 0x80 9971 ? (font->min_char_or_byte2 < 0x80
@@ -10045,6 +10065,98 @@ x_find_ccl_program (fontp)
10045} 10065}
10046 10066
10047 10067
10068/* Return a char-table whose elements are t if the font FONT_INFO
10069 contains a glyph for the corresponding character, and nil if not.
10070
10071 Fixme: For the moment, this function works only for fonts whose
10072 glyph encoding is the same as Unicode (e.g. ISO10646-1 fonts). */
10073
10074Lisp_Object
10075x_get_font_repertory (f, font_info)
10076 FRAME_PTR f;
10077 struct font_info *font_info;
10078{
10079 XFontStruct *font = (XFontStruct *) font_info->font;
10080 Lisp_Object table;
10081 int min_byte1, max_byte1, min_byte2, max_byte2;
10082
10083 table = Fmake_char_table (Qnil, Qnil);
10084
10085 min_byte1 = font->min_byte1;
10086 max_byte1 = font->max_byte1;
10087 min_byte2 = font->min_char_or_byte2;
10088 max_byte2 = font->max_char_or_byte2;
10089 if (min_byte1 == 0 && max_byte1 == 0)
10090 {
10091 if (! font->per_char || font->all_chars_exist == True)
10092 char_table_set_range (table, min_byte2, max_byte2, Qt);
10093 else
10094 {
10095 XCharStruct *pcm = font->per_char;
10096 int from = -1;
10097 int i;
10098
10099 for (i = min_byte2; i <= max_byte2; i++, pcm++)
10100 {
10101 if (pcm->width == 0 && pcm->rbearing == pcm->lbearing)
10102 {
10103 if (from >= 0)
10104 {
10105 char_table_set_range (table, from, i - 1, Qt);
10106 from = -1;
10107 }
10108 }
10109 else if (from < 0)
10110 from = i;
10111 }
10112 if (from >= 0)
10113 char_table_set_range (table, from, i - 1, Qt);
10114 }
10115 }
10116 else
10117 {
10118 if (! font->per_char || font->all_chars_exist == True)
10119 {
10120 int i;
10121
10122 for (i = min_byte1; i <= max_byte1; i++)
10123 char_table_set_range (table,
10124 (i << 8) | min_byte2, (i << 8) | max_byte2,
10125 Qt);
10126 }
10127 else
10128 {
10129 XCharStruct *pcm = font->per_char;
10130 int i;
10131
10132 for (i = min_byte1; i <= max_byte1; i++)
10133 {
10134 int from = -1;
10135 int j;
10136
10137 for (j = min_byte2; j <= max_byte2; j++, pcm++)
10138 {
10139 if (pcm->width == 0 && pcm->rbearing == pcm->lbearing)
10140 {
10141 if (from >= 0)
10142 {
10143 char_table_set_range (table, (i << 8) | from,
10144 (i << 8) | (j - 1), Qt);
10145 from = -1;
10146 }
10147 }
10148 else if (from < 0)
10149 from = j;
10150 }
10151 if (from >= 0)
10152 char_table_set_range (table, (i << 8) | from,
10153 (i << 8) | (j - 1), Qt);
10154 }
10155 }
10156 }
10157
10158 return table;
10159}
10048 10160
10049/*********************************************************************** 10161/***********************************************************************
10050 Initialization 10162 Initialization
@@ -10801,8 +10913,6 @@ syms_of_xterm ()
10801 staticpro (&Qvendor_specific_keysyms); 10913 staticpro (&Qvendor_specific_keysyms);
10802 Qvendor_specific_keysyms = intern ("vendor-specific-keysyms"); 10914 Qvendor_specific_keysyms = intern ("vendor-specific-keysyms");
10803 10915
10804 staticpro (&Qutf_8);
10805 Qutf_8 = intern ("utf-8");
10806 staticpro (&Qlatin_1); 10916 staticpro (&Qlatin_1);
10807 Qlatin_1 = intern ("latin-1"); 10917 Qlatin_1 = intern ("latin-1");
10808 10918