[Indic] Ra is a consonant too
[framework/uifw/harfbuzz.git] / src / hb-font-private.hh
index 7609300..dd71b67 100644 (file)
@@ -32,6 +32,7 @@
 #include "hb-private.hh"
 
 #include "hb-font.h"
+#include "hb-object-private.hh"
 
 HB_BEGIN_DECLS
 
@@ -40,21 +41,43 @@ HB_BEGIN_DECLS
  * hb_font_funcs_t
  */
 
+#define HB_FONT_FUNCS_IMPLEMENT_CALLBACKS \
+  HB_FONT_FUNC_IMPLEMENT (glyph) \
+  HB_FONT_FUNC_IMPLEMENT (glyph_h_advance) \
+  HB_FONT_FUNC_IMPLEMENT (glyph_v_advance) \
+  HB_FONT_FUNC_IMPLEMENT (glyph_h_origin) \
+  HB_FONT_FUNC_IMPLEMENT (glyph_v_origin) \
+  HB_FONT_FUNC_IMPLEMENT (glyph_h_kerning) \
+  HB_FONT_FUNC_IMPLEMENT (glyph_v_kerning) \
+  HB_FONT_FUNC_IMPLEMENT (glyph_extents) \
+  HB_FONT_FUNC_IMPLEMENT (glyph_contour_point) \
+  /* ^--- Add new callbacks here */
+
 struct _hb_font_funcs_t {
-  hb_reference_count_t ref_count;
+  hb_object_header_t header;
 
   hb_bool_t immutable;
 
+  /* Don't access these directly.  Call hb_font_get_*() instead. */
+
   struct {
-    hb_font_get_glyph_func_t           get_glyph;
-    hb_font_get_glyph_advance_func_t   get_glyph_advance;
-    hb_font_get_glyph_extents_func_t   get_glyph_extents;
-    hb_font_get_contour_point_func_t   get_contour_point;
-    hb_font_get_kerning_func_t         get_kerning;
-  } v;
-};
+#define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_func_t name;
+    HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
+#undef HB_FONT_FUNC_IMPLEMENT
+  } get;
+
+  struct {
+#define HB_FONT_FUNC_IMPLEMENT(name) void *name;
+    HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
+#undef HB_FONT_FUNC_IMPLEMENT
+  } user_data;
 
-extern HB_INTERNAL hb_font_funcs_t _hb_font_funcs_nil;
+  struct {
+#define HB_FONT_FUNC_IMPLEMENT(name) hb_destroy_func_t name;
+    HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
+#undef HB_FONT_FUNC_IMPLEMENT
+  } destroy;
+};
 
 
 /*
@@ -62,16 +85,17 @@ extern HB_INTERNAL hb_font_funcs_t _hb_font_funcs_nil;
  */
 
 struct _hb_face_t {
-  hb_reference_count_t ref_count;
+  hb_object_header_t header;
+
+  hb_bool_t immutable;
 
   hb_get_table_func_t  get_table;
   void                *user_data;
   hb_destroy_func_t    destroy;
 
-  hb_blob_t *head_blob;
-  const struct head *head_table;
-
   struct hb_ot_layout_t *ot_layout;
+
+  unsigned int upem;
 };
 
 
@@ -80,10 +104,15 @@ struct _hb_face_t {
  */
 
 struct _hb_font_t {
-  hb_reference_count_t ref_count;
+  hb_object_header_t header;
+
+  hb_bool_t immutable;
+
+  hb_font_t *parent;
+  hb_face_t *face;
 
-  unsigned int x_scale;
-  unsigned int y_scale;
+  int x_scale;
+  int y_scale;
 
   unsigned int x_ppem;
   unsigned int y_ppem;
@@ -91,6 +120,42 @@ struct _hb_font_t {
   hb_font_funcs_t   *klass;
   void              *user_data;
   hb_destroy_func_t  destroy;
+
+
+  /* Convert from font-space to user-space */
+  inline hb_position_t em_scale_x (int16_t v) { return em_scale (v, this->x_scale); }
+  inline hb_position_t em_scale_y (int16_t v) { return em_scale (v, this->y_scale); }
+
+  /* Convert from parent-font user-space to our user-space */
+  inline hb_position_t parent_scale_x_distance (hb_position_t v) {
+    if (unlikely (parent && parent->x_scale != x_scale))
+      return v * (int64_t) this->x_scale / this->parent->x_scale;
+    return v;
+  }
+  inline hb_position_t parent_scale_y_distance (hb_position_t v) {
+    if (unlikely (parent && parent->y_scale != y_scale))
+      return v * (int64_t) this->y_scale / this->parent->y_scale;
+    return v;
+  }
+  inline hb_position_t parent_scale_x_position (hb_position_t v) {
+    return parent_scale_x_distance (v);
+  }
+  inline hb_position_t parent_scale_y_position (hb_position_t v) {
+    return parent_scale_y_distance (v);
+  }
+
+  inline void parent_scale_distance (hb_position_t *x, hb_position_t *y) {
+    *x = parent_scale_x_distance (*x);
+    *y = parent_scale_y_distance (*y);
+  }
+  inline void parent_scale_position (hb_position_t *x, hb_position_t *y) {
+    *x = parent_scale_x_position (*x);
+    *y = parent_scale_y_position (*y);
+  }
+
+
+  private:
+  inline hb_position_t em_scale (int16_t v, int scale) { return v * (int64_t) scale / this->face->upem; }
 };