harfbuzz-ruby 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +12 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +258 -0
  5. data/Rakefile +8 -0
  6. data/benchmark/shaping_bench.rb +77 -0
  7. data/examples/basic_shaping.rb +67 -0
  8. data/examples/glyph_outlines.rb +79 -0
  9. data/examples/opentype_features.rb +91 -0
  10. data/examples/render_svg.rb +112 -0
  11. data/examples/render_waterfall.rb +177 -0
  12. data/examples/variable_fonts.rb +73 -0
  13. data/lib/harfbuzz/aat/layout.rb +78 -0
  14. data/lib/harfbuzz/blob.rb +136 -0
  15. data/lib/harfbuzz/buffer.rb +497 -0
  16. data/lib/harfbuzz/c/aat/layout.rb +15 -0
  17. data/lib/harfbuzz/c/base.rb +114 -0
  18. data/lib/harfbuzz/c/blob.rb +23 -0
  19. data/lib/harfbuzz/c/buffer.rb +127 -0
  20. data/lib/harfbuzz/c/common.rb +39 -0
  21. data/lib/harfbuzz/c/draw.rb +22 -0
  22. data/lib/harfbuzz/c/enums.rb +146 -0
  23. data/lib/harfbuzz/c/face.rb +37 -0
  24. data/lib/harfbuzz/c/font.rb +88 -0
  25. data/lib/harfbuzz/c/font_funcs.rb +58 -0
  26. data/lib/harfbuzz/c/map.rb +28 -0
  27. data/lib/harfbuzz/c/ot/color.rb +32 -0
  28. data/lib/harfbuzz/c/ot/font.rb +7 -0
  29. data/lib/harfbuzz/c/ot/layout.rb +83 -0
  30. data/lib/harfbuzz/c/ot/math.rb +23 -0
  31. data/lib/harfbuzz/c/ot/meta.rb +10 -0
  32. data/lib/harfbuzz/c/ot/metrics.rb +16 -0
  33. data/lib/harfbuzz/c/ot/name.rb +13 -0
  34. data/lib/harfbuzz/c/ot/shape.rb +10 -0
  35. data/lib/harfbuzz/c/ot/var.rb +22 -0
  36. data/lib/harfbuzz/c/paint.rb +38 -0
  37. data/lib/harfbuzz/c/set.rb +42 -0
  38. data/lib/harfbuzz/c/shape.rb +11 -0
  39. data/lib/harfbuzz/c/shape_plan.rb +24 -0
  40. data/lib/harfbuzz/c/structs.rb +120 -0
  41. data/lib/harfbuzz/c/subset.rb +49 -0
  42. data/lib/harfbuzz/c/unicode.rb +40 -0
  43. data/lib/harfbuzz/c/version.rb +25 -0
  44. data/lib/harfbuzz/draw_funcs.rb +112 -0
  45. data/lib/harfbuzz/error.rb +27 -0
  46. data/lib/harfbuzz/face.rb +186 -0
  47. data/lib/harfbuzz/feature.rb +76 -0
  48. data/lib/harfbuzz/flags.rb +85 -0
  49. data/lib/harfbuzz/font.rb +404 -0
  50. data/lib/harfbuzz/font_funcs.rb +286 -0
  51. data/lib/harfbuzz/glyph_info.rb +35 -0
  52. data/lib/harfbuzz/glyph_position.rb +41 -0
  53. data/lib/harfbuzz/library.rb +98 -0
  54. data/lib/harfbuzz/map.rb +157 -0
  55. data/lib/harfbuzz/ot/color.rb +125 -0
  56. data/lib/harfbuzz/ot/font.rb +16 -0
  57. data/lib/harfbuzz/ot/layout.rb +583 -0
  58. data/lib/harfbuzz/ot/math.rb +111 -0
  59. data/lib/harfbuzz/ot/meta.rb +34 -0
  60. data/lib/harfbuzz/ot/metrics.rb +54 -0
  61. data/lib/harfbuzz/ot/name.rb +81 -0
  62. data/lib/harfbuzz/ot/shape.rb +34 -0
  63. data/lib/harfbuzz/ot/var.rb +116 -0
  64. data/lib/harfbuzz/paint_funcs.rb +134 -0
  65. data/lib/harfbuzz/set.rb +272 -0
  66. data/lib/harfbuzz/shape_plan.rb +115 -0
  67. data/lib/harfbuzz/shaping_result.rb +94 -0
  68. data/lib/harfbuzz/subset.rb +130 -0
  69. data/lib/harfbuzz/unicode_funcs.rb +201 -0
  70. data/lib/harfbuzz/variation.rb +49 -0
  71. data/lib/harfbuzz/version.rb +5 -0
  72. data/lib/harfbuzz-ffi.rb +4 -0
  73. data/lib/harfbuzz.rb +313 -0
  74. data/sig/harfbuzz.rbs +594 -0
  75. metadata +132 -0
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HarfBuzz
4
+ module C
5
+ attach_function :hb_ot_math_has_data, [:hb_face_t], :hb_bool_t
6
+ attach_function :hb_ot_math_get_constant, [:hb_font_t, :uint], :hb_position_t
7
+ attach_function :hb_ot_math_get_glyph_italics_correction,
8
+ [:hb_font_t, :hb_codepoint_t], :hb_position_t
9
+ attach_function :hb_ot_math_get_glyph_top_accent_attachment,
10
+ [:hb_font_t, :hb_codepoint_t], :hb_position_t
11
+ attach_function :hb_ot_math_is_glyph_extended_shape,
12
+ [:hb_face_t, :hb_codepoint_t], :hb_bool_t
13
+ attach_function :hb_ot_math_get_glyph_kerning,
14
+ [:hb_font_t, :hb_codepoint_t, :uint, :hb_position_t], :hb_position_t
15
+ attach_function :hb_ot_math_get_glyph_variants,
16
+ [:hb_font_t, :hb_codepoint_t, :hb_direction_t, :uint, :pointer, :pointer], :uint
17
+ attach_function :hb_ot_math_get_glyph_assembly,
18
+ [:hb_font_t, :hb_codepoint_t, :hb_direction_t,
19
+ :uint, :pointer, :pointer, :pointer], :uint
20
+ attach_function :hb_ot_math_get_min_connector_overlap,
21
+ [:hb_font_t, :hb_direction_t], :hb_position_t
22
+ end
23
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HarfBuzz
4
+ module C
5
+ attach_function :hb_ot_meta_get_entry_tags,
6
+ [:hb_face_t, :uint, :pointer, :pointer], :uint
7
+ attach_function :hb_ot_meta_reference_entry,
8
+ [:hb_face_t, :hb_ot_meta_tag_t], :hb_blob_t
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HarfBuzz
4
+ module C
5
+ attach_function :hb_ot_metrics_get_position,
6
+ [:hb_font_t, :uint, :pointer], :hb_bool_t
7
+ attach_function :hb_ot_metrics_get_position_with_fallback,
8
+ [:hb_font_t, :uint, :pointer], :void
9
+ attach_function :hb_ot_metrics_get_variation,
10
+ [:hb_font_t, :uint], :float
11
+ attach_function :hb_ot_metrics_get_x_variation,
12
+ [:hb_font_t, :uint], :hb_position_t
13
+ attach_function :hb_ot_metrics_get_y_variation,
14
+ [:hb_font_t, :uint], :hb_position_t
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HarfBuzz
4
+ module C
5
+ attach_function :hb_ot_name_list_names, [:hb_face_t, :pointer], :pointer
6
+ attach_function :hb_ot_name_get_utf8,
7
+ [:hb_face_t, :hb_ot_name_id_t, :pointer, :pointer, :pointer], :uint
8
+ attach_function :hb_ot_name_get_utf16,
9
+ [:hb_face_t, :hb_ot_name_id_t, :pointer, :pointer, :pointer], :uint
10
+ attach_function :hb_ot_name_get_utf32,
11
+ [:hb_face_t, :hb_ot_name_id_t, :pointer, :pointer, :pointer], :uint
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HarfBuzz
4
+ module C
5
+ attach_function :hb_ot_shape_glyphs_closure,
6
+ [:hb_font_t, :hb_buffer_t, :pointer, :uint, :hb_set_t], :void
7
+ attach_function :hb_ot_shape_plan_collect_lookups,
8
+ [:hb_shape_plan_t, :hb_tag_t, :hb_set_t], :void
9
+ end
10
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HarfBuzz
4
+ module C
5
+ attach_function :hb_ot_var_has_data, [:hb_face_t], :hb_bool_t
6
+ attach_function :hb_ot_var_get_axis_count, [:hb_face_t], :uint
7
+ attach_function :hb_ot_var_get_axis_infos, [:hb_face_t, :uint, :pointer, :pointer], :uint
8
+ attach_function :hb_ot_var_find_axis_info,
9
+ [:hb_face_t, :hb_tag_t, :pointer], :hb_bool_t
10
+ attach_function :hb_ot_var_get_named_instance_count, [:hb_face_t], :uint
11
+ attach_function :hb_ot_var_named_instance_get_subfamily_name_id,
12
+ [:hb_face_t, :uint], :hb_ot_name_id_t
13
+ attach_function :hb_ot_var_named_instance_get_postscript_name_id,
14
+ [:hb_face_t, :uint], :hb_ot_name_id_t
15
+ attach_function :hb_ot_var_named_instance_get_design_coords,
16
+ [:hb_face_t, :uint, :pointer, :pointer], :uint
17
+ attach_function :hb_ot_var_normalize_variations,
18
+ [:hb_face_t, :pointer, :uint, :pointer, :uint], :void
19
+ attach_function :hb_ot_var_normalize_coords,
20
+ [:hb_face_t, :uint, :pointer, :pointer], :void
21
+ end
22
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HarfBuzz
4
+ module C
5
+ attach_function :hb_paint_funcs_create, [], :hb_paint_funcs_t
6
+ attach_function :hb_paint_funcs_destroy, [:hb_paint_funcs_t], :void
7
+ attach_function :hb_paint_funcs_reference, [:hb_paint_funcs_t], :hb_paint_funcs_t
8
+ attach_function :hb_paint_funcs_is_immutable, [:hb_paint_funcs_t], :hb_bool_t
9
+ attach_function :hb_paint_funcs_make_immutable, [:hb_paint_funcs_t], :void
10
+
11
+ attach_function :hb_paint_funcs_set_push_transform_func,
12
+ [:hb_paint_funcs_t, :pointer, :pointer, :pointer], :void
13
+ attach_function :hb_paint_funcs_set_pop_transform_func,
14
+ [:hb_paint_funcs_t, :pointer, :pointer, :pointer], :void
15
+ attach_function :hb_paint_funcs_set_push_clip_glyph_func,
16
+ [:hb_paint_funcs_t, :pointer, :pointer, :pointer], :void
17
+ attach_function :hb_paint_funcs_set_push_clip_rectangle_func,
18
+ [:hb_paint_funcs_t, :pointer, :pointer, :pointer], :void
19
+ attach_function :hb_paint_funcs_set_pop_clip_func,
20
+ [:hb_paint_funcs_t, :pointer, :pointer, :pointer], :void
21
+ attach_function :hb_paint_funcs_set_color_func,
22
+ [:hb_paint_funcs_t, :pointer, :pointer, :pointer], :void
23
+ attach_function :hb_paint_funcs_set_linear_gradient_func,
24
+ [:hb_paint_funcs_t, :pointer, :pointer, :pointer], :void
25
+ attach_function :hb_paint_funcs_set_radial_gradient_func,
26
+ [:hb_paint_funcs_t, :pointer, :pointer, :pointer], :void
27
+ attach_function :hb_paint_funcs_set_sweep_gradient_func,
28
+ [:hb_paint_funcs_t, :pointer, :pointer, :pointer], :void
29
+ attach_function :hb_paint_funcs_set_push_group_func,
30
+ [:hb_paint_funcs_t, :pointer, :pointer, :pointer], :void
31
+ attach_function :hb_paint_funcs_set_pop_group_func,
32
+ [:hb_paint_funcs_t, :pointer, :pointer, :pointer], :void
33
+ attach_function :hb_paint_funcs_set_image_func,
34
+ [:hb_paint_funcs_t, :pointer, :pointer, :pointer], :void
35
+ attach_function :hb_paint_funcs_set_custom_palette_color_func,
36
+ [:hb_paint_funcs_t, :pointer, :pointer, :pointer], :void
37
+ end
38
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HarfBuzz
4
+ module C
5
+ HB_SET_VALUE_INVALID = 0xFFFFFFFF
6
+
7
+ attach_function :hb_set_create, [], :hb_set_t
8
+ attach_function :hb_set_destroy, [:hb_set_t], :void
9
+ attach_function :hb_set_reference, [:hb_set_t], :hb_set_t
10
+ attach_function :hb_set_get_empty, [], :hb_set_t
11
+ attach_function :hb_set_clear, [:hb_set_t], :void
12
+ attach_function :hb_set_is_empty, [:hb_set_t], :hb_bool_t
13
+ attach_function :hb_set_get_population, [:hb_set_t], :uint
14
+ attach_function :hb_set_has, [:hb_set_t, :hb_codepoint_t], :hb_bool_t
15
+ attach_function :hb_set_add, [:hb_set_t, :hb_codepoint_t], :void
16
+ attach_function :hb_set_add_range, [:hb_set_t, :hb_codepoint_t, :hb_codepoint_t], :void
17
+ attach_function :hb_set_add_sorted_array,
18
+ [:hb_set_t, :pointer, :uint], :void
19
+ attach_function :hb_set_del, [:hb_set_t, :hb_codepoint_t], :void
20
+ attach_function :hb_set_del_range, [:hb_set_t, :hb_codepoint_t, :hb_codepoint_t], :void
21
+ attach_function :hb_set_is_equal, [:hb_set_t, :hb_set_t], :hb_bool_t
22
+ attach_function :hb_set_hash, [:hb_set_t], :uint
23
+ attach_function :hb_set_is_subset, [:hb_set_t, :hb_set_t], :hb_bool_t
24
+ attach_function :hb_set_set, [:hb_set_t, :hb_set_t], :void
25
+ attach_function :hb_set_union, [:hb_set_t, :hb_set_t], :void
26
+ attach_function :hb_set_intersect, [:hb_set_t, :hb_set_t], :void
27
+ attach_function :hb_set_subtract, [:hb_set_t, :hb_set_t], :void
28
+ attach_function :hb_set_symmetric_difference, [:hb_set_t, :hb_set_t], :void
29
+ attach_function :hb_set_invert, [:hb_set_t], :void
30
+ attach_function :hb_set_get_min, [:hb_set_t], :hb_codepoint_t
31
+ attach_function :hb_set_get_max, [:hb_set_t], :hb_codepoint_t
32
+ attach_function :hb_set_next, [:hb_set_t, :pointer], :hb_bool_t
33
+ attach_function :hb_set_previous, [:hb_set_t, :pointer], :hb_bool_t
34
+ attach_function :hb_set_next_range, [:hb_set_t, :pointer, :pointer], :hb_bool_t
35
+ attach_function :hb_set_previous_range, [:hb_set_t, :pointer, :pointer], :hb_bool_t
36
+ attach_function :hb_set_next_many, [:hb_set_t, :hb_codepoint_t, :pointer, :uint], :uint
37
+
38
+ attach_function :hb_set_set_user_data,
39
+ [:hb_set_t, :pointer, :pointer, :pointer, :hb_bool_t], :hb_bool_t
40
+ attach_function :hb_set_get_user_data, [:hb_set_t, :pointer], :pointer
41
+ end
42
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HarfBuzz
4
+ module C
5
+ attach_function :hb_shape,
6
+ [:hb_font_t, :hb_buffer_t, :pointer, :uint], :void
7
+ attach_function :hb_shape_full,
8
+ [:hb_font_t, :hb_buffer_t, :pointer, :uint, :pointer], :hb_bool_t
9
+ attach_function :hb_shape_list_shapers, [], :pointer
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HarfBuzz
4
+ module C
5
+ attach_function :hb_shape_plan_create,
6
+ [:hb_face_t, :pointer, :pointer, :uint, :pointer], :hb_shape_plan_t
7
+ attach_function :hb_shape_plan_create_cached,
8
+ [:hb_face_t, :pointer, :pointer, :uint, :pointer], :hb_shape_plan_t
9
+ attach_function :hb_shape_plan_create2,
10
+ [:hb_face_t, :pointer, :pointer, :uint, :pointer, :uint, :pointer], :hb_shape_plan_t
11
+ attach_function :hb_shape_plan_create_cached2,
12
+ [:hb_face_t, :pointer, :pointer, :uint, :pointer, :uint, :pointer], :hb_shape_plan_t
13
+ attach_function :hb_shape_plan_destroy, [:hb_shape_plan_t], :void
14
+ attach_function :hb_shape_plan_reference, [:hb_shape_plan_t], :hb_shape_plan_t
15
+ attach_function :hb_shape_plan_execute,
16
+ [:hb_shape_plan_t, :hb_font_t, :hb_buffer_t, :pointer, :uint], :hb_bool_t
17
+ attach_function :hb_shape_plan_get_shaper, [:hb_shape_plan_t], :string
18
+ attach_function :hb_shape_plan_get_empty, [], :hb_shape_plan_t
19
+
20
+ attach_function :hb_shape_plan_set_user_data,
21
+ [:hb_shape_plan_t, :pointer, :pointer, :pointer, :hb_bool_t], :hb_bool_t
22
+ attach_function :hb_shape_plan_get_user_data, [:hb_shape_plan_t, :pointer], :pointer
23
+ end
24
+ end
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HarfBuzz
4
+ module C
5
+ class HbGlyphInfoT < FFI::Struct
6
+ layout :codepoint, :hb_codepoint_t,
7
+ :mask, :hb_mask_t,
8
+ :cluster, :uint32,
9
+ :var1, :uint32,
10
+ :var2, :uint32
11
+ end
12
+
13
+ class HbGlyphPositionT < FFI::Struct
14
+ layout :x_advance, :hb_position_t,
15
+ :y_advance, :hb_position_t,
16
+ :x_offset, :hb_position_t,
17
+ :y_offset, :hb_position_t,
18
+ :var, :uint32
19
+ end
20
+
21
+ class HbFeatureT < FFI::Struct
22
+ layout :tag, :hb_tag_t,
23
+ :value, :uint32,
24
+ :start, :uint,
25
+ :end, :uint
26
+ end
27
+
28
+ class HbVariationT < FFI::Struct
29
+ layout :tag, :hb_tag_t,
30
+ :value, :float
31
+ end
32
+
33
+ class HbSegmentPropertiesT < FFI::Struct
34
+ layout :direction, :int,
35
+ :script, :uint32,
36
+ :language, :pointer,
37
+ :reserved1, :pointer,
38
+ :reserved2, :pointer
39
+ end
40
+
41
+ class HbGlyphExtentsT < FFI::Struct
42
+ layout :x_bearing, :hb_position_t,
43
+ :y_bearing, :hb_position_t,
44
+ :width, :hb_position_t,
45
+ :height, :hb_position_t
46
+ end
47
+
48
+ class HbFontExtentsT < FFI::Struct
49
+ layout :ascender, :hb_position_t,
50
+ :descender, :hb_position_t,
51
+ :line_gap, :hb_position_t,
52
+ :reserved9, :hb_position_t,
53
+ :reserved8, :hb_position_t,
54
+ :reserved7, :hb_position_t,
55
+ :reserved6, :hb_position_t,
56
+ :reserved5, :hb_position_t,
57
+ :reserved4, :hb_position_t,
58
+ :reserved3, :hb_position_t,
59
+ :reserved2, :hb_position_t,
60
+ :reserved1, :hb_position_t
61
+ end
62
+
63
+ class HbOtVarAxisInfoT < FFI::Struct
64
+ layout :axis_index, :uint,
65
+ :tag, :hb_tag_t,
66
+ :name_id, :uint,
67
+ :flags, :uint,
68
+ :min_value, :float,
69
+ :default_value, :float,
70
+ :max_value, :float,
71
+ :reserved, :uint
72
+ end
73
+
74
+ class HbOtNameEntryT < FFI::Struct
75
+ layout :name_id, :uint,
76
+ :var, :uint32,
77
+ :language, :pointer
78
+ end
79
+
80
+ class HbOtMathGlyphVariantT < FFI::Struct
81
+ layout :glyph, :hb_codepoint_t,
82
+ :advance, :hb_position_t
83
+ end
84
+
85
+ class HbOtMathGlyphPartT < FFI::Struct
86
+ layout :glyph, :hb_codepoint_t,
87
+ :start_connector_length, :hb_position_t,
88
+ :end_connector_length, :hb_position_t,
89
+ :full_advance, :hb_position_t,
90
+ :flags, :uint
91
+ end
92
+
93
+ class HbOtColorLayerT < FFI::Struct
94
+ layout :glyph, :hb_codepoint_t,
95
+ :color_index, :uint
96
+ end
97
+
98
+ class HbAatLayoutFeatureSelectorInfoT < FFI::Struct
99
+ layout :name_id, :uint,
100
+ :enable, :uint,
101
+ :disable, :uint,
102
+ :reserved, :uint
103
+ end
104
+
105
+ class HbDrawStateT < FFI::Struct
106
+ layout :path_open, :hb_bool_t,
107
+ :path_start_x, :float,
108
+ :path_start_y, :float,
109
+ :current_x, :float,
110
+ :current_y, :float,
111
+ :reserved1, :uint32,
112
+ :reserved2, :uint32,
113
+ :reserved3, :uint32,
114
+ :reserved4, :uint32,
115
+ :reserved5, :uint32,
116
+ :reserved6, :uint32,
117
+ :reserved7, :uint32
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HarfBuzz
4
+ module Subset
5
+ # Subset C bindings loaded from libharfbuzz-subset
6
+ module C
7
+ extend FFI::Library
8
+
9
+ SUBSET_LIBRARY_NAMES = %w[
10
+ harfbuzz-subset libharfbuzz-subset libharfbuzz-subset-0
11
+ ].freeze
12
+
13
+ begin
14
+ ffi_lib SUBSET_LIBRARY_NAMES
15
+ @available = true
16
+ rescue FFI::NotFoundError
17
+ @available = false
18
+ end
19
+
20
+ def self.available?
21
+ @available
22
+ end
23
+
24
+ if @available
25
+ attach_function :hb_subset_input_create_or_fail, [], :pointer
26
+ attach_function :hb_subset_input_destroy, [:pointer], :void
27
+ attach_function :hb_subset_input_reference, [:pointer], :pointer
28
+ attach_function :hb_subset_input_unicode_set, [:pointer], HarfBuzz::C.find_type(:hb_set_t)
29
+ attach_function :hb_subset_input_glyph_set, [:pointer], HarfBuzz::C.find_type(:hb_set_t)
30
+ attach_function :hb_subset_input_set_flags, [:pointer, :uint32], :void
31
+ attach_function :hb_subset_input_get_flags, [:pointer], :uint32
32
+ attach_function :hb_subset_or_fail,
33
+ [HarfBuzz::C.find_type(:hb_face_t), :pointer], HarfBuzz::C.find_type(:hb_face_t)
34
+ attach_function :hb_subset_plan_create_or_fail,
35
+ [HarfBuzz::C.find_type(:hb_face_t), :pointer], :pointer
36
+ attach_function :hb_subset_plan_destroy, [:pointer], :void
37
+ attach_function :hb_subset_plan_reference, [:pointer], :pointer
38
+ attach_function :hb_subset_plan_execute_or_fail,
39
+ [:pointer], HarfBuzz::C.find_type(:hb_face_t)
40
+ attach_function :hb_subset_plan_old_to_new_glyph_mapping,
41
+ [:pointer], HarfBuzz::C.find_type(:hb_map_t)
42
+ attach_function :hb_subset_plan_new_to_old_glyph_mapping,
43
+ [:pointer], HarfBuzz::C.find_type(:hb_map_t)
44
+ attach_function :hb_subset_plan_unicode_to_old_glyph_mapping,
45
+ [:pointer], HarfBuzz::C.find_type(:hb_map_t)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HarfBuzz
4
+ module C
5
+ attach_function :hb_unicode_funcs_create, [:hb_unicode_funcs_t], :hb_unicode_funcs_t
6
+ attach_function :hb_unicode_funcs_get_default, [], :hb_unicode_funcs_t
7
+ attach_function :hb_unicode_funcs_get_empty, [], :hb_unicode_funcs_t
8
+ attach_function :hb_unicode_funcs_destroy, [:hb_unicode_funcs_t], :void
9
+ attach_function :hb_unicode_funcs_reference, [:hb_unicode_funcs_t], :hb_unicode_funcs_t
10
+ attach_function :hb_unicode_funcs_get_parent, [:hb_unicode_funcs_t], :hb_unicode_funcs_t
11
+ attach_function :hb_unicode_funcs_is_immutable, [:hb_unicode_funcs_t], :hb_bool_t
12
+ attach_function :hb_unicode_funcs_make_immutable, [:hb_unicode_funcs_t], :void
13
+
14
+ attach_function :hb_unicode_funcs_set_general_category_func,
15
+ [:hb_unicode_funcs_t, :pointer, :pointer, :pointer], :void
16
+ attach_function :hb_unicode_funcs_set_combining_class_func,
17
+ [:hb_unicode_funcs_t, :pointer, :pointer, :pointer], :void
18
+ attach_function :hb_unicode_funcs_set_mirroring_func,
19
+ [:hb_unicode_funcs_t, :pointer, :pointer, :pointer], :void
20
+ attach_function :hb_unicode_funcs_set_script_func,
21
+ [:hb_unicode_funcs_t, :pointer, :pointer, :pointer], :void
22
+ attach_function :hb_unicode_funcs_set_compose_func,
23
+ [:hb_unicode_funcs_t, :pointer, :pointer, :pointer], :void
24
+ attach_function :hb_unicode_funcs_set_decompose_func,
25
+ [:hb_unicode_funcs_t, :pointer, :pointer, :pointer], :void
26
+
27
+ attach_function :hb_unicode_general_category,
28
+ [:hb_unicode_funcs_t, :hb_codepoint_t], :hb_unicode_general_category_t
29
+ attach_function :hb_unicode_combining_class,
30
+ [:hb_unicode_funcs_t, :hb_codepoint_t], :uint
31
+ attach_function :hb_unicode_mirroring,
32
+ [:hb_unicode_funcs_t, :hb_codepoint_t], :hb_codepoint_t
33
+ attach_function :hb_unicode_script,
34
+ [:hb_unicode_funcs_t, :hb_codepoint_t], :uint32
35
+ attach_function :hb_unicode_compose,
36
+ [:hb_unicode_funcs_t, :hb_codepoint_t, :hb_codepoint_t, :pointer], :hb_bool_t
37
+ attach_function :hb_unicode_decompose,
38
+ [:hb_unicode_funcs_t, :hb_codepoint_t, :pointer, :pointer], :hb_bool_t
39
+ end
40
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HarfBuzz
4
+ module C
5
+ # === Version Functions ===
6
+
7
+ # Returns the HarfBuzz library version
8
+ # @param major [FFI::Pointer] Pointer to store major version
9
+ # @param minor [FFI::Pointer] Pointer to store minor version
10
+ # @param micro [FFI::Pointer] Pointer to store micro version
11
+ # @return [void]
12
+ attach_function :hb_version, [:pointer, :pointer, :pointer], :void
13
+
14
+ # Returns the HarfBuzz library version as a string
15
+ # @return [String] Version string (e.g., "8.3.0")
16
+ attach_function :hb_version_string, [], :string
17
+
18
+ # Checks if the library version is at least the specified version
19
+ # @param major [Integer] Major version
20
+ # @param minor [Integer] Minor version
21
+ # @param micro [Integer] Micro version
22
+ # @return [Integer] Non-zero if version >= specified, 0 otherwise
23
+ attach_function :hb_version_atleast, [:uint, :uint, :uint], :hb_bool_t
24
+ end
25
+ end
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HarfBuzz
4
+ # Wraps hb_draw_funcs_t — callbacks for glyph outline rendering
5
+ #
6
+ # @example Extracting an SVG path
7
+ # draw = HarfBuzz::DrawFuncs.new
8
+ # path = []
9
+ # draw.on_move_to { |x, y| path << "M#{x},#{y}" }
10
+ # draw.on_line_to { |x, y| path << "L#{x},#{y}" }
11
+ # draw.on_cubic_to { |c1x, c1y, c2x, c2y, x, y| path << "C#{c1x},#{c1y},#{c2x},#{c2y},#{x},#{y}" }
12
+ # draw.on_close_path { path << "Z" }
13
+ # draw.make_immutable!
14
+ # font.draw_glyph(glyph_id, draw)
15
+ class DrawFuncs
16
+ attr_reader :ptr
17
+
18
+ def initialize
19
+ @ptr = C.hb_draw_funcs_create
20
+ raise AllocationError, "Failed to create draw_funcs" if @ptr.null?
21
+
22
+ HarfBuzz::DrawFuncs.define_finalizer(self, @ptr)
23
+ end
24
+
25
+ # @return [Boolean] true if immutable
26
+ def immutable?
27
+ C.from_hb_bool(C.hb_draw_funcs_is_immutable(@ptr))
28
+ end
29
+
30
+ # Makes immutable (call after setting all callbacks)
31
+ # @return [self]
32
+ def make_immutable!
33
+ C.hb_draw_funcs_make_immutable(@ptr)
34
+ self
35
+ end
36
+
37
+ # Sets the move_to callback
38
+ # @yield [x, y] Called for move-to operations
39
+ def on_move_to(&block)
40
+ @move_to_callback = block
41
+ cb = FFI::Function.new(:void,
42
+ [:pointer, :pointer, :pointer, :float, :float, :pointer]) do
43
+ |_dfuncs, _draw_data, _st, x, y, _user_data|
44
+ block.call(x, y)
45
+ end
46
+ @move_to_ffi = cb
47
+ C.hb_draw_funcs_set_move_to_func(@ptr, cb, nil, nil)
48
+ end
49
+
50
+ # Sets the line_to callback
51
+ # @yield [x, y] Called for line-to operations
52
+ def on_line_to(&block)
53
+ @line_to_callback = block
54
+ cb = FFI::Function.new(:void,
55
+ [:pointer, :pointer, :pointer, :float, :float, :pointer]) do
56
+ |_dfuncs, _draw_data, _st, x, y, _user_data|
57
+ block.call(x, y)
58
+ end
59
+ @line_to_ffi = cb
60
+ C.hb_draw_funcs_set_line_to_func(@ptr, cb, nil, nil)
61
+ end
62
+
63
+ # Sets the quadratic_to callback
64
+ # @yield [cx, cy, x, y] Control point and end point
65
+ def on_quadratic_to(&block)
66
+ @quadratic_to_callback = block
67
+ cb = FFI::Function.new(:void,
68
+ [:pointer, :pointer, :pointer,
69
+ :float, :float, :float, :float, :pointer]) do
70
+ |_dfuncs, _draw_data, _st, cx, cy, x, y, _user_data|
71
+ block.call(cx, cy, x, y)
72
+ end
73
+ @quadratic_to_ffi = cb
74
+ C.hb_draw_funcs_set_quadratic_to_func(@ptr, cb, nil, nil)
75
+ end
76
+
77
+ # Sets the cubic_to callback
78
+ # @yield [c1x, c1y, c2x, c2y, x, y] Two control points and end point
79
+ def on_cubic_to(&block)
80
+ @cubic_to_callback = block
81
+ cb = FFI::Function.new(:void,
82
+ [:pointer, :pointer, :pointer,
83
+ :float, :float, :float, :float, :float, :float, :pointer]) do
84
+ |_dfuncs, _draw_data, _st, c1x, c1y, c2x, c2y, x, y, _user_data|
85
+ block.call(c1x, c1y, c2x, c2y, x, y)
86
+ end
87
+ @cubic_to_ffi = cb
88
+ C.hb_draw_funcs_set_cubic_to_func(@ptr, cb, nil, nil)
89
+ end
90
+
91
+ # Sets the close_path callback
92
+ # @yield Called when a path is closed
93
+ def on_close_path(&block)
94
+ @close_path_callback = block
95
+ cb = FFI::Function.new(:void, [:pointer, :pointer, :pointer, :pointer]) do
96
+ |_dfuncs, _draw_data, _st, _user_data|
97
+ block.call
98
+ end
99
+ @close_path_ffi = cb
100
+ C.hb_draw_funcs_set_close_path_func(@ptr, cb, nil, nil)
101
+ end
102
+
103
+ def inspect
104
+ "#<HarfBuzz::DrawFuncs immutable=#{immutable?}>"
105
+ end
106
+
107
+ def self.define_finalizer(obj, ptr)
108
+ destroy = C.method(:hb_draw_funcs_destroy)
109
+ ObjectSpace.define_finalizer(obj, proc { destroy.call(ptr) })
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HarfBuzz
4
+ # Base error class for all HarfBuzz errors
5
+ class Error < StandardError; end
6
+
7
+ # Raised when the HarfBuzz shared library cannot be found
8
+ class LibraryNotFoundError < Error; end
9
+
10
+ # Raised when memory allocation fails (create functions return NULL)
11
+ class AllocationError < Error; end
12
+
13
+ # Raised when an invalid argument is passed to a function
14
+ class InvalidArgumentError < Error; end
15
+
16
+ # Raised when a Feature string cannot be parsed
17
+ class FeatureParseError < Error; end
18
+
19
+ # Raised when a Variation string cannot be parsed
20
+ class VariationParseError < Error; end
21
+
22
+ # Raised when hb_subset_or_fail or similar operations fail
23
+ class SubsetError < Error; end
24
+
25
+ # Raised when an optional feature (FreeType, Subset) is unavailable
26
+ class UnavailableError < Error; end
27
+ end