prawnpdf/prawn — pull request #730 by packetmonkey (2014-06-06 16:37:31+00:00)
Title: Allow a user to pass an IO object when adding a font

This PR lets

```ruby
require 'bundler'
Bundler.setup
require 'prawn'
require 'open-uri'
pdf = Prawn::Document.new
pdf.font_families.update(
"MyFont" => {
format: 'ttf',
bold: open("https://mybucket.s3.amazonaws.com/myfont.ttf")
}
)
pdf.font("MyFont", :style => :bold)
pdf.text "Some bold text"
pdf.render_file 'output.pdf'
```

Work as expected. The big thing to notice is when passing in an IO object we need to also pass in a format: key so Prawn knows what kind of format the font is. Normally prawn uses the file extension at the end of a path to determine what format the file is in, TTF, DFONT or AFM. Really I don't think this is ideal either, where I would prefer to see the TTF class be able to tell you if a given binary stream is a TTF file or not (really asking the class if it can work with said binary stream). I glanced at the TTF spec and it didn't look incredibly easy (no simple magic number at the head of the file).

The other thing I notice is the `name` variable isn't really the font name so much as either the path the user supplied or the IO object for the font, I didn't refactor all the methods to use a more correct name but I did leave a comment in the method. If we think it's worth doing now I can try to make that update but I didn't want to risk mucking up the font code as this is the first time I have really gotten into it.

I also changed the gemfile to require a more recent commit of TTFunk as mentioned in [TTFunk Pull #17](https://github.com/prawnpdf/ttfunk/pull/17), once we are ready to merge the code we can remove that and instead cut a new release of TTFunk and make prawn require that release.

Any thoughts? It works, but it's not quite ideal.