Module: EideticPDF::AFM

Defined in:
lib/epdfafm.rb

Overview

:nodoc: all

Defined Under Namespace

Classes: AdobeFontMetrics, AfmChar, Codepoints, Glyphs

Constant Summary collapse

FontPath =
[File.join(File.dirname(__FILE__), '..', 'fonts')]

Class Method Summary collapse

Class Method Details

.find_font(family, weight = '', style = '') ⇒ Object



304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/epdfafm.rb', line 304

def find_font(family, weight='', style='')
  italic = (style =~ /Italic|Oblique/i) ? '(Italic|Obl(ique)?)' : ''
  weight_style = "#{weight}#{italic}"
  re_s = '^' + family
  if weight_style.empty?
    re_s << '(-Roman)?'
  else
    re_s << '-' << weight_style
  end
  re_s << '$'
  re = Regexp.new(re_s, Regexp::IGNORECASE)
  afm = AdobeFontMetrics.find_font(re)
end

.font_metrics(name, options = {}) ⇒ Object

Raises:

  • (Exception)


318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/epdfafm.rb', line 318

def font_metrics(name, options={})
  afm = find_font(name, options[:weight], options[:style])
  raise Exception.new("Unknown font %s." % name) if afm.nil?
  encoding = (afm.encoding_scheme == 'FontSpecific') ? nil : options[:encoding] || 'WinAnsiEncoding'
  needs_descriptor = afm.needs_descriptor(encoding)
  differences = afm.differences(encoding)
  widths = afm.widths(encoding)
  cwidths = widths.compact.extend(Statistics)
  fm = PdfK::FontMetrics.new(needs_descriptor, widths, afm.ascender, afm.descender, afm.flags, afm.font_b_box, afm.missing_width,
    afm.std_v_w, afm.std_h_w, afm.italic_angle, afm.cap_height, afm.x_height, afm.leading, cwidths.max, cwidths.mean.round,
    afm.underline_position, afm.underline_thickness, differences)
  fm
end

.font_names(reload = false) ⇒ Object



336
337
338
# File 'lib/epdfafm.rb', line 336

def font_names(reload=false)
  AdobeFontMetrics.afm_cache(reload).map { |afm| afm.font_name }
end

.font_weights(family_name) ⇒ Object



332
333
334
# File 'lib/epdfafm.rb', line 332

def font_weights(family_name)
  AdobeFontMetrics.find_fonts(:family_name => family_name).map { |afm| afm.weight }.sort.uniq
end