Class: Pdfrb::Model::Type::Font

Inherits:
Cos::Dictionary show all
Defined in:
lib/pdfrb/model/type/font.rb

Instance Attribute Summary

Attributes inherited from Object

#document, #gen, #oid, #value

Instance Method Summary collapse

Methods inherited from Cos::Dictionary

#[], #[]=, arlington_available?, arlington_default, arlington_key_to_symbol, arlington_loaded_for?, arlington_mark_loaded, arlington_object, arlington_one_type_to_ruby, arlington_required?, arlington_types_to_ruby, arlington_version, define_field, define_field_from_arlington, #delete, #each, each_field, #each_raw, #empty?, field, #initialize, #key?, #keys, lookup_type, own_fields, #pdf_type, register_type, type_map, #validate

Methods inherited from Object

#==, define_type, #deref, #indirect?, #initialize, #must_be_indirect?, #pdf_type, pdf_type

Constructor Details

This class inherits a constructor from Pdfrb::Model::Cos::Dictionary

Instance Method Details

#base_fontObject



10
# File 'lib/pdfrb/model/type/font.rb', line 10

def base_font; self[:BaseFont]; end

#cid?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/pdfrb/model/type/font.rb', line 42

def cid?
  subtype&.to_sym == :Type0
end

#descendant_fontObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/pdfrb/model/type/font.rb', line 50

def descendant_font
  return nil unless cid?

  ref = self[:DescendantFonts]
  return nil unless ref

  arr = if ref.is_a?(Pdfrb::Model::Reference) && document
          document.object(ref)
        else
          ref
        end
  return nil unless arr.is_a?(Array) || arr.is_a?(Pdfrb::Model::PdfArray)

  first = arr[0]
  return nil unless first

  if first.is_a?(Pdfrb::Model::Reference) && document
    document.object(first)
  else
    first
  end
end

#embedded?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
# File 'lib/pdfrb/model/type/font.rb', line 24

def embedded?
  fd = font_descriptor
  return false unless fd

  !!(fd.value[:FontFile] || fd.value[:FontFile2] || fd.value[:FontFile3])
end

#encodingObject



11
# File 'lib/pdfrb/model/type/font.rb', line 11

def encoding; self[:Encoding]; end

#first_charObject



12
# File 'lib/pdfrb/model/type/font.rb', line 12

def first_char; self[:FirstChar]; end

#font_descriptorObject



17
18
19
20
21
22
# File 'lib/pdfrb/model/type/font.rb', line 17

def font_descriptor
  ref = self[:FontDescriptor]
  return nil unless ref

  document ? document.object(ref) : ref
end

#font_fileObject



31
32
33
34
35
36
# File 'lib/pdfrb/model/type/font.rb', line 31

def font_file
  fd = font_descriptor
  return nil unless fd

  fd.value[:FontFile2] || fd.value[:FontFile3] || fd.value[:FontFile]
end

#glyph_width(char_code) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/pdfrb/model/type/font.rb', line 73

def glyph_width(char_code)
  return nil unless widths && first_char && last_char

  idx = char_code - first_char
  return nil if idx.negative? || idx >= widths.length

  widths[idx]
end

#last_charObject



13
# File 'lib/pdfrb/model/type/font.rb', line 13

def last_char; self[:LastChar]; end

#simple?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/pdfrb/model/type/font.rb', line 38

def simple?
  [:Type1, :TrueType, :MMType1].include?(subtype&.to_sym)
end

#subtypeObject



9
# File 'lib/pdfrb/model/type/font.rb', line 9

def subtype; self[:Subtype]; end

#to_unicodeObject



15
# File 'lib/pdfrb/model/type/font.rb', line 15

def to_unicode; self[:ToUnicode]; end

#type3?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/pdfrb/model/type/font.rb', line 46

def type3?
  subtype&.to_sym == :Type3
end

#widthsObject



14
# File 'lib/pdfrb/model/type/font.rb', line 14

def widths; self[:Widths]; end