Skip to content

Commit

Permalink
Fix ERROR on hinting_impact check
Browse files Browse the repository at this point in the history
When running from a directory where the user lacks write permissions we were getting an ERROR.
To fix the problem, we now use a better location for creating a temp-dir (and a temp-file) for this check.

hinting_impact
On the Universal profile

(issue #4917)
  • Loading branch information
felipesanches committed Nov 29, 2024
1 parent d5c05e7 commit 6846c27
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ A more detailed list of changes is available in the corresponding milestones for

### Changes to existing checks
### On the Universal profile
- **[[hinting_impact]]:** Fix ERROR when running from a directory where the user lacks write permissions. Use a better location for creating a temp-dir (and a temp-file) for this check. (issue #4917)
- **[family/control_chars]:** renamed to **control_chars** as it is not realy a family-wide check. (issue #4896)
- **[glyf_nested_components]** renamed to **nested_components**.

Expand Down
25 changes: 14 additions & 11 deletions Lib/fontbakery/checks/hinting_impact.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import os
from io import BytesIO
import tempfile

from dehinter.font import dehint
from fontTools.subset import main as pyftsubset
from fontTools.ttLib import TTFont

from fontbakery.prelude import check, Message, INFO
from fontbakery.testable import Font
from fontbakery.utils import filesize_formatting


def hinting_stats(font: Font):
"""Return file size differences for a hinted font compared
to an dehinted version of same file.
"""
Return file size differences for a hinted font compared to an dehinted version
of same file
"""
import os
from io import BytesIO
from dehinter.font import dehint
from fontTools.subset import main as pyftsubset
from fontTools.ttLib import TTFont

hinted_size = os.stat(font.file).st_size
ttFont = TTFont(font.file) # Use our own copy since we will dehint it

Expand All @@ -25,7 +26,9 @@ def hinting_stats(font: Font):
dehinted_size = len(dehinted_buffer.read())
elif font.is_cff or font.is_cff2:
ext = os.path.splitext(font.file)[1]
tmp = font.file.replace(ext, "-tmp-dehinted%s" % ext)
tmp_dir = tempfile.mkdtemp()
tmp = os.path.join(tmp_dir, "dehinted%s" % ext)

args = [
font.file,
"--no-hinting",
Expand All @@ -45,7 +48,7 @@ def hinting_stats(font: Font):

dehinted_size = os.stat(tmp).st_size
os.remove(tmp)

os.rmdir(tmp_dir)
else:
return None

Expand Down

0 comments on commit 6846c27

Please sign in to comment.