svglib icon indicating copy to clipboard operation
svglib copied to clipboard

Fix fontconfig error on MacOS

Open deeplook opened this issue 7 years ago • 2 comments

This was created to handle better the discussion in https://github.com/deeplook/svglib/commit/e1a462cdd9ed97acf51d5b9d5941bcb555a975b2#diff-e6e044b14a79cba500110ac3f00978da. More details to come. Found on svglib 0.9.0b0, MacOS 10.13.4, Python 3.6.5, reportlab 3.5.6. This is the bare bones traceback:

$ PYTHONPATH=. py.test -k tests/test_basic.py
======================================= test session starts =======================================
platform darwin -- Python 3.6.5, pytest-3.5.1, py-1.5.3, pluggy-0.6.0
rootdir: /Users/gherman/Downloads/svglib, inifile:
plugins: remotedata-0.2.1, openfiles-0.3.0, doctestplus-0.1.3, arraydiff-0.2
collected 42 items / 9 deselected

tests/test_basic.py .....................F...........                                       [100%]

============================================ FAILURES =============================================
__________________________________ TestTextNode.test_font_family __________________________________

self = <test_basic.TestTextNode object at 0x11a5c2208>

    def test_font_family(self):
        def font_config_available():
            try:
                subprocess.call(["fc-match"])
            except OSError:
                return False
            return True

        converter = svglib.Svg2RlgAttributeConverter()
        # Check PDF standard names are untouched
        assert converter.convertFontFamily('ZapfDingbats') == 'ZapfDingbats'
        assert converter.convertFontFamily('bilbo ZapfDingbats') == 'ZapfDingbats'
        assert converter.convertFontFamily(' bilbo    ZapfDingbats  ') == 'ZapfDingbats'
        assert converter.convertFontFamily(' bilbo,    ZapfDingbats  ') == 'ZapfDingbats'
        if font_config_available():
            # Fontconfig will always provide at least a default font and register
            # that font under the provided font name.
>           assert converter.convertFontFamily('SomeFont') == 'SomeFont'
E           AssertionError: assert 'Helvetica' == 'SomeFont'
E             - Helvetica
E             + SomeFont

tests/test_basic.py:407: AssertionError
-------------------------------------- Captured stderr call ---------------------------------------
Fontconfig warning: ignoring UTF-8: not a valid region tag
---------------------------------------- Captured log call ----------------------------------------
svglib.py                  419 WARNING  Unable to find a suitable font for 'font-family:SomeFont'
======================== 1 failed, 32 passed, 9 deselected in 1.02 seconds ========================

deeplook avatar Sep 04 '18 08:09 deeplook

@claudep Sorry, I've lost a bit track on this. Anything else you needed or wanted?

deeplook avatar Sep 10 '18 18:09 deeplook

Yes, it would be instructive to know the exact path/error in find_font() which makes the function return NOT_FOUND.

claudep avatar Sep 10 '18 20:09 claudep