Module: HarfBuzz::OT::Layout

Defined in:
lib/harfbuzz/ot/layout.rb

Overview

OpenType Layout table queries (GSUB/GPOS)

Class Method Summary collapse

Class Method Details

.attach_points(face, glyph) ⇒ Array<Integer>

Returns attachment point list for a glyph

Parameters:

  • face (Face)

    Font face

  • glyph (Integer)

    Glyph ID

Returns:

  • (Array<Integer>)

    Attachment point indices



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/harfbuzz/ot/layout.rb', line 66

def attach_points(face, glyph)
  count_ptr = FFI::MemoryPointer.new(:uint)
  count_ptr.write_uint(0)
  total = C.hb_ot_layout_get_attach_points(face.ptr, glyph, 0, count_ptr, nil)
  return [] if total.zero?

  points_ptr = FFI::MemoryPointer.new(:uint, total)
  count_ptr.write_uint(total)
  C.hb_ot_layout_get_attach_points(face.ptr, glyph, 0, count_ptr, points_ptr)
  points_ptr.read_array_of_uint(count_ptr.read_uint)
end

.baseline(font, baseline_tag, dir, script_tag, language = nil) ⇒ Integer?

Returns a baseline coordinate value

Parameters:

  • font (Font)

    Font

  • baseline_tag (Integer)

    Baseline tag (HB_OT_LAYOUT_BASELINE_TAG_*)

  • dir (Symbol)

    Direction (:ltr, :rtl, :ttb, :btt)

  • script_tag (Integer)

    Script tag

  • language (FFI::Pointer, nil) (defaults to: nil)

    Language pointer (nil = default)

Returns:

  • (Integer, nil)

    Baseline coordinate or nil if not available



365
366
367
368
369
370
371
372
373
374
# File 'lib/harfbuzz/ot/layout.rb', line 365

def baseline(font, baseline_tag, dir, script_tag, language = nil)
  lang_ptr = language || FFI::Pointer::NULL
  coord_ptr = FFI::MemoryPointer.new(:int32)
  found = C.from_hb_bool(
    C.hb_ot_layout_get_baseline(
      font.ptr, baseline_tag, dir, script_tag, lang_ptr, coord_ptr
    )
  )
  found ? coord_ptr.read_int32 : nil
end

.baseline2(font, baseline_tag, dir, script, language = nil) ⇒ Integer?

Returns a baseline coordinate value (v2: takes hb_script_t + hb_language_t)

Parameters:

  • font (Font)

    Font

  • baseline_tag (Integer)

    Baseline tag

  • dir (Symbol)

    Direction

  • script (Integer)

    Script value (hb_script_t, e.g. from HarfBuzz.script("Latn"))

  • language (FFI::Pointer, nil) (defaults to: nil)

    Language pointer (nil = default)

Returns:

  • (Integer, nil)

    Baseline coordinate or nil if not available



422
423
424
425
426
427
428
429
430
431
# File 'lib/harfbuzz/ot/layout.rb', line 422

def baseline2(font, baseline_tag, dir, script, language = nil)
  lang_ptr = language || FFI::Pointer::NULL
  coord_ptr = FFI::MemoryPointer.new(:int32)
  found = C.from_hb_bool(
    C.hb_ot_layout_get_baseline2(
      font.ptr, baseline_tag, dir, script, lang_ptr, coord_ptr
    )
  )
  found ? coord_ptr.read_int32 : nil
end

.baseline_with_fallback(font, baseline_tag, dir, script_tag, language = nil) ⇒ Integer

Returns a baseline coordinate with fallback

Parameters:

  • font (Font)

    Font

  • baseline_tag (Integer)

    Baseline tag

  • dir (Symbol)

    Direction

  • script_tag (Integer)

    Script tag

  • language (FFI::Pointer, nil) (defaults to: nil)

    Language pointer

Returns:

  • (Integer)

    Baseline coordinate (with fallback)



383
384
385
386
387
388
389
390
# File 'lib/harfbuzz/ot/layout.rb', line 383

def baseline_with_fallback(font, baseline_tag, dir, script_tag, language = nil)
  lang_ptr = language || FFI::Pointer::NULL
  coord_ptr = FFI::MemoryPointer.new(:int32)
  C.hb_ot_layout_get_baseline_with_fallback(
    font.ptr, baseline_tag, dir, script_tag, lang_ptr, coord_ptr
  )
  coord_ptr.read_int32
end

.baseline_with_fallback2(font, baseline_tag, dir, script, language = nil) ⇒ Integer

Returns a baseline coordinate with fallback (v2: takes hb_script_t + hb_language_t)

Parameters:

  • font (Font)

    Font

  • baseline_tag (Integer)

    Baseline tag

  • dir (Symbol)

    Direction

  • script (Integer)

    Script value (hb_script_t)

  • language (FFI::Pointer, nil) (defaults to: nil)

    Language pointer

Returns:

  • (Integer)

    Baseline coordinate (with fallback)



440
441
442
443
444
445
446
447
# File 'lib/harfbuzz/ot/layout.rb', line 440

def baseline_with_fallback2(font, baseline_tag, dir, script, language = nil)
  lang_ptr = language || FFI::Pointer::NULL
  coord_ptr = FFI::MemoryPointer.new(:int32)
  C.hb_ot_layout_get_baseline_with_fallback2(
    font.ptr, baseline_tag, dir, script, lang_ptr, coord_ptr
  )
  coord_ptr.read_int32
end

.collect_features(face, table_tag, scripts: nil, languages: nil, features: nil) ⇒ HarfBuzz::Set

Collects all feature indices

Parameters:

  • face (Face)

    Font face

  • table_tag (Integer)

    GSUB or GPOS tag

Returns:



518
519
520
521
522
523
524
525
526
527
# File 'lib/harfbuzz/ot/layout.rb', line 518

def collect_features(face, table_tag, scripts: nil, languages: nil, features: nil)
  set = HarfBuzz::Set.new
  scripts_ptr   = build_tag_array_ptr(scripts)
  languages_ptr = build_tag_array_ptr(languages)
  features_ptr  = build_tag_array_ptr(features)
  C.hb_ot_layout_collect_features(
    face.ptr, table_tag, scripts_ptr, languages_ptr, features_ptr, set.ptr
  )
  set
end

.collect_lookups(face, table_tag, scripts: nil, languages: nil, features: nil) ⇒ HarfBuzz::Set

Collects all lookups referenced by features

Parameters:

  • face (Face)

    Font face

  • table_tag (Integer)

    GSUB or GPOS tag

  • scripts (Array<Integer>, nil) (defaults to: nil)

    Script tags filter (nil = all)

  • languages (Array<Integer>, nil) (defaults to: nil)

    Language tags filter (nil = all)

  • features (Array<Integer>, nil) (defaults to: nil)

    Feature tags filter (nil = all)

Returns:



503
504
505
506
507
508
509
510
511
512
# File 'lib/harfbuzz/ot/layout.rb', line 503

def collect_lookups(face, table_tag, scripts: nil, languages: nil, features: nil)
  set = HarfBuzz::Set.new
  scripts_ptr  = build_tag_array_ptr(scripts)
  languages_ptr = build_tag_array_ptr(languages)
  features_ptr  = build_tag_array_ptr(features)
  C.hb_ot_layout_collect_lookups(
    face.ptr, table_tag, scripts_ptr, languages_ptr, features_ptr, set.ptr
  )
  set
end

.feature_characters(face, table_tag, feature_index) ⇒ Array<Integer>

Returns codepoints for a named feature's characters

Parameters:

  • face (Face)

    Font face

  • table_tag (Integer)

    GSUB or GPOS tag

  • feature_index (Integer)

    Feature index

Returns:

  • (Array<Integer>)

    Codepoints



342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'lib/harfbuzz/ot/layout.rb', line 342

def feature_characters(face, table_tag, feature_index)
  count_ptr = FFI::MemoryPointer.new(:uint)
  count_ptr.write_uint(0)
  total = C.hb_ot_layout_feature_get_characters(
    face.ptr, table_tag, feature_index, 0, count_ptr, nil
  )
  return [] if total.zero?

  cps_ptr = FFI::MemoryPointer.new(:uint32, total)
  count_ptr.write_uint(total)
  C.hb_ot_layout_feature_get_characters(
    face.ptr, table_tag, feature_index, 0, count_ptr, cps_ptr
  )
  cps_ptr.read_array_of_uint32(count_ptr.read_uint)
end

.feature_indexes(face, table_tag, script_index, language_index) ⇒ Array<Integer>

Returns feature indices for a language

Parameters:

  • face (Face)

    Font face

  • table_tag (Integer)

    GSUB or GPOS tag

  • script_index (Integer)

    Script index

  • language_index (Integer)

    Language index

Returns:

  • (Array<Integer>)

    Feature indices



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/harfbuzz/ot/layout.rb', line 205

def feature_indexes(face, table_tag, script_index, language_index)
  count_ptr = FFI::MemoryPointer.new(:uint)
  count_ptr.write_uint(0)
  total = C.hb_ot_layout_language_get_feature_indexes(
    face.ptr, table_tag, script_index, language_index, 0, count_ptr, nil
  )
  return [] if total.zero?

  idx_ptr = FFI::MemoryPointer.new(:uint, total)
  count_ptr.write_uint(total)
  C.hb_ot_layout_language_get_feature_indexes(
    face.ptr, table_tag, script_index, language_index, 0, count_ptr, idx_ptr
  )
  idx_ptr.read_array_of_uint(count_ptr.read_uint)
end

.feature_lookups(face, table_tag, feature_index) ⇒ Array<Integer>

Returns lookup indices for a feature

Parameters:

  • face (Face)

    Font face

  • table_tag (Integer)

    GSUB or GPOS tag

  • feature_index (Integer)

    Feature index

Returns:

  • (Array<Integer>)

    Lookup indices



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/harfbuzz/ot/layout.rb', line 265

def feature_lookups(face, table_tag, feature_index)
  count_ptr = FFI::MemoryPointer.new(:uint)
  count_ptr.write_uint(0)
  total = C.hb_ot_layout_feature_get_lookups(
    face.ptr, table_tag, feature_index, 0, count_ptr, nil
  )
  return [] if total.zero?

  idx_ptr = FFI::MemoryPointer.new(:uint, total)
  count_ptr.write_uint(total)
  C.hb_ot_layout_feature_get_lookups(
    face.ptr, table_tag, feature_index, 0, count_ptr, idx_ptr
  )
  idx_ptr.read_array_of_uint(count_ptr.read_uint)
end

.feature_name_ids(face, table_tag, feature_index) ⇒ Hash?

Returns OpenType feature UI name IDs

Parameters:

  • face (Face)

    Font face

  • table_tag (Integer)

    GSUB or GPOS tag

  • feature_index (Integer)

    Feature index

Returns:

  • (Hash, nil)

    Name ID hash or nil



313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/harfbuzz/ot/layout.rb', line 313

def feature_name_ids(face, table_tag, feature_index)
  label_id_ptr       = FFI::MemoryPointer.new(:uint)
  tooltip_id_ptr     = FFI::MemoryPointer.new(:uint)
  sample_id_ptr      = FFI::MemoryPointer.new(:uint)
  num_params_ptr     = FFI::MemoryPointer.new(:uint)
  first_param_id_ptr = FFI::MemoryPointer.new(:uint)
  found = C.from_hb_bool(
    C.hb_ot_layout_feature_get_name_ids(
      face.ptr, table_tag, feature_index,
      label_id_ptr, tooltip_id_ptr, sample_id_ptr,
      num_params_ptr, first_param_id_ptr
    )
  )
  return nil unless found

  {
    label_id: label_id_ptr.read_uint,
    tooltip_id: tooltip_id_ptr.read_uint,
    sample_id: sample_id_ptr.read_uint,
    num_named_parameters: num_params_ptr.read_uint,
    first_param_id: first_param_id_ptr.read_uint
  }
end

.feature_tags(face, table_tag) ⇒ Array<Integer>

Returns the feature tags for a table

Parameters:

  • face (Face)

    Font face

  • table_tag (Integer)

    GSUB or GPOS tag

Returns:

  • (Array<Integer>)

    Feature tags



483
484
485
486
487
488
489
490
491
492
493
494
# File 'lib/harfbuzz/ot/layout.rb', line 483

def feature_tags(face, table_tag)
  count_ptr = FFI::MemoryPointer.new(:uint)
  count_ptr.write_uint(0)
  C.hb_ot_layout_table_get_feature_tags(face.ptr, table_tag, 0, count_ptr, nil)
  count = count_ptr.read_uint
  return [] if count.zero?

  tags_ptr = FFI::MemoryPointer.new(:uint32, count)
  count_ptr.write_uint(count)
  C.hb_ot_layout_table_get_feature_tags(face.ptr, table_tag, 0, count_ptr, tags_ptr)
  tags_ptr.read_array_of_uint32(count_ptr.read_uint)
end

.feature_tags_for_lang(face, table_tag, script_index, language_index) ⇒ Array<Integer>

Returns feature tags for a language

Parameters:

  • face (Face)

    Font face

  • table_tag (Integer)

    GSUB or GPOS tag

  • script_index (Integer)

    Script index

  • language_index (Integer)

    Language index

Returns:

  • (Array<Integer>)

    Feature tags



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/harfbuzz/ot/layout.rb', line 227

def feature_tags_for_lang(face, table_tag, script_index, language_index)
  count_ptr = FFI::MemoryPointer.new(:uint)
  count_ptr.write_uint(0)
  total = C.hb_ot_layout_language_get_feature_tags(
    face.ptr, table_tag, script_index, language_index, 0, count_ptr, nil
  )
  return [] if total.zero?

  tags_ptr = FFI::MemoryPointer.new(:uint32, total)
  count_ptr.write_uint(total)
  C.hb_ot_layout_language_get_feature_tags(
    face.ptr, table_tag, script_index, language_index, 0, count_ptr, tags_ptr
  )
  tags_ptr.read_array_of_uint32(count_ptr.read_uint)
end

.find_feature(face, table_tag, script_index, language_index, feature_tag) ⇒ Array

Finds a specific feature in a language, returns [found, feature_index]

Parameters:

  • face (Face)

    Font face

  • table_tag (Integer)

    GSUB or GPOS tag

  • script_index (Integer)

    Script index

  • language_index (Integer)

    Language index

  • feature_tag (Integer)

    Feature tag to find

Returns:

  • (Array)

    [Boolean, Integer] found and feature index



250
251
252
253
254
255
256
257
258
# File 'lib/harfbuzz/ot/layout.rb', line 250

def find_feature(face, table_tag, script_index, language_index, feature_tag)
  idx_ptr = FFI::MemoryPointer.new(:uint)
  found = C.from_hb_bool(
    C.hb_ot_layout_language_find_feature(
      face.ptr, table_tag, script_index, language_index, feature_tag, idx_ptr
    )
  )
  [found, idx_ptr.read_uint]
end

.find_script(face, table_tag, script_tag) ⇒ Array

Finds a script in the table, returns [found, index]

Parameters:

  • face (Face)

    Font face

  • table_tag (Integer)

    GSUB or GPOS tag

  • script_tag (Integer)

    Script tag to find

Returns:

  • (Array)

    [Boolean, Integer] found and script index



100
101
102
103
104
105
106
# File 'lib/harfbuzz/ot/layout.rb', line 100

def find_script(face, table_tag, script_tag)
  idx_ptr = FFI::MemoryPointer.new(:uint)
  found = C.from_hb_bool(
    C.hb_ot_layout_table_find_script(face.ptr, table_tag, script_tag, idx_ptr)
  )
  [found, idx_ptr.read_uint]
end

.font_extents(font, dir, script_tag, language = nil) ⇒ Hash?

Returns font extents from OT tables

Parameters:

  • font (Font)

    Font

  • dir (Symbol)

    Direction

  • script_tag (Integer)

    Script tag

  • language (FFI::Pointer, nil) (defaults to: nil)

    Language pointer

Returns:

  • (Hash, nil)

    Font extents hash or nil



398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# File 'lib/harfbuzz/ot/layout.rb', line 398

def font_extents(font, dir, script_tag, language = nil)
  lang_ptr = language || FFI::Pointer::NULL
  extents = C::HbFontExtentsT.new
  found = C.from_hb_bool(
    C.hb_ot_layout_get_font_extents(
      font.ptr, dir, script_tag, lang_ptr, extents.to_ptr
    )
  )
  return nil unless found

  {
    ascender: extents[:ascender],
    descender: extents[:descender],
    line_gap: extents[:line_gap]
  }
end

.font_extents2(font, dir, script, language = nil) ⇒ Hash?

Returns font extents from OT tables (v2: takes hb_script_t + hb_language_t)

Parameters:

  • font (Font)

    Font

  • dir (Symbol)

    Direction

  • script (Integer)

    Script value (hb_script_t)

  • language (FFI::Pointer, nil) (defaults to: nil)

    Language pointer

Returns:

  • (Hash, nil)

    Font extents hash or nil



455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
# File 'lib/harfbuzz/ot/layout.rb', line 455

def font_extents2(font, dir, script, language = nil)
  lang_ptr = language || FFI::Pointer::NULL
  extents = C::HbFontExtentsT.new
  found = C.from_hb_bool(
    C.hb_ot_layout_get_font_extents2(
      font.ptr, dir, script, lang_ptr, extents.to_ptr
    )
  )
  return nil unless found

  {
    ascender: extents[:ascender],
    descender: extents[:descender],
    line_gap: extents[:line_gap]
  }
end

.glyph_class(face, glyph) ⇒ Symbol

Returns the glyph class from GDEF

Parameters:

  • face (Face)

    Font face

  • glyph (Integer)

    Glyph ID

Returns:

  • (Symbol)

    Glyph class (:base_glyph, :ligature, :mark, :component)



31
32
33
# File 'lib/harfbuzz/ot/layout.rb', line 31

def glyph_class(face, glyph)
  C.hb_ot_layout_get_glyph_class(face.ptr, glyph)
end

.glyphs_in_class(face, klass) ⇒ HarfBuzz::Set

Returns all glyphs in a given GDEF class

Parameters:

  • face (Face)

    Font face

  • klass (Symbol)

    Glyph class

Returns:



39
40
41
42
43
# File 'lib/harfbuzz/ot/layout.rb', line 39

def glyphs_in_class(face, klass)
  set = HarfBuzz::Set.new
  C.hb_ot_layout_get_glyphs_in_class(face.ptr, klass, set.ptr)
  set
end

.has_glyph_classes?(face) ⇒ Boolean

Returns true if the face has GDEF glyph classes.

Parameters:

  • face (Face)

    Font face

Returns:

  • (Boolean)

    true if the face has GDEF glyph classes



11
12
13
# File 'lib/harfbuzz/ot/layout.rb', line 11

def has_glyph_classes?(face)
  C.from_hb_bool(C.hb_ot_layout_has_glyph_classes(face.ptr))
end

.has_positioning?(face) ⇒ Boolean

Returns true if the face has a GPOS table.

Parameters:

  • face (Face)

    Font face

Returns:

  • (Boolean)

    true if the face has a GPOS table



23
24
25
# File 'lib/harfbuzz/ot/layout.rb', line 23

def has_positioning?(face)
  C.from_hb_bool(C.hb_ot_layout_has_positioning(face.ptr))
end

.has_substitution?(face) ⇒ Boolean

Returns true if the face has a GSUB table.

Parameters:

  • face (Face)

    Font face

Returns:

  • (Boolean)

    true if the face has a GSUB table



17
18
19
# File 'lib/harfbuzz/ot/layout.rb', line 17

def has_substitution?(face)
  C.from_hb_bool(C.hb_ot_layout_has_substitution(face.ptr))
end

.horizontal_baseline_tag_for_script(script) ⇒ Integer

Returns the horizontal baseline tag for a script

Parameters:

  • script (Integer)

    Script value

Returns:

  • (Integer)

    Baseline tag



475
476
477
# File 'lib/harfbuzz/ot/layout.rb', line 475

def horizontal_baseline_tag_for_script(script)
  C.hb_ot_layout_get_horizontal_baseline_tag_for_script(script)
end

.language_tags(face, table_tag, script_index) ⇒ Array<Integer>

Returns language tags for a script

Parameters:

  • face (Face)

    Font face

  • table_tag (Integer)

    GSUB or GPOS tag

  • script_index (Integer)

    Script index

Returns:

  • (Array<Integer>)

    Language tags



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/harfbuzz/ot/layout.rb', line 131

def language_tags(face, table_tag, script_index)
  count_ptr = FFI::MemoryPointer.new(:uint)
  count_ptr.write_uint(0)
  total = C.hb_ot_layout_script_get_language_tags(
    face.ptr, table_tag, script_index, 0, count_ptr, nil
  )
  return [] if total.zero?

  tags_ptr = FFI::MemoryPointer.new(:uint32, total)
  count_ptr.write_uint(total)
  C.hb_ot_layout_script_get_language_tags(
    face.ptr, table_tag, script_index, 0, count_ptr, tags_ptr
  )
  tags_ptr.read_array_of_uint32(count_ptr.read_uint)
end

.ligature_carets(font, dir, glyph) ⇒ Array<Integer>

Returns ligature caret positions for a glyph

Parameters:

  • font (Font)

    Font

  • dir (Symbol)

    Direction (:ltr, :rtl)

  • glyph (Integer)

    Glyph ID

Returns:

  • (Array<Integer>)

    Caret positions



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/harfbuzz/ot/layout.rb', line 83

def ligature_carets(font, dir, glyph)
  count_ptr = FFI::MemoryPointer.new(:uint)
  count_ptr.write_uint(0)
  total = C.hb_ot_layout_get_ligature_carets(font.ptr, dir, glyph, 0, count_ptr, nil)
  return [] if total.zero?

  carets_ptr = FFI::MemoryPointer.new(:int32, total)
  count_ptr.write_uint(total)
  C.hb_ot_layout_get_ligature_carets(font.ptr, dir, glyph, 0, count_ptr, carets_ptr)
  carets_ptr.read_array_of_int32(count_ptr.read_uint)
end

.required_feature(face, table_tag, script_index, language_index) ⇒ Array?

Returns [feature_index, feature_tag] for the required feature, or nil

Parameters:

  • face (Face)

    Font face

  • table_tag (Integer)

    GSUB or GPOS tag

  • script_index (Integer)

    Script index

  • language_index (Integer)

    Language index

Returns:

  • (Array, nil)

    [feature_index, feature_tag] or nil



188
189
190
191
192
193
194
195
196
197
# File 'lib/harfbuzz/ot/layout.rb', line 188

def required_feature(face, table_tag, script_index, language_index)
  idx_ptr = FFI::MemoryPointer.new(:uint)
  tag_ptr = FFI::MemoryPointer.new(:uint32)
  found = C.from_hb_bool(
    C.hb_ot_layout_language_get_required_feature(
      face.ptr, table_tag, script_index, language_index, idx_ptr, tag_ptr
    )
  )
  found ? [idx_ptr.read_uint, tag_ptr.read_uint32] : nil
end

.required_feature_index(face, table_tag, script_index, language_index) ⇒ Integer?

Returns the required feature index for a language, or nil if none

Parameters:

  • face (Face)

    Font face

  • table_tag (Integer)

    GSUB or GPOS tag

  • script_index (Integer)

    Script index

  • language_index (Integer)

    Language index

Returns:

  • (Integer, nil)

    Feature index or nil



172
173
174
175
176
177
178
179
180
# File 'lib/harfbuzz/ot/layout.rb', line 172

def required_feature_index(face, table_tag, script_index, language_index)
  idx_ptr = FFI::MemoryPointer.new(:uint)
  found = C.from_hb_bool(
    C.hb_ot_layout_language_get_required_feature_index(
      face.ptr, table_tag, script_index, language_index, idx_ptr
    )
  )
  found ? idx_ptr.read_uint : nil
end

.script_tags(face, table_tag) ⇒ Array<Integer>

Returns the script tags for a table

Parameters:

  • face (Face)

    Font face

  • table_tag (Integer)

    GSUB (0x47535542) or GPOS (0x47504F53)

Returns:

  • (Array<Integer>)

    Script tags



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/harfbuzz/ot/layout.rb', line 49

def script_tags(face, table_tag)
  count_ptr = FFI::MemoryPointer.new(:uint)
  count_ptr.write_uint(0)
  C.hb_ot_layout_table_get_script_tags(face.ptr, table_tag, 0, count_ptr, nil)
  count = count_ptr.read_uint
  return [] if count.zero?

  tags_ptr = FFI::MemoryPointer.new(:uint32, count)
  count_ptr.write_uint(count)
  C.hb_ot_layout_table_get_script_tags(face.ptr, table_tag, 0, count_ptr, tags_ptr)
  tags_ptr.read_array_of_uint32(count_ptr.read_uint)
end

.select_language(face, table_tag, script_index, language_tags) ⇒ Array

Selects the best matching language, returns [found, language_index]

Parameters:

  • face (Face)

    Font face

  • table_tag (Integer)

    GSUB or GPOS tag

  • script_index (Integer)

    Script index

  • language_tags (Array<Integer>)

    Candidate language tags

Returns:

  • (Array)

    [Boolean, Integer] found and language index



153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/harfbuzz/ot/layout.rb', line 153

def select_language(face, table_tag, script_index, language_tags)
  tags_ptr = FFI::MemoryPointer.new(:uint32, language_tags.size)
  tags_ptr.put_array_of_uint32(0, language_tags)
  lang_idx_ptr = FFI::MemoryPointer.new(:uint)
  found = C.from_hb_bool(
    C.hb_ot_layout_script_select_language(
      face.ptr, table_tag, script_index,
      language_tags.size, tags_ptr, lang_idx_ptr
    )
  )
  [found, lang_idx_ptr.read_uint]
end

.select_script(face, table_tag, script_tags) ⇒ Array

Selects the best matching script from a list

Parameters:

  • face (Face)

    Font face

  • table_tag (Integer)

    GSUB or GPOS tag

  • script_tags (Array<Integer>)

    Candidate script tags (in preference order)

Returns:

  • (Array)

    [Boolean, Integer, Integer] exact_match, script_index, chosen_script_tag



113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/harfbuzz/ot/layout.rb', line 113

def select_script(face, table_tag, script_tags)
  tags_ptr = FFI::MemoryPointer.new(:uint32, script_tags.size)
  tags_ptr.put_array_of_uint32(0, script_tags)
  idx_ptr = FFI::MemoryPointer.new(:uint)
  chosen_tag_ptr = FFI::MemoryPointer.new(:uint32)
  exact = C.from_hb_bool(
    C.hb_ot_layout_table_select_script(
      face.ptr, table_tag, script_tags.size, tags_ptr, idx_ptr, chosen_tag_ptr
    )
  )
  [exact, idx_ptr.read_uint, chosen_tag_ptr.read_uint32]
end

.size_params(face) ⇒ Hash?

Returns size design parameters for the face

Parameters:

  • face (Face)

    Font face

Returns:

  • (Hash, nil)

    Size params hash or nil if not available



284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/harfbuzz/ot/layout.rb', line 284

def size_params(face)
  design_size_ptr    = FFI::MemoryPointer.new(:uint)
  subfamily_id_ptr   = FFI::MemoryPointer.new(:uint)
  name_id_ptr        = FFI::MemoryPointer.new(:uint)
  range_start_ptr    = FFI::MemoryPointer.new(:uint)
  range_end_ptr      = FFI::MemoryPointer.new(:uint)
  found = C.from_hb_bool(
    C.hb_ot_layout_get_size_params(
      face.ptr,
      design_size_ptr, subfamily_id_ptr, name_id_ptr,
      range_start_ptr, range_end_ptr
    )
  )
  return nil unless found

  {
    design_size: design_size_ptr.read_uint,
    subfamily_id: subfamily_id_ptr.read_uint,
    subfamily_name_id: name_id_ptr.read_uint,
    range_start: range_start_ptr.read_uint,
    range_end: range_end_ptr.read_uint
  }
end

.tag_to_language(tag) ⇒ FFI::Pointer

Converts an OT tag to a language pointer

Parameters:

  • tag (Integer)

    Language tag

Returns:

  • (FFI::Pointer)

    Language pointer



561
562
563
# File 'lib/harfbuzz/ot/layout.rb', line 561

def tag_to_language(tag)
  C.hb_ot_tag_to_language(tag)
end

.tag_to_script(tag) ⇒ Integer

Converts an OT tag to a script value

Parameters:

  • tag (Integer)

    Script tag

Returns:

  • (Integer)

    Script value



568
569
570
# File 'lib/harfbuzz/ot/layout.rb', line 568

def tag_to_script(tag)
  C.hb_ot_tag_to_script(tag)
end

.tags_from_script_and_language(script, language) ⇒ Array<Array<Integer>>

Converts script+language to OT tags

Parameters:

  • script (Integer)

    Script value

  • language (FFI::Pointer)

    Language pointer

Returns:

  • (Array<Array<Integer>>)

    [script_tags, language_tags]



533
534
535
536
537
538
539
540
541
542
543
544
545
# File 'lib/harfbuzz/ot/layout.rb', line 533

def tags_from_script_and_language(script, language)
  s_count = FFI::MemoryPointer.new(:uint)
  l_count = FFI::MemoryPointer.new(:uint)
  s_count.write_uint(8)
  l_count.write_uint(8)
  s_tags = FFI::MemoryPointer.new(:uint32, 8)
  l_tags = FFI::MemoryPointer.new(:uint32, 8)
  C.hb_ot_tags_from_script_and_language(script, language, s_count, s_tags, l_count, l_tags)
  [
    s_tags.read_array_of_uint32(s_count.read_uint),
    l_tags.read_array_of_uint32(l_count.read_uint)
  ]
end

.tags_to_script_and_language(script_tag, language_tag) ⇒ Array

Converts OT tags to script + language

Parameters:

  • script_tag (Integer)

    OT script tag

  • language_tag (Integer)

    OT language tag

Returns:

  • (Array)

    [script, language_ptr]



551
552
553
554
555
556
# File 'lib/harfbuzz/ot/layout.rb', line 551

def tags_to_script_and_language(script_tag, language_tag)
  script_ptr = FFI::MemoryPointer.new(:uint32)
  lang_ptr = FFI::MemoryPointer.new(:pointer)
  C.hb_ot_tags_to_script_and_language(script_tag, language_tag, script_ptr, lang_ptr)
  [script_ptr.read_uint32, lang_ptr.read_pointer]
end