comparison src/font-mgr.c @ 5763:23dc211f4d2f

Make fc-name-parse signal on invalid-argument. Add fc-name-parse-harder, which retries without unparseable attributes. Add tests for fc-name-parse and fc-name-parse-harder. A few fixups in comments and docstrings.
author Stephen J. Turnbull <stephen@xemacs.org>
date Sun, 15 Sep 2013 23:50:20 +0900
parents 3192994c49ca
children 15b0715c204d
comparison
equal deleted inserted replaced
5762:427a72c6ee17 5763:23dc211f4d2f
1 /* Lisp font handling implementation for X with Xft. 1 /* Lisp font handling implementation for X with Xft.
2 2
3 Copyright (C) 2003 Eric Knauel and Matthias Neubauer 3 Copyright (C) 2003 Eric Knauel and Matthias Neubauer
4 Copyright (C) 2005 Eric Knauel 4 Copyright (C) 2005 Eric Knauel
5 Copyright (C) 2004-2009 Free Software Foundation, Inc. 5 Copyright (C) 2004-2009, 2013 Free Software Foundation, Inc.
6 Copyright (C) 2010 Ben Wing. 6 Copyright (C) 2010 Ben Wing.
7 7
8 Authors: Eric Knauel <knauel@informatik.uni-tuebingen.de> 8 Authors: Eric Knauel <knauel@informatik.uni-tuebingen.de>
9 Matthias Neubauer <neubauer@informatik.uni-freiburg.de> 9 Matthias Neubauer <neubauer@informatik.uni-freiburg.de>
10 Stephen J. Turnbull <stephen@xemacs.org> 10 Stephen J. Turnbull <stephen@xemacs.org>
141 */ 141 */
142 static Lisp_Object make_xlfd_font_regexp (void); 142 static Lisp_Object make_xlfd_font_regexp (void);
143 static void string_list_to_fcobjectset (Lisp_Object list, FcObjectSet *os); 143 static void string_list_to_fcobjectset (Lisp_Object list, FcObjectSet *os);
144 144
145 /* 145 /*
146 extract the C representation of the Lisp string STR and convert it 146 Extract the C representation of the Lisp string STR and convert it
147 to the encoding used by the Fontconfig API for property and font 147 to the encoding used by the Fontconfig API for property and font
148 names. I suppose that Qnative is the right encoding, the manual 148 names. These functions assume that STR is a Lisp string.
149 doesn't say much about this topic. This functions assumes that STR
150 is a Lisp string.
151 */ 149 */
152 #define extract_fcapi_string(str) \ 150 #define extract_fcapi_string(str) \
153 (LISP_STRING_TO_EXTERNAL ((str), Qfc_font_name_encoding)) 151 (LISP_STRING_TO_EXTERNAL ((str), Qfc_font_name_encoding))
154 152
155 #define build_fcapi_string(str) \ 153 #define build_fcapi_string(str) \
156 (build_extstring ((Extbyte *) (str), Qfc_font_name_encoding)) 154 (build_extstring ((Extbyte *) (str), Qfc_font_name_encoding))
157 155
158 /* #### This homebrew lashup should be replaced with FcConstants. 156 /* #### This homebrew lashup should be replaced with FcConstants.
159 157
158 #### This isn't true any more (fontconfig v2.10.95), if it ever was.
160 fontconfig assumes that objects (property names) are statically allocated, 159 fontconfig assumes that objects (property names) are statically allocated,
161 and you will get bizarre results if you pass Lisp string data or strings 160 and you will get bizarre results if you pass Lisp string data or strings
162 allocated on the stack as objects. fontconfig _does_ copy values, so we 161 allocated on the stack as objects. fontconfig _does_ copy values, so we
163 (I hope) don't have to worry about that member. 162 (I hope) don't have to worry about that member.
164 163
225 ()) 224 ())
226 { 225 {
227 fc_pattern *fcpat = XFC_PATTERN (ALLOC_NORMAL_LISP_OBJECT (fc_pattern)); 226 fc_pattern *fcpat = XFC_PATTERN (ALLOC_NORMAL_LISP_OBJECT (fc_pattern));
228 227
229 fcpat->fcpatPtr = FcPatternCreate (); 228 fcpat->fcpatPtr = FcPatternCreate ();
229 assert (fcpat->fcpatPtr);
230 return wrap_fc_pattern (fcpat); 230 return wrap_fc_pattern (fcpat);
231 } 231 }
232 232
233 DEFUN ("fc-name-parse", Ffc_name_parse, 1, 1, 0, /* 233 DEFUN ("fc-name-parse", Ffc_name_parse, 1, 1, 0, /*
234 Parse an Fc font name and return its representation as a fc pattern object. 234 Parse an Fc font name and return its representation as a Fc pattern object.
235 Signal `invalid-argument' if the name is unparseable.
236
237 Note: The name returned by xft-font-truename has been observed to be
238 unparseable \(in the case of the xft-font-default-font-name). The cause
239 is unknown so you can't assume getting a name from a font instance then
240 instantiating the font again will round-trip. See `fc-name-parse-harder'.
235 */ 241 */
236 (name)) 242 (name))
237 { 243 {
238 fc_pattern *fcpat = XFC_PATTERN (ALLOC_NORMAL_LISP_OBJECT (fc_pattern)); 244 fc_pattern *fcpat = XFC_PATTERN (ALLOC_NORMAL_LISP_OBJECT (fc_pattern));
239 245
240 CHECK_STRING (name); 246 CHECK_STRING (name);
241
242 fcpat->fcpatPtr = FcNameParse ((FcChar8 *) extract_fcapi_string (name)); 247 fcpat->fcpatPtr = FcNameParse ((FcChar8 *) extract_fcapi_string (name));
248 if (!fcpat->fcpatPtr)
249 /* #### Is this the best API? Could return a symbol or similar. */
250 invalid_argument ("unparseable Fc font name", name);
243 return wrap_fc_pattern (fcpat); 251 return wrap_fc_pattern (fcpat);
244 } 252 }
245 253
246 /* #### Ga-a-ack! Xft's similar function is actually a different API. 254 /* #### Ga-a-ack! Xft's similar function is actually a different API.
247 We provide both. */ 255 We provide both. */
1384 Vfc_config_weak_list = make_weak_list (WEAK_LIST_SIMPLE); 1392 Vfc_config_weak_list = make_weak_list (WEAK_LIST_SIMPLE);
1385 staticpro (&Vfc_config_weak_list); 1393 staticpro (&Vfc_config_weak_list);
1386 #endif 1394 #endif
1387 1395
1388 DEFVAR_LISP ("xft-xlfd-font-regexp", &Vxlfd_font_name_regexp /* 1396 DEFVAR_LISP ("xft-xlfd-font-regexp", &Vxlfd_font_name_regexp /*
1389 The regular expression used to match XLFD font names. */ 1397 The regular expression used to match XLFD font names.
1390 ); 1398 */ );
1391 Vxlfd_font_name_regexp = make_xlfd_font_regexp(); 1399 Vxlfd_font_name_regexp = make_xlfd_font_regexp();
1392 } 1400 }
1393 1401
1394 void 1402 void
1395 reinit_vars_of_font_mgr (void) 1403 reinit_vars_of_font_mgr (void)