harfbuzz 0.4 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4401c3c179f2d103fb41c0b754774021af45cc7af0de5526e378e28939e43378
4
- data.tar.gz: c4c2d68da5da9f48bd5521706a17debec1a41d772cc442f0493753b6ab18bd6a
3
+ metadata.gz: 9f1994c4e013fface603443dcb45250688ad78d0d3b2629c2d264f442a7c5b71
4
+ data.tar.gz: 280dbf3262160b8aa7eec734203a18f78eb69be977d7f770b56cb5d2fb9204e4
5
5
  SHA512:
6
- metadata.gz: 93df44f68443d7bef5e959e1f331138e46d1c359a6e0231511376ee07813f77662d19fa021c60c7110b21ec6508b617d550cd0cf07abbd19fdd144f202fcba06
7
- data.tar.gz: fdaf1f46f8a3eddab026be6d259bb74ee0f6a7654e27a119e7867ebc04b67f04ef56a7d7881c23f9806030c85ae0853fa8784c7e288f4ebb0bc82b6e0960e6b9
6
+ metadata.gz: 6f5dfdbf1ee3fa758fe3649922a831ede67aab3e168b3bb85467b9694147abf00131969b68db7d23f744eae82f83f49e6dd3e7292d01199265fb9d509cceb077
7
+ data.tar.gz: 0c136c2afed468e220324c9bce978e77344b749853c665714dface90a5e7590a2fb0698eaaf43173df1e12c05097c9421126786afd368b8d1a7710c8e5a1e19d
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  .DS_Store
2
+ Gemfile.lock
2
3
  *.gem
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md CHANGED
@@ -53,6 +53,8 @@ Memory management may not be correct. (I've seen crashes when processing large a
53
53
 
54
54
  ## To-do
55
55
 
56
+ - Update for recent (version 4.0+) versions of Harfbuzz.
57
+
56
58
  - Implement hb_buffer_set_* functions.
57
59
 
58
60
  - Add documentation.
data/Rakefile CHANGED
@@ -1,10 +1,9 @@
1
- require 'rubygems/tasks'
1
+ require 'bundler/gem_tasks'
2
+ Bundler.require
2
3
  require 'rake/testtask'
3
4
 
4
- Gem::Tasks.new
5
- Rake::TestTask.new
5
+ Rake::TestTask.new do |t|
6
+ t.test_files = FileList['test/test_*.rb']
7
+ end
6
8
 
7
- desc 'Run benchmark'
8
- task :benchmark do
9
- load './examples/benchmark.rb'
10
- end
9
+ task :default => :test
@@ -8,7 +8,7 @@ Features = %w{+dlig +hlig}
8
8
 
9
9
  Benchmark.bm do |benchmark|
10
10
  benchmark.report do
11
- face = Harfbuzz::Face.new(Harfbuzz::Blob.new(File.open('/Library/Fonts/ACaslonPro-Regular.otf', 'rb')))
11
+ face = Harfbuzz::Face.new(Harfbuzz::Blob.new(File.open('/Users/johnl/Fonts/A/Adobe Caslon Pro/ACaslonPro-Regular.otf', 'rb')))
12
12
  font = Harfbuzz::Font.new(face)
13
13
  Words.each do |word|
14
14
  buffer = Harfbuzz::Buffer.new
data/examples/example.rb CHANGED
@@ -14,7 +14,7 @@ puts "Shapers: #{Harfbuzz.shapers.join(', ')}"
14
14
  # Create a font to be used for shaping. To get the most of out this example, use an OpenType font.
15
15
  #
16
16
 
17
- face = Harfbuzz::Face.new(File.open('/Library/Fonts/ACaslonPro-Regular.otf', 'rb'))
17
+ face = Harfbuzz::Face.new(File.open('/Users/johnl/Fonts/A/Adobe Caslon Pro/ACaslonPro-Regular.otf', 'rb'))
18
18
 
19
19
  puts "Font face index: #{face.index}"
20
20
  puts "Font face upem: #{face.upem}"
@@ -82,7 +82,7 @@ buffer.length.times do |i|
82
82
  info, position = glyph_infos[i], glyph_positions[i]
83
83
  glyph_name = font.glyph_to_string(info.codepoint)
84
84
  glyph_extents = font.glyph_extents(info.codepoint)
85
- puts "/%-10.10s %5u | mask: %04X | cluster: %2u | advance: %4d,%4d | offset: %4d,%4d | bearing: %4d,%4d | size: %4d,%4d" % [
85
+ puts "/%-10.10s | gid: %5u | mask: %04X | cluster: %2u | advance: %4d,%4d | offset: %4d,%4d | bearing: %4d,%4d | size: %4d,%4d" % [
86
86
  glyph_name,
87
87
  info.codepoint,
88
88
  info.mask,
data/harfbuzz.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'harfbuzz'
3
- s.version = '0.4'
3
+ s.version = '0.5'
4
4
  s.summary = 'Ruby interface to the Harfbuzz text shaping engine'
5
5
  s.author = 'John Labovitz'
6
6
  s.email = 'johnl@johnlabovitz.com'
@@ -14,9 +14,9 @@ Gem::Specification.new do |s|
14
14
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
15
15
  s.require_path = 'lib'
16
16
 
17
- s.add_dependency 'ffi', '~> 1.9'
17
+ s.add_dependency 'ffi', '~> 1.15'
18
18
 
19
- s.add_development_dependency 'rake', '~> 12.3'
20
- s.add_development_dependency 'minitest', '~> 5.11'
19
+ s.add_development_dependency 'rake', '~> 13.0'
20
+ s.add_development_dependency 'minitest', '~> 5.16'
21
21
  s.add_development_dependency 'minitest-power_assert', '~> 0.3'
22
22
  end
data/lib/harfbuzz/base.rb CHANGED
@@ -4,7 +4,7 @@ module Harfbuzz
4
4
 
5
5
  def self.finalize(method, ptr)
6
6
  proc {
7
- Harfbuzz.send(method, ptr) unless ptr == 0
7
+ Harfbuzz.send(method, ptr) if ptr
8
8
  }
9
9
  end
10
10
 
@@ -62,6 +62,7 @@ module Harfbuzz
62
62
  end
63
63
 
64
64
  attach_function :hb_buffer_create, [], :hb_buffer_t
65
+ attach_function :hb_buffer_destroy, [:hb_buffer_t], :void
65
66
  attach_function :hb_buffer_add_utf8, [
66
67
  :hb_buffer_t, # buffer
67
68
  :pointer, # text
data/lib/harfbuzz/face.rb CHANGED
@@ -6,6 +6,7 @@ module Harfbuzz
6
6
  :hb_blob_t, # blob
7
7
  :uint, # index
8
8
  ], :hb_face_t
9
+ attach_function :hb_face_destroy, [:hb_face_t], :void
9
10
  attach_function :hb_face_get_index, [:hb_face_t], :uint
10
11
  attach_function :hb_face_get_upem, [:hb_face_t], :uint
11
12
  attach_function :hb_face_get_glyph_count, [:hb_face_t], :uint
data/lib/harfbuzz/font.rb CHANGED
@@ -76,11 +76,19 @@ module Harfbuzz
76
76
  end
77
77
 
78
78
  attach_function :hb_font_create, [:hb_face_t], :hb_font_t
79
+ attach_function :hb_font_destroy, [:hb_font_t], :void
79
80
  attach_function :hb_font_set_scale, [
80
81
  :hb_font_t, # font
81
82
  :int, # x_scale
82
83
  :int, # y_scale
83
84
  ], :void
85
+ attach_function :hb_font_set_ptem, [
86
+ :hb_font_t,
87
+ :float,
88
+ ], :void
89
+ attach_function :hb_font_get_ptem, [
90
+ :hb_font_t,
91
+ ], :float
84
92
  attach_function :hb_ft_font_set_funcs, [:hb_font_t], :void
85
93
  attach_function :hb_font_get_scale, [
86
94
  :hb_font_t, # font
@@ -115,14 +123,23 @@ module Harfbuzz
115
123
  :hb_codepoint_t, # glyph
116
124
  GlyphExtents.by_ref # extents
117
125
  ], :hb_bool_t
126
+ attach_function :hb_font_get_glyph_advance_for_direction, [
127
+ :hb_font_t, # font
128
+ :hb_codepoint_t, # glyph
129
+ # :hb_direction_t, # direction
130
+ :int, # direction
131
+ :pointer, # x
132
+ :pointer, # y
133
+ ], :void
118
134
 
119
135
  class Font < Base
120
136
 
121
137
  attr_reader :hb_font
122
138
 
123
- def initialize(face)
139
+ def initialize(face, size=nil)
124
140
  @hb_font = Harfbuzz.hb_font_create(face.hb_face)
125
- Harfbuzz.hb_font_set_scale(@hb_font, face.upem, face.upem)
141
+ # Harfbuzz.hb_font_set_scale(@hb_font, face.upem, face.upem)
142
+ Harfbuzz.hb_font_set_ptem(@hb_font, size) if size
126
143
  Harfbuzz.hb_ft_font_set_funcs(@hb_font)
127
144
  define_finalizer(:hb_font_destroy, @hb_font)
128
145
  end
@@ -147,6 +164,10 @@ module Harfbuzz
147
164
  ]
148
165
  end
149
166
 
167
+ def ptem
168
+ Harfbuzz.hb_font_get_ptem(@hb_font)
169
+ end
170
+
150
171
  def glyph_to_string(glyph)
151
172
  string_ptr = FFI::MemoryPointer.new(:char, 20)
152
173
  Harfbuzz.hb_font_glyph_to_string(@hb_font, glyph, string_ptr, 20)
@@ -179,6 +200,17 @@ module Harfbuzz
179
200
  glyph_extents
180
201
  end
181
202
 
203
+ def glyph_advance_for_direction(glyph, direction)
204
+ x_ptr = FFI::MemoryPointer.new(:int32, 1)
205
+ y_ptr = FFI::MemoryPointer.new(:int32, 1)
206
+ Harfbuzz.hb_font_get_glyph_advance_for_direction(@hb_font, glyph, direction, x_ptr, y_ptr)
207
+ if Harfbuzz.hb_direction_is_horizontal(direction)
208
+ x_ptr.read_int32
209
+ else
210
+ y_ptr.read_int32
211
+ end
212
+ end
213
+
182
214
  if Harfbuzz.version_at_least(1,1,3)
183
215
 
184
216
  def h_extents
data/lib/harfbuzz.rb CHANGED
@@ -13,6 +13,37 @@ module Harfbuzz
13
13
  typedef :bool, :hb_bool_t
14
14
  typedef :int32, :hb_position_t
15
15
 
16
+ # hb_direction_t enum
17
+ HB_DIRECTION_INVALID = 0
18
+ HB_DIRECTION_LTR = 4
19
+ HB_DIRECTION_RTL = 5
20
+ HB_DIRECTION_TTB = 6
21
+ HB_DIRECTION_BTT = 7
22
+
23
+ def self.hb_direction_is_valid(dir)
24
+ dir & ~3 == 4
25
+ end
26
+
27
+ def self.hb_direction_is_horizontal(dir)
28
+ dir & ~1 == 4
29
+ end
30
+
31
+ def self.hb_direction_is_vertical(dir)
32
+ dir & ~1 == 6
33
+ end
34
+
35
+ def self.hb_direction_is_forward(dir)
36
+ dir & ~2 == 4
37
+ end
38
+
39
+ def self.hb_direction_is_backward(dir)
40
+ dir & ~2 == 5
41
+ end
42
+
43
+ def self.hb_direction_reverse(dir)
44
+ dir ^ 1
45
+ end
46
+
16
47
  end
17
48
 
18
49
  require 'harfbuzz/version'
data/test/helpers.rb CHANGED
@@ -7,7 +7,7 @@ module Harfbuzz
7
7
  module Setup
8
8
 
9
9
  def setup
10
- @data = File.open('/Library/Fonts/ACaslonPro-Regular.otf', 'rb')
10
+ @data = File.open('/Users/johnl/Fonts/A/Adobe Caslon Pro/ACaslonPro-Regular.otf', 'rb')
11
11
  @blob = Harfbuzz::Blob.new(@data)
12
12
  @face = Harfbuzz::Face.new(@blob)
13
13
  @font = Harfbuzz::Font.new(@face)
data/test/test_font.rb CHANGED
@@ -6,6 +6,11 @@ module Harfbuzz
6
6
 
7
7
  include Setup
8
8
 
9
+ def test_init_with_size
10
+ font2 = Harfbuzz::Font.new(@face, 12)
11
+ assert { font2.ptem == 12.0 }
12
+ end
13
+
9
14
  def test_scale
10
15
  scale = @font.scale
11
16
  assert { scale.kind_of?(Array) }
@@ -38,6 +43,11 @@ module Harfbuzz
38
43
  assert { extents.height != 0 }
39
44
  end
40
45
 
46
+ def test_glyph_advance
47
+ advance = @font.glyph_advance_for_direction(1, Harfbuzz::HB_DIRECTION_LTR)
48
+ assert { advance > 0 }
49
+ end
50
+
41
51
  end
42
52
 
43
53
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: harfbuzz
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Labovitz
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-08 00:00:00.000000000 Z
11
+ date: 2022-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.9'
19
+ version: '1.15'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.9'
26
+ version: '1.15'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '12.3'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '12.3'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '5.11'
47
+ version: '5.16'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '5.11'
54
+ version: '5.16'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest-power_assert
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -75,6 +75,7 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - ".gitignore"
77
77
  - CHANGELOG.md
78
+ - Gemfile
78
79
  - LICENSE.txt
79
80
  - README.md
80
81
  - Rakefile
@@ -102,7 +103,7 @@ homepage: http://github.com/jslabovitz/harfbuzz-gem
102
103
  licenses:
103
104
  - MIT
104
105
  metadata: {}
105
- post_install_message:
106
+ post_install_message:
106
107
  rdoc_options: []
107
108
  require_paths:
108
109
  - lib
@@ -117,9 +118,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
118
  - !ruby/object:Gem::Version
118
119
  version: '0'
119
120
  requirements: []
120
- rubyforge_project:
121
- rubygems_version: 2.7.4
122
- signing_key:
121
+ rubygems_version: 3.3.22
122
+ signing_key:
123
123
  specification_version: 4
124
124
  summary: Ruby interface to the Harfbuzz text shaping engine
125
125
  test_files: