Skip to content

Instantly share code, notes, and snippets.

@henrik
Created October 19, 2009 18:50
Show Gist options
  • Save henrik/da21359077f03472fc7a to your computer and use it in GitHub Desktop.
Save henrik/da21359077f03472fc7a to your computer and use it in GitHub Desktop.
Lowercase numbers in Prawn for Adobe Pro fonts.
# Lowercase numbers in Prawn.
# Works with Adobe Pro fonts only: http://en.wikipedia.org/wiki/Text_figures
require "rubygems"
require "prawn"
class Prawn::Document
def adobe_pro_osf(text)
text.to_s.gsub(/\d/) { ["F64#{($&.to_i + 3).to_s(16)}".hex].pack("U") }
end
end
pdf = Prawn::Document.new
pdf.font_families.update("Garamond" => {
:normal => '/Users/henrik/Sites/auktion/app/pdf/assets/Garamond3LTStd.ttf',
:bold => '/Users/henrik/Sites/auktion/app/pdf/assets/Garamond3LTStd-Bold.ttf',
:italic => '/Users/henrik/Sites/auktion/app/pdf/assets/Garamond3LTStd-Italic.ttf',
:bold_italic => '/Users/henrik/Sites/auktion/app/pdf/assets/Garamond3LTStd-BoldItalic.ttf'
})
pdf.font 'Garamond'
pdf.text("Upper case: 0123456789")
pdf.text("Lower case: #{pdf.adobe_pro_osf '0123456789'}")
pdf.render_file('/tmp/x.pdf')
`open /tmp/x.pdf` # OS X
@henrik
Copy link
Author

henrik commented Aug 31, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment