/[emacs]/emacs/src/macterm.c
ViewVC logotype

Diff of /emacs/src/macterm.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.111 by mituharu, Mon Apr 18 07:44:54 2005 UTC revision 1.112 by mituharu, Tue Apr 19 12:04:09 2005 UTC
# Line 5841  char **font_name_table = NULL; Line 5841  char **font_name_table = NULL;
5841  int font_name_table_size = 0;  int font_name_table_size = 0;
5842  int font_name_count = 0;  int font_name_count = 0;
5843    
5844  #if 0  /* Alist linking character set strings to Mac text encoding and Emacs
5845  /* compare two strings ignoring case */     coding system. */
5846  static int  static Lisp_Object Vmac_charset_info_alist;
 stricmp (const char *s, const char *t)  
 {  
   for ( ; tolower (*s) == tolower (*t); s++, t++)  
     if (*s == '\0')  
       return 0;  
   return tolower (*s) - tolower (*t);  
 }  
   
 /* compare two strings ignoring case and handling wildcard */  
 static int  
 wildstrieq (char *s1, char *s2)  
 {  
   if (strcmp (s1, "*") == 0 || strcmp (s2, "*") == 0)  
     return true;  
   
   return stricmp (s1, s2) == 0;  
 }  
5847    
5848  /* Assume parameter 1 is fully qualified, no wildcards. */  static Lisp_Object
5849  static int  create_text_encoding_info_alist ()
 mac_font_pattern_match (fontname, pattern)  
     char * fontname;  
     char * pattern;  
5850  {  {
5851    char *regex = (char *) alloca (strlen (pattern) * 2 + 3);    Lisp_Object result = Qnil, rest;
   char *font_name_copy = (char *) alloca (strlen (fontname) + 1);  
   char *ptr;  
   
   /* Copy fontname so we can modify it during comparison.  */  
   strcpy (font_name_copy, fontname);  
5852    
5853    ptr = regex;    for (rest = Vmac_charset_info_alist; CONSP (rest); rest = XCDR (rest))
   *ptr++ = '^';  
   
   /* Turn pattern into a regexp and do a regexp match.  */  
   for (; *pattern; pattern++)  
5854      {      {
5855        if (*pattern == '?')        Lisp_Object charset_info = XCAR (rest);
5856          *ptr++ = '.';        Lisp_Object charset, coding_system, text_encoding;
5857        else if (*pattern == '*')        Lisp_Object existing_info;
5858          {  
5859            *ptr++ = '.';        if (!(CONSP (charset_info)
5860            *ptr++ = '*';              && STRINGP (charset = XCAR (charset_info))
5861          }              && CONSP (XCDR (charset_info))
5862                && INTEGERP (text_encoding = XCAR (XCDR (charset_info)))
5863                && CONSP (XCDR (XCDR (charset_info)))
5864                && SYMBOLP (coding_system = XCAR (XCDR (XCDR (charset_info))))))
5865            continue;
5866    
5867          existing_info = assq_no_quit (text_encoding, result);
5868          if (NILP (existing_info))
5869            result = Fcons (list3 (text_encoding, coding_system, charset),
5870                            result);
5871        else        else
5872          *ptr++ = *pattern;          if (NILP (Fmember (charset, XCDR (XCDR (existing_info)))))
5873              XSETCDR (XCDR (existing_info),
5874                       Fcons (charset, XCDR (XCDR (existing_info))));
5875      }      }
   *ptr = '$';  
   *(ptr + 1) = '\0';  
   
   return (fast_c_string_match_ignore_case (build_string (regex),  
                                            font_name_copy) >= 0);  
 }  
   
 /* Two font specs are considered to match if their foundry, family,  
    weight, slant, and charset match.  */  
 static int  
 mac_font_match (char *mf, char *xf)  
 {  
   char m_foundry[50], m_family[50], m_weight[20], m_slant[2], m_charset[20];  
   char x_foundry[50], x_family[50], x_weight[20], x_slant[2], x_charset[20];  
   
   if (sscanf (mf, "-%49[^-]-%49[^-]-%19[^-]-%1[^-]-%*[^-]--%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%19s",  
               m_foundry, m_family, m_weight, m_slant, m_charset) != 5)  
     return mac_font_pattern_match (mf, xf);  
   
   if (sscanf (xf, "-%49[^-]-%49[^-]-%19[^-]-%1[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%19s",  
               x_foundry, x_family, x_weight, x_slant, x_charset) != 5)  
     return mac_font_pattern_match (mf, xf);  
5876    
5877    return (wildstrieq (m_foundry, x_foundry)    return result;
           && wildstrieq (m_family, x_family)  
           && wildstrieq (m_weight, x_weight)  
           && wildstrieq (m_slant, x_slant)  
           && wildstrieq (m_charset, x_charset))  
          || mac_font_pattern_match (mf, xf);  
5878  }  }
 #endif  
5879    
 static Lisp_Object Qbig5, Qcn_gb, Qsjis, Qeuc_kr;  
5880    
5881  static void  static void
5882  decode_mac_font_name (name, size, scriptcode)  decode_mac_font_name (name, size, coding_system)
5883       char *name;       char *name;
5884       int size;       int size;
5885  #if TARGET_API_MAC_CARBON       Lisp_Object coding_system;
      int scriptcode;  
 #else  
      short scriptcode;  
 #endif  
5886  {  {
   Lisp_Object coding_system;  
5887    struct coding_system coding;    struct coding_system coding;
5888    char *buf;    char *buf, *p;
5889    
5890    switch (scriptcode)    for (p = name; *p; p++)
5891      {      if (!isascii (*p) || iscntrl (*p))
     case smTradChinese:  
       coding_system = Qbig5;  
       break;  
     case smSimpChinese:  
       coding_system = Qcn_gb;  
       break;  
     case smJapanese:  
       coding_system = Qsjis;  
       break;  
     case smKorean:  
       coding_system = Qeuc_kr;  
5892        break;        break;
5893      default:  
5894        return;    if (*p == '\0'
5895      }        || NILP (coding_system) || NILP (Fcoding_system_p (coding_system)))
5896        return;
5897    
5898    setup_coding_system (coding_system, &coding);    setup_coding_system (coding_system, &coding);
5899    coding.src_multibyte = 0;    coding.src_multibyte = 0;
# Line 5971  decode_mac_font_name (name, size, script Line 5909  decode_mac_font_name (name, size, script
5909    
5910    
5911  static char *  static char *
5912  mac_to_x_fontname (name, size, style, scriptcode)  mac_to_x_fontname (name, size, style, charset)
5913       char *name;       char *name;
5914       int size;       int size;
5915       Style style;       Style style;
5916  #if TARGET_API_MAC_CARBON       char *charset;
      int scriptcode;  
 #else  
      short scriptcode;  
 #endif  
5917  {  {
5918    char foundry[32], family[32], cs[32];    char foundry[32], family[32], cs[32];
5919    char xf[256], *result, *p;    char xf[256], *result, *p;
5920    
5921    if (sscanf (name, "%31[^-]-%31[^-]-%31s", foundry, family, cs) != 3)    if (sscanf (name, "%31[^-]-%31[^-]-%31s", foundry, family, cs) == 3)
5922        charset = cs;
5923      else
5924      {      {
5925        strcpy(foundry, "Apple");        strcpy(foundry, "Apple");
5926        strcpy(family, name);        strcpy(family, name);
   
       switch (scriptcode)  
       {  
       case smTradChinese:       /* == kTextEncodingMacChineseTrad */  
         strcpy(cs, "big5-0");  
         break;  
       case smSimpChinese:       /* == kTextEncodingMacChineseSimp */  
         strcpy(cs, "gb2312.1980-0");  
         break;  
       case smJapanese:          /* == kTextEncodingMacJapanese */  
         strcpy(cs, "jisx0208.1983-sjis");  
         break;  
       case -smJapanese:  
         /* Each Apple Japanese font is entered into the font table  
            twice: once as a jisx0208.1983-sjis font and once as a  
            jisx0201.1976-0 font.  The latter can be used to display  
            the ascii charset and katakana-jisx0201 charset.  A  
            negative script code signals that the name of this latter  
            font is being built.  */  
         strcpy(cs, "jisx0201.1976-0");  
         break;  
       case smKorean:            /* == kTextEncodingMacKorean */  
         strcpy(cs, "ksc5601.1989-0");  
         break;  
 #if TARGET_API_MAC_CARBON  
       case kTextEncodingMacCyrillic:  
         strcpy(cs, "mac-cyrillic");  
         break;  
       case kTextEncodingMacCentralEurRoman:  
         strcpy(cs, "mac-centraleurroman");  
         break;  
       case kTextEncodingMacSymbol:  
       case kTextEncodingMacDingbats:  
         strcpy(cs, "adobe-fontspecific");  
         break;  
 #endif  
       default:  
         strcpy(cs, "mac-roman");  
         break;  
       }  
5927      }      }
5928    
5929    sprintf(xf, "-%s-%s-%s-%c-normal--%d-%d-75-75-m-%d-%s",    sprintf(xf, "-%s-%s-%s-%c-normal--%d-%d-75-75-m-%d-%s",
5930            foundry, family, style & bold ? "bold" : "medium",            foundry, family, style & bold ? "bold" : "medium",
5931            style & italic ? 'i' : 'r', size, size * 10, size * 10, cs);            style & italic ? 'i' : 'r', size, size * 10, size * 10, charset);
5932    
5933    result = (char *) xmalloc (strlen (xf) + 1);    result = (char *) xmalloc (strlen (xf) + 1);
5934    strcpy (result, xf);    strcpy (result, xf);
# Line 6050  mac_to_x_fontname (name, size, style, sc Line 5946  mac_to_x_fontname (name, size, style, sc
5946     "ETL-Fixed-iso8859-1", "ETL-Fixed-koi8-r", etc.  Both types of font     "ETL-Fixed-iso8859-1", "ETL-Fixed-koi8-r", etc.  Both types of font
5947     names are handled accordingly.  */     names are handled accordingly.  */
5948  static void  static void
5949  x_font_name_to_mac_font_name (char *xf, char *mf)  x_font_name_to_mac_font_name (xf, mf, mf_decoded, style, cs)
5950         char *xf, *mf, *mf_decoded;
5951         Style *style;
5952         char *cs;
5953  {  {
5954    char foundry[32], family[32], weight[20], slant[2], cs[32];    char foundry[32], family[32], weight[20], slant[2], *p;
5955    Lisp_Object coding_system = Qnil;    Lisp_Object charset_info, coding_system = Qnil;
5956    struct coding_system coding;    struct coding_system coding;
5957    
5958    strcpy (mf, "");    strcpy (mf, "");
# Line 6064  x_font_name_to_mac_font_name (char *xf, Line 5963  x_font_name_to_mac_font_name (char *xf,
5963                foundry, family, weight, slant, cs) != 5)                foundry, family, weight, slant, cs) != 5)
5964      return;      return;
5965    
5966    if (strcmp (cs, "big5-0") == 0)    *style = normal;
5967      coding_system = Qbig5;    if (strcmp (weight, "bold") == 0)
5968    else if (strcmp (cs, "gb2312.1980-0") == 0)      *style |= bold;
5969      coding_system = Qcn_gb;    if (*slant == 'i')
5970    else if (strcmp (cs, "jisx0208.1983-sjis") == 0      *style |= italic;
5971             || strcmp (cs, "jisx0201.1976-0") == 0)  
5972      coding_system = Qsjis;    charset_info = Fassoc (build_string (cs), Vmac_charset_info_alist);
5973    else if (strcmp (cs, "ksc5601.1989-0") == 0)    if (!NILP (charset_info))
5974      coding_system = Qeuc_kr;      {
5975    else if (strcmp (cs, "mac-roman") == 0        strcpy (mf_decoded, family);
5976             || strcmp (cs, "mac-cyrillic") == 0        coding_system = Fcar (Fcdr (Fcdr (charset_info)));
5977             || strcmp (cs, "mac-centraleurroman") == 0      }
            || strcmp (cs, "adobe-fontspecific") == 0)  
     strcpy (mf, family);  
5978    else    else
5979      sprintf (mf, "%s-%s-%s", foundry, family, cs);      sprintf (mf_decoded, "%s-%s-%s", foundry, family, cs);
5980    
5981    if (!NILP (coding_system))    for (p = mf_decoded; *p; p++)
5982        if (!isascii (*p) || iscntrl (*p))
5983          break;
5984    
5985      if (*p == '\0'
5986          || NILP (coding_system) || NILP (Fcoding_system_p (coding_system)))
5987        strcpy (mf, mf_decoded);
5988      else
5989      {      {
5990        setup_coding_system (coding_system, &coding);        setup_coding_system (coding_system, &coding);
5991        coding.src_multibyte = 1;        coding.src_multibyte = 1;
5992        coding.dst_multibyte = 1;        coding.dst_multibyte = 1;
5993        coding.mode |= CODING_MODE_LAST_BLOCK;        coding.mode |= CODING_MODE_LAST_BLOCK;
5994        encode_coding (&coding, family, mf, strlen (family), sizeof (Str32) - 1);        encode_coding (&coding, mf_decoded, mf,
5995                         strlen (mf_decoded), sizeof (Str32) - 1);
5996        mf[coding.produced] = '\0';        mf[coding.produced] = '\0';
5997      }      }
5998  }  }
# Line 6122  static void Line 6027  static void
6027  init_font_name_table ()  init_font_name_table ()
6028  {  {
6029  #if TARGET_API_MAC_CARBON  #if TARGET_API_MAC_CARBON
6030    SInt32 sv;    FMFontFamilyIterator ffi;
6031      FMFontFamilyInstanceIterator ffii;
6032      FMFontFamily ff;
6033      Lisp_Object text_encoding_info_alist;
6034      struct gcpro gcpro1;
6035    
6036      /* Create a dummy instance iterator here to avoid creating and
6037         destroying it in the loop.  */
6038      if (FMCreateFontFamilyInstanceIterator (0, &ffii) != noErr)
6039        return;
6040      /* Create an iterator to enumerate the font families.  */
6041      if (FMCreateFontFamilyIterator (NULL, NULL, kFMDefaultOptions, &ffi)
6042          != noErr)
6043        {
6044          FMDisposeFontFamilyInstanceIterator (&ffii);
6045          return;
6046        }
6047    
6048    if (Gestalt (gestaltSystemVersion, &sv) == noErr && sv >= 0x1000)    text_encoding_info_alist = create_text_encoding_info_alist ();
6049    
6050      GCPRO1 (text_encoding_info_alist);
6051    
6052      while (FMGetNextFontFamily (&ffi, &ff) == noErr)
6053      {      {
6054        FMFontFamilyIterator ffi;        Str255 name;
6055        FMFontFamilyInstanceIterator ffii;        FMFont font;
6056        FMFontFamily ff;        FMFontStyle style;
6057          FMFontSize size;
6058        /* Create a dummy instance iterator here to avoid creating and        TextEncoding encoding;
6059           destroying it in the loop.  */        TextEncodingBase sc;
6060        if (FMCreateFontFamilyInstanceIterator (0, &ffii) != noErr)        Lisp_Object text_encoding_info;
         return;  
       /* Create an iterator to enumerate the font families.  */  
       if (FMCreateFontFamilyIterator (NULL, NULL, kFMDefaultOptions, &ffi)  
           != noErr)  
         {  
           FMDisposeFontFamilyInstanceIterator (&ffii);  
           return;  
         }  
6061    
6062        while (FMGetNextFontFamily (&ffi, &ff) == noErr)        if (FMGetFontFamilyName (ff, name) != noErr)
6063          {          break;
6064            Str255 name;        p2cstr (name);
6065            FMFont font;        if (*name == '.')
6066            FMFontStyle style;          continue;
           FMFontSize size;  
           TextEncoding encoding;  
           TextEncodingBase sc;  
6067    
6068            if (FMGetFontFamilyName (ff, name) != noErr)        if (FMGetFontFamilyTextEncoding (ff, &encoding) != noErr)
6069              break;          break;
6070            p2cstr (name);        sc = GetTextEncodingBase (encoding);
6071            if (*name == '.')        text_encoding_info = assq_no_quit (make_number (sc),
6072              continue;                                           text_encoding_info_alist);
6073          if (!NILP (text_encoding_info))
6074            decode_mac_font_name (name, sizeof (name),
6075                                  XCAR (XCDR (text_encoding_info)));
6076          else
6077            text_encoding_info = assq_no_quit (make_number (kTextEncodingMacRoman),
6078                                               text_encoding_info_alist);
6079    
6080            if (FMGetFontFamilyTextEncoding (ff, &encoding) != noErr)        /* Point the instance iterator at the current font family.  */
6081              break;        if (FMResetFontFamilyInstanceIterator (ff, &ffii) != noErr)
6082            sc = GetTextEncodingBase (encoding);          break;
           decode_mac_font_name (name, sizeof (name), sc);  
6083    
6084            /* Point the instance iterator at the current font family.  */        while (FMGetNextFontFamilyInstance (&ffii, &font, &style, &size)
6085            if (FMResetFontFamilyInstanceIterator (ff, &ffii) != noErr)               == noErr)
6086              break;          {
6087              Lisp_Object rest = XCDR (XCDR (text_encoding_info));
6088    
6089            while (FMGetNextFontFamilyInstance (&ffii, &font, &style, &size)            for (; !NILP (rest); rest = XCDR (rest))
                  == noErr)  
6090              {              {
6091                /* Both jisx0208.1983-sjis and jisx0201.1976-0 parts are                char *cs = SDATA (XCAR (rest));
6092                   contained in Apple Japanese (SJIS) font.  */  
             again:  
6093                if (size == 0)                if (size == 0)
6094                  {                  {
6095                    add_font_name_table_entry (mac_to_x_fontname (name, size,                    add_font_name_table_entry (mac_to_x_fontname (name, size,
6096                                                                  style, sc));                                                                  style, cs));
6097                    add_font_name_table_entry (mac_to_x_fontname (name, size,                    add_font_name_table_entry (mac_to_x_fontname (name, size,
6098                                                                  italic, sc));                                                                  italic, cs));
6099                    add_font_name_table_entry (mac_to_x_fontname (name, size,                    add_font_name_table_entry (mac_to_x_fontname (name, size,
6100                                                                  bold, sc));                                                                  bold, cs));
6101                    add_font_name_table_entry (mac_to_x_fontname (name, size,                    add_font_name_table_entry (mac_to_x_fontname (name, size,
6102                                                                  italic | bold,                                                                  italic | bold,
6103                                                                  sc));                                                                  cs));
6104                  }                  }
6105                else                else
                 add_font_name_table_entry (mac_to_x_fontname (name, size,  
                                                               style, sc));  
               if (sc == smJapanese)  
6106                  {                  {
6107                    sc = -smJapanese;                    add_font_name_table_entry (mac_to_x_fontname (name, size,
6108                    goto again;                                                                  style, cs));
6109                  }                  }
               else if (sc == -smJapanese)  
                 sc = smJapanese;  
6110              }              }
6111          }          }
   
       /* Dispose of the iterators.  */  
       FMDisposeFontFamilyIterator (&ffi);  
       FMDisposeFontFamilyInstanceIterator (&ffii);  
6112      }      }
   else  
     {  
 #endif  /* TARGET_API_MAC_CARBON */  
       GrafPtr port;  
       SInt16 fontnum, old_fontnum;  
       int num_mac_fonts = CountResources('FOND');  
       int i, j;  
       Handle font_handle, font_handle_2;  
       short id, scriptcode;  
       ResType type;  
       Str32 name;  
       struct FontAssoc *fat;  
       struct AsscEntry *assc_entry;  
6113    
6114        GetPort (&port);  /* save the current font number used */    UNGCPRO;
6115  #if TARGET_API_MAC_CARBON  
6116        old_fontnum = GetPortTextFont (port);    /* Dispose of the iterators.  */
6117  #else    FMDisposeFontFamilyIterator (&ffi);
6118        old_fontnum = port->txFont;    FMDisposeFontFamilyInstanceIterator (&ffii);
6119  #endif  #else  /* !TARGET_API_MAC_CARBON */
6120      GrafPtr port;
6121      SInt16 fontnum, old_fontnum;
6122      int num_mac_fonts = CountResources('FOND');
6123      int i, j;
6124      Handle font_handle, font_handle_2;
6125      short id, scriptcode;
6126      ResType type;
6127      Str32 name;
6128      struct FontAssoc *fat;
6129      struct AsscEntry *assc_entry;
6130      Lisp_Object text_encoding_info_alist, text_encoding_info;
6131      struct gcpro gcpro1;
6132    
6133      GetPort (&port);  /* save the current font number used */
6134      old_fontnum = port->txFont;
6135    
6136      text_encoding_info_alist = create_text_encoding_info_alist ();
6137    
6138        for (i = 1; i <= num_mac_fonts; i++)  /* get all available fonts */    GCPRO1 (text_encoding_info_alist);
6139    
6140      for (i = 1; i <= num_mac_fonts; i++)  /* get all available fonts */
6141        {
6142          font_handle = GetIndResource ('FOND', i);
6143          if (!font_handle)
6144            continue;
6145    
6146          GetResInfo (font_handle, &id, &type, name);
6147          GetFNum (name, &fontnum);
6148          p2cstr (name);
6149          if (fontnum == 0)
6150            continue;
6151    
6152          TextFont (fontnum);
6153          scriptcode = FontToScript (fontnum);
6154          text_encoding_info = assq_no_quit (make_number (scriptcode),
6155                                             text_encoding_info_alist);
6156          if (!NILP (text_encoding_info))
6157            decode_mac_font_name (name, sizeof (name),
6158                                  XCAR (XCDR (text_encoding_info)));
6159          else
6160            text_encoding_info = assq_no_quit (make_number (smRoman),
6161                                               text_encoding_info_alist);
6162          do
6163          {          {
6164            font_handle = GetIndResource ('FOND', i);            HLock (font_handle);
6165            if (!font_handle)  
6166              continue;            if (GetResourceSizeOnDisk (font_handle)
6167                  >= sizeof (struct FamRec))
           GetResInfo (font_handle, &id, &type, name);  
           GetFNum (name, &fontnum);  
           p2cstr (name);  
           if (fontnum == 0)  
             continue;  
   
           TextFont (fontnum);  
           scriptcode = FontToScript (fontnum);  
           decode_mac_font_name (name, sizeof (name), scriptcode);  
           do  
6168              {              {
6169                HLock (font_handle);                fat = (struct FontAssoc *) (*font_handle
6170                                              + sizeof (struct FamRec));
6171                  assc_entry
6172                    = (struct AsscEntry *) (*font_handle
6173                                            + sizeof (struct FamRec)
6174                                            + sizeof (struct FontAssoc));
6175    
6176                if (GetResourceSizeOnDisk (font_handle)                for (j = 0; j <= fat->numAssoc; j++, assc_entry++)
                   >= sizeof (struct FamRec))  
6177                  {                  {
6178                    fat = (struct FontAssoc *) (*font_handle                    Lisp_Object rest = XCDR (XCDR (text_encoding_info));
                                               + sizeof (struct FamRec));  
                   assc_entry  
                     = (struct AsscEntry *) (*font_handle  
                                             + sizeof (struct FamRec)  
                                             + sizeof (struct FontAssoc));  
6179    
6180                    for (j = 0; j <= fat->numAssoc; j++, assc_entry++)                    for (; !NILP (rest); rest = XCDR (rest))
6181                      {                      {
6182                        if (font_name_table_size == 0)                        char *cs = SDATA (XCAR (rest));
6183                          {  
6184                            font_name_table_size = 16;                        add_font_name_table_entry (mac_to_x_fontname (name,
6185                            font_name_table = (char **)                                                                      assc_entry->fontSize,
6186                              xmalloc (font_name_table_size * sizeof (char *));                                                                      assc_entry->fontStyle,
6187                          }                                                                      cs));
                       else if (font_name_count >= font_name_table_size)  
                         {  
                           font_name_table_size += 16;  
                           font_name_table = (char **)  
                             xrealloc (font_name_table,  
                                       font_name_table_size * sizeof (char *));  
                         }  
                       font_name_table[font_name_count++]  
                         = mac_to_x_fontname (name,  
                                              assc_entry->fontSize,  
                                              assc_entry->fontStyle,  
                                              scriptcode);  
                       /* Both jisx0208.1983-sjis and jisx0201.1976-0  
                          parts are contained in Apple Japanese (SJIS)  
                          font.  */  
                       if (smJapanese == scriptcode)  
                         {  
                           font_name_table[font_name_count++]  
                             = mac_to_x_fontname (name,  
                                                  assc_entry->fontSize,  
                                                  assc_entry->fontStyle,  
                                                  -smJapanese);  
                         }  
6188                      }                      }
6189                  }                  }
   
               HUnlock (font_handle);  
               font_handle_2 = GetNextFOND (font_handle);  
               ReleaseResource (font_handle);  
               font_handle = font_handle_2;  
6190              }              }
           while (ResError () == noErr && font_handle);  
         }  
6191    
6192        TextFont (old_fontnum);            HUnlock (font_handle);
6193  #if TARGET_API_MAC_CARBON            font_handle_2 = GetNextFOND (font_handle);
6194              ReleaseResource (font_handle);
6195              font_handle = font_handle_2;
6196            }
6197          while (ResError () == noErr && font_handle);
6198      }      }
6199  #endif  /* TARGET_API_MAC_CARBON */  
6200      UNGCPRO;
6201    
6202      TextFont (old_fontnum);
6203    #endif  /* !TARGET_API_MAC_CARBON */
6204  }  }
6205    
6206    
# Line 6384  mac_do_list_fonts (pattern, maxnames) Line 6288  mac_do_list_fonts (pattern, maxnames)
6288          ptr++;          ptr++;
6289          if (i == *field)          if (i == *field)
6290            {            {
6291              if ('1' <= *ptr && *ptr <= '9')              if ('0' <= *ptr && *ptr <= '9')
6292                {                {
6293                  *val = *ptr++ - '0';                  *val = *ptr++ - '0';
6294                  while ('0' <= *ptr && *ptr <= '9' && *val < 10000)                  while ('0' <= *ptr && *ptr <= '9' && *val < 10000)
# Line 6402  mac_do_list_fonts (pattern, maxnames) Line 6306  mac_do_list_fonts (pattern, maxnames)
6306    
6307    if (i == 14 && ptr == NULL)    if (i == 14 && ptr == NULL)
6308      {      {
6309        if (scl_val[XLFD_SCL_POINT_SIZE] > 0)        if (scl_val[XLFD_SCL_PIXEL_SIZE] < 0)
6310          {          scl_val[XLFD_SCL_PIXEL_SIZE] =
6311            scl_val[XLFD_SCL_PIXEL_SIZE] = scl_val[XLFD_SCL_POINT_SIZE] / 10;            (scl_val[XLFD_SCL_POINT_SIZE] > 0 ? scl_val[XLFD_SCL_POINT_SIZE] / 10
6312            scl_val[XLFD_SCL_AVGWIDTH] = scl_val[XLFD_SCL_POINT_SIZE];             : (scl_val[XLFD_SCL_AVGWIDTH] > 0 ? scl_val[XLFD_SCL_AVGWIDTH] / 10
6313          }                : -1));
6314        else if (scl_val[XLFD_SCL_PIXEL_SIZE] > 0)        if (scl_val[XLFD_SCL_POINT_SIZE] < 0)
6315          {          scl_val[XLFD_SCL_POINT_SIZE] =
6316            scl_val[XLFD_SCL_POINT_SIZE] =            (scl_val[XLFD_SCL_PIXEL_SIZE] > 0 ? scl_val[XLFD_SCL_PIXEL_SIZE] * 10
6317              scl_val[XLFD_SCL_AVGWIDTH] = scl_val[XLFD_SCL_PIXEL_SIZE] * 10;             : (scl_val[XLFD_SCL_AVGWIDTH] > 0 ? scl_val[XLFD_SCL_AVGWIDTH]
6318          }                : -1));
6319        else if (scl_val[XLFD_SCL_AVGWIDTH] > 0)        if (scl_val[XLFD_SCL_AVGWIDTH] < 0)
6320          {          scl_val[XLFD_SCL_AVGWIDTH] =
6321            scl_val[XLFD_SCL_PIXEL_SIZE] = scl_val[XLFD_SCL_AVGWIDTH] / 10;            (scl_val[XLFD_SCL_PIXEL_SIZE] > 0 ? scl_val[XLFD_SCL_PIXEL_SIZE] * 10
6322            scl_val[XLFD_SCL_POINT_SIZE] = scl_val[XLFD_SCL_AVGWIDTH];             : (scl_val[XLFD_SCL_POINT_SIZE] > 0 ? scl_val[XLFD_SCL_POINT_SIZE]
6323          }                : -1));
6324      }      }
6325    else    else
6326      scl_val[XLFD_SCL_PIXEL_SIZE] = -1;      scl_val[XLFD_SCL_PIXEL_SIZE] = -1;
# Line 6507  mac_do_list_fonts (pattern, maxnames) Line 6411  mac_do_list_fonts (pattern, maxnames)
6411    return font_list;    return font_list;
6412  }  }
6413    
6414  /* Return a list of at most MAXNAMES font specs matching the one in  /* Return a list of names of available fonts matching PATTERN on frame F.
6415     PATTERN.  Cache matching fonts for patterns in  
6416     dpyinfo->name_list_element to avoid looking them up again by     Frame F null means we have not yet created any frame on Mac, and
6417     calling mac_font_pattern_match (slow).  Return as many matching     consult the first display in x_display_list.  MAXNAMES sets a limit
6418     fonts as possible if MAXNAMES = -1.  */     on how many fonts to match.  */
6419    
6420  Lisp_Object  Lisp_Object
6421  x_list_fonts (struct frame *f,  x_list_fonts (f, pattern, size, maxnames)
6422                Lisp_Object pattern,       struct frame *f;
6423                int size,       Lisp_Object pattern;
6424                int maxnames)       int size, maxnames;
6425  {  {
6426    Lisp_Object newlist = Qnil, tem, key;    Lisp_Object list = Qnil, patterns, tem, key;
6427    struct mac_display_info *dpyinfo = f ? FRAME_MAC_DISPLAY_INFO (f) : NULL;    struct mac_display_info *dpyinfo
6428        = f ? FRAME_MAC_DISPLAY_INFO (f) : x_display_list;
6429    
6430      xassert (size <= 0);
6431    
6432      patterns = Fassoc (pattern, Valternate_fontname_alist);
6433      if (NILP (patterns))
6434        patterns = Fcons (pattern, Qnil);
6435    
6436    if (dpyinfo)    for (; CONSP (patterns); patterns = XCDR (patterns))
6437      {      {
6438          pattern = XCAR (patterns);
6439    
6440          if (!STRINGP (pattern))
6441            continue;
6442    
6443        tem = XCAR (XCDR (dpyinfo->name_list_element));        tem = XCAR (XCDR (dpyinfo->name_list_element));
6444        key = Fcons (pattern, make_number (maxnames));        key = Fcons (pattern, make_number (maxnames));
6445    
6446        newlist = Fassoc (key, tem);        list = Fassoc (key, tem);
6447        if (!NILP (newlist))        if (!NILP (list))
6448          {          {
6449            newlist = Fcdr_safe (newlist);            list = Fcdr_safe (list);
6450              /* We have a cashed list.  Don't have to get the list again.  */
6451            goto label_cached;            goto label_cached;
6452          }          }
     }  
6453    
6454    BLOCK_INPUT;        BLOCK_INPUT;
6455    newlist = mac_do_list_fonts (SDATA (pattern), maxnames);        list = mac_do_list_fonts (SDATA (pattern), maxnames);
6456    UNBLOCK_INPUT;        UNBLOCK_INPUT;
6457    
6458    /* MAC_TODO: add code for matching outline fonts here */        /* MAC_TODO: add code for matching outline fonts here */
6459    
6460    if (dpyinfo)        /* Now store the result in the cache.  */
     {  
6461        XSETCAR (XCDR (dpyinfo->name_list_element),        XSETCAR (XCDR (dpyinfo->name_list_element),
6462                 Fcons (Fcons (key, newlist),                 Fcons (Fcons (key, list),
6463                        XCAR (XCDR (dpyinfo->name_list_element))));                        XCAR (XCDR (dpyinfo->name_list_element))));
6464    
6465        label_cached:
6466          if (NILP (list)) continue; /* Try the remaining alternatives.  */
6467      }      }
  label_cached:  
6468    
6469    return newlist;    return list;
6470  }  }
6471    
6472    
# Line 6668  is_fully_specified_xlfd (char *p) Line 6585  is_fully_specified_xlfd (char *p)
6585  }  }
6586    
6587    
6588  const int kDefaultFontSize = 9;  const int kDefaultFontSize = 12;
6589    
6590    
6591  /* XLoadQueryFont creates and returns an internal representation for a  /* XLoadQueryFont creates and returns an internal representation for a
# Line 6680  const int kDefaultFontSize = 9; Line 6597  const int kDefaultFontSize = 9;
6597  static MacFontStruct *  static MacFontStruct *
6598  XLoadQueryFont (Display *dpy, char *fontname)  XLoadQueryFont (Display *dpy, char *fontname)
6599  {  {
6600    int i, size, is_two_byte_font, char_width;    int i, size, point_size, avgwidth, is_two_byte_font, char_width;
6601    char *name;    char *name;
6602    GrafPtr port;    GrafPtr port;
6603    SInt16 old_fontnum, old_fontsize;    SInt16 old_fontnum, old_fontsize;
6604    Style old_fontface;    Style old_fontface;
6605    Str32 mfontname;    Str32 mfontname, mfontname_decoded, charset;
6606    SInt16 fontnum;    SInt16 fontnum;
6607    Style fontface = normal;    Style fontface;
6608    #if TARGET_API_MAC_CARBON
6609      TextEncoding encoding;
6610      int scriptcode;
6611    #else
6612      short scriptcode;
6613    #endif
6614    MacFontStruct *font;    MacFontStruct *font;
6615    FontInfo the_fontinfo;    FontInfo the_fontinfo;
6616    char s_weight[7], c_slant;  #ifdef MAC_OSX
6617      UInt32 old_flags, new_flags;
6618    #endif
6619    
6620    if (is_fully_specified_xlfd (fontname))    if (is_fully_specified_xlfd (fontname))
6621      name = fontname;      name = fontname;
# Line 6715  XLoadQueryFont (Display *dpy, char *font Line 6640  XLoadQueryFont (Display *dpy, char *font
6640    old_fontface = port->txFace;    old_fontface = port->txFace;
6641  #endif  #endif
6642    
6643    if (sscanf (name, "-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]--%d-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%*s", &size) != 1)    if (sscanf (name, "-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]--%d-%d-%*[^-]-%*[^-]-%*c-%d-%*s", &size, &point_size, &avgwidth) != 3)
6644        size = 0;
6645      else
6646        {
6647          if (size == 0)
6648            if (point_size > 0)
6649              size = point_size / 10;
6650            else if (avgwidth > 0)
6651              size = avgwidth / 10;
6652        }
6653      if (size == 0)
6654      size = kDefaultFontSize;      size = kDefaultFontSize;
6655    
6656    if (sscanf (name, "-%*[^-]-%*[^-]-%6[^-]-%*c-%*[^-]--%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%*s", s_weight) == 1)    x_font_name_to_mac_font_name (name, mfontname, mfontname_decoded,
6657      if (strcmp (s_weight, "bold") == 0)                                  &fontface, charset);
       fontface |= bold;  
   
   if (sscanf (name, "-%*[^-]-%*[^-]-%*[^-]-%c-%*[^-]--%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%*s", &c_slant) == 1)  
     if (c_slant == 'i')  
       fontface |= italic;  
   
   x_font_name_to_mac_font_name (name, mfontname);  
6658    c2pstr (mfontname);    c2pstr (mfontname);
6659    #if TARGET_API_MAC_CARBON
6660      fontnum = FMGetFontFamilyFromName (mfontname);
6661      if (fontnum == kInvalidFontFamily
6662          || FMGetFontFamilyTextEncoding (fontnum, &encoding) != noErr)
6663        return NULL;
6664      scriptcode = GetTextEncodingBase (encoding);
6665    #else
6666    GetFNum (mfontname, &fontnum);    GetFNum (mfontname, &fontnum);
6667    if (fontnum == 0)    if (fontnum == 0)
6668      return NULL;      return NULL;
6669      scriptcode = FontToScript (fontnum);
6670    #endif
6671    
6672    font = (MacFontStruct *) xmalloc (sizeof (struct MacFontStruct));    font = (MacFontStruct *) xmalloc (sizeof (struct MacFontStruct));
6673    
   font->fontname = (char *) xmalloc (strlen (name) + 1);  
   bcopy (name, font->fontname, strlen (name) + 1);  
   
6674    font->mac_fontnum = fontnum;    font->mac_fontnum = fontnum;
6675    font->mac_fontsize = size;    font->mac_fontsize = size;
6676    font->mac_fontface = fontface;    font->mac_fontface = fontface;
6677    font->mac_scriptcode = FontToScript (fontnum);    font->mac_scriptcode = scriptcode;
6678    
6679    /* Apple Japanese (SJIS) font is listed as both    /* Apple Japanese (SJIS) font is listed as both
6680       "*-jisx0208.1983-sjis" (Japanese script) and "*-jisx0201.1976-0"       "*-jisx0208.1983-sjis" (Japanese script) and "*-jisx0201.1976-0"
6681       (Roman script) in init_font_name_table ().  The latter should be       (Roman script) in init_font_name_table ().  The latter should be
6682       treated as a one-byte font.  */       treated as a one-byte font.  */
6683    {    if (scriptcode == smJapanese && strcmp (charset, "jisx0201.1976-0") == 0)
6684      char cs[32];      font->mac_scriptcode = smRoman;
6685    
6686      if (sscanf (name,    font->full_name = mac_to_x_fontname (mfontname_decoded, size, fontface, charset);
                 "-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]--%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%31s",  
                 cs) == 1  
         && 0 == strcmp (cs, "jisx0201.1976-0"))  
       font->mac_scriptcode = smRoman;  
   }  
6687    
6688    is_two_byte_font = font->mac_scriptcode == smJapanese ||    is_two_byte_font = font->mac_scriptcode == smJapanese ||
6689                       font->mac_scriptcode == smTradChinese ||                       font->mac_scriptcode == smTradChinese ||
# Line 6879  mac_unload_font (dpyinfo, font) Line 6808  mac_unload_font (dpyinfo, font)
6808       struct mac_display_info *dpyinfo;       struct mac_display_info *dpyinfo;
6809       XFontStruct *font;       XFontStruct *font;
6810  {  {
6811    xfree (font->fontname);    xfree (font->full_name);
6812    if (font->per_char)    if (font->per_char)
6813      xfree (font->per_char);      xfree (font->per_char);
6814    xfree (font);    xfree (font);
# Line 6919  x_load_font (f, fontname, size) Line 6848  x_load_font (f, fontname, size)
6848                                SDATA (XCAR (tail)))))                                SDATA (XCAR (tail)))))
6849              return (dpyinfo->font_table + i);              return (dpyinfo->font_table + i);
6850      }      }
6851      else
6852        return NULL;
6853    
6854    /* Load the font and add it to the table.  */    /* Load the font and add it to the table.  */
6855    {    {
# Line 6928  x_load_font (f, fontname, size) Line 6859  x_load_font (f, fontname, size)
6859      unsigned long value;      unsigned long value;
6860      int i;      int i;
6861    
6862      /* If we have found fonts by x_list_font, load one of them.  If      fontname = (char *) SDATA (XCAR (font_names));
        not, we still try to load a font by the name given as FONTNAME  
        because XListFonts (called in x_list_font) of some X server has  
        a bug of not finding a font even if the font surely exists and  
        is loadable by XLoadQueryFont.  */  
     if (size > 0 && !NILP (font_names))  
       fontname = (char *) SDATA (XCAR (font_names));  
6863    
6864      BLOCK_INPUT;      BLOCK_INPUT;
6865      font = (MacFontStruct *) XLoadQueryFont (FRAME_MAC_DISPLAY (f), fontname);      font = (MacFontStruct *) XLoadQueryFont (FRAME_MAC_DISPLAY (f), fontname);
# Line 6967  x_load_font (f, fontname, size) Line 6892  x_load_font (f, fontname, size)
6892      bzero (fontp, sizeof (*fontp));      bzero (fontp, sizeof (*fontp));
6893      fontp->font = font;      fontp->font = font;
6894      fontp->font_idx = i;      fontp->font_idx = i;
6895      fontp->name = (char *) xmalloc (strlen (font->fontname) + 1);      fontp->name = (char *) xmalloc (strlen (fontname) + 1);
6896      bcopy (font->fontname, fontp->name, strlen (font->fontname) + 1);      bcopy (fontname, fontp->name, strlen (fontname) + 1);
6897    
6898      if (font->min_bounds.width == font->max_bounds.width)      if (font->min_bounds.width == font->max_bounds.width)
6899        {        {
# Line 6999  x_load_font (f, fontname, size) Line 6924  x_load_font (f, fontname, size)
6924            fontp->average_width = FONT_WIDTH (font);            fontp->average_width = FONT_WIDTH (font);
6925        }        }
6926    
6927      fontp->full_name = fontp->name;      fontp->full_name = (char *) xmalloc (strlen (font->full_name) + 1);
6928        bcopy (font->full_name, fontp->full_name, strlen (font->full_name) + 1);
6929    
6930      fontp->size = font->max_bounds.width;      fontp->size = font->max_bounds.width;
6931      fontp->height = FONT_HEIGHT (font);      fontp->height = FONT_HEIGHT (font);
# Line 9810  syms_of_macterm () Line 9736  syms_of_macterm ()
9736    Qmac_ready_for_drag_n_drop = intern ("mac-ready-for-drag-n-drop");    Qmac_ready_for_drag_n_drop = intern ("mac-ready-for-drag-n-drop");
9737    staticpro (&Qmac_ready_for_drag_n_drop);    staticpro (&Qmac_ready_for_drag_n_drop);
9738    
   Qbig5 = intern ("big5");  
   staticpro (&Qbig5);  
   
   Qcn_gb = intern ("cn-gb");  
   staticpro (&Qcn_gb);  
   
   Qsjis = intern ("sjis");  
   staticpro (&Qsjis);  
   
   Qeuc_kr = intern ("euc-kr");  
   staticpro (&Qeuc_kr);  
   
9739    DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars,    DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars,
9740                 doc: /* If not nil, Emacs uses toolkit scroll bars.  */);                 doc: /* If not nil, Emacs uses toolkit scroll bars.  */);
9741    Vx_toolkit_scroll_bars = Qt;    Vx_toolkit_scroll_bars = Qt;
# Line 9888  Toolbox for processing before Emacs sees Line 9802  Toolbox for processing before Emacs sees
9802  The text will be rendered using Core Graphics text rendering which  The text will be rendered using Core Graphics text rendering which
9803  may anti-alias the text.  */);  may anti-alias the text.  */);
9804    Vmac_use_core_graphics = Qnil;    Vmac_use_core_graphics = Qnil;
9805    
9806      /* Register an entry for `mac-roman' so that it can be used when
9807         creating the terminal frame on Mac OS 9 before loading
9808         term/mac-win.elc.  */
9809      DEFVAR_LISP ("mac-charset-info-alist", &Vmac_charset_info_alist,
9810                   doc: /* Alist linking Emacs character sets to Mac text encoding and Emacs coding system.
9811    Each entry should be of the form:
9812    
9813       (CHARSET-NAME TEXT-ENCODING CODING-SYSTEM)
9814    
9815    where CHARSET-NAME is a string used in font names to identify the
9816    charset, TEXT-ENCODING is a TextEncodingBase value, and CODING_SYSTEM
9817    is a coding system corresponding to TEXT-ENCODING.  */);
9818      Vmac_charset_info_alist =
9819        Fcons (list3 (build_string ("mac-roman"),
9820                      make_number (smRoman), Qnil), Qnil);
9821  }  }
9822    
9823  /* arch-tag: f2259165-4454-4c04-a029-a133c8af7b5b  /* arch-tag: f2259165-4454-4c04-a029-a133c8af7b5b

Legend:
Removed from v.1.111  
changed lines
  Added in v.1.112

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26