Class: Pdfrb::Font::CMap::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfrb/font/cmap/writer.rb

Overview

Writes a CMap text file from a mapping of glyph codes to Unicode strings. Used when embedding CID fonts with a subset of glyphs to provide /ToUnicode CMap data.

Supports both 1-byte and 2-byte codespaceranges, supplementary Unicode planes (via UTF-16 surrogate pairs), and automatic chunking of bfchar sections (max 100 entries per section per the PDF spec).

Constant Summary collapse

MAX_BFCHAR_ENTRIES =
100

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmap_name:, cid_system_info:, mapping:, code_size: 2) ⇒ Writer

Returns a new instance of Writer.

Parameters:

  • cmap_name (String, Symbol)

    e.g. "Adobe-Identity-UCS"

  • cid_system_info (Hash)

    with :registry, :ordering, :supplement

  • mapping (Hash<Integer => String>)

    glyph code → Unicode string

  • code_size (Integer) (defaults to: 2)

    1 or 2 (bytes per glyph code)



23
24
25
26
27
28
# File 'lib/pdfrb/font/cmap/writer.rb', line 23

def initialize(cmap_name:, cid_system_info:, mapping:, code_size: 2)
  @cmap_name = cmap_name.to_s
  @cid_system_info = cid_system_info
  @mapping = mapping
  @code_size = code_size
end

Instance Attribute Details

#cid_system_infoObject (readonly)

Returns the value of attribute cid_system_info.



17
18
19
# File 'lib/pdfrb/font/cmap/writer.rb', line 17

def cid_system_info
  @cid_system_info
end

#cmap_nameObject (readonly)

Returns the value of attribute cmap_name.



17
18
19
# File 'lib/pdfrb/font/cmap/writer.rb', line 17

def cmap_name
  @cmap_name
end

#mappingObject (readonly)

Returns the value of attribute mapping.



17
18
19
# File 'lib/pdfrb/font/cmap/writer.rb', line 17

def mapping
  @mapping
end

Instance Method Details

#to_sObject



30
31
32
33
34
35
36
37
# File 'lib/pdfrb/font/cmap/writer.rb', line 30

def to_s
  buffer = +""
  emit_header(buffer)
  emit_codespacerange(buffer)
  emit_bfchar(buffer)
  emit_footer(buffer)
  buffer.force_encoding(::Encoding::BINARY)
end