Class: CombinePDF::Fonts::Font

Inherits:
Hash
  • Object
show all
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

Instance Method Summary collapse

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.



45
46
47
48
49
50
51
# File 'lib/combine_pdf/combine_pdf_fonts.rb', line 45

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

#cmapObject

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.



35
36
37
# File 'lib/combine_pdf/combine_pdf_fonts.rb', line 35

def cmap
  @cmap
end

#metricsObject

get the metrics dictionary for the font



37
38
39
# File 'lib/combine_pdf/combine_pdf_fonts.rb', line 37

def metrics
  @metrics
end

#nameObject

set/get the name of the font



31
32
33
# File 'lib/combine_pdf/combine_pdf_fonts.rb', line 31

def name
  @name
end

Instance Method Details

#encode(text) ⇒ Object

This function translate a unicode string, to a character glyph ID stream.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/combine_pdf/combine_pdf_fonts.rb', line 54

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