Class: CombinePDF::Fonts::Font
- Inherits:
-
Hash
- Object
- Hash
- CombinePDF::Fonts::Font
- Defined in:
- lib/combine_pdf/combine_pdf_fonts.rb
Overview
the internal class for the Fonts model
this is an internal class, used by PDFWriter and PDF. you don’t normally need to use this.
Instance Attribute Summary collapse
-
#cmap ⇒ Object
set/get a character/Glyph mapping for the font (the equivilant of a CMap).
-
#metrics ⇒ Object
get the metrics dictionary for the font.
-
#name ⇒ Object
set/get the name of the font.
Instance Method Summary collapse
-
#encode(text) ⇒ Object
This function translate a unicode string, to a character glyph ID stream.
-
#initialize(name = nil, font_metrics = {32=>{:wx=>250, :boundingbox=>[0, 0, 0, 0]}}, object = nil, c_map = nil) ⇒ Font
constructor
internelized a new Font object, setting it’s name, it’s metrics Hash and the object Hash.
Constructor Details
#initialize(name = nil, font_metrics = {32=>{:wx=>250, :boundingbox=>[0, 0, 0, 0]}}, object = nil, c_map = nil) ⇒ Font
internelized a new Font object, setting it’s name, it’s metrics Hash and the object Hash. Optionally set a CMap, if the glyph ID and character codes aren’t the same.
42 43 44 45 46 47 48 |
# File 'lib/combine_pdf/combine_pdf_fonts.rb', line 42 def initialize(name = nil, font_metrics = {32=>{:wx=>250, :boundingbox=>[0, 0, 0, 0]}}, object = nil, c_map = nil) self.name = name self.cmap = c_map self.metrics = font_metrics self[:is_reference_only] = true self[:referenced_object] = object end |
Instance Attribute Details
#cmap ⇒ Object
set/get a character/Glyph mapping for the font (the equivilant of a CMap)
the cmap is a Hash were each key is the unicode character code and the value is the glyph ID for the font.
32 33 34 |
# File 'lib/combine_pdf/combine_pdf_fonts.rb', line 32 def cmap @cmap end |
#metrics ⇒ Object
get the metrics dictionary for the font
34 35 36 |
# File 'lib/combine_pdf/combine_pdf_fonts.rb', line 34 def metrics @metrics end |
#name ⇒ Object
set/get the name of the font
28 29 30 |
# File 'lib/combine_pdf/combine_pdf_fonts.rb', line 28 def name @name end |
Instance Method Details
#encode(text) ⇒ Object
This function translate a unicode string, to a character glyph ID stream.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/combine_pdf/combine_pdf_fonts.rb', line 51 def encode text # FixMe: embed RTL text convertion return PDFOperations._format_string_to_pdf(text) unless self.cmap coded_array = text.chars.map do |c| if self.cmap[c] self.cmap[c] else warn "CombinePDF ERROR: couldn't encode string - characters not supported by the chosen font." "" end end coded_array.unshift "<" coded_array.push ">" coded_array.join end |