Class: Krill::AFM

Inherits:
Struct
  • Object
show all
Defined in:
lib/krill/afm.rb

Defined Under Namespace

Classes: WinAnsi

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ AFM

Returns a new instance of AFM.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/krill/afm.rb', line 9

def initialize(filename)
  super

  data = parse(filename)

  @character_widths = data.fetch(:character_widths)
  @kernings = data.fetch(:kernings)
  attributes = data.fetch(:attributes)

  bbox = attributes['fontbbox'].split(/\s+/).map { |e| Integer(e) }
  line_height = Float(bbox[3] - bbox[1]) / 1000.0

  @name = attributes['fontname']
  @family = attributes['familyname']
  @ascender = attributes['ascender'].to_i / 1000.0
  @descender = attributes['descender'].to_i / 1000.0
  @line_gap = line_height - (ascender - descender)
end

Instance Attribute Details

#ascenderObject (readonly)

Returns the value of attribute ascender.



3
4
5
# File 'lib/krill/afm.rb', line 3

def ascender
  @ascender
end

#character_widthsObject (readonly)

Returns the value of attribute character_widths.



3
4
5
# File 'lib/krill/afm.rb', line 3

def character_widths
  @character_widths
end

#descenderObject (readonly)

Returns the value of attribute descender.



3
4
5
# File 'lib/krill/afm.rb', line 3

def descender
  @descender
end

#familyObject (readonly)

Returns the value of attribute family.



3
4
5
# File 'lib/krill/afm.rb', line 3

def family
  @family
end

#filenameObject

Returns the value of attribute filename

Returns:

  • (Object)

    the current value of filename



2
3
4
# File 'lib/krill/afm.rb', line 2

def filename
  @filename
end

#kerningsObject (readonly)

Returns the value of attribute kernings.



3
4
5
# File 'lib/krill/afm.rb', line 3

def kernings
  @kernings
end

#line_gapObject (readonly)

Returns the value of attribute line_gap.



3
4
5
# File 'lib/krill/afm.rb', line 3

def line_gap
  @line_gap
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/krill/afm.rb', line 3

def name
  @name
end

Class Method Details

.open(filename) ⇒ Object



5
6
7
# File 'lib/krill/afm.rb', line 5

def self.open(filename)
  new filename
end

Instance Method Details

#bold?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/krill/afm.rb', line 28

def bold?
  name["Bold"].present?
end

#italic?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/krill/afm.rb', line 32

def italic?
  name["Italic"].present?
end

#unicode?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/krill/afm.rb', line 36

def unicode?
  false
end