prawnpdf / ttfunk

Font Metrics Parser for Prawn
http://prawnpdf.org
Other
125 stars 75 forks source link

Is it possible to use NotoColorEmoji.ttf? #81

Closed brandoncc closed 4 years ago

brandoncc commented 4 years ago

I'm trying to get emoji rendering working, and I'm failing. I'm trying to use NotoColorEmoji.ttf and I am experiencing this error:

2020-03-09T00:23:31.723Z 35337 TID-ouxjoy04c WARN: NoMethodError: undefined method `key?' for nil:NilClass
2020-03-09T00:23:31.723Z 35337 TID-ouxjoy04c WARN: /Users/brandoncc/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/ttfunk-1.6.2.1/lib/ttfunk/table/glyf.rb:32:in `for'
/Users/brandoncc/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/ttfunk-1.6.2.1/lib/ttfunk/subset/base.rb:105:in `glyph_for'

Here is my list of fallback fonts:

  def fallback_fonts
    [
      'NotoColorEmoji',
      'IPAGothic',
      'IPAMincho',
      'IPAPMincho',
      'IPAPGothic',
      'WenQuanYi Zen Hei',
      'DejaVuSans',
      'DroidSans',
      'DroidSerif'
    ]
  end

All of the other fonts work, but many of the emojis just render as boxes.

Any points on either another way, or getting this font to work, would be appreciated. Thanks!

gettalong commented 4 years ago

The NotoColorEmoji font cannot be used because the font outlines are not stored in the standard TrueType glyph font table but in a separate, special font table that supports colors. And this special table is not supported by ttfunk.

In short: It is not possible to use a font with colored glyphs with ttfunk.

brandoncc commented 4 years ago

Thanks @gettalong. I guess that must be why I keep seeing recommendations of using Japanese fonts (which I am also doing, but many emojis are not supported).

brandoncc commented 3 years ago

I'm still struggling with this. is there any chance there will eventually be support?

Thanks!

gettalong commented 3 years ago

The reason why this is not that easy to support are manyfold. For example,

So your best bet would be to do the Emoji parsing yourself, output the text before, output the emoji (taken from a list of images extracted from the font), output the text after.

You might want to look at asciidoctor-pdf which has implemented support for inline images. Generally, that codebase extends Prawn in many ways and is a good resource to find solutions to common text layout problems. It is rather huge, though.

brandoncc commented 3 years ago

Thank you for that excellent information @gettalong. I suspect that https://github.com/hidakatsuya/prawn-emoji probably implements a solution like you are describing. Unfortunately, it is unusable because of this issue.

I'm actually blown away that nobody has solved this yet. It is safe to say that I currently don't have nearly the knowledge needed to solve it myself.

Thanks again for entertaining my question!