mirror of
https://github.com/Kozea/WeasyPrint.git
synced 2024-09-11 20:47:56 +03:00
Add an option to disable hinting
Hinting is now enabled by default. Fix #1858.
This commit is contained in:
parent
9b21d0f100
commit
2358a01bc4
@ -376,12 +376,16 @@ def test_command_line_render(tmpdir):
|
||||
assert (
|
||||
len(tmpdir.join('out26.pdf').read_binary()) <
|
||||
len(tmpdir.join('out25.pdf').read_binary()) <
|
||||
len(tmpdir.join('out19.pdf').read_binary()) <
|
||||
len(tmpdir.join('out16.pdf').read_binary()) <
|
||||
len(tmpdir.join('out15.pdf').read_binary()) <
|
||||
len(tmpdir.join('out20.pdf').read_binary()))
|
||||
assert len({
|
||||
tmpdir.join(f'out{i}.pdf').read_binary()
|
||||
for i in (16, 18, 19, 21)}) == 1
|
||||
for i in (16, 18)}) == 1
|
||||
assert len({
|
||||
tmpdir.join(f'out{i}.pdf').read_binary()
|
||||
for i in (19, 21)}) == 1
|
||||
assert len({
|
||||
tmpdir.join(f'out{i}.pdf').read_binary()
|
||||
for i in (15, 17, 23, 24, 27)}) == 1
|
||||
|
@ -134,8 +134,8 @@ class HTML:
|
||||
: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`
|
||||
@ -188,8 +188,8 @@ class HTML:
|
||||
: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`
|
||||
|
@ -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>
|
||||
|
||||
@ -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',
|
||||
@ -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)
|
||||
|
||||
|
@ -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':
|
||||
|
@ -97,7 +97,7 @@ class 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
|
||||
|
||||
@ -106,7 +106,7 @@ class Font:
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user