(unidata.txt): Don't use $<, it's non-portable in this context.
[bpt/emacs.git] / src / font.h
index 019e12c..21e821e 100644 (file)
@@ -1,6 +1,6 @@
 /* font.h -- Interface definition for font handling.
-   Copyright (C) 2006 Free Software Foundation, Inc.
-   Copyright (C) 2006
+   Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2007, 2008
      National Institute of Advanced Industrial Science and Technology (AIST)
      Registration Number H13PRO009
 
@@ -8,7 +8,7 @@ This file is part of GNU Emacs.
 
 GNU Emacs is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
 any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
@@ -68,8 +68,9 @@ struct font;
 enum font_property_index
   {
     /* FONT-TYPE is a symbol indicating a font backend; currently `x',
-       `xft', `ftx', `freetype' are available.  For windows, we need
-       `bdf' and `windows'.  For Mac OS X, we need `atm'.  */
+       `xft', `ftx', `freetype' are available on X and gdi on Windows.
+       For Windows, we `bdf' and `uniscribe' backends are in progress.
+       For Mac OS X, we need `atm'.  */
     FONT_TYPE_INDEX,
 
     /* FONT-FOUNDRY is a foundry name (symbol).  */
@@ -121,7 +122,8 @@ enum font_property_index
        can be opend on any frame.  */
     FONT_FRAME_INDEX = FONT_SPEC_MAX,
 
-    /* List of font-objects opened from the font-entity.  */
+    /* List of font-objects opened from the font-entity.  The value is
+       nil if no font can be opened for this font-entity.  */
     FONT_OBJLIST_INDEX,
 
     /* This value is the length of font-entity vector.  */
@@ -131,13 +133,13 @@ enum font_property_index
 extern Lisp_Object QCspacing, QCdpi, QCscalable, QCotf, QClanguage, QCscript;
 
 /* Important character set symbols.  */
-extern Lisp_Object Qiso8859_1, Qiso10646_1, Qunicode_bmp;
+extern Lisp_Object Qiso8859_1, Qiso10646_1, Qunicode_bmp, Qunicode_sip;
 
 extern Lisp_Object null_string;
 extern Lisp_Object null_vector;
 
 /* Structure for an opened font.  We can safely cast this structure to
-   "struft font_info".  */
+   "struct font_info".  */
 
 struct font
 {
@@ -152,6 +154,9 @@ struct font
   /* Font-driver for the font.  */
   struct font_driver *driver;
 
+  /* Symbol of font font; x, ttf, pcf, etc,   */
+  Lisp_Object format;
+
   /* File name of the font, or NULL if the font is not associated with
      a file.  */
   char *file_name;
@@ -172,6 +177,9 @@ struct font
   /* Ascent and descent of the font (in pixels).  */
   int ascent, descent;
 
+  /* 1 iff the font is scalable.  */
+  int scalable;
+
   /* There will be more to this structure, but they are private to a
      font-driver.  */
 };
@@ -191,6 +199,7 @@ struct font_metrics
 
 struct font_bitmap
 {
+  int bits_per_pixel;
   int rows;
   int width;
   int pitch;
@@ -203,30 +212,38 @@ struct font_bitmap
 
 /* Predicates to check various font-related objects.  */
 
-#define FONTP(x)       \
-  (VECTORP (x) && (ASIZE (x) == FONT_SPEC_MAX || ASIZE (x) == FONT_ENTITY_MAX))
 #define FONT_SPEC_P(x) \
   (VECTORP (x) && ASIZE (x) == FONT_SPEC_MAX)
 #define FONT_ENTITY_P(x)       \
   (VECTORP (x) && ASIZE (x) == FONT_ENTITY_MAX)
 #define FONT_OBJECT_P(x)       \
   (XTYPE (x) == Lisp_Misc && XMISCTYPE (x) == Lisp_Misc_Save_Value)
+#define FONTP(x)                                       \
+  ((VECTORP (x) && (ASIZE (x) == FONT_SPEC_MAX         \
+                   || ASIZE (x) == FONT_ENTITY_MAX))   \
+   || FONT_OBJECT_P (x))
+
+#define FONT_ENTITY_NOT_LOADABLE(entity)       \
+  EQ (AREF (entity, FONT_OBJLIST_INDEX), Qt)
+
+#define FONT_ENTITY_SET_NOT_LOADABLE(entity)   \
+  ASET (entity, FONT_OBJLIST_INDEX, Qt)
 
 
 /* Check macros for various font-related objects.  */
 
 #define CHECK_FONT(x)  \
-  do { if (! FONTP (x)) x = wrong_type_argument (Qfont, x); } while (0)
+  do { if (! FONTP (x)) wrong_type_argument (Qfont, x); } while (0)
 #define CHECK_FONT_SPEC(x)     \
-  do { if (! FONT_SPEC_P (x)) x = wrong_type_argument (Qfont, x); } while (0)
+  do { if (! FONT_SPEC_P (x)) wrong_type_argument (Qfont, x); } while (0)
 #define CHECK_FONT_ENTITY(x)   \
-  do { if (! FONT_ENTITY_P (x)) x = wrong_type_argument (Qfont, x); } while (0)
+  do { if (! FONT_ENTITY_P (x)) wrong_type_argument (Qfont, x); } while (0)
 #define CHECK_FONT_OBJECT(x)   \
-  do { if (! FONT_OBJECT_P (x)) x = wrong_type_argument (Qfont, x); } while (0)
+  do { if (! FONT_OBJECT_P (x)) wrong_type_argument (Qfont, x); } while (0)
 
 #define CHECK_FONT_GET_OBJECT(x, font)                                 \
   do {                                                                 \
-    if (! FONT_OBJECT_P (x)) x = wrong_type_argument (Qfont, x);       \
+    if (! FONT_OBJECT_P (x)) wrong_type_argument (Qfont, x);   \
     if (! XSAVE_VALUE (x)->pointer) error ("Font already closed");     \
     font = XSAVE_VALUE (x)->pointer;                                   \
   } while (0)
@@ -239,34 +256,67 @@ struct face;
 struct composition;
 
 /* Macros for lispy glyph-string.  */
-#define LGSTRING_FONT(lgs) AREF (AREF ((lgs), 0), 0)
-#define LGSTRING_LBEARING(lgs) AREF (AREF ((lgs), 0), 1)
-#define LGSTRING_RBEARING(lgs) AREF (AREF ((lgs), 0), 2)
-#define LGSTRING_WIDTH(lgs) AREF (AREF ((lgs), 0), 3)
-#define LGSTRING_ASCENT(lgs) AREF (AREF ((lgs), 0), 4)
-#define LGSTRING_DESCENT(lgs) AREF (AREF ((lgs), 0), 5)
-#define LGSTRING_SET_FONT(lgs, val) ASET (AREF ((lgs), 0), 0, (val))
-#define LGSTRING_SET_LBEARING(lgs, val) ASET (AREF ((lgs), 0), 1, (val))
-#define LGSTRING_SET_RBEARING(lgs, val)        ASET (AREF ((lgs), 0), 2, (val))
-#define LGSTRING_SET_WIDTH(lgs, val) ASET (AREF ((lgs), 0), 3, (val))
-#define LGSTRING_SET_ASCENT(lgs, val) ASET (AREF ((lgs), 0), 4, (val))
-#define LGSTRING_SET_DESCENT(lgs, val) ASET (AREF ((lgs), 0), 5, (val))
+enum lgstring_indices
+  {
+    LGSTRING_IX_FONT, LGSTRING_IX_WIDTH,
+    LGSTRING_IX_LBEARING, LGSTRING_IX_RBEARING,
+    LGSTRING_IX_ASCENT, LGSTRING_IX_DESCENT
+  };
+#define LGSTRING_SLOT(lgs, ix) AREF (AREF ((lgs), 0), ix)
+#define LGSTRING_FONT(lgs) LGSTRING_SLOT (lgs, LGSTRING_IX_FONT)
+#define LGSTRING_WIDTH(lgs) XINT (LGSTRING_SLOT (lgs, LGSTRING_IX_WIDTH))
+#define LGSTRING_LBEARING(lgs) XINT (LGSTRING_SLOT (lgs, LGSTRING_IX_LBEARING))
+#define LGSTRING_RBEARING(lgs) XINT (LGSTRING_SLOT (lgs, LGSTRING_IX_RBEARING))
+#define LGSTRING_ASCENT(lgs) XINT (LGSTRING_SLOT (lgs, LGSTRING_IX_ASCENT))
+#define LGSTRING_DESCENT(lgs) XINT (LGSTRING_SLOT (lgs, LGSTRING_IX_DESCENT))
+#define LGSTRING_SET_SLOT(lgs, ix, val) ASET (AREF ((lgs), 0), ix, (val))
+#define LGSTRING_SET_FONT(lgs, val)     \
+  LGSTRING_SET_SLOT(lgs, LGSTRING_IX_FONT, (val))
+#define LGSTRING_SET_WIDTH(lgs, val)   \
+  LGSTRING_SET_SLOT(lgs, LGSTRING_IX_WIDTH, make_number (val))
+#define LGSTRING_SET_LBEARING(lgs, val) \
+  LGSTRING_SET_SLOT(lgs, LGSTRING_IX_LBEARING, make_number (val))
+#define LGSTRING_SET_RBEARING(lgs, val)        \
+  LGSTRING_SET_SLOT(lgs, LGSTRING_IX_RBEARING, make_number (val))
+#define LGSTRING_SET_ASCENT(lgs, val)  \
+  LGSTRING_SET_SLOT(lgs, LGSTRING_IX_ASCENT, make_number (val))
+#define LGSTRING_SET_DESCENT(lgs, val) \
+  LGSTRING_SET_SLOT(lgs, LGSTRING_IX_DESCENT, make_number (val))
 
 #define LGSTRING_LENGTH(lgs) (ASIZE ((lgs)) - 1)
 #define LGSTRING_GLYPH(lgs, idx) AREF ((lgs), (idx) + 1)
+#define LGSTRING_SET_GLYPH(lgs, idx, val) ASET ((lgs), (idx) + 1, (val))
 
-#define LGLYPH_FROM(g) AREF ((g), 0)
-#define LGLYPH_TO(g) AREF ((g), 1)
-#define LGLYPH_CHAR(g) AREF ((g), 2)
-#define LGLYPH_CODE(g) AREF ((g), 3)
-#define LGLYPH_WIDTH(g) AREF ((g), 4)
-#define LGLYPH_ADJUSTMENT(g) AREF ((g), 5)
-#define LGLYPH_SET_FROM(g, val) ASET ((g), 0, (val))
-#define LGLYPH_SET_TO(g, val) ASET ((g), 1, (val))
-#define LGLYPH_SET_CHAR(g, val) ASET ((g), 2, (val))
-#define LGLYPH_SET_CODE(g, val) ASET ((g), 3, (val))
-#define LGLYPH_SET_WIDTH(g, val) ASET ((g), 4, (val))
-#define LGLYPH_SET_ADJUSTMENT(g, val) ASET ((g), 5, (val))
+/* Vector size of Lispy glyph.  */
+enum lglyph_indices
+  {
+    LGLYPH_IX_FROM, LGLYPH_IX_TO,  LGLYPH_IX_CHAR, LGLYPH_IX_CODE,
+    LGLYPH_IX_WIDTH, LGLYPH_IX_LBEARING, LGLYPH_IX_RBEARING,
+    LGLYPH_IX_ASCENT, LGLYPH_IX_DESCENT, LGLYPH_IX_ADJUSTMENT,
+    /* Not an index.  */
+    LGLYPH_SIZE
+  };
+#define LGLYPH_FROM(g) XINT (AREF ((g), LGLYPH_IX_FROM))
+#define LGLYPH_TO(g) XINT (AREF ((g), LGLYPH_IX_TO))
+#define LGLYPH_CHAR(g) XINT (AREF ((g), LGLYPH_IX_CHAR))
+#define LGLYPH_CODE(g) XUINT (AREF ((g), LGLYPH_IX_CODE))
+#define LGLYPH_WIDTH(g) XINT (AREF ((g), LGLYPH_IX_WIDTH))
+#define LGLYPH_LBEARING(g) XINT (AREF ((g), LGLYPH_IX_LBEARING))
+#define LGLYPH_RBEARING(g) XINT (AREF ((g), LGLYPH_IX_RBEARING))
+#define LGLYPH_ASCENT(g) XINT (AREF ((g), LGLYPH_IX_ASCENT))
+#define LGLYPH_DESCENT(g) XINT (AREF ((g), LGLYPH_IX_DESCENT))
+#define LGLYPH_ADJUSTMENT(g) AREF ((g), LGLYPH_IX_ADJUSTMENT)
+#define LGLYPH_SET_FROM(g, val) ASET ((g), LGLYPH_IX_FROM, make_number (val))
+#define LGLYPH_SET_TO(g, val) ASET ((g), LGLYPH_IX_TO, make_number (val))
+#define LGLYPH_SET_CHAR(g, val) ASET ((g), LGLYPH_IX_CHAR, make_number (val))
+/* FIXME: we should use make_uint_number here.  */
+#define LGLYPH_SET_CODE(g, val) ASET ((g), LGLYPH_IX_CODE, make_number (val))
+#define LGLYPH_SET_WIDTH(g, val) ASET ((g), LGLYPH_IX_WIDTH, make_number (val))
+#define LGLYPH_SET_LBEARING(g, val) ASET ((g), LGLYPH_IX_RBEARING, make_number (val))
+#define LGLYPH_SET_RBEARING(g, val) ASET ((g), LGLYPH_IX_LBEARING, make_number (val))
+#define LGLYPH_SET_ASCENT(g, val) ASET ((g), LGLYPH_IX_ASCENT, make_number (val))
+#define LGLYPH_SET_DESCENT(g, val) ASET ((g), LGLYPH_IX_DESCENT, make_number (val))
+#define LGLYPH_SET_ADJUSTMENT(g, val) ASET ((g), LGLYPH_IX_ADJUSTMENT, (val))
 
 #define LGLYPH_XOFF(g) (VECTORP (LGLYPH_ADJUSTMENT (g)) \
                        ? XINT (AREF (LGLYPH_ADJUSTMENT (g), 0)) : 0)
@@ -284,15 +334,20 @@ struct font_driver
   /* Symbol indicating the type of the font-driver.  */
   Lisp_Object type;
 
-  /* Return a cache of font-entities on FRAME.  The cache must be a
+  /* Return a cache of font-entities on frame F.  The cache must be a
      cons whose cdr part is the actual cache area.  */
-  Lisp_Object (*get_cache) P_ ((Lisp_Object frame));
+  Lisp_Object (*get_cache) P_ ((FRAME_PTR F));
 
-  /* List fonts matching with FONT_SPEC on FRAME.  The value is a
-     vector of font-entities.  This is the sole API that allocates
-     font-entities.  */
+  /* List fonts exactly matching with FONT_SPEC on FRAME.  The value
+     is a vector of font-entities.  This is the sole API that
+     allocates font-entities.  */
   Lisp_Object (*list) P_ ((Lisp_Object frame, Lisp_Object font_spec));
 
+  /* Return a font entity most closely maching with FONT_SPEC on
+     FRAME.  The closeness is detemined by the font backend, thus
+     `face-font-selection-order' is ignored here.  */
+  Lisp_Object (*match) P_ ((Lisp_Object frame, Lisp_Object font_spec));
+
   /* Optional.
      List available families.  The value is a list of family names
      (symbols).  */
@@ -330,9 +385,9 @@ struct font_driver
      If FONT doesn't have such a glyph, return FONT_INVALID_CODE.  */
   unsigned (*encode_char) P_ ((struct font *font, int c));
 
-  /* Perform the size computation of glyphs of FONT and fillin members
-     of METRICS.  The glyphs are specified by their glyph codes in
-     CODE (length NGLYPHS).  */
+  /* Computate the total metrics of the NGLYPHS glyphs specified by
+     the font FONT and the sequence of glyph codes CODE, and store the
+     result in METRICS.  */
   int (*text_extents) P_ ((struct font *font,
                           unsigned *code, int nglyphs,
                           struct font_metrics *metrics));
@@ -379,17 +434,11 @@ struct font_driver
   Lisp_Object (*otf_capability) P_ ((struct font *font));
 
   /* Optional.
-     Drive FONT's OTF GSUB features according to GSUB_SPEC.
-
-     GSUB_SPEC is in this format (all elements are symbols):
-       (SCRIPT LANGSYS GSUB-FEATURE ...)
-     If one of GSUB-FEATURE is nil, apply all gsub features except for
-     already applied and listed later.  For instance, if the font has
-     GSUB features nukt, haln, rphf, blwf, and half,
-       (deva nil nukt haln nil rphf)
-     applies nukt and haln in this order, then applies blwf and half
-     in the order apearing in the font.  The features are of the
-     default langsys of `deva' script.
+     Apply FONT's OTF-FEATURES to the glyph string.
+
+     FEATURES specifies which OTF features to apply in this format:
+       (SCRIPT LANGSYS GSUB-FEATURE GPOS-FEATURE)
+     See the documentation of `font-drive-otf' for the detail.
 
      This method applies the specified features to the codes in the
      elements of GSTRING-IN (between FROMth and TOth).  The output
@@ -399,40 +448,77 @@ struct font_driver
      Return the number of output codes.  If none of the features are
      applicable to the input data, return 0.  If GSTRING-OUT is too
      short, return -1.  */
-  int (*otf_gsub) P_ ((struct font *font, Lisp_Object gsub_spec,
+  int (*otf_drive) P_ ((struct font *font, Lisp_Object features,
                       Lisp_Object gstring_in, int from, int to,
-                      Lisp_Object gstring_out, int idx));
+                      Lisp_Object gstring_out, int idx, int alternate_subst));
 
   /* Optional.
-     Drive FONT's OTF GPOS features according to GPOS_SPEC.
+     Make the font driver ready for frame F.  Usually this function
+     makes some data specific to F and store it in F by calling
+     font_put_frame_data ().  */
+  int (*start_for_frame) P_ ((FRAME_PTR f));
+  
+  /* Optional.
+     End using the driver for frame F.  Usually this function free
+     some data stored for F.  */
+  int (*end_for_frame) P_ ((FRAME_PTR f));
 
-     GPOS_SPEC is in this format (all elements are symbols):
-       (SCRIPT LANGSYS GPOS-FEATURE ...)
-     The meaning is the same as GSUB_SPEC above. 
+  /* Optional.
 
-     This method applies the specified features to the codes in the
-     elements of GSTRING (between FROMth and TOth).  The resulting
-     positioning information (x-offset and y-offset) is stored in the
-     slots of the elements.
-
-     Return 1 if at least one glyph has nonzero x-offset or y-offset.
-     Otherwise return 0.  */
-  int (*otf_gpos) P_ ((struct font *font, Lisp_Object gpos_spec,
-                      Lisp_Object gstring, int from, int to));
+     Shape text in LGSTRING.  See the docstring of `font-make-gstring'
+     for the format of LGSTRING.  If the (N+1)th element of LGSTRING
+     is nil, input of shaping is from the 1st to (N)th elements.  In
+     each input glyph, FROM, TO, CHAR, and CODE are already set.
+
+     This function updates all fields of the input glyphs.  If the
+     output glyphs (M) are more than the input glyphs (N), (N+1)th
+     through (M)th elements of LGSTRING are updated possibly by making
+     a new glyph object and storing it in LGSTRING.  If (M) is greater
+     than the length of LGSTRING, nil should be return.  In that case,
+     this function is called again with the larger LGSTRING.  */
+  Lisp_Object (*shape) P_ ((Lisp_Object lgstring));
 };
 
 
+/* Chain of font drivers.  There's one global font driver list
+   (font_driver_list in font.c).  In addition, each frame has it's own
+   font driver list at FRAME_PTR->font_driver_list.  */
+
 struct font_driver_list
 {
+  /* 1 iff this driver is currently used.  It is igonred in the global
+     font driver list.*/
+  int on;
+  /* Pointer to the font driver.  */
   struct font_driver *driver;
+  /* Pointer to the next element of the chain.  */
   struct font_driver_list *next;
 };
 
+
+/* Chain of arbitrary data specific to each font driver.  Each frame
+   has it's own font data list at FRAME_PTR->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 int enable_font_backend;
 
 EXFUN (Ffont_spec, MANY);
+EXFUN (Ffont_get, 2);
 EXFUN (Flist_fonts, 4);
+EXFUN (Fclear_font_cache, 0);
+EXFUN (Ffont_xlfd_name, 1);
 
+extern int font_registry_charsets P_ ((Lisp_Object, struct charset **,
+                                      struct charset **));
 extern Lisp_Object font_symbolic_weight P_ ((Lisp_Object font));
 extern Lisp_Object font_symbolic_slant P_ ((Lisp_Object font));
 extern Lisp_Object font_symbolic_width P_ ((Lisp_Object font));
@@ -451,9 +537,10 @@ extern int font_set_lface_from_name P_ ((FRAME_PTR f,
                                         Lisp_Object fontname,
                                         int force_p, int may_fail_p));
 extern Lisp_Object font_find_for_lface P_ ((FRAME_PTR f, Lisp_Object *lface,
+                                           Lisp_Object spec, int c));
+extern Lisp_Object font_open_for_lface P_ ((FRAME_PTR f, Lisp_Object entity,
+                                           Lisp_Object *lface,
                                            Lisp_Object spec));
-extern Lisp_Object font_open_for_lface P_ ((FRAME_PTR f, Lisp_Object *lface,
-                                           Lisp_Object entity));
 extern void font_load_for_face P_ ((FRAME_PTR f, struct face *face));
 extern void font_prepare_for_face P_ ((FRAME_PTR f, struct face *face));
 extern Lisp_Object font_open_by_name P_ ((FRAME_PTR f, char *name));
@@ -474,23 +561,21 @@ extern int font_unparse_fcname P_ ((Lisp_Object font, int pixel_size,
                                  char *name, int bytes));
 extern void register_font_driver P_ ((struct font_driver *driver, FRAME_PTR f));
 extern void free_font_driver_list P_ ((FRAME_PTR f));
+extern Lisp_Object font_update_drivers P_ ((FRAME_PTR f, Lisp_Object list));
 extern Lisp_Object font_at P_ ((int c, EMACS_INT pos, struct face *face,
                                struct window *w, Lisp_Object object));
 
-extern struct font *font_prepare_composition P_ ((struct composition *cmp));
+extern struct font *font_prepare_composition P_ ((struct composition *cmp,
+                                                 FRAME_PTR f));
 
+extern Lisp_Object font_put_extra P_ ((Lisp_Object font, Lisp_Object prop,
+                                       Lisp_Object val));
 
-#ifdef HAVE_LIBOTF
-/* This can be used as `otf_capability' method of a font-driver.  */
-extern Lisp_Object font_otf_capability P_ ((struct font *font));
-/* This can be used as `otf_gsub' method of a font-driver.  */
-extern int font_otf_gsub P_ ((struct font *font, Lisp_Object gsub_spec,
-                             Lisp_Object gstring_in, int from, int to,
-                             Lisp_Object gstring_out, int idx));
-/* This can be used as `otf_gpos' method of a font-driver.  */
-extern int font_otf_gpos P_ ((struct font *font, Lisp_Object gpos_spec,
-                             Lisp_Object gstring, int from, int to));
-#endif /* HAVE_LIBOTF */
+extern int font_put_frame_data P_ ((FRAME_PTR f,
+                                   struct font_driver *driver,
+                                   void *data));
+extern void *font_get_frame_data P_ ((FRAME_PTR f,
+                                     struct font_driver *driver));
 
 #ifdef HAVE_FREETYPE
 extern struct font_driver ftfont_driver;