Mercurial > emacs
comparison src/w32fns.c @ 96385:01647003e227
* w32fns.c (x_to_w32_font, w32_to_x_font, x_to_w32_weight)
(w32_to_x_weight, w32_to_all_x_charsets): Remove obsolete functions.
(w32_to_x_charset, x_to_w32_charset)
(Qw32_charset_ansi, Qw32_charset_symbol, Qw32_charset_default)
(Qw32_charset_shiftjis, Qw32_charset_hangeul, Qw32_charset_johab)
(Qw32_charset_chinesebig5, Qw32_charset_gb2312, Qw32_charset_oem)
(Qw32_charset_easteurope, Qw32_charset_turkish, Qw32_charset_baltic)
(Qw32_charset_russian, Qw32_charset_arabic, Qw32_charset_greek)
(Qw32_charset_hebrew, Qw32_charset_vietnamese, Qw32_charset_thai)
(Qw32_charset_mac, Vw32_charset_info_alist): Move to w32font.c.
(Qw32_charset_unicode): Remove.
(syms_of_w32fns): Update for above changes.
* w32font.c (w32_to_x_charset, x_to_w32_charset)
(Qw32_charset_ansi, Qw32_charset_symbol, Qw32_charset_default)
(Qw32_charset_shiftjis, Qw32_charset_hangeul, Qw32_charset_johab)
(Qw32_charset_chinesebig5, Qw32_charset_gb2312, Qw32_charset_oem)
(Qw32_charset_easteurope, Qw32_charset_turkish, Qw32_charset_baltic)
(Qw32_charset_russian, Qw32_charset_arabic, Qw32_charset_greek)
(Qw32_charset_hebrew, Qw32_charset_vietnamese, Qw32_charset_thai)
(Qw32_charset_mac, Vw32_charset_info_alist): Move from w32fns.c.
(syms_of_w32font): Update for above changes.
* w32-fns.el (top-level): Unconditionally define all charsets.
author | Jason Rumney <jasonr@gnu.org> |
---|---|
date | Fri, 27 Jun 2008 22:33:12 +0000 |
parents | c3309dba6542 |
children | 4b6d1b55f59c |
comparison
equal
deleted
inserted
replaced
96384:59d141ae8c74 | 96385:01647003e227 |
---|---|
189 | 189 |
190 /* A flag to control whether we should only repaint if GetUpdateRect | 190 /* A flag to control whether we should only repaint if GetUpdateRect |
191 indicates there is an update region. */ | 191 indicates there is an update region. */ |
192 static int w32_strict_painting; | 192 static int w32_strict_painting; |
193 | 193 |
194 /* Associative list linking character set strings to Windows codepages. */ | |
195 static Lisp_Object Vw32_charset_info_alist; | |
196 | |
197 /* VIETNAMESE_CHARSET is not defined in some versions of MSVC. */ | |
198 #ifndef VIETNAMESE_CHARSET | |
199 #define VIETNAMESE_CHARSET 163 | |
200 #endif | |
201 | |
202 Lisp_Object Qnone; | 194 Lisp_Object Qnone; |
203 Lisp_Object Qsuppress_icon; | 195 Lisp_Object Qsuppress_icon; |
204 Lisp_Object Qundefined_color; | 196 Lisp_Object Qundefined_color; |
205 Lisp_Object Qcancel_timer; | 197 Lisp_Object Qcancel_timer; |
206 Lisp_Object Qfont_param; | 198 Lisp_Object Qfont_param; |
210 Lisp_Object Qalt; | 202 Lisp_Object Qalt; |
211 Lisp_Object Qctrl; | 203 Lisp_Object Qctrl; |
212 Lisp_Object Qcontrol; | 204 Lisp_Object Qcontrol; |
213 Lisp_Object Qshift; | 205 Lisp_Object Qshift; |
214 | 206 |
215 Lisp_Object Qw32_charset_ansi; | |
216 Lisp_Object Qw32_charset_default; | |
217 Lisp_Object Qw32_charset_symbol; | |
218 Lisp_Object Qw32_charset_shiftjis; | |
219 Lisp_Object Qw32_charset_hangeul; | |
220 Lisp_Object Qw32_charset_gb2312; | |
221 Lisp_Object Qw32_charset_chinesebig5; | |
222 Lisp_Object Qw32_charset_oem; | |
223 | |
224 #ifndef JOHAB_CHARSET | |
225 #define JOHAB_CHARSET 130 | |
226 #endif | |
227 #ifdef JOHAB_CHARSET | |
228 Lisp_Object Qw32_charset_easteurope; | |
229 Lisp_Object Qw32_charset_turkish; | |
230 Lisp_Object Qw32_charset_baltic; | |
231 Lisp_Object Qw32_charset_russian; | |
232 Lisp_Object Qw32_charset_arabic; | |
233 Lisp_Object Qw32_charset_greek; | |
234 Lisp_Object Qw32_charset_hebrew; | |
235 Lisp_Object Qw32_charset_vietnamese; | |
236 Lisp_Object Qw32_charset_thai; | |
237 Lisp_Object Qw32_charset_johab; | |
238 Lisp_Object Qw32_charset_mac; | |
239 #endif | |
240 | |
241 #ifdef UNICODE_CHARSET | |
242 Lisp_Object Qw32_charset_unicode; | |
243 #endif | |
244 | 207 |
245 /* The ANSI codepage. */ | 208 /* The ANSI codepage. */ |
246 int w32_ansi_code_page; | 209 int w32_ansi_code_page; |
247 | 210 |
248 /* Prefix for system colors. */ | 211 /* Prefix for system colors. */ |
4642 x_focus_on_frame (check_x_frame (frame)); | 4605 x_focus_on_frame (check_x_frame (frame)); |
4643 return Qnil; | 4606 return Qnil; |
4644 } | 4607 } |
4645 | 4608 |
4646 | 4609 |
4647 /* The font conversion stuff between x and w32 */ | |
4648 | |
4649 /* X font string is as follows (from faces.el) | |
4650 * (let ((- "[-?]") | |
4651 * (foundry "[^-]+") | |
4652 * (family "[^-]+") | |
4653 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1 | |
4654 * (weight\? "\\([^-]*\\)") ; 1 | |
4655 * (slant "\\([ior]\\)") ; 2 | |
4656 * (slant\? "\\([^-]?\\)") ; 2 | |
4657 * (swidth "\\([^-]*\\)") ; 3 | |
4658 * (adstyle "[^-]*") ; 4 | |
4659 * (pixelsize "[0-9]+") | |
4660 * (pointsize "[0-9][0-9]+") | |
4661 * (resx "[0-9][0-9]+") | |
4662 * (resy "[0-9][0-9]+") | |
4663 * (spacing "[cmp?*]") | |
4664 * (avgwidth "[0-9]+") | |
4665 * (registry "[^-]+") | |
4666 * (encoding "[^-]+") | |
4667 * ) | |
4668 */ | |
4669 | |
4670 static LONG | |
4671 x_to_w32_weight (lpw) | |
4672 char * lpw; | |
4673 { | |
4674 if (!lpw) return (FW_DONTCARE); | |
4675 | |
4676 if (xstrcasecmp (lpw, "heavy") == 0) return FW_HEAVY; | |
4677 else if (xstrcasecmp (lpw, "extrabold") == 0) return FW_EXTRABOLD; | |
4678 else if (xstrcasecmp (lpw, "bold") == 0) return FW_BOLD; | |
4679 else if (xstrcasecmp (lpw, "demibold") == 0) return FW_SEMIBOLD; | |
4680 else if (xstrcasecmp (lpw, "semibold") == 0) return FW_SEMIBOLD; | |
4681 else if (xstrcasecmp (lpw, "medium") == 0) return FW_MEDIUM; | |
4682 else if (xstrcasecmp (lpw, "normal") == 0) return FW_NORMAL; | |
4683 else if (xstrcasecmp (lpw, "light") == 0) return FW_LIGHT; | |
4684 else if (xstrcasecmp (lpw, "extralight") == 0) return FW_EXTRALIGHT; | |
4685 else if (xstrcasecmp (lpw, "thin") == 0) return FW_THIN; | |
4686 else | |
4687 return FW_DONTCARE; | |
4688 } | |
4689 | |
4690 | |
4691 static char * | |
4692 w32_to_x_weight (fnweight) | |
4693 int fnweight; | |
4694 { | |
4695 if (fnweight >= FW_HEAVY) return "heavy"; | |
4696 if (fnweight >= FW_EXTRABOLD) return "extrabold"; | |
4697 if (fnweight >= FW_BOLD) return "bold"; | |
4698 if (fnweight >= FW_SEMIBOLD) return "demibold"; | |
4699 if (fnweight >= FW_MEDIUM) return "medium"; | |
4700 if (fnweight >= FW_NORMAL) return "normal"; | |
4701 if (fnweight >= FW_LIGHT) return "light"; | |
4702 if (fnweight >= FW_EXTRALIGHT) return "extralight"; | |
4703 if (fnweight >= FW_THIN) return "thin"; | |
4704 else | |
4705 return "*"; | |
4706 } | |
4707 | |
4708 LONG | |
4709 x_to_w32_charset (lpcs) | |
4710 char * lpcs; | |
4711 { | |
4712 Lisp_Object this_entry, w32_charset; | |
4713 char *charset; | |
4714 int len = strlen (lpcs); | |
4715 | |
4716 /* Support "*-#nnn" format for unknown charsets. */ | |
4717 if (strncmp (lpcs, "*-#", 3) == 0) | |
4718 return atoi (lpcs + 3); | |
4719 | |
4720 /* All Windows fonts qualify as unicode. */ | |
4721 if (!strncmp (lpcs, "iso10646", 8)) | |
4722 return DEFAULT_CHARSET; | |
4723 | |
4724 /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */ | |
4725 charset = alloca (len + 1); | |
4726 strcpy (charset, lpcs); | |
4727 lpcs = strchr (charset, '*'); | |
4728 if (lpcs) | |
4729 *lpcs = '\0'; | |
4730 | |
4731 /* Look through w32-charset-info-alist for the character set. | |
4732 Format of each entry is | |
4733 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)). | |
4734 */ | |
4735 this_entry = Fassoc (build_string (charset), Vw32_charset_info_alist); | |
4736 | |
4737 if (NILP (this_entry)) | |
4738 { | |
4739 /* At startup, we want iso8859-1 fonts to come up properly. */ | |
4740 if (xstrcasecmp (charset, "iso8859-1") == 0) | |
4741 return ANSI_CHARSET; | |
4742 else | |
4743 return DEFAULT_CHARSET; | |
4744 } | |
4745 | |
4746 w32_charset = Fcar (Fcdr (this_entry)); | |
4747 | |
4748 /* Translate Lisp symbol to number. */ | |
4749 if (EQ (w32_charset, Qw32_charset_ansi)) | |
4750 return ANSI_CHARSET; | |
4751 if (EQ (w32_charset, Qw32_charset_symbol)) | |
4752 return SYMBOL_CHARSET; | |
4753 if (EQ (w32_charset, Qw32_charset_shiftjis)) | |
4754 return SHIFTJIS_CHARSET; | |
4755 if (EQ (w32_charset, Qw32_charset_hangeul)) | |
4756 return HANGEUL_CHARSET; | |
4757 if (EQ (w32_charset, Qw32_charset_chinesebig5)) | |
4758 return CHINESEBIG5_CHARSET; | |
4759 if (EQ (w32_charset, Qw32_charset_gb2312)) | |
4760 return GB2312_CHARSET; | |
4761 if (EQ (w32_charset, Qw32_charset_oem)) | |
4762 return OEM_CHARSET; | |
4763 #ifdef JOHAB_CHARSET | |
4764 if (EQ (w32_charset, Qw32_charset_johab)) | |
4765 return JOHAB_CHARSET; | |
4766 if (EQ (w32_charset, Qw32_charset_easteurope)) | |
4767 return EASTEUROPE_CHARSET; | |
4768 if (EQ (w32_charset, Qw32_charset_turkish)) | |
4769 return TURKISH_CHARSET; | |
4770 if (EQ (w32_charset, Qw32_charset_baltic)) | |
4771 return BALTIC_CHARSET; | |
4772 if (EQ (w32_charset, Qw32_charset_russian)) | |
4773 return RUSSIAN_CHARSET; | |
4774 if (EQ (w32_charset, Qw32_charset_arabic)) | |
4775 return ARABIC_CHARSET; | |
4776 if (EQ (w32_charset, Qw32_charset_greek)) | |
4777 return GREEK_CHARSET; | |
4778 if (EQ (w32_charset, Qw32_charset_hebrew)) | |
4779 return HEBREW_CHARSET; | |
4780 if (EQ (w32_charset, Qw32_charset_vietnamese)) | |
4781 return VIETNAMESE_CHARSET; | |
4782 if (EQ (w32_charset, Qw32_charset_thai)) | |
4783 return THAI_CHARSET; | |
4784 if (EQ (w32_charset, Qw32_charset_mac)) | |
4785 return MAC_CHARSET; | |
4786 #endif /* JOHAB_CHARSET */ | |
4787 #ifdef UNICODE_CHARSET | |
4788 if (EQ (w32_charset, Qw32_charset_unicode)) | |
4789 return UNICODE_CHARSET; | |
4790 #endif | |
4791 | |
4792 return DEFAULT_CHARSET; | |
4793 } | |
4794 | |
4795 | |
4796 char * | |
4797 w32_to_x_charset (fncharset, matching) | |
4798 int fncharset; | |
4799 char *matching; | |
4800 { | |
4801 static char buf[32]; | |
4802 Lisp_Object charset_type; | |
4803 int match_len = 0; | |
4804 | |
4805 if (matching) | |
4806 { | |
4807 /* If fully specified, accept it as it is. Otherwise use a | |
4808 substring match. */ | |
4809 char *wildcard = strchr (matching, '*'); | |
4810 if (wildcard) | |
4811 *wildcard = '\0'; | |
4812 else if (strchr (matching, '-')) | |
4813 return matching; | |
4814 | |
4815 match_len = strlen (matching); | |
4816 } | |
4817 | |
4818 switch (fncharset) | |
4819 { | |
4820 case ANSI_CHARSET: | |
4821 /* Handle startup case of w32-charset-info-alist not | |
4822 being set up yet. */ | |
4823 if (NILP (Vw32_charset_info_alist)) | |
4824 return "iso8859-1"; | |
4825 charset_type = Qw32_charset_ansi; | |
4826 break; | |
4827 case DEFAULT_CHARSET: | |
4828 charset_type = Qw32_charset_default; | |
4829 break; | |
4830 case SYMBOL_CHARSET: | |
4831 charset_type = Qw32_charset_symbol; | |
4832 break; | |
4833 case SHIFTJIS_CHARSET: | |
4834 charset_type = Qw32_charset_shiftjis; | |
4835 break; | |
4836 case HANGEUL_CHARSET: | |
4837 charset_type = Qw32_charset_hangeul; | |
4838 break; | |
4839 case GB2312_CHARSET: | |
4840 charset_type = Qw32_charset_gb2312; | |
4841 break; | |
4842 case CHINESEBIG5_CHARSET: | |
4843 charset_type = Qw32_charset_chinesebig5; | |
4844 break; | |
4845 case OEM_CHARSET: | |
4846 charset_type = Qw32_charset_oem; | |
4847 break; | |
4848 | |
4849 /* More recent versions of Windows (95 and NT4.0) define more | |
4850 character sets. */ | |
4851 #ifdef EASTEUROPE_CHARSET | |
4852 case EASTEUROPE_CHARSET: | |
4853 charset_type = Qw32_charset_easteurope; | |
4854 break; | |
4855 case TURKISH_CHARSET: | |
4856 charset_type = Qw32_charset_turkish; | |
4857 break; | |
4858 case BALTIC_CHARSET: | |
4859 charset_type = Qw32_charset_baltic; | |
4860 break; | |
4861 case RUSSIAN_CHARSET: | |
4862 charset_type = Qw32_charset_russian; | |
4863 break; | |
4864 case ARABIC_CHARSET: | |
4865 charset_type = Qw32_charset_arabic; | |
4866 break; | |
4867 case GREEK_CHARSET: | |
4868 charset_type = Qw32_charset_greek; | |
4869 break; | |
4870 case HEBREW_CHARSET: | |
4871 charset_type = Qw32_charset_hebrew; | |
4872 break; | |
4873 case VIETNAMESE_CHARSET: | |
4874 charset_type = Qw32_charset_vietnamese; | |
4875 break; | |
4876 case THAI_CHARSET: | |
4877 charset_type = Qw32_charset_thai; | |
4878 break; | |
4879 case MAC_CHARSET: | |
4880 charset_type = Qw32_charset_mac; | |
4881 break; | |
4882 case JOHAB_CHARSET: | |
4883 charset_type = Qw32_charset_johab; | |
4884 break; | |
4885 #endif | |
4886 | |
4887 #ifdef UNICODE_CHARSET | |
4888 case UNICODE_CHARSET: | |
4889 charset_type = Qw32_charset_unicode; | |
4890 break; | |
4891 #endif | |
4892 default: | |
4893 /* Encode numerical value of unknown charset. */ | |
4894 sprintf (buf, "*-#%u", fncharset); | |
4895 return buf; | |
4896 } | |
4897 | |
4898 { | |
4899 Lisp_Object rest; | |
4900 char * best_match = NULL; | |
4901 int matching_found = 0; | |
4902 | |
4903 /* Look through w32-charset-info-alist for the character set. | |
4904 Prefer ISO codepages, and prefer lower numbers in the ISO | |
4905 range. Only return charsets for codepages which are installed. | |
4906 | |
4907 Format of each entry is | |
4908 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)). | |
4909 */ | |
4910 for (rest = Vw32_charset_info_alist; CONSP (rest); rest = XCDR (rest)) | |
4911 { | |
4912 char * x_charset; | |
4913 Lisp_Object w32_charset; | |
4914 Lisp_Object codepage; | |
4915 | |
4916 Lisp_Object this_entry = XCAR (rest); | |
4917 | |
4918 /* Skip invalid entries in alist. */ | |
4919 if (!CONSP (this_entry) || !STRINGP (XCAR (this_entry)) | |
4920 || !CONSP (XCDR (this_entry)) | |
4921 || !SYMBOLP (XCAR (XCDR (this_entry)))) | |
4922 continue; | |
4923 | |
4924 x_charset = SDATA (XCAR (this_entry)); | |
4925 w32_charset = XCAR (XCDR (this_entry)); | |
4926 codepage = XCDR (XCDR (this_entry)); | |
4927 | |
4928 /* Look for Same charset and a valid codepage (or non-int | |
4929 which means ignore). */ | |
4930 if (EQ (w32_charset, charset_type) | |
4931 && (!INTEGERP (codepage) || XINT (codepage) == CP_DEFAULT | |
4932 || IsValidCodePage (XINT (codepage)))) | |
4933 { | |
4934 /* If we don't have a match already, then this is the | |
4935 best. */ | |
4936 if (!best_match) | |
4937 { | |
4938 best_match = x_charset; | |
4939 if (matching && !strnicmp (x_charset, matching, match_len)) | |
4940 matching_found = 1; | |
4941 } | |
4942 /* If we already found a match for MATCHING, then | |
4943 only consider other matches. */ | |
4944 else if (matching_found | |
4945 && strnicmp (x_charset, matching, match_len)) | |
4946 continue; | |
4947 /* If this matches what we want, and the best so far doesn't, | |
4948 then this is better. */ | |
4949 else if (!matching_found && matching | |
4950 && !strnicmp (x_charset, matching, match_len)) | |
4951 { | |
4952 best_match = x_charset; | |
4953 matching_found = 1; | |
4954 } | |
4955 /* If this is fully specified, and the best so far isn't, | |
4956 then this is better. */ | |
4957 else if ((!strchr (best_match, '-') && strchr (x_charset, '-')) | |
4958 /* If this is an ISO codepage, and the best so far isn't, | |
4959 then this is better, but only if it fully specifies the | |
4960 encoding. */ | |
4961 || (strnicmp (best_match, "iso", 3) != 0 | |
4962 && strnicmp (x_charset, "iso", 3) == 0 | |
4963 && strchr (x_charset, '-'))) | |
4964 best_match = x_charset; | |
4965 /* If both are ISO8859 codepages, choose the one with the | |
4966 lowest number in the encoding field. */ | |
4967 else if (strnicmp (best_match, "iso8859-", 8) == 0 | |
4968 && strnicmp (x_charset, "iso8859-", 8) == 0) | |
4969 { | |
4970 int best_enc = atoi (best_match + 8); | |
4971 int this_enc = atoi (x_charset + 8); | |
4972 if (this_enc > 0 && this_enc < best_enc) | |
4973 best_match = x_charset; | |
4974 } | |
4975 } | |
4976 } | |
4977 | |
4978 /* If no match, encode the numeric value. */ | |
4979 if (!best_match) | |
4980 { | |
4981 sprintf (buf, "*-#%u", fncharset); | |
4982 return buf; | |
4983 } | |
4984 | |
4985 strncpy (buf, best_match, 31); | |
4986 /* If the charset is not fully specified, put -0 on the end. */ | |
4987 if (!strchr (best_match, '-')) | |
4988 { | |
4989 int pos = strlen (best_match); | |
4990 /* Charset specifiers shouldn't be very long. If it is a made | |
4991 up one, truncating it should not do any harm since it isn't | |
4992 recognized anyway. */ | |
4993 if (pos > 29) | |
4994 pos = 29; | |
4995 strcpy (buf + pos, "-0"); | |
4996 } | |
4997 buf[31] = '\0'; | |
4998 return buf; | |
4999 } | |
5000 } | |
5001 | |
5002 | |
5003 /* Return all the X charsets that map to a font. */ | |
5004 static Lisp_Object | |
5005 w32_to_all_x_charsets (fncharset) | |
5006 int fncharset; | |
5007 { | |
5008 static char buf[32]; | |
5009 Lisp_Object charset_type; | |
5010 Lisp_Object retval = Qnil; | |
5011 | |
5012 switch (fncharset) | |
5013 { | |
5014 case ANSI_CHARSET: | |
5015 /* Handle startup case of w32-charset-info-alist not | |
5016 being set up yet. */ | |
5017 if (NILP (Vw32_charset_info_alist)) | |
5018 return Fcons (build_string ("iso8859-1"), Qnil); | |
5019 | |
5020 charset_type = Qw32_charset_ansi; | |
5021 break; | |
5022 case DEFAULT_CHARSET: | |
5023 charset_type = Qw32_charset_default; | |
5024 break; | |
5025 case SYMBOL_CHARSET: | |
5026 charset_type = Qw32_charset_symbol; | |
5027 break; | |
5028 case SHIFTJIS_CHARSET: | |
5029 charset_type = Qw32_charset_shiftjis; | |
5030 break; | |
5031 case HANGEUL_CHARSET: | |
5032 charset_type = Qw32_charset_hangeul; | |
5033 break; | |
5034 case GB2312_CHARSET: | |
5035 charset_type = Qw32_charset_gb2312; | |
5036 break; | |
5037 case CHINESEBIG5_CHARSET: | |
5038 charset_type = Qw32_charset_chinesebig5; | |
5039 break; | |
5040 case OEM_CHARSET: | |
5041 charset_type = Qw32_charset_oem; | |
5042 break; | |
5043 | |
5044 /* More recent versions of Windows (95 and NT4.0) define more | |
5045 character sets. */ | |
5046 #ifdef EASTEUROPE_CHARSET | |
5047 case EASTEUROPE_CHARSET: | |
5048 charset_type = Qw32_charset_easteurope; | |
5049 break; | |
5050 case TURKISH_CHARSET: | |
5051 charset_type = Qw32_charset_turkish; | |
5052 break; | |
5053 case BALTIC_CHARSET: | |
5054 charset_type = Qw32_charset_baltic; | |
5055 break; | |
5056 case RUSSIAN_CHARSET: | |
5057 charset_type = Qw32_charset_russian; | |
5058 break; | |
5059 case ARABIC_CHARSET: | |
5060 charset_type = Qw32_charset_arabic; | |
5061 break; | |
5062 case GREEK_CHARSET: | |
5063 charset_type = Qw32_charset_greek; | |
5064 break; | |
5065 case HEBREW_CHARSET: | |
5066 charset_type = Qw32_charset_hebrew; | |
5067 break; | |
5068 case VIETNAMESE_CHARSET: | |
5069 charset_type = Qw32_charset_vietnamese; | |
5070 break; | |
5071 case THAI_CHARSET: | |
5072 charset_type = Qw32_charset_thai; | |
5073 break; | |
5074 case MAC_CHARSET: | |
5075 charset_type = Qw32_charset_mac; | |
5076 break; | |
5077 case JOHAB_CHARSET: | |
5078 charset_type = Qw32_charset_johab; | |
5079 break; | |
5080 #endif | |
5081 | |
5082 #ifdef UNICODE_CHARSET | |
5083 case UNICODE_CHARSET: | |
5084 charset_type = Qw32_charset_unicode; | |
5085 break; | |
5086 #endif | |
5087 default: | |
5088 /* Encode numerical value of unknown charset. */ | |
5089 sprintf (buf, "*-#%u", fncharset); | |
5090 return Fcons (build_string (buf), Qnil); | |
5091 } | |
5092 | |
5093 { | |
5094 Lisp_Object rest; | |
5095 /* Look through w32-charset-info-alist for the character set. | |
5096 Only return fully specified charsets for codepages which are | |
5097 installed. | |
5098 | |
5099 Format of each entry in Vw32_charset_info_alist is | |
5100 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)). | |
5101 */ | |
5102 for (rest = Vw32_charset_info_alist; CONSP (rest); rest = XCDR (rest)) | |
5103 { | |
5104 Lisp_Object x_charset; | |
5105 Lisp_Object w32_charset; | |
5106 Lisp_Object codepage; | |
5107 | |
5108 Lisp_Object this_entry = XCAR (rest); | |
5109 | |
5110 /* Skip invalid entries in alist. */ | |
5111 if (!CONSP (this_entry) || !STRINGP (XCAR (this_entry)) | |
5112 || !CONSP (XCDR (this_entry)) | |
5113 || !SYMBOLP (XCAR (XCDR (this_entry)))) | |
5114 continue; | |
5115 | |
5116 x_charset = XCAR (this_entry); | |
5117 w32_charset = XCAR (XCDR (this_entry)); | |
5118 codepage = XCDR (XCDR (this_entry)); | |
5119 | |
5120 if (!strchr (SDATA (x_charset), '-')) | |
5121 continue; | |
5122 | |
5123 /* Look for Same charset and a valid codepage (or non-int | |
5124 which means ignore). */ | |
5125 if (EQ (w32_charset, charset_type) | |
5126 && (!INTEGERP (codepage) || XINT (codepage) == CP_DEFAULT | |
5127 || IsValidCodePage (XINT (codepage)))) | |
5128 { | |
5129 retval = Fcons (x_charset, retval); | |
5130 } | |
5131 } | |
5132 | |
5133 /* If no match, encode the numeric value. */ | |
5134 if (NILP (retval)) | |
5135 { | |
5136 sprintf (buf, "*-#%u", fncharset); | |
5137 return Fcons (build_string (buf), Qnil); | |
5138 } | |
5139 | |
5140 return retval; | |
5141 } | |
5142 } | |
5143 | |
5144 static BOOL | |
5145 w32_to_x_font (lplogfont, lpxstr, len, specific_charset) | |
5146 LOGFONT * lplogfont; | |
5147 char * lpxstr; | |
5148 int len; | |
5149 char * specific_charset; | |
5150 { | |
5151 char* fonttype; | |
5152 char *fontname; | |
5153 char height_pixels[8]; | |
5154 char height_dpi[8]; | |
5155 char width_pixels[8]; | |
5156 char *fontname_dash; | |
5157 int display_resy = (int) one_w32_display_info.resy; | |
5158 int display_resx = (int) one_w32_display_info.resx; | |
5159 struct coding_system coding; | |
5160 | |
5161 if (!lpxstr) abort (); | |
5162 | |
5163 if (!lplogfont) | |
5164 return FALSE; | |
5165 | |
5166 if (lplogfont->lfOutPrecision == OUT_STRING_PRECIS) | |
5167 fonttype = "raster"; | |
5168 else if (lplogfont->lfOutPrecision == OUT_STROKE_PRECIS) | |
5169 fonttype = "outline"; | |
5170 else | |
5171 fonttype = "unknown"; | |
5172 | |
5173 setup_coding_system (Fcheck_coding_system (Vlocale_coding_system), | |
5174 &coding); | |
5175 coding.src_multibyte = 0; | |
5176 coding.dst_multibyte = 1; | |
5177 coding.mode |= CODING_MODE_LAST_BLOCK; | |
5178 /* We explicitely disable composition handling because selection | |
5179 data should not contain any composition sequence. */ | |
5180 coding.common_flags &= ~CODING_ANNOTATION_MASK; | |
5181 | |
5182 coding.dst_bytes = LF_FACESIZE * 2; | |
5183 coding.destination = (unsigned char *) xmalloc (coding.dst_bytes + 1); | |
5184 decode_coding_c_string (&coding, lplogfont->lfFaceName, | |
5185 strlen(lplogfont->lfFaceName), Qnil); | |
5186 fontname = coding.destination; | |
5187 | |
5188 *(fontname + coding.produced) = '\0'; | |
5189 | |
5190 /* Replace dashes with underscores so the dashes are not | |
5191 misinterpreted. */ | |
5192 fontname_dash = fontname; | |
5193 while (fontname_dash = strchr (fontname_dash, '-')) | |
5194 *fontname_dash = '_'; | |
5195 | |
5196 if (lplogfont->lfHeight) | |
5197 { | |
5198 sprintf (height_pixels, "%u", eabs (lplogfont->lfHeight)); | |
5199 sprintf (height_dpi, "%u", | |
5200 eabs (lplogfont->lfHeight) * 720 / display_resy); | |
5201 } | |
5202 else | |
5203 { | |
5204 strcpy (height_pixels, "*"); | |
5205 strcpy (height_dpi, "*"); | |
5206 } | |
5207 | |
5208 #if 0 /* Never put the width in the xlfd. It fails on fonts with | |
5209 double-width characters. */ | |
5210 if (lplogfont->lfWidth) | |
5211 sprintf (width_pixels, "%u", lplogfont->lfWidth * 10); | |
5212 else | |
5213 #endif | |
5214 strcpy (width_pixels, "*"); | |
5215 | |
5216 _snprintf (lpxstr, len - 1, | |
5217 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s", | |
5218 fonttype, /* foundry */ | |
5219 fontname, /* family */ | |
5220 w32_to_x_weight (lplogfont->lfWeight), /* weight */ | |
5221 lplogfont->lfItalic?'i':'r', /* slant */ | |
5222 /* setwidth name */ | |
5223 /* add style name */ | |
5224 height_pixels, /* pixel size */ | |
5225 height_dpi, /* point size */ | |
5226 display_resx, /* resx */ | |
5227 display_resy, /* resy */ | |
5228 ((lplogfont->lfPitchAndFamily & 0x3) == VARIABLE_PITCH) | |
5229 ? 'p' : 'c', /* spacing */ | |
5230 width_pixels, /* avg width */ | |
5231 w32_to_x_charset (lplogfont->lfCharSet, specific_charset) | |
5232 /* charset registry and encoding */ | |
5233 ); | |
5234 | |
5235 lpxstr[len - 1] = 0; /* just to be sure */ | |
5236 return (TRUE); | |
5237 } | |
5238 | |
5239 static BOOL | |
5240 x_to_w32_font (lpxstr, lplogfont) | |
5241 char * lpxstr; | |
5242 LOGFONT * lplogfont; | |
5243 { | |
5244 struct coding_system coding; | |
5245 | |
5246 if (!lplogfont) return (FALSE); | |
5247 | |
5248 memset (lplogfont, 0, sizeof (*lplogfont)); | |
5249 | |
5250 /* Set default value for each field. */ | |
5251 #if 1 | |
5252 lplogfont->lfOutPrecision = OUT_DEFAULT_PRECIS; | |
5253 lplogfont->lfClipPrecision = CLIP_DEFAULT_PRECIS; | |
5254 lplogfont->lfQuality = DEFAULT_QUALITY; | |
5255 #else | |
5256 /* go for maximum quality */ | |
5257 lplogfont->lfOutPrecision = OUT_STROKE_PRECIS; | |
5258 lplogfont->lfClipPrecision = CLIP_STROKE_PRECIS; | |
5259 lplogfont->lfQuality = PROOF_QUALITY; | |
5260 #endif | |
5261 | |
5262 lplogfont->lfCharSet = DEFAULT_CHARSET; | |
5263 lplogfont->lfWeight = FW_DONTCARE; | |
5264 lplogfont->lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; | |
5265 | |
5266 if (!lpxstr) | |
5267 return FALSE; | |
5268 | |
5269 /* Provide a simple escape mechanism for specifying Windows font names | |
5270 * directly -- if font spec does not beginning with '-', assume this | |
5271 * format: | |
5272 * "<font name>[:height in pixels[:width in pixels[:weight]]]" | |
5273 */ | |
5274 | |
5275 if (*lpxstr == '-') | |
5276 { | |
5277 int fields, tem; | |
5278 char name[50], weight[20], slant, pitch, pixels[10], height[10], | |
5279 width[10], resy[10], remainder[50]; | |
5280 char * encoding; | |
5281 int dpi = (int) one_w32_display_info.resy; | |
5282 | |
5283 fields = sscanf (lpxstr, | |
5284 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%49s", | |
5285 name, weight, &slant, pixels, height, resy, &pitch, width, remainder); | |
5286 if (fields == EOF) | |
5287 return (FALSE); | |
5288 | |
5289 /* In the general case when wildcards cover more than one field, | |
5290 we don't know which field is which, so don't fill any in. | |
5291 However, we need to cope with this particular form, which is | |
5292 generated by font_list_1 (invoked by try_font_list): | |
5293 "-raster-6x10-*-gb2312*-*" | |
5294 and make sure to correctly parse the charset field. */ | |
5295 if (fields == 3) | |
5296 { | |
5297 fields = sscanf (lpxstr, | |
5298 "-%*[^-]-%49[^-]-*-%49s", | |
5299 name, remainder); | |
5300 } | |
5301 else if (fields < 9) | |
5302 { | |
5303 fields = 0; | |
5304 remainder[0] = 0; | |
5305 } | |
5306 | |
5307 if (fields > 0 && name[0] != '*') | |
5308 { | |
5309 Lisp_Object string = build_string (name); | |
5310 setup_coding_system | |
5311 (Fcheck_coding_system (Vlocale_coding_system), &coding); | |
5312 coding.mode |= (CODING_MODE_SAFE_ENCODING | CODING_MODE_LAST_BLOCK); | |
5313 /* Disable composition/charset annotation. */ | |
5314 coding.common_flags &= ~CODING_ANNOTATION_MASK; | |
5315 coding.dst_bytes = SCHARS (string) * 2; | |
5316 | |
5317 coding.destination = (unsigned char *) xmalloc (coding.dst_bytes); | |
5318 encode_coding_object (&coding, string, 0, 0, | |
5319 SCHARS (string), SBYTES (string), Qnil); | |
5320 if (coding.produced >= LF_FACESIZE) | |
5321 coding.produced = LF_FACESIZE - 1; | |
5322 | |
5323 coding.destination[coding.produced] = '\0'; | |
5324 | |
5325 strcpy (lplogfont->lfFaceName, coding.destination); | |
5326 xfree (coding.destination); | |
5327 } | |
5328 else | |
5329 { | |
5330 lplogfont->lfFaceName[0] = '\0'; | |
5331 } | |
5332 | |
5333 fields--; | |
5334 | |
5335 lplogfont->lfWeight = x_to_w32_weight ((fields > 0 ? weight : "")); | |
5336 | |
5337 fields--; | |
5338 | |
5339 lplogfont->lfItalic = (fields > 0 && slant == 'i'); | |
5340 | |
5341 fields--; | |
5342 | |
5343 if (fields > 0 && pixels[0] != '*') | |
5344 lplogfont->lfHeight = atoi (pixels); | |
5345 | |
5346 fields--; | |
5347 fields--; | |
5348 if (fields > 0 && resy[0] != '*') | |
5349 { | |
5350 tem = atoi (resy); | |
5351 if (tem > 0) dpi = tem; | |
5352 } | |
5353 | |
5354 if (fields > -1 && lplogfont->lfHeight == 0 && height[0] != '*') | |
5355 lplogfont->lfHeight = atoi (height) * dpi / 720; | |
5356 | |
5357 if (fields > 0) | |
5358 { | |
5359 if (pitch == 'p') | |
5360 lplogfont->lfPitchAndFamily = VARIABLE_PITCH | FF_DONTCARE; | |
5361 else if (pitch == 'c') | |
5362 lplogfont->lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE; | |
5363 } | |
5364 | |
5365 fields--; | |
5366 | |
5367 if (fields > 0 && width[0] != '*') | |
5368 lplogfont->lfWidth = atoi (width) / 10; | |
5369 | |
5370 fields--; | |
5371 | |
5372 /* Strip the trailing '-' if present. (it shouldn't be, as it | |
5373 fails the test against xlfd-tight-regexp in fontset.el). */ | |
5374 { | |
5375 int len = strlen (remainder); | |
5376 if (len > 0 && remainder[len-1] == '-') | |
5377 remainder[len-1] = 0; | |
5378 } | |
5379 encoding = remainder; | |
5380 #if 0 | |
5381 if (strncmp (encoding, "*-", 2) == 0) | |
5382 encoding += 2; | |
5383 #endif | |
5384 lplogfont->lfCharSet = x_to_w32_charset (encoding); | |
5385 } | |
5386 else | |
5387 { | |
5388 int fields; | |
5389 char name[100], height[10], width[10], weight[20]; | |
5390 | |
5391 fields = sscanf (lpxstr, | |
5392 "%99[^:]:%9[^:]:%9[^:]:%19s", | |
5393 name, height, width, weight); | |
5394 | |
5395 if (fields == EOF) return (FALSE); | |
5396 | |
5397 if (fields > 0) | |
5398 { | |
5399 strncpy (lplogfont->lfFaceName, name, LF_FACESIZE); | |
5400 lplogfont->lfFaceName[LF_FACESIZE-1] = 0; | |
5401 } | |
5402 else | |
5403 { | |
5404 lplogfont->lfFaceName[0] = 0; | |
5405 } | |
5406 | |
5407 fields--; | |
5408 | |
5409 if (fields > 0) | |
5410 lplogfont->lfHeight = atoi (height); | |
5411 | |
5412 fields--; | |
5413 | |
5414 if (fields > 0) | |
5415 lplogfont->lfWidth = atoi (width); | |
5416 | |
5417 fields--; | |
5418 | |
5419 lplogfont->lfWeight = x_to_w32_weight ((fields > 0 ? weight : "")); | |
5420 } | |
5421 | |
5422 /* This makes TrueType fonts work better. */ | |
5423 lplogfont->lfHeight = - eabs (lplogfont->lfHeight); | |
5424 | |
5425 return (TRUE); | |
5426 } | |
5427 | |
5428 | |
5429 | |
5430 DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0, | 4610 DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0, |
5431 doc: /* Internal function called by `color-defined-p', which see. */) | 4611 doc: /* Internal function called by `color-defined-p', which see. */) |
5432 (color, frame) | 4612 (color, frame) |
5433 Lisp_Object color, frame; | 4613 Lisp_Object color, frame; |
5434 { | 4614 { |
7993 doc: /* Non-nil means use strict rules for repainting frames. | 7173 doc: /* Non-nil means use strict rules for repainting frames. |
7994 Set this to nil to get the old behavior for repainting; this should | 7174 Set this to nil to get the old behavior for repainting; this should |
7995 only be necessary if the default setting causes problems. */); | 7175 only be necessary if the default setting causes problems. */); |
7996 w32_strict_painting = 1; | 7176 w32_strict_painting = 1; |
7997 | 7177 |
7998 DEFVAR_LISP ("w32-charset-info-alist", | |
7999 &Vw32_charset_info_alist, | |
8000 doc: /* Alist linking Emacs character sets to Windows fonts and codepages. | |
8001 Each entry should be of the form: | |
8002 | |
8003 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)) | |
8004 | |
8005 where CHARSET_NAME is a string used in font names to identify the charset, | |
8006 WINDOWS_CHARSET is a symbol that can be one of: | |
8007 w32-charset-ansi, w32-charset-default, w32-charset-symbol, | |
8008 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312, | |
8009 w32-charset-chinesebig5, | |
8010 w32-charset-johab, w32-charset-hebrew, | |
8011 w32-charset-arabic, w32-charset-greek, w32-charset-turkish, | |
8012 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope, | |
8013 w32-charset-russian, w32-charset-mac, w32-charset-baltic, | |
8014 w32-charset-unicode, | |
8015 or w32-charset-oem. | |
8016 CODEPAGE should be an integer specifying the codepage that should be used | |
8017 to display the character set, t to do no translation and output as Unicode, | |
8018 or nil to do no translation and output as 8 bit (or multibyte on far-east | |
8019 versions of Windows) characters. */); | |
8020 Vw32_charset_info_alist = Qnil; | |
8021 | |
8022 DEFSYM (Qw32_charset_ansi, "w32-charset-ansi"); | |
8023 DEFSYM (Qw32_charset_symbol, "w32-charset-symbol"); | |
8024 DEFSYM (Qw32_charset_default, "w32-charset-default"); | |
8025 DEFSYM (Qw32_charset_shiftjis, "w32-charset-shiftjis"); | |
8026 DEFSYM (Qw32_charset_hangeul, "w32-charset-hangeul"); | |
8027 DEFSYM (Qw32_charset_chinesebig5, "w32-charset-chinesebig5"); | |
8028 DEFSYM (Qw32_charset_gb2312, "w32-charset-gb2312"); | |
8029 DEFSYM (Qw32_charset_oem, "w32-charset-oem"); | |
8030 | |
8031 #ifdef JOHAB_CHARSET | |
8032 { | |
8033 static int w32_extra_charsets_defined = 1; | |
8034 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined, | |
8035 doc: /* Internal variable. */); | |
8036 | |
8037 DEFSYM (Qw32_charset_johab, "w32-charset-johab"); | |
8038 DEFSYM (Qw32_charset_easteurope, "w32-charset-easteurope"); | |
8039 DEFSYM (Qw32_charset_turkish, "w32-charset-turkish"); | |
8040 DEFSYM (Qw32_charset_baltic, "w32-charset-baltic"); | |
8041 DEFSYM (Qw32_charset_russian, "w32-charset-russian"); | |
8042 DEFSYM (Qw32_charset_arabic, "w32-charset-arabic"); | |
8043 DEFSYM (Qw32_charset_greek, "w32-charset-greek"); | |
8044 DEFSYM (Qw32_charset_hebrew, "w32-charset-hebrew"); | |
8045 DEFSYM (Qw32_charset_vietnamese, "w32-charset-vietnamese"); | |
8046 DEFSYM (Qw32_charset_thai, "w32-charset-thai"); | |
8047 DEFSYM (Qw32_charset_mac, "w32-charset-mac"); | |
8048 } | |
8049 #endif | |
8050 | |
8051 #ifdef UNICODE_CHARSET | |
8052 { | |
8053 static int w32_unicode_charset_defined = 1; | |
8054 DEFVAR_BOOL ("w32-unicode-charset-defined", | |
8055 &w32_unicode_charset_defined, | |
8056 doc: /* Internal variable. */); | |
8057 DEFSYM (Qw32_charset_unicode, "w32-charset-unicode"); | |
8058 } | |
8059 #endif | |
8060 | |
8061 #if 0 /* TODO: Port to W32 */ | 7178 #if 0 /* TODO: Port to W32 */ |
8062 defsubr (&Sx_change_window_property); | 7179 defsubr (&Sx_change_window_property); |
8063 defsubr (&Sx_delete_window_property); | 7180 defsubr (&Sx_delete_window_property); |
8064 defsubr (&Sx_window_property); | 7181 defsubr (&Sx_window_property); |
8065 #endif | 7182 #endif |