Module: HarfBuzz::OT::Color
- Defined in:
- lib/harfbuzz/ot/color.rb
Overview
OpenType Color Fonts API (CPAL, COLR, SVG, CBDT/CBLC)
Class Method Summary collapse
-
.glyph_has_paint?(face, glyph) ⇒ Boolean
True if glyph has COLRv1 paint data.
-
.glyph_layers(face, glyph) ⇒ Array<C::HbOtColorLayerT>
Returns COLR layers for a glyph.
-
.glyph_png(font, glyph) ⇒ Blob
Returns the PNG blob for a glyph at a given size.
-
.glyph_svg(face, glyph) ⇒ Blob
Returns the SVG blob for a glyph.
-
.has_layers?(face) ⇒ Boolean
True if face has COLR layers.
-
.has_paint?(face) ⇒ Boolean
True if face has COLRv1 paint data.
-
.has_palettes?(face) ⇒ Boolean
True if the face has CPAL color palettes.
-
.has_png?(face) ⇒ Boolean
True if face has PNG glyphs.
-
.has_svg?(face) ⇒ Boolean
True if face has SVG glyphs.
-
.palette_color_name_id(face, idx) ⇒ Integer
Name ID.
-
.palette_colors(face, idx) ⇒ Array<Integer>
Returns colors in a palette.
-
.palette_count(face) ⇒ Integer
Number of palettes.
-
.palette_flags(face, idx) ⇒ Integer
Palette flags bitmask.
-
.palette_name_id(face, idx) ⇒ Integer
Name ID.
Class Method Details
.glyph_has_paint?(face, glyph) ⇒ Boolean
Returns true if glyph has COLRv1 paint data.
120 121 122 |
# File 'lib/harfbuzz/ot/color.rb', line 120 def glyph_has_paint?(face, glyph) C.from_hb_bool(C.hb_ot_color_glyph_has_paint(face.ptr, glyph)) end |
.glyph_layers(face, glyph) ⇒ Array<C::HbOtColorLayerT>
Returns COLR layers for a glyph
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/harfbuzz/ot/color.rb', line 69 def glyph_layers(face, glyph) count_ptr = FFI::MemoryPointer.new(:uint) count_ptr.write_uint(0) C.hb_ot_color_glyph_get_layers(face.ptr, glyph, 0, count_ptr, nil) count = count_ptr.read_uint return [] if count.zero? layers_ptr = FFI::MemoryPointer.new(C::HbOtColorLayerT, count) count_ptr.write_uint(count) C.hb_ot_color_glyph_get_layers(face.ptr, glyph, 0, count_ptr, layers_ptr) actual = count_ptr.read_uint actual.times.map { |i| C::HbOtColorLayerT.new(layers_ptr + i * C::HbOtColorLayerT.size) } end |
.glyph_png(font, glyph) ⇒ Blob
Returns the PNG blob for a glyph at a given size
107 108 109 |
# File 'lib/harfbuzz/ot/color.rb', line 107 def glyph_png(font, glyph) Blob.wrap_owned(C.hb_ot_color_glyph_reference_png(font.ptr, glyph)) end |
.glyph_svg(face, glyph) ⇒ Blob
Returns the SVG blob for a glyph
93 94 95 |
# File 'lib/harfbuzz/ot/color.rb', line 93 def glyph_svg(face, glyph) Blob.wrap_owned(C.hb_ot_color_glyph_reference_svg(face.ptr, glyph)) end |
.has_layers?(face) ⇒ Boolean
Returns true if face has COLR layers.
61 62 63 |
# File 'lib/harfbuzz/ot/color.rb', line 61 def has_layers?(face) C.from_hb_bool(C.hb_ot_color_has_layers(face.ptr)) end |
.has_paint?(face) ⇒ Boolean
Returns true if face has COLRv1 paint data.
113 114 115 |
# File 'lib/harfbuzz/ot/color.rb', line 113 def has_paint?(face) C.from_hb_bool(C.hb_ot_color_has_paint(face.ptr)) end |
.has_palettes?(face) ⇒ Boolean
Returns true if the face has CPAL color palettes.
11 12 13 |
# File 'lib/harfbuzz/ot/color.rb', line 11 def has_palettes?(face) C.from_hb_bool(C.hb_ot_color_has_palettes(face.ptr)) end |
.has_png?(face) ⇒ Boolean
Returns true if face has PNG glyphs.
99 100 101 |
# File 'lib/harfbuzz/ot/color.rb', line 99 def has_png?(face) C.from_hb_bool(C.hb_ot_color_has_png(face.ptr)) end |
.has_svg?(face) ⇒ Boolean
Returns true if face has SVG glyphs.
85 86 87 |
# File 'lib/harfbuzz/ot/color.rb', line 85 def has_svg?(face) C.from_hb_bool(C.hb_ot_color_has_svg(face.ptr)) end |
.palette_color_name_id(face, idx) ⇒ Integer
Returns Name ID.
31 32 33 |
# File 'lib/harfbuzz/ot/color.rb', line 31 def palette_color_name_id(face, idx) C.hb_ot_color_palette_color_get_name_id(face.ptr, idx) end |
.palette_colors(face, idx) ⇒ Array<Integer>
Returns colors in a palette
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/harfbuzz/ot/color.rb', line 46 def palette_colors(face, idx) count_ptr = FFI::MemoryPointer.new(:uint) count_ptr.write_uint(0) C.hb_ot_color_palette_get_colors(face.ptr, idx, 0, count_ptr, nil) count = count_ptr.read_uint return [] if count.zero? colors_ptr = FFI::MemoryPointer.new(:uint32, count) count_ptr.write_uint(count) C.hb_ot_color_palette_get_colors(face.ptr, idx, 0, count_ptr, colors_ptr) colors_ptr.read_array_of_uint32(count_ptr.read_uint) end |
.palette_count(face) ⇒ Integer
Returns Number of palettes.
17 18 19 |
# File 'lib/harfbuzz/ot/color.rb', line 17 def palette_count(face) C.hb_ot_color_palette_get_count(face.ptr) end |
.palette_flags(face, idx) ⇒ Integer
Returns Palette flags bitmask.
38 39 40 |
# File 'lib/harfbuzz/ot/color.rb', line 38 def palette_flags(face, idx) C.hb_ot_color_palette_get_flags(face.ptr, idx) end |
.palette_name_id(face, idx) ⇒ Integer
Returns Name ID.
24 25 26 |
# File 'lib/harfbuzz/ot/color.rb', line 24 def palette_name_id(face, idx) C.hb_ot_color_palette_get_name_id(face.ptr, idx) end |