diff options
| author | Dmitry Antipov | 2014-07-03 16:20:00 +0400 |
|---|---|---|
| committer | Dmitry Antipov | 2014-07-03 16:20:00 +0400 |
| commit | 60ab579771527dcc29547119f2c1b7099eda4d55 (patch) | |
| tree | 8804ef001fbd3b73845b9f5dc690dd188054a6f6 /src | |
| parent | 95268e987c484b98aac3de54cf91d65db16f4c22 (diff) | |
| download | emacs-60ab579771527dcc29547119f2c1b7099eda4d55.tar.gz emacs-60ab579771527dcc29547119f2c1b7099eda4d55.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 17 | ||||
| -rw-r--r-- | src/font.c | 55 | ||||
| -rw-r--r-- | src/font.h | 23 | ||||
| -rw-r--r-- | src/frame.h | 8 | ||||
| -rw-r--r-- | src/ftxfont.c | 24 | ||||
| -rw-r--r-- | src/xftfont.c | 8 |
6 files changed, 56 insertions, 79 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 0f9b7431462..7fb620fc533 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,20 @@ | |||
| 1 | 2014-07-03 Dmitry Antipov <dmantipov@yandex.ru> | ||
| 2 | |||
| 3 | Use convenient alists to manage per-frame font driver-specific data. | ||
| 4 | * frame.h (struct frame): Rename font_data_list to... | ||
| 5 | [HAVE_XFT || HAVE_FREETYPE]: ... font_data, which is a Lisp_Object now. | ||
| 6 | * font.h (struct font_data_list): Remove; no longer need a special | ||
| 7 | data type. | ||
| 8 | (font_put_frame_data, font_get_frame_data) [HAVE_XFT || HAVE_FREETYPE]: | ||
| 9 | Adjust prototypes. | ||
| 10 | * font.c (font_put_frame_data, font_get_frame_data) | ||
| 11 | [HAVE_XFT || HAVE_FREETYPE]: Prefer alist functions to ad-hoc list | ||
| 12 | management. | ||
| 13 | * xftfont.c (xftfont_get_xft_draw, xftfont_end_for_frame): | ||
| 14 | Related users changed. | ||
| 15 | * ftxfont.c (ftxfont_get_gcs, ftxfont_end_for_frame): Likewise. | ||
| 16 | Prefer convenient xmalloc and xfree. | ||
| 17 | |||
| 1 | 2014-07-03 Eli Zaretskii <eliz@gnu.org> | 18 | 2014-07-03 Eli Zaretskii <eliz@gnu.org> |
| 2 | 19 | ||
| 3 | * dispnew.c (prepare_desired_row): Accept 2 additional arguments: | 20 | * dispnew.c (prepare_desired_row): Accept 2 additional arguments: |
diff --git a/src/font.c b/src/font.c index 251d43ba8b2..7b9edcd3fb8 100644 --- a/src/font.c +++ b/src/font.c | |||
| @@ -3539,53 +3539,34 @@ font_update_drivers (struct frame *f, Lisp_Object new_drivers) | |||
| 3539 | return active_drivers; | 3539 | return active_drivers; |
| 3540 | } | 3540 | } |
| 3541 | 3541 | ||
| 3542 | int | 3542 | #if defined (HAVE_XFT) || defined (HAVE_FREETYPE) |
| 3543 | font_put_frame_data (struct frame *f, struct font_driver *driver, void *data) | ||
| 3544 | { | ||
| 3545 | struct font_data_list *list, *prev; | ||
| 3546 | 3543 | ||
| 3547 | for (prev = NULL, list = f->font_data_list; list; | 3544 | void |
| 3548 | prev = list, list = list->next) | 3545 | font_put_frame_data (struct frame *f, Lisp_Object driver, void *data) |
| 3549 | if (list->driver == driver) | 3546 | { |
| 3550 | break; | 3547 | Lisp_Object val = assq_no_quit (driver, f->font_data); |
| 3551 | if (! data) | ||
| 3552 | { | ||
| 3553 | if (list) | ||
| 3554 | { | ||
| 3555 | if (prev) | ||
| 3556 | prev->next = list->next; | ||
| 3557 | else | ||
| 3558 | f->font_data_list = list->next; | ||
| 3559 | xfree (list); | ||
| 3560 | } | ||
| 3561 | return 0; | ||
| 3562 | } | ||
| 3563 | 3548 | ||
| 3564 | if (! list) | 3549 | if (!data) |
| 3550 | f->font_data = Fdelq (val, f->font_data); | ||
| 3551 | else | ||
| 3565 | { | 3552 | { |
| 3566 | list = xmalloc (sizeof *list); | 3553 | if (NILP (val)) |
| 3567 | list->driver = driver; | 3554 | f->font_data = Fcons (Fcons (driver, make_save_ptr (data)), |
| 3568 | list->next = f->font_data_list; | 3555 | f->font_data); |
| 3569 | f->font_data_list = list; | 3556 | else |
| 3557 | XSETCDR (val, make_save_ptr (data)); | ||
| 3570 | } | 3558 | } |
| 3571 | list->data = data; | ||
| 3572 | return 0; | ||
| 3573 | } | 3559 | } |
| 3574 | 3560 | ||
| 3575 | |||
| 3576 | void * | 3561 | void * |
| 3577 | font_get_frame_data (struct frame *f, struct font_driver *driver) | 3562 | font_get_frame_data (struct frame *f, Lisp_Object driver) |
| 3578 | { | 3563 | { |
| 3579 | struct font_data_list *list; | 3564 | Lisp_Object val = assq_no_quit (driver, f->font_data); |
| 3580 | 3565 | ||
| 3581 | for (list = f->font_data_list; list; list = list->next) | 3566 | return NILP (val) ? NULL : XSAVE_POINTER (XCDR (val), 0); |
| 3582 | if (list->driver == driver) | ||
| 3583 | break; | ||
| 3584 | if (! list) | ||
| 3585 | return NULL; | ||
| 3586 | return list->data; | ||
| 3587 | } | 3567 | } |
| 3588 | 3568 | ||
| 3569 | #endif /* HAVE_XFT || HAVE_FREETYPE */ | ||
| 3589 | 3570 | ||
| 3590 | /* Sets attributes on a font. Any properties that appear in ALIST and | 3571 | /* Sets attributes on a font. Any properties that appear in ALIST and |
| 3591 | BOOLEAN_PROPERTIES or NON_BOOLEAN_PROPERTIES are set on the font. | 3572 | BOOLEAN_PROPERTIES or NON_BOOLEAN_PROPERTIES are set on the font. |
diff --git a/src/font.h b/src/font.h index 42137deeaa4..a41762db975 100644 --- a/src/font.h +++ b/src/font.h | |||
| @@ -723,20 +723,6 @@ struct font_driver_list | |||
| 723 | struct font_driver_list *next; | 723 | struct font_driver_list *next; |
| 724 | }; | 724 | }; |
| 725 | 725 | ||
| 726 | |||
| 727 | /* Chain of arbitrary data specific to each font driver. | ||
| 728 | Each frame has its own font data list at F->font_data_list. */ | ||
| 729 | |||
| 730 | struct font_data_list | ||
| 731 | { | ||
| 732 | /* Pointer to the font driver. */ | ||
| 733 | struct font_driver *driver; | ||
| 734 | /* Data specific to the font driver. */ | ||
| 735 | void *data; | ||
| 736 | /* Pointer to the next element of the chain. */ | ||
| 737 | struct font_data_list *next; | ||
| 738 | }; | ||
| 739 | |||
| 740 | extern Lisp_Object copy_font_spec (Lisp_Object); | 726 | extern Lisp_Object copy_font_spec (Lisp_Object); |
| 741 | extern Lisp_Object merge_font_spec (Lisp_Object, Lisp_Object); | 727 | extern Lisp_Object merge_font_spec (Lisp_Object, Lisp_Object); |
| 742 | 728 | ||
| @@ -809,11 +795,10 @@ extern void font_fill_lglyph_metrics (Lisp_Object, Lisp_Object); | |||
| 809 | extern Lisp_Object font_put_extra (Lisp_Object font, Lisp_Object prop, | 795 | extern Lisp_Object font_put_extra (Lisp_Object font, Lisp_Object prop, |
| 810 | Lisp_Object val); | 796 | Lisp_Object val); |
| 811 | 797 | ||
| 812 | extern int font_put_frame_data (struct frame *f, | 798 | #if defined (HAVE_XFT) || defined (HAVE_FREETYPE) |
| 813 | struct font_driver *driver, | 799 | extern void font_put_frame_data (struct frame *, Lisp_Object, void *); |
| 814 | void *data); | 800 | extern void *font_get_frame_data (struct frame *f, Lisp_Object); |
| 815 | extern void *font_get_frame_data (struct frame *f, | 801 | #endif /* HAVE_XFT || HAVE_FREETYPE */ |
| 816 | struct font_driver *driver); | ||
| 817 | 802 | ||
| 818 | extern void font_filter_properties (Lisp_Object font, | 803 | extern void font_filter_properties (Lisp_Object font, |
| 819 | Lisp_Object alist, | 804 | Lisp_Object alist, |
diff --git a/src/frame.h b/src/frame.h index 2da9fff2d4a..4fb98278a51 100644 --- a/src/frame.h +++ b/src/frame.h | |||
| @@ -159,6 +159,11 @@ struct frame | |||
| 159 | tool bar only supports top. */ | 159 | tool bar only supports top. */ |
| 160 | Lisp_Object tool_bar_position; | 160 | Lisp_Object tool_bar_position; |
| 161 | 161 | ||
| 162 | #if defined (HAVE_XFT) || defined (HAVE_FREETYPE) | ||
| 163 | /* List of data specific to font-driver and frame, but common to faces. */ | ||
| 164 | Lisp_Object font_data; | ||
| 165 | #endif | ||
| 166 | |||
| 162 | /* Beyond here, there should be no more Lisp_Object components. */ | 167 | /* Beyond here, there should be no more Lisp_Object components. */ |
| 163 | 168 | ||
| 164 | /* Cache of realized faces. */ | 169 | /* Cache of realized faces. */ |
| @@ -328,9 +333,6 @@ struct frame | |||
| 328 | 333 | ||
| 329 | /* List of font-drivers available on the frame. */ | 334 | /* List of font-drivers available on the frame. */ |
| 330 | struct font_driver_list *font_driver_list; | 335 | struct font_driver_list *font_driver_list; |
| 331 | /* List of data specific to font-driver and frame, but common to | ||
| 332 | faces. */ | ||
| 333 | struct font_data_list *font_data_list; | ||
| 334 | 336 | ||
| 335 | /* Total width of fringes reserved for drawing truncation bitmaps, | 337 | /* Total width of fringes reserved for drawing truncation bitmaps, |
| 336 | continuation bitmaps and alike. The width is in canonical char | 338 | continuation bitmaps and alike. The width is in canonical char |
diff --git a/src/ftxfont.c b/src/ftxfont.c index 53f2616bb62..63e3477ebf4 100644 --- a/src/ftxfont.c +++ b/src/ftxfont.c | |||
| @@ -59,7 +59,7 @@ ftxfont_get_gcs (struct frame *f, unsigned long foreground, unsigned long backgr | |||
| 59 | XColor color; | 59 | XColor color; |
| 60 | XGCValues xgcv; | 60 | XGCValues xgcv; |
| 61 | int i; | 61 | int i; |
| 62 | struct ftxfont_frame_data *data = font_get_frame_data (f, &ftxfont_driver); | 62 | struct ftxfont_frame_data *data = font_get_frame_data (f, Qftx); |
| 63 | struct ftxfont_frame_data *prev = NULL, *this = NULL, *new; | 63 | struct ftxfont_frame_data *prev = NULL, *this = NULL, *new; |
| 64 | 64 | ||
| 65 | if (data) | 65 | if (data) |
| @@ -78,19 +78,11 @@ ftxfont_get_gcs (struct frame *f, unsigned long foreground, unsigned long backgr | |||
| 78 | } | 78 | } |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | new = malloc (sizeof *new); | 81 | new = xmalloc (sizeof *new); |
| 82 | if (! new) | ||
| 83 | return NULL; | ||
| 84 | new->next = this; | 82 | new->next = this; |
| 85 | if (prev) | 83 | if (prev) |
| 86 | { | ||
| 87 | prev->next = new; | 84 | prev->next = new; |
| 88 | } | 85 | font_put_frame_data (f, Qftx, new); |
| 89 | else if (font_put_frame_data (f, &ftxfont_driver, new) < 0) | ||
| 90 | { | ||
| 91 | free (new); | ||
| 92 | return NULL; | ||
| 93 | } | ||
| 94 | 86 | ||
| 95 | new->colors[0].pixel = background; | 87 | new->colors[0].pixel = background; |
| 96 | new->colors[1].pixel = foreground; | 88 | new->colors[1].pixel = foreground; |
| @@ -123,8 +115,8 @@ ftxfont_get_gcs (struct frame *f, unsigned long foreground, unsigned long backgr | |||
| 123 | if (prev) | 115 | if (prev) |
| 124 | prev->next = new->next; | 116 | prev->next = new->next; |
| 125 | else if (data) | 117 | else if (data) |
| 126 | font_put_frame_data (f, &ftxfont_driver, new->next); | 118 | font_put_frame_data (f, Qftx, new->next); |
| 127 | free (new); | 119 | xfree (new); |
| 128 | return NULL; | 120 | return NULL; |
| 129 | } | 121 | } |
| 130 | return new->gcs; | 122 | return new->gcs; |
| @@ -337,7 +329,7 @@ ftxfont_draw (struct glyph_string *s, int from, int to, int x, int y, | |||
| 337 | static int | 329 | static int |
| 338 | ftxfont_end_for_frame (struct frame *f) | 330 | ftxfont_end_for_frame (struct frame *f) |
| 339 | { | 331 | { |
| 340 | struct ftxfont_frame_data *data = font_get_frame_data (f, &ftxfont_driver); | 332 | struct ftxfont_frame_data *data = font_get_frame_data (f, Qftx); |
| 341 | 333 | ||
| 342 | block_input (); | 334 | block_input (); |
| 343 | while (data) | 335 | while (data) |
| @@ -347,11 +339,11 @@ ftxfont_end_for_frame (struct frame *f) | |||
| 347 | 339 | ||
| 348 | for (i = 0; i < 6; i++) | 340 | for (i = 0; i < 6; i++) |
| 349 | XFreeGC (FRAME_X_DISPLAY (f), data->gcs[i]); | 341 | XFreeGC (FRAME_X_DISPLAY (f), data->gcs[i]); |
| 350 | free (data); | 342 | xfree (data); |
| 351 | data = next; | 343 | data = next; |
| 352 | } | 344 | } |
| 353 | unblock_input (); | 345 | unblock_input (); |
| 354 | font_put_frame_data (f, &ftxfont_driver, NULL); | 346 | font_put_frame_data (f, Qftx, NULL); |
| 355 | return 0; | 347 | return 0; |
| 356 | } | 348 | } |
| 357 | 349 | ||
diff --git a/src/xftfont.c b/src/xftfont.c index 2b4ec065734..bd3f2c92142 100644 --- a/src/xftfont.c +++ b/src/xftfont.c | |||
| @@ -593,7 +593,7 @@ xftfont_text_extents (struct font *font, unsigned int *code, int nglyphs, struct | |||
| 593 | static XftDraw * | 593 | static XftDraw * |
| 594 | xftfont_get_xft_draw (struct frame *f) | 594 | xftfont_get_xft_draw (struct frame *f) |
| 595 | { | 595 | { |
| 596 | XftDraw *xft_draw = font_get_frame_data (f, &xftfont_driver); | 596 | XftDraw *xft_draw = font_get_frame_data (f, Qxft); |
| 597 | 597 | ||
| 598 | if (! xft_draw) | 598 | if (! xft_draw) |
| 599 | { | 599 | { |
| @@ -604,7 +604,7 @@ xftfont_get_xft_draw (struct frame *f) | |||
| 604 | FRAME_X_COLORMAP (f)); | 604 | FRAME_X_COLORMAP (f)); |
| 605 | unblock_input (); | 605 | unblock_input (); |
| 606 | eassert (xft_draw != NULL); | 606 | eassert (xft_draw != NULL); |
| 607 | font_put_frame_data (f, &xftfont_driver, xft_draw); | 607 | font_put_frame_data (f, Qxft, xft_draw); |
| 608 | } | 608 | } |
| 609 | return xft_draw; | 609 | return xft_draw; |
| 610 | } | 610 | } |
| @@ -680,14 +680,14 @@ xftfont_end_for_frame (struct frame *f) | |||
| 680 | /* Don't do anything if display is dead */ | 680 | /* Don't do anything if display is dead */ |
| 681 | if (FRAME_X_DISPLAY (f) == NULL) return 0; | 681 | if (FRAME_X_DISPLAY (f) == NULL) return 0; |
| 682 | 682 | ||
| 683 | xft_draw = font_get_frame_data (f, &xftfont_driver); | 683 | xft_draw = font_get_frame_data (f, Qxft); |
| 684 | 684 | ||
| 685 | if (xft_draw) | 685 | if (xft_draw) |
| 686 | { | 686 | { |
| 687 | block_input (); | 687 | block_input (); |
| 688 | XftDrawDestroy (xft_draw); | 688 | XftDrawDestroy (xft_draw); |
| 689 | unblock_input (); | 689 | unblock_input (); |
| 690 | font_put_frame_data (f, &xftfont_driver, NULL); | 690 | font_put_frame_data (f, Qxft, NULL); |
| 691 | } | 691 | } |
| 692 | return 0; | 692 | return 0; |
| 693 | } | 693 | } |