From 780809fb0ca403a71917ab9a5c79d18df9268d31 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 9 Mar 2025 18:40:27 -0600 Subject: [PATCH 01/40] [fontations] Check for font serial change automatically Let's see what tsan thinks... I also have not profiled this. It also doesn't hold the mutex for the whole use time. It probably should or bad things might happen. --- src/fontations/lib.rs | 103 ++++++++++++++++++++++++++++-------------- 1 file changed, 69 insertions(+), 34 deletions(-) diff --git a/src/fontations/lib.rs b/src/fontations/lib.rs index 702a33022..48e025c75 100644 --- a/src/fontations/lib.rs +++ b/src/fontations/lib.rs @@ -6,6 +6,7 @@ use std::mem::transmute; use std::os::raw::c_void; use std::ptr::null_mut; use std::sync::atomic::{AtomicPtr, Ordering}; +use std::sync::Mutex; use read_fonts::tables::cpal::ColorRecord; use read_fonts::TableProvider; @@ -26,15 +27,20 @@ use skrifa::{GlyphId, MetadataProvider}; #[repr(C)] struct FontationsData<'a> { face_blob: *mut hb_blob_t, + font: *mut hb_font_t, font_ref: FontRef<'a>, char_map: Charmap<'a>, + outline_glyphs: OutlineGlyphCollection<'a>, + color_glyphs: ColorGlyphCollection<'a>, + + // Mutex for the below + mutex: Mutex<()>, + serial: u32, x_size: Size, y_size: Size, location: Location, x_glyph_metrics: Option>, y_glyph_metrics: Option>, - outline_glyphs: OutlineGlyphCollection<'a>, - color_glyphs: ColorGlyphCollection<'a>, } impl FontationsData<'_> { @@ -49,14 +55,47 @@ impl FontationsData<'_> { let char_map = Charmap::new(&font_ref); + let outline_glyphs = font_ref.outline_glyphs(); + + let color_glyphs = font_ref.color_glyphs(); + + let mut data = FontationsData { + face_blob, + font, + font_ref, + char_map, + outline_glyphs, + color_glyphs, + mutex: Mutex::new(()), + serial: u32::MAX, + x_size: Size::new(0.0), + y_size: Size::new(0.0), + location: Location::default(), + x_glyph_metrics: None, + y_glyph_metrics: None, + }; + + data.check_for_updates(); + + data + } + + unsafe fn _check_for_updates(&mut self) { + let _lock = self.mutex.lock().unwrap(); + + let font_serial = hb_font_get_serial(self.font); + if self.serial == font_serial { + return; + } + let mut x_scale: i32 = 0; let mut y_scale: i32 = 0; - hb_font_get_scale(font, &mut x_scale, &mut y_scale); - let x_size = Size::new(x_scale as f32); - let y_size = Size::new(y_scale as f32); + hb_font_get_scale(self.font, &mut x_scale, &mut y_scale); + self.x_size = Size::new(x_scale as f32); + self.y_size = Size::new(y_scale as f32); let mut num_coords: u32 = 0; - let coords = hb_font_get_var_coords_normalized(font, &mut num_coords); + let coords = hb_font_get_var_coords_normalized(self.font, &mut num_coords); let coords = if coords.is_null() { &[] } else { @@ -67,7 +106,7 @@ impl FontationsData<'_> { // otherwise, use the provided coords. // This currently doesn't seem to have a perf effect on fontations, but it's a good idea to // check if the coords are all zeros before creating a Location. - let location = if all_zeros { + self.location = if all_zeros { Location::default() } else { let mut location = Location::new(num_coords as usize); @@ -79,29 +118,15 @@ impl FontationsData<'_> { location }; - let outline_glyphs = font_ref.outline_glyphs(); + let location = transmute::<&Location, &Location>(&self.location); + self.x_glyph_metrics = Some(self.font_ref.glyph_metrics(self.x_size, location)); + let location = transmute::<&Location, &Location>(&self.location); + self.y_glyph_metrics = Some(self.font_ref.glyph_metrics(self.y_size, location)); - let color_glyphs = font_ref.color_glyphs(); - - let mut data = FontationsData { - face_blob, - font_ref, - char_map, - x_size, - y_size, - location, - x_glyph_metrics: None, - y_glyph_metrics: None, - outline_glyphs, - color_glyphs, - }; - // transmute location - let location = transmute::<&Location, &Location>(&data.location); - data.x_glyph_metrics = Some(data.font_ref.glyph_metrics(data.x_size, location)); - let location = transmute::<&Location, &Location>(&data.location); - data.y_glyph_metrics = Some(data.font_ref.glyph_metrics(data.y_size, location)); - - data + self.serial = font_serial; + } + fn check_for_updates(&mut self) { + unsafe { self._check_for_updates() } } } @@ -175,7 +200,9 @@ extern "C" fn _hb_fontations_get_glyph_h_advances( advance_stride: ::std::os::raw::c_uint, _user_data: *mut ::std::os::raw::c_void, ) { - let data = unsafe { &*(font_data as *const FontationsData) }; + let data = unsafe { &mut *(font_data as *mut FontationsData) }; + data.check_for_updates(); + let glyph_metrics = &data.y_glyph_metrics.as_ref().unwrap(); for i in 0..count { @@ -195,7 +222,9 @@ extern "C" fn _hb_fontations_get_glyph_extents( extents: *mut hb_glyph_extents_t, _user_data: *mut ::std::os::raw::c_void, ) -> hb_bool_t { - let data = unsafe { &*(font_data as *const FontationsData) }; + let data = unsafe { &mut *(font_data as *mut FontationsData) }; + data.check_for_updates(); + let x_size = &data.x_size; let y_size = &data.y_size; let x_glyph_metrics = &data.x_glyph_metrics.as_ref().unwrap(); @@ -230,7 +259,9 @@ extern "C" fn _hb_fontations_get_font_h_extents( extents: *mut hb_font_extents_t, _user_data: *mut ::std::os::raw::c_void, ) -> hb_bool_t { - let data = unsafe { &*(font_data as *const FontationsData) }; + let data = unsafe { &mut *(font_data as *mut FontationsData) }; + data.check_for_updates(); + let font_ref = &data.font_ref; let size = &data.y_size; let location = &data.location; @@ -305,7 +336,9 @@ extern "C" fn _hb_fontations_draw_glyph( draw_data: *mut ::std::os::raw::c_void, _user_data: *mut ::std::os::raw::c_void, ) { - let data = unsafe { &*(font_data as *const FontationsData) }; + let data = unsafe { &mut *(font_data as *mut FontationsData) }; + data.check_for_updates(); + let x_size = &data.x_size; let location = &data.location; let outline_glyphs = &data.outline_glyphs; @@ -688,7 +721,9 @@ extern "C" fn _hb_fontations_paint_glyph( foreground: hb_color_t, _user_data: *mut ::std::os::raw::c_void, ) { - let data = unsafe { &*(font_data as *const FontationsData) }; + let data = unsafe { &mut *(font_data as *mut FontationsData) }; + data.check_for_updates(); + let font_ref = &data.font_ref; let location = &data.location; let color_glyphs = &data.color_glyphs; From e77fb463358d0c3ece7bb56ae79a6696303969d1 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 9 Mar 2025 18:53:36 -0600 Subject: [PATCH 02/40] [fontations] Do double-checked locking See if tsan likes this. It liked the previous version. --- src/fontations/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fontations/lib.rs b/src/fontations/lib.rs index 48e025c75..4b50ab533 100644 --- a/src/fontations/lib.rs +++ b/src/fontations/lib.rs @@ -81,13 +81,13 @@ impl FontationsData<'_> { } unsafe fn _check_for_updates(&mut self) { - let _lock = self.mutex.lock().unwrap(); - let font_serial = hb_font_get_serial(self.font); if self.serial == font_serial { return; } + let _lock = self.mutex.lock().unwrap(); + let mut x_scale: i32 = 0; let mut y_scale: i32 = 0; hb_font_get_scale(self.font, &mut x_scale, &mut y_scale); From 0b62666ece2290ae9dbade6c0e6fe16d5144ca80 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 9 Mar 2025 19:38:32 -0600 Subject: [PATCH 03/40] [aat/morx] Use a separate bit for deleted-glyphs Should address: https://github.com/harfbuzz/harfbuzz/pull/5119#issuecomment-2709170388 --- src/hb-aat-layout-common.hh | 8 ++------ src/hb-aat-layout.cc | 3 +-- src/hb-ot-layout.hh | 14 +++++++++++++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/hb-aat-layout-common.hh b/src/hb-aat-layout-common.hh index e2ac53f6f..fa34afaa7 100644 --- a/src/hb-aat-layout-common.hh +++ b/src/hb-aat-layout-common.hh @@ -119,10 +119,7 @@ struct hb_aat_apply_context_t : for (unsigned int i = 0; i < count; i++) { if (glyphs[i] == DELETED_GLYPH) - { - buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_DEFAULT_IGNORABLES; - _hb_glyph_info_set_default_ignorable (&buffer->cur()); - } + _hb_glyph_info_set_aat_deleted (&buffer->cur()); else { buffer_glyph_set.add (glyphs[i]); @@ -153,8 +150,7 @@ struct hb_aat_apply_context_t : HB_NODISCARD bool delete_glyph () { - buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_DEFAULT_IGNORABLES; - _hb_glyph_info_set_default_ignorable (&buffer->cur()); + _hb_glyph_info_set_aat_deleted (&buffer->cur()); return buffer->replace_glyph (DELETED_GLYPH); } diff --git a/src/hb-aat-layout.cc b/src/hb-aat-layout.cc index c984da447..16076c6f5 100644 --- a/src/hb-aat-layout.cc +++ b/src/hb-aat-layout.cc @@ -324,8 +324,7 @@ hb_aat_layout_substitute (const hb_ot_shape_plan_t *plan, static bool is_deleted_glyph (const hb_glyph_info_t *info) { - return info->codepoint == AAT::DELETED_GLYPH && - _hb_glyph_info_is_default_ignorable (info); + return _hb_glyph_info_is_aat_deleted (info); } void diff --git a/src/hb-ot-layout.hh b/src/hb-ot-layout.hh index 52dafbba4..cf0307995 100644 --- a/src/hb-ot-layout.hh +++ b/src/hb-ot-layout.hh @@ -202,7 +202,8 @@ enum hb_unicode_props_flags_t { /* If GEN_CAT=FORMAT, top byte masks: */ UPROPS_MASK_Cf_ZWJ = 0x0100u, UPROPS_MASK_Cf_ZWNJ = 0x0200u, - UPROPS_MASK_Cf_VS = 0x0400u + UPROPS_MASK_Cf_VS = 0x0400u, + UPROPS_MASK_Cf_AAT_DELETED = 0x0800u }; HB_MARK_AS_FLAG_T (hb_unicode_props_flags_t); @@ -418,6 +419,17 @@ _hb_glyph_info_flip_joiners (hb_glyph_info_t *info) return; info->unicode_props() ^= UPROPS_MASK_Cf_ZWNJ | UPROPS_MASK_Cf_ZWJ; } +static inline bool +_hb_glyph_info_is_aat_deleted (const hb_glyph_info_t *info) +{ + return _hb_glyph_info_is_unicode_format (info) && (info->unicode_props() & UPROPS_MASK_Cf_AAT_DELETED); +} +static inline void +_hb_glyph_info_set_aat_deleted (hb_glyph_info_t *info) +{ + _hb_glyph_info_set_general_category (info, HB_UNICODE_GENERAL_CATEGORY_FORMAT); + info->unicode_props() |= UPROPS_MASK_Cf_AAT_DELETED; +} /* lig_props: aka lig_id / lig_comp * From 7518718671b6d2ef285ff7b0b56f50d28be1ee20 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 12 Feb 2025 11:39:14 +0000 Subject: [PATCH 04/40] [buffer] Add HB_BUFFER_CLUSTER_LEVEL_GRAPHEMES https://github.com/harfbuzz/harfbuzz/discussions/5026#discussioncomment-12168668 --- src/hb-buffer-verify.cc | 37 ++++++++++++++++++------------------- src/hb-buffer.cc | 4 ++-- src/hb-buffer.h | 18 ++++++++++++++++-- src/hb-coretext-shape.cc | 4 ++-- src/hb-ot-layout.hh | 2 +- src/hb-ot-shape.cc | 4 ++-- src/hb-ot-shaper-hangul.cc | 6 ++---- src/hb-ot-shaper-thai.cc | 2 +- 8 files changed, 44 insertions(+), 33 deletions(-) diff --git a/src/hb-buffer-verify.cc b/src/hb-buffer-verify.cc index 345f08d26..76f821637 100644 --- a/src/hb-buffer-verify.cc +++ b/src/hb-buffer-verify.cc @@ -63,24 +63,25 @@ static bool buffer_verify_monotone (hb_buffer_t *buffer, hb_font_t *font) { - /* Check that clusters are monotone. */ - if (buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES || - buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS) + if (!HB_BUFFER_CLUSTER_LEVEL_IS_MONOTONE (buffer->cluster_level)) { - bool is_forward = HB_DIRECTION_IS_FORWARD (hb_buffer_get_direction (buffer)); - - unsigned int num_glyphs; - hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, &num_glyphs); - - for (unsigned int i = 1; i < num_glyphs; i++) - if (info[i-1].cluster != info[i].cluster && - (info[i-1].cluster < info[i].cluster) != is_forward) - { - buffer_verify_error (buffer, font, BUFFER_VERIFY_ERROR "clusters are not monotone."); - return false; - } + /* Cannot perform this check without monotone clusters. */ + return true; } + bool is_forward = HB_DIRECTION_IS_FORWARD (hb_buffer_get_direction (buffer)); + + unsigned int num_glyphs; + hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, &num_glyphs); + + for (unsigned int i = 1; i < num_glyphs; i++) + if (info[i-1].cluster != info[i].cluster && + (info[i-1].cluster < info[i].cluster) != is_forward) + { + buffer_verify_error (buffer, font, BUFFER_VERIFY_ERROR "clusters are not monotone."); + return false; + } + return true; } @@ -92,8 +93,7 @@ buffer_verify_unsafe_to_break (hb_buffer_t *buffer, unsigned int num_features, const char * const *shapers) { - if (buffer->cluster_level != HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES && - buffer->cluster_level != HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS) + if (!HB_BUFFER_CLUSTER_LEVEL_IS_MONOTONE (buffer->cluster_level)) { /* Cannot perform this check without monotone clusters. */ return true; @@ -207,8 +207,7 @@ buffer_verify_unsafe_to_concat (hb_buffer_t *buffer, unsigned int num_features, const char * const *shapers) { - if (buffer->cluster_level != HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES && - buffer->cluster_level != HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS) + if (!HB_BUFFER_CLUSTER_LEVEL_IS_MONOTONE (buffer->cluster_level)) { /* Cannot perform this check without monotone clusters. */ return true; diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index d0c40664a..7fb95fe7e 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -518,7 +518,7 @@ void hb_buffer_t::merge_clusters_impl (unsigned int start, unsigned int end) { - if (cluster_level == HB_BUFFER_CLUSTER_LEVEL_CHARACTERS) + if (!HB_BUFFER_CLUSTER_LEVEL_IS_MONOTONE (cluster_level)) { unsafe_to_break (start, end); return; @@ -551,7 +551,7 @@ void hb_buffer_t::merge_out_clusters (unsigned int start, unsigned int end) { - if (cluster_level == HB_BUFFER_CLUSTER_LEVEL_CHARACTERS) + if (!HB_BUFFER_CLUSTER_LEVEL_IS_MONOTONE (cluster_level)) return; if (unlikely (end - start < 2)) diff --git a/src/hb-buffer.h b/src/hb-buffer.h index dd0edb9b7..5d3b63f47 100644 --- a/src/hb-buffer.h +++ b/src/hb-buffer.h @@ -422,9 +422,9 @@ hb_buffer_get_flags (const hb_buffer_t *buffer); * @HB_BUFFER_CLUSTER_LEVEL_CHARACTERS: Don't group cluster values. * @HB_BUFFER_CLUSTER_LEVEL_DEFAULT: Default cluster level, * equal to @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES. - * + * * Data type for holding HarfBuzz's clustering behavior options. The cluster level - * dictates one aspect of how HarfBuzz will treat non-base characters + * dictates one aspect of how HarfBuzz will treat non-base characters * during shaping. * * In @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES, non-base @@ -446,9 +446,23 @@ typedef enum { HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES = 0, HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS = 1, HB_BUFFER_CLUSTER_LEVEL_CHARACTERS = 2, + HB_BUFFER_CLUSTER_LEVEL_GRAPHEMES = 3, HB_BUFFER_CLUSTER_LEVEL_DEFAULT = HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES } hb_buffer_cluster_level_t; +#define HB_BUFFER_CLUSTER_LEVEL_IS_MONOTONE(level) \ + ((bool) ((1u << (unsigned) (level)) & \ + ((1u << HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES) | \ + (1u << HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS)))) +#define HB_BUFFER_CLUSTER_LEVEL_IS_GRAPHEMES(level) \ + ((bool) ((1u << (unsigned) (level)) & \ + ((1u << HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES) | \ + (1u << HB_BUFFER_CLUSTER_LEVEL_GRAPHEMES)))) +#define HB_BUFFER_CLUSTER_LEVEL_IS_CHARACTERS(level) \ + ((bool) ((1u << (unsigned) (level)) & \ + ((1u << HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARCATERS) | \ + (1u << HB_BUFFER_CLUSTER_LEVEL_CHARACTERS)))) + HB_EXTERN void hb_buffer_set_cluster_level (hb_buffer_t *buffer, hb_buffer_cluster_level_t cluster_level); diff --git a/src/hb-coretext-shape.cc b/src/hb-coretext-shape.cc index 0bb235f6d..2e029fe2b 100644 --- a/src/hb-coretext-shape.cc +++ b/src/hb-coretext-shape.cc @@ -646,7 +646,7 @@ _hb_coretext_shape (hb_shape_plan_t *shape_plan, * B1 M1 B2 M2, and B1-B2 form a ligature, M2's cluster will * continue pointing to B2 even though B2 was merged into B1's * cluster... */ - if (buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES) + if (HB_BUFFER_CLUSTER_LEVEL_IS_GRAPHEMES (buffer->cluster_level)) { hb_unicode_funcs_t *unicode = buffer->unicode; unsigned int count = buffer->len; @@ -1292,7 +1292,7 @@ resize_and_retry: * or the native OT backend, only that the cluster indices will be * monotonic in the output buffer. */ if (count > 1 && (status_or & kCTRunStatusNonMonotonic) && - buffer->cluster_level != HB_BUFFER_CLUSTER_LEVEL_CHARACTERS) + HB_BUFFER_CLUSTER_LEVEL_IS_MONOTONE (buffer->cluster_level)) { hb_glyph_info_t *info = buffer->info; if (HB_DIRECTION_IS_FORWARD (buffer->props.direction)) diff --git a/src/hb-ot-layout.hh b/src/hb-ot-layout.hh index 52dafbba4..938b9a696 100644 --- a/src/hb-ot-layout.hh +++ b/src/hb-ot-layout.hh @@ -387,7 +387,7 @@ static inline void _hb_ot_layout_reverse_graphemes (hb_buffer_t *buffer) { buffer->reverse_groups (_hb_grapheme_group_func, - buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS); + HB_BUFFER_CLUSTER_LEVEL_IS_MONOTONE (buffer->cluster_level)); } static inline bool diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 6eecc1a10..0469d5981 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -551,7 +551,7 @@ hb_form_clusters (hb_buffer_t *buffer) if (!(buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_NON_ASCII)) return; - if (buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES) + if (HB_BUFFER_CLUSTER_LEVEL_IS_GRAPHEMES (buffer->cluster_level)) foreach_grapheme (buffer, start, end) buffer->merge_clusters (start, end); else @@ -609,7 +609,7 @@ hb_ensure_native_direction (hb_buffer_t *buffer) * Ogham fonts are supposed to be implemented BTT or not. Need to research that * first. */ if ((HB_DIRECTION_IS_HORIZONTAL (direction) && - direction != horiz_dir && horiz_dir != HB_DIRECTION_INVALID) || + direction != horiz_dir && HB_DIRECTION_IS_VALID (horiz_dir)) || (HB_DIRECTION_IS_VERTICAL (direction) && direction != HB_DIRECTION_TTB)) { diff --git a/src/hb-ot-shaper-hangul.cc b/src/hb-ot-shaper-hangul.cc index c90476bc4..50ea53272 100644 --- a/src/hb-ot-shaper-hangul.cc +++ b/src/hb-ot-shaper-hangul.cc @@ -298,8 +298,7 @@ preprocess_text_hangul (const hb_ot_shape_plan_t *plan HB_UNUSED, end = start + 2; if (unlikely (!buffer->successful)) break; - if (buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES) - buffer->merge_out_clusters (start, end); + buffer->merge_out_clusters (start, end); continue; } } @@ -372,8 +371,7 @@ preprocess_text_hangul (const hb_ot_shape_plan_t *plan HB_UNUSED, if (i < end) info[i++].hangul_shaping_feature() = TJMO; - if (buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES) - buffer->merge_out_clusters (start, end); + buffer->merge_out_clusters (start, end); continue; } else if ((!tindex && buffer->idx + 1 < count && isT (buffer->cur(+1).codepoint))) diff --git a/src/hb-ot-shaper-thai.cc b/src/hb-ot-shaper-thai.cc index 6cd67cde3..6124a2114 100644 --- a/src/hb-ot-shaper-thai.cc +++ b/src/hb-ot-shaper-thai.cc @@ -360,7 +360,7 @@ preprocess_text_thai (const hb_ot_shape_plan_t *plan, { /* Since we decomposed, and NIKHAHIT is combining, merge clusters with the * previous cluster. */ - if (start && buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES) + if (start) buffer->merge_out_clusters (start - 1, end); } } From 9305aae476893c670d072089018f8698666d4015 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 12 Feb 2025 11:49:15 +0000 Subject: [PATCH 05/40] [ot-layout] Revert back logic --- src/hb-ot-layout.hh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/hb-ot-layout.hh b/src/hb-ot-layout.hh index 938b9a696..7b5507449 100644 --- a/src/hb-ot-layout.hh +++ b/src/hb-ot-layout.hh @@ -386,8 +386,10 @@ _hb_grapheme_group_func (const hb_glyph_info_t& a HB_UNUSED, static inline void _hb_ot_layout_reverse_graphemes (hb_buffer_t *buffer) { + // MONOTONE_GRAPHEMES was already applied and is taken care of by _hb_grapheme_group_func. + // So we just check for MONOTONE_CHARACTERS here. buffer->reverse_groups (_hb_grapheme_group_func, - HB_BUFFER_CLUSTER_LEVEL_IS_MONOTONE (buffer->cluster_level)); + buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS); } static inline bool From 1531be8a1d1fd204b705fb46acdbbacf90373a48 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 10 Mar 2025 01:02:11 -0600 Subject: [PATCH 06/40] [buffer] Add docs for the new cluster level --- docs/harfbuzz-sections.txt | 3 +++ src/hb-buffer.h | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index 5eb940ee8..f09c85128 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -114,6 +114,9 @@ hb_glyph_position_t hb_buffer_content_type_t hb_buffer_flags_t hb_buffer_cluster_level_t +HB_BUFFER_CLUSTER_LEVEL_IS_CHARACTERS +HB_BUFFER_CLUSTER_LEVEL_IS_GRAPHEMES +HB_BUFFER_CLUSTER_LEVEL_IS_MONOTONE hb_segment_properties_t hb_buffer_serialize_format_t hb_buffer_serialize_flags_t diff --git a/src/hb-buffer.h b/src/hb-buffer.h index 5d3b63f47..ae5f85203 100644 --- a/src/hb-buffer.h +++ b/src/hb-buffer.h @@ -422,6 +422,7 @@ hb_buffer_get_flags (const hb_buffer_t *buffer); * @HB_BUFFER_CLUSTER_LEVEL_CHARACTERS: Don't group cluster values. * @HB_BUFFER_CLUSTER_LEVEL_DEFAULT: Default cluster level, * equal to @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES. + * @HB_BUFFER_CLUSTER_LEVEL_GRAPHEMES: Only group clusters, but don't enfore monotone order. * * Data type for holding HarfBuzz's clustering behavior options. The cluster level * dictates one aspect of how HarfBuzz will treat non-base characters @@ -429,11 +430,26 @@ hb_buffer_get_flags (const hb_buffer_t *buffer); * * In @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES, non-base * characters are merged into the cluster of the base character that precedes them. + * There is also cluster merging evertim the clusters will otherwise become non-monotone. * * In @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS, non-base characters are initially * assigned their own cluster values, which are not merged into preceding base * clusters. This allows HarfBuzz to perform additional operations like reorder - * sequences of adjacent marks. + * sequences of adjacent marks. The output is still monotone, but the cluster + * values are more granular. + * + * In @HB_BUFFER_CLUSTER_LEVEL_CHARACTERS, non-base characters are assigned their + * own cluster values, which are not merged into preceding base clusters. Moreover, + * the cluster values are not merged into monotone order. This is the most granular + * cluster level, and it is useful for clients that need to know the exact cluster + * values of each character, but is harder to use for clients, since clusters + * might appear in any order. + * + * In @HB_BUFFER_CLUSTER_LEVEL_GRAPHEMES, non-base characters are merged into the + * cluster of the base character that precedes them. This is similar to the Unicode + * Grapheme Cluster algorithm, but it is not exactly the same. The output is + * not forced to be monotone. This is useful for clients that want to use HarfBuzz + * as a cheap implementation of the Unicode Grapheme Cluster algorithm. * * @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES is the default, because it maintains * backward compatibility with older versions of HarfBuzz. New client programs that From f88fe4d403d18cf9a54663fe9e1a145aec7e6e45 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 10 Mar 2025 01:02:56 -0600 Subject: [PATCH 07/40] [util] Update for new grapheme cluster level --- util/shape-options.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/shape-options.hh b/util/shape-options.hh index caad5a999..a663008ff 100644 --- a/util/shape-options.hh +++ b/util/shape-options.hh @@ -383,7 +383,7 @@ shape_options_t::add_options (option_parser_t *parser) 0, 0, G_OPTION_ARG_INT, &this->not_found_variation_selector_glyph, "Glyph value to replace not-found variation-selector characters with", nullptr}, {"utf8-clusters", 0, 0, G_OPTION_ARG_NONE, &this->utf8_clusters, "Use UTF8 byte indices, not char indices", nullptr}, - {"cluster-level", 0, 0, G_OPTION_ARG_INT, &this->cluster_level, "Cluster merging level (default: 0)", "0/1/2"}, + {"cluster-level", 0, 0, G_OPTION_ARG_INT, &this->cluster_level, "Cluster merging level (default: 0)", "0/1/2/3"}, {"normalize-glyphs",0, 0, G_OPTION_ARG_NONE, &this->normalize_glyphs, "Rearrange glyph clusters in nominal order", nullptr}, {"unsafe-to-concat",0, 0, G_OPTION_ARG_NONE, &this->unsafe_to_concat, "Produce unsafe-to-concat glyph flag", nullptr}, {"safe-to-insert-tatweel",0, 0, G_OPTION_ARG_NONE, &this->safe_to_insert_tatweel, "Produce safe-to-insert-tatweel glyph flag", nullptr}, From d8a774c0119bf38540ab2b1212e70e9284e957a0 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 10 Mar 2025 01:04:35 -0600 Subject: [PATCH 08/40] [test] Add test for new grapheme cluster level --- test/shape/data/in-house/tests/cluster.tests | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/shape/data/in-house/tests/cluster.tests b/test/shape/data/in-house/tests/cluster.tests index 2663e2362..544a561be 100644 --- a/test/shape/data/in-house/tests/cluster.tests +++ b/test/shape/data/in-house/tests/cluster.tests @@ -1,3 +1,5 @@ +# Our cluster-level=3 doesn't really test anything here. +../fonts/4fac3929fc3332834e93673780ec0fe94342d193.ttf;--cluster-level=3;U+0078,U+030A,U+0058,U+030A;[gid2=0+1083|gid3=1@-1132,-8+0|gid1=2+1200|gid3=3@-1190,349+0] ../fonts/4fac3929fc3332834e93673780ec0fe94342d193.ttf;--cluster-level=2;U+0078,U+030A,U+0058,U+030A;[gid2=0+1083|gid3=1@-1132,-8+0|gid1=2+1200|gid3=3@-1190,349+0] ../fonts/43ef465752be9af900745f72fe29cb853a1401a5.ttf;--cluster-level=1;U+05D4,U+05B7,U+05E9,U+05BC,U+05C1,U+05B8,U+05DE,U+05B4,U+05DD;[uni05DD=8+1359|uni05B4=7@111,0+0|uni05DE=6+1391|uni05B8=5+0|uni05BC=3+0|uni05C1=3+0|uni05E9=2+1451|uni05B7=1@28,0+0|uni05D4=0+1338] ../fonts/6f36d056bad6d478fc0bf7397bd52dc3bd197d5f.ttf;--cluster-level=1;U+099B,U+09CB,U+09C8,U+09C2,U+09CB,U+098C;[evowelsigninibeng=0+346|aivowelsignbeng=0+346|evowelsignbeng=0+346|chabeng=0+687|uuvowelsignlongbeng=0@-96,0+0|aavowelsignbeng=0+266|aavowelsignbeng=4+266|lvocalicbeng=5+639] From 885eef8ea57e12ecb3c1adcce26c234dd03b3fd9 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Mon, 10 Mar 2025 10:33:36 +0200 Subject: [PATCH 09/40] [buffer/doc] Add docs for the new cluster level macros --- src/hb-buffer.h | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/hb-buffer.h b/src/hb-buffer.h index ae5f85203..14063ccd0 100644 --- a/src/hb-buffer.h +++ b/src/hb-buffer.h @@ -422,7 +422,7 @@ hb_buffer_get_flags (const hb_buffer_t *buffer); * @HB_BUFFER_CLUSTER_LEVEL_CHARACTERS: Don't group cluster values. * @HB_BUFFER_CLUSTER_LEVEL_DEFAULT: Default cluster level, * equal to @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES. - * @HB_BUFFER_CLUSTER_LEVEL_GRAPHEMES: Only group clusters, but don't enfore monotone order. + * @HB_BUFFER_CLUSTER_LEVEL_GRAPHEMES: Only group clusters, but don't enforce monotone order. * * Data type for holding HarfBuzz's clustering behavior options. The cluster level * dictates one aspect of how HarfBuzz will treat non-base characters @@ -430,7 +430,7 @@ hb_buffer_get_flags (const hb_buffer_t *buffer); * * In @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES, non-base * characters are merged into the cluster of the base character that precedes them. - * There is also cluster merging evertim the clusters will otherwise become non-monotone. + * There is also cluster merging every time the clusters will otherwise become non-monotone. * * In @HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS, non-base characters are initially * assigned their own cluster values, which are not merged into preceding base @@ -466,14 +466,43 @@ typedef enum { HB_BUFFER_CLUSTER_LEVEL_DEFAULT = HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES } hb_buffer_cluster_level_t; +/** + * HB_BUFFER_CLUSTER_LEVEL_IS_MONOTONE: + * @level: #hb_buffer_cluster_level_t to test + * + * Tests whether a cluster level groups cluster values into monotone order. + * Requires that the level be valid. + * + * XSince: REPLACEME + */ #define HB_BUFFER_CLUSTER_LEVEL_IS_MONOTONE(level) \ ((bool) ((1u << (unsigned) (level)) & \ ((1u << HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES) | \ (1u << HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS)))) + +/** + * HB_BUFFER_CLUSTER_LEVEL_IS_GRAPHEMES: + * @level: #hb_buffer_cluster_level_t to test + * + * Tests whether a cluster level groups cluster values by graphemes. Requires + * that the level be valid. + * + * XSince: REPLACEME + */ #define HB_BUFFER_CLUSTER_LEVEL_IS_GRAPHEMES(level) \ ((bool) ((1u << (unsigned) (level)) & \ ((1u << HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES) | \ (1u << HB_BUFFER_CLUSTER_LEVEL_GRAPHEMES)))) + +/** + * HB_BUFFER_CLUSTER_LEVEL_IS_CHARACTERS + * @level: #hb_buffer_cluster_level_t to test + * + * Tests whether a cluster level does not group cluster values by graphemes. + * Requires that the level be valid. + * + * XSince: REPLACEME + */ #define HB_BUFFER_CLUSTER_LEVEL_IS_CHARACTERS(level) \ ((bool) ((1u << (unsigned) (level)) & \ ((1u << HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARCATERS) | \ From 8ee8e0a213149d88a5657bade405fc94f8871c84 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Mon, 10 Mar 2025 10:36:55 +0200 Subject: [PATCH 10/40] [ci] Enable doc_tests on linux-ci only One workflow is enough. --- .github/workflows/fontations.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/fontations.yml b/.github/workflows/fontations.yml index ba8ff9aa3..371265b2d 100644 --- a/.github/workflows/fontations.yml +++ b/.github/workflows/fontations.yml @@ -56,7 +56,6 @@ jobs: -Dchafa=disabled \ -Dgraphite=enabled \ -Doptimization=2 \ - -Ddoc_tests=true \ -Dfontations=enabled - name: Build run: meson compile -Cbuild From 18e95505796bd59d0e33e5404e2cfa90a23d10ff Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 Mar 2025 10:27:39 +0000 Subject: [PATCH 11/40] Bump github/codeql-action from 3.28.10 to 3.28.11 Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.10 to 3.28.11. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d...6bb031afdd8eb862ea3fc1848194185e076637e5) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/scorecard.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index 3b0aa261e..eb0ceca04 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -59,6 +59,6 @@ jobs: # Upload the results to GitHub's code scanning dashboard. - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d # v3.28.10 + uses: github/codeql-action/upload-sarif@6bb031afdd8eb862ea3fc1848194185e076637e5 # v3.28.11 with: sarif_file: results.sarif From 2edab536bd0a6f9f9d179191e8ef882805546167 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 Mar 2025 10:56:16 +0000 Subject: [PATCH 12/40] Bump setuptools from 75.8.2 to 76.0.0 in /.ci Bumps [setuptools](https://github.com/pypa/setuptools) from 75.8.2 to 76.0.0. - [Release notes](https://github.com/pypa/setuptools/releases) - [Changelog](https://github.com/pypa/setuptools/blob/main/NEWS.rst) - [Commits](https://github.com/pypa/setuptools/compare/v75.8.2...v76.0.0) --- updated-dependencies: - dependency-name: setuptools dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .ci/requirements.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.ci/requirements.txt b/.ci/requirements.txt index 05fb773d1..ba70c63ee 100644 --- a/.ci/requirements.txt +++ b/.ci/requirements.txt @@ -81,7 +81,7 @@ ninja==1.11.1.3 \ # via -r requirements.in # The following packages are considered to be unsafe in a requirements file: -setuptools==75.8.2 \ - --hash=sha256:4880473a969e5f23f2a2be3646b2dfd84af9028716d398e46192f84bc36900d2 \ - --hash=sha256:558e47c15f1811c1fa7adbd0096669bf76c1d3f433f58324df69f3f5ecac4e8f +setuptools==76.0.0 \ + --hash=sha256:199466a166ff664970d0ee145839f5582cb9bca7a0a3a2e795b6a9cb2308e9c6 \ + --hash=sha256:43b4ee60e10b0d0ee98ad11918e114c70701bc6051662a9a675a0496c1a158f4 # via -r requirements.in From 5a0384491490b8ebe44ff23b2642a04c0deb85bd Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 10 Mar 2025 14:54:13 -0600 Subject: [PATCH 13/40] [gen-ragel-artifacts] Fail if ragel failed --- src/gen-ragel-artifacts.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gen-ragel-artifacts.py b/src/gen-ragel-artifacts.py index 8bbb375bf..84bd7b22e 100755 --- a/src/gen-ragel-artifacts.py +++ b/src/gen-ragel-artifacts.py @@ -19,7 +19,9 @@ outdir = os.path.dirname (OUTPUT) shutil.copy (INPUT, outdir) rl = os.path.basename (INPUT) hh = rl.replace ('.rl', '.hh') -subprocess.Popen (ragel.split() + ['-e', '-F1', '-o', hh, rl], cwd=outdir).wait () +ret = subprocess.Popen (ragel.split() + ['-e', '-F1', '-o', hh, rl], cwd=outdir).wait () +if ret: + sys.exit (ret) # copy it also to src/ shutil.copyfile (os.path.join (outdir, hh), os.path.join (CURRENT_SOURCE_DIR, hh)) From c2e92b6f7b006a406d950bf0b4b89c3de1822d5f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 10 Mar 2025 16:18:48 -0600 Subject: [PATCH 14/40] [ragel] Update output files --- src/hb-buffer-deserialize-json.hh | 8 ++++---- src/hb-buffer-deserialize-text-glyphs.hh | 10 +++++----- src/hb-buffer-deserialize-text-unicode.hh | 10 +++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/hb-buffer-deserialize-json.hh b/src/hb-buffer-deserialize-json.hh index 471bbb93f..02054ff9b 100644 --- a/src/hb-buffer-deserialize-json.hh +++ b/src/hb-buffer-deserialize-json.hh @@ -32,7 +32,7 @@ #include "hb.hh" -#line 36 "hb-buffer-deserialize-json.hh" +#line 33 "hb-buffer-deserialize-json.hh" static const unsigned char _deserialize_json_trans_keys[] = { 0u, 0u, 9u, 123u, 9u, 123u, 9u, 34u, 97u, 117u, 120u, 121u, 34u, 34u, 9u, 58u, 9u, 57u, 48u, 57u, 9u, 125u, 9u, 125u, 9u, 125u, 34u, 34u, 9u, 58u, 9u, 57u, @@ -565,12 +565,12 @@ _hb_buffer_deserialize_json (hb_buffer_t *buffer, hb_glyph_info_t info = {0}; hb_glyph_position_t pos = {0}; -#line 569 "hb-buffer-deserialize-json.hh" +#line 562 "hb-buffer-deserialize-json.hh" { cs = deserialize_json_start; } -#line 574 "hb-buffer-deserialize-json.hh" +#line 565 "hb-buffer-deserialize-json.hh" { int _slen; int _trans; @@ -782,7 +782,7 @@ _resume: *end_ptr = p; } break; -#line 786 "hb-buffer-deserialize-json.hh" +#line 743 "hb-buffer-deserialize-json.hh" } _again: diff --git a/src/hb-buffer-deserialize-text-glyphs.hh b/src/hb-buffer-deserialize-text-glyphs.hh index ea81273b3..5fe75659b 100644 --- a/src/hb-buffer-deserialize-text-glyphs.hh +++ b/src/hb-buffer-deserialize-text-glyphs.hh @@ -32,7 +32,7 @@ #include "hb.hh" -#line 36 "hb-buffer-deserialize-text-glyphs.hh" +#line 33 "hb-buffer-deserialize-text-glyphs.hh" static const unsigned char _deserialize_text_glyphs_trans_keys[] = { 0u, 0u, 48u, 57u, 45u, 57u, 48u, 57u, 45u, 57u, 48u, 57u, 48u, 57u, 45u, 57u, 48u, 57u, 44u, 44u, 45u, 57u, 48u, 57u, 44u, 57u, 43u, 124u, 9u, 124u, 9u, 124u, @@ -349,12 +349,12 @@ _hb_buffer_deserialize_text_glyphs (hb_buffer_t *buffer, hb_glyph_info_t info = {0}; hb_glyph_position_t pos = {0}; -#line 353 "hb-buffer-deserialize-text-glyphs.hh" +#line 346 "hb-buffer-deserialize-text-glyphs.hh" { cs = deserialize_text_glyphs_start; } -#line 358 "hb-buffer-deserialize-text-glyphs.hh" +#line 349 "hb-buffer-deserialize-text-glyphs.hh" { int _slen; int _trans; @@ -550,7 +550,7 @@ _resume: *end_ptr = p; } break; -#line 554 "hb-buffer-deserialize-text-glyphs.hh" +#line 516 "hb-buffer-deserialize-text-glyphs.hh" } _again: @@ -667,7 +667,7 @@ _again: *end_ptr = p; } break; -#line 671 "hb-buffer-deserialize-text-glyphs.hh" +#line 616 "hb-buffer-deserialize-text-glyphs.hh" } } diff --git a/src/hb-buffer-deserialize-text-unicode.hh b/src/hb-buffer-deserialize-text-unicode.hh index a8cdf67e7..8ca73bf25 100644 --- a/src/hb-buffer-deserialize-text-unicode.hh +++ b/src/hb-buffer-deserialize-text-unicode.hh @@ -32,7 +32,7 @@ #include "hb.hh" -#line 36 "hb-buffer-deserialize-text-unicode.hh" +#line 33 "hb-buffer-deserialize-text-unicode.hh" static const unsigned char _deserialize_text_unicode_trans_keys[] = { 0u, 0u, 9u, 117u, 43u, 102u, 48u, 102u, 48u, 57u, 9u, 124u, 9u, 124u, 9u, 124u, 9u, 124u, 0 @@ -197,12 +197,12 @@ _hb_buffer_deserialize_text_unicode (hb_buffer_t *buffer, hb_glyph_info_t info = {0}; const hb_glyph_position_t pos = {0}; -#line 201 "hb-buffer-deserialize-text-unicode.hh" +#line 194 "hb-buffer-deserialize-text-unicode.hh" { cs = deserialize_text_unicode_start; } -#line 206 "hb-buffer-deserialize-text-unicode.hh" +#line 197 "hb-buffer-deserialize-text-unicode.hh" { int _slen; int _trans; @@ -269,7 +269,7 @@ _resume: *end_ptr = p; } break; -#line 273 "hb-buffer-deserialize-text-unicode.hh" +#line 256 "hb-buffer-deserialize-text-unicode.hh" } _again: @@ -307,7 +307,7 @@ _again: *end_ptr = p; } break; -#line 311 "hb-buffer-deserialize-text-unicode.hh" +#line 289 "hb-buffer-deserialize-text-unicode.hh" } } From 7a912c474622ad369d2f9f10199325127d48d8ad Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 10 Mar 2025 16:20:16 -0600 Subject: [PATCH 15/40] [buffer-deserialize] Fix return value and parsing I think I got it right. Alternative to https://github.com/harfbuzz/harfbuzz/pull/5028 --- src/hb-buffer-deserialize-json.hh | 764 +++++++++------------ src/hb-buffer-deserialize-json.rl | 6 +- src/hb-buffer-deserialize-text-glyphs.hh | 787 ++++++++-------------- src/hb-buffer-deserialize-text-glyphs.rl | 31 +- src/hb-buffer-deserialize-text-unicode.hh | 212 ++---- src/hb-buffer-deserialize-text-unicode.rl | 32 +- src/hb-buffer-serialize.cc | 6 +- src/hb-number-parser.hh | 8 +- src/hb-ot-shaper-indic-machine.hh | 14 +- src/hb-ot-shaper-khmer-machine.hh | 14 +- src/hb-ot-shaper-myanmar-machine.hh | 14 +- src/hb-ot-shaper-use-machine.hh | 14 +- src/test-buffer-serialize.cc | 27 +- test/api/test-buffer.c | 21 +- 14 files changed, 777 insertions(+), 1173 deletions(-) diff --git a/src/hb-buffer-deserialize-json.hh b/src/hb-buffer-deserialize-json.hh index 02054ff9b..aed094ac3 100644 --- a/src/hb-buffer-deserialize-json.hh +++ b/src/hb-buffer-deserialize-json.hh @@ -34,42 +34,79 @@ #line 33 "hb-buffer-deserialize-json.hh" static const unsigned char _deserialize_json_trans_keys[] = { - 0u, 0u, 9u, 123u, 9u, 123u, 9u, 34u, 97u, 117u, 120u, 121u, 34u, 34u, 9u, 58u, - 9u, 57u, 48u, 57u, 9u, 125u, 9u, 125u, 9u, 125u, 34u, 34u, 9u, 58u, 9u, 57u, - 48u, 57u, 9u, 125u, 9u, 125u, 108u, 108u, 34u, 34u, 9u, 58u, 9u, 57u, 9u, 125u, - 9u, 125u, 120u, 121u, 34u, 34u, 9u, 58u, 9u, 57u, 48u, 57u, 9u, 125u, 9u, 125u, - 34u, 34u, 9u, 58u, 9u, 57u, 48u, 57u, 9u, 125u, 9u, 125u, 108u, 108u, 34u, 34u, - 9u, 58u, 9u, 57u, 9u, 125u, 9u, 125u, 34u, 34u, 9u, 58u, 9u, 57u, 34u, 92u, - 9u, 125u, 34u, 92u, 9u, 125u, 9u, 125u, 34u, 34u, 9u, 58u, 9u, 57u, 9u, 125u, - 9u, 93u, 9u, 123u, 0u, 0u, 0 + 0u, 0u, 9u, 34u, 97u, 117u, 120u, 121u, 34u, 34u, 9u, 58u, 9u, 57u, 48u, 57u, + 9u, 125u, 9u, 125u, 9u, 93u, 9u, 125u, 34u, 34u, 9u, 58u, 9u, 57u, 48u, 57u, + 9u, 125u, 9u, 125u, 108u, 108u, 34u, 34u, 9u, 58u, 9u, 57u, 9u, 125u, 9u, 125u, + 120u, 121u, 34u, 34u, 9u, 58u, 9u, 57u, 48u, 57u, 9u, 125u, 9u, 125u, 34u, 34u, + 9u, 58u, 9u, 57u, 48u, 57u, 9u, 125u, 9u, 125u, 108u, 108u, 34u, 34u, 9u, 58u, + 9u, 57u, 9u, 125u, 9u, 125u, 34u, 34u, 9u, 58u, 9u, 57u, 34u, 92u, 9u, 125u, + 34u, 92u, 9u, 125u, 9u, 125u, 34u, 34u, 9u, 58u, 9u, 57u, 9u, 125u, 9u, 123u, + 9u, 123u, 9u, 123u, 0 }; static const char _deserialize_json_key_spans[] = { - 0, 115, 115, 26, 21, 2, 1, 50, - 49, 10, 117, 117, 117, 1, 50, 49, - 10, 117, 117, 1, 1, 50, 49, 117, - 117, 2, 1, 50, 49, 10, 117, 117, - 1, 50, 49, 10, 117, 117, 1, 1, - 50, 49, 117, 117, 1, 50, 49, 59, - 117, 59, 117, 117, 1, 50, 49, 117, - 85, 115, 0 + 0, 26, 21, 2, 1, 50, 49, 10, + 117, 117, 85, 117, 1, 50, 49, 10, + 117, 117, 1, 1, 50, 49, 117, 117, + 2, 1, 50, 49, 10, 117, 117, 1, + 50, 49, 10, 117, 117, 1, 1, 50, + 49, 117, 117, 1, 50, 49, 59, 117, + 59, 117, 117, 1, 50, 49, 117, 115, + 115, 115 }; static const short _deserialize_json_index_offsets[] = { - 0, 0, 116, 232, 259, 281, 284, 286, - 337, 387, 398, 516, 634, 752, 754, 805, - 855, 866, 984, 1102, 1104, 1106, 1157, 1207, - 1325, 1443, 1446, 1448, 1499, 1549, 1560, 1678, - 1796, 1798, 1849, 1899, 1910, 2028, 2146, 2148, - 2150, 2201, 2251, 2369, 2487, 2489, 2540, 2590, - 2650, 2768, 2828, 2946, 3064, 3066, 3117, 3167, - 3285, 3371, 3487 + 0, 0, 27, 49, 52, 54, 105, 155, + 166, 284, 402, 488, 606, 608, 659, 709, + 720, 838, 956, 958, 960, 1011, 1061, 1179, + 1297, 1300, 1302, 1353, 1403, 1414, 1532, 1650, + 1652, 1703, 1753, 1764, 1882, 2000, 2002, 2004, + 2055, 2105, 2223, 2341, 2343, 2394, 2444, 2504, + 2622, 2682, 2800, 2918, 2920, 2971, 3021, 3139, + 3255, 3371 }; static const char _deserialize_json_indicies[] = { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 2, 1, 3, 1, 4, 5, + 1, 6, 7, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 8, 1, 9, 10, 1, 11, 1, 11, + 11, 11, 11, 11, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 11, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 12, 1, 12, 12, 12, 12, 12, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 12, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 13, 1, + 1, 14, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 1, 16, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 1, 18, + 18, 18, 18, 18, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 18, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 19, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 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, 32, 32, 32, - 32, 32, 1, 33, 33, 33, 33, 33, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 33, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 34, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 20, 1, 24, + 1, 24, 24, 24, 24, 24, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 24, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 25, 1, 25, 25, 25, 25, + 25, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 25, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 26, 1, 1, 27, 28, 28, 28, 28, + 28, 28, 28, 28, 28, 1, 29, 30, + 30, 30, 30, 30, 30, 30, 30, 30, + 1, 31, 31, 31, 31, 31, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 31, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 32, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -189,14 +171,13 @@ static const char _deserialize_json_indicies[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 35, - 1, 33, 33, 33, 33, 33, 1, 1, + 1, 1, 1, 1, 1, 33, 1, 31, + 31, 31, 31, 31, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 31, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 33, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 34, 1, 1, 1, - 32, 32, 32, 32, 32, 32, 32, 32, - 32, 32, 1, 1, 1, 1, 1, 1, + 1, 1, 32, 1, 1, 1, 30, 30, + 30, 30, 30, 30, 30, 30, 30, 30, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -204,25 +185,26 @@ static const char _deserialize_json_indicies[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 35, 1, 36, - 1, 37, 1, 37, 37, 37, 37, 37, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 33, 1, 34, 1, 35, + 1, 35, 35, 35, 35, 35, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 37, 1, 1, 1, 1, 1, + 35, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 38, 1, 38, 38, - 38, 38, 38, 1, 1, 1, 1, 1, + 1, 1, 36, 1, 36, 36, 36, 36, + 36, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 38, 1, 1, + 1, 1, 1, 36, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 39, 40, 40, - 40, 40, 40, 40, 40, 40, 40, 1, - 41, 41, 41, 41, 41, 1, 1, 1, + 1, 1, 1, 37, 38, 38, 38, 38, + 38, 38, 38, 38, 38, 1, 39, 39, + 39, 39, 39, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 41, + 1, 1, 1, 1, 1, 39, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 42, 1, 1, 1, 1, + 1, 40, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -232,13 +214,13 @@ static const char _deserialize_json_indicies[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 43, 1, 41, 41, - 41, 41, 41, 1, 1, 1, 1, 1, + 1, 1, 41, 1, 39, 39, 39, 39, + 39, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 41, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 42, 1, 1, 1, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 1, + 1, 1, 1, 39, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 40, + 1, 1, 1, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -247,229 +229,201 @@ static const char _deserialize_json_indicies[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 43, 1, 45, 46, 1, 47, - 1, 47, 47, 47, 47, 47, 1, 1, + 41, 1, 43, 44, 1, 45, 1, 45, + 45, 45, 45, 45, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 45, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 47, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 46, 1, 46, 46, 46, 46, 46, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 48, 1, 48, 48, 48, 48, - 48, 1, 1, 1, 1, 1, 1, 1, + 1, 46, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 47, 1, + 1, 48, 49, 49, 49, 49, 49, 49, + 49, 49, 49, 1, 50, 51, 51, 51, + 51, 51, 51, 51, 51, 51, 1, 52, + 52, 52, 52, 52, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 48, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 52, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 49, 1, 1, 50, 51, 51, 51, 51, - 51, 51, 51, 51, 51, 1, 52, 53, - 53, 53, 53, 53, 53, 53, 53, 53, - 1, 54, 54, 54, 54, 54, 1, 1, + 1, 1, 53, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 54, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 54, 1, 52, 52, 52, + 52, 52, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 52, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 53, 1, 1, 1, 51, 51, 51, 51, + 51, 51, 51, 51, 51, 51, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 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, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 63, 1, + 1, 1, 61, 61, 61, 61, 61, 61, + 61, 61, 61, 61, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 56, 1, 57, 1, 57, - 57, 57, 57, 57, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 57, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 58, 1, 58, 58, 58, 58, 58, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 64, + 1, 65, 1, 66, 1, 66, 66, 66, + 66, 66, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 58, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 59, 1, - 1, 60, 61, 61, 61, 61, 61, 61, - 61, 61, 61, 1, 62, 63, 63, 63, - 63, 63, 63, 63, 63, 63, 1, 64, - 64, 64, 64, 64, 1, 1, 1, 1, + 1, 1, 1, 1, 66, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 64, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 65, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 67, 1, + 67, 67, 67, 67, 67, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 67, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 68, + 69, 69, 69, 69, 69, 69, 69, 69, + 69, 1, 70, 70, 70, 70, 70, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 70, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 71, 1, 1,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, 71, - 71, 71, 71, 1, 72, 72, 72, 72, - 72, 1, 1, 1, 1, 1, 1, 1, + 1, 75, 1, 75, 75, 75, 75, 75, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 72, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 73, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 75, 1, 76, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 77, 78, 78, 78, 78, 78, + 78, 78, 78, 78, 1, 80, 79, 79, + 79, 79, 79, 79, 79, 79, 79, 79, + 79, 79, 79, 79, 79, 79, 79, 79, + 79, 79, 79, 79, 79, 79, 79, 79, + 79, 79, 79, 79, 79, 79, 79, 79, + 79, 79, 79, 79, 79, 79, 79, 79, + 79, 79, 79, 79, 79, 79, 79, 79, + 79, 79, 79, 79, 79, 79, 79, 81, + 79, 82, 82, 82, 82, 82, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 82, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 83, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 74, 1, 72, 72, 72, 72, 72, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 72, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 73, 1, 1, - 1, 75, 75, 75, 75, 75, 75, 75, - 75, 75, 75, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 84, 1, 79, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 74, 1, - 76, 1, 76, 76, 76, 76, 76, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 79, 1, 85, 85, 85, 85, 85, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 76, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 85, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 86, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 77, 1, 77, 77, 77, - 77, 77, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 77, 1, 78, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 79, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 1, 82, - 81, 81, 81, 81, 81, 81, 81, 81, - 81, 81, 81, 81, 81, 81, 81, 81, - 81, 81, 81, 81, 81, 81, 81, 81, - 81, 81, 81, 81, 81, 81, 81, 81, - 81, 81, 81, 81, 81, 81, 81, 81, - 81, 81, 81, 81, 81, 81, 81, 81, - 81, 81, 81, 81, 81, 81, 81, 81, - 81, 83, 81, 84, 84, 84, 84, 84, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 84, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 85, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 86, -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- 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 92, 1, 92, 92, - 92, 92, 92, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 92, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 93, 94, 94, - 94, 94, 94, 94, 94, 94, 94, 1, - 87, 87, 87, 87, 87, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 87, + 1, 85, 85, 85, 85, 85, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 88, 1, 1, 1, 95, - 95, 95, 95, 95, 95, 95, 95, 95, - 95, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 85, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 86, 1, 1, 1, + 88, 88, 88, 88, 88, 88, 88, 88, + 88, 88, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -477,21 +431,52 @@ static const char _deserialize_json_indicies[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 89, 1, 96, 96, - 96, 96, 96, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 87, 1, 89, + 1, 89, 89, 89, 89, 89, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 96, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 97, 1, 1, 1, 1, 1, 1, + 89, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 90, 1, 90, 90, 90, 90,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -502,47 +487,62 @@ static const char _deserialize_json_indicies[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 3, 1, - 1, 0 + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 96, 1, 23, 23, 23, 23, + 23, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 23, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 96, 1, + 0 }; static const char _deserialize_json_trans_targs[] = { - 1, 0, 2, 3, 3, 4, 5, 19, - 25, 38, 44, 52, 6, 13, 7, 8, - 9, 10, 12, 10, 12, 11, 3, 56, - 11, 56, 14, 15, 16, 17, 18, 17, - 18, 11, 3, 56, 20, 21, 22, 23, - 24, 11, 3, 56, 24, 26, 32, 27, - 28, 29, 30, 31, 30, 31, 11, 3, - 56, 33, 34, 35, 36, 37, 36, 37, - 11, 3, 56, 39, 40, 41, 42, 43, - 11, 3, 56, 43, 45, 46, 47, 50, - 51, 47, 48, 49, 11, 3, 56, 11, - 3, 56, 51, 53, 54, 50, 55, 55, - 56, 57, 58 + 1, 0, 2, 3, 18, 24, 37, 43, + 51, 4, 12, 5, 6, 7, 8, 11, + 8, 11, 9, 1, 10, 9, 10, 57, + 13, 14, 15, 16, 17, 16, 17, 9, + 1, 10, 19, 20, 21, 22, 23, 9, + 1, 10, 23, 25, 31, 26, 27, 28, + 29, 30, 29, 30, 9, 1, 10, 32, + 33, 34, 35, 36, 35, 36, 9, 1, + 10, 38, 39, 40, 41, 42, 9, 1, + 10, 42, 44, 45, 46, 49, 50, 46, + 47, 48, 9, 1, 10, 9, 1, 10, + 50, 52, 53, 49, 54, 54, 55, 56, + 1 }; static const char _deserialize_json_trans_actions[] = { - 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 2, 2, 2, 0, 0, 3, 3, 4, - 0, 5, 0, 0, 2, 2, 2, 0, - 0, 6, 6, 7, 0, 0, 0, 2, - 2, 8, 8, 9, 0, 0, 0, 0, - 0, 2, 2, 2, 0, 0, 10, 10, - 11, 0, 0, 2, 2, 2, 0, 0, - 12, 12, 13, 0, 0, 0, 2, 2, - 14, 14, 15, 0, 0, 0, 2, 16, - 16, 0, 17, 0, 18, 18, 19, 20, - 20, 21, 17, 0, 0, 22, 22, 23, - 0, 0, 0 + 0, 0, 0, 0, 0, 1, 1, 1, + 0, 0, 2, 2, 2, 0, 0, 3, + 0, 0, 1, 1, 1, 0, 0, 4, + 4, 4, 0, 0, 0, 1, 1, 5, + 5, 5, 0, 0, 0, 0, 0, 1, + 1, 1, 0, 0, 6, 6, 6, 0, + 0, 1, 1, 1, 0, 0, 7, 7, + 7, 0, 0, 0, 1, 1, 8, 8, + 8, 0, 0, 0, 1, 9, 9, 0, + 10, 0, 11, 11, 11, 12, 12, 12, + 10, 0, 0, 13, 13, 14, 0, 0, + 15 }; -static const int deserialize_json_start = 1; -static const int deserialize_json_first_final = 56; +static const int deserialize_json_start = 55; +static const int deserialize_json_first_final = 55; static const int deserialize_json_error = 0; -static const int deserialize_json_en_main = 1; +static const int deserialize_json_en_main = 55; #line 111 "hb-buffer-deserialize-json.rl" @@ -595,14 +595,14 @@ _resume: goto _again; switch ( _deserialize_json_trans_actions[_trans] ) { - case 1: + case 15: #line 38 "hb-buffer-deserialize-json.rl" { hb_memset (&info, 0, sizeof (info)); hb_memset (&pos , 0, sizeof (pos )); } break; - case 5: + case 3: #line 43 "hb-buffer-deserialize-json.rl" { buffer->add_info (info); @@ -612,75 +612,21 @@ _resume: *end_ptr = p; } break; - case 2: + case 1: #line 51 "hb-buffer-deserialize-json.rl" { tok = p; } - break; - case 17: -#line 55 "hb-buffer-deserialize-json.rl" - { if (unlikely (!buffer->ensure_glyphs ())) return false; } - break; - case 23: -#line 56 "hb-buffer-deserialize-json.rl" - { if (unlikely (!buffer->ensure_unicode ())) return false; } - break; - case 18: -#line 58 "hb-buffer-deserialize-json.rl" - { - /* TODO Unescape \" and \\ if found. */ - if (!hb_font_glyph_from_string (font, - tok+1, p - tok - 2, /* Skip "" */ - &info.codepoint)) - return false; -} - break; - case 20: -#line 66 "hb-buffer-deserialize-json.rl" - { if (!parse_uint (tok, p, &info.codepoint)) return false; } - break; - case 8: -#line 67 "hb-buffer-deserialize-json.rl" - { if (!parse_uint (tok, p, &info.cluster )) return false; } break; case 10: -#line 68 "hb-buffer-deserialize-json.rl" - { if (!parse_int (tok, p, &pos.x_offset )) return false; } - break; - case 12: -#line 69 "hb-buffer-deserialize-json.rl" - { if (!parse_int (tok, p, &pos.y_offset )) return false; } - break; - case 3: -#line 70 "hb-buffer-deserialize-json.rl" - { if (!parse_int (tok, p, &pos.x_advance)) return false; } - break; - case 6: -#line 71 "hb-buffer-deserialize-json.rl" - { if (!parse_int (tok, p, &pos.y_advance)) return false; } - break; - case 14: -#line 72 "hb-buffer-deserialize-json.rl" - { if (!parse_uint (tok, p, &info.mask )) return false; } - break; - case 16: -#line 51 "hb-buffer-deserialize-json.rl" - { - tok = p; -} #line 55 "hb-buffer-deserialize-json.rl" { if (unlikely (!buffer->ensure_glyphs ())) return false; } break; - case 22: -#line 51 "hb-buffer-deserialize-json.rl" - { - tok = p; -} + case 14: #line 56 "hb-buffer-deserialize-json.rl" { if (unlikely (!buffer->ensure_unicode ())) return false; } break; - case 19: + case 11: #line 58 "hb-buffer-deserialize-json.rl" { /* TODO Unescape \" and \\ if found. */ @@ -688,101 +634,53 @@ _resume: tok+1, p - tok - 2, /* Skip "" */ &info.codepoint)) return false; -} -#line 43 "hb-buffer-deserialize-json.rl" - { - buffer->add_info (info); - if (unlikely (!buffer->successful)) - return false; - buffer->pos[buffer->len - 1] = pos; - *end_ptr = p; } break; - case 21: + case 12: #line 66 "hb-buffer-deserialize-json.rl" { if (!parse_uint (tok, p, &info.codepoint)) return false; } -#line 43 "hb-buffer-deserialize-json.rl" - { - buffer->add_info (info); - if (unlikely (!buffer->successful)) - return false; - buffer->pos[buffer->len - 1] = pos; - *end_ptr = p; -} break; - case 9: + case 5: #line 67 "hb-buffer-deserialize-json.rl" { if (!parse_uint (tok, p, &info.cluster )) return false; } -#line 43 "hb-buffer-deserialize-json.rl" - { - buffer->add_info (info); - if (unlikely (!buffer->successful)) - return false; - buffer->pos[buffer->len - 1] = pos; - *end_ptr = p; -} break; - case 11: + case 6: #line 68 "hb-buffer-deserialize-json.rl" { if (!parse_int (tok, p, &pos.x_offset )) return false; } -#line 43 "hb-buffer-deserialize-json.rl" - { - buffer->add_info (info); - if (unlikely (!buffer->successful)) - return false; - buffer->pos[buffer->len - 1] = pos; - *end_ptr = p; -} - break; - case 13: -#line 69 "hb-buffer-deserialize-json.rl" - { if (!parse_int (tok, p, &pos.y_offset )) return false; } -#line 43 "hb-buffer-deserialize-json.rl" - { - buffer->add_info (info); - if (unlikely (!buffer->successful)) - return false; - buffer->pos[buffer->len - 1] = pos; - *end_ptr = p; -} - break; - case 4: -#line 70 "hb-buffer-deserialize-json.rl" - { if (!parse_int (tok, p, &pos.x_advance)) return false; } -#line 43 "hb-buffer-deserialize-json.rl" - { - buffer->add_info (info); - if (unlikely (!buffer->successful)) - return false; - buffer->pos[buffer->len - 1] = pos; - *end_ptr = p; -} break; case 7: +#line 69 "hb-buffer-deserialize-json.rl" + { if (!parse_int (tok, p, &pos.y_offset )) return false; } + break; + case 2: +#line 70 "hb-buffer-deserialize-json.rl" + { if (!parse_int (tok, p, &pos.x_advance)) return false; } + break; + case 4: #line 71 "hb-buffer-deserialize-json.rl" { if (!parse_int (tok, p, &pos.y_advance)) return false; } -#line 43 "hb-buffer-deserialize-json.rl" - { - buffer->add_info (info); - if (unlikely (!buffer->successful)) - return false; - buffer->pos[buffer->len - 1] = pos; - *end_ptr = p; -} break; - case 15: + case 8: #line 72 "hb-buffer-deserialize-json.rl" { if (!parse_uint (tok, p, &info.mask )) return false; } -#line 43 "hb-buffer-deserialize-json.rl" - { - buffer->add_info (info); - if (unlikely (!buffer->successful)) - return false; - buffer->pos[buffer->len - 1] = pos; - *end_ptr = p; -} break; -#line 743 "hb-buffer-deserialize-json.hh" + case 9: +#line 51 "hb-buffer-deserialize-json.rl" + { + tok = p; +} +#line 55 "hb-buffer-deserialize-json.rl" + { if (unlikely (!buffer->ensure_glyphs ())) return false; } + break; + case 13: +#line 51 "hb-buffer-deserialize-json.rl" + { + tok = p; +} +#line 56 "hb-buffer-deserialize-json.rl" + { if (unlikely (!buffer->ensure_unicode ())) return false; } + break; +#line 657 "hb-buffer-deserialize-json.hh" } _again: @@ -799,7 +697,7 @@ _again: *end_ptr = p; - return p == pe && *(p-1) != ']'; + return p == pe; } #endif /* HB_BUFFER_DESERIALIZE_JSON_HH */ diff --git a/src/hb-buffer-deserialize-json.rl b/src/hb-buffer-deserialize-json.rl index 2f1ad9118..eb092bfe9 100644 --- a/src/hb-buffer-deserialize-json.rl +++ b/src/hb-buffer-deserialize-json.rl @@ -101,12 +101,12 @@ element = glyph @ensure_glyphs | yadvance | glyphflags; item = - ( '{' space* element (comma element)* space* '}') + ( '{' space* element (comma element)* space* '}' space* (','|']') space* ) >clear_item @add_item ; -main := space* '['? space* item (comma item)* space* (','|']')?; +main := space* '['? space* item*; }%% @@ -133,7 +133,7 @@ _hb_buffer_deserialize_json (hb_buffer_t *buffer, *end_ptr = p; - return p == pe && *(p-1) != ']'; + return p == pe; } #endif /* HB_BUFFER_DESERIALIZE_JSON_HH */ diff --git a/src/hb-buffer-deserialize-text-glyphs.hh b/src/hb-buffer-deserialize-text-glyphs.hh index 5fe75659b..a268def5d 100644 --- a/src/hb-buffer-deserialize-text-glyphs.hh +++ b/src/hb-buffer-deserialize-text-glyphs.hh @@ -34,285 +34,247 @@ #line 33 "hb-buffer-deserialize-text-glyphs.hh" static const unsigned char _deserialize_text_glyphs_trans_keys[] = { - 0u, 0u, 48u, 57u, 45u, 57u, 48u, 57u, 45u, 57u, 48u, 57u, 48u, 57u, 45u, 57u, - 48u, 57u, 44u, 44u, 45u, 57u, 48u, 57u, 44u, 57u, 43u, 124u, 9u, 124u, 9u, 124u, - 9u, 124u, 9u, 124u, 9u, 124u, 9u, 124u, 9u, 124u, 9u, 124u, 9u, 124u, 9u, 124u, - 9u, 124u, 9u, 124u, 9u, 124u, 0 + 0u, 0u, 35u, 124u, 48u, 57u, 93u, 124u, 45u, 57u, 48u, 57u, 35u, 124u, 45u, 57u, + 48u, 57u, 35u, 124u, 35u, 124u, 35u, 124u, 48u, 57u, 35u, 124u, 45u, 57u, 48u, 57u, + 44u, 44u, 45u, 57u, 48u, 57u, 35u, 124u, 35u, 124u, 44u, 57u, 35u, 124u, 43u, 124u, + 48u, 124u, 35u, 124u, 35u, 124u, 35u, 124u, 0 }; static const char _deserialize_text_glyphs_key_spans[] = { - 0, 10, 13, 10, 13, 10, 10, 13, - 10, 1, 13, 10, 14, 82, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116 + 0, 90, 10, 32, 13, 10, 90, 13, + 10, 90, 90, 90, 10, 90, 13, 10, + 1, 13, 10, 90, 90, 14, 90, 82, + 77, 90, 90, 90 }; static const short _deserialize_text_glyphs_index_offsets[] = { - 0, 0, 11, 25, 36, 50, 61, 72, - 86, 97, 99, 113, 124, 139, 222, 339, - 456, 573, 690, 807, 924, 1041, 1158, 1275, - 1392, 1509, 1626 + 0, 0, 91, 102, 135, 149, 160, 251, + 265, 276, 367, 458, 549, 560, 651, 665, + 676, 678, 692, 703, 794, 885, 900, 991, + 1074, 1152, 1243, 1334 }; static const char _deserialize_text_glyphs_indicies[] = { - 0, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 1, 3, 1, 1, 4, - 5, 5, 5, 5, 5, 5, 5, 5, - 5, 1, 6, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 1, 8, 1, 1, - 9, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 1, 11, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 1, 13, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 1, 15, 1, 1, 16, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 1, 18, - 19, 19, 19, 19, 19, 19, 19, 19, - 19, 1, 20, 1, 21, 1, 1, 22, - 23, 23, 23, 23, 23, 23, 23, 23, - 23, 1, 24, 25, 25, 25, 25, 25, - 25, 25, 25, 25, 1, 20, 1, 1, - 1, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 1, 26, 26, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 26, 1, - 1, 26, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 26, 26, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 26, 1, 28, - 28, 28, 28, 28, 27, 27, 27, 27, + 1, 0, 0, 0, 0, 0, 0, + 0, 2, 3, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 4, 0, 0, 5, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 6, 7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23, 23, 23, 23, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 25, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 25, 3, 16, 3, 3, 3, 3, + 3, 3, 3, 3, 17, 3, 3, 3, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 18, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 18, 3, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 28, 27, - 27, 29, 27, 27, 27, 27, 27, 27, - 27, 30, 1, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 31, 27, 27, 32, 27, - 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 33, 1, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 28, 27, 34, 34, 34, 34, - 34, 26, 26, 26, 26, 26, 26, 26, - 26, 26, 26, 26, 26, 26, 26, 26, - 26, 26, 26, 34, 26, 26, 35, 26, - 26, 26, 26, 26, 26, 26, 36, 1, - 26, 26, 26, 26, 26, 26, 26, 26, - 26, 26, 26, 26, 26, 26, 26, 26, - 37, 26, 26, 38, 26, 26, 26, 26, - 26, 26, 26, 26, 26, 26, 26, 26, - 26, 26, 26, 26, 26, 26, 26, 26, - 26, 26, 26, 26, 26, 26, 26, 39, - 1, 26, 26, 26, 26, 26, 26, 26, - 26, 26, 26, 26, 26, 26, 26, 26, - 26, 26, 26, 26, 26, 26, 26, 26, - 26, 26, 26, 26, 26, 26, 26, 40, - 26, 41, 41, 41, 41, 41, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 41, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 42, 1, 43, 43, - 43, 43, 43, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 43, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 44, 1, 41, 41, 41, 41, 41, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 41, 1, 1, 1, 1, 1, - 1, 1, 1,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 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 57, 1, - 0 + 3, 28, 3, 3, 3, 3, 3, 3, + 3, 29, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 30, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 31, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 31, 3, 32, 3, 3, 33, + 34, 34, 34, 34, 34, 34, 34, 34, + 34, 3, 35, 36, 36, 36, 36, 36, + 36, 36, 36, 36, 3, 37, 3, 38, + 3, 3, 39, 40, 40, 40, 40, 40, + 40, 40, 40, 40, 3, 41, 42, 42, + 42, 42, 42, 42, 42, 42, 42, 3, + 43, 3, 3, 3, 3, 3, 3, 3, + 44, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 45, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 45, 3, 43, 3, 3, 3, 3, + 3, 3, 3, 44, 3, 3, 3, 3, + 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 45, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 45, 3, 37, 3, + 3, 3, 36, 36, 36, 36, 36, 36, + 36, 36, 36, 36, 3, 28, 3, 3, + 3, 3, 3, 3, 3, 29, 3, 3, + 3, 3, 46, 46, 46, 46, 46, 46, + 46, 46, 46, 46, 3, 3, 3, 3, + 3, 3, 30, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 31, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 31, 3, + 0, 0, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 0, 3, 3, 0, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 0, 0, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 0, 3, 47, 47, 47, 47, 47, + 47, 47, 47, 47, 47, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 10, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 10, + 3, 49, 48, 48, 48, 48, 48, 48, + 48, 50, 3, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 51, 48, 48, 52, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 53, 54, 55, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 55, 48, 57, 56, 56, 56, + 56, 56, 56, 56, 58, 3, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 59, 56, + 56, 60, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 61, 62, 56, + 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 62, 56, 63, + 48, 48, 48, 48, 48, 48, 48, 64, + 3, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 65, 48, 48, 66, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 54, 67, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 67, 48, 0 }; static const char _deserialize_text_glyphs_trans_targs[] = { - 16, 0, 18, 3, 19, 22, 19, 22, - 5, 20, 21, 20, 21, 23, 26, 8, - 9, 12, 9, 12, 10, 11, 24, 25, - 24, 25, 15, 15, 14, 1, 2, 6, - 7, 13, 15, 1, 2, 6, 7, 13, - 14, 17, 14, 17, 14, 18, 17, 1, - 4, 14, 17, 1, 14, 17, 1, 2, - 7, 14, 17, 1, 2, 14, 26 + 1, 2, 4, 0, 12, 14, 23, 26, + 3, 24, 26, 5, 6, 11, 6, 11, + 2, 7, 26, 8, 9, 10, 9, 10, + 2, 26, 13, 22, 2, 4, 14, 26, + 15, 16, 21, 16, 21, 17, 18, 19, + 20, 19, 20, 2, 4, 26, 22, 24, + 1, 2, 4, 12, 14, 27, 23, 26, + 1, 2, 4, 12, 14, 23, 26, 2, + 4, 12, 14, 26 }; static const char _deserialize_text_glyphs_trans_actions[] = { - 1, 0, 1, 1, 1, 1, 0, 0, - 1, 1, 1, 0, 0, 1, 1, 1, - 1, 1, 0, 0, 2, 1, 1, 1, - 0, 0, 0, 4, 3, 5, 5, 5, - 5, 4, 6, 7, 7, 7, 7, 0, - 6, 8, 8, 0, 0, 0, 9, 10, - 10, 9, 11, 12, 11, 13, 14, 14, - 14, 13, 15, 16, 16, 15, 0 + 0, 1, 1, 0, 1, 1, 0, 1, + 2, 2, 3, 2, 2, 2, 0, 0, + 4, 4, 4, 2, 2, 2, 0, 0, + 5, 5, 2, 2, 6, 6, 6, 6, + 2, 2, 2, 0, 0, 7, 2, 2, + 2, 0, 0, 8, 8, 8, 0, 0, + 9, 10, 10, 10, 10, 9, 9, 10, + 12, 13, 13, 13, 13, 12, 13, 14, + 14, 14, 14, 14 }; static const char _deserialize_text_glyphs_eof_actions[] = { 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 3, 6, - 8, 0, 8, 9, 11, 11, 9, 13, - 15, 15, 13 + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 11, 0 }; -static const int deserialize_text_glyphs_start = 14; -static const int deserialize_text_glyphs_first_final = 14; +static const int deserialize_text_glyphs_start = 25; +static const int deserialize_text_glyphs_first_final = 25; static const int deserialize_text_glyphs_error = 0; -static const int deserialize_text_glyphs_en_main = 14; +static const int deserialize_text_glyphs_en_main = 25; -#line 98 "hb-buffer-deserialize-text-glyphs.rl" +#line 99 "hb-buffer-deserialize-text-glyphs.rl" static hb_bool_t @@ -322,39 +284,22 @@ _hb_buffer_deserialize_text_glyphs (hb_buffer_t *buffer, const char **end_ptr, hb_font_t *font) { - const char *p = buf, *pe = buf + buf_len, *eof = pe, *orig_pe = pe; + const char *p = buf, *pe = buf + buf_len, *eof = pe; /* Ensure we have positions. */ (void) hb_buffer_get_glyph_positions (buffer, nullptr); - while (p < pe && ISSPACE (*p)) - p++; - if (p < pe && *p == (buffer->len ? '|' : '[')) - *end_ptr = ++p; - - const char *end = strchr ((char *) p, ']'); - if (end) - pe = eof = end; - else - { - end = strrchr ((char *) p, '|'); - if (end) - pe = eof = end; - else - pe = eof = p; - } - const char *tok = nullptr; int cs; hb_glyph_info_t info = {0}; hb_glyph_position_t pos = {0}; -#line 346 "hb-buffer-deserialize-text-glyphs.hh" +#line 291 "hb-buffer-deserialize-text-glyphs.hh" { cs = deserialize_text_glyphs_start; } -#line 349 "hb-buffer-deserialize-text-glyphs.hh" +#line 294 "hb-buffer-deserialize-text-glyphs.hh" { int _slen; int _trans; @@ -379,13 +324,13 @@ _resume: goto _again; switch ( _deserialize_text_glyphs_trans_actions[_trans] ) { - case 1: + case 2: #line 51 "hb-buffer-deserialize-text-glyphs.rl" { tok = p; } break; - case 7: + case 1: #line 55 "hb-buffer-deserialize-text-glyphs.rl" { /* TODO Unescape delimiters. */ @@ -393,40 +338,53 @@ _resume: tok, p - tok, &info.codepoint)) return false; -} - break; - case 14: -#line 63 "hb-buffer-deserialize-text-glyphs.rl" - { if (!parse_uint (tok, p, &info.cluster )) return false; } - break; - case 2: -#line 64 "hb-buffer-deserialize-text-glyphs.rl" - { if (!parse_int (tok, p, &pos.x_offset )) return false; } - break; - case 16: -#line 65 "hb-buffer-deserialize-text-glyphs.rl" - { if (!parse_int (tok, p, &pos.y_offset )) return false; } - break; - case 10: -#line 66 "hb-buffer-deserialize-text-glyphs.rl" - { if (!parse_int (tok, p, &pos.x_advance)) return false; } - break; - case 12: -#line 67 "hb-buffer-deserialize-text-glyphs.rl" - { if (!parse_int (tok, p, &pos.y_advance)) return false; } - break; - case 4: -#line 38 "hb-buffer-deserialize-text-glyphs.rl" - { - hb_memset (&info, 0, sizeof (info)); - hb_memset (&pos , 0, sizeof (pos )); -} -#line 51 "hb-buffer-deserialize-text-glyphs.rl" - { - tok = p; } break; case 6: +#line 63 "hb-buffer-deserialize-text-glyphs.rl" + { if (!parse_uint (tok, p, &info.cluster )) return false; } + break; + case 7: +#line 64 "hb-buffer-deserialize-text-glyphs.rl" + { if (!parse_int (tok, p, &pos.x_offset )) return false; } + break; + case 8: +#line 65 "hb-buffer-deserialize-text-glyphs.rl" + { if (!parse_int (tok, p, &pos.y_offset )) return false; } + break; + case 4: +#line 66 "hb-buffer-deserialize-text-glyphs.rl" + { if (!parse_int (tok, p, &pos.x_advance)) return false; } + break; + case 5: +#line 67 "hb-buffer-deserialize-text-glyphs.rl" + { if (!parse_int (tok, p, &pos.y_advance)) return false; } + break; + case 3: +#line 68 "hb-buffer-deserialize-text-glyphs.rl" + { if (!parse_uint (tok, p, &info.mask )) return false; } + break; + case 9: +#line 38 "hb-buffer-deserialize-text-glyphs.rl" + { + hb_memset (&info, 0, sizeof (info)); + hb_memset (&pos , 0, sizeof (pos )); +} +#line 51 "hb-buffer-deserialize-text-glyphs.rl" + { + tok = p; +} + break; + case 10: +#line 38 "hb-buffer-deserialize-text-glyphs.rl" + { + hb_memset (&info, 0, sizeof (info)); + hb_memset (&pos , 0, sizeof (pos )); +} +#line 51 "hb-buffer-deserialize-text-glyphs.rl" + { + tok = p; +} #line 55 "hb-buffer-deserialize-text-glyphs.rl" { /* TODO Unescape delimiters. */ @@ -435,6 +393,8 @@ _resume: &info.codepoint)) return false; } + break; + case 12: #line 43 "hb-buffer-deserialize-text-glyphs.rl" { buffer->add_info (info); @@ -442,11 +402,37 @@ _resume: return false; buffer->pos[buffer->len - 1] = pos; *end_ptr = p; +} +#line 38 "hb-buffer-deserialize-text-glyphs.rl" + { + hb_memset (&info, 0, sizeof (info)); + hb_memset (&pos , 0, sizeof (pos )); +} +#line 51 "hb-buffer-deserialize-text-glyphs.rl" + { + tok = p; +} + break; + case 14: +#line 55 "hb-buffer-deserialize-text-glyphs.rl" + { + /* TODO Unescape delimiters. */ + if (!hb_font_glyph_from_string (font, + tok, p - tok, + &info.codepoint)) + return false; +} +#line 38 "hb-buffer-deserialize-text-glyphs.rl" + { + hb_memset (&info, 0, sizeof (info)); + hb_memset (&pos , 0, sizeof (pos )); +} +#line 51 "hb-buffer-deserialize-text-glyphs.rl" + { + tok = p; } break; case 13: -#line 63 "hb-buffer-deserialize-text-glyphs.rl" - { if (!parse_uint (tok, p, &info.cluster )) return false; } #line 43 "hb-buffer-deserialize-text-glyphs.rl" { buffer->add_info (info); @@ -455,56 +441,6 @@ _resume: buffer->pos[buffer->len - 1] = pos; *end_ptr = p; } - break; - case 15: -#line 65 "hb-buffer-deserialize-text-glyphs.rl" - { if (!parse_int (tok, p, &pos.y_offset )) return false; } -#line 43 "hb-buffer-deserialize-text-glyphs.rl" - { - buffer->add_info (info); - if (unlikely (!buffer->successful)) - return false; - buffer->pos[buffer->len - 1] = pos; - *end_ptr = p; -} - break; - case 9: -#line 66 "hb-buffer-deserialize-text-glyphs.rl" - { if (!parse_int (tok, p, &pos.x_advance)) return false; } -#line 43 "hb-buffer-deserialize-text-glyphs.rl" - { - buffer->add_info (info); - if (unlikely (!buffer->successful)) - return false; - buffer->pos[buffer->len - 1] = pos; - *end_ptr = p; -} - break; - case 11: -#line 67 "hb-buffer-deserialize-text-glyphs.rl" - { if (!parse_int (tok, p, &pos.y_advance)) return false; } -#line 43 "hb-buffer-deserialize-text-glyphs.rl" - { - buffer->add_info (info); - if (unlikely (!buffer->successful)) - return false; - buffer->pos[buffer->len - 1] = pos; - *end_ptr = p; -} - break; - case 8: -#line 68 "hb-buffer-deserialize-text-glyphs.rl" - { if (!parse_uint (tok, p, &info.mask )) return false; } -#line 43 "hb-buffer-deserialize-text-glyphs.rl" - { - buffer->add_info (info); - if (unlikely (!buffer->successful)) - return false; - buffer->pos[buffer->len - 1] = pos; - *end_ptr = p; -} - break; - case 5: #line 38 "hb-buffer-deserialize-text-glyphs.rl" { hb_memset (&info, 0, sizeof (info)); @@ -523,34 +459,7 @@ _resume: return false; } break; - case 3: -#line 38 "hb-buffer-deserialize-text-glyphs.rl" - { - hb_memset (&info, 0, sizeof (info)); - hb_memset (&pos , 0, sizeof (pos )); -} -#line 51 "hb-buffer-deserialize-text-glyphs.rl" - { - tok = p; -} -#line 55 "hb-buffer-deserialize-text-glyphs.rl" - { - /* TODO Unescape delimiters. */ - if (!hb_font_glyph_from_string (font, - tok, p - tok, - &info.codepoint)) - return false; -} -#line 43 "hb-buffer-deserialize-text-glyphs.rl" - { - buffer->add_info (info); - if (unlikely (!buffer->successful)) - return false; - buffer->pos[buffer->len - 1] = pos; - *end_ptr = p; -} - break; -#line 516 "hb-buffer-deserialize-text-glyphs.hh" +#line 430 "hb-buffer-deserialize-text-glyphs.hh" } _again: @@ -562,63 +471,7 @@ _again: if ( p == eof ) { switch ( _deserialize_text_glyphs_eof_actions[cs] ) { - case 6: -#line 55 "hb-buffer-deserialize-text-glyphs.rl" - { - /* TODO Unescape delimiters. */ - if (!hb_font_glyph_from_string (font, - tok, p - tok, - &info.codepoint)) - return false; -} -#line 43 "hb-buffer-deserialize-text-glyphs.rl" - { - buffer->add_info (info); - if (unlikely (!buffer->successful)) - return false; - buffer->pos[buffer->len - 1] = pos; - *end_ptr = p; -} - break; - case 13: -#line 63 "hb-buffer-deserialize-text-glyphs.rl" - { if (!parse_uint (tok, p, &info.cluster )) return false; } -#line 43 "hb-buffer-deserialize-text-glyphs.rl" - { - buffer->add_info (info); - if (unlikely (!buffer->successful)) - return false; - buffer->pos[buffer->len - 1] = pos; - *end_ptr = p; -} - break; - case 15: -#line 65 "hb-buffer-deserialize-text-glyphs.rl" - { if (!parse_int (tok, p, &pos.y_offset )) return false; } -#line 43 "hb-buffer-deserialize-text-glyphs.rl" - { - buffer->add_info (info); - if (unlikely (!buffer->successful)) - return false; - buffer->pos[buffer->len - 1] = pos; - *end_ptr = p; -} - break; - case 9: -#line 66 "hb-buffer-deserialize-text-glyphs.rl" - { if (!parse_int (tok, p, &pos.x_advance)) return false; } -#line 43 "hb-buffer-deserialize-text-glyphs.rl" - { - buffer->add_info (info); - if (unlikely (!buffer->successful)) - return false; - buffer->pos[buffer->len - 1] = pos; - *end_ptr = p; -} - break; case 11: -#line 67 "hb-buffer-deserialize-text-glyphs.rl" - { if (!parse_int (tok, p, &pos.y_advance)) return false; } #line 43 "hb-buffer-deserialize-text-glyphs.rl" { buffer->add_info (info); @@ -628,62 +481,16 @@ _again: *end_ptr = p; } break; - case 8: -#line 68 "hb-buffer-deserialize-text-glyphs.rl" - { if (!parse_uint (tok, p, &info.mask )) return false; } -#line 43 "hb-buffer-deserialize-text-glyphs.rl" - { - buffer->add_info (info); - if (unlikely (!buffer->successful)) - return false; - buffer->pos[buffer->len - 1] = pos; - *end_ptr = p; -} - break; - case 3: -#line 38 "hb-buffer-deserialize-text-glyphs.rl" - { - hb_memset (&info, 0, sizeof (info)); - hb_memset (&pos , 0, sizeof (pos )); -} -#line 51 "hb-buffer-deserialize-text-glyphs.rl" - { - tok = p; -} -#line 55 "hb-buffer-deserialize-text-glyphs.rl" - { - /* TODO Unescape delimiters. */ - if (!hb_font_glyph_from_string (font, - tok, p - tok, - &info.codepoint)) - return false; -} -#line 43 "hb-buffer-deserialize-text-glyphs.rl" - { - buffer->add_info (info); - if (unlikely (!buffer->successful)) - return false; - buffer->pos[buffer->len - 1] = pos; - *end_ptr = p; -} - break; -#line 616 "hb-buffer-deserialize-text-glyphs.hh" +#line 450 "hb-buffer-deserialize-text-glyphs.hh" } } _out: {} } -#line 136 "hb-buffer-deserialize-text-glyphs.rl" +#line 120 "hb-buffer-deserialize-text-glyphs.rl" - if (pe < orig_pe && *pe == ']') - { - pe++; - if (p == pe) - p++; - } - *end_ptr = p; return p == pe; diff --git a/src/hb-buffer-deserialize-text-glyphs.rl b/src/hb-buffer-deserialize-text-glyphs.rl index 21db14b56..8efedb8d3 100644 --- a/src/hb-buffer-deserialize-text-glyphs.rl +++ b/src/hb-buffer-deserialize-text-glyphs.rl @@ -86,14 +86,15 @@ glyph_item = offsets? advances? glyphflags? + ( '|' | ']') ) >clear_item %add_item ; -glyphs = glyph_item (space* '|' space* glyph_item)* space*; +glyphs = '['? glyph_item* ; -main := space* glyphs; +main := glyphs; }%% @@ -104,28 +105,11 @@ _hb_buffer_deserialize_text_glyphs (hb_buffer_t *buffer, const char **end_ptr, hb_font_t *font) { - const char *p = buf, *pe = buf + buf_len, *eof = pe, *orig_pe = pe; + const char *p = buf, *pe = buf + buf_len, *eof = pe; /* Ensure we have positions. */ (void) hb_buffer_get_glyph_positions (buffer, nullptr); - while (p < pe && ISSPACE (*p)) - p++; - if (p < pe && *p == (buffer->len ? '|' : '[')) - *end_ptr = ++p; - - const char *end = strchr ((char *) p, ']'); - if (end) - pe = eof = end; - else - { - end = strrchr ((char *) p, '|'); - if (end) - pe = eof = end; - else - pe = eof = p; - } - const char *tok = nullptr; int cs; hb_glyph_info_t info = {0}; @@ -135,13 +119,6 @@ _hb_buffer_deserialize_text_glyphs (hb_buffer_t *buffer, write exec; }%% - if (pe < orig_pe && *pe == ']') - { - pe++; - if (p == pe) - p++; - } - *end_ptr = p; return p == pe; diff --git a/src/hb-buffer-deserialize-text-unicode.hh b/src/hb-buffer-deserialize-text-unicode.hh index 8ca73bf25..0bb00c4c2 100644 --- a/src/hb-buffer-deserialize-text-unicode.hh +++ b/src/hb-buffer-deserialize-text-unicode.hh @@ -34,135 +34,106 @@ #line 33 "hb-buffer-deserialize-text-unicode.hh" static const unsigned char _deserialize_text_unicode_trans_keys[] = { - 0u, 0u, 9u, 117u, 43u, 102u, 48u, 102u, 48u, 57u, 9u, 124u, 9u, 124u, 9u, 124u, - 9u, 124u, 0 + 0u, 0u, 43u, 102u, 48u, 102u, 48u, 124u, 48u, 57u, 62u, 124u, 48u, 124u, 60u, 117u, + 85u, 117u, 85u, 117u, 0 }; static const char _deserialize_text_unicode_key_spans[] = { - 0, 109, 60, 55, 10, 116, 116, 116, - 116 + 0, 60, 55, 77, 10, 63, 77, 58, + 33, 33 }; static const short _deserialize_text_unicode_index_offsets[] = { - 0, 0, 110, 171, 227, 238, 355, 472, - 589 + 0, 0, 61, 117, 195, 206, 270, 348, + 407, 441 }; static const char _deserialize_text_unicode_indicies[] = { - 0, 0, 0, 0, 0, 1, 1, + 0, 1, 1, 1, 1, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, + 1, 1, 1, 1, 1, 1, 1, 2, + 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 2, + 2, 2, 2, 2, 2, 1, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, + 1, 1, 1, 1, 1, 1, 1, 2, + 2, 2, 2, 2, 2, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 2, + 2, 2, 2, 2, 2, 1, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 1, 1, 1, 4, 5, 1, 1, 3, + 3, 3, 3, 3, 3, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 3, + 3, 3, 3, 3, 3, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 5, 1, 6, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 1, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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14, 14, - 14, 14, 14, 14, 14, 14, 14, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 13, 1, 0 + 1, 1, 12, 1, 0 }; static const char _deserialize_text_unicode_trans_targs[] = { - 1, 0, 2, 3, 5, 7, 8, 6, - 5, 4, 1, 6, 6, 1, 8 + 2, 0, 3, 3, 4, 9, 5, 6, + 9, 6, 8, 1, 1 }; static const char _deserialize_text_unicode_trans_actions[] = { - 0, 0, 1, 0, 2, 2, 2, 3, - 0, 4, 3, 0, 5, 5, 0 + 0, 0, 1, 0, 2, 2, 1, 1, + 3, 0, 0, 4, 6 }; static const char _deserialize_text_unicode_eof_actions[] = { - 0, 0, 0, 0, 0, 3, 0, 5, - 5 + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 5 }; -static const int deserialize_text_unicode_start = 1; -static const int deserialize_text_unicode_first_final = 5; +static const int deserialize_text_unicode_start = 7; +static const int deserialize_text_unicode_first_final = 7; static const int deserialize_text_unicode_error = 0; -static const int deserialize_text_unicode_en_main = 1; +static const int deserialize_text_unicode_en_main = 7; -#line 79 "hb-buffer-deserialize-text-unicode.rl" +#line 80 "hb-buffer-deserialize-text-unicode.rl" static hb_bool_t @@ -172,37 +143,19 @@ _hb_buffer_deserialize_text_unicode (hb_buffer_t *buffer, const char **end_ptr, hb_font_t *font) { - const char *p = buf, *pe = buf + buf_len, *eof = pe, *orig_pe = pe; - - while (p < pe && ISSPACE (*p)) - p++; - if (p < pe && *p == (buffer->len ? '|' : '<')) - *end_ptr = ++p; - - const char *end = strchr ((char *) p, '>'); - if (end) - pe = eof = end; - else - { - end = strrchr ((char *) p, '|'); - if (end) - pe = eof = end; - else - pe = eof = p; - } - + const char *p = buf, *pe = buf + buf_len, *eof = pe; const char *tok = nullptr; int cs; hb_glyph_info_t info = {0}; const hb_glyph_position_t pos = {0}; -#line 194 "hb-buffer-deserialize-text-unicode.hh" +#line 147 "hb-buffer-deserialize-text-unicode.hh" { cs = deserialize_text_unicode_start; } -#line 197 "hb-buffer-deserialize-text-unicode.hh" +#line 150 "hb-buffer-deserialize-text-unicode.hh" { int _slen; int _trans; @@ -227,38 +180,27 @@ _resume: goto _again; switch ( _deserialize_text_unicode_trans_actions[_trans] ) { - case 1: + case 4: #line 38 "hb-buffer-deserialize-text-unicode.rl" { hb_memset (&info, 0, sizeof (info)); } break; - case 2: + case 1: #line 51 "hb-buffer-deserialize-text-unicode.rl" { tok = p; } break; - case 4: + case 2: #line 55 "hb-buffer-deserialize-text-unicode.rl" {if (!parse_hex (tok, p, &info.codepoint )) return false; } break; case 3: -#line 55 "hb-buffer-deserialize-text-unicode.rl" - {if (!parse_hex (tok, p, &info.codepoint )) return false; } -#line 42 "hb-buffer-deserialize-text-unicode.rl" - { - buffer->add_info (info); - if (unlikely (!buffer->successful)) - return false; - if (buffer->have_positions) - buffer->pos[buffer->len - 1] = pos; - *end_ptr = p; -} - break; - case 5: #line 57 "hb-buffer-deserialize-text-unicode.rl" { if (!parse_uint (tok, p, &info.cluster )) return false; } + break; + case 6: #line 42 "hb-buffer-deserialize-text-unicode.rl" { buffer->add_info (info); @@ -267,9 +209,13 @@ _resume: if (buffer->have_positions) buffer->pos[buffer->len - 1] = pos; *end_ptr = p; +} +#line 38 "hb-buffer-deserialize-text-unicode.rl" + { + hb_memset (&info, 0, sizeof (info)); } break; -#line 256 "hb-buffer-deserialize-text-unicode.hh" +#line 203 "hb-buffer-deserialize-text-unicode.hh" } _again: @@ -281,22 +227,7 @@ _again: if ( p == eof ) { switch ( _deserialize_text_unicode_eof_actions[cs] ) { - case 3: -#line 55 "hb-buffer-deserialize-text-unicode.rl" - {if (!parse_hex (tok, p, &info.codepoint )) return false; } -#line 42 "hb-buffer-deserialize-text-unicode.rl" - { - buffer->add_info (info); - if (unlikely (!buffer->successful)) - return false; - if (buffer->have_positions) - buffer->pos[buffer->len - 1] = pos; - *end_ptr = p; -} - break; case 5: -#line 57 "hb-buffer-deserialize-text-unicode.rl" - { if (!parse_uint (tok, p, &info.cluster )) return false; } #line 42 "hb-buffer-deserialize-text-unicode.rl" { buffer->add_info (info); @@ -307,23 +238,16 @@ _again: *end_ptr = p; } break; -#line 289 "hb-buffer-deserialize-text-unicode.hh" +#line 224 "hb-buffer-deserialize-text-unicode.hh" } } _out: {} } -#line 115 "hb-buffer-deserialize-text-unicode.rl" +#line 98 "hb-buffer-deserialize-text-unicode.rl" - if (pe < orig_pe && *pe == '>') - { - pe++; - if (p == pe) - p++; - } - *end_ptr = p; return p == pe; diff --git a/src/hb-buffer-deserialize-text-unicode.rl b/src/hb-buffer-deserialize-text-unicode.rl index 92873b804..1e123c8b2 100644 --- a/src/hb-buffer-deserialize-text-unicode.rl +++ b/src/hb-buffer-deserialize-text-unicode.rl @@ -67,14 +67,15 @@ unicode_item = ( unicode cluster? + ('|' | '>') ) >clear_item %add_item ; -unicodes = unicode_item (space* '|' space* unicode_item)* space*; +unicodes = '<'? unicode_item*; -main := space* unicodes; +main := unicodes; }%% @@ -85,25 +86,7 @@ _hb_buffer_deserialize_text_unicode (hb_buffer_t *buffer, const char **end_ptr, hb_font_t *font) { - const char *p = buf, *pe = buf + buf_len, *eof = pe, *orig_pe = pe; - - while (p < pe && ISSPACE (*p)) - p++; - if (p < pe && *p == (buffer->len ? '|' : '<')) - *end_ptr = ++p; - - const char *end = strchr ((char *) p, '>'); - if (end) - pe = eof = end; - else - { - end = strrchr ((char *) p, '|'); - if (end) - pe = eof = end; - else - pe = eof = p; - } - + const char *p = buf, *pe = buf + buf_len, *eof = pe; const char *tok = nullptr; int cs; @@ -114,13 +97,6 @@ _hb_buffer_deserialize_text_unicode (hb_buffer_t *buffer, write exec; }%% - if (pe < orig_pe && *pe == '>') - { - pe++; - if (p == pe) - p++; - } - *end_ptr = p; return p == pe; diff --git a/src/hb-buffer-serialize.cc b/src/hb-buffer-serialize.cc index 16f189519..de2c99d98 100644 --- a/src/hb-buffer-serialize.cc +++ b/src/hb-buffer-serialize.cc @@ -737,8 +737,7 @@ parse_hex (const char *pp, const char *end, uint32_t *pv) * Deserializes glyphs @buffer from textual representation in the format * produced by hb_buffer_serialize_glyphs(). * - * Return value: `true` if parse was successful, `false` if an error - * occurred. + * Return value: `true` if the full string was parsed, `false` otherwise. * * Since: 0.9.7 **/ @@ -810,8 +809,7 @@ hb_buffer_deserialize_glyphs (hb_buffer_t *buffer, * Deserializes Unicode @buffer from textual representation in the format * produced by hb_buffer_serialize_unicode(). * - * Return value: `true` if parse was successful, `false` if an error - * occurred. + * Return value: `true` if the full string was parsed, `false` otherwise. * * Since: 2.7.3 **/ diff --git a/src/hb-number-parser.hh b/src/hb-number-parser.hh index 1a9dbba6d..ec68c3a72 100644 --- a/src/hb-number-parser.hh +++ b/src/hb-number-parser.hh @@ -31,7 +31,7 @@ #include "hb.hh" -#line 35 "hb-number-parser.hh" +#line 32 "hb-number-parser.hh" static const unsigned char _double_parser_trans_keys[] = { 0u, 0u, 43u, 57u, 46u, 57u, 48u, 57u, 43u, 57u, 48u, 57u, 48u, 101u, 48u, 57u, 46u, 101u, 0 @@ -135,12 +135,12 @@ strtod_rl (const char *p, const char **end_ptr /* IN/OUT */) int cs; -#line 139 "hb-number-parser.hh" +#line 132 "hb-number-parser.hh" { cs = double_parser_start; } -#line 144 "hb-number-parser.hh" +#line 135 "hb-number-parser.hh" { int _slen; int _trans; @@ -198,7 +198,7 @@ _resume: exp_overflow = true; } break; -#line 202 "hb-number-parser.hh" +#line 187 "hb-number-parser.hh" } _again: diff --git a/src/hb-ot-shaper-indic-machine.hh b/src/hb-ot-shaper-indic-machine.hh index 6ff65c30a..92fb64ad0 100644 --- a/src/hb-ot-shaper-indic-machine.hh +++ b/src/hb-ot-shaper-indic-machine.hh @@ -53,7 +53,7 @@ enum indic_syllable_type_t { }; -#line 57 "hb-ot-shaper-indic-machine.hh" +#line 54 "hb-ot-shaper-indic-machine.hh" #define indic_syllable_machine_ex_A 9u #define indic_syllable_machine_ex_C 1u #define indic_syllable_machine_ex_CM 16u @@ -77,7 +77,7 @@ enum indic_syllable_type_t { #define indic_syllable_machine_ex_ZWNJ 5u -#line 81 "hb-ot-shaper-indic-machine.hh" +#line 76 "hb-ot-shaper-indic-machine.hh" static const unsigned char _indic_syllable_machine_trans_keys[] = { 8u, 57u, 4u, 57u, 5u, 57u, 5u, 57u, 13u, 13u, 4u, 57u, 4u, 57u, 4u, 57u, 8u, 57u, 5u, 57u, 5u, 57u, 13u, 13u, 4u, 57u, 4u, 57u, 4u, 57u, 4u, 57u, @@ -1126,7 +1126,7 @@ find_syllables_indic (hb_buffer_t *buffer) int cs; hb_glyph_info_t *info = buffer->info; -#line 1130 "hb-ot-shaper-indic-machine.hh" +#line 1119 "hb-ot-shaper-indic-machine.hh" { cs = indic_syllable_machine_start; ts = 0; @@ -1142,7 +1142,7 @@ find_syllables_indic (hb_buffer_t *buffer) unsigned int syllable_serial = 1; -#line 1146 "hb-ot-shaper-indic-machine.hh" +#line 1131 "hb-ot-shaper-indic-machine.hh" { int _slen; int _trans; @@ -1156,7 +1156,7 @@ _resume: #line 1 "NONE" {ts = p;} break; -#line 1160 "hb-ot-shaper-indic-machine.hh" +#line 1143 "hb-ot-shaper-indic-machine.hh" } _keys = _indic_syllable_machine_trans_keys + (cs<<1); @@ -1268,7 +1268,7 @@ _eof_trans: #line 117 "hb-ot-shaper-indic-machine.rl" {act = 7;} break; -#line 1272 "hb-ot-shaper-indic-machine.hh" +#line 1232 "hb-ot-shaper-indic-machine.hh" } _again: @@ -1277,7 +1277,7 @@ _again: #line 1 "NONE" {ts = 0;} break; -#line 1281 "hb-ot-shaper-indic-machine.hh" +#line 1239 "hb-ot-shaper-indic-machine.hh" } if ( ++p != pe ) diff --git a/src/hb-ot-shaper-khmer-machine.hh b/src/hb-ot-shaper-khmer-machine.hh index f1e7a91f0..848ed231f 100644 --- a/src/hb-ot-shaper-khmer-machine.hh +++ b/src/hb-ot-shaper-khmer-machine.hh @@ -48,7 +48,7 @@ enum khmer_syllable_type_t { }; -#line 52 "hb-ot-shaper-khmer-machine.hh" +#line 49 "hb-ot-shaper-khmer-machine.hh" #define khmer_syllable_machine_ex_C 1u #define khmer_syllable_machine_ex_DOTTEDCIRCLE 11u #define khmer_syllable_machine_ex_H 4u @@ -66,7 +66,7 @@ enum khmer_syllable_type_t { #define khmer_syllable_machine_ex_ZWNJ 5u -#line 70 "hb-ot-shaper-khmer-machine.hh" +#line 65 "hb-ot-shaper-khmer-machine.hh" static const unsigned char _khmer_syllable_machine_trans_keys[] = { 5u, 26u, 5u, 26u, 1u, 15u, 5u, 26u, 5u, 26u, 5u, 26u, 5u, 26u, 5u, 26u, 5u, 26u, 5u, 26u, 5u, 26u, 5u, 26u, 5u, 26u, 1u, 15u, 5u, 26u, 5u, 26u, @@ -294,7 +294,7 @@ find_syllables_khmer (hb_buffer_t *buffer) int cs; hb_glyph_info_t *info = buffer->info; -#line 298 "hb-ot-shaper-khmer-machine.hh" +#line 287 "hb-ot-shaper-khmer-machine.hh" { cs = khmer_syllable_machine_start; ts = 0; @@ -310,7 +310,7 @@ find_syllables_khmer (hb_buffer_t *buffer) unsigned int syllable_serial = 1; -#line 314 "hb-ot-shaper-khmer-machine.hh" +#line 299 "hb-ot-shaper-khmer-machine.hh" { int _slen; int _trans; @@ -324,7 +324,7 @@ _resume: #line 1 "NONE" {ts = p;} break; -#line 328 "hb-ot-shaper-khmer-machine.hh" +#line 311 "hb-ot-shaper-khmer-machine.hh" } _keys = _khmer_syllable_machine_trans_keys + (cs<<1); @@ -394,7 +394,7 @@ _eof_trans: #line 98 "hb-ot-shaper-khmer-machine.rl" {act = 3;} break; -#line 398 "hb-ot-shaper-khmer-machine.hh" +#line 368 "hb-ot-shaper-khmer-machine.hh" } _again: @@ -403,7 +403,7 @@ _again: #line 1 "NONE" {ts = 0;} break; -#line 407 "hb-ot-shaper-khmer-machine.hh" +#line 375 "hb-ot-shaper-khmer-machine.hh" } if ( ++p != pe ) diff --git a/src/hb-ot-shaper-myanmar-machine.hh b/src/hb-ot-shaper-myanmar-machine.hh index 4b8da586d..292bc9f3d 100644 --- a/src/hb-ot-shaper-myanmar-machine.hh +++ b/src/hb-ot-shaper-myanmar-machine.hh @@ -50,7 +50,7 @@ enum myanmar_syllable_type_t { }; -#line 54 "hb-ot-shaper-myanmar-machine.hh" +#line 51 "hb-ot-shaper-myanmar-machine.hh" #define myanmar_syllable_machine_ex_A 9u #define myanmar_syllable_machine_ex_As 32u #define myanmar_syllable_machine_ex_C 1u @@ -78,7 +78,7 @@ enum myanmar_syllable_type_t { #define myanmar_syllable_machine_ex_ZWNJ 5u -#line 82 "hb-ot-shaper-myanmar-machine.hh" +#line 77 "hb-ot-shaper-myanmar-machine.hh" static const unsigned char _myanmar_syllable_machine_trans_keys[] = { 1u, 57u, 3u, 57u, 5u, 57u, 5u, 57u, 3u, 57u, 5u, 57u, 3u, 57u, 3u, 57u, 3u, 57u, 3u, 57u, 3u, 57u, 5u, 57u, 1u, 15u, 3u, 57u, 3u, 57u, 3u, 57u, @@ -549,7 +549,7 @@ find_syllables_myanmar (hb_buffer_t *buffer) int cs; hb_glyph_info_t *info = buffer->info; -#line 553 "hb-ot-shaper-myanmar-machine.hh" +#line 542 "hb-ot-shaper-myanmar-machine.hh" { cs = myanmar_syllable_machine_start; ts = 0; @@ -565,7 +565,7 @@ find_syllables_myanmar (hb_buffer_t *buffer) unsigned int syllable_serial = 1; -#line 569 "hb-ot-shaper-myanmar-machine.hh" +#line 554 "hb-ot-shaper-myanmar-machine.hh" { int _slen; int _trans; @@ -579,7 +579,7 @@ _resume: #line 1 "NONE" {ts = p;} break; -#line 583 "hb-ot-shaper-myanmar-machine.hh" +#line 566 "hb-ot-shaper-myanmar-machine.hh" } _keys = _myanmar_syllable_machine_trans_keys + (cs<<1); @@ -649,7 +649,7 @@ _eof_trans: #line 113 "hb-ot-shaper-myanmar-machine.rl" {act = 3;} break; -#line 653 "hb-ot-shaper-myanmar-machine.hh" +#line 623 "hb-ot-shaper-myanmar-machine.hh" } _again: @@ -658,7 +658,7 @@ _again: #line 1 "NONE" {ts = 0;} break; -#line 662 "hb-ot-shaper-myanmar-machine.hh" +#line 630 "hb-ot-shaper-myanmar-machine.hh" } if ( ++p != pe ) diff --git a/src/hb-ot-shaper-use-machine.hh b/src/hb-ot-shaper-use-machine.hh index 65b6adc36..5072e4d38 100644 --- a/src/hb-ot-shaper-use-machine.hh +++ b/src/hb-ot-shaper-use-machine.hh @@ -53,7 +53,7 @@ enum use_syllable_type_t { }; -#line 57 "hb-ot-shaper-use-machine.hh" +#line 54 "hb-ot-shaper-use-machine.hh" #define use_syllable_machine_ex_B 1u #define use_syllable_machine_ex_CGJ 6u #define use_syllable_machine_ex_CMAbv 31u @@ -100,7 +100,7 @@ enum use_syllable_type_t { #define use_syllable_machine_ex_ZWNJ 14u -#line 104 "hb-ot-shaper-use-machine.hh" +#line 99 "hb-ot-shaper-use-machine.hh" static const unsigned char _use_syllable_machine_trans_keys[] = { 49u, 51u, 0u, 56u, 11u, 56u, 11u, 56u, 1u, 53u, 14u, 48u, 14u, 47u, 14u, 47u, 14u, 47u, 14u, 46u, 14u, 46u, 14u, 14u, 14u, 48u, 14u, 48u, 14u, 48u, 1u, 14u, @@ -929,7 +929,7 @@ find_syllables_use (hb_buffer_t *buffer) unsigned int act HB_UNUSED; int cs; -#line 933 "hb-ot-shaper-use-machine.hh" +#line 922 "hb-ot-shaper-use-machine.hh" { cs = use_syllable_machine_start; ts = 0; @@ -942,7 +942,7 @@ find_syllables_use (hb_buffer_t *buffer) unsigned int syllable_serial = 1; -#line 946 "hb-ot-shaper-use-machine.hh" +#line 931 "hb-ot-shaper-use-machine.hh" { int _slen; int _trans; @@ -956,7 +956,7 @@ _resume: #line 1 "NONE" {ts = p;} break; -#line 960 "hb-ot-shaper-use-machine.hh" +#line 943 "hb-ot-shaper-use-machine.hh" } _keys = _use_syllable_machine_trans_keys + (cs<<1); @@ -1078,7 +1078,7 @@ _eof_trans: #line 181 "hb-ot-shaper-use-machine.rl" {act = 9;} break; -#line 1082 "hb-ot-shaper-use-machine.hh" +#line 1039 "hb-ot-shaper-use-machine.hh" } _again: @@ -1087,7 +1087,7 @@ _again: #line 1 "NONE" {ts = 0;} break; -#line 1091 "hb-ot-shaper-use-machine.hh" +#line 1046 "hb-ot-shaper-use-machine.hh" } if ( ++p != pe ) diff --git a/src/test-buffer-serialize.cc b/src/test-buffer-serialize.cc index aced1c8d1..421e5da68 100644 --- a/src/test-buffer-serialize.cc +++ b/src/test-buffer-serialize.cc @@ -43,6 +43,23 @@ main (int argc, char **argv) #ifndef HB_NO_BUFFER_SERIALIZE + hb_buffer_serialize_format_t format = HB_BUFFER_SERIALIZE_FORMAT_TEXT; + if (argc > 1) + { + if (!strcmp (argv[1], "--json")) + { + format = HB_BUFFER_SERIALIZE_FORMAT_JSON; + argc--; + argv++; + } + else if (!strcmp (argv[1], "--text")) + { + format = HB_BUFFER_SERIALIZE_FORMAT_TEXT; + argc--; + argv++; + } + } + if (argc < 2) argv[1] = (char *) "/dev/null"; @@ -68,10 +85,13 @@ main (int argc, char **argv) while (true) { const char *p = line; + const char *end = p + strlen (p); + if (p < end && *(end - 1) == '\n') + end--; if (!hb_buffer_deserialize_glyphs (buf, - p, -1, &p, + p, end - p, &p, font, - HB_BUFFER_SERIALIZE_FORMAT_TEXT)) + format)) { ret = false; break; @@ -97,7 +117,8 @@ main (int argc, char **argv) unsigned len; offset += hb_buffer_serialize_glyphs (buf, offset, count, out, sizeof (out), &len, - font, HB_BUFFER_SERIALIZE_FORMAT_TEXT, + font, + format, HB_BUFFER_SERIALIZE_FLAG_GLYPH_FLAGS); fwrite (out, 1, len, stdout); } diff --git a/test/api/test-buffer.c b/test/api/test-buffer.c index 522fc7323..59db49e28 100644 --- a/test/api/test-buffer.c +++ b/test/api/test-buffer.c @@ -869,7 +869,7 @@ static const serialization_test_t serialization_tests[] = { { "[{\"u\":1600,\"cl\":0},{\"u\":1589,\"cl\":1}]", HB_BUFFER_SERIALIZE_FORMAT_JSON, -1, 2, TRUE }, /* Unfinished */ - //{ "[{\"u\":1600,\"cl\":0},{\"u\":1589,\"cl\":1}", HB_BUFFER_SERIALIZE_FORMAT_JSON, -1, 2, TRUE }, + { "[{\"u\":1600,\"cl\":0},{\"u\":1589,\"cl\":1}", HB_BUFFER_SERIALIZE_FORMAT_JSON, 36, 1, TRUE }, /* Mixed glyphs/Unicodes -> parse fail */ { "[{\"u\":1600,\"cl\":0},{\"g\":1589,\"cl\":1}]", HB_BUFFER_SERIALIZE_FORMAT_JSON, -1, 0, FALSE }, @@ -894,8 +894,7 @@ test_buffer_serialize_deserialize (void) const serialization_test_t *test = &serialization_tests[i]; g_test_message ("serialize test #%d", i); - - (void) hb_buffer_deserialize_unicode (b, test->contents, -1, &end_ptr, test->format); + bool ret = hb_buffer_deserialize_unicode (b, test->contents, -1, &end_ptr, test->format); // Expected parse failure, got one, don't round-trip if (test->success) @@ -908,13 +907,17 @@ test_buffer_serialize_deserialize (void) consumed = end_ptr - test->contents; g_assert_cmpint (consumed, ==, test->parsed_length); } - - consumed = 0; - hb_buffer_serialize_unicode (b, 0, num_glyphs, round_trip, - sizeof(round_trip), &consumed, test->format, - HB_BUFFER_SERIALIZE_FLAG_DEFAULT); - g_assert_cmpstr (round_trip, ==, test->contents); + else + { + consumed = 0; + hb_buffer_serialize (b, 0, num_glyphs, round_trip, + sizeof(round_trip), &consumed, NULL, test->format, + HB_BUFFER_SERIALIZE_FLAG_DEFAULT); + g_assert_cmpstr (round_trip, ==, test->contents); + } } + else + g_assert (!ret); hb_buffer_destroy (b); From 4323c6643b9854aa813c78ab3a636638fc7227c3 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 10 Mar 2025 20:06:08 -0600 Subject: [PATCH 16/40] [fontations] Make fontations use hb_malloc et al --- src/fontations/lib.rs | 31 +++++++++++++++++++++++++ src/hb-static.cc | 5 ++++ src/hb.hh | 54 +++++++++++++++++++++---------------------- 3 files changed, 63 insertions(+), 27 deletions(-) diff --git a/src/fontations/lib.rs b/src/fontations/lib.rs index 4b50ab533..38c0eb2d8 100644 --- a/src/fontations/lib.rs +++ b/src/fontations/lib.rs @@ -2,6 +2,7 @@ #![allow(non_upper_case_globals)] include!(concat!(env!("OUT_DIR"), "/hb.rs")); +use std::alloc::{GlobalAlloc, Layout}; use std::mem::transmute; use std::os::raw::c_void; use std::ptr::null_mut; @@ -23,6 +24,36 @@ use skrifa::outline::DrawSettings; use skrifa::OutlineGlyphCollection; use skrifa::{GlyphId, MetadataProvider}; +extern "C" { + pub fn hb_malloc(_: usize) -> *const ::std::os::raw::c_void; + pub fn hb_calloc(_: usize, _: usize) -> *const ::std::os::raw::c_void; + pub fn hb_realloc(_: *const ::std::os::raw::c_void, _: usize) -> *const ::std::os::raw::c_void; + pub fn hb_free(_: *const ::std::os::raw::c_void); +} + +struct MyAllocator; + +unsafe impl GlobalAlloc for MyAllocator { + unsafe fn alloc(&self, layout: Layout) -> *mut u8 { + hb_malloc(layout.size()) as *mut u8 + } + + unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { + hb_calloc(layout.size(), 1) as *mut u8 + } + + unsafe fn realloc(&self, ptr: *mut u8, _layout: Layout, new_size: usize) -> *mut u8 { + hb_realloc(ptr as *const c_void, new_size) as *mut u8 + } + + unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) { + hb_free(ptr as *mut c_void); + } +} + +#[global_allocator] +static GLOBAL: MyAllocator = MyAllocator; + // A struct for storing your “fontations” data #[repr(C)] struct FontationsData<'a> { diff --git a/src/hb-static.cc b/src/hb-static.cc index c9bd0a61b..634299778 100644 --- a/src/hb-static.cc +++ b/src/hb-static.cc @@ -40,6 +40,11 @@ #include "hb-ot-hmtx-table.hh" #include "hb-ot-maxp-table.hh" +void* hb_malloc(size_t size) { return hb_malloc_impl (size); } +void* hb_calloc(size_t nmemb, size_t size) { return hb_calloc_impl (nmemb, size); } +void* hb_realloc(void *ptr, size_t size) { return hb_realloc_impl (ptr, size); } +void hb_free(void *ptr) { hb_free_impl (ptr); } + #ifndef HB_NO_VISIBILITY #include "hb-ot-name-language-static.hh" diff --git a/src/hb.hh b/src/hb.hh index 0691c8425..e245ad288 100644 --- a/src/hb.hh +++ b/src/hb.hh @@ -230,33 +230,6 @@ #define HB_PASTE(a,b) HB_PASTE1(a,b) -/* Compile-time custom allocator support. */ - -#if !defined(HB_CUSTOM_MALLOC) \ - && defined(hb_malloc_impl) \ - && defined(hb_calloc_impl) \ - && defined(hb_realloc_impl) \ - && defined(hb_free_impl) -#define HB_CUSTOM_MALLOC -#endif - -#ifdef HB_CUSTOM_MALLOC -extern "C" void* hb_malloc_impl(size_t size); -extern "C" void* hb_calloc_impl(size_t nmemb, size_t size); -extern "C" void* hb_realloc_impl(void *ptr, size_t size); -extern "C" void hb_free_impl(void *ptr); -#define hb_malloc hb_malloc_impl -#define hb_calloc hb_calloc_impl -#define hb_realloc hb_realloc_impl -#define hb_free hb_free_impl -#else -#define hb_malloc malloc -#define hb_calloc calloc -#define hb_realloc realloc -#define hb_free free -#endif - - /* * Compiler attributes */ @@ -539,6 +512,33 @@ static_assert ((sizeof (hb_var_int_t) == 4), ""); #define HB_PI 3.14159265358979f #define HB_2_PI (2.f * HB_PI) +/* Compile-time custom allocator support. */ + +#if !defined(HB_CUSTOM_MALLOC) \ + && defined(hb_malloc_impl) \ + && defined(hb_calloc_impl) \ + && defined(hb_realloc_impl) \ + && defined(hb_free_impl) +#define HB_CUSTOM_MALLOC +#endif + +#ifdef HB_CUSTOM_MALLOC +extern "C" void* hb_malloc_impl(size_t size); +extern "C" void* hb_calloc_impl(size_t nmemb, size_t size); +extern "C" void* hb_realloc_impl(void *ptr, size_t size); +extern "C" void hb_free_impl(void *ptr); +#else +#define hb_malloc_impl malloc +#define hb_calloc_impl calloc +#define hb_realloc_impl realloc +#define hb_free_impl free +#endif +extern "C" void* hb_malloc(size_t size); +extern "C" void* hb_calloc(size_t nmemb, size_t size); +extern "C" void* hb_realloc(void *ptr, size_t size); +extern "C" void hb_free(void *ptr); + + /* Headers we include for everyone. Keep topologically sorted by dependency. * They express dependency amongst themselves, but no other file should include From 3c02fcd0e8ebd9330634058839941a672f777ac3 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 10 Mar 2025 23:16:30 -0600 Subject: [PATCH 17/40] [test-multithread] Simplify --- test/api/meson.build | 2 +- test/api/test-multithread.c | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/test/api/meson.build b/test/api/meson.build index 59e7af387..0f7ac6900 100644 --- a/test/api/meson.build +++ b/test/api/meson.build @@ -87,7 +87,7 @@ if conf.get('HAVE_DIRECTWRITE', 0) == 1 ] endif -if conf.get('HAVE_FREETYPE', 0) == 1 and conf.get('HAVE_PTHREAD', 0) == 1 +if conf.get('HAVE_PTHREAD', 0) == 1 tests += 'test-multithread.c' endif diff --git a/test/api/test-multithread.c b/test/api/test-multithread.c index b83ca6693..90bde064e 100644 --- a/test/api/test-multithread.c +++ b/test/api/test-multithread.c @@ -26,8 +26,6 @@ #include #include -#include -#include #include "hb-test.h" From dbad6cdfec7df9c5934ad153bfa53fe3ba39a9f0 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 10 Mar 2025 23:20:54 -0600 Subject: [PATCH 18/40] [test-c(plusplus)] Add more headers --- test/api/meson.build | 2 +- test/api/test-c.c | 21 +++++++++++++++++++++ test/api/test-cplusplus.cc | 20 ++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/test/api/meson.build b/test/api/meson.build index 0f7ac6900..1b68de01f 100644 --- a/test/api/meson.build +++ b/test/api/meson.build @@ -102,7 +102,7 @@ foreach source : tests cpp_args = [] test_name = source.split('.')[0] - deps = [glib_dep, freetype_dep, thread_dep, libharfbuzz_dep, libharfbuzz_icu_dep] + deps = [glib_dep, freetype_dep, cairo_dep, graphite2_dep, thread_dep, libharfbuzz_dep, libharfbuzz_icu_dep] suite = ['api'] if test_name.contains('-subset') or test_name.contains('-instance') deps += libharfbuzz_subset_dep diff --git a/test/api/test-c.c b/test/api/test-c.c index 59eef4242..69c6e826f 100644 --- a/test/api/test-c.c +++ b/test/api/test-c.c @@ -32,6 +32,7 @@ #endif #include +#include #include #include @@ -47,10 +48,30 @@ #include #endif +#ifdef HAVE_FONTATIONS +#include +#endif + +#ifdef HAVE_GRAPHITE2 +#include +#endif + +#ifdef HAVE_CAIRO +#include +#endif + +#ifdef HAVE_GDI +#include +#endif + #ifdef HAVE_UNISCRIBE #include #endif +#ifdef HAVE_DIRECTWRITE +#include +#endif + #ifdef HAVE_CORETEXT #include #endif diff --git a/test/api/test-cplusplus.cc b/test/api/test-cplusplus.cc index 01b000271..c5226e246 100644 --- a/test/api/test-cplusplus.cc +++ b/test/api/test-cplusplus.cc @@ -49,10 +49,30 @@ #include #endif +#ifdef HAVE_FONTATIONS +#include +#endif + +#ifdef HAVE_GRAPHITE2 +#include +#endif + +#ifdef HAVE_CAIRO +#include +#endif + +#ifdef HAVE_GDI +#include +#endif + #ifdef HAVE_UNISCRIBE #include #endif +#ifdef HAVE_DIRECTWRITE +#include +#endif + #ifdef HAVE_CORETEXT #include #endif From 57deae5fd4dd97b94ed31bdf278607b92557308d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 10 Mar 2025 23:40:22 -0600 Subject: [PATCH 19/40] [meson] Check correct dependency Ouch! --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 4ca64243a..1f0f4e720 100644 --- a/meson.build +++ b/meson.build @@ -314,7 +314,7 @@ endif gdi_uniscribe_deps = [] # GDI (Uniscribe) (Windows) if host_machine.system() == 'windows' and not get_option('gdi').disabled() - if (get_option('directwrite').enabled() and + if (get_option('gdi').enabled() and not (cpp.has_header('usp10.h') and cpp.has_header('windows.h'))) error('GDI/Uniscribe was enabled explicitly, but required headers are missing.') endif From 41dcc493e5ce3838a02671667f44984ea8ed8206 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 10 Mar 2025 23:40:39 -0600 Subject: [PATCH 20/40] [test-cplusplus] Simplify --- meson.build | 3 ++- src/hb-directwrite.h | 2 ++ src/meson.build | 1 + test/api/meson.build | 12 ++++++++- test/api/test-c.c | 38 ++++++++++++++++------------ test/api/test-cplusplus.cc | 52 +++----------------------------------- 6 files changed, 41 insertions(+), 67 deletions(-) diff --git a/meson.build b/meson.build index 1f0f4e720..2aa816ea7 100644 --- a/meson.build +++ b/meson.build @@ -333,11 +333,12 @@ if host_machine.system() == 'windows' and not get_option('gdi').disabled() endif # DirectWrite (Windows) +directwrite_dep = [] if host_machine.system() == 'windows' and not get_option('directwrite').disabled() if get_option('directwrite').enabled() and not cpp.has_header('dwrite_1.h') error('DirectWrite was enabled explicitly, but required header is missing.') endif - + directwrite_dep = cpp.find_library('dwrite', required: false) conf.set('HAVE_DIRECTWRITE', 1) endif diff --git a/src/hb-directwrite.h b/src/hb-directwrite.h index 121569c15..1735e80fd 100644 --- a/src/hb-directwrite.h +++ b/src/hb-directwrite.h @@ -27,6 +27,8 @@ #include "hb.h" +#include + HB_BEGIN_DECLS HB_EXTERN hb_face_t * diff --git a/src/meson.build b/src/meson.build index a2d23b1e2..34b184160 100644 --- a/src/meson.build +++ b/src/meson.build @@ -506,6 +506,7 @@ endif if conf.get('HAVE_DIRECTWRITE', 0) == 1 hb_sources += hb_directwrite_sources hb_headers += hb_directwrite_headers + harfbuzz_deps += directwrite_dep # hb-directwrite needs a C++ linker libharfbuzz_link_language = 'cpp' endif diff --git a/test/api/meson.build b/test/api/meson.build index 1b68de01f..186366f23 100644 --- a/test/api/meson.build +++ b/test/api/meson.build @@ -102,7 +102,17 @@ foreach source : tests cpp_args = [] test_name = source.split('.')[0] - deps = [glib_dep, freetype_dep, cairo_dep, graphite2_dep, thread_dep, libharfbuzz_dep, libharfbuzz_icu_dep] + deps = [directwrite_dep, + coretext_deps, + freetype_dep, + gdi_uniscribe_deps, + glib_dep, + graphite2_dep, + thread_dep, + libharfbuzz_dep, + libharfbuzz_icu_dep, + libharfbuzz_cairo_dep, + libharfbuzz_gobject_dep] suite = ['api'] if test_name.contains('-subset') or test_name.contains('-instance') deps += libharfbuzz_subset_dep diff --git a/test/api/test-c.c b/test/api/test-c.c index 69c6e826f..f0087d510 100644 --- a/test/api/test-c.c +++ b/test/api/test-c.c @@ -36,12 +36,16 @@ #include #include -#ifdef HAVE_GLIB -#include +#ifdef HAVE_CAIRO +#include #endif -#ifdef HAVE_ICU -#include +#ifdef HAVE_CORETEXT +#include +#endif + +#ifdef HAVE_DIRECTWRITE +#include #endif #ifdef HAVE_FREETYPE @@ -52,32 +56,34 @@ #include #endif +#ifdef HAVE_GDI +#include +#endif + +#ifdef HAVE_GLIB +#include +#endif + #ifdef HAVE_GRAPHITE2 #include #endif -#ifdef HAVE_CAIRO -#include +#ifdef HAVE_GOBJECT +#include #endif -#ifdef HAVE_GDI -#include +#ifdef HAVE_ICU +#include #endif #ifdef HAVE_UNISCRIBE #include #endif -#ifdef HAVE_DIRECTWRITE -#include -#endif - -#ifdef HAVE_CORETEXT -#include -#endif - +#ifndef NO_MAIN int main (void) { return !*hb_shape_list_shapers (); } +#endif diff --git a/test/api/test-cplusplus.cc b/test/api/test-cplusplus.cc index c5226e246..41cb43496 100644 --- a/test/api/test-cplusplus.cc +++ b/test/api/test-cplusplus.cc @@ -28,55 +28,9 @@ /* This file tests that all headers can be included from C++ files, * as well as test the C++ API. */ -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include - -#ifdef HAVE_GLIB -#include -#endif - -#ifdef HAVE_ICU -#include -#endif - -#ifdef HAVE_FREETYPE -#include -#endif - -#ifdef HAVE_FONTATIONS -#include -#endif - -#ifdef HAVE_GRAPHITE2 -#include -#endif - -#ifdef HAVE_CAIRO -#include -#endif - -#ifdef HAVE_GDI -#include -#endif - -#ifdef HAVE_UNISCRIBE -#include -#endif - -#ifdef HAVE_DIRECTWRITE -#include -#endif - -#ifdef HAVE_CORETEXT -#include -#endif - +#define NO_MAIN +#include "test-c.c" +#undef NO_MAIN /* Test C++ API. */ From d2ccf595bd8017dbdac2abf1faaa69c30da12b1d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 11 Mar 2025 00:15:19 -0600 Subject: [PATCH 21/40] Directwrite is a C++ header? --- test/api/test-c.c | 4 ---- test/api/test-cplusplus.cc | 5 +++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/test/api/test-c.c b/test/api/test-c.c index f0087d510..87e14b876 100644 --- a/test/api/test-c.c +++ b/test/api/test-c.c @@ -44,10 +44,6 @@ #include #endif -#ifdef HAVE_DIRECTWRITE -#include -#endif - #ifdef HAVE_FREETYPE #include #endif diff --git a/test/api/test-cplusplus.cc b/test/api/test-cplusplus.cc index 41cb43496..74e4fb265 100644 --- a/test/api/test-cplusplus.cc +++ b/test/api/test-cplusplus.cc @@ -32,6 +32,11 @@ #include "test-c.c" #undef NO_MAIN +#ifdef HAVE_DIRECTWRITE +#include +#endif + + /* Test C++ API. */ #include "hb-cplusplus.hh" From d247c116fb71969ccdae722c96cce95bf24428b6 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 11 Mar 2025 00:11:41 -0600 Subject: [PATCH 22/40] [test-draw] Test all font funcs --- test/api/hb-test.h | 11 +------- test/api/test-draw.c | 61 ++++++++------------------------------------ 2 files changed, 12 insertions(+), 60 deletions(-) diff --git a/test/api/hb-test.h b/test/api/hb-test.h index 25d07ce0a..cdf355580 100644 --- a/test/api/hb-test.h +++ b/test/api/hb-test.h @@ -223,16 +223,6 @@ hb_test_add_func (const char *test_path, } #define hb_test_add(Func) hb_test_add_func (#Func, Func) -static inline void -hb_test_add_func_flavor (const char *test_path, - const char *flavor, - hb_test_func_t test_func) -{ - char *path = g_strdup_printf ("%s/%s", test_path, flavor); - hb_test_add_func (path, test_func); - g_free (path); -} -#define hb_test_add_flavor(Flavor, Func) hb_test_add_func (#Func, Flavor, Func) static inline void hb_test_add_data_func (const char *test_path, @@ -257,6 +247,7 @@ hb_test_add_data_func_flavor (const char *test_path, } #define hb_test_add_data_flavor(UserData, Flavor, Func) hb_test_add_data_func_flavor (#Func, Flavor, UserData, Func) +#define hb_test_add_flavor(Flavor, Func) hb_test_add_data_flavor (Flavor, Flavor, Func) static inline void hb_test_add_vtable (const char *test_path, diff --git a/test/api/test-draw.c b/test/api/test-draw.c index a068c78f6..f8ec18ca3 100644 --- a/test/api/test-draw.c +++ b/test/api/test-draw.c @@ -26,12 +26,6 @@ #include #include -#ifdef HAVE_FREETYPE -#include -#endif -#ifdef HAVE_FONTATIONS -#include -#endif typedef struct draw_data_t { @@ -1078,8 +1072,9 @@ test_hb_draw_immutable (void) } static void -test_hb_draw_funcs (const char* font_funcs_name) +test_hb_draw_funcs (const void* user_data) { + const char *font_funcs_name = user_data; char str[1024]; draw_data_t draw_data = { .str = str, @@ -1097,12 +1092,6 @@ test_hb_draw_funcs (const char* font_funcs_name) char expected[] = "M50,0L50,750L450,750L450,0L50,0Z"; g_assert_cmpmem (str, draw_data.consumed, expected, sizeof (expected) - 1); } - { - draw_data.consumed = 0; - hb_font_draw_glyph (font, 5, funcs, &draw_data); - char expected[] = "M15,0Q15,0 15,0Z"; - g_assert_cmpmem (str, draw_data.consumed, expected, sizeof (expected) - 1); - } hb_font_destroy (font); } { @@ -1127,8 +1116,9 @@ test_hb_draw_funcs (const char* font_funcs_name) } static void -test_hb_draw_compare_ot_funcs (const char* font_funcs_name) +test_hb_draw_compare_ot_funcs (const void *user_data) { + const char* font_funcs_name = user_data; char str[1024]; draw_data_t draw_data = { .str = str, @@ -1162,34 +1152,6 @@ test_hb_draw_compare_ot_funcs (const char* font_funcs_name) hb_face_destroy (face); } -#ifdef HAVE_FREETYPE -static void -test_hb_draw_ft (void) -{ - test_hb_draw_funcs ("ft"); -} - -static void -test_hb_draw_compare_ot_ft (void) -{ - test_hb_draw_compare_ot_funcs ("ft"); -} -#endif - -#ifdef HAVE_FONTATIONS -static void -test_hb_draw_fontations (void) -{ - test_hb_draw_funcs ("fontations"); -} - -static void -test_hb_draw_compare_ot_fontations (void) -{ - test_hb_draw_compare_ot_funcs ("fontations"); -} -#endif - int main (int argc, char **argv) { @@ -1224,14 +1186,13 @@ main (int argc, char **argv) hb_test_add (test_hb_draw_synthetic_slant); hb_test_add (test_hb_draw_subfont_scale); hb_test_add (test_hb_draw_immutable); -#ifdef HAVE_FREETYPE - hb_test_add (test_hb_draw_ft); - hb_test_add (test_hb_draw_compare_ot_ft); -#endif -#ifdef HAVE_FONTATIONS - hb_test_add (test_hb_draw_fontations); - hb_test_add (test_hb_draw_compare_ot_fontations); -#endif + + const char **font_funcs = hb_font_list_funcs (); + for (const char **font_funcs_name = font_funcs; *font_funcs_name; font_funcs_name++) + { + hb_test_add_flavor (*font_funcs_name, test_hb_draw_funcs); + hb_test_add_flavor (*font_funcs_name, test_hb_draw_compare_ot_funcs); + } unsigned result = hb_test_run (); From 8ca892b0e223767ae67cdc3d3edd1fac49eb36c4 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 11 Mar 2025 00:19:34 -0600 Subject: [PATCH 23/40] [directwrite] Simplify headers --- meson.build | 2 +- src/hb-directwrite.cc | 3 --- src/hb-directwrite.h | 2 +- test/api/test-directwrite.cc | 2 -- 4 files changed, 2 insertions(+), 7 deletions(-) diff --git a/meson.build b/meson.build index 2aa816ea7..a93d723c2 100644 --- a/meson.build +++ b/meson.build @@ -335,7 +335,7 @@ endif # DirectWrite (Windows) directwrite_dep = [] if host_machine.system() == 'windows' and not get_option('directwrite').disabled() - if get_option('directwrite').enabled() and not cpp.has_header('dwrite_1.h') + if get_option('directwrite').enabled() and not cpp.has_header('dwrite_3.h') error('DirectWrite was enabled explicitly, but required header is missing.') endif directwrite_dep = cpp.find_library('dwrite', required: false) diff --git a/src/hb-directwrite.cc b/src/hb-directwrite.cc index f138bd4f3..ddd765a84 100644 --- a/src/hb-directwrite.cc +++ b/src/hb-directwrite.cc @@ -28,9 +28,6 @@ #include "hb-shaper-impl.hh" -#include -#include - #include "hb-directwrite.h" #include "hb-ms-feature-ranges.hh" diff --git a/src/hb-directwrite.h b/src/hb-directwrite.h index 1735e80fd..b5b314e16 100644 --- a/src/hb-directwrite.h +++ b/src/hb-directwrite.h @@ -27,7 +27,7 @@ #include "hb.h" -#include +#include HB_BEGIN_DECLS diff --git a/test/api/test-directwrite.cc b/test/api/test-directwrite.cc index 345b9d2a9..c48572192 100644 --- a/test/api/test-directwrite.cc +++ b/test/api/test-directwrite.cc @@ -25,8 +25,6 @@ */ -#include - #include "hb-test.h" #include "hb-directwrite.h" From 6b2f8592324ffeb5a5c86447de72f9b02d0e7cb1 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 11 Mar 2025 00:27:32 -0600 Subject: [PATCH 24/40] [test-c] Disable gobject include It can't find its dependent headers since not installed. --- test/api/meson.build | 3 ++- test/api/test-c.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/test/api/meson.build b/test/api/meson.build index 186366f23..273248a91 100644 --- a/test/api/meson.build +++ b/test/api/meson.build @@ -112,7 +112,8 @@ foreach source : tests libharfbuzz_dep, libharfbuzz_icu_dep, libharfbuzz_cairo_dep, - libharfbuzz_gobject_dep] + #libharfbuzz_gobject_dep + ] suite = ['api'] if test_name.contains('-subset') or test_name.contains('-instance') deps += libharfbuzz_subset_dep diff --git a/test/api/test-c.c b/test/api/test-c.c index 87e14b876..d0bdc9d6d 100644 --- a/test/api/test-c.c +++ b/test/api/test-c.c @@ -65,7 +65,7 @@ #endif #ifdef HAVE_GOBJECT -#include +//#include // Doesn't work uninstalled #endif #ifdef HAVE_ICU From 756668d35c3e64447e3dc297472745ff144f9311 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 11 Mar 2025 11:27:02 -0600 Subject: [PATCH 25/40] [directwrite] Drop dependency again as per review https://github.com/harfbuzz/harfbuzz/pull/5132#issuecomment-2714186460 --- meson.build | 2 -- src/meson.build | 1 - test/api/meson.build | 3 +-- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/meson.build b/meson.build index a93d723c2..31fa1aaf1 100644 --- a/meson.build +++ b/meson.build @@ -333,12 +333,10 @@ if host_machine.system() == 'windows' and not get_option('gdi').disabled() endif # DirectWrite (Windows) -directwrite_dep = [] if host_machine.system() == 'windows' and not get_option('directwrite').disabled() if get_option('directwrite').enabled() and not cpp.has_header('dwrite_3.h') error('DirectWrite was enabled explicitly, but required header is missing.') endif - directwrite_dep = cpp.find_library('dwrite', required: false) conf.set('HAVE_DIRECTWRITE', 1) endif diff --git a/src/meson.build b/src/meson.build index 34b184160..a2d23b1e2 100644 --- a/src/meson.build +++ b/src/meson.build @@ -506,7 +506,6 @@ endif if conf.get('HAVE_DIRECTWRITE', 0) == 1 hb_sources += hb_directwrite_sources hb_headers += hb_directwrite_headers - harfbuzz_deps += directwrite_dep # hb-directwrite needs a C++ linker libharfbuzz_link_language = 'cpp' endif diff --git a/test/api/meson.build b/test/api/meson.build index 273248a91..24d0d854f 100644 --- a/test/api/meson.build +++ b/test/api/meson.build @@ -102,8 +102,7 @@ foreach source : tests cpp_args = [] test_name = source.split('.')[0] - deps = [directwrite_dep, - coretext_deps, + deps = [coretext_deps, freetype_dep, gdi_uniscribe_deps, glib_dep, From e4fe8bf95e4e7080abfdb005e48563b56b1c8fc6 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 10 Mar 2025 20:49:14 -0600 Subject: [PATCH 26/40] [ft] Add hb_ft_face_create_from_blob_or_fail() Part of https://github.com/harfbuzz/harfbuzz/issues/5117 Untested. New API: +hb_ft_face_create_from_blob_or_fail() --- docs/harfbuzz-sections.txt | 1 + src/hb-ft.cc | 72 +++++++++++++++++++++++++++++++++++++- src/hb-ft.h | 4 +++ 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index f09c85128..736f66179 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -536,6 +536,7 @@ hb_ft_face_create hb_ft_face_create_cached hb_ft_face_create_referenced hb_ft_face_create_from_file_or_fail +hb_ft_face_create_from_blob_or_fail hb_ft_font_create hb_ft_font_create_referenced hb_ft_font_changed diff --git a/src/hb-ft.cc b/src/hb-ft.cc index 3159a9ec3..8e83a3deb 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -1610,7 +1610,8 @@ destroy_ft_library (void *arg) * font file and face index. * * This is similar in functionality to hb_face_create_from_file_or_fail(), - * but uses the FreeType library for loading the font file. + * but uses the FreeType library for loading the font file. This can + * be useful, for example, to load WOFF and WOFF2 font data. * * Return value: (transfer full): The new face object, or `NULL` if * no face is found at the specified index or the file cannot be read. @@ -1647,6 +1648,75 @@ hb_ft_face_create_from_file_or_fail (const char *file_name, return face; } +static hb_user_data_key_t ft_blob_key = {0}; + +static void +_destroy_blob (void *p) +{ + hb_blob_destroy ((hb_blob_t *) p); +} + +/** + * hb_ft_face_create_from_blob_or_fail: + * @blob: A blob + * @index: The index of the face within the blob + * + * Creates an #hb_face_t face object from the specified + * font blob and face index. + * + * This is similar in functionality to hb_face_create_from_blob_or_fail(), + * but uses the FreeType library for loading the font blob. This can + * be useful, for example, to load WOFF and WOFF2 font data. + * + * Return value: (transfer full): The new face object, or `NULL` if + * loading fails (eg. blob does not contain valid font data). + * + * XSince: REPLACEME + */ +hb_face_t * +hb_ft_face_create_from_blob_or_fail (hb_blob_t *blob, + unsigned int index) +{ + FT_Library ft_library = reference_ft_library (); + if (unlikely (!ft_library)) + { + DEBUG_MSG (FT, ft_library, "reference_ft_library failed"); + return nullptr; + } + + hb_blob_make_immutable (blob); + unsigned blob_size; + const char *blob_data = hb_blob_get_data (blob, &blob_size); + + FT_Face ft_face; + if (unlikely (FT_New_Memory_Face (ft_library, + (const FT_Byte *) blob_data, + blob_size, + index, + &ft_face))) + return nullptr; + + hb_face_t *face = hb_ft_face_create_referenced (ft_face); + FT_Done_Face (ft_face); + + ft_face->generic.data = ft_library; + ft_face->generic.finalizer = finalize_ft_library; + + if (hb_face_is_immutable (face)) + return nullptr; + + // Hook the blob to the hb_face_t, since FT_Face still needs it. + hb_blob_reference (blob); + if (!hb_face_set_user_data (face, &ft_blob_key, blob, _destroy_blob, true)) + { + hb_blob_destroy (blob); + hb_face_destroy (face); + return nullptr; + } + + return face; +} + static void _release_blob (void *arg) { diff --git a/src/hb-ft.h b/src/hb-ft.h index 42bfb4f46..227b4f221 100644 --- a/src/hb-ft.h +++ b/src/hb-ft.h @@ -88,6 +88,10 @@ HB_EXTERN hb_face_t * hb_ft_face_create_from_file_or_fail (const char *file_name, unsigned int index); +HB_EXTERN hb_face_t * +hb_ft_face_create_from_blob_or_fail (hb_blob_t *blob, + unsigned int index); + /* * hb-font from ft-face. */ From 8ca9fe7617ba087e8b4937666642458d7adaf6d4 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 10 Mar 2025 21:13:07 -0600 Subject: [PATCH 27/40] [face] Avoid edit-sanitizing in hb_face_count() --- src/hb-face.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/hb-face.cc b/src/hb-face.cc index e35aa1caf..4db8c7a92 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -79,14 +79,14 @@ hb_face_count (hb_blob_t *blob) if (unlikely (!blob)) return 0; - /* TODO We shouldn't be sanitizing blob. Port to run sanitizer and return if not sane. */ - /* Make API signature const after. */ - hb_blob_t *sanitized = hb_sanitize_context_t ().sanitize_blob (hb_blob_reference (blob)); - const OT::OpenTypeFontFile& ot = *sanitized->as (); - unsigned int ret = ot.get_face_count (); - hb_blob_destroy (sanitized); + hb_sanitize_context_t c (blob); - return ret; + const char *start = hb_blob_get_data (blob, nullptr); + auto *ot = reinterpret_cast (const_cast (start)); + if (unlikely (!ot->sanitize (&c))) + return 0; + + return ot->get_face_count (); } /* From f98c203e7a3e3a18433f830f7e633005362397c6 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 10 Mar 2025 21:30:28 -0600 Subject: [PATCH 28/40] [coretext] Add hb_coretext_face_create_from_blob_or_fail() Part of https://github.com/harfbuzz/harfbuzz/issues/5117 Untested. New API: +hb_coretext_face_create_from_blob_or_fail() --- docs/harfbuzz-sections.txt | 1 + src/hb-coretext-shape.cc | 76 ++++++++++++++++++++++++++++++-------- src/hb-coretext.h | 4 ++ 3 files changed, 66 insertions(+), 15 deletions(-) diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index 736f66179..6592277c3 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -347,6 +347,7 @@ HB_CORETEXT_TAG_MORT HB_CORETEXT_TAG_MORX hb_coretext_face_create hb_coretext_face_create_from_file_or_fail +hb_coretext_face_create_from_blob_or_fail hb_coretext_font_create hb_coretext_face_get_cg_font hb_coretext_font_get_ct_font diff --git a/src/hb-coretext-shape.cc b/src/hb-coretext-shape.cc index 2e029fe2b..33296c77c 100644 --- a/src/hb-coretext-shape.cc +++ b/src/hb-coretext-shape.cc @@ -160,30 +160,42 @@ release_data (void *info, const void *data, size_t size) hb_blob_destroy ((hb_blob_t *) info); } +static CGFontRef +create_cg_font (hb_blob_t *blob, unsigned int index) +{ + if (unlikely (index != 0)) + return nullptr; // How? + + hb_blob_make_immutable (blob); + unsigned int blob_length; + const char *blob_data = hb_blob_get_data (blob, &blob_length); + if (unlikely (!blob_length)) + DEBUG_MSG (CORETEXT, blob, "Empty blob"); + + hb_blob_reference (blob); + CGDataProviderRef provider = CGDataProviderCreateWithData (blob, blob_data, blob_length, &release_data); + CGFontRef cg_font = nullptr; + if (likely (provider)) + { + cg_font = CGFontCreateWithDataProvider (provider); + if (unlikely (!cg_font)) + DEBUG_MSG (CORETEXT, blob, "CGFontCreateWithDataProvider() failed"); + CGDataProviderRelease (provider); + } + return cg_font; +} + static CGFontRef create_cg_font (hb_face_t *face) { CGFontRef cg_font = nullptr; if (face->destroy == _hb_cg_font_release) - { cg_font = CGFontRetain ((CGFontRef) face->user_data); - } else { hb_blob_t *blob = hb_face_reference_blob (face); - unsigned int blob_length; - const char *blob_data = hb_blob_get_data (blob, &blob_length); - if (unlikely (!blob_length)) - DEBUG_MSG (CORETEXT, face, "Face has empty blob"); - - CGDataProviderRef provider = CGDataProviderCreateWithData (blob, blob_data, blob_length, &release_data); - if (likely (provider)) - { - cg_font = CGFontCreateWithDataProvider (provider); - if (unlikely (!cg_font)) - DEBUG_MSG (CORETEXT, face, "Face CGFontCreateWithDataProvider() failed"); - CGDataProviderRelease (provider); - } + cg_font = create_cg_font (blob, face->index); + hb_blob_destroy (blob); } return cg_font; } @@ -404,6 +416,40 @@ hb_coretext_face_create_from_file_or_fail (const char *file_name, return face; } +/** + * hb_coretext_face_create_from_blob_or_fail: + * @blob: A blob containing the font data + * @index: The index of the face within the blob + * + * Creates an #hb_face_t face object from the specified + * blob and face index. + * + * This is similar in functionality to hb_face_create_from_blob_or_fail(), + * but uses the CoreText library for loading the font data. + * + * Note that currently only @index equal to 0 is supported. + * + * Return value: (transfer full): The new face object, or `NULL` if + * no face is found at the specified index or the blob cannot be read. + * + * XSince: REPLACEME + */ +hb_face_t * +hb_coretext_face_create_from_blob_or_fail (hb_blob_t *blob, + unsigned int index) +{ + auto cg_font = create_cg_font (blob, index); + if (unlikely (!cg_font)) + return nullptr; + + hb_face_t *face = hb_coretext_face_create (cg_font); + CFRelease (cg_font); + if (unlikely (hb_face_is_immutable (face))) + return nullptr; + + return face; +} + /** * hb_coretext_face_get_cg_font: * @face: The #hb_face_t to work upon diff --git a/src/hb-coretext.h b/src/hb-coretext.h index 3626f1c12..a7c7fee76 100644 --- a/src/hb-coretext.h +++ b/src/hb-coretext.h @@ -84,6 +84,10 @@ HB_EXTERN hb_face_t * hb_coretext_face_create_from_file_or_fail (const char *file_name, unsigned int index); +HB_EXTERN hb_face_t * +hb_coretext_face_create_from_blob_or_fail (hb_blob_t *blob, + unsigned int index); + HB_EXTERN hb_font_t * hb_coretext_font_create (CTFontRef ct_font); From b1c50eb938d5a6d7fdf09bf8490b1b54c1c6aedf Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 10 Mar 2025 21:35:46 -0600 Subject: [PATCH 29/40] [face] Rename a variable --- src/hb-face.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hb-face.cc b/src/hb-face.cc index 4db8c7a92..b6c7d80c1 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -370,15 +370,15 @@ hb_face_create_from_file_or_fail_using (const char *file_name, if (!loader_name || !*loader_name) { - static hb_atomic_ptr_t static_funcs_name; - loader_name = static_funcs_name.get_acquire (); + static hb_atomic_ptr_t static_loader_name; + loader_name = static_loader_name.get_acquire (); if (!loader_name) { loader_name = getenv ("HB_FACE_LOADER"); if (!loader_name) loader_name = ""; - if (!static_funcs_name.cmpexch (nullptr, loader_name)) - loader_name = static_funcs_name.get_acquire (); + if (!static_loader_name.cmpexch (nullptr, loader_name)) + loader_name = static_loader_name.get_acquire (); } retry = true; } From cbc205c2f025d1980d24737fbbb87be1eb73b9aa Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 10 Mar 2025 21:41:54 -0600 Subject: [PATCH 30/40] [font/face] Refactor some code --- src/hb-face.cc | 27 ++++++++++++++++----------- src/hb-font.cc | 26 ++++++++++++++++---------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/hb-face.cc b/src/hb-face.cc index b6c7d80c1..56ff340ff 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -342,6 +342,21 @@ static struct supported_face_loaders_t { #endif }; +static const char *get_default_loader_name () +{ + static hb_atomic_ptr_t static_loader_name; + const char *loader_name = static_loader_name.get_acquire (); + if (!loader_name) + { + loader_name = getenv ("HB_FACE_LOADER"); + if (!loader_name) + loader_name = ""; + if (!static_loader_name.cmpexch (nullptr, loader_name)) + loader_name = static_loader_name.get_acquire (); + } + return loader_name; +} + /** * hb_face_create_from_file_or_fail_using: * @file_name: A font filename @@ -367,19 +382,9 @@ hb_face_create_from_file_or_fail_using (const char *file_name, const char *loader_name) { bool retry = false; - if (!loader_name || !*loader_name) { - static hb_atomic_ptr_t static_loader_name; - loader_name = static_loader_name.get_acquire (); - if (!loader_name) - { - loader_name = getenv ("HB_FACE_LOADER"); - if (!loader_name) - loader_name = ""; - if (!static_loader_name.cmpexch (nullptr, loader_name)) - loader_name = static_loader_name.get_acquire (); - } + loader_name = get_default_loader_name (); retry = true; } if (loader_name && !*loader_name) loader_name = nullptr; diff --git a/src/hb-font.cc b/src/hb-font.cc index 33d71c86d..28d9ff2f5 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -2321,6 +2321,21 @@ static struct supported_font_funcs_t { #endif }; +static const char *get_default_funcs_name () +{ + static hb_atomic_ptr_t static_funcs_name; + const char *name = static_funcs_name.get_acquire (); + if (!name) + { + name = getenv ("HB_FONT_FUNCS"); + if (!name) + name = ""; + if (!static_funcs_name.cmpexch (nullptr, name)) + name = static_funcs_name.get_acquire (); + } + return name; +} + /** * hb_font_set_funcs_using: * @font: #hb_font_t to work upon @@ -2345,16 +2360,7 @@ hb_font_set_funcs_using (hb_font_t *font, if (!name || !*name) { - static hb_atomic_ptr_t static_funcs_name; - name = static_funcs_name.get_acquire (); - if (!name) - { - name = getenv ("HB_FONT_FUNCS"); - if (!name) - name = ""; - if (!static_funcs_name.cmpexch (nullptr, name)) - name = static_funcs_name.get_acquire (); - } + name = get_default_funcs_name (); retry = true; } if (name && !*name) name = nullptr; From 8e8a9f6f40554fc716c7d6657fb48ca431648205 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 10 Mar 2025 21:48:36 -0600 Subject: [PATCH 31/40] [face] Add hb_face_create_or_fail_using() Fixes https://github.com/harfbuzz/harfbuzz/issues/5117 Untested. New API: +hb_face_create_or_fail_using --- docs/harfbuzz-sections.txt | 1 + src/hb-face.cc | 77 ++++++++++++++++++++++++++++++++++---- src/hb-face.h | 5 +++ 3 files changed, 76 insertions(+), 7 deletions(-) diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index 6592277c3..fb29dba9b 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -368,6 +368,7 @@ hb_face_count hb_face_t hb_face_create hb_face_create_or_fail +hb_face_create_or_fail_using hb_face_create_from_file_or_fail hb_face_create_from_file_or_fail_using hb_face_list_loaders diff --git a/src/hb-face.cc b/src/hb-face.cc index 56ff340ff..0399e720e 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -328,17 +328,29 @@ hb_face_create_from_file_or_fail (const char *file_name, static struct supported_face_loaders_t { char name[9]; - hb_face_t * (*func) (const char *font_file, unsigned face_index); + hb_face_t * (*from_file) (const char *font_file, unsigned face_index); + hb_face_t * (*from_blob) (hb_blob_t *blob, unsigned face_index); } supported_face_loaders[] = { + {"ot", #ifndef HB_NO_OPEN - {"ot", hb_face_create_from_file_or_fail}, + hb_face_create_from_file_or_fail, +#else + nullptr, #endif + hb_face_create_or_fail + }, #ifdef HAVE_FREETYPE - {"ft", hb_ft_face_create_from_file_or_fail}, + {"ft", + hb_ft_face_create_from_file_or_fail, + hb_ft_face_create_from_blob_or_fail + }, #endif #ifdef HAVE_CORETEXT - {"coretext", hb_coretext_face_create_from_file_or_fail}, + {"coretext", + hb_coretext_face_create_from_file_or_fail, + hb_coretext_face_create_from_blob_or_fail + }, #endif }; @@ -368,7 +380,7 @@ static const char *get_default_loader_name () * is used. * * For example, the FreeType ("ft") loader might be able to load - * .woff and .woff2 files if FreeType is built with those features, + * WOFF and WOFF2 files if FreeType is built with those features, * whereas the OpenType ("ot") loader will not. * * Return value: (transfer full): The new face object, or `NULL` if @@ -381,6 +393,7 @@ hb_face_create_from_file_or_fail_using (const char *file_name, unsigned int index, const char *loader_name) { + // Duplicated in hb_face_create_or_fail_using bool retry = false; if (!loader_name || !*loader_name) { @@ -392,8 +405,58 @@ hb_face_create_from_file_or_fail_using (const char *file_name, retry: for (unsigned i = 0; i < ARRAY_LENGTH (supported_face_loaders); i++) { - if (!loader_name || !strcmp (supported_face_loaders[i].name, loader_name)) - return supported_face_loaders[i].func (file_name, index); + if (!loader_name || (supported_face_loaders[i].from_file && !strcmp (supported_face_loaders[i].name, loader_name))) + return supported_face_loaders[i].from_file (file_name, index); + } + + if (retry) + { + retry = false; + loader_name = nullptr; + goto retry; + } + + return nullptr; +} + +/** + * hb_face_create_or_fail_using: + * @blob: #hb_blob_t to work upon + * @index: The index of the face within @blob + * @loader_name: (nullable): The name of the loader to use, or `NULL` + * + * A thin wrapper around the face loader functions registered with HarfBuzz. + * If @loader_name is `NULL` or the empty string, the first available loader + * is used. + * + * For example, the FreeType ("ft") loader might be able to load + * WOFF and WOFF2 files if FreeType is built with those features, + * whereas the OpenType ("ot") loader will not. + * + * Return value: (transfer full): The new face object, or `NULL` if + * the loader fails to load the face. + * + * XSince: REPLACEME + **/ +hb_face_t * +hb_face_create_or_fail_using (hb_blob_t *blob, + unsigned int index, + const char *loader_name) +{ + // Duplicated in hb_face_create_from_file_or_fail_using + bool retry = false; + if (!loader_name || !*loader_name) + { + loader_name = get_default_loader_name (); + retry = true; + } + if (loader_name && !*loader_name) loader_name = nullptr; + +retry: + for (unsigned i = 0; i < ARRAY_LENGTH (supported_face_loaders); i++) + { + if (!loader_name || (supported_face_loaders[i].from_blob && !strcmp (supported_face_loaders[i].name, loader_name))) + return supported_face_loaders[i].from_blob (blob, index); } if (retry) diff --git a/src/hb-face.h b/src/hb-face.h index c59ec0c4b..5d39a48cc 100644 --- a/src/hb-face.h +++ b/src/hb-face.h @@ -63,6 +63,11 @@ HB_EXTERN hb_face_t * hb_face_create_or_fail (hb_blob_t *blob, unsigned int index); +HB_EXTERN hb_face_t * +hb_face_create_or_fail_using (hb_blob_t *blob, + unsigned int index, + const char *loader_name); + HB_EXTERN hb_face_t * hb_face_create_from_file_or_fail (const char *file_name, unsigned int index); From 8687f5c38ef27da72279a15cfb07c8f2739eb78a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 10 Mar 2025 23:11:27 -0600 Subject: [PATCH 32/40] [face] Add tests for new constructors --- test/api/hb-test.h | 16 +++++-- test/api/meson.build | 1 + test/api/test-face.c | 111 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+), 5 deletions(-) create mode 100644 test/api/test-face.c diff --git a/test/api/hb-test.h b/test/api/hb-test.h index cdf355580..82006364d 100644 --- a/test/api/hb-test.h +++ b/test/api/hb-test.h @@ -305,14 +305,20 @@ G_STMT_START { \ } G_STMT_END +static inline char * +hb_test_resolve_path (const char *path) +{ +#if GLIB_CHECK_VERSION(2,37,2) + return g_test_build_filename (G_TEST_DIST, path, NULL); +#else + return path = g_strdup (path); +#endif +} + static inline hb_face_t * hb_test_open_font_file (const char *font_path) { -#if GLIB_CHECK_VERSION(2,37,2) - char *path = g_test_build_filename (G_TEST_DIST, font_path, NULL); -#else - char *path = g_strdup (font_path); -#endif + char *path = hb_test_resolve_path (font_path); hb_blob_t *blob = hb_blob_create_from_file_or_fail (path); hb_face_t *face; diff --git a/test/api/meson.build b/test/api/meson.build index 24d0d854f..bc4e0c5b8 100644 --- a/test/api/meson.build +++ b/test/api/meson.build @@ -18,6 +18,7 @@ tests = [ 'test-draw.c', 'test-draw-varc.c', 'test-extents.c', + 'test-face.c', 'test-font.c', 'test-font-scale.c', 'test-get-table-tags.c', diff --git a/test/api/test-face.c b/test/api/test-face.c new file mode 100644 index 000000000..7f9cda165 --- /dev/null +++ b/test/api/test-face.c @@ -0,0 +1,111 @@ +/* + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Author(s): Behdad Esfahbod + */ + +#include "hb-test.h" + +/* Unit tests for hb-face.h */ + +#define FONT_FILE "fonts/Roboto-Regular.ac.ttf" +static const char *font_file; + +hb_face_t *master_face = NULL; + +#define HEAD_TAG HB_TAG ('h', 'e', 'a', 'd') +hb_blob_t *master_head = NULL; + +static void +test_face (hb_face_t *face) +{ + g_assert (face); + + hb_blob_t *head = hb_face_reference_table (face, HEAD_TAG); + + unsigned int length = hb_blob_get_length (head); + unsigned int master_length = hb_blob_get_length (master_head); + g_assert_cmpuint (length, ==, master_length); + + const char *data = hb_blob_get_data (head, NULL); + const char *master_data = hb_blob_get_data (master_head, NULL); + g_assert (memcmp (data, master_data, length) == 0); + + hb_blob_destroy (head); +} + +static void +test_create_from_file_using (const char *loader) +{ + hb_face_t *face = hb_face_create_from_file_or_fail_using (font_file, 0, loader); + test_face (face); + hb_face_destroy (face); +} + +static void +test_create_from_file (void) +{ + test_create_from_file_using (NULL); + const char **loaders = hb_face_list_loaders (); + for (unsigned i = 0; loaders[i]; i++) + test_create_from_file_using (loaders[i]); +} + +static void +test_create_from_blob_using (const char *loader) +{ + hb_blob_t *blob = hb_blob_create_from_file_or_fail (font_file); + hb_face_t *face = hb_face_create_or_fail_using (blob, 0, loader); + hb_blob_destroy (blob); + test_face (face); + hb_face_destroy (face); +} + +static void +test_create_from_blob (void) +{ + test_create_from_file_using (NULL); + const char **loaders = hb_face_list_loaders (); + for (unsigned i = 0; loaders[i]; i++) + test_create_from_blob_using (loaders[i]); +} + +int +main (int argc, char **argv) +{ + hb_test_init (&argc, &argv); + + font_file = hb_test_resolve_path (FONT_FILE); + master_face = hb_test_open_font_file (FONT_FILE); + master_head = hb_face_reference_table (master_face, HEAD_TAG); + g_assert (hb_blob_get_length (master_head) > 0); + + hb_test_add (test_create_from_file); + hb_test_add (test_create_from_blob); + + int ret = hb_test_run(); + + hb_blob_destroy (master_head); + hb_face_destroy (master_face); + g_free ((char *) font_file); + + return ret; +} From 5e6da541665822fba4137c5bfcaabe6a60fdca4f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 11 Mar 2025 12:00:18 -0600 Subject: [PATCH 33/40] [test] Minor, accept absolute font paths --- test/api/hb-test.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/api/hb-test.h b/test/api/hb-test.h index 82006364d..537a2df82 100644 --- a/test/api/hb-test.h +++ b/test/api/hb-test.h @@ -309,10 +309,10 @@ static inline char * hb_test_resolve_path (const char *path) { #if GLIB_CHECK_VERSION(2,37,2) - return g_test_build_filename (G_TEST_DIST, path, NULL); -#else - return path = g_strdup (path); + if (path[0] != '/') + return g_test_build_filename (G_TEST_DIST, path, NULL); #endif + return g_strdup (path); } static inline hb_face_t * From 759e1881e81a5ceb7280ddffe5ddd1fd6d4da484 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 11 Mar 2025 12:12:08 -0600 Subject: [PATCH 34/40] [coretext] Fix loading TTC files --- src/hb-coretext-shape.cc | 53 ++++++++++++++++++-------------- test/api/hb-test.h | 20 +++++++++---- test/api/test-face.c | 65 +++++++++++++++++++--------------------- 3 files changed, 76 insertions(+), 62 deletions(-) diff --git a/src/hb-coretext-shape.cc b/src/hb-coretext-shape.cc index 33296c77c..58a1fb28e 100644 --- a/src/hb-coretext-shape.cc +++ b/src/hb-coretext-shape.cc @@ -160,18 +160,44 @@ release_data (void *info, const void *data, size_t size) hb_blob_destroy ((hb_blob_t *) info); } +static CGFontRef +create_cg_font (CFArrayRef ct_font_desc_array, unsigned int index) +{ + auto ct_font_desc = (CFArrayGetCount (ct_font_desc_array) > index) ? + (CTFontDescriptorRef) CFArrayGetValueAtIndex (ct_font_desc_array, index) : nullptr; + if (unlikely (!ct_font_desc)) + { + CFRelease (ct_font_desc_array); + return nullptr; + } + auto ct_font = ct_font_desc ? CTFontCreateWithFontDescriptor (ct_font_desc, 0, nullptr) : nullptr; + CFRelease (ct_font_desc_array); + if (unlikely (!ct_font)) + return nullptr; + + auto cg_font = ct_font ? CTFontCopyGraphicsFont (ct_font, nullptr) : nullptr; + CFRelease (ct_font); + + return cg_font; +} + static CGFontRef create_cg_font (hb_blob_t *blob, unsigned int index) { - if (unlikely (index != 0)) - return nullptr; // How? - hb_blob_make_immutable (blob); unsigned int blob_length; const char *blob_data = hb_blob_get_data (blob, &blob_length); if (unlikely (!blob_length)) DEBUG_MSG (CORETEXT, blob, "Empty blob"); + if (unlikely (index != 0)) + { + auto ct_font_desc_array = CTFontManagerCreateFontDescriptorsFromData (CFDataCreate (kCFAllocatorDefault, (const UInt8 *) blob_data, blob_length)); + if (unlikely (!ct_font_desc_array)) + return nullptr; + return create_cg_font (ct_font_desc_array, index); + } + hb_blob_reference (blob); CGDataProviderRef provider = CGDataProviderCreateWithData (blob, blob_data, blob_length, &release_data); CGFontRef cg_font = nullptr; @@ -389,24 +415,9 @@ hb_coretext_face_create_from_file_or_fail (const char *file_name, CFRelease (url); return nullptr; } - auto ct_font_desc = (CFArrayGetCount (ct_font_desc_array) > index) ? - (CTFontDescriptorRef) CFArrayGetValueAtIndex (ct_font_desc_array, index) : nullptr; - if (unlikely (!ct_font_desc)) - { - CFRelease (ct_font_desc_array); - CFRelease (url); - return nullptr; - } - CFRelease (url); - auto ct_font = ct_font_desc ? CTFontCreateWithFontDescriptor (ct_font_desc, 0, nullptr) : nullptr; - CFRelease (ct_font_desc_array); - if (unlikely (!ct_font)) - return nullptr; - auto cg_font = ct_font ? CTFontCopyGraphicsFont (ct_font, nullptr) : nullptr; - CFRelease (ct_font); - if (unlikely (!cg_font)) - return nullptr; + auto cg_font = create_cg_font (ct_font_desc_array, index); + CFRelease (url); hb_face_t *face = hb_coretext_face_create (cg_font); CFRelease (cg_font); @@ -427,8 +438,6 @@ hb_coretext_face_create_from_file_or_fail (const char *file_name, * This is similar in functionality to hb_face_create_from_blob_or_fail(), * but uses the CoreText library for loading the font data. * - * Note that currently only @index equal to 0 is supported. - * * Return value: (transfer full): The new face object, or `NULL` if * no face is found at the specified index or the blob cannot be read. * diff --git a/test/api/hb-test.h b/test/api/hb-test.h index 537a2df82..648f452e4 100644 --- a/test/api/hb-test.h +++ b/test/api/hb-test.h @@ -241,9 +241,14 @@ hb_test_add_data_func_flavor (const char *test_path, gconstpointer test_data, hb_test_data_func_t test_func) { - char *path = g_strdup_printf ("%s/%s", test_path, flavor); - hb_test_add_data_func (path, test_data, test_func); - g_free (path); + if (flavor && *flavor) + { + char *path = g_strdup_printf ("%s/%s", test_path, flavor); + hb_test_add_data_func (path, test_data, test_func); + g_free (path); + } + else + hb_test_add_data_func (test_path, test_data, test_func); } #define hb_test_add_data_flavor(UserData, Flavor, Func) hb_test_add_data_func_flavor (#Func, Flavor, UserData, Func) @@ -316,7 +321,7 @@ hb_test_resolve_path (const char *path) } static inline hb_face_t * -hb_test_open_font_file (const char *font_path) +hb_test_open_font_file_with_index (const char *font_path, unsigned face_index) { char *path = hb_test_resolve_path (font_path); @@ -325,13 +330,18 @@ hb_test_open_font_file (const char *font_path) if (!blob) g_error ("Font %s not found.", path); - face = hb_face_create (blob, 0); + face = hb_face_create (blob, face_index); hb_blob_destroy (blob); g_free (path); return face; } +static inline hb_face_t * +hb_test_open_font_file (const char *font_path) +{ + return hb_test_open_font_file_with_index (font_path, 0); +} HB_END_DECLS diff --git a/test/api/test-face.c b/test/api/test-face.c index 7f9cda165..9d45eca29 100644 --- a/test/api/test-face.c +++ b/test/api/test-face.c @@ -27,7 +27,8 @@ /* Unit tests for hb-face.h */ #define FONT_FILE "fonts/Roboto-Regular.ac.ttf" -static const char *font_file; +static const char *font_file = NULL; +static unsigned int face_index = 0; hb_face_t *master_face = NULL; @@ -37,69 +38,63 @@ hb_blob_t *master_head = NULL; static void test_face (hb_face_t *face) { - g_assert (face); + g_assert_nonnull (face); hb_blob_t *head = hb_face_reference_table (face, HEAD_TAG); - unsigned int length = hb_blob_get_length (head); - unsigned int master_length = hb_blob_get_length (master_head); - g_assert_cmpuint (length, ==, master_length); - - const char *data = hb_blob_get_data (head, NULL); - const char *master_data = hb_blob_get_data (master_head, NULL); - g_assert (memcmp (data, master_data, length) == 0); + unsigned int length; + unsigned int master_length; + const char *data = hb_blob_get_data (head, &length); + const char *master_data = hb_blob_get_data (master_head, &master_length); + g_assert_cmpmem (data, length, master_data, master_length); hb_blob_destroy (head); } static void -test_create_from_file_using (const char *loader) +test_create_from_file_using (const void *user_data) { - hb_face_t *face = hb_face_create_from_file_or_fail_using (font_file, 0, loader); + const char *loader = user_data; + hb_face_t *face = hb_face_create_from_file_or_fail_using (font_file, face_index, loader); test_face (face); hb_face_destroy (face); } static void -test_create_from_file (void) -{ - test_create_from_file_using (NULL); - const char **loaders = hb_face_list_loaders (); - for (unsigned i = 0; loaders[i]; i++) - test_create_from_file_using (loaders[i]); -} - -static void -test_create_from_blob_using (const char *loader) +test_create_from_blob_using (const void *user_data) { + const char *loader = user_data; hb_blob_t *blob = hb_blob_create_from_file_or_fail (font_file); - hb_face_t *face = hb_face_create_or_fail_using (blob, 0, loader); + hb_face_t *face = hb_face_create_or_fail_using (blob, face_index, loader); hb_blob_destroy (blob); test_face (face); hb_face_destroy (face); } -static void -test_create_from_blob (void) -{ - test_create_from_file_using (NULL); - const char **loaders = hb_face_list_loaders (); - for (unsigned i = 0; loaders[i]; i++) - test_create_from_blob_using (loaders[i]); -} - int main (int argc, char **argv) { hb_test_init (&argc, &argv); - font_file = hb_test_resolve_path (FONT_FILE); - master_face = hb_test_open_font_file (FONT_FILE); + font_file = FONT_FILE; + if (argc > 1) + font_file = argv[1]; + if (argc > 2) + face_index = atoi (argv[2]); + + master_face = hb_test_open_font_file_with_index (font_file, face_index); master_head = hb_face_reference_table (master_face, HEAD_TAG); g_assert (hb_blob_get_length (master_head) > 0); - hb_test_add (test_create_from_file); - hb_test_add (test_create_from_blob); + font_file = hb_test_resolve_path (font_file); + + hb_test_add_flavor ("", test_create_from_file_using); + hb_test_add_flavor ("", test_create_from_blob_using); + for (const char **loaders = hb_face_list_loaders (); *loaders; loaders++) + { + hb_test_add_flavor (*loaders, test_create_from_file_using); + hb_test_add_flavor (*loaders, test_create_from_blob_using); + } int ret = hb_test_run(); From f0a67e99483b7fe3a20a822e3c87db85c80362be Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 11 Mar 2025 20:37:30 -0600 Subject: [PATCH 35/40] [coretext] Split common code into hb-coretext.cc --- src/harfbuzz.cc | 1 + src/hb-coretext-font.cc | 2 +- src/hb-coretext-shape.cc | 423 +----------------------------------- src/hb-coretext.cc | 456 +++++++++++++++++++++++++++++++++++++++ src/hb-coretext.hh | 53 +++++ src/meson.build | 2 +- 6 files changed, 513 insertions(+), 424 deletions(-) create mode 100644 src/hb-coretext.cc create mode 100644 src/hb-coretext.hh diff --git a/src/harfbuzz.cc b/src/harfbuzz.cc index 9ff800daa..de45f59a5 100644 --- a/src/harfbuzz.cc +++ b/src/harfbuzz.cc @@ -8,6 +8,7 @@ #include "hb-common.cc" #include "hb-coretext-font.cc" #include "hb-coretext-shape.cc" +#include "hb-coretext.cc" #include "hb-directwrite.cc" #include "hb-draw.cc" #include "hb-face-builder.cc" diff --git a/src/hb-coretext-font.cc b/src/hb-coretext-font.cc index 6d03e77e5..91f9b0e0b 100644 --- a/src/hb-coretext-font.cc +++ b/src/hb-coretext-font.cc @@ -28,7 +28,7 @@ #ifdef HAVE_CORETEXT -#include "hb-coretext.h" +#include "hb-coretext.hh" #include "hb-draw.hh" #include "hb-font.hh" diff --git a/src/hb-coretext-shape.cc b/src/hb-coretext-shape.cc index 58a1fb28e..3056397f7 100644 --- a/src/hb-coretext-shape.cc +++ b/src/hb-coretext-shape.cc @@ -32,317 +32,9 @@ #include "hb-shaper-impl.hh" -#include "hb-coretext.h" +#include "hb-coretext.hh" #include "hb-aat-layout.hh" - -/** - * SECTION:hb-coretext - * @title: hb-coretext - * @short_description: CoreText integration - * @include: hb-coretext.h - * - * Functions for using HarfBuzz with the CoreText fonts. - **/ - -static CTFontRef create_ct_font (CGFontRef cg_font, CGFloat font_size); - -static void -release_table_data (void *user_data) -{ - CFDataRef cf_data = reinterpret_cast (user_data); - CFRelease(cf_data); -} - -static hb_blob_t * -_hb_cg_reference_table (hb_face_t *face HB_UNUSED, hb_tag_t tag, void *user_data) -{ - CGFontRef cg_font = reinterpret_cast (user_data); - CFDataRef cf_data = CGFontCopyTableForTag (cg_font, tag); - if (unlikely (!cf_data)) - return nullptr; - - const char *data = reinterpret_cast (CFDataGetBytePtr (cf_data)); - const size_t length = CFDataGetLength (cf_data); - if (!data || !length) - { - CFRelease (cf_data); - return nullptr; - } - - return hb_blob_create (data, length, HB_MEMORY_MODE_READONLY, - reinterpret_cast (const_cast<__CFData *> (cf_data)), - release_table_data); -} - -static unsigned -_hb_cg_get_table_tags (const hb_face_t *face HB_UNUSED, - unsigned int start_offset, - unsigned int *table_count, - hb_tag_t *table_tags, - void *user_data) -{ - CGFontRef cg_font = reinterpret_cast (user_data); - - CTFontRef ct_font = create_ct_font (cg_font, (CGFloat) HB_CORETEXT_DEFAULT_FONT_SIZE); - - auto arr = CTFontCopyAvailableTables (ct_font, kCTFontTableOptionNoOptions); - - unsigned population = (unsigned) CFArrayGetCount (arr); - unsigned end_offset; - - if (!table_count) - goto done; - - if (unlikely (start_offset >= population)) - { - *table_count = 0; - goto done; - } - - end_offset = start_offset + *table_count; - if (unlikely (end_offset < start_offset)) - { - *table_count = 0; - goto done; - } - end_offset= hb_min (end_offset, (unsigned) population); - - *table_count = end_offset - start_offset; - for (unsigned i = start_offset; i < end_offset; i++) - { - CTFontTableTag tag = (CTFontTableTag)(uintptr_t) CFArrayGetValueAtIndex (arr, i); - table_tags[i - start_offset] = tag; - } - -done: - CFRelease (arr); - CFRelease (ct_font); - return population; -} - -static void -_hb_cg_font_release (void *data) -{ - CGFontRelease ((CGFontRef) data); -} - - -static CTFontDescriptorRef -get_last_resort_font_desc () -{ - // TODO Handle allocation failures? - CTFontDescriptorRef last_resort = CTFontDescriptorCreateWithNameAndSize (CFSTR("LastResort"), 0); - CFArrayRef cascade_list = CFArrayCreate (kCFAllocatorDefault, - (const void **) &last_resort, - 1, - &kCFTypeArrayCallBacks); - CFRelease (last_resort); - CFDictionaryRef attributes = CFDictionaryCreate (kCFAllocatorDefault, - (const void **) &kCTFontCascadeListAttribute, - (const void **) &cascade_list, - 1, - &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks); - CFRelease (cascade_list); - - CTFontDescriptorRef font_desc = CTFontDescriptorCreateWithAttributes (attributes); - CFRelease (attributes); - return font_desc; -} - -static void -release_data (void *info, const void *data, size_t size) -{ - assert (hb_blob_get_length ((hb_blob_t *) info) == size && - hb_blob_get_data ((hb_blob_t *) info, nullptr) == data); - - hb_blob_destroy ((hb_blob_t *) info); -} - -static CGFontRef -create_cg_font (CFArrayRef ct_font_desc_array, unsigned int index) -{ - auto ct_font_desc = (CFArrayGetCount (ct_font_desc_array) > index) ? - (CTFontDescriptorRef) CFArrayGetValueAtIndex (ct_font_desc_array, index) : nullptr; - if (unlikely (!ct_font_desc)) - { - CFRelease (ct_font_desc_array); - return nullptr; - } - auto ct_font = ct_font_desc ? CTFontCreateWithFontDescriptor (ct_font_desc, 0, nullptr) : nullptr; - CFRelease (ct_font_desc_array); - if (unlikely (!ct_font)) - return nullptr; - - auto cg_font = ct_font ? CTFontCopyGraphicsFont (ct_font, nullptr) : nullptr; - CFRelease (ct_font); - - return cg_font; -} - -static CGFontRef -create_cg_font (hb_blob_t *blob, unsigned int index) -{ - hb_blob_make_immutable (blob); - unsigned int blob_length; - const char *blob_data = hb_blob_get_data (blob, &blob_length); - if (unlikely (!blob_length)) - DEBUG_MSG (CORETEXT, blob, "Empty blob"); - - if (unlikely (index != 0)) - { - auto ct_font_desc_array = CTFontManagerCreateFontDescriptorsFromData (CFDataCreate (kCFAllocatorDefault, (const UInt8 *) blob_data, blob_length)); - if (unlikely (!ct_font_desc_array)) - return nullptr; - return create_cg_font (ct_font_desc_array, index); - } - - hb_blob_reference (blob); - CGDataProviderRef provider = CGDataProviderCreateWithData (blob, blob_data, blob_length, &release_data); - CGFontRef cg_font = nullptr; - if (likely (provider)) - { - cg_font = CGFontCreateWithDataProvider (provider); - if (unlikely (!cg_font)) - DEBUG_MSG (CORETEXT, blob, "CGFontCreateWithDataProvider() failed"); - CGDataProviderRelease (provider); - } - return cg_font; -} - -static CGFontRef -create_cg_font (hb_face_t *face) -{ - CGFontRef cg_font = nullptr; - if (face->destroy == _hb_cg_font_release) - cg_font = CGFontRetain ((CGFontRef) face->user_data); - else - { - hb_blob_t *blob = hb_face_reference_blob (face); - cg_font = create_cg_font (blob, face->index); - hb_blob_destroy (blob); - } - return cg_font; -} - -static CTFontRef -create_ct_font (CGFontRef cg_font, CGFloat font_size) -{ - CTFontRef ct_font = nullptr; - - /* CoreText does not enable trak table usage / tracking when creating a CTFont - * using CTFontCreateWithGraphicsFont. The only way of enabling tracking seems - * to be through the CTFontCreateUIFontForLanguage call. */ - CFStringRef cg_postscript_name = CGFontCopyPostScriptName (cg_font); - if (CFStringHasPrefix (cg_postscript_name, CFSTR (".SFNSText")) || - CFStringHasPrefix (cg_postscript_name, CFSTR (".SFNSDisplay"))) - { -#if !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) && MAC_OS_X_VERSION_MIN_REQUIRED < 1080 -# define kCTFontUIFontSystem kCTFontSystemFontType -# define kCTFontUIFontEmphasizedSystem kCTFontEmphasizedSystemFontType -#endif - CTFontUIFontType font_type = kCTFontUIFontSystem; - if (CFStringHasSuffix (cg_postscript_name, CFSTR ("-Bold"))) - font_type = kCTFontUIFontEmphasizedSystem; - - ct_font = CTFontCreateUIFontForLanguage (font_type, font_size, nullptr); - CFStringRef ct_result_name = CTFontCopyPostScriptName(ct_font); - if (CFStringCompare (ct_result_name, cg_postscript_name, 0) != kCFCompareEqualTo) - { - CFRelease(ct_font); - ct_font = nullptr; - } - CFRelease (ct_result_name); - } - CFRelease (cg_postscript_name); - - if (!ct_font) - ct_font = CTFontCreateWithGraphicsFont (cg_font, font_size, nullptr, nullptr); - - if (unlikely (!ct_font)) { - DEBUG_MSG (CORETEXT, cg_font, "Font CTFontCreateWithGraphicsFont() failed"); - return nullptr; - } - - /* crbug.com/576941 and crbug.com/625902 and the investigation in the latter - * bug indicate that the cascade list reconfiguration occasionally causes - * crashes in CoreText on OS X 10.9, thus let's skip this step on older - * operating system versions. Except for the emoji font, where _not_ - * reconfiguring the cascade list causes CoreText crashes. For details, see - * crbug.com/549610 */ - // 0x00070000 stands for "kCTVersionNumber10_10", see CoreText.h -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - if (&CTGetCoreTextVersion != nullptr && CTGetCoreTextVersion() < 0x00070000) { -#pragma GCC diagnostic pop - CFStringRef fontName = CTFontCopyPostScriptName (ct_font); - bool isEmojiFont = CFStringCompare (fontName, CFSTR("AppleColorEmoji"), 0) == kCFCompareEqualTo; - CFRelease (fontName); - if (!isEmojiFont) - return ct_font; - } - - CFURLRef original_url = nullptr; -#if !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) && MAC_OS_X_VERSION_MIN_REQUIRED < 1060 - ATSFontRef atsFont; - FSRef fsref; - OSStatus status; - atsFont = CTFontGetPlatformFont (ct_font, NULL); - status = ATSFontGetFileReference (atsFont, &fsref); - if (status == noErr) - original_url = CFURLCreateFromFSRef (NULL, &fsref); -#else - original_url = (CFURLRef) CTFontCopyAttribute (ct_font, kCTFontURLAttribute); -#endif - - /* Create font copy with cascade list that has LastResort first; this speeds up CoreText - * font fallback which we don't need anyway. */ - { - CTFontDescriptorRef last_resort_font_desc = get_last_resort_font_desc (); - CTFontRef new_ct_font = CTFontCreateCopyWithAttributes (ct_font, 0.0, nullptr, last_resort_font_desc); - CFRelease (last_resort_font_desc); - if (new_ct_font) - { - /* The CTFontCreateCopyWithAttributes call fails to stay on the same font - * when reconfiguring the cascade list and may switch to a different font - * when there are fonts that go by the same name, since the descriptor is - * just name and size. - * - * Avoid reconfiguring the cascade lists if the new font is outside the - * system locations that we cannot access from the sandboxed renderer - * process in Blink. This can be detected by the new file URL location - * that the newly found font points to. */ - CFURLRef new_url = nullptr; -#if !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) && MAC_OS_X_VERSION_MIN_REQUIRED < 1060 - atsFont = CTFontGetPlatformFont (new_ct_font, NULL); - status = ATSFontGetFileReference (atsFont, &fsref); - if (status == noErr) - new_url = CFURLCreateFromFSRef (NULL, &fsref); -#else - new_url = (CFURLRef) CTFontCopyAttribute (new_ct_font, kCTFontURLAttribute); -#endif - // Keep reconfigured font if URL cannot be retrieved (seems to be the case - // on Mac OS 10.12 Sierra), speculative fix for crbug.com/625606 - if (!original_url || !new_url || CFEqual (original_url, new_url)) { - CFRelease (ct_font); - ct_font = new_ct_font; - } else { - CFRelease (new_ct_font); - DEBUG_MSG (CORETEXT, ct_font, "Discarding reconfigured CTFont, location changed."); - } - if (new_url) - CFRelease (new_url); - } - else - DEBUG_MSG (CORETEXT, ct_font, "Font copy with empty cascade list failed"); - } - - if (original_url) - CFRelease (original_url); - return ct_font; -} - hb_coretext_face_data_t * _hb_coretext_shaper_face_data_create (hb_face_t *face) { @@ -363,119 +55,6 @@ _hb_coretext_shaper_face_data_destroy (hb_coretext_face_data_t *data) CFRelease ((CGFontRef) data); } -/** - * hb_coretext_face_create: - * @cg_font: The CGFontRef to work upon - * - * Creates an #hb_face_t face object from the specified - * CGFontRef. - * - * Return value: (transfer full): The new face object - * - * Since: 0.9.10 - */ -hb_face_t * -hb_coretext_face_create (CGFontRef cg_font) -{ - hb_face_t *face = hb_face_create_for_tables (_hb_cg_reference_table, CGFontRetain (cg_font), _hb_cg_font_release); - hb_face_set_get_table_tags_func (face, _hb_cg_get_table_tags, cg_font, nullptr); - return face; -} - -/** - * hb_coretext_face_create_from_file_or_fail: - * @file_name: A font filename - * @index: The index of the face within the file - * - * Creates an #hb_face_t face object from the specified - * font file and face index. - * - * This is similar in functionality to hb_face_create_from_file_or_fail(), - * but uses the CoreText library for loading the font file. - * - * Return value: (transfer full): The new face object, or `NULL` if - * no face is found at the specified index or the file cannot be read. - * - * Since: 10.1.0 - */ -hb_face_t * -hb_coretext_face_create_from_file_or_fail (const char *file_name, - unsigned int index) -{ - auto url = CFURLCreateFromFileSystemRepresentation (nullptr, - (const UInt8 *) file_name, - strlen (file_name), - false); - if (unlikely (!url)) - return nullptr; - - auto ct_font_desc_array = CTFontManagerCreateFontDescriptorsFromURL (url); - if (unlikely (!ct_font_desc_array)) - { - CFRelease (url); - return nullptr; - } - - auto cg_font = create_cg_font (ct_font_desc_array, index); - CFRelease (url); - - hb_face_t *face = hb_coretext_face_create (cg_font); - CFRelease (cg_font); - if (unlikely (hb_face_is_immutable (face))) - return nullptr; - - return face; -} - -/** - * hb_coretext_face_create_from_blob_or_fail: - * @blob: A blob containing the font data - * @index: The index of the face within the blob - * - * Creates an #hb_face_t face object from the specified - * blob and face index. - * - * This is similar in functionality to hb_face_create_from_blob_or_fail(), - * but uses the CoreText library for loading the font data. - * - * Return value: (transfer full): The new face object, or `NULL` if - * no face is found at the specified index or the blob cannot be read. - * - * XSince: REPLACEME - */ -hb_face_t * -hb_coretext_face_create_from_blob_or_fail (hb_blob_t *blob, - unsigned int index) -{ - auto cg_font = create_cg_font (blob, index); - if (unlikely (!cg_font)) - return nullptr; - - hb_face_t *face = hb_coretext_face_create (cg_font); - CFRelease (cg_font); - if (unlikely (hb_face_is_immutable (face))) - return nullptr; - - return face; -} - -/** - * hb_coretext_face_get_cg_font: - * @face: The #hb_face_t to work upon - * - * Fetches the CGFontRef associated with an #hb_face_t - * face object - * - * Return value: the CGFontRef found - * - * Since: 0.9.10 - */ -CGFontRef -hb_coretext_face_get_cg_font (hb_face_t *face) -{ - return (CGFontRef) (const void *) face->data.coretext; -} - hb_coretext_font_data_t * _hb_coretext_shaper_font_data_create (hb_font_t *font) diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc new file mode 100644 index 000000000..da7645bce --- /dev/null +++ b/src/hb-coretext.cc @@ -0,0 +1,456 @@ +/* + * Copyright © 2012,2013 Mozilla Foundation. + * Copyright © 2012,2013 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Mozilla Author(s): Jonathan Kew + * Google Author(s): Behdad Esfahbod + */ + +#include "hb.hh" + +#ifdef HAVE_CORETEXT + +#include "hb-shaper-impl.hh" + +#include "hb-coretext.hh" + + +/** + * SECTION:hb-coretext + * @title: hb-coretext + * @short_description: CoreText integration + * @include: hb-coretext.h + * + * Functions for using HarfBuzz with the CoreText fonts. + **/ + +static void +release_table_data (void *user_data) +{ + CFDataRef cf_data = reinterpret_cast (user_data); + CFRelease(cf_data); +} + +static hb_blob_t * +_hb_cg_reference_table (hb_face_t *face HB_UNUSED, hb_tag_t tag, void *user_data) +{ + CGFontRef cg_font = reinterpret_cast (user_data); + CFDataRef cf_data = CGFontCopyTableForTag (cg_font, tag); + if (unlikely (!cf_data)) + return nullptr; + + const char *data = reinterpret_cast (CFDataGetBytePtr (cf_data)); + const size_t length = CFDataGetLength (cf_data); + if (!data || !length) + { + CFRelease (cf_data); + return nullptr; + } + + return hb_blob_create (data, length, HB_MEMORY_MODE_READONLY, + reinterpret_cast (const_cast<__CFData *> (cf_data)), + release_table_data); +} + +static unsigned +_hb_cg_get_table_tags (const hb_face_t *face HB_UNUSED, + unsigned int start_offset, + unsigned int *table_count, + hb_tag_t *table_tags, + void *user_data) +{ + CGFontRef cg_font = reinterpret_cast (user_data); + + CTFontRef ct_font = create_ct_font (cg_font, (CGFloat) HB_CORETEXT_DEFAULT_FONT_SIZE); + + auto arr = CTFontCopyAvailableTables (ct_font, kCTFontTableOptionNoOptions); + + unsigned population = (unsigned) CFArrayGetCount (arr); + unsigned end_offset; + + if (!table_count) + goto done; + + if (unlikely (start_offset >= population)) + { + *table_count = 0; + goto done; + } + + end_offset = start_offset + *table_count; + if (unlikely (end_offset < start_offset)) + { + *table_count = 0; + goto done; + } + end_offset= hb_min (end_offset, (unsigned) population); + + *table_count = end_offset - start_offset; + for (unsigned i = start_offset; i < end_offset; i++) + { + CTFontTableTag tag = (CTFontTableTag)(uintptr_t) CFArrayGetValueAtIndex (arr, i); + table_tags[i - start_offset] = tag; + } + +done: + CFRelease (arr); + CFRelease (ct_font); + return population; +} + +static void +_hb_cg_font_release (void *data) +{ + CGFontRelease ((CGFontRef) data); +} + + +static CTFontDescriptorRef +get_last_resort_font_desc () +{ + // TODO Handle allocation failures? + CTFontDescriptorRef last_resort = CTFontDescriptorCreateWithNameAndSize (CFSTR("LastResort"), 0); + CFArrayRef cascade_list = CFArrayCreate (kCFAllocatorDefault, + (const void **) &last_resort, + 1, + &kCFTypeArrayCallBacks); + CFRelease (last_resort); + CFDictionaryRef attributes = CFDictionaryCreate (kCFAllocatorDefault, + (const void **) &kCTFontCascadeListAttribute, + (const void **) &cascade_list, + 1, + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks); + CFRelease (cascade_list); + + CTFontDescriptorRef font_desc = CTFontDescriptorCreateWithAttributes (attributes); + CFRelease (attributes); + return font_desc; +} + +static void +release_data (void *info, const void *data, size_t size) +{ + assert (hb_blob_get_length ((hb_blob_t *) info) == size && + hb_blob_get_data ((hb_blob_t *) info, nullptr) == data); + + hb_blob_destroy ((hb_blob_t *) info); +} + +CGFontRef +create_cg_font (CFArrayRef ct_font_desc_array, unsigned int index) +{ + auto ct_font_desc = (CFArrayGetCount (ct_font_desc_array) > index) ? + (CTFontDescriptorRef) CFArrayGetValueAtIndex (ct_font_desc_array, index) : nullptr; + if (unlikely (!ct_font_desc)) + { + CFRelease (ct_font_desc_array); + return nullptr; + } + auto ct_font = ct_font_desc ? CTFontCreateWithFontDescriptor (ct_font_desc, 0, nullptr) : nullptr; + CFRelease (ct_font_desc_array); + if (unlikely (!ct_font)) + return nullptr; + + auto cg_font = ct_font ? CTFontCopyGraphicsFont (ct_font, nullptr) : nullptr; + CFRelease (ct_font); + + return cg_font; +} + +CGFontRef +create_cg_font (hb_blob_t *blob, unsigned int index) +{ + hb_blob_make_immutable (blob); + unsigned int blob_length; + const char *blob_data = hb_blob_get_data (blob, &blob_length); + if (unlikely (!blob_length)) + DEBUG_MSG (CORETEXT, blob, "Empty blob"); + + if (unlikely (index != 0)) + { + auto ct_font_desc_array = CTFontManagerCreateFontDescriptorsFromData (CFDataCreate (kCFAllocatorDefault, (const UInt8 *) blob_data, blob_length)); + if (unlikely (!ct_font_desc_array)) + return nullptr; + return create_cg_font (ct_font_desc_array, index); + } + + hb_blob_reference (blob); + CGDataProviderRef provider = CGDataProviderCreateWithData (blob, blob_data, blob_length, &release_data); + CGFontRef cg_font = nullptr; + if (likely (provider)) + { + cg_font = CGFontCreateWithDataProvider (provider); + if (unlikely (!cg_font)) + DEBUG_MSG (CORETEXT, blob, "CGFontCreateWithDataProvider() failed"); + CGDataProviderRelease (provider); + } + return cg_font; +} + +CGFontRef +create_cg_font (hb_face_t *face) +{ + CGFontRef cg_font = nullptr; + if (face->destroy == _hb_cg_font_release) + cg_font = CGFontRetain ((CGFontRef) face->user_data); + else + { + hb_blob_t *blob = hb_face_reference_blob (face); + cg_font = create_cg_font (blob, face->index); + hb_blob_destroy (blob); + } + return cg_font; +} + +CTFontRef +create_ct_font (CGFontRef cg_font, CGFloat font_size) +{ + CTFontRef ct_font = nullptr; + + /* CoreText does not enable trak table usage / tracking when creating a CTFont + * using CTFontCreateWithGraphicsFont. The only way of enabling tracking seems + * to be through the CTFontCreateUIFontForLanguage call. */ + CFStringRef cg_postscript_name = CGFontCopyPostScriptName (cg_font); + if (CFStringHasPrefix (cg_postscript_name, CFSTR (".SFNSText")) || + CFStringHasPrefix (cg_postscript_name, CFSTR (".SFNSDisplay"))) + { +#if !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) && MAC_OS_X_VERSION_MIN_REQUIRED < 1080 +# define kCTFontUIFontSystem kCTFontSystemFontType +# define kCTFontUIFontEmphasizedSystem kCTFontEmphasizedSystemFontType +#endif + CTFontUIFontType font_type = kCTFontUIFontSystem; + if (CFStringHasSuffix (cg_postscript_name, CFSTR ("-Bold"))) + font_type = kCTFontUIFontEmphasizedSystem; + + ct_font = CTFontCreateUIFontForLanguage (font_type, font_size, nullptr); + CFStringRef ct_result_name = CTFontCopyPostScriptName(ct_font); + if (CFStringCompare (ct_result_name, cg_postscript_name, 0) != kCFCompareEqualTo) + { + CFRelease(ct_font); + ct_font = nullptr; + } + CFRelease (ct_result_name); + } + CFRelease (cg_postscript_name); + + if (!ct_font) + ct_font = CTFontCreateWithGraphicsFont (cg_font, font_size, nullptr, nullptr); + + if (unlikely (!ct_font)) { + DEBUG_MSG (CORETEXT, cg_font, "Font CTFontCreateWithGraphicsFont() failed"); + return nullptr; + } + + /* crbug.com/576941 and crbug.com/625902 and the investigation in the latter + * bug indicate that the cascade list reconfiguration occasionally causes + * crashes in CoreText on OS X 10.9, thus let's skip this step on older + * operating system versions. Except for the emoji font, where _not_ + * reconfiguring the cascade list causes CoreText crashes. For details, see + * crbug.com/549610 */ + // 0x00070000 stands for "kCTVersionNumber10_10", see CoreText.h +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + if (&CTGetCoreTextVersion != nullptr && CTGetCoreTextVersion() < 0x00070000) { +#pragma GCC diagnostic pop + CFStringRef fontName = CTFontCopyPostScriptName (ct_font); + bool isEmojiFont = CFStringCompare (fontName, CFSTR("AppleColorEmoji"), 0) == kCFCompareEqualTo; + CFRelease (fontName); + if (!isEmojiFont) + return ct_font; + } + + CFURLRef original_url = nullptr; +#if !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) && MAC_OS_X_VERSION_MIN_REQUIRED < 1060 + ATSFontRef atsFont; + FSRef fsref; + OSStatus status; + atsFont = CTFontGetPlatformFont (ct_font, NULL); + status = ATSFontGetFileReference (atsFont, &fsref); + if (status == noErr) + original_url = CFURLCreateFromFSRef (NULL, &fsref); +#else + original_url = (CFURLRef) CTFontCopyAttribute (ct_font, kCTFontURLAttribute); +#endif + + /* Create font copy with cascade list that has LastResort first; this speeds up CoreText + * font fallback which we don't need anyway. */ + { + CTFontDescriptorRef last_resort_font_desc = get_last_resort_font_desc (); + CTFontRef new_ct_font = CTFontCreateCopyWithAttributes (ct_font, 0.0, nullptr, last_resort_font_desc); + CFRelease (last_resort_font_desc); + if (new_ct_font) + { + /* The CTFontCreateCopyWithAttributes call fails to stay on the same font + * when reconfiguring the cascade list and may switch to a different font + * when there are fonts that go by the same name, since the descriptor is + * just name and size. + * + * Avoid reconfiguring the cascade lists if the new font is outside the + * system locations that we cannot access from the sandboxed renderer + * process in Blink. This can be detected by the new file URL location + * that the newly found font points to. */ + CFURLRef new_url = nullptr; +#if !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) && MAC_OS_X_VERSION_MIN_REQUIRED < 1060 + atsFont = CTFontGetPlatformFont (new_ct_font, NULL); + status = ATSFontGetFileReference (atsFont, &fsref); + if (status == noErr) + new_url = CFURLCreateFromFSRef (NULL, &fsref); +#else + new_url = (CFURLRef) CTFontCopyAttribute (new_ct_font, kCTFontURLAttribute); +#endif + // Keep reconfigured font if URL cannot be retrieved (seems to be the case + // on Mac OS 10.12 Sierra), speculative fix for crbug.com/625606 + if (!original_url || !new_url || CFEqual (original_url, new_url)) { + CFRelease (ct_font); + ct_font = new_ct_font; + } else { + CFRelease (new_ct_font); + DEBUG_MSG (CORETEXT, ct_font, "Discarding reconfigured CTFont, location changed."); + } + if (new_url) + CFRelease (new_url); + } + else + DEBUG_MSG (CORETEXT, ct_font, "Font copy with empty cascade list failed"); + } + + if (original_url) + CFRelease (original_url); + return ct_font; +} + +/** + * hb_coretext_face_create: + * @cg_font: The CGFontRef to work upon + * + * Creates an #hb_face_t face object from the specified + * CGFontRef. + * + * Return value: (transfer full): The new face object + * + * Since: 0.9.10 + */ +hb_face_t * +hb_coretext_face_create (CGFontRef cg_font) +{ + hb_face_t *face = hb_face_create_for_tables (_hb_cg_reference_table, CGFontRetain (cg_font), _hb_cg_font_release); + hb_face_set_get_table_tags_func (face, _hb_cg_get_table_tags, cg_font, nullptr); + return face; +} + +/** + * hb_coretext_face_create_from_file_or_fail: + * @file_name: A font filename + * @index: The index of the face within the file + * + * Creates an #hb_face_t face object from the specified + * font file and face index. + * + * This is similar in functionality to hb_face_create_from_file_or_fail(), + * but uses the CoreText library for loading the font file. + * + * Return value: (transfer full): The new face object, or `NULL` if + * no face is found at the specified index or the file cannot be read. + * + * Since: 10.1.0 + */ +hb_face_t * +hb_coretext_face_create_from_file_or_fail (const char *file_name, + unsigned int index) +{ + auto url = CFURLCreateFromFileSystemRepresentation (nullptr, + (const UInt8 *) file_name, + strlen (file_name), + false); + if (unlikely (!url)) + return nullptr; + + auto ct_font_desc_array = CTFontManagerCreateFontDescriptorsFromURL (url); + if (unlikely (!ct_font_desc_array)) + { + CFRelease (url); + return nullptr; + } + + auto cg_font = create_cg_font (ct_font_desc_array, index); + CFRelease (url); + + hb_face_t *face = hb_coretext_face_create (cg_font); + CFRelease (cg_font); + if (unlikely (hb_face_is_immutable (face))) + return nullptr; + + return face; +} + +/** + * hb_coretext_face_create_from_blob_or_fail: + * @blob: A blob containing the font data + * @index: The index of the face within the blob + * + * Creates an #hb_face_t face object from the specified + * blob and face index. + * + * This is similar in functionality to hb_face_create_from_blob_or_fail(), + * but uses the CoreText library for loading the font data. + * + * Return value: (transfer full): The new face object, or `NULL` if + * no face is found at the specified index or the blob cannot be read. + * + * XSince: REPLACEME + */ +hb_face_t * +hb_coretext_face_create_from_blob_or_fail (hb_blob_t *blob, + unsigned int index) +{ + auto cg_font = create_cg_font (blob, index); + if (unlikely (!cg_font)) + return nullptr; + + hb_face_t *face = hb_coretext_face_create (cg_font); + CFRelease (cg_font); + if (unlikely (hb_face_is_immutable (face))) + return nullptr; + + return face; +} + +/** + * hb_coretext_face_get_cg_font: + * @face: The #hb_face_t to work upon + * + * Fetches the CGFontRef associated with an #hb_face_t + * face object + * + * Return value: the CGFontRef found + * + * Since: 0.9.10 + */ +CGFontRef +hb_coretext_face_get_cg_font (hb_face_t *face) +{ + return (CGFontRef) (const void *) face->data.coretext; +} + +#endif diff --git a/src/hb-coretext.hh b/src/hb-coretext.hh new file mode 100644 index 000000000..a58cf6c06 --- /dev/null +++ b/src/hb-coretext.hh @@ -0,0 +1,53 @@ +/* + * Copyright © 2012,2013 Mozilla Foundation. + * Copyright © 2012,2013 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Mozilla Author(s): Jonathan Kew + * Google Author(s): Behdad Esfahbod + */ + + +#ifndef HB_CORETEXT_HH +#define HB_CORETEXT_HH + +#include "hb.hh" + +#include "hb-coretext.h" + +#include "hb-aat-layout.hh" + + +HB_INTERNAL CGFontRef +create_cg_font (CFArrayRef ct_font_desc_array, unsigned int index); + +HB_INTERNAL CGFontRef +create_cg_font (hb_blob_t *blob, unsigned int index); + +HB_INTERNAL CGFontRef +create_cg_font (hb_face_t *face); + +HB_INTERNAL CTFontRef +create_ct_font (CGFontRef cg_font, CGFloat font_size); + + +#endif /* HB_OT_LAYOUT_HH */ diff --git a/src/meson.build b/src/meson.build index a2d23b1e2..d4262be10 100644 --- a/src/meson.build +++ b/src/meson.build @@ -350,7 +350,7 @@ hb_wasm_headers = files() # System-dependent sources and headers -hb_coretext_sources = files('hb-coretext-shape.cc', 'hb-coretext-font.cc') +hb_coretext_sources = files('hb-coretext.cc', 'hb-coretext-shape.cc', 'hb-coretext-font.cc') hb_coretext_headers = files('hb-coretext.h') hb_directwrite_sources = files('hb-directwrite.cc') From 5bf81c37580a46052dad58db730d7840d55c17c8 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 11 Mar 2025 22:46:16 -0600 Subject: [PATCH 36/40] [common] Make hb_malloc() et al public New API: +hb_malloc() +hb_calloc() +hb_realloc() +hb_free() --- docs/harfbuzz-sections.txt | 4 +++ src/fontations/lib.rs | 9 +------ src/hb-common.cc | 52 ++++++++++++++++++++++++++++++++++++++ src/hb-common.h | 11 ++++++++ src/hb-static.cc | 6 +---- src/hb.hh | 4 --- 6 files changed, 69 insertions(+), 17 deletions(-) diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index f09c85128..c90853678 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -184,6 +184,10 @@ uint8_t HB_EXTERN HB_DEPRECATED HB_DEPRECATED_FOR +hb_malloc +hb_calloc +hb_realloc +hb_free HB_H_IN HB_OT_H_IN diff --git a/src/fontations/lib.rs b/src/fontations/lib.rs index 38c0eb2d8..e3b4c240f 100644 --- a/src/fontations/lib.rs +++ b/src/fontations/lib.rs @@ -24,13 +24,6 @@ use skrifa::outline::DrawSettings; use skrifa::OutlineGlyphCollection; use skrifa::{GlyphId, MetadataProvider}; -extern "C" { - pub fn hb_malloc(_: usize) -> *const ::std::os::raw::c_void; - pub fn hb_calloc(_: usize, _: usize) -> *const ::std::os::raw::c_void; - pub fn hb_realloc(_: *const ::std::os::raw::c_void, _: usize) -> *const ::std::os::raw::c_void; - pub fn hb_free(_: *const ::std::os::raw::c_void); -} - struct MyAllocator; unsafe impl GlobalAlloc for MyAllocator { @@ -43,7 +36,7 @@ unsafe impl GlobalAlloc for MyAllocator { } unsafe fn realloc(&self, ptr: *mut u8, _layout: Layout, new_size: usize) -> *mut u8 { - hb_realloc(ptr as *const c_void, new_size) as *mut u8 + hb_realloc(ptr as *mut c_void, new_size) as *mut u8 } unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) { diff --git a/src/hb-common.cc b/src/hb-common.cc index d3355c971..3344a1bcf 100644 --- a/src/hb-common.cc +++ b/src/hb-common.cc @@ -1217,6 +1217,58 @@ uint8_t return hb_color_get_blue (color); } +/** + * hb_malloc: + * @size: The size of the memory to allocate. + * + * Allocates @size bytes of memory, using the allocator set at + * compile-time. Typically just malloc(). + * + * Return value: A pointer to the allocated memory. + * + * XSince: REPLACEME + **/ +void* hb_malloc(size_t size) { return hb_malloc_impl (size); } + +/** + * hb_calloc: + * @nmemb: The number of elements to allocate. + * @size: The size of each element. + * + * Allocates @nmemb elements of @size bytes each, initialized to zero, + * using the allocator set at compile-time. Typically just calloc(). + * + * Return value: A pointer to the allocated memory. + * + * XSince: REPLACEME + **/ +void* hb_calloc(size_t nmemb, size_t size) { return hb_calloc_impl (nmemb, size); } + +/** + * hb_realloc: + * @ptr: The pointer to the memory to reallocate. + * @size: The new size of the memory. + * + * Reallocates the memory pointed to by @ptr to @size bytes, using the + * allocator set at compile-time. Typically just realloc(). + * + * Return value: A pointer to the reallocated memory. + * + * XSince: REPLACEME + **/ +void* hb_realloc(void *ptr, size_t size) { return hb_realloc_impl (ptr, size); } + +/** + * hb_free: + * @ptr: The pointer to the memory to free. + * + * Frees the memory pointed to by @ptr, using the allocator set at + * compile-time. Typically just free(). + * + * XSince: REPLACEME + **/ +void hb_free(void *ptr) { hb_free_impl (ptr); } + /* If there is no visibility control, then hb-static.cc will NOT * define anything. Instead, we get it to define one set in here diff --git a/src/hb-common.h b/src/hb-common.h index 110854548..1d7b824b6 100644 --- a/src/hb-common.h +++ b/src/hb-common.h @@ -65,6 +65,7 @@ typedef unsigned __int64 uint64_t; #else # include #endif +#include #if defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) #define HB_DEPRECATED __attribute__((__deprecated__)) @@ -948,6 +949,16 @@ typedef struct hb_glyph_extents_t { */ typedef struct hb_font_t hb_font_t; +/* Not of much use to clients. */ +HB_EXTERN void* +hb_malloc (size_t size); +HB_EXTERN void* +hb_calloc (size_t nmemb, size_t size); +HB_EXTERN void* +hb_realloc (void *ptr, size_t size); +HB_EXTERN void +hb_free (void *ptr); + HB_END_DECLS #endif /* HB_COMMON_H */ diff --git a/src/hb-static.cc b/src/hb-static.cc index 634299778..e328bc48a 100644 --- a/src/hb-static.cc +++ b/src/hb-static.cc @@ -40,12 +40,8 @@ #include "hb-ot-hmtx-table.hh" #include "hb-ot-maxp-table.hh" -void* hb_malloc(size_t size) { return hb_malloc_impl (size); } -void* hb_calloc(size_t nmemb, size_t size) { return hb_calloc_impl (nmemb, size); } -void* hb_realloc(void *ptr, size_t size) { return hb_realloc_impl (ptr, size); } -void hb_free(void *ptr) { hb_free_impl (ptr); } - #ifndef HB_NO_VISIBILITY + #include "hb-ot-name-language-static.hh" uint64_t const _hb_NullPool[(HB_NULL_POOL_SIZE + sizeof (uint64_t) - 1) / sizeof (uint64_t)] = {}; diff --git a/src/hb.hh b/src/hb.hh index e245ad288..ffbfef099 100644 --- a/src/hb.hh +++ b/src/hb.hh @@ -533,10 +533,6 @@ extern "C" void hb_free_impl(void *ptr); #define hb_realloc_impl realloc #define hb_free_impl free #endif -extern "C" void* hb_malloc(size_t size); -extern "C" void* hb_calloc(size_t nmemb, size_t size); -extern "C" void* hb_realloc(void *ptr, size_t size); -extern "C" void hb_free(void *ptr); From 05cfdb91058ffb919a460bcf35044ecd7b299c3d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 12 Mar 2025 00:08:42 -0600 Subject: [PATCH 37/40] [fontations] link_with instead of link_whole Now that the hb-fontations symbol is called from libharfbuzz, it gets pulled in properly. --- src/fontations/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fontations/meson.build b/src/fontations/meson.build index d21b9af4c..7f26f3570 100644 --- a/src/fontations/meson.build +++ b/src/fontations/meson.build @@ -50,7 +50,7 @@ harfbuzz_fontations = custom_target( ) harfbuzz_fontations_dep = declare_dependency( - link_whole: harfbuzz_fontations, + link_with: harfbuzz_fontations, ) clippy_fix = run_target( From 8d300049f5ccf58b7d7e82b77563e522663ebb6d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 12 Mar 2025 00:43:10 -0600 Subject: [PATCH 38/40] [fontations] Assert layout alignment --- src/fontations/lib.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/fontations/lib.rs b/src/fontations/lib.rs index e3b4c240f..9753a0e5f 100644 --- a/src/fontations/lib.rs +++ b/src/fontations/lib.rs @@ -28,18 +28,22 @@ struct MyAllocator; unsafe impl GlobalAlloc for MyAllocator { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { + assert!(layout.align() <= 16); hb_malloc(layout.size()) as *mut u8 } unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { + assert!(layout.align() <= 16); hb_calloc(layout.size(), 1) as *mut u8 } - unsafe fn realloc(&self, ptr: *mut u8, _layout: Layout, new_size: usize) -> *mut u8 { + unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { + assert!(layout.align() <= 16); hb_realloc(ptr as *mut c_void, new_size) as *mut u8 } - unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) { + unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { + assert!(layout.align() <= 16); hb_free(ptr as *mut c_void); } } From fbb81e344b3ddba349d1e2cefa2ff42515aef51d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 12 Mar 2025 00:52:12 -0600 Subject: [PATCH 39/40] [fontations] Adjust alignment requirement --- src/fontations/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/fontations/lib.rs b/src/fontations/lib.rs index 9753a0e5f..06025d931 100644 --- a/src/fontations/lib.rs +++ b/src/fontations/lib.rs @@ -28,22 +28,22 @@ struct MyAllocator; unsafe impl GlobalAlloc for MyAllocator { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - assert!(layout.align() <= 16); + assert!(layout.align() <= 2 * std::mem::size_of::<*mut u8>()); hb_malloc(layout.size()) as *mut u8 } unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { - assert!(layout.align() <= 16); + assert!(layout.align() <= 2 * std::mem::size_of::<*mut u8>()); hb_calloc(layout.size(), 1) as *mut u8 } unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { - assert!(layout.align() <= 16); + assert!(layout.align() <= 2 * std::mem::size_of::<*mut u8>()); hb_realloc(ptr as *mut c_void, new_size) as *mut u8 } unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { - assert!(layout.align() <= 16); + assert!(layout.align() <= 2 * std::mem::size_of::<*mut u8>()); hb_free(ptr as *mut c_void); } } From 469502c99bf976c3a47660d1f0adba64bb1f14e0 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 12 Mar 2025 11:02:43 -0600 Subject: [PATCH 40/40] [test-paint] Test fontations too Luckily it passes! --- test/api/test-paint.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/test/api/test-paint.c b/test/api/test-paint.c index 5752359c5..77d283441 100644 --- a/test/api/test-paint.c +++ b/test/api/test-paint.c @@ -467,7 +467,7 @@ test_hb_paint (gconstpointer d, } static void -test_compare_ot_ft (const char *file, hb_codepoint_t glyph) +test_compare_to_ot (const char *file, hb_codepoint_t glyph) { hb_face_t *face; hb_font_t *font; @@ -525,21 +525,15 @@ test_hb_paint_ft (gconstpointer data) } static void -test_compare_ot_ft_novf (gconstpointer d) +test_compare_to_ot_novf (gconstpointer d) { - if (have_ft_colrv1 ()) - test_compare_ot_ft (TEST_GLYPHS, GPOINTER_TO_UINT (d)); - else - g_test_skip ("FreeType COLRv1 support not present"); + test_compare_to_ot (TEST_GLYPHS, GPOINTER_TO_UINT (d)); } static void -test_compare_ot_ft_vf (gconstpointer d) +test_compare_to_ot_vf (gconstpointer d) { - if (have_ft_colrv1 ()) - test_compare_ot_ft (TEST_GLYPHS_VF, GPOINTER_TO_UINT (d)); - else - g_test_skip ("FreeType COLRv1 support not present"); + test_compare_to_ot (TEST_GLYPHS_VF, GPOINTER_TO_UINT (d)); } static void @@ -650,12 +644,20 @@ main (int argc, char **argv) hb_face_t *face = hb_test_open_font_file (TEST_GLYPHS); unsigned glyph_count = hb_face_get_glyph_count (face); - for (unsigned int i = 1; i < glyph_count; i++) + const char **font_funcs = hb_font_list_funcs (); + for (const char **font_func = font_funcs; *font_func; font_func++) { - char buf[20]; - snprintf (buf, 20, "test-%u", i); - hb_test_add_data_flavor (GUINT_TO_POINTER (i), buf, test_compare_ot_ft_novf); - hb_test_add_data_flavor (GUINT_TO_POINTER (i), buf, test_compare_ot_ft_vf); + if (strcmp (*font_func, "ot") == 0) + continue; + if (!have_ft_colrv1 () && strcmp (*font_func, "ft") == 0) + continue; + for (unsigned int i = 1; i < glyph_count; i++) + { + char buf[32]; + snprintf (buf, 32, "test-%s-%u", *font_func, i); + hb_test_add_data_flavor (GUINT_TO_POINTER (i), buf, test_compare_to_ot_novf); + hb_test_add_data_flavor (GUINT_TO_POINTER (i), buf, test_compare_to_ot_vf); + } } hb_face_destroy (face);