emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] harfbuzz 015a6e1: Unify three font info structures


From: Robert Pluim
Subject: [Emacs-diffs] harfbuzz 015a6e1: Unify three font info structures
Date: Fri, 8 Feb 2019 09:37:40 -0500 (EST)

branch: harfbuzz
commit 015a6e1df2772bd43680df5cbeaffccf98a881da
Author: Robert Pluim <address@hidden>
Commit: Robert Pluim <address@hidden>

    Unify three font info structures
    
    * src/ftfont.h (struct font_info): New type, unifies similar types
    from ftcrfont.c, ftfont.c and xftfont.c
    * src/xftfont.c (struct xftfont_info): Remove, replace with struct
    font_info.  Adjust all uses.
    * src/ftcrfont.c (struct ftcrfont_info): Likewise.
    * src/ftfont.c (struct ftfont_info): Likewise.
    
    (cherry picked from commit 9e0d69b5a17a0fa3b0dd099a51584a85f3ddb5bf)
---
 src/ftcrfont.c | 45 ++++++-----------------------------------
 src/ftfont.c   | 63 ++++++++++++++++++++++++----------------------------------
 src/ftfont.h   | 40 +++++++++++++++++++++++++++++++++----
 src/xftfont.c  | 46 ++++++++++--------------------------------
 4 files changed, 79 insertions(+), 115 deletions(-)

diff --git a/src/ftcrfont.c b/src/ftcrfont.c
index 95ff893..45e526d 100644
--- a/src/ftcrfont.c
+++ b/src/ftcrfont.c
@@ -27,36 +27,6 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
 #include "font.h"
 #include "ftfont.h"
 
-/* FTCR font driver.  */
-
-/* The actual structure for FTCR font.  A pointer to this structure
-   can be cast to struct font *.  */
-
-struct ftcrfont_info
-{
-  struct font font;
-  /* The following six members must be here in this order to be
-     compatible with struct ftfont_info (in ftfont.c).  */
-#ifdef HAVE_LIBOTF
-  bool maybe_otf;        /* Flag to tell if this may be OTF or not.  */
-  OTF *otf;
-#endif /* HAVE_LIBOTF */
-#ifdef HAVE_HARFBUZZ
-  hb_font_t *hb_font;
-#endif  /* HAVE_HARFBUZZ */
-  FT_Size ft_size;
-  int index;
-  FT_Matrix matrix;
-
-  cairo_font_face_t *cr_font_face;
-  /* To prevent cairo from cluttering the activated FT_Size maintained
-     in ftfont.c, we activate this special FT_Size before drawing.  */
-  FT_Size ft_size_draw;
-  /* Font metrics cache.  */
-  struct font_metrics **metrics;
-  short metrics_nrows;
-};
-
 #define METRICS_NCOLS_PER_ROW  (128)
 
 enum metrics_status
@@ -73,7 +43,7 @@ ftcrfont_glyph_extents (struct font *font,
                         unsigned glyph,
                         struct font_metrics *metrics)
 {
-  struct ftcrfont_info *ftcrfont_info = (struct ftcrfont_info *) font;
+  struct font_info *ftcrfont_info = (struct font_info *) font;
   int row, col;
   struct font_metrics *cache;
 
@@ -135,7 +105,7 @@ ftcrfont_open (struct frame *f, Lisp_Object entity, int 
pixel_size)
 {
   Lisp_Object font_object;
   struct font *font;
-  struct ftcrfont_info *ftcrfont_info;
+  struct font_info *ftcrfont_info;
   FT_Face ft_face;
   FT_UInt size;
 
@@ -143,14 +113,14 @@ ftcrfont_open (struct frame *f, Lisp_Object entity, int 
pixel_size)
   size = XFIXNUM (AREF (entity, FONT_SIZE_INDEX));
   if (size == 0)
     size = pixel_size;
-  font_object = font_build_object (VECSIZE (struct ftcrfont_info),
+  font_object = font_build_object (VECSIZE (struct font_info),
                                   Qftcr, entity, size);
   font_object = ftfont_open2 (f, entity, pixel_size, font_object);
   if (NILP (font_object)) return Qnil;
 
   font = XFONT_OBJECT (font_object);
   font->driver = &ftcrfont_driver;
-  ftcrfont_info = (struct ftcrfont_info *) font;
+  ftcrfont_info = (struct font_info *) font;
   ft_face = ftcrfont_info->ft_size->face;
   FT_New_Size (ft_face, &ftcrfont_info->ft_size_draw);
   FT_Activate_Size (ftcrfont_info->ft_size_draw);
@@ -170,7 +140,7 @@ ftcrfont_close (struct font *font)
   if (font_data_structures_may_be_ill_formed ())
     return;
 
-  struct ftcrfont_info *ftcrfont_info = (struct ftcrfont_info *) font;
+  struct font_info *ftcrfont_info = (struct font_info *) font;
   int i;
 
   block_input ();
@@ -226,7 +196,7 @@ ftcrfont_draw (struct glyph_string *s,
 {
   struct frame *f = s->f;
   struct face *face = s->face;
-  struct ftcrfont_info *ftcrfont_info = (struct ftcrfont_info *) s->font;
+  struct font_info *ftcrfont_info = (struct font_info *) s->font;
   cairo_t *cr;
   cairo_glyph_t *glyphs;
   cairo_surface_t *surface;
@@ -315,9 +285,6 @@ struct font_driver const ftcrfont_driver =
 void
 syms_of_ftcrfont (void)
 {
-  if (ftfont_info_size != offsetof (struct ftcrfont_info, cr_font_face))
-    abort ();
-
   DEFSYM (Qftcr, "ftcr");
   register_font_driver (&ftcrfont_driver, NULL);
 }
diff --git a/src/ftfont.c b/src/ftfont.c
index c266287..63df123 100644
--- a/src/ftfont.c
+++ b/src/ftfont.c
@@ -24,6 +24,17 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
 #include <fontconfig/fontconfig.h>
 #include <fontconfig/fcfreetype.h>
 
+/* These two blocks are here because this file is built when using XFT
+   and when using Cairo, so struct font_info in ftfont.h needs access
+   to the appropriate types.  */
+#ifdef HAVE_XFT
+# include <X11/Xlib.h>
+# include <X11/Xft/Xft.h>
+#endif
+#ifdef USE_CAIRO
+# include <cairo-ft.h>
+#endif
+
 #include <c-strcase.h>
 
 #include "lisp.h"
@@ -49,28 +60,6 @@ static Lisp_Object freetype_font_cache;
 /* Cache for FT_Face and FcCharSet. */
 static Lisp_Object ft_face_cache;
 
-/* The actual structure for FreeType font that can be cast to struct
-   font.  */
-
-struct ftfont_info
-{
-  struct font font;
-#ifdef HAVE_LIBOTF
-  /* The following four members must be here in this order to be
-     compatible with struct xftfont_info (in xftfont.c).  */
-  bool maybe_otf;      /* Flag to tell if this may be OTF or not.  */
-  OTF *otf;
-#endif /* HAVE_LIBOTF */
-#ifdef HAVE_HARFBUZZ
-  hb_font_t *hb_font;
-#endif  /* HAVE_HARFBUZZ */
-  FT_Size ft_size;
-  int index;
-  FT_Matrix matrix;
-};
-
-size_t ftfont_info_size = sizeof (struct ftfont_info);
-
 enum ftfont_cache_for
   {
     FTFONT_CACHE_FOR_FACE,
@@ -455,7 +444,7 @@ ftfont_get_fc_charset (Lisp_Object entity)
 
 #ifdef HAVE_LIBOTF
 static OTF *
-ftfont_get_otf (struct ftfont_info *ftfont_info)
+ftfont_get_otf (struct font_info *ftfont_info)
 {
   OTF *otf;
 
@@ -479,7 +468,7 @@ ftfont_get_otf (struct ftfont_info *ftfont_info)
 #ifdef HAVE_HARFBUZZ
 
 static hb_font_t *
-ftfont_get_hb_font (struct ftfont_info *ftfont_info)
+ftfont_get_hb_font (struct font_info *ftfont_info)
 {
   if (! ftfont_info->hb_font)
     ftfont_info->hb_font
@@ -1111,7 +1100,7 @@ ftfont_open2 (struct frame *f,
               int pixel_size,
               Lisp_Object font_object)
 {
-  struct ftfont_info *ftfont_info;
+  struct font_info *ftfont_info;
   struct font *font;
   struct ftfont_cache_data *cache_data;
   FT_Face ft_face;
@@ -1162,7 +1151,7 @@ ftfont_open2 (struct frame *f,
 
   ASET (font_object, FONT_FILE_INDEX, filename);
   font = XFONT_OBJECT (font_object);
-  ftfont_info = (struct ftfont_info *) font;
+  ftfont_info = (struct font_info *) font;
   ftfont_info->ft_size = ft_face->size;
   ftfont_info->index = XFIXNUM (idx);
 #ifdef HAVE_LIBOTF
@@ -1255,7 +1244,7 @@ ftfont_open (struct frame *f, Lisp_Object entity, int 
pixel_size)
   size = XFIXNUM (AREF (entity, FONT_SIZE_INDEX));
   if (size == 0)
     size = pixel_size;
-  font_object = font_build_object (VECSIZE (struct ftfont_info),
+  font_object = font_build_object (VECSIZE (struct font_info),
                                   Qfreetype, entity, size);
   return ftfont_open2 (f, entity, pixel_size, font_object);
 }
@@ -1266,7 +1255,7 @@ ftfont_close (struct font *font)
   if (font_data_structures_may_be_ill_formed ())
     return;
 
-  struct ftfont_info *ftfont_info = (struct ftfont_info *) font;
+  struct font_info *ftfont_info = (struct font_info *) font;
   Lisp_Object val, cache;
 
   val = Fcons (font->props[FONT_FILE_INDEX], make_fixnum (ftfont_info->index));
@@ -1314,9 +1303,9 @@ ftfont_has_char (Lisp_Object font, int c)
     }
   else
     {
-      struct ftfont_info *ftfont_info;
+      struct font_info *ftfont_info;
 
-      ftfont_info = (struct ftfont_info *) XFONT_OBJECT (font);
+      ftfont_info = (struct font_info *) XFONT_OBJECT (font);
       return (FT_Get_Char_Index (ftfont_info->ft_size->face, (FT_ULong) c)
              != 0);
     }
@@ -1325,7 +1314,7 @@ ftfont_has_char (Lisp_Object font, int c)
 unsigned
 ftfont_encode_char (struct font *font, int c)
 {
-  struct ftfont_info *ftfont_info = (struct ftfont_info *) font;
+  struct font_info *ftfont_info = (struct font_info *) font;
   FT_Face ft_face = ftfont_info->ft_size->face;
   FT_ULong charcode = c;
   FT_UInt code = FT_Get_Char_Index (ft_face, charcode);
@@ -1355,7 +1344,7 @@ void
 ftfont_text_extents (struct font *font, unsigned int *code,
                     int nglyphs, struct font_metrics *metrics)
 {
-  struct ftfont_info *ftfont_info = (struct ftfont_info *) font;
+  struct font_info *ftfont_info = (struct font_info *) font;
   FT_Face ft_face = ftfont_info->ft_size->face;
   int i, width = 0;
   bool first;
@@ -1396,7 +1385,7 @@ ftfont_text_extents (struct font *font, unsigned int 
*code,
 int
 ftfont_get_bitmap (struct font *font, unsigned int code, struct font_bitmap 
*bitmap, int bits_per_pixel)
 {
-  struct ftfont_info *ftfont_info = (struct ftfont_info *) font;
+  struct font_info *ftfont_info = (struct font_info *) font;
   FT_Face ft_face = ftfont_info->ft_size->face;
   FT_Int32 load_flags = FT_LOAD_RENDER;
 
@@ -1440,7 +1429,7 @@ int
 ftfont_anchor_point (struct font *font, unsigned int code, int idx,
                     int *x, int *y)
 {
-  struct ftfont_info *ftfont_info = (struct ftfont_info *) font;
+  struct font_info *ftfont_info = (struct font_info *) font;
   FT_Face ft_face = ftfont_info->ft_size->face;
 
   if (ftfont_info->ft_size != ft_face->size)
@@ -1505,7 +1494,7 @@ ftfont_otf_features (OTF_GSUB_GPOS *gsub_gpos)
 Lisp_Object
 ftfont_otf_capability (struct font *font)
 {
-  struct ftfont_info *ftfont_info = (struct ftfont_info *) font;
+  struct font_info *ftfont_info = (struct font_info *) font;
   OTF *otf = ftfont_get_otf (ftfont_info);
   Lisp_Object gsub_gpos;
 
@@ -2658,7 +2647,7 @@ ftfont_shape_by_flt (Lisp_Object lgstring, struct font 
*font,
 int
 ftfont_variation_glyphs (struct font *font, int c, unsigned variations[256])
 {
-  struct ftfont_info *ftfont_info = (struct ftfont_info *) font;
+  struct font_info *ftfont_info = (struct font_info *) font;
   OTF *otf = ftfont_get_otf (ftfont_info);
 
   if (! otf)
@@ -2946,7 +2935,7 @@ Lisp_Object
 ftfont_shape (Lisp_Object lgstring, Lisp_Object direction)
 {
   struct font *font = CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring));
-  struct ftfont_info *ftfont_info = (struct ftfont_info *) font;
+  struct font_info *ftfont_info = (struct font_info *) font;
 #ifdef HAVE_HARFBUZZ
   if (getenv ("EMACS_NO_HARFBUZZ") == NULL)
     {
diff --git a/src/ftfont.h b/src/ftfont.h
index d856c10..3bbcbfb 100644
--- a/src/ftfont.h
+++ b/src/ftfont.h
@@ -26,7 +26,7 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
 #include FT_FREETYPE_H
 #include FT_SIZES_H
 #ifdef FT_BDF_H
-#include FT_BDF_H
+# include FT_BDF_H
 #endif
 
 #ifdef HAVE_HARFBUZZ
@@ -35,9 +35,9 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
 #endif  /* HAVE_HARFBUZZ */
 
 #ifdef HAVE_LIBOTF
-#include <otf.h>
+# include <otf.h>
 #ifdef HAVE_M17N_FLT
-#include <m17n-flt.h>
+# include <m17n-flt.h>
 #endif /* HAVE_M17N_FLT */
 #endif /* HAVE_LIBOTF */
 
@@ -46,6 +46,38 @@ extern Lisp_Object ftfont_open2 (struct frame *f,
                                  Lisp_Object entity,
                                  int pixel_size,
                                  Lisp_Object font_object);
-extern size_t ftfont_info_size;
+
+/* This struct is shared by the XFT, Freetype, and Cairo font
+   backends.  Members up to and including 'matrix' are common, the
+   rest depend on which backend is in use.  */
+struct font_info
+{
+  struct font font;
+#ifdef HAVE_LIBOTF
+  bool maybe_otf;      /* Flag to tell if this may be OTF or not.  */
+  OTF *otf;
+#endif /* HAVE_LIBOTF */
+  FT_Size ft_size;
+  int index;
+  FT_Matrix matrix;
+#ifdef HAVE_HARFBUZZ
+  hb_font_t *hb_font;
+#endif  /* HAVE_HARFBUZZ */
+
+#ifdef USE_CAIRO
+  cairo_font_face_t *cr_font_face;
+  /* To prevent cairo from cluttering the activated FT_Size maintained
+     in ftfont.c, we activate this special FT_Size before drawing.  */
+  FT_Size ft_size_draw;
+  /* Font metrics cache.  */
+  struct font_metrics **metrics;
+  short metrics_nrows;
+#else
+  /* These are used by the XFT backend.  */
+  Display *display;
+  XftFont *xftfont;
+  unsigned x_display_id;
+#endif
+};
 
 #endif /* EMACS_FTFONT_H */
diff --git a/src/xftfont.c b/src/xftfont.c
index 6f56c05..6531929 100644
--- a/src/xftfont.c
+++ b/src/xftfont.c
@@ -35,30 +35,6 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
 
 /* Xft font driver.  */
 
-
-/* The actual structure for Xft font that can be cast to struct
-   font.  */
-
-struct xftfont_info
-{
-  struct font font;
-  /* The following five members must be here in this order to be
-     compatible with struct ftfont_info (in ftfont.c).  */
-#ifdef HAVE_LIBOTF
-  bool maybe_otf;        /* Flag to tell if this may be OTF or not.  */
-  OTF *otf;
-#endif /* HAVE_LIBOTF */
-#ifdef HAVE_HARFBUZZ
-  hb_font_t *hb_font;
-#endif  /* HAVE_HARFBUZZ */
-  FT_Size ft_size;
-  int index;
-  FT_Matrix matrix;
-  Display *display;
-  XftFont *xftfont;
-  unsigned x_display_id;
-};
-
 /* Structure pointed by (struct face *)->extra  */
 
 struct xftface_info
@@ -258,7 +234,7 @@ xftfont_open (struct frame *f, Lisp_Object entity, int 
pixel_size)
   Display *display = FRAME_X_DISPLAY (f);
   Lisp_Object val, filename, idx, font_object;
   FcPattern *pat = NULL, *match;
-  struct xftfont_info *xftfont_info = NULL;
+  struct font_info *xftfont_info = NULL;
   struct font *font;
   double size = 0;
   XftFont *xftfont = NULL;
@@ -333,7 +309,7 @@ xftfont_open (struct frame *f, Lisp_Object entity, int 
pixel_size)
 
   /* We should not destroy PAT here because it is kept in XFTFONT and
      destroyed automatically when XFTFONT is closed.  */
-  font_object = font_build_object (VECSIZE (struct xftfont_info),
+  font_object = font_build_object (VECSIZE (struct font_info),
                                   Qxft, entity, size);
   ASET (font_object, FONT_FILE_INDEX, filename);
   font = XFONT_OBJECT (font_object);
@@ -341,7 +317,7 @@ xftfont_open (struct frame *f, Lisp_Object entity, int 
pixel_size)
   font->driver = &xftfont_driver;
   font->encoding_charset = font->repertory_charset = -1;
 
-  xftfont_info = (struct xftfont_info *) font;
+  xftfont_info = (struct font_info *) font;
   xftfont_info->display = display;
   xftfont_info->xftfont = xftfont;
   xftfont_info->x_display_id = FRAME_DISPLAY_INFO (f)->x_id;
@@ -466,7 +442,7 @@ static void
 xftfont_close (struct font *font)
 {
   struct x_display_info *xdi;
-  struct xftfont_info *xftfont_info = (struct xftfont_info *) font;
+  struct font_info *xftfont_info = (struct font_info *) font;
 
 #ifdef HAVE_LIBOTF
   if (xftfont_info->otf)
@@ -539,7 +515,7 @@ xftfont_done_face (struct frame *f, struct face *face)
 static int
 xftfont_has_char (Lisp_Object font, int c)
 {
-  struct xftfont_info *xftfont_info;
+  struct font_info *xftfont_info;
   struct charset *cs = NULL;
 
   if (EQ (AREF (font, FONT_ADSTYLE_INDEX), Qja)
@@ -553,7 +529,7 @@ xftfont_has_char (Lisp_Object font, int c)
 
   if (FONT_ENTITY_P (font))
     return ftfont_has_char (font, c);
-  xftfont_info = (struct xftfont_info *) XFONT_OBJECT (font);
+  xftfont_info = (struct font_info *) XFONT_OBJECT (font);
   return (XftCharExists (xftfont_info->display, xftfont_info->xftfont,
                         (FcChar32) c) == FcTrue);
 }
@@ -561,7 +537,7 @@ xftfont_has_char (Lisp_Object font, int c)
 static unsigned
 xftfont_encode_char (struct font *font, int c)
 {
-  struct xftfont_info *xftfont_info = (struct xftfont_info *) font;
+  struct font_info *xftfont_info = (struct font_info *) font;
   unsigned code = XftCharIndex (xftfont_info->display, xftfont_info->xftfont,
                                (FcChar32) c);
 
@@ -572,7 +548,7 @@ static void
 xftfont_text_extents (struct font *font, unsigned int *code,
                      int nglyphs, struct font_metrics *metrics)
 {
-  struct xftfont_info *xftfont_info = (struct xftfont_info *) font;
+  struct font_info *xftfont_info = (struct font_info *) font;
   XGlyphInfo extents;
 
   block_input ();
@@ -614,7 +590,7 @@ xftfont_draw (struct glyph_string *s, int from, int to, int 
x, int y,
 
   struct frame *f = s->f;
   struct face *face = s->face;
-  struct xftfont_info *xftfont_info = (struct xftfont_info *) s->font;
+  struct font_info *xftfont_info = (struct font_info *) s->font;
   struct xftface_info *xftface_info = NULL;
   XftDraw *xft_draw = xftfont_get_xft_draw (f);
   FT_UInt *code;
@@ -677,7 +653,7 @@ static Lisp_Object
 xftfont_shape (Lisp_Object lgstring, Lisp_Object direction)
 {
   struct font *font = CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring));
-  struct xftfont_info *xftfont_info = (struct xftfont_info *) font;
+  struct font_info *xftfont_info = (struct font_info *) font;
   FT_Face ft_face = XftLockFace (xftfont_info->xftfont);
   xftfont_info->ft_size = ft_face->size;
   Lisp_Object val = ftfont_shape (lgstring, direction);
@@ -721,7 +697,7 @@ static bool
 xftfont_cached_font_ok (struct frame *f, Lisp_Object font_object,
                         Lisp_Object entity)
 {
-  struct xftfont_info *info = (struct xftfont_info *) XFONT_OBJECT 
(font_object);
+  struct font_info *info = (struct font_info *) XFONT_OBJECT (font_object);
   FcPattern *oldpat = info->xftfont->pattern;
   Display *display = FRAME_X_DISPLAY (f);
   FcPattern *pat = FcPatternCreate ();



reply via email to

[Prev in Thread] Current Thread [Next in Thread]