Giter Club home page Giter Club logo

Comments (12)

alexanderankin avatar alexanderankin commented on July 17, 2024 1

reingart#181

from fpdf2.

alexanderankin avatar alexanderankin commented on July 17, 2024

#20 is a new one that I haven't seen yet. typically the problem with font handling is that like the cmap is out of range for some unicode characters or something like that.

from fpdf2.

Lucas-C avatar Lucas-C commented on July 17, 2024

I'm not sure there is a need for a "global" issue given there are already specific issues.
What do you think?

from fpdf2.

alexanderankin avatar alexanderankin commented on July 17, 2024

I figured that in the long term font handling should be "overhauled" (actually, hauled out to the trash and replaced with some font library), so this would be a good place to discuss. Also, I'm used to JIRA's "epic" concept which lets issues be linked to one another. I would prefer we keep this open for now.

I somehow think that even after #26 theres gonna be some unicode stuff that crops up just because font handling is for font libs not fpdf.

from fpdf2.

Lucas-C avatar Lucas-C commented on July 17, 2024

If you're used to JIRA, you may want to check out GitHub Projects: https://github.com/alexanderankin/pyfpdf/projects

I fully agree about using a dedicated lib for font handling!

from fpdf2.

bwdalmijn avatar bwdalmijn commented on July 17, 2024

Hi,
Dont know if my question belongs here, but starting a seperate issue for it seems a bit much.
The self.charwidths attribute of the TTFontFile class is a list.
However the FPDF class wants it to be a dictionary.
Is my observation correct? Is it easy to fix? (I'm not that much at home in the ttfonts python file).

Kind regards,

from fpdf2.

alexanderankin avatar alexanderankin commented on July 17, 2024

from fpdf2.

Lucas-C avatar Lucas-C commented on July 17, 2024

@bwdalmijn What makes you think that "the FPDF class wants it to be a dictionary" ?

from fpdf2.

bwdalmijn avatar bwdalmijn commented on July 17, 2024

@Lucas-C When i try adding a font and then using it (TrueType Fontfile that is):
The functions I use are slightly modified compared to yours, but the mechanics are the same.

pdf.add_font("courier",style='',fname="cour.ttf",file_type="uni")
pdf.add_font("courier",style='B',fname="courb.ttf",file_type="uni")
pdf.add_font("courier",style='I',fname="couri.ttf",file_type="uni")
pdf.add_font("courier",style='BI',fname="courbi.ttf",file_type="uni")
pdf.set_font("courier",9)

when "compiling" i get the error message:

AttributeError: 'list' object has no attribute 'get'

This refers to the "cw" element of a font in the dictionary FPDF.fonts.
The 'cw' element of a core-font, for instance, is a dictionary, where the characters are used as keys for their respective widths.
This way the functions in the fpdf class know how to extract the widths for each character.
This is missing when a ttf file is broken down and made into a font dictionary.

This should explain what i meant earlier.

Kind regards,

from fpdf2.

Lucas-C avatar Lucas-C commented on July 17, 2024

Thank you for the detailed explanations.

There is a minimal code snippet showing how to load "courier.ttf" and use it to render some text:

from fpdf import FPDF

pdf = FPDF()
pdf.add_page()
pdf.add_font("Courier", style="", fname="courier.ttf", uni=True)
pdf.set_font("Courier", "", 36)
pdf.text(50, 50, "Hello!")
pdf.output("hello.pdf")

I have just tested this with latest version of the code on this repository, and it works fine.

Maybe the exception you got came from your custom code?

To help you we will need a minimal code that reproduces your issue, with a specific published version of fpdf2.
Otherwise I'm sorry but we won't be able to help you 😔

from fpdf2.

bwdalmijn avatar bwdalmijn commented on July 17, 2024

Hi @Lucas-C,

Thank you for the reply.
If it works fine for you then correct assumption would be that my alterations caused the error, yes.
Thank you for trying it out.
I will dig a bit to see what's going on.
If you're interested I could drop the main fpdf.py somewhere. That is basically all that differs.

King regards,

from fpdf2.

Lucas-C avatar Lucas-C commented on July 17, 2024

fpdf/fpdf.py changed a lot in the last 2 weeks, with the addition of black as code formatter.
Your version may be very different now.

If yours adds some useful features, and you want to contribute to this repo by adding them in fpdf2, feel free to open a Pull Request to submit your code!

from fpdf2.

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.