Class: HarfBuzz::Feature

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

Parameters:

  • hash (Hash)

    Map of tag => value (true/false/Integer)

Returns:

  • (Array<Feature>)

    List of features



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"

Parameters:

  • str (String)

    Feature string

Returns:

Raises:



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_indexInteger

Returns End index in buffer (HB_FEATURE_GLOBAL_END for global).

Returns:

  • (Integer)

    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

#inspectObject



72
73
74
# File 'lib/harfbuzz/feature.rb', line 72

def inspect
  "#<HarfBuzz::Feature #{to_s}>"
end

#startInteger

Returns Start index in buffer (HB_FEATURE_GLOBAL_START for global).

Returns:

  • (Integer)

    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

#tagInteger

Returns Feature tag as uint32.

Returns:

  • (Integer)

    Feature tag as uint32



14
15
16
# File 'lib/harfbuzz/feature.rb', line 14

def tag
  @struct[:tag]
end

#to_sString

Returns Feature string representation.

Returns:

  • (String)

    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_structC::HbFeatureT

Returns the FFI struct for passing to C functions

Returns:



61
62
63
# File 'lib/harfbuzz/feature.rb', line 61

def to_struct
  @struct
end

#valueInteger

Returns Feature value.

Returns:

  • (Integer)

    Feature value



19
20
21
# File 'lib/harfbuzz/feature.rb', line 19

def value
  @struct[:value]
end