emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/src/w32font.c,v


From: Jason Rumney
Subject: [Emacs-diffs] Changes to emacs/src/w32font.c,v
Date: Fri, 27 Jun 2008 22:33:14 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     Jason Rumney <jasonr>   08/06/27 22:33:12

Index: src/w32font.c
===================================================================
RCS file: /sources/emacs/emacs/src/w32font.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -b -r1.43 -r1.44
--- src/w32font.c       26 Jun 2008 22:11:25 -0000      1.43
+++ src/w32font.c       27 Jun 2008 22:33:12 -0000      1.44
@@ -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;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]