Class: HarfBuzz::Feature
- Inherits:
-
Object
- Object
- HarfBuzz::Feature
- Defined in:
- lib/harfbuzz/feature.rb
Overview
Represents an OpenType feature (e.g., "liga", "+kern", "smcp=1")
Constant Summary collapse
- HB_FEATURE_GLOBAL_START =
0- HB_FEATURE_GLOBAL_END =
0xFFFFFFFF
Class Method Summary collapse
-
.from_hash(hash) ⇒ Array<Feature>
Builds a list of Feature objects from a Hash.
-
.from_string(str) ⇒ Feature
Parses a feature string such as "liga", "+kern", "-calt", "smcp=1".
Instance Method Summary collapse
-
#end_index ⇒ Integer
End index in buffer (HB_FEATURE_GLOBAL_END for global).
-
#initialize(struct) ⇒ Feature
constructor
A new instance of Feature.
- #inspect ⇒ Object
-
#start ⇒ Integer
Start index in buffer (HB_FEATURE_GLOBAL_START for global).
-
#tag ⇒ Integer
Feature tag as uint32.
-
#to_s ⇒ String
Feature string representation.
-
#to_struct ⇒ C::HbFeatureT
Returns the FFI struct for passing to C functions.
-
#value ⇒ Integer
Feature value.
Constructor Details
#initialize(struct) ⇒ Feature
Returns a new instance of Feature.
9 10 11 |
# File 'lib/harfbuzz/feature.rb', line 9 def initialize(struct) @struct = struct end |
Class Method Details
.from_hash(hash) ⇒ Array<Feature>
Builds a list of Feature objects from a Hash
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/harfbuzz/feature.rb', line 48 def self.from_hash(hash) hash.map do |tag, value| case value when true then from_string("+#{tag}") when false then from_string("-#{tag}") when Integer then from_string("#{tag}=#{value}") else raise InvalidArgumentError, "Unknown feature value: #{value.inspect}" end end end |
.from_string(str) ⇒ Feature
Parses a feature string such as "liga", "+kern", "-calt", "smcp=1"
37 38 39 40 41 42 43 |
# File 'lib/harfbuzz/feature.rb', line 37 def self.from_string(str) struct = C::HbFeatureT.new result = C.hb_feature_from_string(str, str.bytesize, struct) raise FeatureParseError, "Invalid feature string: #{str.inspect}" if result.zero? new(struct) end |
Instance Method Details
#end_index ⇒ Integer
Returns End index in buffer (HB_FEATURE_GLOBAL_END for global).
29 30 31 |
# File 'lib/harfbuzz/feature.rb', line 29 def end_index @struct[:end] end |
#inspect ⇒ Object
72 73 74 |
# File 'lib/harfbuzz/feature.rb', line 72 def inspect "#<HarfBuzz::Feature #{to_s}>" end |
#start ⇒ Integer
Returns Start index in buffer (HB_FEATURE_GLOBAL_START for global).
24 25 26 |
# File 'lib/harfbuzz/feature.rb', line 24 def start @struct[:start] end |
#tag ⇒ Integer
Returns Feature tag as uint32.
14 15 16 |
# File 'lib/harfbuzz/feature.rb', line 14 def tag @struct[:tag] end |
#to_s ⇒ String
Returns Feature string representation.
66 67 68 69 70 |
# File 'lib/harfbuzz/feature.rb', line 66 def to_s buf = FFI::MemoryPointer.new(:char, 128) C.hb_feature_to_string(@struct, buf, 128) buf.read_string end |
#to_struct ⇒ C::HbFeatureT
Returns the FFI struct for passing to C functions
61 62 63 |
# File 'lib/harfbuzz/feature.rb', line 61 def to_struct @struct end |
#value ⇒ Integer
Returns Feature value.
19 20 21 |
# File 'lib/harfbuzz/feature.rb', line 19 def value @struct[:value] end |