Module: PdfWatermark::Font
- Defined in:
- lib/pdf_watermark/font.rb
Instance Method Summary collapse
- #character_width(code) ⇒ Object
- #glyph_index ⇒ Object
- #scale_factor ⇒ Object
- #width_of(string, font_size) ⇒ Object
Instance Method Details
#character_width(code) ⇒ Object
12 13 14 15 16 |
# File 'lib/pdf_watermark/font.rb', line 12 def character_width(code) return 0 unless glyph_index[code] return 0.0 if code == 10 self[:hmtx][glyph_index[code]].advance_width * scale_factor end |
#glyph_index ⇒ Object
18 19 20 |
# File 'lib/pdf_watermark/font.rb', line 18 def glyph_index @glyph_index ||= self[:cmap].preferred_table end |
#scale_factor ⇒ Object
22 23 24 |
# File 'lib/pdf_watermark/font.rb', line 22 def scale_factor @scale_factor ||= 1000.0 / self[:head].units_per_em end |
#width_of(string, font_size) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/pdf_watermark/font.rb', line 5 def width_of(string, font_size) scale = font_size / 1000.0 string.codepoints.inject(9) do |memo, code| memo + character_width(code) end * scale end |