[base] Add hb_ot_layout_get_baseline API
authorEbrahim Byagowi <ebrahim@gnu.org>
Tue, 30 Jul 2019 00:12:51 +0000 (04:42 +0430)
committerGitHub <noreply@github.com>
Tue, 30 Jul 2019 00:12:51 +0000 (04:42 +0430)
docs/harfbuzz-sections.txt
src/hb-ot-face-table-list.hh
src/hb-ot-layout.cc
src/hb-ot-layout.h
test/api/test-baseline.c

index 0bc2a2c..f8650b0 100644 (file)
@@ -548,6 +548,7 @@ HB_OT_TAG_GDEF
 HB_OT_TAG_GPOS
 HB_OT_TAG_GSUB
 HB_OT_TAG_JSTF
 HB_OT_TAG_GPOS
 HB_OT_TAG_GSUB
 HB_OT_TAG_JSTF
+hb_ot_layout_baseline_tag_t
 hb_ot_layout_collect_lookups
 hb_ot_layout_collect_features
 hb_ot_layout_feature_get_characters
 hb_ot_layout_collect_lookups
 hb_ot_layout_collect_features
 hb_ot_layout_feature_get_characters
@@ -555,6 +556,7 @@ hb_ot_layout_feature_get_lookups
 hb_ot_layout_feature_get_name_ids
 hb_ot_layout_feature_with_variations_get_lookups
 hb_ot_layout_get_attach_points
 hb_ot_layout_feature_get_name_ids
 hb_ot_layout_feature_with_variations_get_lookups
 hb_ot_layout_get_attach_points
+hb_ot_layout_get_baseline
 hb_ot_layout_get_glyph_class
 hb_ot_layout_get_glyphs_in_class
 hb_ot_layout_get_ligature_carets
 hb_ot_layout_get_glyph_class
 hb_ot_layout_get_glyphs_in_class
 hb_ot_layout_get_ligature_carets
index 97fb765..9799edd 100644 (file)
@@ -97,10 +97,14 @@ HB_OT_TABLE (OT, kern)
 HB_OT_ACCELERATOR (OT, GDEF)
 HB_OT_ACCELERATOR (OT, GSUB)
 HB_OT_ACCELERATOR (OT, GPOS)
 HB_OT_ACCELERATOR (OT, GDEF)
 HB_OT_ACCELERATOR (OT, GSUB)
 HB_OT_ACCELERATOR (OT, GPOS)
-//HB_OT_TABLE (OT, BASE)
 //HB_OT_TABLE (OT, JSTF)
 #endif
 
 //HB_OT_TABLE (OT, JSTF)
 #endif
 
+/* OpenType baseline. */
+#ifndef HB_NO_BASE
+HB_OT_TABLE (OT, BASE)
+#endif
+
 /* AAT shaping. */
 #ifndef HB_NO_AAT
 HB_OT_TABLE (AAT, morx)
 /* AAT shaping. */
 #ifndef HB_NO_AAT
 HB_OT_TABLE (AAT, morx)
index 4cd65b4..666e162 100644 (file)
@@ -1940,75 +1940,34 @@ hb_ot_layout_substitute_lookup (OT::hb_ot_apply_context_t *c,
   apply_string<GSUBProxy> (c, lookup, accel);
 }
 
   apply_string<GSUBProxy> (c, lookup, accel);
 }
 
-#if 0
-hb_bool_t
-hb_ot_layout_get_baseline (hb_font_t               *font,
-                          hb_ot_layout_baseline_t  baseline,
-                          hb_direction_t           direction,
-                          hb_tag_t                 script_tag,
-                          hb_tag_t                 language_tag,
-                          hb_position_t           *coord        /* OUT.  May be NULL. */)
-{
-  bool result = font->face->table.BASE->get_baseline (font, baseline, direction, script_tag,
-                                                     language_tag, coord);
-
-  /* TODO: Simulate https://docs.microsoft.com/en-us/typography/opentype/spec/baselinetags#ideographic-em-box */
-  if (!result && coord) *coord = 0;
-
-  if (coord) *coord = font->em_scale_dir (*coord, direction);
-
-  return result;
-}
-
-/* To be moved to public header */
-/*
- * BASE
- */
-
-/**
- * hb_ot_layout_baseline_t:
- *
- * https://docs.microsoft.com/en-us/typography/opentype/spec/baselinetags
- *
- * Since: DONTREPLACEME
- */
-typedef enum {
-  HB_OT_LAYOUT_BASELINE_HANG = HB_TAG('h','a','n','g'),
-  HB_OT_LAYOUT_BASELINE_ICFB = HB_TAG('i','c','f','b'),
-  HB_OT_LAYOUT_BASELINE_ICFT = HB_TAG('i','c','f','t'),
-  HB_OT_LAYOUT_BASELINE_IDEO = HB_TAG('i','d','e','o'),
-  HB_OT_LAYOUT_BASELINE_IDTB = HB_TAG('i','d','t','b'),
-  HB_OT_LAYOUT_BASELINE_MATH = HB_TAG('m','a','t','h'),
-  HB_OT_LAYOUT_BASELINE_ROMN = HB_TAG('r','o','m','n'),
-
-  _HB_OT_LAYOUT_BASELINE_MAX_VALUE = HB_TAG_MAX_SIGNED /*< skip >*/
-} hb_ot_layout_baseline_t;
-
-
+#ifndef HB_NO_BASE
 /**
  * hb_ot_layout_get_baseline:
 /**
  * hb_ot_layout_get_baseline:
- * @font: The #hb_font_t to work upon
- * @baseline: The #hb_ot_layout_baseline_t to query
- * @direction: The #hb_direction_t text direction to use (horizontal or vertical)
- * @script_tag:  #hb_tag_t of the script to use
- * @language_tag: #hb_tag_t of the language to use
- * @coord: (out): The position of the requested baseline
- *
- * Fetches the coordinates of the specified baseline in the face, underneath
- * the specified script and language and in the specified text direction.
+ * @font: a font
+ * @baseline: a baseline tag
+ * @direction: text direction.
+ * @script_tag:  script tag.
+ * @language_tag: language tag.
+ * @coord: (out): baseline value if found.
  *
  *
- * Return value: true if the baseline is found for the settings queried, false otherwise
+ * Fetches a baseline value from the face.
  *
  *
+ * Return value: if found baseline value in the the font.
  **/
  **/
-HB_EXTERN hb_bool_t
-hb_ot_layout_get_baseline (hb_font_t               *font,
-                          hb_ot_layout_baseline_t  baseline,
-                          hb_direction_t           direction,
-                          hb_tag_t                 script_tag,
-                          hb_tag_t                 language_tag,
-                          hb_position_t           *coord        /* OUT.  May be NULL. */);
-
-#endif
+hb_bool_t
+hb_ot_layout_get_baseline (hb_font_t                   *font,
+                          hb_ot_layout_baseline_tag_t  baseline_tag,
+                          hb_direction_t               direction,
+                          hb_tag_t                     script_tag,
+                          hb_tag_t                     language_tag,
+                          hb_position_t               *coord        /* OUT.  May be NULL. */)
+{
+  bool result = font->face->table.BASE->get_baseline (font, baseline_tag, direction, script_tag, language_tag, coord);
 
 
+  if (result && coord)
+    *coord = HB_DIRECTION_IS_HORIZONTAL (direction) ? font->em_scale_y (*coord) : font->em_scale_x (*coord);
 
 
+  return result;
+}
+#endif
 #endif
 #endif
index 3b9a78e..73254aa 100644 (file)
@@ -402,6 +402,38 @@ hb_ot_layout_feature_get_characters (hb_face_t      *face,
                                     unsigned int   *char_count    /* IN/OUT.  May be NULL */,
                                     hb_codepoint_t *characters    /* OUT.     May be NULL */);
 
                                     unsigned int   *char_count    /* IN/OUT.  May be NULL */,
                                     hb_codepoint_t *characters    /* OUT.     May be NULL */);
 
+/*
+ * BASE
+ */
+
+/**
+ * hb_ot_layout_baseline_tag_t:
+ *
+ * https://docs.microsoft.com/en-us/typography/opentype/spec/baselinetags
+ *
+ * Since: REPLACEME
+ */
+typedef enum {
+  HB_OT_LAYOUT_BASELINE_TAG_ROMAN                      = HB_TAG ('r','o','m','n'),
+  HB_OT_LAYOUT_BASELINE_TAG_HANGING                    = HB_TAG ('h','a','n','g'),
+  HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT   = HB_TAG ('i','c','f','b'),
+  HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_TOP_OR_RIGHT     = HB_TAG ('i','c','f','t'),
+  HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_BOTTOM_OR_LEFT  = HB_TAG ('i','d','e','o'),
+  HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT    = HB_TAG ('i','d','t','p'),
+  HB_OT_LAYOUT_BASELINE_TAG_MATH                       = HB_TAG ('m','a','t','h'),
+
+  _HB_OT_LAYOUT_BASELINE_TAG_MAX_VALUE = HB_TAG_MAX_SIGNED /*< skip >*/
+} hb_ot_layout_baseline_tag_t;
+
+HB_EXTERN hb_bool_t
+hb_ot_layout_get_baseline (hb_font_t                   *font,
+                          hb_ot_layout_baseline_tag_t  baseline_tag,
+                          hb_direction_t               direction,
+                          hb_tag_t                     script_tag,
+                          hb_tag_t                     language_tag,
+                          hb_position_t               *coord        /* OUT.  May be NULL. */);
+
+
 HB_END_DECLS
 
 #endif /* HB_OT_LAYOUT_H */
 HB_END_DECLS
 
 #endif /* HB_OT_LAYOUT_H */
index a120e14..982c683 100644 (file)
@@ -34,14 +34,12 @@ test_ot_layout_base (void)
   hb_face_t *face = hb_test_open_font_file ("fonts/base.ttf");
   hb_font_t *font = hb_font_create (face);
 
   hb_face_t *face = hb_test_open_font_file ("fonts/base.ttf");
   hb_font_t *font = hb_font_create (face);
 
-#if 0
   hb_position_t position;
   hb_position_t position;
-  g_assert (hb_ot_layout_get_baseline (font, HB_OT_LAYOUT_BASELINE_ICFB, HB_DIRECTION_TTB,
+  g_assert (hb_ot_layout_get_baseline (font, HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT, HB_DIRECTION_TTB,
                                       HB_TAG ('h','a','n','i'),
                                       HB_TAG ('E','N','G',' '),
                                       &position));
   g_assert_cmpint (46, ==, position);
                                       HB_TAG ('h','a','n','i'),
                                       HB_TAG ('E','N','G',' '),
                                       &position));
   g_assert_cmpint (46, ==, position);
-#endif
 
   hb_font_destroy (font);
   hb_face_destroy (face);
 
   hb_font_destroy (font);
   hb_face_destroy (face);