Changeset 3084

Show
Ignore:
Timestamp:
2003年05月27日 05時38分51秒 (6 years ago)
Author:
himi
Message:

* mw32font.c: Defined Qspec and Qstrict. Removed Qstrict_spec.
(mw32_load_strict_spec, mw32_load_function_spec): New functions.
(mw32_spec_base_font_loader): New function. Substituded it for
mw32_strict_logical_font_loader and mw32_elisp_logical_font_loader.
(mw32_check_font_option): Separated checking option part from
mw32_check_font_request_alist().
(mw32_check_font_request_alist): Made it adapt to the new font "spec"
format. Furthermore, check logfont lisp object strictly.
(reinit_syms_of_mw32font): Added mw32_spec_base_font_loader.
Removed mw32_strict_logical_font_loader and
mw32_elisp_logical_font_loader.
(syms_of_mw32font): Initialize Qspec and Qstrict.
Removed the code on Qstrict_spec.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • work/cvs2svn/src/mw32font.c

    r3062 r3084  
    4242extern Lisp_Object QCwidth, QCheight, QCfamily, QCweight, QCslant; 
    4343 
    44 Lisp_Object Qany, Qstrict_spec
     44Lisp_Object Qany, Qspec, Qstrict
    4545Lisp_Object Qoverhang, Qrelative_compose, Qdefault_ascent; 
    4646Lisp_Object Qencoding, Qfont_unit_byte; 
     
    16611661 
    16621662  if (!check_lisp_object_logfont(llf, 1)) return NULL; 
    1663   if (EQ(XCAR(llf), Qbdf_font)) 
     1663  if (EQ (XCAR (llf), Qbdf_font)) 
    16641664    { 
    16651665      Lisp_Object tem; 
    16661666      unsigned char* filename; 
    1667       tem = XCDR(llf); 
    1668       filename = XSTRING(CAR(tem))->data; 
    1669       plf = mw32_add_logical_font(pfr); 
     1667      tem = XCDR (llf); 
     1668      filename = XSTRING (CAR (tem))->data; 
     1669      plf = mw32_add_logical_font (pfr); 
    16701670      if (!mw32_set_bdf_font (f, plf, filename)) 
    16711671        { 
    1672           mw32_delete_logical_font(plf); 
     1672          mw32_delete_logical_font (plf); 
    16731673          return NULL; 
    16741674        } 
     
    16771677    { 
    16781678      LOGFONT lf; 
    1679       lf = lisp_object_to_logfont(llf); 
    1680       plf = mw32_add_logical_font(pfr); 
     1679      lf = lisp_object_to_logfont (llf); 
     1680      plf = mw32_add_logical_font (pfr); 
    16811681      if (!mw32_set_windows_logical_font (f, plf, &lf, c)) 
    16821682        { 
    1683           mw32_delete_logical_font(plf); 
     1683          mw32_delete_logical_font (plf); 
    16841684          return NULL; 
    16851685        } 
     
    16871687  mw32_set_option_alist_to_logical_font (plf, option); 
    16881688 
    1689   return mw32_register_logical_font(f, plf); 
     1689  return mw32_register_logical_font (f, plf); 
    16901690} 
    16911691 
     
    18441844      } 
    18451845    else if (CHAR_TABLE_P(chspec)) 
    1846       if (NILP(Faref (chspec, make_number(c)))) return 0; 
    1847       else 
    1848         return 0; 
     1846      { 
     1847        if (NILP(Faref (chspec, make_number(c)))) 
     1848          return 0; 
     1849        else 
     1850          return 0; 
     1851      } 
    18491852  } 
    18501853  /* <avgwidth> */ 
     
    19141917} 
    19151918 
    1916 /* 
    1917   (strict-spec ((specvec logfont [option-alist]) 
    1918                 (specvec logfont [option-alist]) 
    1919                 ...)) 
    1920  */ 
     1919/* val is (<logfont> [<option-alist>]) */ 
    19211920static MW32LogicalFont* 
    1922 mw32_strict_logical_font_loader(MW32FontRequest *pfr, 
    1923                                 struct frame *f, 
    1924                                 struct face *face, 
    1925                                 int c) 
    1926 
    1927   MW32LogicalFont *plf; 
    1928   Lisp_Object *attrs; 
    1929   Lisp_Object alist, specs, tem, spec, logfont, option; 
    1930  
    1931   if (face) 
    1932     attrs = face->lface; 
     1921mw32_load_strict_spec (Lisp_Object val, 
     1922                       MW32FontRequest *pfr, 
     1923                       struct frame *f, 
     1924                       int c) 
     1925
     1926  Lisp_Object logfont, option; 
     1927 
     1928  if (!CONSP (val)) return NULL; 
     1929 
     1930  logfont = XCAR (val); 
     1931  val = XCDR (val); 
     1932 
     1933  if (CONSP (val) && CONSP (XCAR (val))) 
     1934    option = XCAR (val); 
    19331935  else 
    1934     attrs = face_unspecified_attrs; 
    1935  
    1936   alist = AREF(Vmw32_font_request_table, pfr->idx); 
    1937   specs = assq_no_quit(Qstrict_spec, alist); 
    1938   for (;CONSP (specs);specs = XCDR (specs)) 
    1939     { 
    1940       tem = XCAR (specs); 
    1941       if (!CONSP (tem)) continue; 
    1942       spec = XCAR (tem); 
    1943       if (!VECTORP (spec)) continue; 
    1944       tem = XCDR (tem); 
    1945       if (!CONSP (tem)) continue; 
    1946       logfont = XCAR (tem); 
    1947       tem = XCDR (tem); 
    1948  
    1949       if (CONSP (tem) && CONSP (XCAR (tem))) 
    1950           option = XCAR (tem); 
    1951       else option = Qnil; 
    1952  
    1953       if (!mw32_fr_spec_match_p (spec, attrs, c)) continue; 
    1954       plf = mw32_load_lf_from_lisp_object(f, pfr, logfont, option, c); 
    1955       if (plf) return plf; 
    1956     } 
    1957  
    1958   return NULL; 
     1936    option = Qnil; 
     1937 
     1938  return  mw32_load_lf_from_lisp_object(f, pfr, logfont, option, c); 
     1939
     1940 
     1941/* val is (<func>) */ 
     1942static MW32LogicalFont* 
     1943mw32_load_function_spec (Lisp_Object val, 
     1944                         MW32FontRequest *pfr, 
     1945                         struct frame *f, 
     1946                         int c, 
     1947                         Lisp_Object face_attrs) 
     1948
     1949  Lisp_Object func, result, logfont, option; 
     1950  Lisp_Object args[4]; 
     1951 
     1952  if (!CONSP (val)) return NULL; 
     1953 
     1954  func = XCAR (val); 
     1955  if (!FUNCTIONP (func)) return NULL; 
     1956  val = XCDR (val); 
     1957 
     1958  args[0] = func; 
     1959  args[1] = make_number(c); 
     1960  args[2] = face_attrs; 
     1961  XSETFRAME (args[3], f); 
     1962 
     1963  result = safe_call (4, args); 
     1964  if (!CONSP(result)) return NULL; 
     1965 
     1966  option = Qnil; 
     1967  logfont = CAR (result); 
     1968  if (!CONSP (logfont)) 
     1969    { 
     1970      logfont = result; 
     1971      if (CONSP (val)) option = XCAR(val); 
     1972    } 
     1973  else 
     1974    { 
     1975      option = CAR (CDR (result)); 
     1976    } 
     1977  if ((!NILP (option)) && (!CONSP (option))) return NULL; 
     1978 
     1979  return mw32_load_lf_from_lisp_object (f, pfr, logfont, option, c); 
    19591980} 
    19601981 
     
    19721993} 
    19731994 
     1995/* 
     1996  (spec 
     1997    (<specvec> strict <logfont> [<option-alist>]) 
     1998                      or 
     1999    (<specvec> function <func> [<option-alist>]) 
     2000    ...) 
     2001*/ 
     2002 
    19742003static MW32LogicalFont* 
    1975 mw32_elisp_logical_font_loader(MW32FontRequest *pfr, 
    1976                                struct frame *f, 
    1977                                struct face *face, 
    1978                                int c) 
    1979 
     2004mw32_spec_base_font_loader (MW32FontRequest *pfr, 
     2005                            struct frame *f, 
     2006                            struct face *face, 
     2007                            int c) 
     2008
     2009  struct gcpro gcpro1, gcpro2; 
    19802010  MW32LogicalFont *plf; 
    19812011  Lisp_Object *attrs; 
    1982   Lisp_Object alist, func, frame, face_attrs; 
    1983   Lisp_Object result, logfont, option; 
    1984   Lisp_Object args[4]; 
    1985  
    1986   if (!MW32_MAIN_THREAD_P()) return NULL; 
     2012  Lisp_Object alist, specs, tem, spec, type, face_attrs; 
    19872013 
    19882014  if (face) 
     
    19912017    attrs = face_unspecified_attrs; 
    19922018 
     2019  face_attrs = mw32_convert_face_attrs(attrs); 
     2020 
    19932021  alist = AREF(Vmw32_font_request_table, pfr->idx); 
    1994   func = assq_no_quit(Qfunction, alist); 
    1995   if (!CONSP(func)) return NULL; 
    1996   func = CDR (func); 
    1997   if (!FUNCTIONP(func)) return NULL; 
    1998   face_attrs = mw32_convert_face_attrs(attrs); 
    1999  
    2000   /* (lambda (char face-attrs frame)) */ 
    2001   args[0] = func; 
    2002   args[1] = make_number(c); 
    2003   args[2] = face_attrs; 
    2004   XSETFRAME(frame, f); 
    2005   args[3] = frame; 
    2006  
    2007   result = safe_call (4, args); 
    2008   if (!CONSP(result)) return NULL; 
    2009   option = Qnil; 
    2010   logfont = CAR (result); 
    2011   if (!CONSP(logfont)) logfont = result; 
    2012   else option = CAR (CDR (result)); 
    2013   if ((!NILP (option)) && (!CONSP (option))) return NULL; 
    2014  
    2015   plf = mw32_load_lf_from_lisp_object(f, pfr, logfont, option, c); 
    2016  
     2022  specs = assq_no_quit(Qspec, alist); 
     2023  if (!CONSP (specs)) return NULL; 
     2024  specs = XCDR (specs); 
     2025  GCPRO2 (specs, face_attrs); 
     2026 
     2027  plf = NULL; 
     2028  for (; CONSP (specs); specs = XCDR (specs)) 
     2029    { 
     2030      tem = XCAR (specs); 
     2031      if (!CONSP (tem)) continue; 
     2032      spec = XCAR (tem); 
     2033      if (!VECTORP (spec)) continue; 
     2034      if (!mw32_fr_spec_match_p (spec, attrs, c)) continue; 
     2035 
     2036      tem = XCDR (tem); 
     2037      if (!CONSP (tem)) continue; 
     2038      type = XCAR (tem); 
     2039      tem = XCDR (tem); 
     2040 
     2041      if (EQ (type, Qstrict)) 
     2042        plf = mw32_load_strict_spec(tem, pfr, f, c); 
     2043      else if (EQ (type, Qfunction)) 
     2044        plf = mw32_load_function_spec(tem, pfr, f, c, face_attrs); 
     2045 
     2046      if (plf) break; 
     2047    } 
     2048 
     2049  UNGCPRO; 
    20172050  return plf; 
    20182051} 
     
    21822215 
    21832216static void 
     2217mw32_check_font_option (Lisp_Object option) 
     2218{ 
     2219  Lisp_Object encoding, relative_compose, default_ascent; 
     2220  Lisp_Object centering, spacing; 
     2221 
     2222  encoding = mw32_get_font_request_parameter (Qencoding, option); 
     2223  if (!NILP (encoding) && (!mw32_valid_encoding_p (encoding))) 
     2224    Fsignal (Qerror, Fcons (build_string ("Invalid encoding"), 
     2225                            Fcons (encoding, Qnil))); 
     2226 
     2227  relative_compose = mw32_get_font_request_parameter (Qrelative_compose, 
     2228                                                      option); 
     2229  if (!NILP (relative_compose)) CHECK_NUMBER (relative_compose, 0); 
     2230 
     2231  default_ascent = mw32_get_font_request_parameter (Qdefault_ascent, 
     2232                                                    option); 
     2233  if (!NILP (default_ascent)) CHECK_NUMBER (default_ascent, 1); 
     2234 
     2235  spacing = mw32_get_font_request_parameter (Qspacing, option); 
     2236  if (!NILP (spacing)) CHECK_NUMBER (spacing, 2); 
     2237 
     2238  centering = mw32_get_font_request_parameter (Qcentering, option); 
     2239  /* needless to check centering */ 
     2240} 
     2241 
     2242static void 
    21842243mw32_check_font_request_alist (Lisp_Object alist) 
    21852244{ 
    2186   Lisp_Object width, height, base, overhang, encoding; 
    2187   Lisp_Object relative_compose, default_ascent, encoder; 
    2188   Lisp_Object spacing, dim, centering; 
    2189   Lisp_Object fr, spec, logfont, option, tem; 
    2190  
    2191  
    2192   /* check strict-spec */ 
    2193   fr = assq_no_quit (Qstrict_spec, alist); 
     2245  Lisp_Object fr, spec, type, logfont, func, tem; 
     2246 
     2247  /* check spec */ 
     2248  fr = assq_no_quit (Qspec, alist); 
    21942249  for (fr = XCDR (fr); CONSP (fr); fr = XCDR (fr)) 
    21952250    { 
     
    22052260                                Fcons (spec, Qnil))); 
    22062261 
    2207       /* check logfont */ 
     2262      /* check spec value */ 
    22082263      tem = XCDR (tem); 
    22092264      if (!CONSP (tem)) 
    2210         Fsignal (Qerror, Fcons (build_string ("Invalid logfont"), 
     2265        Fsignal (Qerror, Fcons (build_string ("Invalid font spec value"), 
    22112266                                Fcons (tem, Qnil))); 
    2212       logfont = XCAR (tem); 
    2213  
    2214       /* check option */ 
     2267 
     2268      type = XCAR (tem); 
    22152269      tem = XCDR (tem); 
    2216       if (!CONSP (tem)) 
    2217         continue; 
    2218       option = XCAR (tem); 
    2219  
    2220       encoding = mw32_get_font_request_parameter (Qencoding, option); 
    2221       if (!NILP (encoding) && (!mw32_valid_encoding_p (encoding))) 
    2222         Fsignal (Qerror, Fcons (build_string ("Invalid encoding"), 
    2223                                 Fcons (encoding, Qnil))); 
    2224  
    2225       relative_compose = mw32_get_font_request_parameter (Qrelative_compose, 
    2226                                                           option); 
    2227       if (!NILP (relative_compose)) CHECK_NUMBER (relative_compose, 0); 
    2228  
    2229       default_ascent = mw32_get_font_request_parameter (Qdefault_ascent, 
    2230                                                         option); 
    2231       if (!NILP (default_ascent)) CHECK_NUMBER (default_ascent, 1); 
    2232  
    2233       spacing = mw32_get_font_request_parameter (Qspacing, option); 
    2234       if (!NILP (spacing)) CHECK_NUMBER (spacing, 2); 
    2235  
    2236       centering = mw32_get_font_request_parameter (Qcentering, option); 
    2237       /* needless to check centering */ 
    2238     } 
    2239  
    2240   /* check function */ 
    2241   fr = assq_no_quit (Qfunction, alist); 
    2242   if (CONSP (fr)) 
    2243     { 
    2244       Lisp_Object func = CDR (fr); 
    2245       if (!FUNCTIONP (func)) 
    2246         Fsignal (Qerror, Fcons (build_string ("Invalid function"), 
    2247                                 Fcons (func, Qnil))); 
     2270      if (EQ (type, Qstrict)) 
     2271        { 
     2272          if (!CONSP (tem)) 
     2273            Fsignal (Qerror, Fcons (build_string ("Invalid font strict spec value"), 
     2274                                    Fcons (tem, Qnil))); 
     2275          logfont = XCAR (tem); 
     2276          if (!check_lisp_object_logfont (logfont, 1)) 
     2277            { 
     2278              Fsignal (Qerror, Fcons (build_string ("Invalid logfont"), 
     2279                                      Fcons (logfont, Qnil))); 
     2280            } 
     2281          tem = XCDR (tem); 
     2282          if (CONSP (tem)) 
     2283            mw32_check_font_option (XCAR (tem)); 
     2284        } 
     2285      else if (EQ (type, Qfunction)) 
     2286        { 
     2287          if (!CONSP (tem)) 
     2288            Fsignal (Qerror, Fcons (build_string ("Invalid font function spec value"), 
     2289                                    Fcons (tem, Qnil))); 
     2290          func = XCAR (tem); 
     2291          if (!FUNCTIONP (tem)) 
     2292            Fsignal (Qerror, Fcons (build_string ("Invalid function"), 
     2293                                    Fcons (func, Qnil))); 
     2294          tem = XCDR (tem); 
     2295          if (CONSP (tem)) 
     2296            mw32_check_font_option (XCAR (tem)); 
     2297        } 
     2298      else 
     2299        { 
     2300          Fsignal (Qerror, Fcons (build_string ("Invalid font spec type"), 
     2301                                  Fcons (type, Qnil))); 
     2302        } 
    22482303    } 
    22492304} 
     
    26842739  mw32_init_cached_bitmap_slots(); 
    26852740 
    2686   mw32_add_lf_loader(mw32_strict_logical_font_loader); 
    2687   mw32_add_lf_loader(mw32_elisp_logical_font_loader); 
     2741  mw32_add_lf_loader(mw32_spec_base_font_loader); 
    26882742  mw32_add_lf_loader(mw32_default_logical_font_loader); 
    26892743} 
     
    26932747  Qany = intern ("any"); 
    26942748  staticpro (&Qany); 
    2695   Qstrict_spec = intern ("strict-spec"); 
    2696   staticpro (&Qstrict_spec); 
     2749  Qspec = intern ("spec"); 
     2750  staticpro (&Qspec); 
     2751  Qstrict = intern ("strict"); 
     2752  staticpro (&Qstrict); 
    26972753  Qw32_logfont = intern ("w32-logfont"); 
    26982754  staticpro (&Qw32_logfont);