[Indic] Ra is a consonant too
[framework/uifw/harfbuzz.git] / src / hb-font-private.hh
index a58701e..dd71b67 100644 (file)
@@ -1,5 +1,6 @@
 /*
- * Copyright (C) 2009  Red Hat, Inc.
+ * Copyright © 2009  Red Hat, Inc.
+ * Copyright © 2011  Google, Inc.
  *
  *  This is part of HarfBuzz, a text shaping library.
  *
  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  *
  * Red Hat Author(s): Behdad Esfahbod
+ * Google Author(s): Behdad Esfahbod
  */
 
-#ifndef HB_FONT_PRIVATE_H
-#define HB_FONT_PRIVATE_H
+#ifndef HB_FONT_PRIVATE_HH
+#define HB_FONT_PRIVATE_HH
 
-#include "hb-private.h"
+#include "hb-private.hh"
 
 #include "hb-font.h"
-
-#include "hb-ot-head-private.hh"
+#include "hb-object-private.hh"
 
 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;
 
-  hb_font_get_glyph_func_t             get_glyph;
-  hb_font_get_contour_point_func_t     get_contour_point;
-  hb_font_get_glyph_metrics_func_t     get_glyph_metrics;
-  hb_font_get_kerning_func_t           get_kerning;
+  /* Don't access these directly.  Call hb_font_get_*() instead. */
+
+  struct {
+#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;
+
+  struct {
+#define HB_FONT_FUNC_IMPLEMENT(name) hb_destroy_func_t name;
+    HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
+#undef HB_FONT_FUNC_IMPLEMENT
+  } destroy;
 };
 
-extern HB_INTERNAL hb_font_funcs_t _hb_font_funcs_nil;
-
 
 /*
  * hb_face_t
  */
 
 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;
-  hb_destroy_func_t    destroy;
   void                *user_data;
-
-  hb_blob_t *head_blob;
-  const struct head *head_table;
+  hb_destroy_func_t    destroy;
 
   struct hb_ot_layout_t *ot_layout;
+
+  unsigned int upem;
 };
 
 
@@ -76,20 +104,61 @@ 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;
 
   hb_font_funcs_t   *klass;
-  hb_destroy_func_t  destroy;
   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; }
 };
 
 
 HB_END_DECLS
 
-#endif /* HB_FONT_PRIVATE_H */
+#endif /* HB_FONT_PRIVATE_HH */