Skip to content

Conversation

@nulano
Copy link
Contributor

@nulano nulano commented May 27, 2020

For #4651

I would assume the advance value only depends on hinting, which should probably run without the FT_LOAD_RENDER flag. In fact, the FreeType docs mention the flag FT_LOAD_BITMAP_METRICS_ONLY which seems appropriate here and conflicts with FT_LOAD_RENDER. https://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#ft_load_xxx

While the FT_LOAD_BITMAP_METRICS_ONLY will likely be ignored due to FT_LOAD_NO_BITMAP, it should serve as a reminder for when #891 is resolved properly. (I know the solution, I intend to submit a PR later. Essentially, Pillow should check the bitdepth of the returned bitmap instead of guessing.) Edit: Removed for now as it is not supported on all FreeType versions.

Testing I get the following results (in s) on my Windows 10 laptop with the code below.

7.1.2 (PyPI) master (local compile) PR (local compile)
0.088 0.0895 0.079
    from timeit import repeat

    print(
        'getsize() (x100): ',
        min(repeat(
            'font.getsize("Hello world")',
            'from PIL import ImageFont; font = ImageFont.truetype("Tests/fonts/FreeMono.ttf", 20, layout_engine=ImageFont.LAYOUT_BASIC)',
            number=100, repeat=30
        )),
    )

@radarhere
Copy link
Member

Thanks!

@radarhere radarhere merged commit 8e6e728 into python-pillow:master May 27, 2020
@hugovk
Copy link
Member

hugovk commented May 27, 2020

Test on macOS, also improved:

7.1.2 (PyPI) master before merge (local compile) master after merge (local compile)
0.035 0.015 0.011

@nulano nulano deleted the ft-getsize branch May 27, 2020 12:38
@radarhere radarhere changed the title Do not render glyphs during text layout Speed up text layout by not rendering glyphs May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants