Skip to content

Commit

Permalink
Add an option to disable hinting
Browse files Browse the repository at this point in the history
Hinting is now enabled by default. Fix #1858.
  • Loading branch information
liZe committed Apr 9, 2023
1 parent 9b21d0f commit d9c8af8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
8 changes: 4 additions & 4 deletions weasyprint/__init__.py
Expand Up @@ -134,8 +134,8 @@ def render(self, stylesheets=None, presentational_hints=False,
:param bool presentational_hints:
Whether HTML presentational hints are followed.
:param tuple optimize_size:
Optimize size of generated PDF. Can contain "images", "fonts" and
"pdf".
Optimize size of generated PDF. Can contain "images", "fonts",
"hinting" and "pdf".
:param int jpeg_quality: JPEG quality between 0 (worst) to 95 (best).
:param int dpi: Maximum resolution of images embedded in the PDF.
:type font_config: :class:`text.fonts.FontConfiguration`
Expand Down Expand Up @@ -188,8 +188,8 @@ def write_pdf(self, target=None, stylesheets=None, zoom=1,
:param bool presentational_hints: Whether HTML presentational hints are
followed.
:param tuple optimize_size:
Optimize size of generated PDF. Can contain "images", "fonts" and
"pdf".
Optimize size of generated PDF. Can contain "images", "fonts",
"hinting" and "pdf".
:param int jpeg_quality: JPEG quality between 0 (worst) to 95 (best).
:param int dpi: Maximum resolution of images embedded in the PDF.
:type font_config: :class:`text.fonts.FontConfiguration`
Expand Down
12 changes: 6 additions & 6 deletions weasyprint/__main__.py
Expand Up @@ -90,10 +90,10 @@ def main(argv=None, stdout=None, stdin=None):
.. option:: -O <type>, --optimize-size <type>
Optimize the size of generated documents. Supported types are
``images``, ``fonts``, ``pdf``, ``all`` and ``none``. This option can
be used multiple times, ``all`` adds all allowed values, ``none``
removes all previously set values (including the default ones,
``fonts`` and ``pdf``).
``images``, ``fonts``, ``hinting``, ``pdf``, ``all`` and ``none``.
This option can be used multiple times, ``all`` adds all allowed
values, ``none`` removes all previously set values (including the
default ones, ``fonts`` and ``pdf``).
.. option:: -c <folder>, --cache-folder <folder>
Expand Down Expand Up @@ -169,7 +169,7 @@ def main(argv=None, stdout=None, stdin=None):
parser.add_argument(
'-O', '--optimize-size', action='append',
help='optimize output size for specified features',
choices=('images', 'fonts', 'pdf', 'all', 'none'),
choices=('images', 'fonts', 'hinting', 'pdf', 'all', 'none'),
default=['fonts', 'pdf'])
parser.add_argument(
'-c', '--cache-folder',
Expand Down Expand Up @@ -214,7 +214,7 @@ def main(argv=None, stdout=None, stdin=None):
if arg == 'none':
optimize_size.clear()
elif arg == 'all':
optimize_size |= {'images', 'fonts', 'pdf'}
optimize_size |= {'images', 'fonts', 'hinting', 'pdf'}
else:
optimize_size.add(arg)

Expand Down
3 changes: 2 additions & 1 deletion weasyprint/pdf/fonts.py
Expand Up @@ -25,7 +25,8 @@ def build_fonts_dictionary(pdf, fonts, optimize_size):
if 'fonts' in optimize_size and not font.used_in_forms:
for file_font in file_fonts:
cmap = {**cmap, **file_font.cmap}
font.clean(cmap)
hinting = 'hinting' not in optimize_size
font.clean(cmap, hinting)

# Include font
if font.type == 'otf':
Expand Down
4 changes: 2 additions & 2 deletions weasyprint/pdf/stream.py
Expand Up @@ -97,7 +97,7 @@ def __init__(self, pango_font):
if len(widths) > 1 and len(set(widths)) == 1:
self.flags += 2 ** (1 - 1) # FixedPitch

def clean(self, cmap):
def clean(self, cmap, hinting):
if self.ttfont is None:
return

Expand All @@ -106,7 +106,7 @@ def clean(self, cmap):
optimized_font = io.BytesIO()
options = subset.Options(
retain_gids=True, passthrough_tables=True,
ignore_missing_glyphs=True, hinting=False,
ignore_missing_glyphs=True, hinting=hinting,
desubroutinize=True)
options.drop_tables += ['GSUB', 'GPOS', 'SVG']
subsetter = subset.Subsetter(options)
Expand Down

0 comments on commit d9c8af8

Please sign in to comment.