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

AttributeError: '_TTGlyphSet' object has no attribute 'values' #2317

Open
AlexDaucourt opened this issue Dec 2, 2024 · 1 comment
Open

Comments

@AlexDaucourt
Copy link

AlexDaucourt commented Dec 2, 2024

Hello,
First of all thanks for this library which is very useful for me.

I have a bug that appeared in 63.0, when I am using the write_pdf function with a render for fonts. I don't know if the bug is from the library or if the code itself is bad written from me

the code :

css = CSS(string=css_content, font_config=font_config, base_url=f'{path}/stylesheet.css')
HTML(string = html_content, base_url=f'{path}/index.html').render(font_config=font_config, stylesheets=[css]).write_pdf(f'{path}output.pdf', stylesheets=[css],font_config= font_config)

Here is the log (I removed the path each time) :

AttributeError: '_TTGlyphSet' object has no attribute 'values'
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File <command-1818667483983404>:721
      1 css_content = """
      2 
      3 /* Global */
   (...)
    717 
    718 """
    720 css = CSS(string=css_content, font_config=font_config, base_url=path/stylesheet.css')
--> 721 HTML(string = html_content, base_url='path/index.html').render(font_config=font_config, stylesheets=[css]).write_pdf(f"path/output.pdf", stylesheets=[css],font_config= font_config)

File /local_disk0/.ephemeral_nfs/envs/pythonEnv-c6709ed0-ad05-47e5-8eec-de3caf3bf4cb/lib/python3.9/site-packages/weasyprint/document.py:404, in Document.write_pdf(self, target, zoom, finisher, **options)
    401     if 'identifier' in properties and not options['pdf_identifier']:
    402         options['pdf_identifier'] = properties['identifier']
--> 404 pdf = generate_pdf(self, target, zoom, **options)
    406 if finisher:
    407     finisher(self, pdf)

File /local_disk0/.ephemeral_nfs/envs/pythonEnv-c6709ed0-ad05-47e5-8eec-de3caf3bf4cb/lib/python3.9/site-packages/weasyprint/pdf/__init__.py:283, in generate_pdf(document, target, zoom, **options)
    281 # Embedded fonts
    282 subset = not options['full_fonts']
--> 283 pdf_fonts = build_fonts_dictionary(
    284     pdf, document.fonts, compress, subset, options)
    285 pdf.add_object(pdf_fonts)
    286 if 'AcroForm' in pdf.catalog:
    287     # Include Dingbats for forms

File /local_disk0/.ephemeral_nfs/envs/pythonEnv-c6709ed0-ad05-47e5-8eec-de3caf3bf4cb/lib/python3.9/site-packages/weasyprint/pdf/fonts.py:312, in build_fonts_dictionary(pdf, fonts, compress, subset, options)
    310 ttfont = TTFont(full_font, fontNumber=font.index)
    311 font_widths, cmap = {}, {}
--> 312 for i, glyph in enumerate(ttfont.getGlyphSet().values()):
    313     font_widths[i] = glyph.width * 1000 / font.upem
    314 for letter, key in ttfont.getBestCmap().items():

AttributeError: '_TTGlyphSet' object has no attribute 'values'

Thanks if you can help :)

@liZe
Copy link
Member

liZe commented Dec 3, 2024

Hi!

Thanks for the report, maybe there’s a bug in fonttools. Could you please share the font that’s causing this problem?

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

No branches or pull requests

2 participants