# HG changeset patch # User Jason Rumney # Date 1214605992 0 # Node ID 01647003e22776217102c775bbfba34374d0b66f # Parent 59d141ae8c746334252880acc6e764f8d16a5fef * 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. diff -r 59d141ae8c74 -r 01647003e227 lisp/ChangeLog --- a/lisp/ChangeLog Fri Jun 27 21:12:46 2008 +0000 +++ b/lisp/ChangeLog Fri Jun 27 22:33:12 2008 +0000 @@ -1,3 +1,7 @@ +2008-06-27 Jason Rumney + + * w32-fns.el (top-level): Unconditionally define all charsets. + 2008-06-27 Alan Mackenzie * progmodes/cc-mode.el (c-mode-base-map): Don't bind C-M-[ae] to diff -r 59d141ae8c74 -r 01647003e227 lisp/w32-fns.el --- a/lisp/w32-fns.el Fri Jun 27 21:12:46 2008 +0000 +++ b/lisp/w32-fns.el Fri Jun 27 22:33:12 2008 +0000 @@ -376,26 +376,22 @@ (w32-add-charset-info "ms-symbol" 'w32-charset-symbol nil) (w32-add-charset-info "ms-oem" 'w32-charset-oem 437) (w32-add-charset-info "ms-oemlatin" 'w32-charset-oem 850) -(if (boundp 'w32-extra-charsets-defined) - (progn - (w32-add-charset-info "iso8859-2" 'w32-charset-easteurope 28592) - (w32-add-charset-info "iso8859-3" 'w32-charset-turkish 28593) - (w32-add-charset-info "iso8859-4" 'w32-charset-baltic 28594) - (w32-add-charset-info "iso8859-6" 'w32-charset-arabic 28596) - (w32-add-charset-info "iso8859-7" 'w32-charset-greek 28597) - (w32-add-charset-info "iso8859-8" 'w32-charset-hebrew 1255) - (w32-add-charset-info "iso8859-9" 'w32-charset-turkish 1254) - (w32-add-charset-info "iso8859-13" 'w32-charset-baltic 1257) - (w32-add-charset-info "koi8-r" 'w32-charset-russian 20866) - (w32-add-charset-info "iso8859-5" 'w32-charset-russian 28595) - (w32-add-charset-info "tis620" 'w32-charset-thai 874) - (w32-add-charset-info "windows-1258" 'w32-charset-vietnamese 1258) - (w32-add-charset-info "ksc5601.1992" 'w32-charset-johab 1361) - (w32-add-charset-info "mac-roman" 'w32-charset-mac 10000))) -(if (boundp 'w32-unicode-charset-defined) - (progn - (w32-add-charset-info "iso10646-1" 'w32-charset-unicode t)) - (w32-add-charset-info "iso10646-1" 'w32-charset-default t)) +(w32-add-charset-info "iso8859-2" 'w32-charset-easteurope 28592) +(w32-add-charset-info "iso8859-3" 'w32-charset-turkish 28593) +(w32-add-charset-info "iso8859-4" 'w32-charset-baltic 28594) +(w32-add-charset-info "iso8859-6" 'w32-charset-arabic 28596) +(w32-add-charset-info "iso8859-7" 'w32-charset-greek 28597) +(w32-add-charset-info "iso8859-8" 'w32-charset-hebrew 1255) +(w32-add-charset-info "iso8859-9" 'w32-charset-turkish 1254) +(w32-add-charset-info "iso8859-13" 'w32-charset-baltic 1257) +(w32-add-charset-info "koi8-r" 'w32-charset-russian 20866) +(w32-add-charset-info "iso8859-5" 'w32-charset-russian 28595) +(w32-add-charset-info "tis620" 'w32-charset-thai 874) +(w32-add-charset-info "windows-1258" 'w32-charset-vietnamese 1258) +(w32-add-charset-info "ksc5601.1992" 'w32-charset-johab 1361) +(w32-add-charset-info "mac-roman" 'w32-charset-mac 10000))) +(w32-add-charset-info "iso10646-1" 'w32-charset-default t)) + ;; ;; If unicode windows charset is not defined, use ansi fonts. ;; (w32-add-charset-info "iso10646-1" 'w32-charset-ansi t)) diff -r 59d141ae8c74 -r 01647003e227 src/ChangeLog --- a/src/ChangeLog Fri Jun 27 21:12:46 2008 +0000 +++ b/src/ChangeLog Fri Jun 27 22:33:12 2008 +0000 @@ -1,3 +1,28 @@ +2008-06-27 Jason Rumney + + * 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. + 2008-06-27 Dan Nicolaescu * s/usg5-4.h: Fix previous change: keep the correct branch of a @@ -20,12 +45,12 @@ * w32font.h (FONT_HANDLE, FONT_TEXTMETRIC): New macros. - * w32term.c (x_draw_glyph_string_foreground): + * w32term.c (x_draw_glyph_string_foreground) (x_draw_composite_glyph_string_foreground): Sync with xterm.c. Use FONT_HANDLE macro. (x_draw_glyph_string): Use FONT_TEXTMETRIC macro. - * w32uniscribe.c (uniscribe_otf_capability, uniscribe_shape): + * w32uniscribe.c (uniscribe_otf_capability, uniscribe_shape) (uniscribe_encode_char): Use FONT_HANDLE macro. * w32font.c (Fx_select_font): Use FONT_HANDLE macro. @@ -65,10 +90,10 @@ (w32font_open_internal): Remove compat code. Set new hfont member. (Fx_select_font): Use new hfont member. - * w32uniscribe.c (uniscribe_otf_capability, uniscribe_shape): + * w32uniscribe.c (uniscribe_otf_capability, uniscribe_shape) (uniscribe_encode_char): Use new hfont member. - * w32term.c (x_draw_glyph_string_foreground): + * w32term.c (x_draw_glyph_string_foreground) (x_draw_composite_glyph_string_foreground): Use new hfont member. (x_draw_glyph_string): Use metrics in w32font_info. diff -r 59d141ae8c74 -r 01647003e227 src/w32fns.c --- a/src/w32fns.c Fri Jun 27 21:12:46 2008 +0000 +++ b/src/w32fns.c Fri Jun 27 22:33:12 2008 +0000 @@ -191,14 +191,6 @@ indicates there is an update region. */ static int w32_strict_painting; -/* Associative list linking character set strings to Windows codepages. */ -static Lisp_Object Vw32_charset_info_alist; - -/* VIETNAMESE_CHARSET is not defined in some versions of MSVC. */ -#ifndef VIETNAMESE_CHARSET -#define VIETNAMESE_CHARSET 163 -#endif - Lisp_Object Qnone; Lisp_Object Qsuppress_icon; Lisp_Object Qundefined_color; @@ -212,35 +204,6 @@ Lisp_Object Qcontrol; Lisp_Object Qshift; -Lisp_Object Qw32_charset_ansi; -Lisp_Object Qw32_charset_default; -Lisp_Object Qw32_charset_symbol; -Lisp_Object Qw32_charset_shiftjis; -Lisp_Object Qw32_charset_hangeul; -Lisp_Object Qw32_charset_gb2312; -Lisp_Object Qw32_charset_chinesebig5; -Lisp_Object Qw32_charset_oem; - -#ifndef JOHAB_CHARSET -#define JOHAB_CHARSET 130 -#endif -#ifdef JOHAB_CHARSET -Lisp_Object Qw32_charset_easteurope; -Lisp_Object Qw32_charset_turkish; -Lisp_Object Qw32_charset_baltic; -Lisp_Object Qw32_charset_russian; -Lisp_Object Qw32_charset_arabic; -Lisp_Object Qw32_charset_greek; -Lisp_Object Qw32_charset_hebrew; -Lisp_Object Qw32_charset_vietnamese; -Lisp_Object Qw32_charset_thai; -Lisp_Object Qw32_charset_johab; -Lisp_Object Qw32_charset_mac; -#endif - -#ifdef UNICODE_CHARSET -Lisp_Object Qw32_charset_unicode; -#endif /* The ANSI codepage. */ int w32_ansi_code_page; @@ -4644,789 +4607,6 @@ } -/* The font conversion stuff between x and w32 */ - -/* X font string is as follows (from faces.el) - * (let ((- "[-?]") - * (foundry "[^-]+") - * (family "[^-]+") - * (weight "\\(bold\\|demibold\\|medium\\)") ; 1 - * (weight\? "\\([^-]*\\)") ; 1 - * (slant "\\([ior]\\)") ; 2 - * (slant\? "\\([^-]?\\)") ; 2 - * (swidth "\\([^-]*\\)") ; 3 - * (adstyle "[^-]*") ; 4 - * (pixelsize "[0-9]+") - * (pointsize "[0-9][0-9]+") - * (resx "[0-9][0-9]+") - * (resy "[0-9][0-9]+") - * (spacing "[cmp?*]") - * (avgwidth "[0-9]+") - * (registry "[^-]+") - * (encoding "[^-]+") - * ) - */ - -static LONG -x_to_w32_weight (lpw) - char * lpw; -{ - if (!lpw) return (FW_DONTCARE); - - if (xstrcasecmp (lpw, "heavy") == 0) return FW_HEAVY; - else if (xstrcasecmp (lpw, "extrabold") == 0) return FW_EXTRABOLD; - else if (xstrcasecmp (lpw, "bold") == 0) return FW_BOLD; - else if (xstrcasecmp (lpw, "demibold") == 0) return FW_SEMIBOLD; - else if (xstrcasecmp (lpw, "semibold") == 0) return FW_SEMIBOLD; - else if (xstrcasecmp (lpw, "medium") == 0) return FW_MEDIUM; - else if (xstrcasecmp (lpw, "normal") == 0) return FW_NORMAL; - else if (xstrcasecmp (lpw, "light") == 0) return FW_LIGHT; - else if (xstrcasecmp (lpw, "extralight") == 0) return FW_EXTRALIGHT; - else if (xstrcasecmp (lpw, "thin") == 0) return FW_THIN; - else - return FW_DONTCARE; -} - - -static char * -w32_to_x_weight (fnweight) - int fnweight; -{ - if (fnweight >= FW_HEAVY) return "heavy"; - if (fnweight >= FW_EXTRABOLD) return "extrabold"; - if (fnweight >= FW_BOLD) return "bold"; - if (fnweight >= FW_SEMIBOLD) return "demibold"; - if (fnweight >= FW_MEDIUM) return "medium"; - if (fnweight >= FW_NORMAL) return "normal"; - if (fnweight >= FW_LIGHT) return "light"; - if (fnweight >= FW_EXTRALIGHT) return "extralight"; - if (fnweight >= FW_THIN) return "thin"; - else - return "*"; -} - -LONG -x_to_w32_charset (lpcs) - char * lpcs; -{ - Lisp_Object this_entry, w32_charset; - char *charset; - int len = strlen (lpcs); - - /* Support "*-#nnn" format for unknown charsets. */ - if (strncmp (lpcs, "*-#", 3) == 0) - return atoi (lpcs + 3); - - /* All Windows fonts qualify as unicode. */ - if (!strncmp (lpcs, "iso10646", 8)) - return DEFAULT_CHARSET; - - /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */ - charset = alloca (len + 1); - strcpy (charset, lpcs); - lpcs = strchr (charset, '*'); - if (lpcs) - *lpcs = '\0'; - - /* Look through w32-charset-info-alist for the character set. - Format of each entry is - (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)). - */ - this_entry = Fassoc (build_string (charset), Vw32_charset_info_alist); - - if (NILP (this_entry)) - { - /* At startup, we want iso8859-1 fonts to come up properly. */ - if (xstrcasecmp (charset, "iso8859-1") == 0) - return ANSI_CHARSET; - else - return DEFAULT_CHARSET; - } - - w32_charset = Fcar (Fcdr (this_entry)); - - /* Translate Lisp symbol to number. */ - if (EQ (w32_charset, Qw32_charset_ansi)) - return ANSI_CHARSET; - if (EQ (w32_charset, Qw32_charset_symbol)) - return SYMBOL_CHARSET; - if (EQ (w32_charset, Qw32_charset_shiftjis)) - return SHIFTJIS_CHARSET; - if (EQ (w32_charset, Qw32_charset_hangeul)) - return HANGEUL_CHARSET; - if (EQ (w32_charset, Qw32_charset_chinesebig5)) - return CHINESEBIG5_CHARSET; - if (EQ (w32_charset, Qw32_charset_gb2312)) - return GB2312_CHARSET; - if (EQ (w32_charset, Qw32_charset_oem)) - return OEM_CHARSET; -#ifdef JOHAB_CHARSET - if (EQ (w32_charset, Qw32_charset_johab)) - return JOHAB_CHARSET; - if (EQ (w32_charset, Qw32_charset_easteurope)) - return EASTEUROPE_CHARSET; - if (EQ (w32_charset, Qw32_charset_turkish)) - return TURKISH_CHARSET; - if (EQ (w32_charset, Qw32_charset_baltic)) - return BALTIC_CHARSET; - if (EQ (w32_charset, Qw32_charset_russian)) - return RUSSIAN_CHARSET; - if (EQ (w32_charset, Qw32_charset_arabic)) - return ARABIC_CHARSET; - if (EQ (w32_charset, Qw32_charset_greek)) - return GREEK_CHARSET; - if (EQ (w32_charset, Qw32_charset_hebrew)) - return HEBREW_CHARSET; - if (EQ (w32_charset, Qw32_charset_vietnamese)) - return VIETNAMESE_CHARSET; - if (EQ (w32_charset, Qw32_charset_thai)) - return THAI_CHARSET; - if (EQ (w32_charset, Qw32_charset_mac)) - return MAC_CHARSET; -#endif /* JOHAB_CHARSET */ -#ifdef UNICODE_CHARSET - if (EQ (w32_charset, Qw32_charset_unicode)) - return UNICODE_CHARSET; -#endif - - return DEFAULT_CHARSET; -} - - -char * -w32_to_x_charset (fncharset, matching) - int fncharset; - char *matching; -{ - static char buf[32]; - Lisp_Object charset_type; - int match_len = 0; - - if (matching) - { - /* If fully specified, accept it as it is. Otherwise use a - substring match. */ - char *wildcard = strchr (matching, '*'); - if (wildcard) - *wildcard = '\0'; - else if (strchr (matching, '-')) - return matching; - - match_len = strlen (matching); - } - - switch (fncharset) - { - case ANSI_CHARSET: - /* Handle startup case of w32-charset-info-alist not - being set up yet. */ - if (NILP (Vw32_charset_info_alist)) - return "iso8859-1"; - charset_type = Qw32_charset_ansi; - break; - case DEFAULT_CHARSET: - charset_type = Qw32_charset_default; - break; - case SYMBOL_CHARSET: - charset_type = Qw32_charset_symbol; - break; - case SHIFTJIS_CHARSET: - charset_type = Qw32_charset_shiftjis; - break; - case HANGEUL_CHARSET: - charset_type = Qw32_charset_hangeul; - break; - case GB2312_CHARSET: - charset_type = Qw32_charset_gb2312; - break; - case CHINESEBIG5_CHARSET: - charset_type = Qw32_charset_chinesebig5; - break; - case OEM_CHARSET: - charset_type = Qw32_charset_oem; - break; - - /* More recent versions of Windows (95 and NT4.0) define more - character sets. */ -#ifdef EASTEUROPE_CHARSET - case EASTEUROPE_CHARSET: - charset_type = Qw32_charset_easteurope; - break; - case TURKISH_CHARSET: - charset_type = Qw32_charset_turkish; - break; - case BALTIC_CHARSET: - charset_type = Qw32_charset_baltic; - break; - case RUSSIAN_CHARSET: - charset_type = Qw32_charset_russian; - break; - case ARABIC_CHARSET: - charset_type = Qw32_charset_arabic; - break; - case GREEK_CHARSET: - charset_type = Qw32_charset_greek; - break; - case HEBREW_CHARSET: - charset_type = Qw32_charset_hebrew; - break; - case VIETNAMESE_CHARSET: - charset_type = Qw32_charset_vietnamese; - break; - case THAI_CHARSET: - charset_type = Qw32_charset_thai; - break; - case MAC_CHARSET: - charset_type = Qw32_charset_mac; - break; - case JOHAB_CHARSET: - charset_type = Qw32_charset_johab; - break; -#endif - -#ifdef UNICODE_CHARSET - case UNICODE_CHARSET: - charset_type = Qw32_charset_unicode; - break; -#endif - default: - /* Encode numerical value of unknown charset. */ - sprintf (buf, "*-#%u", fncharset); - return buf; - } - - { - Lisp_Object rest; - char * best_match = NULL; - int matching_found = 0; - - /* Look through w32-charset-info-alist for the character set. - Prefer ISO codepages, and prefer lower numbers in the ISO - range. Only return charsets for codepages which are installed. - - Format of each entry is - (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)). - */ - for (rest = Vw32_charset_info_alist; CONSP (rest); rest = XCDR (rest)) - { - char * x_charset; - Lisp_Object w32_charset; - Lisp_Object codepage; - - Lisp_Object this_entry = XCAR (rest); - - /* Skip invalid entries in alist. */ - if (!CONSP (this_entry) || !STRINGP (XCAR (this_entry)) - || !CONSP (XCDR (this_entry)) - || !SYMBOLP (XCAR (XCDR (this_entry)))) - continue; - - x_charset = SDATA (XCAR (this_entry)); - w32_charset = XCAR (XCDR (this_entry)); - codepage = XCDR (XCDR (this_entry)); - - /* Look for Same charset and a valid codepage (or non-int - which means ignore). */ - if (EQ (w32_charset, charset_type) - && (!INTEGERP (codepage) || XINT (codepage) == CP_DEFAULT - || IsValidCodePage (XINT (codepage)))) - { - /* If we don't have a match already, then this is the - best. */ - if (!best_match) - { - best_match = x_charset; - if (matching && !strnicmp (x_charset, matching, match_len)) - matching_found = 1; - } - /* If we already found a match for MATCHING, then - only consider other matches. */ - else if (matching_found - && strnicmp (x_charset, matching, match_len)) - continue; - /* If this matches what we want, and the best so far doesn't, - then this is better. */ - else if (!matching_found && matching - && !strnicmp (x_charset, matching, match_len)) - { - best_match = x_charset; - matching_found = 1; - } - /* If this is fully specified, and the best so far isn't, - then this is better. */ - else if ((!strchr (best_match, '-') && strchr (x_charset, '-')) - /* If this is an ISO codepage, and the best so far isn't, - then this is better, but only if it fully specifies the - encoding. */ - || (strnicmp (best_match, "iso", 3) != 0 - && strnicmp (x_charset, "iso", 3) == 0 - && strchr (x_charset, '-'))) - best_match = x_charset; - /* If both are ISO8859 codepages, choose the one with the - lowest number in the encoding field. */ - else if (strnicmp (best_match, "iso8859-", 8) == 0 - && strnicmp (x_charset, "iso8859-", 8) == 0) - { - int best_enc = atoi (best_match + 8); - int this_enc = atoi (x_charset + 8); - if (this_enc > 0 && this_enc < best_enc) - best_match = x_charset; - } - } - } - - /* If no match, encode the numeric value. */ - if (!best_match) - { - sprintf (buf, "*-#%u", fncharset); - return buf; - } - - strncpy (buf, best_match, 31); - /* If the charset is not fully specified, put -0 on the end. */ - if (!strchr (best_match, '-')) - { - int pos = strlen (best_match); - /* Charset specifiers shouldn't be very long. If it is a made - up one, truncating it should not do any harm since it isn't - recognized anyway. */ - if (pos > 29) - pos = 29; - strcpy (buf + pos, "-0"); - } - buf[31] = '\0'; - return buf; - } -} - - -/* Return all the X charsets that map to a font. */ -static Lisp_Object -w32_to_all_x_charsets (fncharset) - int fncharset; -{ - static char buf[32]; - Lisp_Object charset_type; - Lisp_Object retval = Qnil; - - switch (fncharset) - { - case ANSI_CHARSET: - /* Handle startup case of w32-charset-info-alist not - being set up yet. */ - if (NILP (Vw32_charset_info_alist)) - return Fcons (build_string ("iso8859-1"), Qnil); - - charset_type = Qw32_charset_ansi; - break; - case DEFAULT_CHARSET: - charset_type = Qw32_charset_default; - break; - case SYMBOL_CHARSET: - charset_type = Qw32_charset_symbol; - break; - case SHIFTJIS_CHARSET: - charset_type = Qw32_charset_shiftjis; - break; - case HANGEUL_CHARSET: - charset_type = Qw32_charset_hangeul; - break; - case GB2312_CHARSET: - charset_type = Qw32_charset_gb2312; - break; - case CHINESEBIG5_CHARSET: - charset_type = Qw32_charset_chinesebig5; - break; - case OEM_CHARSET: - charset_type = Qw32_charset_oem; - break; - - /* More recent versions of Windows (95 and NT4.0) define more - character sets. */ -#ifdef EASTEUROPE_CHARSET - case EASTEUROPE_CHARSET: - charset_type = Qw32_charset_easteurope; - break; - case TURKISH_CHARSET: - charset_type = Qw32_charset_turkish; - break; - case BALTIC_CHARSET: - charset_type = Qw32_charset_baltic; - break; - case RUSSIAN_CHARSET: - charset_type = Qw32_charset_russian; - break; - case ARABIC_CHARSET: - charset_type = Qw32_charset_arabic; - break; - case GREEK_CHARSET: - charset_type = Qw32_charset_greek; - break; - case HEBREW_CHARSET: - charset_type = Qw32_charset_hebrew; - break; - case VIETNAMESE_CHARSET: - charset_type = Qw32_charset_vietnamese; - break; - case THAI_CHARSET: - charset_type = Qw32_charset_thai; - break; - case MAC_CHARSET: - charset_type = Qw32_charset_mac; - break; - case JOHAB_CHARSET: - charset_type = Qw32_charset_johab; - break; -#endif - -#ifdef UNICODE_CHARSET - case UNICODE_CHARSET: - charset_type = Qw32_charset_unicode; - break; -#endif - default: - /* Encode numerical value of unknown charset. */ - sprintf (buf, "*-#%u", fncharset); - return Fcons (build_string (buf), Qnil); - } - - { - Lisp_Object rest; - /* Look through w32-charset-info-alist for the character set. - Only return fully specified charsets for codepages which are - installed. - - Format of each entry in Vw32_charset_info_alist is - (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)). - */ - for (rest = Vw32_charset_info_alist; CONSP (rest); rest = XCDR (rest)) - { - Lisp_Object x_charset; - Lisp_Object w32_charset; - Lisp_Object codepage; - - Lisp_Object this_entry = XCAR (rest); - - /* Skip invalid entries in alist. */ - if (!CONSP (this_entry) || !STRINGP (XCAR (this_entry)) - || !CONSP (XCDR (this_entry)) - || !SYMBOLP (XCAR (XCDR (this_entry)))) - continue; - - x_charset = XCAR (this_entry); - w32_charset = XCAR (XCDR (this_entry)); - codepage = XCDR (XCDR (this_entry)); - - if (!strchr (SDATA (x_charset), '-')) - continue; - - /* Look for Same charset and a valid codepage (or non-int - which means ignore). */ - if (EQ (w32_charset, charset_type) - && (!INTEGERP (codepage) || XINT (codepage) == CP_DEFAULT - || IsValidCodePage (XINT (codepage)))) - { - retval = Fcons (x_charset, retval); - } - } - - /* If no match, encode the numeric value. */ - if (NILP (retval)) - { - sprintf (buf, "*-#%u", fncharset); - return Fcons (build_string (buf), Qnil); - } - - return retval; - } -} - -static BOOL -w32_to_x_font (lplogfont, lpxstr, len, specific_charset) - LOGFONT * lplogfont; - char * lpxstr; - int len; - char * specific_charset; -{ - char* fonttype; - char *fontname; - char height_pixels[8]; - char height_dpi[8]; - char width_pixels[8]; - char *fontname_dash; - int display_resy = (int) one_w32_display_info.resy; - int display_resx = (int) one_w32_display_info.resx; - struct coding_system coding; - - if (!lpxstr) abort (); - - if (!lplogfont) - return FALSE; - - if (lplogfont->lfOutPrecision == OUT_STRING_PRECIS) - fonttype = "raster"; - else if (lplogfont->lfOutPrecision == OUT_STROKE_PRECIS) - fonttype = "outline"; - else - fonttype = "unknown"; - - setup_coding_system (Fcheck_coding_system (Vlocale_coding_system), - &coding); - coding.src_multibyte = 0; - coding.dst_multibyte = 1; - coding.mode |= CODING_MODE_LAST_BLOCK; - /* We explicitely disable composition handling because selection - data should not contain any composition sequence. */ - coding.common_flags &= ~CODING_ANNOTATION_MASK; - - coding.dst_bytes = LF_FACESIZE * 2; - coding.destination = (unsigned char *) xmalloc (coding.dst_bytes + 1); - decode_coding_c_string (&coding, lplogfont->lfFaceName, - strlen(lplogfont->lfFaceName), Qnil); - fontname = coding.destination; - - *(fontname + coding.produced) = '\0'; - - /* Replace dashes with underscores so the dashes are not - misinterpreted. */ - fontname_dash = fontname; - while (fontname_dash = strchr (fontname_dash, '-')) - *fontname_dash = '_'; - - if (lplogfont->lfHeight) - { - sprintf (height_pixels, "%u", eabs (lplogfont->lfHeight)); - sprintf (height_dpi, "%u", - eabs (lplogfont->lfHeight) * 720 / display_resy); - } - else - { - strcpy (height_pixels, "*"); - strcpy (height_dpi, "*"); - } - -#if 0 /* Never put the width in the xlfd. It fails on fonts with - double-width characters. */ - if (lplogfont->lfWidth) - sprintf (width_pixels, "%u", lplogfont->lfWidth * 10); - else -#endif - strcpy (width_pixels, "*"); - - _snprintf (lpxstr, len - 1, - "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s", - fonttype, /* foundry */ - fontname, /* family */ - w32_to_x_weight (lplogfont->lfWeight), /* weight */ - lplogfont->lfItalic?'i':'r', /* slant */ - /* setwidth name */ - /* add style name */ - height_pixels, /* pixel size */ - height_dpi, /* point size */ - display_resx, /* resx */ - display_resy, /* resy */ - ((lplogfont->lfPitchAndFamily & 0x3) == VARIABLE_PITCH) - ? 'p' : 'c', /* spacing */ - width_pixels, /* avg width */ - w32_to_x_charset (lplogfont->lfCharSet, specific_charset) - /* charset registry and encoding */ - ); - - lpxstr[len - 1] = 0; /* just to be sure */ - return (TRUE); -} - -static BOOL -x_to_w32_font (lpxstr, lplogfont) - char * lpxstr; - LOGFONT * lplogfont; -{ - struct coding_system coding; - - if (!lplogfont) return (FALSE); - - memset (lplogfont, 0, sizeof (*lplogfont)); - - /* Set default value for each field. */ -#if 1 - lplogfont->lfOutPrecision = OUT_DEFAULT_PRECIS; - lplogfont->lfClipPrecision = CLIP_DEFAULT_PRECIS; - lplogfont->lfQuality = DEFAULT_QUALITY; -#else - /* go for maximum quality */ - lplogfont->lfOutPrecision = OUT_STROKE_PRECIS; - lplogfont->lfClipPrecision = CLIP_STROKE_PRECIS; - lplogfont->lfQuality = PROOF_QUALITY; -#endif - - lplogfont->lfCharSet = DEFAULT_CHARSET; - lplogfont->lfWeight = FW_DONTCARE; - lplogfont->lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; - - if (!lpxstr) - return FALSE; - - /* Provide a simple escape mechanism for specifying Windows font names - * directly -- if font spec does not beginning with '-', assume this - * format: - * "[:height in pixels[:width in pixels[:weight]]]" - */ - - if (*lpxstr == '-') - { - int fields, tem; - char name[50], weight[20], slant, pitch, pixels[10], height[10], - width[10], resy[10], remainder[50]; - char * encoding; - int dpi = (int) one_w32_display_info.resy; - - fields = sscanf (lpxstr, - "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%49s", - name, weight, &slant, pixels, height, resy, &pitch, width, remainder); - if (fields == EOF) - return (FALSE); - - /* In the general case when wildcards cover more than one field, - we don't know which field is which, so don't fill any in. - However, we need to cope with this particular form, which is - generated by font_list_1 (invoked by try_font_list): - "-raster-6x10-*-gb2312*-*" - and make sure to correctly parse the charset field. */ - if (fields == 3) - { - fields = sscanf (lpxstr, - "-%*[^-]-%49[^-]-*-%49s", - name, remainder); - } - else if (fields < 9) - { - fields = 0; - remainder[0] = 0; - } - - if (fields > 0 && name[0] != '*') - { - Lisp_Object string = build_string (name); - setup_coding_system - (Fcheck_coding_system (Vlocale_coding_system), &coding); - coding.mode |= (CODING_MODE_SAFE_ENCODING | CODING_MODE_LAST_BLOCK); - /* Disable composition/charset annotation. */ - coding.common_flags &= ~CODING_ANNOTATION_MASK; - coding.dst_bytes = SCHARS (string) * 2; - - coding.destination = (unsigned char *) xmalloc (coding.dst_bytes); - encode_coding_object (&coding, string, 0, 0, - SCHARS (string), SBYTES (string), Qnil); - if (coding.produced >= LF_FACESIZE) - coding.produced = LF_FACESIZE - 1; - - coding.destination[coding.produced] = '\0'; - - strcpy (lplogfont->lfFaceName, coding.destination); - xfree (coding.destination); - } - else - { - lplogfont->lfFaceName[0] = '\0'; - } - - fields--; - - lplogfont->lfWeight = x_to_w32_weight ((fields > 0 ? weight : "")); - - fields--; - - lplogfont->lfItalic = (fields > 0 && slant == 'i'); - - fields--; - - if (fields > 0 && pixels[0] != '*') - lplogfont->lfHeight = atoi (pixels); - - fields--; - fields--; - if (fields > 0 && resy[0] != '*') - { - tem = atoi (resy); - if (tem > 0) dpi = tem; - } - - if (fields > -1 && lplogfont->lfHeight == 0 && height[0] != '*') - lplogfont->lfHeight = atoi (height) * dpi / 720; - - if (fields > 0) - { - if (pitch == 'p') - lplogfont->lfPitchAndFamily = VARIABLE_PITCH | FF_DONTCARE; - else if (pitch == 'c') - lplogfont->lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE; - } - - fields--; - - if (fields > 0 && width[0] != '*') - lplogfont->lfWidth = atoi (width) / 10; - - fields--; - - /* Strip the trailing '-' if present. (it shouldn't be, as it - fails the test against xlfd-tight-regexp in fontset.el). */ - { - int len = strlen (remainder); - if (len > 0 && remainder[len-1] == '-') - remainder[len-1] = 0; - } - encoding = remainder; -#if 0 - if (strncmp (encoding, "*-", 2) == 0) - encoding += 2; -#endif - lplogfont->lfCharSet = x_to_w32_charset (encoding); - } - else - { - int fields; - char name[100], height[10], width[10], weight[20]; - - fields = sscanf (lpxstr, - "%99[^:]:%9[^:]:%9[^:]:%19s", - name, height, width, weight); - - if (fields == EOF) return (FALSE); - - if (fields > 0) - { - strncpy (lplogfont->lfFaceName, name, LF_FACESIZE); - lplogfont->lfFaceName[LF_FACESIZE-1] = 0; - } - else - { - lplogfont->lfFaceName[0] = 0; - } - - fields--; - - if (fields > 0) - lplogfont->lfHeight = atoi (height); - - fields--; - - if (fields > 0) - lplogfont->lfWidth = atoi (width); - - fields--; - - lplogfont->lfWeight = x_to_w32_weight ((fields > 0 ? weight : "")); - } - - /* This makes TrueType fonts work better. */ - lplogfont->lfHeight = - eabs (lplogfont->lfHeight); - - return (TRUE); -} - - - DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0, doc: /* Internal function called by `color-defined-p', which see. */) (color, frame) @@ -7995,69 +7175,6 @@ only be necessary if the default setting causes problems. */); w32_strict_painting = 1; - DEFVAR_LISP ("w32-charset-info-alist", - &Vw32_charset_info_alist, - doc: /* Alist linking Emacs character sets to Windows fonts and codepages. -Each entry should be of the form: - - (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)) - -where CHARSET_NAME is a string used in font names to identify the charset, -WINDOWS_CHARSET is a symbol that can be one of: -w32-charset-ansi, w32-charset-default, w32-charset-symbol, -w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312, -w32-charset-chinesebig5, -w32-charset-johab, w32-charset-hebrew, -w32-charset-arabic, w32-charset-greek, w32-charset-turkish, -w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope, -w32-charset-russian, w32-charset-mac, w32-charset-baltic, -w32-charset-unicode, -or w32-charset-oem. -CODEPAGE should be an integer specifying the codepage that should be used -to display the character set, t to do no translation and output as Unicode, -or nil to do no translation and output as 8 bit (or multibyte on far-east -versions of Windows) characters. */); - Vw32_charset_info_alist = Qnil; - - DEFSYM (Qw32_charset_ansi, "w32-charset-ansi"); - DEFSYM (Qw32_charset_symbol, "w32-charset-symbol"); - DEFSYM (Qw32_charset_default, "w32-charset-default"); - DEFSYM (Qw32_charset_shiftjis, "w32-charset-shiftjis"); - DEFSYM (Qw32_charset_hangeul, "w32-charset-hangeul"); - DEFSYM (Qw32_charset_chinesebig5, "w32-charset-chinesebig5"); - DEFSYM (Qw32_charset_gb2312, "w32-charset-gb2312"); - DEFSYM (Qw32_charset_oem, "w32-charset-oem"); - -#ifdef JOHAB_CHARSET - { - static int w32_extra_charsets_defined = 1; - DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined, - doc: /* Internal variable. */); - - DEFSYM (Qw32_charset_johab, "w32-charset-johab"); - DEFSYM (Qw32_charset_easteurope, "w32-charset-easteurope"); - DEFSYM (Qw32_charset_turkish, "w32-charset-turkish"); - DEFSYM (Qw32_charset_baltic, "w32-charset-baltic"); - DEFSYM (Qw32_charset_russian, "w32-charset-russian"); - DEFSYM (Qw32_charset_arabic, "w32-charset-arabic"); - DEFSYM (Qw32_charset_greek, "w32-charset-greek"); - DEFSYM (Qw32_charset_hebrew, "w32-charset-hebrew"); - DEFSYM (Qw32_charset_vietnamese, "w32-charset-vietnamese"); - DEFSYM (Qw32_charset_thai, "w32-charset-thai"); - DEFSYM (Qw32_charset_mac, "w32-charset-mac"); - } -#endif - -#ifdef UNICODE_CHARSET - { - static int w32_unicode_charset_defined = 1; - DEFVAR_BOOL ("w32-unicode-charset-defined", - &w32_unicode_charset_defined, - doc: /* Internal variable. */); - DEFSYM (Qw32_charset_unicode, "w32-charset-unicode"); - } -#endif - #if 0 /* TODO: Port to W32 */ defsubr (&Sx_change_window_property); defsubr (&Sx_delete_window_property); diff -r 59d141ae8c74 -r 01647003e227 src/w32font.c --- a/src/w32font.c Fri Jun 27 21:12:46 2008 +0000 +++ b/src/w32font.c Fri Jun 27 22:33:12 2008 +0000 @@ -43,6 +43,15 @@ #define CLEARTYPE_NATURAL_QUALITY 6 #endif +/* VIETNAMESE_CHARSET and JOHAB_CHARSET are not defined in some versions + of MSVC headers. */ +#ifndef VIETNAMESE_CHARSET +#define VIETNAMESE_CHARSET 163 +#endif +#ifndef JOHAB_CHARSET +#define JOHAB_CHARSET 130 +#endif + extern struct font_driver w32font_driver; Lisp_Object Qgdi; @@ -80,6 +89,20 @@ /* Only defined here, but useful for distinguishing IPA capable fonts. */ static Lisp_Object Qphonetic; +/* W32 charsets: for use in Vw32_charset_info_alist. */ +static Lisp_Object Qw32_charset_ansi, Qw32_charset_default; +static Lisp_Object Qw32_charset_symbol, Qw32_charset_shiftjis; +static Lisp_Object Qw32_charset_hangeul, Qw32_charset_gb2312; +static Lisp_Object Qw32_charset_chinesebig5, Qw32_charset_oem; +static Lisp_Object Qw32_charset_easteurope, Qw32_charset_turkish; +static Lisp_Object Qw32_charset_baltic, Qw32_charset_russian; +static Lisp_Object Qw32_charset_arabic, Qw32_charset_greek; +static Lisp_Object Qw32_charset_hebrew, Qw32_charset_vietnamese; +static Lisp_Object Qw32_charset_thai, Qw32_charset_johab, Qw32_charset_mac; + +/* Associative list linking character set strings to Windows codepages. */ +static Lisp_Object Vw32_charset_info_alist; + /* Font spacing symbols - defined in font.c. */ extern Lisp_Object Qc, Qp, Qm; @@ -129,9 +152,6 @@ style variations if the font name is not specified. */ static void list_all_matching_fonts P_ ((struct font_callback_data *)); -/* From old font code in w32fns.c */ -char * w32_to_x_charset P_ ((int, char *)); - static int memq_no_quit (elt, list) @@ -1425,6 +1445,89 @@ return !NILP (match_data->list); } +/* Old function to convert from x to w32 charset, from w32fns.c. */ +static LONG +x_to_w32_charset (lpcs) + char * lpcs; +{ + Lisp_Object this_entry, w32_charset; + char *charset; + int len = strlen (lpcs); + + /* Support "*-#nnn" format for unknown charsets. */ + if (strncmp (lpcs, "*-#", 3) == 0) + return atoi (lpcs + 3); + + /* All Windows fonts qualify as unicode. */ + if (!strncmp (lpcs, "iso10646", 8)) + return DEFAULT_CHARSET; + + /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */ + charset = alloca (len + 1); + strcpy (charset, lpcs); + lpcs = strchr (charset, '*'); + if (lpcs) + *lpcs = '\0'; + + /* Look through w32-charset-info-alist for the character set. + Format of each entry is + (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)). + */ + this_entry = Fassoc (build_string (charset), Vw32_charset_info_alist); + + if (NILP (this_entry)) + { + /* At startup, we want iso8859-1 fonts to come up properly. */ + if (xstrcasecmp (charset, "iso8859-1") == 0) + return ANSI_CHARSET; + else + return DEFAULT_CHARSET; + } + + w32_charset = Fcar (Fcdr (this_entry)); + + /* Translate Lisp symbol to number. */ + if (EQ (w32_charset, Qw32_charset_ansi)) + return ANSI_CHARSET; + if (EQ (w32_charset, Qw32_charset_symbol)) + return SYMBOL_CHARSET; + if (EQ (w32_charset, Qw32_charset_shiftjis)) + return SHIFTJIS_CHARSET; + if (EQ (w32_charset, Qw32_charset_hangeul)) + return HANGEUL_CHARSET; + if (EQ (w32_charset, Qw32_charset_chinesebig5)) + return CHINESEBIG5_CHARSET; + if (EQ (w32_charset, Qw32_charset_gb2312)) + return GB2312_CHARSET; + if (EQ (w32_charset, Qw32_charset_oem)) + return OEM_CHARSET; + if (EQ (w32_charset, Qw32_charset_johab)) + return JOHAB_CHARSET; + if (EQ (w32_charset, Qw32_charset_easteurope)) + return EASTEUROPE_CHARSET; + if (EQ (w32_charset, Qw32_charset_turkish)) + return TURKISH_CHARSET; + if (EQ (w32_charset, Qw32_charset_baltic)) + return BALTIC_CHARSET; + if (EQ (w32_charset, Qw32_charset_russian)) + return RUSSIAN_CHARSET; + if (EQ (w32_charset, Qw32_charset_arabic)) + return ARABIC_CHARSET; + if (EQ (w32_charset, Qw32_charset_greek)) + return GREEK_CHARSET; + if (EQ (w32_charset, Qw32_charset_hebrew)) + return HEBREW_CHARSET; + if (EQ (w32_charset, Qw32_charset_vietnamese)) + return VIETNAMESE_CHARSET; + if (EQ (w32_charset, Qw32_charset_thai)) + return THAI_CHARSET; + if (EQ (w32_charset, Qw32_charset_mac)) + return MAC_CHARSET; + + return DEFAULT_CHARSET; +} + + /* Convert a Lisp font registry (symbol) to a windows charset. */ static LONG registry_to_w32_charset (charset) @@ -1441,6 +1544,203 @@ return DEFAULT_CHARSET; } +/* Old function to convert from w32 to x charset, from w32fns.c. */ +static char * +w32_to_x_charset (fncharset, matching) + int fncharset; + char *matching; +{ + static char buf[32]; + Lisp_Object charset_type; + int match_len = 0; + + if (matching) + { + /* If fully specified, accept it as it is. Otherwise use a + substring match. */ + char *wildcard = strchr (matching, '*'); + if (wildcard) + *wildcard = '\0'; + else if (strchr (matching, '-')) + return matching; + + match_len = strlen (matching); + } + + switch (fncharset) + { + case ANSI_CHARSET: + /* Handle startup case of w32-charset-info-alist not + being set up yet. */ + if (NILP (Vw32_charset_info_alist)) + return "iso8859-1"; + charset_type = Qw32_charset_ansi; + break; + case DEFAULT_CHARSET: + charset_type = Qw32_charset_default; + break; + case SYMBOL_CHARSET: + charset_type = Qw32_charset_symbol; + break; + case SHIFTJIS_CHARSET: + charset_type = Qw32_charset_shiftjis; + break; + case HANGEUL_CHARSET: + charset_type = Qw32_charset_hangeul; + break; + case GB2312_CHARSET: + charset_type = Qw32_charset_gb2312; + break; + case CHINESEBIG5_CHARSET: + charset_type = Qw32_charset_chinesebig5; + break; + case OEM_CHARSET: + charset_type = Qw32_charset_oem; + break; + case EASTEUROPE_CHARSET: + charset_type = Qw32_charset_easteurope; + break; + case TURKISH_CHARSET: + charset_type = Qw32_charset_turkish; + break; + case BALTIC_CHARSET: + charset_type = Qw32_charset_baltic; + break; + case RUSSIAN_CHARSET: + charset_type = Qw32_charset_russian; + break; + case ARABIC_CHARSET: + charset_type = Qw32_charset_arabic; + break; + case GREEK_CHARSET: + charset_type = Qw32_charset_greek; + break; + case HEBREW_CHARSET: + charset_type = Qw32_charset_hebrew; + break; + case VIETNAMESE_CHARSET: + charset_type = Qw32_charset_vietnamese; + break; + case THAI_CHARSET: + charset_type = Qw32_charset_thai; + break; + case MAC_CHARSET: + charset_type = Qw32_charset_mac; + break; + case JOHAB_CHARSET: + charset_type = Qw32_charset_johab; + break; + + default: + /* Encode numerical value of unknown charset. */ + sprintf (buf, "*-#%u", fncharset); + return buf; + } + + { + Lisp_Object rest; + char * best_match = NULL; + int matching_found = 0; + + /* Look through w32-charset-info-alist for the character set. + Prefer ISO codepages, and prefer lower numbers in the ISO + range. Only return charsets for codepages which are installed. + + Format of each entry is + (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)). + */ + for (rest = Vw32_charset_info_alist; CONSP (rest); rest = XCDR (rest)) + { + char * x_charset; + Lisp_Object w32_charset; + Lisp_Object codepage; + + Lisp_Object this_entry = XCAR (rest); + + /* Skip invalid entries in alist. */ + if (!CONSP (this_entry) || !STRINGP (XCAR (this_entry)) + || !CONSP (XCDR (this_entry)) + || !SYMBOLP (XCAR (XCDR (this_entry)))) + continue; + + x_charset = SDATA (XCAR (this_entry)); + w32_charset = XCAR (XCDR (this_entry)); + codepage = XCDR (XCDR (this_entry)); + + /* Look for Same charset and a valid codepage (or non-int + which means ignore). */ + if (EQ (w32_charset, charset_type) + && (!INTEGERP (codepage) || XINT (codepage) == CP_DEFAULT + || IsValidCodePage (XINT (codepage)))) + { + /* If we don't have a match already, then this is the + best. */ + if (!best_match) + { + best_match = x_charset; + if (matching && !strnicmp (x_charset, matching, match_len)) + matching_found = 1; + } + /* If we already found a match for MATCHING, then + only consider other matches. */ + else if (matching_found + && strnicmp (x_charset, matching, match_len)) + continue; + /* If this matches what we want, and the best so far doesn't, + then this is better. */ + else if (!matching_found && matching + && !strnicmp (x_charset, matching, match_len)) + { + best_match = x_charset; + matching_found = 1; + } + /* If this is fully specified, and the best so far isn't, + then this is better. */ + else if ((!strchr (best_match, '-') && strchr (x_charset, '-')) + /* If this is an ISO codepage, and the best so far isn't, + then this is better, but only if it fully specifies the + encoding. */ + || (strnicmp (best_match, "iso", 3) != 0 + && strnicmp (x_charset, "iso", 3) == 0 + && strchr (x_charset, '-'))) + best_match = x_charset; + /* If both are ISO8859 codepages, choose the one with the + lowest number in the encoding field. */ + else if (strnicmp (best_match, "iso8859-", 8) == 0 + && strnicmp (x_charset, "iso8859-", 8) == 0) + { + int best_enc = atoi (best_match + 8); + int this_enc = atoi (x_charset + 8); + if (this_enc > 0 && this_enc < best_enc) + best_match = x_charset; + } + } + } + + /* If no match, encode the numeric value. */ + if (!best_match) + { + sprintf (buf, "*-#%u", fncharset); + return buf; + } + + strncpy (buf, best_match, 31); + /* If the charset is not fully specified, put -0 on the end. */ + if (!strchr (best_match, '-')) + { + int pos = strlen (best_match); + /* Charset specifiers shouldn't be very long. If it is a made + up one, truncating it should not do any harm since it isn't + recognized anyway. */ + if (pos > 29) + pos = 29; + strcpy (buf + pos, "-0"); + } + buf[31] = '\0'; + return buf; + } +} + static Lisp_Object w32_registry (w32_charset, font_type) LONG w32_charset; @@ -2218,6 +2518,51 @@ DEFSYM (Qtifinagh, "tifinagh"); DEFSYM (Qugaritic, "ugaritic"); + /* W32 font encodings. */ + DEFVAR_LISP ("w32-charset-info-alist", + &Vw32_charset_info_alist, + doc: /* Alist linking Emacs character sets to Windows fonts and codepages. +Each entry should be of the form: + + (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)) + +where CHARSET_NAME is a string used in font names to identify the charset, +WINDOWS_CHARSET is a symbol that can be one of: + + w32-charset-ansi, w32-charset-default, w32-charset-symbol, + w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312, + w32-charset-chinesebig5, w32-charset-johab, w32-charset-hebrew, + w32-charset-arabic, w32-charset-greek, w32-charset-turkish, + w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope, + w32-charset-russian, w32-charset-mac, w32-charset-baltic, + or w32-charset-oem. + +CODEPAGE should be an integer specifying the codepage that should be used +to display the character set, t to do no translation and output as Unicode, +or nil to do no translation and output as 8 bit (or multibyte on far-east +versions of Windows) characters. */); + Vw32_charset_info_alist = Qnil; + + DEFSYM (Qw32_charset_ansi, "w32-charset-ansi"); + DEFSYM (Qw32_charset_symbol, "w32-charset-symbol"); + DEFSYM (Qw32_charset_default, "w32-charset-default"); + DEFSYM (Qw32_charset_shiftjis, "w32-charset-shiftjis"); + DEFSYM (Qw32_charset_hangeul, "w32-charset-hangeul"); + DEFSYM (Qw32_charset_chinesebig5, "w32-charset-chinesebig5"); + DEFSYM (Qw32_charset_gb2312, "w32-charset-gb2312"); + DEFSYM (Qw32_charset_oem, "w32-charset-oem"); + DEFSYM (Qw32_charset_johab, "w32-charset-johab"); + DEFSYM (Qw32_charset_easteurope, "w32-charset-easteurope"); + DEFSYM (Qw32_charset_turkish, "w32-charset-turkish"); + DEFSYM (Qw32_charset_baltic, "w32-charset-baltic"); + DEFSYM (Qw32_charset_russian, "w32-charset-russian"); + DEFSYM (Qw32_charset_arabic, "w32-charset-arabic"); + DEFSYM (Qw32_charset_greek, "w32-charset-greek"); + DEFSYM (Qw32_charset_hebrew, "w32-charset-hebrew"); + DEFSYM (Qw32_charset_vietnamese, "w32-charset-vietnamese"); + DEFSYM (Qw32_charset_thai, "w32-charset-thai"); + DEFSYM (Qw32_charset_mac, "w32-charset-mac"); + defsubr (&Sx_select_font); w32font_driver.type = Qgdi;