Class: Pdfrb::Font::Metrics

Inherits:
Struct
  • Object
show all
Defined in:
lib/pdfrb/font/metrics_helper.rb

Overview

Metrics value object + lookup helper. Returns ascent/descent/ cap_height/x_height/line_gap/avg_width for any font (Standard 14 via AFM, embedded TTF/OTF via head/hhea/OS2 tables).

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ascentObject

Returns the value of attribute ascent

Returns:

  • (Object)

    the current value of ascent



8
9
10
# File 'lib/pdfrb/font/metrics_helper.rb', line 8

def ascent
  @ascent
end

#avg_widthObject

Returns the value of attribute avg_width

Returns:

  • (Object)

    the current value of avg_width



8
9
10
# File 'lib/pdfrb/font/metrics_helper.rb', line 8

def avg_width
  @avg_width
end

#bboxObject

Returns the value of attribute bbox

Returns:

  • (Object)

    the current value of bbox



8
9
10
# File 'lib/pdfrb/font/metrics_helper.rb', line 8

def bbox
  @bbox
end

#cap_heightObject

Returns the value of attribute cap_height

Returns:

  • (Object)

    the current value of cap_height



8
9
10
# File 'lib/pdfrb/font/metrics_helper.rb', line 8

def cap_height
  @cap_height
end

#descentObject

Returns the value of attribute descent

Returns:

  • (Object)

    the current value of descent



8
9
10
# File 'lib/pdfrb/font/metrics_helper.rb', line 8

def descent
  @descent
end

#font_nameObject

Returns the value of attribute font_name

Returns:

  • (Object)

    the current value of font_name



8
9
10
# File 'lib/pdfrb/font/metrics_helper.rb', line 8

def font_name
  @font_name
end

#italic_angleObject

Returns the value of attribute italic_angle

Returns:

  • (Object)

    the current value of italic_angle



8
9
10
# File 'lib/pdfrb/font/metrics_helper.rb', line 8

def italic_angle
  @italic_angle
end

#line_gapObject

Returns the value of attribute line_gap

Returns:

  • (Object)

    the current value of line_gap



8
9
10
# File 'lib/pdfrb/font/metrics_helper.rb', line 8

def line_gap
  @line_gap
end

#max_widthObject

Returns the value of attribute max_width

Returns:

  • (Object)

    the current value of max_width



8
9
10
# File 'lib/pdfrb/font/metrics_helper.rb', line 8

def max_width
  @max_width
end

#stem_vObject

Returns the value of attribute stem_v

Returns:

  • (Object)

    the current value of stem_v



8
9
10
# File 'lib/pdfrb/font/metrics_helper.rb', line 8

def stem_v
  @stem_v
end

#units_per_emObject

Returns the value of attribute units_per_em

Returns:

  • (Object)

    the current value of units_per_em



8
9
10
# File 'lib/pdfrb/font/metrics_helper.rb', line 8

def units_per_em
  @units_per_em
end

#x_heightObject

Returns the value of attribute x_height

Returns:

  • (Object)

    the current value of x_height



8
9
10
# File 'lib/pdfrb/font/metrics_helper.rb', line 8

def x_height
  @x_height
end

Instance Method Details

#ascender(font_size) ⇒ Object



17
18
19
# File 'lib/pdfrb/font/metrics_helper.rb', line 17

def ascender(font_size)
  (ascent || 800) * font_size.to_f / (units_per_em || 1000)
end

#descender(font_size) ⇒ Object



21
22
23
# File 'lib/pdfrb/font/metrics_helper.rb', line 21

def descender(font_size)
  (descent || -200) * font_size.to_f / (units_per_em || 1000)
end

#line_height(font_size) ⇒ Object



12
13
14
15
# File 'lib/pdfrb/font/metrics_helper.rb', line 12

def line_height(font_size)
  ((ascent || 800) - (descent || -200) + (line_gap || 0)) *
    font_size.to_f / (units_per_em || 1000)
end