4.0.0
diff --git a/NEWS b/NEWS
index 80ea0f0..b602896 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,93 @@
+Overview of changes leading to 4.0.0
+Tuesday, March 1, 2022
+====================================
+- New public API to create subset plan and gather information on things like
+  glyph mappings in the final subset. The plan can then be passed on to perform
+  the subsetting operation. (Garret Rieger)
+- Draw API for extracting glyph shapes have been extended and finalized and is
+  no longer an experimental API. The draw API supports glyf, CFF and CFF2
+  glyph outlines tables, and applies variation settings set on the font as well
+  as synthetic slant. The new public API is not backward compatible with the
+  previous, non-public, experimental API. (Behdad Esfahbod)
+- The hb-view tool will use HarfBuzz draw API to render the glyphs instead of
+  cairo-ft when compiled with Cairo 1.17.5 or newer, setting HB_DRAW
+  environment variable to 1 or 0 will force using or not use the draw API,
+  respectively. (Behdad Esfahbod)
+- The hb-shape and hb-view tools now default to using HarfBuzz’s own font
+  loading functions (ot) instead of FreeType ones (ft). They also have a new
+  option, --font-slant, to apply synthetic slant to the font. (Behdad Esfahbod)
+- HarfBuzz now supports more than 65535 (the OpenType limit) glyph shapes and
+  metrics. See https://github.com/be-fonts/boring-expansion-spec/issues/6 and
+  https://github.com/be-fonts/boring-expansion-spec/issues/7 for details.
+  (Behdad Esfahbod)
+- New API to get the dominant horizontal baseline tag for a given script.
+  (Behdad Esfahbod)
+- New API to get the baseline positions from the font, and synthesize missing
+  ones. As well as new API to get font metrics and synthesize missing ones.
+  (Matthias Clasen)
+- Improvements to finding dependencies on Windows when building with Visual
+  Studio. (Chun-wei Fan)
+- New buffer flag, HB_BUFFER_FLAG_PRODUCE_UNSAFE_TO_CONCAT, that must be set
+  during shaping for HB_GLYPH_FLAG_UNSAFE_TO_CONCAT flag to be reliably
+  produced. This is to limit the performance hit of producing this flag to when
+  it is actually needed. (Behdad Esfahbod)
+- Documentation improvements. (Matthias Clasen)
+
+- New API
+ - General:
+   +HB_BUFFER_FLAG_PRODUCE_UNSAFE_TO_CONCAT
+   +hb_var_num_t
+
+ - Draw:
+   +hb_draw_funcs_t
+   +hb_draw_funcs_create
+   +hb_draw_funcs_reference
+   +hb_draw_funcs_destroy
+   +hb_draw_funcs_is_immutable
+   +hb_draw_funcs_make_immutable
+   +hb_draw_move_to_func_t
+   +hb_draw_funcs_set_move_to_func
+   +hb_draw_line_to_func_t
+   +hb_draw_funcs_set_line_to_func
+   +hb_draw_quadratic_to_func_t
+   +hb_draw_funcs_set_quadratic_to_func
+   +hb_draw_cubic_to_func_t
+   +hb_draw_funcs_set_cubic_to_func
+   +hb_draw_close_path_func_t
+   +hb_draw_funcs_set_close_path_func
+   +hb_draw_state_t
+   +HB_DRAW_STATE_DEFAULT
+   +hb_draw_move_to
+   +hb_draw_line_to
+   +hb_draw_quadratic_to
+   +hb_draw_cubic_to
+   +hb_draw_close_path
+   +hb_font_get_glyph_shape_func_t
+   +hb_font_funcs_set_glyph_shape_func()
+   +hb_font_get_glyph_shape()
+
+ - OpenType layout
+   +HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_CENTRAL
+   +HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_CENTRAL
+   +hb_ot_layout_get_horizontal_baseline_tag_for_script()
+   +hb_ot_layout_get_baseline_with_fallback
+
+ - Metrics:
+   +hb_ot_metrics_get_position_with_fallback
+
+ - Subset:
+   +hb_subset_plan_t
+   +hb_subset_plan_create_or_fail
+   +hb_subset_plan_reference
+   +hb_subset_plan_destroy
+   +hb_subset_plan_set_user_data
+   +hb_subset_plan_get_user_data
+   +hb_subset_plan_execute_or_fail
+   +hb_subset_plan_unicode_to_old_glyph_mapping
+   +hb_subset_plan_new_to_old_glyph_mapping
+   +hb_subset_plan_old_to_new_glyph_mapping
+
+
 Overview of changes leading to 3.4.0
 Sunday, February 13, 2022
 ====================================
@@ -18,7 +108,7 @@
 +HB_OT_TAG_MATH_SCRIPT
 +HB_SCRIPT_MATH
 +hb_ot_math_kern_entry_t
-+hb_ot_math_get_glyph_kernings
++hb_ot_math_get_glyph_kernings()
 
 - Deprecated API
 +HB_OT_MATH_SCRIPT
diff --git a/configure.ac b/configure.ac
index 6ab2725..5b63c68 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,6 +1,6 @@
 AC_PREREQ([2.64])
 AC_INIT([HarfBuzz],
-        [3.4.0],
+        [4.0.0],
         [https://github.com/harfbuzz/harfbuzz/issues/new],
         [harfbuzz],
         [http://harfbuzz.org/])
diff --git a/docs/harfbuzz-docs.xml b/docs/harfbuzz-docs.xml
index 75c5e04..bb94611 100644
--- a/docs/harfbuzz-docs.xml
+++ b/docs/harfbuzz-docs.xml
@@ -117,6 +117,7 @@
       <index id="api-index-full"><title>API Index</title><xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include></index>
       <index id="deprecated-api-index" role="deprecated"><title>Index of deprecated API</title><xi:include href="xml/api-index-deprecated.xml"><xi:fallback /></xi:include></index>
 
+      <index id="api-index-4-0-0" role="4.0.0"><title>Index of new symbols in 4.0.0</title><xi:include href="xml/api-index-4.0.0.xml"><xi:fallback /></xi:include></index>
       <index id="api-index-3-4-0" role="3.4.0"><title>Index of new symbols in 3.4.0</title><xi:include href="xml/api-index-3.4.0.xml"><xi:fallback /></xi:include></index>
       <index id="api-index-3-3-0" role="3.3.0"><title>Index of new symbols in 3.3.0</title><xi:include href="xml/api-index-3.3.0.xml"><xi:fallback /></xi:include></index>
       <index id="api-index-3-1-0" role="3.1.0"><title>Index of new symbols in 3.1.0</title><xi:include href="xml/api-index-3.1.0.xml"><xi:fallback /></xi:include></index>
diff --git a/meson.build b/meson.build
index 27cd3da..17fb837 100644
--- a/meson.build
+++ b/meson.build
@@ -1,6 +1,6 @@
 project('harfbuzz', 'c', 'cpp',
   meson_version: '>= 0.55.0',
-  version: '3.4.0',
+  version: '4.0.0',
   default_options: [
     'cpp_rtti=false',       # Just to support msvc, we are passing -fno-exceptions also anyway
     'cpp_std=c++11',
diff --git a/src/hb-buffer.h b/src/hb-buffer.h
index 8e73a09..ece7d2d 100644
--- a/src/hb-buffer.h
+++ b/src/hb-buffer.h
@@ -141,7 +141,7 @@
  *				   @HB_BUFFER_FLAG_PRODUCE_UNSAFE_TO_CONCAT during
  *				   shaping, otherwise the buffer flag will not be
  *				   reliably produced.
- * 				   Since: REPLACEME
+ * 				   Since: 4.0.0
  * @HB_GLYPH_FLAG_DEFINED: All the currently defined flags.
  *
  * Flags for #hb_glyph_info_t.
@@ -372,7 +372,7 @@
  * @HB_BUFFER_FLAG_PRODUCE_UNSAFE_TO_CONCAT:
  *                      flag indicating that the @HB_GLYPH_FLAG_UNSAFE_TO_CONCAT
  *                      glyph-flag should be produced by the shaper. By default
- *                      it will not be produced since it incurs a cost. Since: REPLACEME
+ *                      it will not be produced since it incurs a cost. Since: 4.0.0
  *
  * Flags for #hb_buffer_t.
  *
diff --git a/src/hb-draw.cc b/src/hb-draw.cc
index 023cb81..b31019b 100644
--- a/src/hb-draw.cc
+++ b/src/hb-draw.cc
@@ -118,7 +118,7 @@
  * memory cannot be allocated, a special singleton #hb_draw_funcs_t object will
  * be returned.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 hb_draw_funcs_t *
 hb_draw_funcs_create ()
@@ -154,7 +154,7 @@
  * Return value: (transfer full):
  * The referenced #hb_draw_funcs_t.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 hb_draw_funcs_t *
 hb_draw_funcs_reference (hb_draw_funcs_t *dfuncs)
@@ -170,7 +170,7 @@
  * Decreases the reference count on @dfuncs by one. If the result is zero, then
  * @dfuncs and all associated resources are freed. See hb_draw_funcs_reference().
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 void
 hb_draw_funcs_destroy (hb_draw_funcs_t *dfuncs)
@@ -192,7 +192,7 @@
  *
  * Makes @dfuncs object immutable.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 void
 hb_draw_funcs_make_immutable (hb_draw_funcs_t *dfuncs)
@@ -211,7 +211,7 @@
  *
  * Return value: %true if @dfuncs is immutable, %false otherwise
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 hb_bool_t
 hb_draw_funcs_is_immutable (hb_draw_funcs_t *dfuncs)
@@ -230,7 +230,7 @@
  *
  * Perform a "move-to" draw operation.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 void
 hb_draw_move_to (hb_draw_funcs_t *dfuncs, void *draw_data,
@@ -251,7 +251,7 @@
  *
  * Perform a "line-to" draw operation.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 void
 hb_draw_line_to (hb_draw_funcs_t *dfuncs, void *draw_data,
@@ -274,7 +274,7 @@
  *
  * Perform a "quadratic-to" draw operation.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 void
 hb_draw_quadratic_to (hb_draw_funcs_t *dfuncs, void *draw_data,
@@ -301,7 +301,7 @@
  *
  * Perform a "cubic-to" draw operation.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 void
 hb_draw_cubic_to (hb_draw_funcs_t *dfuncs, void *draw_data,
@@ -324,7 +324,7 @@
  *
  * Perform a "close-path" draw operation.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 void
 hb_draw_close_path (hb_draw_funcs_t *dfuncs, void *draw_data,
diff --git a/src/hb-draw.h b/src/hb-draw.h
index 8627e6e..c45a532 100644
--- a/src/hb-draw.h
+++ b/src/hb-draw.h
@@ -44,7 +44,7 @@
  *
  * Current drawing state.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 typedef struct hb_draw_state_t {
   hb_bool_t path_open;
@@ -83,7 +83,7 @@
  * #hb_draw_quadratic_to_func_t calls to #hb_draw_cubic_to_func_t if the
  * callback isn't defined.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 
 typedef struct hb_draw_funcs_t hb_draw_funcs_t;
@@ -101,7 +101,7 @@
  * A virtual method for the #hb_draw_funcs_t to perform a "move-to" draw
  * operation.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  *
  **/
 typedef void (*hb_draw_move_to_func_t) (hb_draw_funcs_t *dfuncs, void *draw_data,
@@ -121,7 +121,7 @@
  * A virtual method for the #hb_draw_funcs_t to perform a "line-to" draw
  * operation.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  *
  **/
 typedef void (*hb_draw_line_to_func_t) (hb_draw_funcs_t *dfuncs, void *draw_data,
@@ -143,7 +143,7 @@
  * A virtual method for the #hb_draw_funcs_t to perform a "quadratic-to" draw
  * operation.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  *
  **/
 typedef void (*hb_draw_quadratic_to_func_t) (hb_draw_funcs_t *dfuncs, void *draw_data,
@@ -168,7 +168,7 @@
  * A virtual method for the #hb_draw_funcs_t to perform a "cubic-to" draw
  * operation.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  *
  **/
 typedef void (*hb_draw_cubic_to_func_t) (hb_draw_funcs_t *dfuncs, void *draw_data,
@@ -188,7 +188,7 @@
  * A virtual method for the #hb_draw_funcs_t to perform a "close-path" draw
  * operation.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  *
  **/
 typedef void (*hb_draw_close_path_func_t) (hb_draw_funcs_t *dfuncs, void *draw_data,
@@ -204,7 +204,7 @@
  *
  * Sets move-to callback to the draw functions object.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 HB_EXTERN void
 hb_draw_funcs_set_move_to_func (hb_draw_funcs_t        *dfuncs,
@@ -220,7 +220,7 @@
  *
  * Sets line-to callback to the draw functions object.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 HB_EXTERN void
 hb_draw_funcs_set_line_to_func (hb_draw_funcs_t        *dfuncs,
@@ -236,7 +236,7 @@
  *
  * Sets quadratic-to callback to the draw functions object.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 HB_EXTERN void
 hb_draw_funcs_set_quadratic_to_func (hb_draw_funcs_t             *dfuncs,
@@ -252,7 +252,7 @@
  *
  * Sets cubic-to callback to the draw functions object.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 HB_EXTERN void
 hb_draw_funcs_set_cubic_to_func (hb_draw_funcs_t         *dfuncs,
@@ -268,7 +268,7 @@
  *
  * Sets close-path callback to the draw functions object.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 HB_EXTERN void
 hb_draw_funcs_set_close_path_func (hb_draw_funcs_t           *dfuncs,
diff --git a/src/hb-font.cc b/src/hb-font.cc
index 1a08582..db05f01 100644
--- a/src/hb-font.cc
+++ b/src/hb-font.cc
@@ -1310,7 +1310,7 @@
  * The shape is returned by way of calls to the callsbacks of the @dfuncs
  * objects, with @draw_data passed to them.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 void
 hb_font_get_glyph_shape (hb_font_t *font,
diff --git a/src/hb-font.h b/src/hb-font.h
index 2179f18..9548857 100644
--- a/src/hb-font.h
+++ b/src/hb-font.h
@@ -522,7 +522,7 @@
  *
  * A virtual method for the #hb_font_funcs_t of an #hb_font_t object.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  *
  **/
 typedef void (*hb_font_get_glyph_shape_func_t) (hb_font_t *font, void *font_data,
@@ -798,7 +798,7 @@
  *
  * Sets the implementation function for #hb_font_get_glyph_shape_func_t.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 HB_EXTERN void
 hb_font_funcs_set_glyph_shape_func (hb_font_funcs_t *ffuncs,
diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc
index 25836d7..07bbe3b 100644
--- a/src/hb-ot-layout.cc
+++ b/src/hb-ot-layout.cc
@@ -1974,7 +1974,7 @@
  *
  * Return value: dominant baseline tag for the @script.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 hb_ot_layout_baseline_tag_t
 hb_ot_layout_get_horizontal_baseline_tag_for_script (hb_script_t script)
@@ -2080,7 +2080,7 @@
  * Fetches a baseline value from the face, and synthesizes
  * it if the font does not have it.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 void
 hb_ot_layout_get_baseline_with_fallback (hb_font_t                   *font,
diff --git a/src/hb-ot-layout.h b/src/hb-ot-layout.h
index 6bc44e7..4edddd9 100644
--- a/src/hb-ot-layout.h
+++ b/src/hb-ot-layout.h
@@ -440,11 +440,11 @@
  * if the direction is horizontal or vertical, respectively.
  * @HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_TOP_OR_RIGHT: Ideographic character face top or right edge,
  * if the direction is horizontal or vertical, respectively.
- * @HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_CENTRAL: The center of the ideographic character face. Since: REPLACEME
+ * @HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_CENTRAL: The center of the ideographic character face. Since: 4.0.0
  * @HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_BOTTOM_OR_LEFT: Ideographic em-box bottom or left edge,
  * if the direction is horizontal or vertical, respectively.
  * @HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT: Ideographic em-box top or right edge baseline,
- * @HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_CENTRAL: The center of the ideographic em-box. Since: REPLACEME
+ * @HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_CENTRAL: The center of the ideographic em-box. Since: 4.0.0
  * if the direction is horizontal or vertical, respectively.
  * @HB_OT_LAYOUT_BASELINE_TAG_MATH: The baseline about which mathematical characters are centered.
  * In vertical writing mode when mathematical characters rotated 90 degrees clockwise, are centered.
diff --git a/src/hb-ot-metrics.cc b/src/hb-ot-metrics.cc
index 79aa682..43c3cbd 100644
--- a/src/hb-ot-metrics.cc
+++ b/src/hb-ot-metrics.cc
@@ -247,7 +247,7 @@
  * Fetches metrics value corresponding to @metrics_tag from @font,
  * and synthesizes a value if it the value is missing in the font.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 void
 hb_ot_metrics_get_position_with_fallback (hb_font_t           *font,
diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc
index 8f737ca..4481758 100644
--- a/src/hb-subset-plan.cc
+++ b/src/hb-subset-plan.cc
@@ -470,7 +470,7 @@
  * hb_subset_plan_destroy(). If there is a failure creating the plan
  * nullptr will be returned.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 hb_subset_plan_t *
 hb_subset_plan_create_or_fail (hb_face_t	 *face,
@@ -548,7 +548,7 @@
  * Decreases the reference count on @plan, and if it reaches zero, destroys
  * @plan, freeing all memory.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 void
 hb_subset_plan_destroy (hb_subset_plan_t *plan)
@@ -613,7 +613,7 @@
  * Return value: (transfer none):
  * A pointer to the #hb_map_t of the mapping.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 const hb_map_t*
 hb_subset_plan_old_to_new_glyph_mapping (const hb_subset_plan_t *plan)
@@ -631,7 +631,7 @@
  * Return value: (transfer none):
  * A pointer to the #hb_map_t of the mapping.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 const hb_map_t*
 hb_subset_plan_new_to_old_glyph_mapping (const hb_subset_plan_t *plan)
@@ -649,7 +649,7 @@
  * Return value: (transfer none):
  * A pointer to the #hb_map_t of the mapping.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 const hb_map_t*
 hb_subset_plan_unicode_to_old_glyph_mapping (const hb_subset_plan_t *plan)
@@ -665,7 +665,7 @@
  *
  * Return value: @plan.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 hb_subset_plan_t *
 hb_subset_plan_reference (hb_subset_plan_t *plan)
@@ -685,7 +685,7 @@
  *
  * Return value: %true if success, %false otherwise
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 hb_bool_t
 hb_subset_plan_set_user_data (hb_subset_plan_t   *plan,
@@ -707,7 +707,7 @@
  *
  * Return value: (transfer none): A pointer to the user data
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 void *
 hb_subset_plan_get_user_data (const hb_subset_plan_t *plan,
diff --git a/src/hb-subset.cc b/src/hb-subset.cc
index 9faac05..aa8f2c6 100644
--- a/src/hb-subset.cc
+++ b/src/hb-subset.cc
@@ -364,7 +364,7 @@
  * on success returns a reference to generated font subset. If the subsetting operation fails
  * returns nullptr.
  *
- * Since: REPLACEME
+ * Since: 4.0.0
  **/
 hb_face_t *
 hb_subset_plan_execute_or_fail (hb_subset_plan_t *plan)
diff --git a/src/hb-version.h b/src/hb-version.h
index 1f52d92..dd2c528 100644
--- a/src/hb-version.h
+++ b/src/hb-version.h
@@ -41,13 +41,13 @@
  *
  * The major component of the library version available at compile-time.
  */
-#define HB_VERSION_MAJOR 3
+#define HB_VERSION_MAJOR 4
 /**
  * HB_VERSION_MINOR:
  *
  * The minor component of the library version available at compile-time.
  */
-#define HB_VERSION_MINOR 4
+#define HB_VERSION_MINOR 0
 /**
  * HB_VERSION_MICRO:
  *
@@ -60,7 +60,7 @@
  *
  * A string literal containing the library version available at compile-time.
  */
-#define HB_VERSION_STRING "3.4.0"
+#define HB_VERSION_STRING "4.0.0"
 
 /**
  * HB_VERSION_ATLEAST: