More normalization kick
[framework/uifw/harfbuzz.git] / src / hb-ot-layout-common-private.hh
index c4a4055..ce47e22 100644 (file)
@@ -1,5 +1,6 @@
 /*
- * Copyright (C) 2007,2008,2009  Red Hat, Inc.
+ * Copyright © 2007,2008,2009  Red Hat, Inc.
+ * Copyright © 2010  Google, Inc.
  *
  *  This is part of HarfBuzz, a text shaping library.
  *
@@ -22,6 +23,7 @@
  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  *
  * Red Hat Author(s): Behdad Esfahbod
+ * Google Author(s): Behdad Esfahbod
  */
 
 #ifndef HB_OT_LAYOUT_COMMON_PRIVATE_HH
@@ -54,9 +56,8 @@ HB_END_DECLS
 template <typename Type>
 struct Record
 {
-  inline int cmp (hb_tag_t b) const {
-    hb_tag_t a = tag;
-    return b < a ? -1 : b == a ? 0 : -1;
+  inline int cmp (hb_tag_t a) const {
+    return tag.cmp (a);
   }
 
   inline bool sanitize (hb_sanitize_context_t *c, void *base) {
@@ -77,6 +78,9 @@ template <typename Type>
 struct RecordArrayOf : SortedArrayOf<Record<Type> > {
   inline const Tag& get_tag (unsigned int i) const
   {
+    /* We cheat slightly and don't define separate Null objects
+     * for Record types.  Instead, we return the correct Null(Tag)
+     * here. */
     if (unlikely (i >= this->len)) return Null(Tag);
     return (*this)[i].tag;
   }
@@ -85,10 +89,10 @@ struct RecordArrayOf : SortedArrayOf<Record<Type> > {
                                hb_tag_t     *record_tags /* OUT */) const
   {
     if (record_count) {
-      const Record<Type> *array = this->sub_array (start_offset, record_count);
+      const Record<Type> *arr = this->sub_array (start_offset, record_count);
       unsigned int count = *record_count;
       for (unsigned int i = 0; i < count; i++)
-       record_tags[i] = array[i].tag;
+       record_tags[i] = arr[i].tag;
     }
     return this->len;
   }
@@ -146,10 +150,10 @@ struct IndexArray : ArrayOf<Index>
                                   unsigned int *_indexes /* OUT */) const
   {
     if (_count) {
-      const USHORT *array = this->sub_array (start_offset, _count);
+      const USHORT *arr = this->sub_array (start_offset, _count);
       unsigned int count = *_count;
       for (unsigned int i = 0; i < count; i++)
-       _indexes[i] = array[i];
+       _indexes[i] = arr[i];
     }
     return this->len;
   }
@@ -256,8 +260,6 @@ struct Feature
        && lookupIndex.sanitize (c);
   }
 
-  /* LONGTERMTODO: implement get_feature_parameters() */
-  /* LONGTERMTODO: implement FeatureSize and other special features? */
   Offset       featureParams;  /* Offset to Feature Parameters table (if one
                                 * has been defined for the feature), relative
                                 * to the beginning of the Feature Table; = Null
@@ -291,7 +293,11 @@ struct Lookup
   inline unsigned int get_subtable_count (void) const { return subTable.len; }
 
   inline unsigned int get_type (void) const { return lookupType; }
-  inline unsigned int get_flag (void) const
+
+  /* lookup_props is a 32-bit integer where the lower 16-bit is LookupFlag and
+   * higher 16-bit is mark-filtering-set if the lookup uses one.
+   * Not to be confused with glyph_props which is very similar. */
+  inline uint32_t get_props (void) const
   {
     unsigned int flag = lookupFlag;
     if (unlikely (flag & LookupFlag::UseMarkFilteringSet))
@@ -432,7 +438,7 @@ struct ClassDefFormat1
   friend struct ClassDef;
 
   private:
-  inline hb_ot_layout_class_t get_class (hb_codepoint_t glyph_id) const
+  inline unsigned int get_class (hb_codepoint_t glyph_id) const
   {
     if ((unsigned int) (glyph_id - startGlyph) < classValue.len)
       return classValue[glyph_id - startGlyph];
@@ -458,7 +464,7 @@ struct ClassDefFormat2
   friend struct ClassDef;
 
   private:
-  inline hb_ot_layout_class_t get_class (hb_codepoint_t glyph_id) const
+  inline unsigned int get_class (hb_codepoint_t glyph_id) const
   {
     int i = rangeRecord.search (glyph_id);
     if (i != -1)
@@ -481,9 +487,9 @@ struct ClassDefFormat2
 
 struct ClassDef
 {
-  inline hb_ot_layout_class_t operator () (hb_codepoint_t glyph_id) const { return get_class (glyph_id); }
+  inline unsigned int operator () (hb_codepoint_t glyph_id) const { return get_class (glyph_id); }
 
-  inline hb_ot_layout_class_t get_class (hb_codepoint_t glyph_id) const
+  inline unsigned int get_class (hb_codepoint_t glyph_id) const
   {
     switch (u.format) {
     case 1: return u.format1.get_class(glyph_id);
@@ -519,15 +525,26 @@ struct ClassDef
 
 struct Device
 {
-  /* XXX speed up */
 
-  inline hb_position_t get_x_delta (hb_ot_layout_context_t *c) const
-  { return c->font->x_ppem ? get_delta (c->font->x_ppem) * (uint64_t) c->font->x_scale / c->font->x_ppem : 0; }
+  inline hb_position_t get_x_delta (hb_font_t *font) const
+  { return get_delta (font->x_ppem, font->x_scale); }
+
+  inline hb_position_t get_y_delta (hb_font_t *font) const
+  { return get_delta (font->y_ppem, font->y_scale); }
+
+  inline int get_delta (unsigned int ppem, int scale) const
+  {
+    if (!ppem) return 0;
+
+    int pixels = get_delta_pixels (ppem);
+
+    if (!pixels) return 0;
+
+    return pixels * (int64_t) scale / ppem;
+  }
 
-  inline hb_position_t get_y_delta (hb_ot_layout_context_t *c) const
-  { return c->font->y_ppem ? get_delta (c->font->y_ppem) * (uint64_t) c->font->y_scale / c->font->y_ppem : 0; }
 
-  inline int get_delta (unsigned int ppem_size) const
+  inline int get_delta_pixels (unsigned int ppem_size) const
   {
     unsigned int f = deltaFormat;
     if (unlikely (f < 1 || f > 3))
@@ -550,7 +567,7 @@ struct Device
     return delta;
   }
 
-  inline unsigned int get_size () const
+  inline unsigned int get_size (void) const
   {
     unsigned int f = deltaFormat;
     if (unlikely (f < 1 || f > 3 || startSize > endSize)) return 3 * USHORT::static_size;