harfbuzz 0.3 → 0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 91353145ce3cd90e818ed73cc55f3c04eca4c2f4
4
- data.tar.gz: 1cce672a648ef09d704538e8ca54b76e40bee79a
2
+ SHA256:
3
+ metadata.gz: 9f1994c4e013fface603443dcb45250688ad78d0d3b2629c2d264f442a7c5b71
4
+ data.tar.gz: 280dbf3262160b8aa7eec734203a18f78eb69be977d7f770b56cb5d2fb9204e4
5
5
  SHA512:
6
- metadata.gz: 3992107ed59cae7f51a3049f7ea4d9782a3664f3cb30b114689b135f86250fe004f8ce26e1328542f4ecd7018d24e038ba6a6183e4457be9de81a288d0c4ea9a
7
- data.tar.gz: 26bfdce861b3d20c8875df4434af889b071b8990247ca7e1e2d7fc2603d00b2a110303c1ca270209731bd7b71135751c9430be2db7834d32da050b454f9da419
6
+ metadata.gz: 6f5dfdbf1ee3fa758fe3649922a831ede67aab3e168b3bb85467b9694147abf00131969b68db7d23f744eae82f83f49e6dd3e7292d01199265fb9d509cceb077
7
+ data.tar.gz: 0c136c2afed468e220324c9bce978e77344b749853c665714dface90a5e7590a2fb0698eaaf43173df1e12c05097c9421126786afd368b8d1a7710c8e5a1e19d
data/.gitignore CHANGED
@@ -1,3 +1,3 @@
1
1
  .DS_Store
2
2
  Gemfile.lock
3
- pkg/
3
+ *.gem
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  Only important or user-facing changes are listed here. See commit log for typos, refactoring, documentation tweaks, etc.
4
4
 
5
+ ## 0.4 / 2018-01-08
6
+
7
+ - Modernize/simplify gem structure.
8
+ - Improve exception messages.
9
+
5
10
  ## 0.3 / 2016-05-10
6
11
 
7
12
  - Add new Harfbuzz bindings:
data/Gemfile CHANGED
@@ -1,7 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # # use local FFI gem
4
- # gem 'ffi', path: '~/src/ffi'
5
-
6
- # Specify your gem's dependencies in itinerary.gemspec
7
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 'bundler'
2
1
  require 'bundler/gem_tasks'
2
+ Bundler.require
3
3
  require 'rake/testtask'
4
4
 
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,22 +1,22 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'harfbuzz'
3
- s.version = '0.3'
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'
7
7
  s.description = %q{
8
8
  Harfbuzz is a Ruby interface to the Harfbuzz text shaping engine.
9
9
  }
10
+ s.license = 'MIT'
10
11
  s.homepage = 'http://github.com/jslabovitz/harfbuzz-gem'
11
12
  s.files = `git ls-files`.split("\n")
12
13
  s.test_files = `git ls-files -- test/*`.split("\n")
13
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
14
- s.require_paths = %w{lib}
14
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
15
+ s.require_path = 'lib'
15
16
 
16
- s.add_dependency 'ffi'
17
+ s.add_dependency 'ffi', '~> 1.15'
17
18
 
18
- s.add_development_dependency 'bundler'
19
- s.add_development_dependency 'rake'
20
- s.add_development_dependency 'minitest'
21
- s.add_development_dependency 'minitest-power_assert'
19
+ s.add_development_dependency 'rake', '~> 13.0'
20
+ s.add_development_dependency 'minitest', '~> 5.16'
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
@@ -91,7 +92,7 @@ module Harfbuzz
91
92
  end
92
93
 
93
94
  def add_utf8(text, offset=0, length=-1)
94
- raise "expected text in UTF-8 encoding, but received #{text.encoding}" unless text.encoding == Encoding::UTF_8
95
+ raise "Expected text in UTF-8 encoding, but received #{text.encoding} (#{text.inspect})" unless text.encoding == Encoding::UTF_8
95
96
  text_ptr = FFI::MemoryPointer.new(:char, text.bytesize)
96
97
  text_ptr.put_bytes(0, text)
97
98
  Harfbuzz.hb_buffer_add_utf8(@hb_buffer, text_ptr, text.bytesize, offset, length)
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,85 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: harfbuzz
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
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: 2016-05-10 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
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
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: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
26
+ version: '1.15'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - ">="
31
+ - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '0'
33
+ version: '13.0'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - ">="
38
+ - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: '0'
40
+ version: '13.0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: minitest
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
- - - ">="
45
+ - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: '0'
47
+ version: '5.16'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
- - - ">="
52
+ - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: '0'
54
+ version: '5.16'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: minitest-power_assert
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
- - - ">="
59
+ - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: '0'
61
+ version: '0.3'
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
- - - ">="
66
+ - - "~>"
81
67
  - !ruby/object:Gem::Version
82
- version: '0'
68
+ version: '0.3'
83
69
  description: "\n Harfbuzz is a Ruby interface to the Harfbuzz text shaping engine.\n
84
70
  \ "
85
71
  email: johnl@johnlabovitz.com
@@ -114,9 +100,10 @@ files:
114
100
  - test/test_shaper.rb
115
101
  - test/test_version.rb
116
102
  homepage: http://github.com/jslabovitz/harfbuzz-gem
117
- licenses: []
103
+ licenses:
104
+ - MIT
118
105
  metadata: {}
119
- post_install_message:
106
+ post_install_message:
120
107
  rdoc_options: []
121
108
  require_paths:
122
109
  - lib
@@ -131,9 +118,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
118
  - !ruby/object:Gem::Version
132
119
  version: '0'
133
120
  requirements: []
134
- rubyforge_project:
135
- rubygems_version: 2.6.4
136
- signing_key:
121
+ rubygems_version: 3.3.22
122
+ signing_key:
137
123
  specification_version: 4
138
124
  summary: Ruby interface to the Harfbuzz text shaping engine
139
125
  test_files:
@@ -144,4 +130,3 @@ test_files:
144
130
  - test/test_general.rb
145
131
  - test/test_shaper.rb
146
132
  - test/test_version.rb
147
- has_rdoc: