Commit 60ab5797 authored by Dmitry Antipov's avatar Dmitry Antipov

Use convenient alists to manage per-frame font driver-specific data.

* frame.h (struct frame): Rename font_data_list to...
[HAVE_XFT || HAVE_FREETYPE]: ... font_data, which is a Lisp_Object now.
* font.h (struct font_data_list): Remove; no longer need a special
data type.
(font_put_frame_data, font_get_frame_data) [HAVE_XFT || HAVE_FREETYPE]:
Adjust prototypes.
* font.c (font_put_frame_data, font_get_frame_data)
[HAVE_XFT || HAVE_FREETYPE]: Prefer alist functions to ad-hoc list
management.
* xftfont.c (xftfont_get_xft_draw, xftfont_end_for_frame):
Related users changed.
* ftxfont.c (ftxfont_get_gcs, ftxfont_end_for_frame): Likewise.
Prefer convenient xmalloc and xfree.
parent 95268e98
2014-07-03 Dmitry Antipov <dmantipov@yandex.ru>
Use convenient alists to manage per-frame font driver-specific data.
* frame.h (struct frame): Rename font_data_list to...
[HAVE_XFT || HAVE_FREETYPE]: ... font_data, which is a Lisp_Object now.
* font.h (struct font_data_list): Remove; no longer need a special
data type.
(font_put_frame_data, font_get_frame_data) [HAVE_XFT || HAVE_FREETYPE]:
Adjust prototypes.
* font.c (font_put_frame_data, font_get_frame_data)
[HAVE_XFT || HAVE_FREETYPE]: Prefer alist functions to ad-hoc list
management.
* xftfont.c (xftfont_get_xft_draw, xftfont_end_for_frame):
Related users changed.
* ftxfont.c (ftxfont_get_gcs, ftxfont_end_for_frame): Likewise.
Prefer convenient xmalloc and xfree.
2014-07-03 Eli Zaretskii <eliz@gnu.org>
* dispnew.c (prepare_desired_row): Accept 2 additional arguments:
......
......@@ -3539,53 +3539,34 @@ font_update_drivers (struct frame *f, Lisp_Object new_drivers)
return active_drivers;
}
int
font_put_frame_data (struct frame *f, struct font_driver *driver, void *data)
{
struct font_data_list *list, *prev;
#if defined (HAVE_XFT) || defined (HAVE_FREETYPE)
for (prev = NULL, list = f->font_data_list; list;
prev = list, list = list->next)
if (list->driver == driver)
break;
if (! data)
{
if (list)
{
if (prev)
prev->next = list->next;
else
f->font_data_list = list->next;
xfree (list);
}
return 0;
}
void
font_put_frame_data (struct frame *f, Lisp_Object driver, void *data)
{
Lisp_Object val = assq_no_quit (driver, f->font_data);
if (! list)
if (!data)
f->font_data = Fdelq (val, f->font_data);
else
{
list = xmalloc (sizeof *list);
list->driver = driver;
list->next = f->font_data_list;
f->font_data_list = list;
if (NILP (val))
f->font_data = Fcons (Fcons (driver, make_save_ptr (data)),
f->font_data);
else
XSETCDR (val, make_save_ptr (data));
}
list->data = data;
return 0;
}
void *
font_get_frame_data (struct frame *f, struct font_driver *driver)
font_get_frame_data (struct frame *f, Lisp_Object driver)
{
struct font_data_list *list;
for (list = f->font_data_list; list; list = list->next)
if (list->driver == driver)
break;
if (! list)
return NULL;
return list->data;
Lisp_Object val = assq_no_quit (driver, f->font_data);
return NILP (val) ? NULL : XSAVE_POINTER (XCDR (val), 0);
}
#endif /* HAVE_XFT || HAVE_FREETYPE */
/* Sets attributes on a font. Any properties that appear in ALIST and
BOOLEAN_PROPERTIES or NON_BOOLEAN_PROPERTIES are set on the font.
......
......@@ -723,20 +723,6 @@ struct font_driver_list
struct font_driver_list *next;
};
/* Chain of arbitrary data specific to each font driver.
Each frame has its own font data list at F->font_data_list. */
struct font_data_list
{
/* Pointer to the font driver. */
struct font_driver *driver;
/* Data specific to the font driver. */
void *data;
/* Pointer to the next element of the chain. */
struct font_data_list *next;
};
extern Lisp_Object copy_font_spec (Lisp_Object);
extern Lisp_Object merge_font_spec (Lisp_Object, Lisp_Object);
......@@ -809,11 +795,10 @@ extern void font_fill_lglyph_metrics (Lisp_Object, Lisp_Object);
extern Lisp_Object font_put_extra (Lisp_Object font, Lisp_Object prop,
Lisp_Object val);
extern int font_put_frame_data (struct frame *f,
struct font_driver *driver,
void *data);
extern void *font_get_frame_data (struct frame *f,
struct font_driver *driver);
#if defined (HAVE_XFT) || defined (HAVE_FREETYPE)
extern void font_put_frame_data (struct frame *, Lisp_Object, void *);
extern void *font_get_frame_data (struct frame *f, Lisp_Object);
#endif /* HAVE_XFT || HAVE_FREETYPE */
extern void font_filter_properties (Lisp_Object font,
Lisp_Object alist,
......
......@@ -159,6 +159,11 @@ struct frame
tool bar only supports top. */
Lisp_Object tool_bar_position;
#if defined (HAVE_XFT) || defined (HAVE_FREETYPE)
/* List of data specific to font-driver and frame, but common to faces. */
Lisp_Object font_data;
#endif
/* Beyond here, there should be no more Lisp_Object components. */
/* Cache of realized faces. */
......@@ -328,9 +333,6 @@ struct frame
/* List of font-drivers available on the frame. */
struct font_driver_list *font_driver_list;
/* List of data specific to font-driver and frame, but common to
faces. */
struct font_data_list *font_data_list;
/* Total width of fringes reserved for drawing truncation bitmaps,
continuation bitmaps and alike. The width is in canonical char
......
......@@ -59,7 +59,7 @@ ftxfont_get_gcs (struct frame *f, unsigned long foreground, unsigned long backgr
XColor color;
XGCValues xgcv;
int i;
struct ftxfont_frame_data *data = font_get_frame_data (f, &ftxfont_driver);
struct ftxfont_frame_data *data = font_get_frame_data (f, Qftx);
struct ftxfont_frame_data *prev = NULL, *this = NULL, *new;
if (data)
......@@ -78,19 +78,11 @@ ftxfont_get_gcs (struct frame *f, unsigned long foreground, unsigned long backgr
}
}
new = malloc (sizeof *new);
if (! new)
return NULL;
new = xmalloc (sizeof *new);
new->next = this;
if (prev)
{
prev->next = new;
}
else if (font_put_frame_data (f, &ftxfont_driver, new) < 0)
{
free (new);
return NULL;
}
font_put_frame_data (f, Qftx, new);
new->colors[0].pixel = background;
new->colors[1].pixel = foreground;
......@@ -123,8 +115,8 @@ ftxfont_get_gcs (struct frame *f, unsigned long foreground, unsigned long backgr
if (prev)
prev->next = new->next;
else if (data)
font_put_frame_data (f, &ftxfont_driver, new->next);
free (new);
font_put_frame_data (f, Qftx, new->next);
xfree (new);
return NULL;
}
return new->gcs;
......@@ -337,7 +329,7 @@ ftxfont_draw (struct glyph_string *s, int from, int to, int x, int y,
static int
ftxfont_end_for_frame (struct frame *f)
{
struct ftxfont_frame_data *data = font_get_frame_data (f, &ftxfont_driver);
struct ftxfont_frame_data *data = font_get_frame_data (f, Qftx);
block_input ();
while (data)
......@@ -347,11 +339,11 @@ ftxfont_end_for_frame (struct frame *f)
for (i = 0; i < 6; i++)
XFreeGC (FRAME_X_DISPLAY (f), data->gcs[i]);
free (data);
xfree (data);
data = next;
}
unblock_input ();
font_put_frame_data (f, &ftxfont_driver, NULL);
font_put_frame_data (f, Qftx, NULL);
return 0;
}
......
......@@ -593,7 +593,7 @@ xftfont_text_extents (struct font *font, unsigned int *code, int nglyphs, struct
static XftDraw *
xftfont_get_xft_draw (struct frame *f)
{
XftDraw *xft_draw = font_get_frame_data (f, &xftfont_driver);
XftDraw *xft_draw = font_get_frame_data (f, Qxft);
if (! xft_draw)
{
......@@ -604,7 +604,7 @@ xftfont_get_xft_draw (struct frame *f)
FRAME_X_COLORMAP (f));
unblock_input ();
eassert (xft_draw != NULL);
font_put_frame_data (f, &xftfont_driver, xft_draw);
font_put_frame_data (f, Qxft, xft_draw);
}
return xft_draw;
}
......@@ -680,14 +680,14 @@ xftfont_end_for_frame (struct frame *f)
/* Don't do anything if display is dead */
if (FRAME_X_DISPLAY (f) == NULL) return 0;
xft_draw = font_get_frame_data (f, &xftfont_driver);
xft_draw = font_get_frame_data (f, Qxft);
if (xft_draw)
{
block_input ();
XftDrawDestroy (xft_draw);
unblock_input ();
font_put_frame_data (f, &xftfont_driver, NULL);
font_put_frame_data (f, Qxft, NULL);
}
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment