-
-
Save henrik/da21359077f03472fc7a to your computer and use it in GitHub Desktop.
Lowercase numbers in Prawn for Adobe Pro fonts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As discussed here: https://groups.google.com/forum/?fromgroups=#!topic/prawn-ruby/BRCVY7DXZt4