Module: FontMetrics

Defined in:
lib/rsyntaxtree/utils.rb

Class Method Summary collapse

Class Method Details

.get_metrics(text, font, fontsize, font_style, font_weight) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rsyntaxtree/utils.rb', line 42

def get_metrics(text, font, fontsize, font_style, font_weight)
  background = Magick::Image.new(1, 1)
  gc = Magick::Draw.new
  gc.annotate(background, 0, 0, 0, 0, text) do |gca|
    gca.font = font
    gca.font_style = font_style == :italic ? Magick::ItalicStyle : Magick::NormalStyle
    gca.font_weight = font_weight == :bold ? Magick::BoldWeight : Magick::NormalWeight
    gca.pointsize = fontsize
    gca.gravity = Magick::CenterGravity
    gca.stroke = 'none'
    gca.kerning = 0
    gca.interline_spacing = 0
    gca.interword_spacing = 0
  end
  gc.get_multiline_type_metrics(background, text)
end