Class: Pdfrb::Font::CFF::File

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfrb/font/cff/file.rb

Overview

Parsed CFF table (TN5176). Exposes the pieces a subsetter needs: header span, Name/String/Global-Subr INDEXes, Top DICT, charset (format 0), CharStrings INDEX, Private DICT span, and the Local Subr INDEX when present.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ File

Returns a new instance of File.



16
17
18
19
# File 'lib/pdfrb/font/cff/file.rb', line 16

def initialize(data)
  @data = data.b
  parse
end

Instance Attribute Details

#charset_formatObject (readonly)

Returns the value of attribute charset_format.



11
12
13
# File 'lib/pdfrb/font/cff/file.rb', line 11

def charset_format
  @charset_format
end

#charset_sidsObject (readonly)

Returns the value of attribute charset_sids.



11
12
13
# File 'lib/pdfrb/font/cff/file.rb', line 11

def charset_sids
  @charset_sids
end

#charstringsObject (readonly)

Returns the value of attribute charstrings.



11
12
13
# File 'lib/pdfrb/font/cff/file.rb', line 11

def charstrings
  @charstrings
end

#dataObject (readonly)

Returns the value of attribute data.



11
12
13
# File 'lib/pdfrb/font/cff/file.rb', line 11

def data
  @data
end

#global_subrsObject (readonly)

Returns the value of attribute global_subrs.



11
12
13
# File 'lib/pdfrb/font/cff/file.rb', line 11

def global_subrs
  @global_subrs
end

#header_sizeObject (readonly)

Returns the value of attribute header_size.



11
12
13
# File 'lib/pdfrb/font/cff/file.rb', line 11

def header_size
  @header_size
end

#local_subrsObject (readonly)

Returns the value of attribute local_subrs.



11
12
13
# File 'lib/pdfrb/font/cff/file.rb', line 11

def local_subrs
  @local_subrs
end

#name_indexObject (readonly)

Returns the value of attribute name_index.



11
12
13
# File 'lib/pdfrb/font/cff/file.rb', line 11

def name_index
  @name_index
end

#private_spanObject (readonly)

Returns the value of attribute private_span.



11
12
13
# File 'lib/pdfrb/font/cff/file.rb', line 11

def private_span
  @private_span
end

#string_indexObject (readonly)

Returns the value of attribute string_index.



11
12
13
# File 'lib/pdfrb/font/cff/file.rb', line 11

def string_index
  @string_index
end

#top_dictObject (readonly)

Returns the value of attribute top_dict.



11
12
13
# File 'lib/pdfrb/font/cff/file.rb', line 11

def top_dict
  @top_dict
end

Instance Method Details

#charstring(gid) ⇒ Object



25
26
27
# File 'lib/pdfrb/font/cff/file.rb', line 25

def charstring(gid)
  charstrings[gid] if charstrings
end

#gid_for_sid(sid) ⇒ Object

Reverse charset: SID -> gid (first wins).



38
39
40
41
42
43
44
45
# File 'lib/pdfrb/font/cff/file.rb', line 38

def gid_for_sid(sid)
  @gid_by_sid ||= begin
    map = { 0 => 0 }
    @charset_sids.each_with_index { |s, i| map[s] ||= i + 1 }
    map
  end
  @gid_by_sid[sid]
end

#num_glyphsObject



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

def num_glyphs
  charstrings&.size || 0
end

#sid_for_gid(gid) ⇒ Object

Charset (format 0 only): gid -> SID, with .notdef implicit at gid 0.



31
32
33
34
35
# File 'lib/pdfrb/font/cff/file.rb', line 31

def sid_for_gid(gid)
  return 0 if gid.zero?

  @charset_sids[gid - 1]
end