Class: Pdfrb::Font::CMap::Writer
- Inherits:
-
Object
- Object
- Pdfrb::Font::CMap::Writer
- 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
-
#cid_system_info ⇒ Object
readonly
Returns the value of attribute cid_system_info.
-
#cmap_name ⇒ Object
readonly
Returns the value of attribute cmap_name.
-
#mapping ⇒ Object
readonly
Returns the value of attribute mapping.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(cmap_name:, cid_system_info:, mapping:, code_size: 2) ⇒ Writer
constructor
A new instance of Writer.
- #to_s ⇒ Object
Constructor Details
#initialize(cmap_name:, cid_system_info:, mapping:, code_size: 2) ⇒ Writer
Returns a new instance of Writer.
32 33 34 35 36 37 |
# File 'lib/pdfrb/font/cmap/writer.rb', line 32 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_info ⇒ Object (readonly)
Returns the value of attribute cid_system_info.
26 27 28 |
# File 'lib/pdfrb/font/cmap/writer.rb', line 26 def cid_system_info @cid_system_info end |
#cmap_name ⇒ Object (readonly)
Returns the value of attribute cmap_name.
26 27 28 |
# File 'lib/pdfrb/font/cmap/writer.rb', line 26 def cmap_name @cmap_name end |
#mapping ⇒ Object (readonly)
Returns the value of attribute mapping.
26 27 28 |
# File 'lib/pdfrb/font/cmap/writer.rb', line 26 def mapping @mapping end |
Class Method Details
.write(mapping, name: "Adobe-Identity-UCS") ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/pdfrb/font/cmap/writer.rb', line 15 def self.write(mapping, name: "Adobe-Identity-UCS") str_mapping = mapping.transform_values { |cp| [cp].pack("U") } new( cmap_name: name, cid_system_info: { registry: "Adobe", ordering: "UCS", supplement: 0 }, mapping: str_mapping, code_size: 1, ).to_s end |
Instance Method Details
#to_s ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/pdfrb/font/cmap/writer.rb', line 39 def to_s buffer = +"" emit_header(buffer) emit_codespacerange(buffer) emit_bfchar(buffer) (buffer) buffer.force_encoding(::Encoding::BINARY) end |