Class: HarfBuzz::Face
- Inherits:
-
Object
- Object
- HarfBuzz::Face
- Defined in:
- lib/harfbuzz/face.rb
Overview
Wraps hb_face_t — a font face (font file + index)
Instance Attribute Summary collapse
-
#ptr ⇒ Object
readonly
Returns the value of attribute ptr.
Class Method Summary collapse
-
.count(blob) ⇒ Integer
Returns the number of faces in a blob.
- .define_finalizer(obj, ptr) ⇒ Object
-
.empty ⇒ Face
Returns the singleton empty face.
-
.for_tables {|tag| ... } ⇒ Face
Creates a Face with custom table access (callback-based).
- .wrap_borrowed(ptr) ⇒ Object
- .wrap_owned(ptr) ⇒ Object
Instance Method Summary collapse
-
#blob ⇒ Blob
Returns the blob for the entire font face.
-
#glyph_count ⇒ Integer
Number of glyphs in this face.
- #glyph_count=(count) ⇒ Object
-
#immutable? ⇒ Boolean
True if face is immutable.
-
#index ⇒ Integer
Face index.
- #index=(idx) ⇒ Object
-
#initialize(blob, index = 0) ⇒ Face
constructor
Creates a Face from a Blob and face index.
- #inspect ⇒ Object
-
#make_immutable! ⇒ self
Makes the face immutable (thread-safe to share after this).
-
#nominal_glyph_mapping ⇒ Map
Map from Unicode codepoints to nominal glyph IDs.
-
#table(tag) ⇒ Blob
(also: #reference_table)
Returns the blob for a specific table.
-
#table_tags ⇒ Array<Integer>
Array of table tags.
-
#unicodes ⇒ Set
Set of all Unicode codepoints in this face.
-
#upem ⇒ Integer
Units per em.
- #upem=(u) ⇒ Object
-
#variation_selectors ⇒ Set
Set of variation selector codepoints.
-
#variation_unicodes(selector) ⇒ Set
Set of Unicode codepoints supported via the variation selector.
Constructor Details
#initialize(blob, index = 0) ⇒ Face
Creates a Face from a Blob and face index
11 12 13 14 15 16 17 |
# File 'lib/harfbuzz/face.rb', line 11 def initialize(blob, index = 0) @blob = blob @ptr = C.hb_face_create(blob.ptr, index) raise AllocationError, "Failed to create face" if @ptr.null? register_finalizer end |
Instance Attribute Details
#ptr ⇒ Object (readonly)
Returns the value of attribute ptr.
6 7 8 |
# File 'lib/harfbuzz/face.rb', line 6 def ptr @ptr end |
Class Method Details
.count(blob) ⇒ Integer
Returns the number of faces in a blob
48 49 50 |
# File 'lib/harfbuzz/face.rb', line 48 def self.count(blob) C.hb_face_count(blob.ptr) end |
.define_finalizer(obj, ptr) ⇒ Object
181 182 183 184 |
# File 'lib/harfbuzz/face.rb', line 181 def self.define_finalizer(obj, ptr) destroy = C.method(:hb_face_destroy) ObjectSpace.define_finalizer(obj, proc { destroy.call(ptr) }) end |
.empty ⇒ Face
Returns the singleton empty face
41 42 43 |
# File 'lib/harfbuzz/face.rb', line 41 def self.empty wrap_borrowed(C.hb_face_get_empty) end |
.for_tables {|tag| ... } ⇒ Face
Creates a Face with custom table access (callback-based)
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/harfbuzz/face.rb', line 23 def self.for_tables(&block) callback_holder = [] cb = FFI::Function.new(:pointer, [:pointer, :uint32, :pointer]) do |_face, tag, _user_data| blob = block.call(tag) blob ? blob.ptr : C.hb_blob_get_empty end callback_holder << cb ptr = C.hb_face_create_for_tables(cb, nil, nil) obj = allocate obj.instance_variable_set(:@ptr, ptr) obj.instance_variable_set(:@callback_holder, callback_holder) obj.send(:register_finalizer) obj end |
.wrap_borrowed(ptr) ⇒ Object
166 167 168 169 170 171 |
# File 'lib/harfbuzz/face.rb', line 166 def self.wrap_borrowed(ptr) obj = allocate obj.instance_variable_set(:@ptr, ptr) obj.instance_variable_set(:@borrowed, true) obj end |
.wrap_owned(ptr) ⇒ Object
159 160 161 162 163 164 |
# File 'lib/harfbuzz/face.rb', line 159 def self.wrap_owned(ptr) obj = allocate obj.instance_variable_set(:@ptr, ptr) obj.send(:register_finalizer) obj end |
Instance Method Details
#blob ⇒ Blob
Returns the blob for the entire font face
109 110 111 112 |
# File 'lib/harfbuzz/face.rb', line 109 def blob ptr = C.hb_face_reference_blob(@ptr) Blob.wrap_owned(ptr) end |
#glyph_count ⇒ Integer
Returns Number of glyphs in this face.
73 74 75 |
# File 'lib/harfbuzz/face.rb', line 73 def glyph_count C.hb_face_get_glyph_count(@ptr) end |
#glyph_count=(count) ⇒ Object
78 79 80 |
# File 'lib/harfbuzz/face.rb', line 78 def glyph_count=(count) C.hb_face_set_glyph_count(@ptr, count) end |
#immutable? ⇒ Boolean
Returns true if face is immutable.
144 145 146 |
# File 'lib/harfbuzz/face.rb', line 144 def immutable? C.from_hb_bool(C.hb_face_is_immutable(@ptr)) end |
#index ⇒ Integer
Returns Face index.
53 54 55 |
# File 'lib/harfbuzz/face.rb', line 53 def index C.hb_face_get_index(@ptr) end |
#index=(idx) ⇒ Object
58 59 60 |
# File 'lib/harfbuzz/face.rb', line 58 def index=(idx) C.hb_face_set_index(@ptr, idx) end |
#inspect ⇒ Object
155 156 157 |
# File 'lib/harfbuzz/face.rb', line 155 def inspect "#<HarfBuzz::Face index=#{index} upem=#{upem} glyph_count=#{glyph_count}>" end |
#make_immutable! ⇒ self
Makes the face immutable (thread-safe to share after this)
150 151 152 153 |
# File 'lib/harfbuzz/face.rb', line 150 def make_immutable! C.hb_face_make_immutable(@ptr) self end |
#nominal_glyph_mapping ⇒ Map
Returns Map from Unicode codepoints to nominal glyph IDs.
122 123 124 125 126 |
# File 'lib/harfbuzz/face.rb', line 122 def nominal_glyph_mapping map = Map.new C.hb_face_collect_nominal_glyph_mapping(@ptr, map.ptr, FFI::Pointer::NULL) map end |
#table(tag) ⇒ Blob Also known as: reference_table
Returns the blob for a specific table
100 101 102 103 |
# File 'lib/harfbuzz/face.rb', line 100 def table(tag) ptr = C.hb_face_reference_table(@ptr, tag) Blob.wrap_owned(ptr) end |
#table_tags ⇒ Array<Integer>
Returns Array of table tags.
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/harfbuzz/face.rb', line 83 def # First call: pass count=0 to get total number of tables (return value) count_ptr = FFI::MemoryPointer.new(:uint) count_ptr.write_uint(0) total = C.(@ptr, 0, count_ptr, nil) return [] if total.zero? = FFI::MemoryPointer.new(:uint32, total) count_ptr.write_uint(total) C.(@ptr, 0, count_ptr, ) actual = count_ptr.read_uint .read_array_of_uint32(actual) end |
#unicodes ⇒ Set
Returns Set of all Unicode codepoints in this face.
115 116 117 118 119 |
# File 'lib/harfbuzz/face.rb', line 115 def unicodes set = Set.new C.hb_face_collect_unicodes(@ptr, set.ptr) set end |
#upem ⇒ Integer
Returns Units per em.
63 64 65 |
# File 'lib/harfbuzz/face.rb', line 63 def upem C.hb_face_get_upem(@ptr) end |
#upem=(u) ⇒ Object
68 69 70 |
# File 'lib/harfbuzz/face.rb', line 68 def upem=(u) C.hb_face_set_upem(@ptr, u) end |