Class: DragonflyFonts::Analysers::Bbox

Inherits:
Object
  • Object
show all
Defined in:
lib/dragonfly_fonts/analysers/bbox.rb

Instance Method Summary collapse

Instance Method Details

#call(content, glyph) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dragonfly_fonts/analysers/bbox.rb', line 6

def call(content, glyph)
  return {} unless content.ext
  return {} unless FONT_FORGE_SUPPORTED_FORMATS.include?(content.ext.downcase)

  res = content.shell_eval do |path|
    "#{fontforge_command} -lang=ff -c 'Open($1); Select(\"#{glyph}\"); Print(GlyphInfo(\"BBox\"));' #{path}"
  end

  return {} unless res.present?

  dimensions = JSON.parse(res)

  Struct::Bbox.new(
    glyph,
    dimensions[0],
    dimensions[1],
    dimensions[2],
    dimensions[3],
    (dimensions[2] - dimensions[0]),
    (dimensions[3] - dimensions[1])
  )
end