Kozea / WeasyPrint

The awesome document factory
https://weasyprint.org
BSD 3-Clause "New" or "Revised" License
7.11k stars 678 forks source link

Windows cannot use custom fonts with the windows installation guide #2185

Closed kimwonj77 closed 3 months ago

kimwonj77 commented 3 months ago

This issue is split from #2180.

Why?

WeasyPrint currently depends on Harfbuzz version 4.1.0 or higher. However, according to the Windows installation documentation, the GTK Installer, which installs libpango and harfbuzz, contains version 3.1.2.

Stacktrace

Traceback (most recent call last):
  File "[redacted]\test.py", line 37, in <module>
    HTML(string=html_content, base_url=".").write_pdf("output.pdf")
  File "[redacted]\.venv\Lib\site-packages\weasyprint\__init__.py", line 259, in write_pdf
    self.render(font_config, counter_style, **options)
  File "[redacted]\.venv\Lib\site-packages\weasyprint\document.py", line 404, in write_pdf
    pdf = generate_pdf(self, target, zoom, **options)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[redacted]\.venv\Lib\site-packages\weasyprint\pdf\__init__.py", line 270, in generate_pdf
    pdf_fonts = build_fonts_dictionary(
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "[redacted]\.venv\Lib\site-packages\weasyprint\pdf\fonts.py", line 286, in build_fonts_dictionary
    font.clean(cmap, options['hinting'])
  File "[redacted]\.venv\Lib\site-packages\weasyprint\pdf\fonts.py", line 112, in clean
    self.subset(cmap, hinting)
  File "[redacted]\.venv\Lib\site-packages\weasyprint\pdf\fonts.py", line 184, in subset
    self._harfbuzz_subset(cmap, hinting)
  File "[redacted]\.venv\Lib\site-packages\weasyprint\pdf\fonts.py", line 195, in _harfbuzz_subset
    harfbuzz.hb_set_add_sorted_array(gid_set, gid_array, len(cmap))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[redacted]\.venv\Lib\site-packages\cffi\api.py", line 912, in __getattr__
    make_accessor(name)
  File "[redacted]\.venv\Lib\site-packages\cffi\api.py", line 908, in make_accessor
    accessors[name](name)
  File "[redacted]\.venv\Lib\site-packages\cffi\api.py", line 838, in accessor_function
    value = backendlib.load_function(BType, name)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: function/symbol 'hb_set_add_sorted_array' not found in library 'C:\Program Files\GTK3-Runtime Win64\bin\libharfbuzz-0.dll': error 0x7f

Function List

Possible options

User side

  1. Use a newer version of Harfbuzz:
    • Msys2-mingw64 provides a newer version of libpango and Harfbuzz (8.5.0).
  2. Install a newer version of GTK:
  3. Use full_fonts=True
    • It slows down performance and has some issues.
  4. Downgrade WeasyPrint: Not an option, as it hasn't been released yet.

    Dev side

    • Avoid using hb_set_add_sorted_array.
liZe commented 3 months ago

Hi!

The documentation for the next version already tells users to use Msys2.

As the subset code is optional (fonttools is used as a fallback), let’s keep it simple and check that we have a version that’s recent enough.