Giter VIP home page Giter VIP logo

Comments (10)

pointlessone avatar pointlessone commented on June 7, 2024 1

Oh well. I may consider tightening up Prawn's public API to not allow that but as of right now you should make sure you're providing proper data to Prawn.

from prawn-rails.

pointlessone avatar pointlessone commented on June 7, 2024

This code only updates a hash. It doesn't load fonts or do anything else. This operation is not expensive and won't save you much CPU time to move it into initializer. Do it wherever you instantiate a document.

from prawn-rails.

waghanza avatar waghanza commented on June 7, 2024

In fact I want to load custom fonts globally

from prawn-rails.

pointlessone avatar pointlessone commented on June 7, 2024

Make it a constant if you want to keep only one instance of the list:

MY_FONTS = {
  "Helvetica": {
    normal: Rails.root.join("app/assets/fonts/Helvetica.ttf"),
    italic: Rails.root.join("app/assets/fonts/Helvetica-Oblique.ttf"),
    bold: Rails.root.join("app/assets/fonts/app/assets/fonts/Helvetica-Bold.ttf"),
    bold_italic: Rails.root.join("app/assets/fonts/Helvetica-BoldOblique.ttf"),
  }
}

Elsewhere:

pdf.font_families.update(MY_FONTS)

from prawn-rails.

waghanza avatar waghanza commented on June 7, 2024

I think I mis-express myself

When I execute rspec, `prawn| is loaded with some afm fonts, and I need to load ttf fonts

I have an error when executing my spec

/usr/share/gems/gems/prawn-2.2.2/lib/prawn/font/afm.rb:105:in `normalize_encoding'

from prawn-rails.

pointlessone avatar pointlessone commented on June 7, 2024

AFM is not a font. It's a font metric. It basically contains only character sizes and advances (how far cursor should move after a specific character). Those are only present for so called PDF built-in fonts. Those are 14 actual Adobe fonts that should be distributed with any PDF renderer (software that reads PDF files and produces some sort of image, either for displaying on a screen, or printing, or saving to a file, etc.). The AFM files used in Prawn for laying out the text but no actual fonts ever included in the PDFs. That is when you us any of those default fonts. The code is not used when you use a TTF font.

from prawn-rails.

waghanza avatar waghanza commented on June 7, 2024

As I understand, ttf fonts SHOULD be included on the software which read pdf ?

from prawn-rails.

pointlessone avatar pointlessone commented on June 7, 2024

These 14 default fonts — yes. Any other font has to be embedded into PDF file. Thats's what happens when you use your own TTF fonts with Prawn.

from prawn-rails.

waghanza avatar waghanza commented on June 7, 2024

Thanks for explaination 😛

It appears that my problem was about a nil that was sent in https://github.com/prawnpdf/prawn/blob/master/lib/prawn/font/afm.rb#L108 (because of a nilable field in database)

from prawn-rails.

waghanza avatar waghanza commented on June 7, 2024

I've found a way to do this 😛 but up to you to choose between allowing nil or documenting this

I can also provide any PR, if you want 😜

from prawn-rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.