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

It not work when you render 汉字 by code tag #1718

Closed
lar-ry opened this issue Sep 15, 2022 · 14 comments
Closed

It not work when you render 汉字 by code tag #1718

lar-ry opened this issue Sep 15, 2022 · 14 comments
Labels
crash Problems preventing documents from being rendered
Milestone

Comments

@lar-ry
Copy link

lar-ry commented Sep 15, 2022

I want to render <code>汉字</code>,

it will display the tip:

invalid literal for int() with base 16: ''

v55.0 is normal, but v56.0b1, v56.0 and v56.1 is abnormal.

@liZe
Copy link
Member

liZe commented Sep 15, 2022

Hi!

Could you please send the PDF generated by version 55 and the one generated by version 56 (if the error doesn’t make WeasyPrint crash)?

@lar-ry
Copy link
Author

lar-ry commented Sep 20, 2022

version 55:
work normal.

Successfully installed weasyprint-55.0
PS C:\Users\larry\md2pdf> python .\md2pdf.py doc/index.md -s .\style\paper-zh.less -r all
🎉 doc/index has converted.
PS C:\Users\larry\md2pdf> 

image
generated pdf: index.pdf


version 56:
it work abnormal and can not make pdf successful.

Successfully installed weasyprint-56.0
PS C:\Users\larry\md2pdf> python .\md2pdf.py doc/index.md -s .\style\paper-zh.less -r all
invalid literal for int() with base 16: ''
PS C:\Users\larry\md2pdf>

@liZe
Copy link
Member

liZe commented Sep 23, 2022

I have two questions:

  1. Could you please share (by mail) the font file used in your document with version 55? It’s 新宋体.
  2. We need to have a traceback to know why WeasyPrint crashes. Could you please make your md2pdf.py script display this whole traceback?

@lar-ry
Copy link
Author

lar-ry commented Sep 26, 2022

  1. It's SourceHanSansSC-Regular.otf and SourceHanSerifSC-Regular.otf:
    SourceHanSansSC-Regular.zip
    SourceHanSerifSC-Regular.zip
  2. whole traceback:
    PS C:\Users\larry\md2pdf> python .\md2pdf.py doc/index.md -s .\style\paper-zh.less -r all
    Traceback (most recent call last):
    File "C:\Users\larry\md2pdf\md2pdf.py", line 138, in <module>
        convert(args.markdown, args.style, args.reserve)
    File "C:\Users\larry\md2pdf\md2pdf.py", line 58, in convert
        html.write_pdf(file_name + ".pdf")
    File "C:\Users\larry\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\weasyprint\__init__.py", line 201, in write_pdf
        .write_pdf(
    File "C:\Users\larry\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\weasyprint\document.py", line 335, in write_pdf
        pdf = generate_pdf(
    File "C:\Users\larry\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\weasyprint\pdf\__init__.py", line 445, in generate_pdf
        pdf_fonts = build_fonts_dictionary(pdf, fonts, optimize_size)
    File "C:\Users\larry\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\weasyprint\pdf\fonts.py", line 83, in build_fonts_dictionary
        _build_bitmap_font_dictionary(
    File "C:\Users\larry\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\weasyprint\pdf\fonts.py", line 208, in _build_bitmap_font_dictionary
        bits = bin(int(data.hex(), 16))[2:]
    ValueError: invalid literal for int() with base 16: ''
    PS C:\Users\larry\md2pdf>
    

@liZe
Copy link
Member

liZe commented Sep 26, 2022

Thanks a lot for this very useful answer.

The problem you have is caused by a bitmap font. Since version 56, WeasyPrint supports bitmap fonts, that’s why the rendering was working with version 55, using another font. Unfortunately, the font you shared is not bitmap, so it’s not the font causing the problem.

If you have some Python skills, it could be possible to save this font using a debugger (the content of the file is in font.file_content). Or maybe you know which bitmap fonts are installed on your system. Would you be interested in trying to find the font causing the problem?

@liZe
Copy link
Member

liZe commented Oct 11, 2022

@lar-ry Is there a way we could help you solving this problem?

@lar-ry
Copy link
Author

lar-ry commented Oct 11, 2022

I had to continue using version 55 because this font was required.

@lar-ry Is there a way we could help you solving this problem?

@liZe
Copy link
Member

liZe commented Oct 11, 2022

I had to continue using version 55 because this font was required.

OK, I understand.

The bug is actually caused by another font, a bitmap font installed on your system. The problem is that we don’t know which font it is.

Do you have some programming skills? If so, I could tell you how to find the font, so that I can fix the problem. But if you don’t have programming skills or don’t want to spend more time on this, no problem 😁️, we can then close this issue.

@lar-ry
Copy link
Author

lar-ry commented Oct 11, 2022

I want to try, what do I need to do?

@liZe
Copy link
Member

liZe commented Oct 11, 2022

I want to try, what do I need to do?

Thank you!

Here’s what you can do:

  • Install WeasyPrint 56.1
  • Open C:\Users\larry\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\weasyprint\pdf\fonts.py
  • Add open('C:\\Users\\larry\\font-' + font.hash, 'wb').write(font.file_content) on line 40. You should have something like:
    for font in fonts.values():
        open('C:\\Users\\larry\\font-' + font.hash, 'wb').write(font.file_content)
        widths = pydyf.Array()
  • Generate your document (you’ll have the bug, it’s normal).

You should now have one or more files named font-XXXXXX (with uppercase characters instead of X) created in your C:\Users\larry\ folder. You can attach them in a comment or send them by mail, that’s the file I need!

@lar-ry
Copy link
Author

lar-ry commented Oct 11, 2022

fonts.zip
I did it, and it created 3 files in fonts.zip

@lar-ry
Copy link
Author

lar-ry commented Oct 11, 2022

Font files:

  • Source Han Sans SC
  • Source Han Serif SC
  • 宋体

PS: You are really professional, thank you.

@liZe
Copy link
Member

liZe commented Oct 11, 2022

Thank you very much for your time, I can now reproduce your bug! I’ll come back as soon as I find a way to fix it.

liZe added a commit that referenced this issue Oct 11, 2022
@liZe liZe closed this as completed in 22cabf7 Oct 11, 2022
@liZe liZe added the crash Problems preventing documents from being rendered label Oct 11, 2022
@liZe liZe added this to the 57.0 milestone Oct 11, 2022
@liZe
Copy link
Member

liZe commented Oct 11, 2022

The bug should now be fixed. The 宋体 font includes both bitmap characters and vector characters. We should use the vector variant (see #1736), removing the bug.

Moreover, the crash happened when characters have no data (ie. they have a width of 0). If we ever meet these characters in bitmap-only fonts again, we’ll now correctly include them.

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jun 30, 2023
Version 59.0
------------

Released on 2023-05-11.

This version also includes the changes from unstable b1 version listed
below.

Bug fixes:

* `#1864 <https://github.com/Kozea/WeasyPrint/issues/1864>`_:
  Handle overflow for svg and symbol tags in SVG images
* `#1867 <https://github.com/Kozea/WeasyPrint/pull/1867>`_:
  Remove duplicate compression of attachments
* `d0ad5c1 <https://github.com/Kozea/WeasyPrint/commit/d0ad5c1>`_:
  Override use tag children instead of drawing their references
* `93df1a5 <https://github.com/Kozea/WeasyPrint/commit/93df1a5>`_:
  Don’t resize the same image twice when the --dpi option is set
* `#1874 <https://github.com/Kozea/WeasyPrint/pull/1874>`_:
  Drawn underline and overline behind text


Version 59.0b1
--------------

Released on 2023-04-14.

**This version is experimental, don't use it in production. If you find bugs,
please report them!**

Command-line API:

* The ``--optimize-size`` option and its short equivalent ``-O`` have been
  deprecated. To activate or deactivate different size optimizations, you can
  now use:

  * ``--uncompressed-pdf``,
  * ``--optimize-images``,
  * ``--full-fonts``,
  * ``--hinting``,
  * ``--dpi <resolution>``, and
  * ``--jpeg-quality <quality>``.

* A new ``--cache-folder <folder>`` option has been added to store temporary
  data in the given folder on the disk instead of keeping them in memory.

Python API:

* Global rendering options are now given in ``**options`` instead of dedicated
  parameters, with slightly different names. It means that the signature of the
  ``HTML.render()``, ``HTML.write_pdf()`` and ``Document.write_pdf()`` has
  changed. Here are the steps to port your Python code to v59.0:

  1. Use named parameters for these functions, not positioned parameters.
  2. Rename some the parameters:

     * ``image_cache`` becomes ``cache`` (see below),
     * ``identifier`` becomes ``pdf_identifier``,
     * ``variant`` becomes ``pdf_variant``,
     * ``version`` becomes ``pdf_version``,
     * ``forms`` becomes ``pdf_forms``.

* The ``optimize_size`` parameter of ``HTML.render()``, ``HTML.write_pdf()``
  and ``Document()`` has been removed and will be ignored. You can now use the
  ``uncompressed_pdf``, ``full_fonts``, ``hinting``, ``dpi`` and
  ``jpeg_quality`` parameters that are included in ``**options``.

* The ``cache`` parameter can be included in ``**options`` to replace
  ``image_cache``. If it is a dictionary, this dictionary will be used to store
  temporary data in memory, and can be even shared between multiple documents.
  If it’s a folder Path or string, WeasyPrint stores temporary data in the
  given temporary folder on disk instead of keeping them in memory.

New features:

* `#1853 <https://github.com/Kozea/WeasyPrint/pull/1853>`_,
  `#1854 <https://github.com/Kozea/WeasyPrint/issues/1854>`_:
  Reduce PDF size, with financial support from Code & Co.
* `#1824 <https://github.com/Kozea/WeasyPrint/issues/1824>`_,
  `#1829 <https://github.com/Kozea/WeasyPrint/pull/1829>`_:
  Reduce memory use for images
* `#1858 <https://github.com/Kozea/WeasyPrint/issues/1858>`_:
  Add an option to keep hinting information in embedded fonts

Bug fixes:

* `#1855 <https://github.com/Kozea/WeasyPrint/issues/1855>`_:
  Fix position of emojis in justified text
* `#1852 <https://github.com/Kozea/WeasyPrint/issues/1852>`_:
  Don’t crash when line can be split before trailing spaces
* `#1843 <https://github.com/Kozea/WeasyPrint/issues/1843>`_:
  Fix syntax of dates in metadata
* `#1827 <https://github.com/Kozea/WeasyPrint/issues/1827>`_,
  `#1832 <https://github.com/Kozea/WeasyPrint/pull/1832>`_:
  Fix word-spacing problems with nested tags

Documentation:

* `#1841 <https://github.com/Kozea/WeasyPrint/issues/1841>`_:
  Add a paragraph about unsupported calc() function


Version 58.1
------------

Released on 2023-03-07.

Bug fixes:

* `#1815 <https://github.com/Kozea/WeasyPrint/issues/1815>`_:
  Fix bookmarks coordinates
* `#1822 <https://github.com/Kozea/WeasyPrint/issues/1822>`_,
  `#1823 <https://github.com/Kozea/WeasyPrint/pull/1823>`_:
  Fix vertical positioning for absolute replaced elements

Documentation:

* `#1814 <https://github.com/Kozea/WeasyPrint/pull/1814>`_:
  Fix broken link pointing to samples


Version 58.0
------------

Released on 2023-02-17.

This version also includes the changes from unstable b1 version listed
below.

Bug fixes:

* `#1807 <https://github.com/Kozea/WeasyPrint/issues/1807>`_:
  Don’t crash when out-of-flow box is split in out-of-flow parent
* `#1806 <https://github.com/Kozea/WeasyPrint/issues/1806>`_:
  Don’t crash when fixed elements aren’t displayed yet in aborted line
* `#1809 <https://github.com/Kozea/WeasyPrint/issues/1809>`_:
  Fix background drawing for out-of-the-page transformed boxes


Version 58.0b1
--------------

Released on 2023-02-03.

**This version is experimental, don't use it in production. If you find bugs,
please report them!**

New features:

* `#61 <https://github.com/Kozea/WeasyPrint/issues/61>`_,
  `#1796 <https://github.com/Kozea/WeasyPrint/pull/1796>`_:
  Support PDF forms, with financial support from Personalkollen
* `#1173 <https://github.com/Kozea/WeasyPrint/issues/1173>`_:
  Add style for form fields

Bug fixes:

* `#1777 <https://github.com/Kozea/WeasyPrint/issues/1777>`_:
  Detect JPEG/MPO images as normal JPEG files
* `#1771 <https://github.com/Kozea/WeasyPrint/pull/1771>`_:
  Improve SVG gradients


Version 57.2
------------

Released on 2022-12-23.

Bug fixes:

* `0f2e377 <https://github.com/Kozea/WeasyPrint/commit/0f2e377>`_:
  Print annotations with PDF/A
* `0e9426f <https://github.com/Kozea/WeasyPrint/commit/0e9426f>`_:
  Hide annotations with PDF/UA
* `#1764 <https://github.com/Kozea/WeasyPrint/issues/1764>`_:
  Use reference instead of stream for annotation appearance stream
* `#1783 <https://github.com/Kozea/WeasyPrint/pull/1783>`_:
  Fix multiple font weights for @font-face declarations


Version 57.1
------------

Released on 2022-11-04.

Dependencies:

* `#1754 <https://github.com/Kozea/WeasyPrint/pull/1754>`_:
  Pillow 9.1.0 is now needed

Bug fixes:

* `#1756 <https://github.com/Kozea/WeasyPrint/pull/1756>`_:
  Fix rem font size for SVG images
* `#1755 <https://github.com/Kozea/WeasyPrint/issues/1755>`_:
  Keep format when transposing images
* `#1753 <https://github.com/Kozea/WeasyPrint/issues/1753>`_:
  Don’t use deprecated ``read_text`` function when ``files`` is available
* `#1741 <https://github.com/Kozea/WeasyPrint/issues/1741>`_:
  Generate better manpage
* `#1747 <https://github.com/Kozea/WeasyPrint/issues/1747>`_:
  Correctly set target counters in pages’ absolute elements
* `#1748 <https://github.com/Kozea/WeasyPrint/issues/1748>`_:
  Always set font size when font is changed in line
* `2b05137 <https://github.com/Kozea/WeasyPrint/commit/2b05137>`_:
  Fix stability of font identifiers

Documentation:

* `#1750 <https://github.com/Kozea/WeasyPrint/pull/1750>`_:
  Fix documentation spelling


Version 57.0
------------

Released on 2022-10-18.

This version also includes the changes from unstable b1 version listed
below.

New features:

* `a4fc7a1 <https://github.com/Kozea/WeasyPrint/commit/a4fc7a1>`_:
  Support image-orientation

Bug fixes:

* `#1739 <https://github.com/Kozea/WeasyPrint/issues/1739>`_:
  Set baseline on all flex containers
* `#1740 <https://github.com/Kozea/WeasyPrint/issues/1740>`_:
  Don’t crash when currentColor is set on root svg tag
* `#1718 <https://github.com/Kozea/WeasyPrint/issues/1718>`_:
  Don’t crash with empty bitmap glyphs
* `#1736 <https://github.com/Kozea/WeasyPrint/issues/1736>`_:
  Always use the font’s vector variant when possible
* `eef8b4d <https://github.com/Kozea/WeasyPrint/commit/eef8b4d>`_:
  Always set color and state before drawing
* `#1662 <https://github.com/Kozea/WeasyPrint/issues/1662>`_:
  Use a stable key to store stream fonts
* `#1733 <https://github.com/Kozea/WeasyPrint/issues/1733>`_:
  Don’t remove attachments when adding internal anchors
* `3c4fa50 <https://github.com/Kozea/WeasyPrint/commit/3c4fa50>`_,
  `c215697 <https://github.com/Kozea/WeasyPrint/commit/c215697>`_,
  `d275dac <https://github.com/Kozea/WeasyPrint/commit/d275dac>`_,
  `b04bfff <https://github.com/Kozea/WeasyPrint/commit/b04bfff>`_:
  Fix many bugs related to PDF/UA structure

Performance:

* `dfccf1b <https://github.com/Kozea/WeasyPrint/commit/dfccf1b>`_:
  Use faces as fonts dictionary keys
* `0dc12b6 <https://github.com/Kozea/WeasyPrint/commit/0dc12b6>`_:
  Cache add_font to avoid calling get_face too often
* `75e17bf <https://github.com/Kozea/WeasyPrint/commit/75e17bf>`_:
  Don’t call process_whitespace twice on many children
* `498d3e1 <https://github.com/Kozea/WeasyPrint/commit/498d3e1>`_:
  Optimize __missing__ functions

Documentation:

* `863b3d6 <https://github.com/Kozea/WeasyPrint/commit/863b3d6>`_:
  Update documentation of installation on macOS with Homebrew


Version 57.0b1
--------------

Released on 2022-09-22.

**This version is experimental, don't use it in production. If you find bugs,
please report them!**

New features:

* `#1704 <https://github.com/Kozea/WeasyPrint/pull/1704>`_:
  Support PDF/UA, with financial support from Novareto
* `#1454 <https://github.com/Kozea/WeasyPrint/issues/1454>`_:
  Support variable fonts

Bug fixes:

* `#1058 <https://github.com/Kozea/WeasyPrint/issues/1058>`_:
  Fix bullet position after page break, with financial support from OpenZeppelin
* `#1707 <https://github.com/Kozea/WeasyPrint/issues/1707>`_:
  Fix footnote positioning in multicolumn layout, with financial support from Code & Co.
* `#1722 <https://github.com/Kozea/WeasyPrint/issues/1722>`_:
  Handle skew transformation with only one parameter
* `#1715 <https://github.com/Kozea/WeasyPrint/issues/1715>`_:
  Don’t crash when images are truncated
* `#1697 <https://github.com/Kozea/WeasyPrint/issues/1697>`_:
  Don’t crash when attr() is used in text-decoration-color
* `#1695 <https://github.com/Kozea/WeasyPrint/pull/1695>`_:
  Include language information in PDF metadata
* `#1612 <https://github.com/Kozea/WeasyPrint/issues/1612>`_:
  Don’t lowercase letters when capitalizing text
* `#1700 <https://github.com/Kozea/WeasyPrint/issues/1700>`_:
  Fix crash when rendering footnote with repagination
* `#1667 <https://github.com/Kozea/WeasyPrint/issues/1667>`_:
  Follow EXIF metadata for image rotation
* `#1669 <https://github.com/Kozea/WeasyPrint/issues/1669>`_:
  Take care of floats when remvoving placeholders
* `#1638 <https://github.com/Kozea/WeasyPrint/issues/1638>`_:
  Use the original box when breaking waiting children
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Problems preventing documents from being rendered
Projects
None yet
Development

No branches or pull requests

2 participants