[MATH] Wire up get_glyph_assembly()
authorBehdad Esfahbod <behdad@behdad.org>
Mon, 26 Sep 2016 19:46:05 +0000 (21:46 +0200)
committerBehdad Esfahbod <behdad@behdad.org>
Mon, 26 Sep 2016 19:46:05 +0000 (21:46 +0200)
src/hb-ot-layout-math-table.hh
src/hb-ot-layout.cc
src/hb-ot-layout.h

index da65c38..886ed2d 100644 (file)
@@ -436,7 +436,9 @@ struct MathGlyphVariantRecord
 struct PartFlags : USHORT
 {
   enum Flags {
-    Extender = 0x0001u, /* If set, the part can be skipped or repeated. */
+    Extender   = 0x0001u, /* If set, the part can be skipped or repeated. */
+
+    Defined    = 0x0001u, /* All defined flags. */
   };
 
   public:
@@ -445,14 +447,30 @@ struct PartFlags : USHORT
 
 struct MathGlyphPartRecord
 {
-  friend struct MathGlyphAssembly;
-
   inline bool sanitize (hb_sanitize_context_t *c) const
   {
     TRACE_SANITIZE (this);
     return_trace (c->check_struct (this));
   }
 
+  inline void extract (hb_math_glyph_part_t &out,
+                      int scale,
+                      hb_font_t *font) const
+  {
+    out.glyph                  = glyph;
+
+    out.start_connector_length = font->em_scale (startConnectorLength, scale);
+    out.end_connector_length   = font->em_scale (endConnectorLength, scale);
+    out.full_advance           = font->em_scale (fullAdvance, scale);
+
+    ASSERT_STATIC ((unsigned int) HB_MATH_GLYPH_PART_FLAG_EXTENDER ==
+                  (unsigned int) PartFlags::Extender);
+
+    out.flags = (hb_math_glyph_part_flags_t)
+               (unsigned int)
+               (partFlags & PartFlags::Defined);
+  }
+
   protected:
   GlyphID   glyph;               /* Glyph ID for the part. */
   USHORT    startConnectorLength; /* Advance width/ height of the straight bar
@@ -482,8 +500,28 @@ struct MathGlyphAssembly
                  partRecords.sanitize(c));
   }
 
-  inline hb_position_t get_italic_correction (hb_font_t *font) const
-  { return italicsCorrection.get_x_value(font, this); }
+  inline unsigned int get_parts (hb_direction_t direction,
+                                hb_font_t *font,
+                                unsigned int start_offset,
+                                unsigned int *parts_count, /* IN/OUT */
+                                hb_math_glyph_part_t *parts /* OUT */,
+                                hb_position_t *italics_correction /* OUT */) const
+  {
+    if (parts_count)
+    {
+      int scale = font->dir_scale (direction);
+      const MathGlyphPartRecord *arr =
+           partRecords.sub_array (start_offset, parts_count);
+      unsigned int count = *parts_count;
+      for (unsigned int i = 0; i < count; i++)
+        arr[i].extract (parts[i], scale, font);
+    }
+
+    if (italics_correction)
+      *italics_correction = italicsCorrection.get_x_value (font, this);
+
+    return partRecords.len;
+  }
 
   protected:
   MathValueRecord         italicsCorrection; /* Italics correction of this
@@ -507,6 +545,9 @@ struct MathGlyphConstruction
                  mathGlyphVariantRecord.sanitize(c));
   }
 
+  inline const MathGlyphAssembly &get_assembly (void) const
+  { return this+glyphAssembly; }
+
   inline unsigned int get_variants (hb_direction_t direction,
                                    hb_font_t *font,
                                    unsigned int start_offset,
@@ -576,6 +617,19 @@ struct MathVariants
   { return get_glyph_construction (glyph, direction, font)
           .get_variants (direction, font, start_offset, variants_count, variants); }
 
+  inline unsigned int get_glyph_parts (hb_codepoint_t glyph,
+                                      hb_direction_t direction,
+                                      hb_font_t *font,
+                                      unsigned int start_offset,
+                                      unsigned int *parts_count, /* IN/OUT */
+                                      hb_math_glyph_part_t *parts /* OUT */,
+                                      hb_position_t *italics_correction /* OUT */) const
+  { return get_glyph_construction (glyph, direction, font)
+          .get_assembly ()
+          .get_parts (direction, font,
+                      start_offset, parts_count, parts,
+                      italics_correction); }
+
   private:
   inline const MathGlyphConstruction &
                get_glyph_construction (hb_codepoint_t glyph,
index 0d3f19b..942158e 100644 (file)
@@ -1341,7 +1341,7 @@ hb_ot_layout_is_math_extended_shape (hb_face_t *face,
  *
  * Since: 1.4
  **/
-HB_EXTERN hb_position_t
+hb_position_t
 hb_ot_layout_get_math_kerning (hb_font_t *font,
                               hb_codepoint_t glyph,
                               hb_ot_math_kern_t kern,
@@ -1351,7 +1351,7 @@ hb_ot_layout_get_math_kerning (hb_font_t *font,
   return math.get_math_glyph_info().get_kerning (glyph, kern, correction_height, font);
 }
 
-HB_EXTERN unsigned int
+unsigned int
 hb_ot_layout_get_math_glyph_variants (hb_font_t *font,
                                      hb_codepoint_t glyph,
                                      hb_direction_t direction,
@@ -1374,15 +1374,19 @@ hb_ot_layout_get_math_min_connector_overlap (hb_font_t *font,
   return math.get_math_variants().get_min_connector_overlap (direction, font);
 }
 
-HB_EXTERN unsigned int
-hb_ot_layout_get_math_glyph_assembly_parts (hb_font_t *font,
-                                           hb_codepoint_t glyph,
-                                           hb_direction_t direction,
-                                           unsigned int start_offset,
-                                           unsigned int *parts_count, /* IN/OUT */
-                                           hb_math_glyph_part_t *parts, /* OUT */
-                                           hb_position_t *italic_correction /* OUT */)
+unsigned int
+hb_ot_layout_get_math_glyph_assembly (hb_font_t *font,
+                                     hb_codepoint_t glyph,
+                                     hb_direction_t direction,
+                                     unsigned int start_offset,
+                                     unsigned int *parts_count, /* IN/OUT */
+                                     hb_math_glyph_part_t *parts, /* OUT */
+                                     hb_position_t *italics_correction /* OUT */)
 {
   const OT::MATH &math = _get_math (font->face);
-  return 0;
+  return math.get_math_variants().get_glyph_parts (glyph, direction, font,
+                                                  start_offset,
+                                                  parts_count,
+                                                  parts,
+                                                  italics_correction);
 }
index 4c01d63..b6fbd00 100644 (file)
@@ -341,13 +341,13 @@ hb_ot_layout_get_math_min_connector_overlap (hb_font_t *font,
                                             hb_direction_t direction);
 
 HB_EXTERN unsigned int
-hb_ot_layout_get_math_glyph_assembly_parts (hb_font_t *font,
-                                           hb_codepoint_t glyph,
-                                           hb_direction_t direction,
-                                           unsigned int start_offset,
-                                           unsigned int *parts_count, /* IN/OUT */
-                                           hb_math_glyph_part_t *parts, /* OUT */
-                                           hb_position_t *italic_correction /* OUT */);
+hb_ot_layout_get_math_glyph_assembly (hb_font_t *font,
+                                     hb_codepoint_t glyph,
+                                     hb_direction_t direction,
+                                     unsigned int start_offset,
+                                     unsigned int *parts_count, /* IN/OUT */
+                                     hb_math_glyph_part_t *parts, /* OUT */
+                                     hb_position_t *italics_correction /* OUT */);
 
 HB_END_DECLS