Class: EideticPDF::AFM::Glyphs

Inherits:
Object
  • Object
show all
Defined in:
lib/epdfafm.rb

Class Method Summary collapse

Class Method Details

.differences_for_encodings(encoding1, encoding2) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/epdfafm.rb', line 54

def self.differences_for_encodings(encoding1, encoding2)
  @@glyph_differences_for_encodings ||= {}
  key = "#{encoding1}-#{encoding2}"
  result = @@glyph_differences_for_encodings[key]
  if result.nil?
    glyphs1, glyphs2 = for_encoding(encoding1), for_encoding(encoding2)
    diffs = []
    same = true
    1.upto(255) do |i|
      if same
        if (glyphs1[i] != glyphs2[i]) and !glyphs2[i].nil?
          same = false
          diffs << PdfObjects::PdfInteger.new(i)
          diffs << PdfObjects::PdfName.new(glyphs2[i])
        end
      else
        if glyphs1[i] == glyphs2[i]
          same = true
        else
          diffs << PdfObjects::PdfName.new(glyphs2[i])
        end
      end
    end
    result = @@glyph_differences_for_encodings[key] = PdfObjects::PdfArray.new(diffs)
  end
  result
end

.for_codepoints(codepoints) ⇒ Object



37
38
39
# File 'lib/epdfafm.rb', line 37

def self.for_codepoints(codepoints)
  codepoints.map { |codepoint| PdfK::glyph_name(codepoint) }
end

.for_encoding(encoding) ⇒ Object



41
42
43
44
# File 'lib/epdfafm.rb', line 41

def self.for_encoding(encoding)
  @@glyphs_by_encoding ||= {}
  @@glyphs_by_encoding[encoding] ||= for_codepoints(Codepoints.for_encoding(encoding))
end

.widths_for_encoding(encoding, chars_by_name) ⇒ Object



50
51
52
# File 'lib/epdfafm.rb', line 50

def self.widths_for_encoding(encoding, chars_by_name)
  widths_for_glyphs(for_encoding(encoding), chars_by_name)
end

.widths_for_glyphs(glyphs, chars_by_name) ⇒ Object



46
47
48
# File 'lib/epdfafm.rb', line 46

def self.widths_for_glyphs(glyphs, chars_by_name)
  glyphs.map { |glyph| (ch = chars_by_name[glyph]) ? ch.width : 0 }
end