Mercurial > emacs
comparison src/macterm.c @ 61658:38a086380ddc
(Qbig5, Qcn_gb, Qsjis, Qeuc_kr): Remove variables.
(syms_of_mac): Don't initialize them.
(Vmac_charset_info_alist): New variable.
(syms_of_mac): Defvar it.
(create_text_encoding_info_alist): New function.
(decode_mac_font_name, mac_to_x_fontname)
(x_font_name_to_mac_font_name, init_font_name_table): Don't hard
code the correspondence among XLFD charsets, Mac script codes, and
Emacs coding systems. Use Vmac_charset_info_alist and result of
create_text_encoding_info_alist instead.
(init_font_name_table) [TARGET_API_MAC_CARBON]: Use Font Manager
routines also on Mac OS Classic.
(init_font_name_table) [!TARGET_API_MAC_CARBON]: Use
add_font_name_table_entry.
(mac_do_list_fonts): Regard 0 in XLFD scaleble fields as
specified. Derive unspecified scalable fields from specified one.
(x_list_fonts): Consider Valternate_fontname_alist.
(kDefaultFontSize): Change value from 9 to 12.
(XLoadQueryFont): Get decoded font family, font face, and charset
from x_font_name_to_mac_font_name. Set full name of loaded font.
(mac_unload_font): Free `full_name' member.
(x_load_font): Don't try XLoadQueryFont if x_list_fonts returns
NULL. Copy full_name member of struct MacFontStruct to that of
struct font_info.
author | YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> |
---|---|
date | Tue, 19 Apr 2005 12:04:09 +0000 |
parents | 351bda10c1b0 |
children | 223bdb2c3b9a bbf359ec4a59 e1fbb019c538 |
comparison
equal
deleted
inserted
replaced
61657:8af99087c1e5 | 61658:38a086380ddc |
---|---|
5839 /* the global font name table */ | 5839 /* the global font name table */ |
5840 char **font_name_table = NULL; | 5840 char **font_name_table = NULL; |
5841 int font_name_table_size = 0; | 5841 int font_name_table_size = 0; |
5842 int font_name_count = 0; | 5842 int font_name_count = 0; |
5843 | 5843 |
5844 #if 0 | 5844 /* Alist linking character set strings to Mac text encoding and Emacs |
5845 /* compare two strings ignoring case */ | 5845 coding system. */ |
5846 static int | 5846 static Lisp_Object Vmac_charset_info_alist; |
5847 stricmp (const char *s, const char *t) | 5847 |
5848 { | 5848 static Lisp_Object |
5849 for ( ; tolower (*s) == tolower (*t); s++, t++) | 5849 create_text_encoding_info_alist () |
5850 if (*s == '\0') | 5850 { |
5851 return 0; | 5851 Lisp_Object result = Qnil, rest; |
5852 return tolower (*s) - tolower (*t); | 5852 |
5853 } | 5853 for (rest = Vmac_charset_info_alist; CONSP (rest); rest = XCDR (rest)) |
5854 | 5854 { |
5855 /* compare two strings ignoring case and handling wildcard */ | 5855 Lisp_Object charset_info = XCAR (rest); |
5856 static int | 5856 Lisp_Object charset, coding_system, text_encoding; |
5857 wildstrieq (char *s1, char *s2) | 5857 Lisp_Object existing_info; |
5858 { | 5858 |
5859 if (strcmp (s1, "*") == 0 || strcmp (s2, "*") == 0) | 5859 if (!(CONSP (charset_info) |
5860 return true; | 5860 && STRINGP (charset = XCAR (charset_info)) |
5861 | 5861 && CONSP (XCDR (charset_info)) |
5862 return stricmp (s1, s2) == 0; | 5862 && INTEGERP (text_encoding = XCAR (XCDR (charset_info))) |
5863 } | 5863 && CONSP (XCDR (XCDR (charset_info))) |
5864 | 5864 && SYMBOLP (coding_system = XCAR (XCDR (XCDR (charset_info)))))) |
5865 /* Assume parameter 1 is fully qualified, no wildcards. */ | 5865 continue; |
5866 static int | 5866 |
5867 mac_font_pattern_match (fontname, pattern) | 5867 existing_info = assq_no_quit (text_encoding, result); |
5868 char * fontname; | 5868 if (NILP (existing_info)) |
5869 char * pattern; | 5869 result = Fcons (list3 (text_encoding, coding_system, charset), |
5870 { | 5870 result); |
5871 char *regex = (char *) alloca (strlen (pattern) * 2 + 3); | |
5872 char *font_name_copy = (char *) alloca (strlen (fontname) + 1); | |
5873 char *ptr; | |
5874 | |
5875 /* Copy fontname so we can modify it during comparison. */ | |
5876 strcpy (font_name_copy, fontname); | |
5877 | |
5878 ptr = regex; | |
5879 *ptr++ = '^'; | |
5880 | |
5881 /* Turn pattern into a regexp and do a regexp match. */ | |
5882 for (; *pattern; pattern++) | |
5883 { | |
5884 if (*pattern == '?') | |
5885 *ptr++ = '.'; | |
5886 else if (*pattern == '*') | |
5887 { | |
5888 *ptr++ = '.'; | |
5889 *ptr++ = '*'; | |
5890 } | |
5891 else | 5871 else |
5892 *ptr++ = *pattern; | 5872 if (NILP (Fmember (charset, XCDR (XCDR (existing_info))))) |
5893 } | 5873 XSETCDR (XCDR (existing_info), |
5894 *ptr = '$'; | 5874 Fcons (charset, XCDR (XCDR (existing_info)))); |
5895 *(ptr + 1) = '\0'; | 5875 } |
5896 | 5876 |
5897 return (fast_c_string_match_ignore_case (build_string (regex), | 5877 return result; |
5898 font_name_copy) >= 0); | 5878 } |
5899 } | 5879 |
5900 | 5880 |
5901 /* Two font specs are considered to match if their foundry, family, | 5881 static void |
5902 weight, slant, and charset match. */ | 5882 decode_mac_font_name (name, size, coding_system) |
5903 static int | |
5904 mac_font_match (char *mf, char *xf) | |
5905 { | |
5906 char m_foundry[50], m_family[50], m_weight[20], m_slant[2], m_charset[20]; | |
5907 char x_foundry[50], x_family[50], x_weight[20], x_slant[2], x_charset[20]; | |
5908 | |
5909 if (sscanf (mf, "-%49[^-]-%49[^-]-%19[^-]-%1[^-]-%*[^-]--%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%19s", | |
5910 m_foundry, m_family, m_weight, m_slant, m_charset) != 5) | |
5911 return mac_font_pattern_match (mf, xf); | |
5912 | |
5913 if (sscanf (xf, "-%49[^-]-%49[^-]-%19[^-]-%1[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%19s", | |
5914 x_foundry, x_family, x_weight, x_slant, x_charset) != 5) | |
5915 return mac_font_pattern_match (mf, xf); | |
5916 | |
5917 return (wildstrieq (m_foundry, x_foundry) | |
5918 && wildstrieq (m_family, x_family) | |
5919 && wildstrieq (m_weight, x_weight) | |
5920 && wildstrieq (m_slant, x_slant) | |
5921 && wildstrieq (m_charset, x_charset)) | |
5922 || mac_font_pattern_match (mf, xf); | |
5923 } | |
5924 #endif | |
5925 | |
5926 static Lisp_Object Qbig5, Qcn_gb, Qsjis, Qeuc_kr; | |
5927 | |
5928 static void | |
5929 decode_mac_font_name (name, size, scriptcode) | |
5930 char *name; | 5883 char *name; |
5931 int size; | 5884 int size; |
5932 #if TARGET_API_MAC_CARBON | 5885 Lisp_Object coding_system; |
5933 int scriptcode; | 5886 { |
5934 #else | |
5935 short scriptcode; | |
5936 #endif | |
5937 { | |
5938 Lisp_Object coding_system; | |
5939 struct coding_system coding; | 5887 struct coding_system coding; |
5940 char *buf; | 5888 char *buf, *p; |
5941 | 5889 |
5942 switch (scriptcode) | 5890 for (p = name; *p; p++) |
5943 { | 5891 if (!isascii (*p) || iscntrl (*p)) |
5944 case smTradChinese: | |
5945 coding_system = Qbig5; | |
5946 break; | 5892 break; |
5947 case smSimpChinese: | 5893 |
5948 coding_system = Qcn_gb; | 5894 if (*p == '\0' |
5949 break; | 5895 || NILP (coding_system) || NILP (Fcoding_system_p (coding_system))) |
5950 case smJapanese: | 5896 return; |
5951 coding_system = Qsjis; | |
5952 break; | |
5953 case smKorean: | |
5954 coding_system = Qeuc_kr; | |
5955 break; | |
5956 default: | |
5957 return; | |
5958 } | |
5959 | 5897 |
5960 setup_coding_system (coding_system, &coding); | 5898 setup_coding_system (coding_system, &coding); |
5961 coding.src_multibyte = 0; | 5899 coding.src_multibyte = 0; |
5962 coding.dst_multibyte = 1; | 5900 coding.dst_multibyte = 1; |
5963 coding.mode |= CODING_MODE_LAST_BLOCK; | 5901 coding.mode |= CODING_MODE_LAST_BLOCK; |
5969 name[coding.produced] = '\0'; | 5907 name[coding.produced] = '\0'; |
5970 } | 5908 } |
5971 | 5909 |
5972 | 5910 |
5973 static char * | 5911 static char * |
5974 mac_to_x_fontname (name, size, style, scriptcode) | 5912 mac_to_x_fontname (name, size, style, charset) |
5975 char *name; | 5913 char *name; |
5976 int size; | 5914 int size; |
5977 Style style; | 5915 Style style; |
5978 #if TARGET_API_MAC_CARBON | 5916 char *charset; |
5979 int scriptcode; | |
5980 #else | |
5981 short scriptcode; | |
5982 #endif | |
5983 { | 5917 { |
5984 char foundry[32], family[32], cs[32]; | 5918 char foundry[32], family[32], cs[32]; |
5985 char xf[256], *result, *p; | 5919 char xf[256], *result, *p; |
5986 | 5920 |
5987 if (sscanf (name, "%31[^-]-%31[^-]-%31s", foundry, family, cs) != 3) | 5921 if (sscanf (name, "%31[^-]-%31[^-]-%31s", foundry, family, cs) == 3) |
5922 charset = cs; | |
5923 else | |
5988 { | 5924 { |
5989 strcpy(foundry, "Apple"); | 5925 strcpy(foundry, "Apple"); |
5990 strcpy(family, name); | 5926 strcpy(family, name); |
5991 | |
5992 switch (scriptcode) | |
5993 { | |
5994 case smTradChinese: /* == kTextEncodingMacChineseTrad */ | |
5995 strcpy(cs, "big5-0"); | |
5996 break; | |
5997 case smSimpChinese: /* == kTextEncodingMacChineseSimp */ | |
5998 strcpy(cs, "gb2312.1980-0"); | |
5999 break; | |
6000 case smJapanese: /* == kTextEncodingMacJapanese */ | |
6001 strcpy(cs, "jisx0208.1983-sjis"); | |
6002 break; | |
6003 case -smJapanese: | |
6004 /* Each Apple Japanese font is entered into the font table | |
6005 twice: once as a jisx0208.1983-sjis font and once as a | |
6006 jisx0201.1976-0 font. The latter can be used to display | |
6007 the ascii charset and katakana-jisx0201 charset. A | |
6008 negative script code signals that the name of this latter | |
6009 font is being built. */ | |
6010 strcpy(cs, "jisx0201.1976-0"); | |
6011 break; | |
6012 case smKorean: /* == kTextEncodingMacKorean */ | |
6013 strcpy(cs, "ksc5601.1989-0"); | |
6014 break; | |
6015 #if TARGET_API_MAC_CARBON | |
6016 case kTextEncodingMacCyrillic: | |
6017 strcpy(cs, "mac-cyrillic"); | |
6018 break; | |
6019 case kTextEncodingMacCentralEurRoman: | |
6020 strcpy(cs, "mac-centraleurroman"); | |
6021 break; | |
6022 case kTextEncodingMacSymbol: | |
6023 case kTextEncodingMacDingbats: | |
6024 strcpy(cs, "adobe-fontspecific"); | |
6025 break; | |
6026 #endif | |
6027 default: | |
6028 strcpy(cs, "mac-roman"); | |
6029 break; | |
6030 } | |
6031 } | 5927 } |
6032 | 5928 |
6033 sprintf(xf, "-%s-%s-%s-%c-normal--%d-%d-75-75-m-%d-%s", | 5929 sprintf(xf, "-%s-%s-%s-%c-normal--%d-%d-75-75-m-%d-%s", |
6034 foundry, family, style & bold ? "bold" : "medium", | 5930 foundry, family, style & bold ? "bold" : "medium", |
6035 style & italic ? 'i' : 'r', size, size * 10, size * 10, cs); | 5931 style & italic ? 'i' : 'r', size, size * 10, size * 10, charset); |
6036 | 5932 |
6037 result = (char *) xmalloc (strlen (xf) + 1); | 5933 result = (char *) xmalloc (strlen (xf) + 1); |
6038 strcpy (result, xf); | 5934 strcpy (result, xf); |
6039 for (p = result; *p; p++) | 5935 for (p = result; *p; p++) |
6040 *p = tolower(*p); | 5936 *p = tolower(*p); |
6048 "monaco", "Taipei", etc. Fonts converted from the GNU intlfonts | 5944 "monaco", "Taipei", etc. Fonts converted from the GNU intlfonts |
6049 collection contain their charset designation in their names, like | 5945 collection contain their charset designation in their names, like |
6050 "ETL-Fixed-iso8859-1", "ETL-Fixed-koi8-r", etc. Both types of font | 5946 "ETL-Fixed-iso8859-1", "ETL-Fixed-koi8-r", etc. Both types of font |
6051 names are handled accordingly. */ | 5947 names are handled accordingly. */ |
6052 static void | 5948 static void |
6053 x_font_name_to_mac_font_name (char *xf, char *mf) | 5949 x_font_name_to_mac_font_name (xf, mf, mf_decoded, style, cs) |
6054 { | 5950 char *xf, *mf, *mf_decoded; |
6055 char foundry[32], family[32], weight[20], slant[2], cs[32]; | 5951 Style *style; |
6056 Lisp_Object coding_system = Qnil; | 5952 char *cs; |
5953 { | |
5954 char foundry[32], family[32], weight[20], slant[2], *p; | |
5955 Lisp_Object charset_info, coding_system = Qnil; | |
6057 struct coding_system coding; | 5956 struct coding_system coding; |
6058 | 5957 |
6059 strcpy (mf, ""); | 5958 strcpy (mf, ""); |
6060 | 5959 |
6061 if (sscanf (xf, "-%31[^-]-%31[^-]-%19[^-]-%1[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%31s", | 5960 if (sscanf (xf, "-%31[^-]-%31[^-]-%19[^-]-%1[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%31s", |
6062 foundry, family, weight, slant, cs) != 5 && | 5961 foundry, family, weight, slant, cs) != 5 && |
6063 sscanf (xf, "-%31[^-]-%31[^-]-%19[^-]-%1[^-]-%*[^-]--%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%31s", | 5962 sscanf (xf, "-%31[^-]-%31[^-]-%19[^-]-%1[^-]-%*[^-]--%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%31s", |
6064 foundry, family, weight, slant, cs) != 5) | 5963 foundry, family, weight, slant, cs) != 5) |
6065 return; | 5964 return; |
6066 | 5965 |
6067 if (strcmp (cs, "big5-0") == 0) | 5966 *style = normal; |
6068 coding_system = Qbig5; | 5967 if (strcmp (weight, "bold") == 0) |
6069 else if (strcmp (cs, "gb2312.1980-0") == 0) | 5968 *style |= bold; |
6070 coding_system = Qcn_gb; | 5969 if (*slant == 'i') |
6071 else if (strcmp (cs, "jisx0208.1983-sjis") == 0 | 5970 *style |= italic; |
6072 || strcmp (cs, "jisx0201.1976-0") == 0) | 5971 |
6073 coding_system = Qsjis; | 5972 charset_info = Fassoc (build_string (cs), Vmac_charset_info_alist); |
6074 else if (strcmp (cs, "ksc5601.1989-0") == 0) | 5973 if (!NILP (charset_info)) |
6075 coding_system = Qeuc_kr; | 5974 { |
6076 else if (strcmp (cs, "mac-roman") == 0 | 5975 strcpy (mf_decoded, family); |
6077 || strcmp (cs, "mac-cyrillic") == 0 | 5976 coding_system = Fcar (Fcdr (Fcdr (charset_info))); |
6078 || strcmp (cs, "mac-centraleurroman") == 0 | 5977 } |
6079 || strcmp (cs, "adobe-fontspecific") == 0) | |
6080 strcpy (mf, family); | |
6081 else | 5978 else |
6082 sprintf (mf, "%s-%s-%s", foundry, family, cs); | 5979 sprintf (mf_decoded, "%s-%s-%s", foundry, family, cs); |
6083 | 5980 |
6084 if (!NILP (coding_system)) | 5981 for (p = mf_decoded; *p; p++) |
5982 if (!isascii (*p) || iscntrl (*p)) | |
5983 break; | |
5984 | |
5985 if (*p == '\0' | |
5986 || NILP (coding_system) || NILP (Fcoding_system_p (coding_system))) | |
5987 strcpy (mf, mf_decoded); | |
5988 else | |
6085 { | 5989 { |
6086 setup_coding_system (coding_system, &coding); | 5990 setup_coding_system (coding_system, &coding); |
6087 coding.src_multibyte = 1; | 5991 coding.src_multibyte = 1; |
6088 coding.dst_multibyte = 1; | 5992 coding.dst_multibyte = 1; |
6089 coding.mode |= CODING_MODE_LAST_BLOCK; | 5993 coding.mode |= CODING_MODE_LAST_BLOCK; |
6090 encode_coding (&coding, family, mf, strlen (family), sizeof (Str32) - 1); | 5994 encode_coding (&coding, mf_decoded, mf, |
5995 strlen (mf_decoded), sizeof (Str32) - 1); | |
6091 mf[coding.produced] = '\0'; | 5996 mf[coding.produced] = '\0'; |
6092 } | 5997 } |
6093 } | 5998 } |
6094 | 5999 |
6095 | 6000 |
6120 | 6025 |
6121 static void | 6026 static void |
6122 init_font_name_table () | 6027 init_font_name_table () |
6123 { | 6028 { |
6124 #if TARGET_API_MAC_CARBON | 6029 #if TARGET_API_MAC_CARBON |
6125 SInt32 sv; | 6030 FMFontFamilyIterator ffi; |
6126 | 6031 FMFontFamilyInstanceIterator ffii; |
6127 if (Gestalt (gestaltSystemVersion, &sv) == noErr && sv >= 0x1000) | 6032 FMFontFamily ff; |
6128 { | 6033 Lisp_Object text_encoding_info_alist; |
6129 FMFontFamilyIterator ffi; | 6034 struct gcpro gcpro1; |
6130 FMFontFamilyInstanceIterator ffii; | 6035 |
6131 FMFontFamily ff; | 6036 /* Create a dummy instance iterator here to avoid creating and |
6132 | 6037 destroying it in the loop. */ |
6133 /* Create a dummy instance iterator here to avoid creating and | 6038 if (FMCreateFontFamilyInstanceIterator (0, &ffii) != noErr) |
6134 destroying it in the loop. */ | 6039 return; |
6135 if (FMCreateFontFamilyInstanceIterator (0, &ffii) != noErr) | 6040 /* Create an iterator to enumerate the font families. */ |
6136 return; | 6041 if (FMCreateFontFamilyIterator (NULL, NULL, kFMDefaultOptions, &ffi) |
6137 /* Create an iterator to enumerate the font families. */ | 6042 != noErr) |
6138 if (FMCreateFontFamilyIterator (NULL, NULL, kFMDefaultOptions, &ffi) | 6043 { |
6139 != noErr) | 6044 FMDisposeFontFamilyInstanceIterator (&ffii); |
6045 return; | |
6046 } | |
6047 | |
6048 text_encoding_info_alist = create_text_encoding_info_alist (); | |
6049 | |
6050 GCPRO1 (text_encoding_info_alist); | |
6051 | |
6052 while (FMGetNextFontFamily (&ffi, &ff) == noErr) | |
6053 { | |
6054 Str255 name; | |
6055 FMFont font; | |
6056 FMFontStyle style; | |
6057 FMFontSize size; | |
6058 TextEncoding encoding; | |
6059 TextEncodingBase sc; | |
6060 Lisp_Object text_encoding_info; | |
6061 | |
6062 if (FMGetFontFamilyName (ff, name) != noErr) | |
6063 break; | |
6064 p2cstr (name); | |
6065 if (*name == '.') | |
6066 continue; | |
6067 | |
6068 if (FMGetFontFamilyTextEncoding (ff, &encoding) != noErr) | |
6069 break; | |
6070 sc = GetTextEncodingBase (encoding); | |
6071 text_encoding_info = assq_no_quit (make_number (sc), | |
6072 text_encoding_info_alist); | |
6073 if (!NILP (text_encoding_info)) | |
6074 decode_mac_font_name (name, sizeof (name), | |
6075 XCAR (XCDR (text_encoding_info))); | |
6076 else | |
6077 text_encoding_info = assq_no_quit (make_number (kTextEncodingMacRoman), | |
6078 text_encoding_info_alist); | |
6079 | |
6080 /* Point the instance iterator at the current font family. */ | |
6081 if (FMResetFontFamilyInstanceIterator (ff, &ffii) != noErr) | |
6082 break; | |
6083 | |
6084 while (FMGetNextFontFamilyInstance (&ffii, &font, &style, &size) | |
6085 == noErr) | |
6140 { | 6086 { |
6141 FMDisposeFontFamilyInstanceIterator (&ffii); | 6087 Lisp_Object rest = XCDR (XCDR (text_encoding_info)); |
6142 return; | 6088 |
6143 } | 6089 for (; !NILP (rest); rest = XCDR (rest)) |
6144 | |
6145 while (FMGetNextFontFamily (&ffi, &ff) == noErr) | |
6146 { | |
6147 Str255 name; | |
6148 FMFont font; | |
6149 FMFontStyle style; | |
6150 FMFontSize size; | |
6151 TextEncoding encoding; | |
6152 TextEncodingBase sc; | |
6153 | |
6154 if (FMGetFontFamilyName (ff, name) != noErr) | |
6155 break; | |
6156 p2cstr (name); | |
6157 if (*name == '.') | |
6158 continue; | |
6159 | |
6160 if (FMGetFontFamilyTextEncoding (ff, &encoding) != noErr) | |
6161 break; | |
6162 sc = GetTextEncodingBase (encoding); | |
6163 decode_mac_font_name (name, sizeof (name), sc); | |
6164 | |
6165 /* Point the instance iterator at the current font family. */ | |
6166 if (FMResetFontFamilyInstanceIterator (ff, &ffii) != noErr) | |
6167 break; | |
6168 | |
6169 while (FMGetNextFontFamilyInstance (&ffii, &font, &style, &size) | |
6170 == noErr) | |
6171 { | 6090 { |
6172 /* Both jisx0208.1983-sjis and jisx0201.1976-0 parts are | 6091 char *cs = SDATA (XCAR (rest)); |
6173 contained in Apple Japanese (SJIS) font. */ | 6092 |
6174 again: | |
6175 if (size == 0) | 6093 if (size == 0) |
6176 { | 6094 { |
6177 add_font_name_table_entry (mac_to_x_fontname (name, size, | 6095 add_font_name_table_entry (mac_to_x_fontname (name, size, |
6178 style, sc)); | 6096 style, cs)); |
6179 add_font_name_table_entry (mac_to_x_fontname (name, size, | 6097 add_font_name_table_entry (mac_to_x_fontname (name, size, |
6180 italic, sc)); | 6098 italic, cs)); |
6181 add_font_name_table_entry (mac_to_x_fontname (name, size, | 6099 add_font_name_table_entry (mac_to_x_fontname (name, size, |
6182 bold, sc)); | 6100 bold, cs)); |
6183 add_font_name_table_entry (mac_to_x_fontname (name, size, | 6101 add_font_name_table_entry (mac_to_x_fontname (name, size, |
6184 italic | bold, | 6102 italic | bold, |
6185 sc)); | 6103 cs)); |
6186 } | 6104 } |
6187 else | 6105 else |
6188 add_font_name_table_entry (mac_to_x_fontname (name, size, | |
6189 style, sc)); | |
6190 if (sc == smJapanese) | |
6191 { | 6106 { |
6192 sc = -smJapanese; | 6107 add_font_name_table_entry (mac_to_x_fontname (name, size, |
6193 goto again; | 6108 style, cs)); |
6194 } | 6109 } |
6195 else if (sc == -smJapanese) | |
6196 sc = smJapanese; | |
6197 } | 6110 } |
6198 } | 6111 } |
6199 | 6112 } |
6200 /* Dispose of the iterators. */ | 6113 |
6201 FMDisposeFontFamilyIterator (&ffi); | 6114 UNGCPRO; |
6202 FMDisposeFontFamilyInstanceIterator (&ffii); | 6115 |
6203 } | 6116 /* Dispose of the iterators. */ |
6204 else | 6117 FMDisposeFontFamilyIterator (&ffi); |
6205 { | 6118 FMDisposeFontFamilyInstanceIterator (&ffii); |
6206 #endif /* TARGET_API_MAC_CARBON */ | 6119 #else /* !TARGET_API_MAC_CARBON */ |
6207 GrafPtr port; | 6120 GrafPtr port; |
6208 SInt16 fontnum, old_fontnum; | 6121 SInt16 fontnum, old_fontnum; |
6209 int num_mac_fonts = CountResources('FOND'); | 6122 int num_mac_fonts = CountResources('FOND'); |
6210 int i, j; | 6123 int i, j; |
6211 Handle font_handle, font_handle_2; | 6124 Handle font_handle, font_handle_2; |
6212 short id, scriptcode; | 6125 short id, scriptcode; |
6213 ResType type; | 6126 ResType type; |
6214 Str32 name; | 6127 Str32 name; |
6215 struct FontAssoc *fat; | 6128 struct FontAssoc *fat; |
6216 struct AsscEntry *assc_entry; | 6129 struct AsscEntry *assc_entry; |
6217 | 6130 Lisp_Object text_encoding_info_alist, text_encoding_info; |
6218 GetPort (&port); /* save the current font number used */ | 6131 struct gcpro gcpro1; |
6219 #if TARGET_API_MAC_CARBON | 6132 |
6220 old_fontnum = GetPortTextFont (port); | 6133 GetPort (&port); /* save the current font number used */ |
6221 #else | 6134 old_fontnum = port->txFont; |
6222 old_fontnum = port->txFont; | 6135 |
6223 #endif | 6136 text_encoding_info_alist = create_text_encoding_info_alist (); |
6224 | 6137 |
6225 for (i = 1; i <= num_mac_fonts; i++) /* get all available fonts */ | 6138 GCPRO1 (text_encoding_info_alist); |
6139 | |
6140 for (i = 1; i <= num_mac_fonts; i++) /* get all available fonts */ | |
6141 { | |
6142 font_handle = GetIndResource ('FOND', i); | |
6143 if (!font_handle) | |
6144 continue; | |
6145 | |
6146 GetResInfo (font_handle, &id, &type, name); | |
6147 GetFNum (name, &fontnum); | |
6148 p2cstr (name); | |
6149 if (fontnum == 0) | |
6150 continue; | |
6151 | |
6152 TextFont (fontnum); | |
6153 scriptcode = FontToScript (fontnum); | |
6154 text_encoding_info = assq_no_quit (make_number (scriptcode), | |
6155 text_encoding_info_alist); | |
6156 if (!NILP (text_encoding_info)) | |
6157 decode_mac_font_name (name, sizeof (name), | |
6158 XCAR (XCDR (text_encoding_info))); | |
6159 else | |
6160 text_encoding_info = assq_no_quit (make_number (smRoman), | |
6161 text_encoding_info_alist); | |
6162 do | |
6226 { | 6163 { |
6227 font_handle = GetIndResource ('FOND', i); | 6164 HLock (font_handle); |
6228 if (!font_handle) | 6165 |
6229 continue; | 6166 if (GetResourceSizeOnDisk (font_handle) |
6230 | 6167 >= sizeof (struct FamRec)) |
6231 GetResInfo (font_handle, &id, &type, name); | |
6232 GetFNum (name, &fontnum); | |
6233 p2cstr (name); | |
6234 if (fontnum == 0) | |
6235 continue; | |
6236 | |
6237 TextFont (fontnum); | |
6238 scriptcode = FontToScript (fontnum); | |
6239 decode_mac_font_name (name, sizeof (name), scriptcode); | |
6240 do | |
6241 { | 6168 { |
6242 HLock (font_handle); | 6169 fat = (struct FontAssoc *) (*font_handle |
6243 | 6170 + sizeof (struct FamRec)); |
6244 if (GetResourceSizeOnDisk (font_handle) | 6171 assc_entry |
6245 >= sizeof (struct FamRec)) | 6172 = (struct AsscEntry *) (*font_handle |
6173 + sizeof (struct FamRec) | |
6174 + sizeof (struct FontAssoc)); | |
6175 | |
6176 for (j = 0; j <= fat->numAssoc; j++, assc_entry++) | |
6246 { | 6177 { |
6247 fat = (struct FontAssoc *) (*font_handle | 6178 Lisp_Object rest = XCDR (XCDR (text_encoding_info)); |
6248 + sizeof (struct FamRec)); | 6179 |
6249 assc_entry | 6180 for (; !NILP (rest); rest = XCDR (rest)) |
6250 = (struct AsscEntry *) (*font_handle | |
6251 + sizeof (struct FamRec) | |
6252 + sizeof (struct FontAssoc)); | |
6253 | |
6254 for (j = 0; j <= fat->numAssoc; j++, assc_entry++) | |
6255 { | 6181 { |
6256 if (font_name_table_size == 0) | 6182 char *cs = SDATA (XCAR (rest)); |
6257 { | 6183 |
6258 font_name_table_size = 16; | 6184 add_font_name_table_entry (mac_to_x_fontname (name, |
6259 font_name_table = (char **) | 6185 assc_entry->fontSize, |
6260 xmalloc (font_name_table_size * sizeof (char *)); | 6186 assc_entry->fontStyle, |
6261 } | 6187 cs)); |
6262 else if (font_name_count >= font_name_table_size) | |
6263 { | |
6264 font_name_table_size += 16; | |
6265 font_name_table = (char **) | |
6266 xrealloc (font_name_table, | |
6267 font_name_table_size * sizeof (char *)); | |
6268 } | |
6269 font_name_table[font_name_count++] | |
6270 = mac_to_x_fontname (name, | |
6271 assc_entry->fontSize, | |
6272 assc_entry->fontStyle, | |
6273 scriptcode); | |
6274 /* Both jisx0208.1983-sjis and jisx0201.1976-0 | |
6275 parts are contained in Apple Japanese (SJIS) | |
6276 font. */ | |
6277 if (smJapanese == scriptcode) | |
6278 { | |
6279 font_name_table[font_name_count++] | |
6280 = mac_to_x_fontname (name, | |
6281 assc_entry->fontSize, | |
6282 assc_entry->fontStyle, | |
6283 -smJapanese); | |
6284 } | |
6285 } | 6188 } |
6286 } | 6189 } |
6287 | |
6288 HUnlock (font_handle); | |
6289 font_handle_2 = GetNextFOND (font_handle); | |
6290 ReleaseResource (font_handle); | |
6291 font_handle = font_handle_2; | |
6292 } | 6190 } |
6293 while (ResError () == noErr && font_handle); | 6191 |
6192 HUnlock (font_handle); | |
6193 font_handle_2 = GetNextFOND (font_handle); | |
6194 ReleaseResource (font_handle); | |
6195 font_handle = font_handle_2; | |
6294 } | 6196 } |
6295 | 6197 while (ResError () == noErr && font_handle); |
6296 TextFont (old_fontnum); | 6198 } |
6297 #if TARGET_API_MAC_CARBON | 6199 |
6298 } | 6200 UNGCPRO; |
6299 #endif /* TARGET_API_MAC_CARBON */ | 6201 |
6202 TextFont (old_fontnum); | |
6203 #endif /* !TARGET_API_MAC_CARBON */ | |
6300 } | 6204 } |
6301 | 6205 |
6302 | 6206 |
6303 void | 6207 void |
6304 mac_clear_font_name_table () | 6208 mac_clear_font_name_table () |
6382 do | 6286 do |
6383 { | 6287 { |
6384 ptr++; | 6288 ptr++; |
6385 if (i == *field) | 6289 if (i == *field) |
6386 { | 6290 { |
6387 if ('1' <= *ptr && *ptr <= '9') | 6291 if ('0' <= *ptr && *ptr <= '9') |
6388 { | 6292 { |
6389 *val = *ptr++ - '0'; | 6293 *val = *ptr++ - '0'; |
6390 while ('0' <= *ptr && *ptr <= '9' && *val < 10000) | 6294 while ('0' <= *ptr && *ptr <= '9' && *val < 10000) |
6391 *val = *val * 10 + *ptr++ - '0'; | 6295 *val = *val * 10 + *ptr++ - '0'; |
6392 if (*ptr != '-') | 6296 if (*ptr != '-') |
6400 } | 6304 } |
6401 while (ptr && i < 14); | 6305 while (ptr && i < 14); |
6402 | 6306 |
6403 if (i == 14 && ptr == NULL) | 6307 if (i == 14 && ptr == NULL) |
6404 { | 6308 { |
6405 if (scl_val[XLFD_SCL_POINT_SIZE] > 0) | 6309 if (scl_val[XLFD_SCL_PIXEL_SIZE] < 0) |
6406 { | 6310 scl_val[XLFD_SCL_PIXEL_SIZE] = |
6407 scl_val[XLFD_SCL_PIXEL_SIZE] = scl_val[XLFD_SCL_POINT_SIZE] / 10; | 6311 (scl_val[XLFD_SCL_POINT_SIZE] > 0 ? scl_val[XLFD_SCL_POINT_SIZE] / 10 |
6408 scl_val[XLFD_SCL_AVGWIDTH] = scl_val[XLFD_SCL_POINT_SIZE]; | 6312 : (scl_val[XLFD_SCL_AVGWIDTH] > 0 ? scl_val[XLFD_SCL_AVGWIDTH] / 10 |
6409 } | 6313 : -1)); |
6410 else if (scl_val[XLFD_SCL_PIXEL_SIZE] > 0) | 6314 if (scl_val[XLFD_SCL_POINT_SIZE] < 0) |
6411 { | 6315 scl_val[XLFD_SCL_POINT_SIZE] = |
6412 scl_val[XLFD_SCL_POINT_SIZE] = | 6316 (scl_val[XLFD_SCL_PIXEL_SIZE] > 0 ? scl_val[XLFD_SCL_PIXEL_SIZE] * 10 |
6413 scl_val[XLFD_SCL_AVGWIDTH] = scl_val[XLFD_SCL_PIXEL_SIZE] * 10; | 6317 : (scl_val[XLFD_SCL_AVGWIDTH] > 0 ? scl_val[XLFD_SCL_AVGWIDTH] |
6414 } | 6318 : -1)); |
6415 else if (scl_val[XLFD_SCL_AVGWIDTH] > 0) | 6319 if (scl_val[XLFD_SCL_AVGWIDTH] < 0) |
6416 { | 6320 scl_val[XLFD_SCL_AVGWIDTH] = |
6417 scl_val[XLFD_SCL_PIXEL_SIZE] = scl_val[XLFD_SCL_AVGWIDTH] / 10; | 6321 (scl_val[XLFD_SCL_PIXEL_SIZE] > 0 ? scl_val[XLFD_SCL_PIXEL_SIZE] * 10 |
6418 scl_val[XLFD_SCL_POINT_SIZE] = scl_val[XLFD_SCL_AVGWIDTH]; | 6322 : (scl_val[XLFD_SCL_POINT_SIZE] > 0 ? scl_val[XLFD_SCL_POINT_SIZE] |
6419 } | 6323 : -1)); |
6420 } | 6324 } |
6421 else | 6325 else |
6422 scl_val[XLFD_SCL_PIXEL_SIZE] = -1; | 6326 scl_val[XLFD_SCL_PIXEL_SIZE] = -1; |
6423 | 6327 |
6424 ptr = regex; | 6328 ptr = regex; |
6505 xfree (nonspecial); | 6409 xfree (nonspecial); |
6506 | 6410 |
6507 return font_list; | 6411 return font_list; |
6508 } | 6412 } |
6509 | 6413 |
6510 /* Return a list of at most MAXNAMES font specs matching the one in | 6414 /* Return a list of names of available fonts matching PATTERN on frame F. |
6511 PATTERN. Cache matching fonts for patterns in | 6415 |
6512 dpyinfo->name_list_element to avoid looking them up again by | 6416 Frame F null means we have not yet created any frame on Mac, and |
6513 calling mac_font_pattern_match (slow). Return as many matching | 6417 consult the first display in x_display_list. MAXNAMES sets a limit |
6514 fonts as possible if MAXNAMES = -1. */ | 6418 on how many fonts to match. */ |
6515 | 6419 |
6516 Lisp_Object | 6420 Lisp_Object |
6517 x_list_fonts (struct frame *f, | 6421 x_list_fonts (f, pattern, size, maxnames) |
6518 Lisp_Object pattern, | 6422 struct frame *f; |
6519 int size, | 6423 Lisp_Object pattern; |
6520 int maxnames) | 6424 int size, maxnames; |
6521 { | 6425 { |
6522 Lisp_Object newlist = Qnil, tem, key; | 6426 Lisp_Object list = Qnil, patterns, tem, key; |
6523 struct mac_display_info *dpyinfo = f ? FRAME_MAC_DISPLAY_INFO (f) : NULL; | 6427 struct mac_display_info *dpyinfo |
6524 | 6428 = f ? FRAME_MAC_DISPLAY_INFO (f) : x_display_list; |
6525 if (dpyinfo) | 6429 |
6526 { | 6430 xassert (size <= 0); |
6431 | |
6432 patterns = Fassoc (pattern, Valternate_fontname_alist); | |
6433 if (NILP (patterns)) | |
6434 patterns = Fcons (pattern, Qnil); | |
6435 | |
6436 for (; CONSP (patterns); patterns = XCDR (patterns)) | |
6437 { | |
6438 pattern = XCAR (patterns); | |
6439 | |
6440 if (!STRINGP (pattern)) | |
6441 continue; | |
6442 | |
6527 tem = XCAR (XCDR (dpyinfo->name_list_element)); | 6443 tem = XCAR (XCDR (dpyinfo->name_list_element)); |
6528 key = Fcons (pattern, make_number (maxnames)); | 6444 key = Fcons (pattern, make_number (maxnames)); |
6529 | 6445 |
6530 newlist = Fassoc (key, tem); | 6446 list = Fassoc (key, tem); |
6531 if (!NILP (newlist)) | 6447 if (!NILP (list)) |
6532 { | 6448 { |
6533 newlist = Fcdr_safe (newlist); | 6449 list = Fcdr_safe (list); |
6450 /* We have a cashed list. Don't have to get the list again. */ | |
6534 goto label_cached; | 6451 goto label_cached; |
6535 } | 6452 } |
6536 } | 6453 |
6537 | 6454 BLOCK_INPUT; |
6538 BLOCK_INPUT; | 6455 list = mac_do_list_fonts (SDATA (pattern), maxnames); |
6539 newlist = mac_do_list_fonts (SDATA (pattern), maxnames); | 6456 UNBLOCK_INPUT; |
6540 UNBLOCK_INPUT; | 6457 |
6541 | 6458 /* MAC_TODO: add code for matching outline fonts here */ |
6542 /* MAC_TODO: add code for matching outline fonts here */ | 6459 |
6543 | 6460 /* Now store the result in the cache. */ |
6544 if (dpyinfo) | |
6545 { | |
6546 XSETCAR (XCDR (dpyinfo->name_list_element), | 6461 XSETCAR (XCDR (dpyinfo->name_list_element), |
6547 Fcons (Fcons (key, newlist), | 6462 Fcons (Fcons (key, list), |
6548 XCAR (XCDR (dpyinfo->name_list_element)))); | 6463 XCAR (XCDR (dpyinfo->name_list_element)))); |
6549 } | 6464 |
6550 label_cached: | 6465 label_cached: |
6551 | 6466 if (NILP (list)) continue; /* Try the remaining alternatives. */ |
6552 return newlist; | 6467 } |
6468 | |
6469 return list; | |
6553 } | 6470 } |
6554 | 6471 |
6555 | 6472 |
6556 #if GLYPH_DEBUG | 6473 #if GLYPH_DEBUG |
6557 | 6474 |
6666 | 6583 |
6667 return 1; | 6584 return 1; |
6668 } | 6585 } |
6669 | 6586 |
6670 | 6587 |
6671 const int kDefaultFontSize = 9; | 6588 const int kDefaultFontSize = 12; |
6672 | 6589 |
6673 | 6590 |
6674 /* XLoadQueryFont creates and returns an internal representation for a | 6591 /* XLoadQueryFont creates and returns an internal representation for a |
6675 font in a MacFontStruct struct. There is really no concept | 6592 font in a MacFontStruct struct. There is really no concept |
6676 corresponding to "loading" a font on the Mac. But we check its | 6593 corresponding to "loading" a font on the Mac. But we check its |
6678 and store them in the returned MacFontStruct. */ | 6595 and store them in the returned MacFontStruct. */ |
6679 | 6596 |
6680 static MacFontStruct * | 6597 static MacFontStruct * |
6681 XLoadQueryFont (Display *dpy, char *fontname) | 6598 XLoadQueryFont (Display *dpy, char *fontname) |
6682 { | 6599 { |
6683 int i, size, is_two_byte_font, char_width; | 6600 int i, size, point_size, avgwidth, is_two_byte_font, char_width; |
6684 char *name; | 6601 char *name; |
6685 GrafPtr port; | 6602 GrafPtr port; |
6686 SInt16 old_fontnum, old_fontsize; | 6603 SInt16 old_fontnum, old_fontsize; |
6687 Style old_fontface; | 6604 Style old_fontface; |
6688 Str32 mfontname; | 6605 Str32 mfontname, mfontname_decoded, charset; |
6689 SInt16 fontnum; | 6606 SInt16 fontnum; |
6690 Style fontface = normal; | 6607 Style fontface; |
6608 #if TARGET_API_MAC_CARBON | |
6609 TextEncoding encoding; | |
6610 int scriptcode; | |
6611 #else | |
6612 short scriptcode; | |
6613 #endif | |
6691 MacFontStruct *font; | 6614 MacFontStruct *font; |
6692 FontInfo the_fontinfo; | 6615 FontInfo the_fontinfo; |
6693 char s_weight[7], c_slant; | 6616 #ifdef MAC_OSX |
6617 UInt32 old_flags, new_flags; | |
6618 #endif | |
6694 | 6619 |
6695 if (is_fully_specified_xlfd (fontname)) | 6620 if (is_fully_specified_xlfd (fontname)) |
6696 name = fontname; | 6621 name = fontname; |
6697 else | 6622 else |
6698 { | 6623 { |
6713 old_fontnum = port->txFont; | 6638 old_fontnum = port->txFont; |
6714 old_fontsize = port->txSize; | 6639 old_fontsize = port->txSize; |
6715 old_fontface = port->txFace; | 6640 old_fontface = port->txFace; |
6716 #endif | 6641 #endif |
6717 | 6642 |
6718 if (sscanf (name, "-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]--%d-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%*s", &size) != 1) | 6643 if (sscanf (name, "-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]--%d-%d-%*[^-]-%*[^-]-%*c-%d-%*s", &size, &point_size, &avgwidth) != 3) |
6644 size = 0; | |
6645 else | |
6646 { | |
6647 if (size == 0) | |
6648 if (point_size > 0) | |
6649 size = point_size / 10; | |
6650 else if (avgwidth > 0) | |
6651 size = avgwidth / 10; | |
6652 } | |
6653 if (size == 0) | |
6719 size = kDefaultFontSize; | 6654 size = kDefaultFontSize; |
6720 | 6655 |
6721 if (sscanf (name, "-%*[^-]-%*[^-]-%6[^-]-%*c-%*[^-]--%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%*s", s_weight) == 1) | 6656 x_font_name_to_mac_font_name (name, mfontname, mfontname_decoded, |
6722 if (strcmp (s_weight, "bold") == 0) | 6657 &fontface, charset); |
6723 fontface |= bold; | |
6724 | |
6725 if (sscanf (name, "-%*[^-]-%*[^-]-%*[^-]-%c-%*[^-]--%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%*s", &c_slant) == 1) | |
6726 if (c_slant == 'i') | |
6727 fontface |= italic; | |
6728 | |
6729 x_font_name_to_mac_font_name (name, mfontname); | |
6730 c2pstr (mfontname); | 6658 c2pstr (mfontname); |
6659 #if TARGET_API_MAC_CARBON | |
6660 fontnum = FMGetFontFamilyFromName (mfontname); | |
6661 if (fontnum == kInvalidFontFamily | |
6662 || FMGetFontFamilyTextEncoding (fontnum, &encoding) != noErr) | |
6663 return NULL; | |
6664 scriptcode = GetTextEncodingBase (encoding); | |
6665 #else | |
6731 GetFNum (mfontname, &fontnum); | 6666 GetFNum (mfontname, &fontnum); |
6732 if (fontnum == 0) | 6667 if (fontnum == 0) |
6733 return NULL; | 6668 return NULL; |
6669 scriptcode = FontToScript (fontnum); | |
6670 #endif | |
6734 | 6671 |
6735 font = (MacFontStruct *) xmalloc (sizeof (struct MacFontStruct)); | 6672 font = (MacFontStruct *) xmalloc (sizeof (struct MacFontStruct)); |
6736 | |
6737 font->fontname = (char *) xmalloc (strlen (name) + 1); | |
6738 bcopy (name, font->fontname, strlen (name) + 1); | |
6739 | 6673 |
6740 font->mac_fontnum = fontnum; | 6674 font->mac_fontnum = fontnum; |
6741 font->mac_fontsize = size; | 6675 font->mac_fontsize = size; |
6742 font->mac_fontface = fontface; | 6676 font->mac_fontface = fontface; |
6743 font->mac_scriptcode = FontToScript (fontnum); | 6677 font->mac_scriptcode = scriptcode; |
6744 | 6678 |
6745 /* Apple Japanese (SJIS) font is listed as both | 6679 /* Apple Japanese (SJIS) font is listed as both |
6746 "*-jisx0208.1983-sjis" (Japanese script) and "*-jisx0201.1976-0" | 6680 "*-jisx0208.1983-sjis" (Japanese script) and "*-jisx0201.1976-0" |
6747 (Roman script) in init_font_name_table (). The latter should be | 6681 (Roman script) in init_font_name_table (). The latter should be |
6748 treated as a one-byte font. */ | 6682 treated as a one-byte font. */ |
6749 { | 6683 if (scriptcode == smJapanese && strcmp (charset, "jisx0201.1976-0") == 0) |
6750 char cs[32]; | 6684 font->mac_scriptcode = smRoman; |
6751 | 6685 |
6752 if (sscanf (name, | 6686 font->full_name = mac_to_x_fontname (mfontname_decoded, size, fontface, charset); |
6753 "-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]--%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%31s", | |
6754 cs) == 1 | |
6755 && 0 == strcmp (cs, "jisx0201.1976-0")) | |
6756 font->mac_scriptcode = smRoman; | |
6757 } | |
6758 | 6687 |
6759 is_two_byte_font = font->mac_scriptcode == smJapanese || | 6688 is_two_byte_font = font->mac_scriptcode == smJapanese || |
6760 font->mac_scriptcode == smTradChinese || | 6689 font->mac_scriptcode == smTradChinese || |
6761 font->mac_scriptcode == smSimpChinese || | 6690 font->mac_scriptcode == smSimpChinese || |
6762 font->mac_scriptcode == smKorean; | 6691 font->mac_scriptcode == smKorean; |
6877 void | 6806 void |
6878 mac_unload_font (dpyinfo, font) | 6807 mac_unload_font (dpyinfo, font) |
6879 struct mac_display_info *dpyinfo; | 6808 struct mac_display_info *dpyinfo; |
6880 XFontStruct *font; | 6809 XFontStruct *font; |
6881 { | 6810 { |
6882 xfree (font->fontname); | 6811 xfree (font->full_name); |
6883 if (font->per_char) | 6812 if (font->per_char) |
6884 xfree (font->per_char); | 6813 xfree (font->per_char); |
6885 xfree (font); | 6814 xfree (font); |
6886 } | 6815 } |
6887 | 6816 |
6917 SDATA (XCAR (tail))) | 6846 SDATA (XCAR (tail))) |
6918 || !strcmp (dpyinfo->font_table[i].full_name, | 6847 || !strcmp (dpyinfo->font_table[i].full_name, |
6919 SDATA (XCAR (tail))))) | 6848 SDATA (XCAR (tail))))) |
6920 return (dpyinfo->font_table + i); | 6849 return (dpyinfo->font_table + i); |
6921 } | 6850 } |
6851 else | |
6852 return NULL; | |
6922 | 6853 |
6923 /* Load the font and add it to the table. */ | 6854 /* Load the font and add it to the table. */ |
6924 { | 6855 { |
6925 char *full_name; | 6856 char *full_name; |
6926 struct MacFontStruct *font; | 6857 struct MacFontStruct *font; |
6927 struct font_info *fontp; | 6858 struct font_info *fontp; |
6928 unsigned long value; | 6859 unsigned long value; |
6929 int i; | 6860 int i; |
6930 | 6861 |
6931 /* If we have found fonts by x_list_font, load one of them. If | 6862 fontname = (char *) SDATA (XCAR (font_names)); |
6932 not, we still try to load a font by the name given as FONTNAME | |
6933 because XListFonts (called in x_list_font) of some X server has | |
6934 a bug of not finding a font even if the font surely exists and | |
6935 is loadable by XLoadQueryFont. */ | |
6936 if (size > 0 && !NILP (font_names)) | |
6937 fontname = (char *) SDATA (XCAR (font_names)); | |
6938 | 6863 |
6939 BLOCK_INPUT; | 6864 BLOCK_INPUT; |
6940 font = (MacFontStruct *) XLoadQueryFont (FRAME_MAC_DISPLAY (f), fontname); | 6865 font = (MacFontStruct *) XLoadQueryFont (FRAME_MAC_DISPLAY (f), fontname); |
6941 UNBLOCK_INPUT; | 6866 UNBLOCK_INPUT; |
6942 if (!font) | 6867 if (!font) |
6965 /* Now fill in the slots of *FONTP. */ | 6890 /* Now fill in the slots of *FONTP. */ |
6966 BLOCK_INPUT; | 6891 BLOCK_INPUT; |
6967 bzero (fontp, sizeof (*fontp)); | 6892 bzero (fontp, sizeof (*fontp)); |
6968 fontp->font = font; | 6893 fontp->font = font; |
6969 fontp->font_idx = i; | 6894 fontp->font_idx = i; |
6970 fontp->name = (char *) xmalloc (strlen (font->fontname) + 1); | 6895 fontp->name = (char *) xmalloc (strlen (fontname) + 1); |
6971 bcopy (font->fontname, fontp->name, strlen (font->fontname) + 1); | 6896 bcopy (fontname, fontp->name, strlen (fontname) + 1); |
6972 | 6897 |
6973 if (font->min_bounds.width == font->max_bounds.width) | 6898 if (font->min_bounds.width == font->max_bounds.width) |
6974 { | 6899 { |
6975 /* Fixed width font. */ | 6900 /* Fixed width font. */ |
6976 fontp->average_width = fontp->space_width = font->min_bounds.width; | 6901 fontp->average_width = fontp->space_width = font->min_bounds.width; |
6997 } | 6922 } |
6998 else | 6923 else |
6999 fontp->average_width = FONT_WIDTH (font); | 6924 fontp->average_width = FONT_WIDTH (font); |
7000 } | 6925 } |
7001 | 6926 |
7002 fontp->full_name = fontp->name; | 6927 fontp->full_name = (char *) xmalloc (strlen (font->full_name) + 1); |
6928 bcopy (font->full_name, fontp->full_name, strlen (font->full_name) + 1); | |
7003 | 6929 |
7004 fontp->size = font->max_bounds.width; | 6930 fontp->size = font->max_bounds.width; |
7005 fontp->height = FONT_HEIGHT (font); | 6931 fontp->height = FONT_HEIGHT (font); |
7006 { | 6932 { |
7007 /* For some font, ascent and descent in max_bounds field is | 6933 /* For some font, ascent and descent in max_bounds field is |
9808 last_mouse_press_frame = Qnil; | 9734 last_mouse_press_frame = Qnil; |
9809 | 9735 |
9810 Qmac_ready_for_drag_n_drop = intern ("mac-ready-for-drag-n-drop"); | 9736 Qmac_ready_for_drag_n_drop = intern ("mac-ready-for-drag-n-drop"); |
9811 staticpro (&Qmac_ready_for_drag_n_drop); | 9737 staticpro (&Qmac_ready_for_drag_n_drop); |
9812 | 9738 |
9813 Qbig5 = intern ("big5"); | |
9814 staticpro (&Qbig5); | |
9815 | |
9816 Qcn_gb = intern ("cn-gb"); | |
9817 staticpro (&Qcn_gb); | |
9818 | |
9819 Qsjis = intern ("sjis"); | |
9820 staticpro (&Qsjis); | |
9821 | |
9822 Qeuc_kr = intern ("euc-kr"); | |
9823 staticpro (&Qeuc_kr); | |
9824 | |
9825 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars, | 9739 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars, |
9826 doc: /* If not nil, Emacs uses toolkit scroll bars. */); | 9740 doc: /* If not nil, Emacs uses toolkit scroll bars. */); |
9827 Vx_toolkit_scroll_bars = Qt; | 9741 Vx_toolkit_scroll_bars = Qt; |
9828 | 9742 |
9829 DEFVAR_BOOL ("x-use-underline-position-properties", | 9743 DEFVAR_BOOL ("x-use-underline-position-properties", |
9886 DEFVAR_LISP ("mac-allow-anti-aliasing", &Vmac_use_core_graphics, | 9800 DEFVAR_LISP ("mac-allow-anti-aliasing", &Vmac_use_core_graphics, |
9887 doc: /* If non-nil, allow anti-aliasing. | 9801 doc: /* If non-nil, allow anti-aliasing. |
9888 The text will be rendered using Core Graphics text rendering which | 9802 The text will be rendered using Core Graphics text rendering which |
9889 may anti-alias the text. */); | 9803 may anti-alias the text. */); |
9890 Vmac_use_core_graphics = Qnil; | 9804 Vmac_use_core_graphics = Qnil; |
9805 | |
9806 /* Register an entry for `mac-roman' so that it can be used when | |
9807 creating the terminal frame on Mac OS 9 before loading | |
9808 term/mac-win.elc. */ | |
9809 DEFVAR_LISP ("mac-charset-info-alist", &Vmac_charset_info_alist, | |
9810 doc: /* Alist linking Emacs character sets to Mac text encoding and Emacs coding system. | |
9811 Each entry should be of the form: | |
9812 | |
9813 (CHARSET-NAME TEXT-ENCODING CODING-SYSTEM) | |
9814 | |
9815 where CHARSET-NAME is a string used in font names to identify the | |
9816 charset, TEXT-ENCODING is a TextEncodingBase value, and CODING_SYSTEM | |
9817 is a coding system corresponding to TEXT-ENCODING. */); | |
9818 Vmac_charset_info_alist = | |
9819 Fcons (list3 (build_string ("mac-roman"), | |
9820 make_number (smRoman), Qnil), Qnil); | |
9891 } | 9821 } |
9892 | 9822 |
9893 /* arch-tag: f2259165-4454-4c04-a029-a133c8af7b5b | 9823 /* arch-tag: f2259165-4454-4c04-a029-a133c8af7b5b |
9894 (do not change this comment) */ | 9824 (do not change this comment) */ |