Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font information missing in UnknownFont error message #1022

Closed
mojavelinux opened this issue Apr 6, 2017 · 3 comments
Closed

Font information missing in UnknownFont error message #1022

mojavelinux opened this issue Apr 6, 2017 · 3 comments
Assignees

Comments

@mojavelinux
Copy link
Contributor

When a font cannot be found, users often see the following error message:

 is not a known font.

This happens when a font family + font style font combination is not found in the font registry. Prawn falls back to loading an AFM font. However, in this case, the name argument is always nil and the error message reports a blank font. All the font information is sitting in the options argument.

In afm.rb, I prose changing:

def initialize(document, name, options = {}) #:nodoc:

  unless BUILT_INS.include?(name)
    raise Prawn::Errors::UnknownFont, "#{name} is not a known font."
  end

to

def initialize(document, name, options = {}) #:nodoc:
  name ||= options[:family]
  unless BUILT_INS.include?(name)
    raise Prawn::Errors::UnknownFont, "#{[name, options[:style]].compact * ':'} is not a known font."
  end

That way, the error message will be:

Noto Serif:bold-italic is not a known font.

The message will be consistent whether it's the family or the family + style that can't be matched.

@settermjd
Copy link

Please do! I just encountered this error, changed the file with your change, and now I know what the problem is.

@brandoncc
Copy link

This just solved my problem as well, please add it to the repo!

@mojavelinux mojavelinux self-assigned this Nov 3, 2017
mojavelinux added a commit to mojavelinux/prawn that referenced this issue Nov 8, 2017
- when an afm font is missing, provide more information to the user
- look for font name in family option in case of missing TTF
mojavelinux added a commit to mojavelinux/prawn that referenced this issue Nov 8, 2017
- when an afm font is missing, provide more information to the user
- look for font name in family option in case of missing TTF
mojavelinux added a commit to mojavelinux/prawn that referenced this issue Nov 8, 2017
- when an afm font is missing, provide more information to the user
- look for font name in family option in case of missing TTF
- add test to confirm error is raised and message is correct
mojavelinux added a commit to mojavelinux/prawn that referenced this issue Nov 8, 2017
- when an afm font is missing, provide more information to the user
- look for font name in family option in case of missing TTF
- add test to confirm error is raised and message is correct
mojavelinux added a commit to mojavelinux/prawn that referenced this issue Nov 8, 2017
- when an afm font is missing, provide more information to the user
- look for font name in family option in case of missing TTF
- add test to confirm error is raised and message is correct
mojavelinux added a commit that referenced this issue Nov 14, 2017
resolves #1022 provide more information about missing font
@mojavelinux
Copy link
Contributor Author

Added!

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

No branches or pull requests

3 participants