freetype 0.0.2 → 0.0.3

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
  SHA1:
3
- metadata.gz: c36f62b7c9de44960d5c1610bdad80291833313e
4
- data.tar.gz: 46b17c2d49414d9fdad8b8ea6072b342286aab00
3
+ metadata.gz: aa176ea1a23ab6bd07409f2eeb11409d18731d7d
4
+ data.tar.gz: 8becb757328442d46e54a301f9e12c8a5da07741
5
5
  SHA512:
6
- metadata.gz: 372d0d55f362b88693b72d12e17336319afea3b75a2a67d1eaedaaa235c02e775f86652e71764a4f5644b3451c98a3e23bced0ff7f31e4819866546877c936a3
7
- data.tar.gz: 55ac0bd04129157365706a0a91ffe5aceea88e3c5f4108ffd0563a40e0e589bb8dd972c33ba0167540228c4962e66ec184eefc88b949543a1add02bacc5285b8
6
+ metadata.gz: 1bd00ed094585cf3d6413fb8c718f20f648f56d51c2b44d5073b594a090333208501b7f71c2f05047cc0dab0656a83a71f70d0fd3e2e9fd25aaeb3fb5c8be320
7
+ data.tar.gz: 1264c6bf8838709888b80eaff21d83aa0af39e2518a772b8260acff0d4f4a86e21a1b54bb2711870d3eaa0f784d8f8bf8293114b11cc103c7e4a848858058fbf
@@ -143,6 +143,8 @@ module FreeType
143
143
  end
144
144
 
145
145
  class Glyph
146
+ include C
147
+
146
148
  def initialize(glyph)
147
149
  @glyph = glyph
148
150
  end
@@ -162,6 +164,15 @@ module FreeType
162
164
  def char_width
163
165
  @glyph[:metrics][:horiAdvance]
164
166
  end
167
+
168
+ def bold
169
+ FT_GlyphSlot_Embolden(@glyph)
170
+ end
171
+
172
+ def oblique
173
+ FT_GlyphSlot_Oblique(@glyph)
174
+ end
175
+ alias italic oblique
165
176
  end
166
177
 
167
178
  class Outline
@@ -176,13 +187,11 @@ module FreeType
176
187
  end
177
188
 
178
189
  def points
179
- @points ||= begin
180
- points = @outline[:n_points].times.map do |i|
181
- FT_Vector.new(@outline[:points] + i * FT_Vector.size)
182
- end
183
- points.zip(tags).map do |(point, tag)|
184
- Point.new(tag, point[:x], point[:y])
185
- end
190
+ points = @outline[:n_points].times.map do |i|
191
+ FT_Vector.new(@outline[:points] + i * FT_Vector.size)
192
+ end
193
+ points.zip(tags).map do |(point, tag)|
194
+ Point.new(tag, point[:x], point[:y])
186
195
  end
187
196
  end
188
197
 
@@ -89,6 +89,16 @@ module FreeTypeApiTest
89
89
  unless Outline === outline
90
90
  t.error('FreeType::API::Face#outline return value was break')
91
91
  end
92
+
93
+ ret = glyph.bold
94
+ unless ret.nil?
95
+ t.error SystemCallError.new(FFI.errno).message
96
+ end
97
+
98
+ ret = glyph.italic
99
+ unless ret.nil?
100
+ t.error SystemCallError.new(FFI.errno).message
101
+ end
92
102
  end
93
103
  end
94
104
  end
@@ -123,6 +123,13 @@ module FreeType
123
123
  y: :FT_Pos
124
124
  end
125
125
 
126
+ class FT_Matrix < ::FFI::Struct
127
+ layout xx: :FT_Fixed,
128
+ xy: :FT_Fixed,
129
+ yx: :FT_Fixed,
130
+ yy: :FT_Fixed
131
+ end
132
+
126
133
  # http://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#FT_GlyphSlotRec
127
134
  class FT_GlyphSlotRec < ::FFI::Struct
128
135
  layout library: :pointer,
@@ -204,6 +211,19 @@ module FreeType
204
211
  charmap: :pointer
205
212
  end
206
213
 
214
+ class << self
215
+ module LazyAttach
216
+ def attach_function(name, func, args, returns = nil, options = nil)
217
+ super
218
+ rescue FFI::NotFoundError
219
+ define_method(name) do |*|
220
+ raise NotImplementedError, "`#{name}' is not implemented in this system"
221
+ end
222
+ end
223
+ end
224
+ prepend LazyAttach
225
+ end
226
+
207
227
  # library = FFI::MemoryPointer.new(:pointer)
208
228
  # err = FT_Init_FreeType(library)
209
229
  # err = FT_Done_Library(library.get_pointer(0))
@@ -232,6 +252,12 @@ module FreeType
232
252
  # attach_function :FT_Get_Glyph, [FT_GlyphSlotRec.ptr, :pointer], :FT_Error
233
253
  # attach_function :FT_Done_Glyph, [:pointer], :void
234
254
 
255
+ attach_function :FT_GlyphSlot_Embolden, [FT_GlyphSlotRec.ptr], :void
256
+ attach_function :FT_GlyphSlot_Oblique, [FT_GlyphSlotRec.ptr], :void
257
+ attach_function :FT_Outline_Embolden, [:pointer, :FT_Pos], :FT_Error
258
+ attach_function :FT_Outline_Transform, [:pointer, FT_Matrix.ptr], :void
259
+ attach_function :FT_Outline_Reverse, [:pointer], :void
260
+
235
261
  # id = FT_Get_Char_Index(face, 'A'.ord) -> glyph id or 0 (undefined)
236
262
  attach_function :FT_Get_Char_Index, [:pointer, :ulong], :uint
237
263
 
@@ -114,6 +114,49 @@ module FFITest
114
114
  end
115
115
  end
116
116
 
117
+ def test_FT_Outline_Embolden(t)
118
+ libopen do |face|
119
+ t.error('err') if FT_Set_Char_Size(face, 0, 32, 300, 300) != 0
120
+ t.error('err') if FT_Load_Char(face, 'a'.ord, FreeType::C::FT_LOAD_DEFAULT) != 0
121
+ if face[:glyph][:format] != :FT_GLYPH_FORMAT_OUTLINE
122
+ t.error "cannot call FT_Outline_Embolden() to format: `#{face[:glyph][:format]}'"
123
+ end
124
+ err = FT_Outline_Embolden(face[:glyph][:outline], 1 << 6)
125
+ if err != 0
126
+ t.error FreeType::Error.find(err).message
127
+ end
128
+ end
129
+ end
130
+
131
+ def test_FT_Outline_Transform(t)
132
+ libopen do |face|
133
+ t.error('err') if FT_Set_Char_Size(face, 0, 32, 300, 300) != 0
134
+ t.error('err') if FT_Load_Char(face, 'a'.ord, FreeType::C::FT_LOAD_DEFAULT) != 0
135
+ if face[:glyph][:format] != :FT_GLYPH_FORMAT_OUTLINE
136
+ t.error "cannot call FT_Outline_Embolden() to format: `#{face[:glyph][:format]}'"
137
+ end
138
+ m = FT_Matrix.new
139
+ m[:xx] = 1 << 16
140
+ m[:xy] = 0x5800
141
+ m[:yx] = 0
142
+ m[:yy] = 1 << 16
143
+ ret = FT_Outline_Transform(face[:glyph][:outline], m)
144
+ unless ret.nil?
145
+ t.error SystemCallError.new(FFI.errno).message
146
+ end
147
+ end
148
+ end
149
+
150
+ def test_FT_Outline_Reverse(t)
151
+ libopen do |face|
152
+ t.error('err') if FT_Set_Char_Size(face, 0, 32, 300, 300) != 0
153
+ t.error('err') if FT_Load_Char(face, 'a'.ord, FreeType::C::FT_LOAD_DEFAULT) != 0
154
+ unless FT_Outline_Reverse(face[:glyph][:outline]).nil?
155
+ t.error 'return value was break'
156
+ end
157
+ end
158
+ end
159
+
117
160
  def test_char(t)
118
161
  libopen do |face, _font|
119
162
  err = FT_Set_Char_Size(face, 0, 32, 300, 300)
@@ -1,3 +1,3 @@
1
1
  module FreeType
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freetype
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ksss
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-17 00:00:00.000000000 Z
11
+ date: 2015-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi