aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenichi Handa2006-06-16 12:12:49 +0000
committerKenichi Handa2006-06-16 12:12:49 +0000
commit2d93c6bd2b000e39a081dcbeb3da39bbff89401e (patch)
tree995bda84d9cdcea8d3d009027b250dd6c1e4507b /src
parente95dad7564e6034d2a227a637bbc97f5c5957f2c (diff)
downloademacs-2d93c6bd2b000e39a081dcbeb3da39bbff89401e.tar.gz
emacs-2d93c6bd2b000e39a081dcbeb3da39bbff89401e.zip
(xftfont_open): Change coding style of error
handling. Generate fontconfig's fontname pattern.
Diffstat (limited to 'src')
-rw-r--r--src/xftfont.c61
1 files changed, 30 insertions, 31 deletions
diff --git a/src/xftfont.c b/src/xftfont.c
index 4bbd856bd56..0ecd39cfff1 100644
--- a/src/xftfont.c
+++ b/src/xftfont.c
@@ -196,14 +196,15 @@ xftfont_open (f, entity, pixel_size)
196 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 196 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
197 Display *display = FRAME_X_DISPLAY (f); 197 Display *display = FRAME_X_DISPLAY (f);
198 Lisp_Object val; 198 Lisp_Object val;
199 FcPattern *pattern, *pat; 199 FcPattern *pattern, *pat = NULL;
200 FcChar8 *file, *name; 200 FcChar8 *file;
201 XFontStruct *xfont; 201 struct xftfont_info *xftfont_info = NULL;
202 struct xftfont_info *xftfont_info; 202 XFontStruct *xfont = NULL;
203 struct font *font; 203 struct font *font;
204 double size = 0; 204 double size = 0;
205 XftFont *xftfont; 205 XftFont *xftfont = NULL;
206 int spacing; 206 int spacing;
207 char *name;
207 int len; 208 int len;
208 209
209 val = AREF (entity, FONT_EXTRA_INDEX); 210 val = AREF (entity, FONT_EXTRA_INDEX);
@@ -217,15 +218,6 @@ xftfont_open (f, entity, pixel_size)
217 size = XINT (AREF (entity, FONT_SIZE_INDEX)); 218 size = XINT (AREF (entity, FONT_SIZE_INDEX));
218 if (size == 0) 219 if (size == 0)
219 size = pixel_size; 220 size = pixel_size;
220 if (FcPatternGetString (pattern, FC_FILE, 1, &name) != FcResultMatch)
221 {
222 int isize = size;
223
224 name = malloc (strlen ((char *) file) + 30);
225 if (! name)
226 return NULL;
227 sprintf (name, ":file=%s:pixelsize=%d", (char *) file, isize);
228 }
229 221
230 pat = FcPatternCreate (); 222 pat = FcPatternCreate ();
231 FcPatternAddString (pat, FC_FILE, file); 223 FcPatternAddString (pat, FC_FILE, file);
@@ -237,26 +229,14 @@ xftfont_open (f, entity, pixel_size)
237 /* We should not destroy PAT here because it is kept in XFTFONT and 229 /* We should not destroy PAT here because it is kept in XFTFONT and
238 destroyed automatically when XFTFONT is closed. */ 230 destroyed automatically when XFTFONT is closed. */
239 if (! xftfont) 231 if (! xftfont)
240 { 232 goto err;
241 UNBLOCK_INPUT;
242 return NULL;
243 }
244 233
245 xftfont_info = malloc (sizeof (struct xftfont_info)); 234 xftfont_info = malloc (sizeof (struct xftfont_info));
246 if (! xftfont_info) 235 if (! xftfont_info)
247 { 236 goto err;
248 XftFontClose (display, xftfont);
249 UNBLOCK_INPUT;
250 return NULL;
251 }
252 xfont = malloc (sizeof (XFontStruct)); 237 xfont = malloc (sizeof (XFontStruct));
253 if (! xftfont_info) 238 if (! xfont)
254 { 239 goto err;
255 XftFontClose (display, xftfont);
256 free (xftfont_info);
257 UNBLOCK_INPUT;
258 return NULL;
259 }
260 xftfont_info->display = display; 240 xftfont_info->display = display;
261 xftfont_info->screen = FRAME_X_SCREEN_NUMBER (f); 241 xftfont_info->screen = FRAME_X_SCREEN_NUMBER (f);
262 xftfont_info->xftfont = xftfont; 242 xftfont_info->xftfont = xftfont;
@@ -266,7 +246,19 @@ xftfont_open (f, entity, pixel_size)
266 font->entity = entity; 246 font->entity = entity;
267 font->pixel_size = size; 247 font->pixel_size = size;
268 font->driver = &xftfont_driver; 248 font->driver = &xftfont_driver;
269 font->font.full_name = font->font.name = (char *) name; 249 len = 64;
250 name = malloc (len);
251 while (name && font_unparse_fcname (entity, pixel_size, name, len) < 0)
252 {
253 char *new = realloc (name, len += 32);
254
255 if (! new)
256 free (name);
257 name = new;
258 }
259 if (! name)
260 goto err;
261 font->font.full_name = font->font.name = name;
270 font->file_name = (char *) file; 262 font->file_name = (char *) file;
271 font->font.size = xftfont->max_advance_width; 263 font->font.size = xftfont->max_advance_width;
272 font->ascent = xftfont->ascent; 264 font->ascent = xftfont->ascent;
@@ -341,6 +333,13 @@ xftfont_open (f, entity, pixel_size)
341 } 333 }
342 334
343 return font; 335 return font;
336
337 err:
338 if (xftfont) XftFontClose (display, xftfont);
339 UNBLOCK_INPUT;
340 if (xftfont_info) free (xftfont_info);
341 if (xfont) free (xfont);
342 return NULL;
344} 343}
345 344
346static void 345static void