module PdfWatermark::Font
Public Instance Methods
character_width(code)
click to toggle source
# 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()
click to toggle source
# File lib/pdf_watermark/font.rb, line 18 def glyph_index @glyph_index ||= self[:cmap].preferred_table end
scale_factor()
click to toggle source
# 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)
click to toggle source
# 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