Skip to content

Commit 2bc635d

Browse files
committed
Remove useless font_size parameter when building Layouts
Also fix a missing font size for fonts inserted for forms.
1 parent 0eac6fd commit 2bc635d

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

weasyprint/css/computed_values.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ def strut_layout(style, context=None):
748748
if key in context.strut_layouts:
749749
return context.strut_layouts[key]
750750

751-
layout = Layout(context, style['font_size'], style)
751+
layout = Layout(context, style)
752752
layout.set_text(' ')
753753
line, _ = layout.get_first_line()
754754
_, _, _, _, text_height, baseline = first_line_metrics(
@@ -782,11 +782,10 @@ def character_ratio(style, character):
782782
style = style.copy()
783783
style['letter_spacing'] = 'normal'
784784
style['word_spacing'] = 0
785-
786785
# Random big value
787-
font_size = 1000
786+
style['font_size'] = 1000
788787

789-
layout = Layout(context=None, font_size=font_size, style=style)
788+
layout = Layout(context=None, style=style)
790789
layout.set_text(character)
791790
line, _ = layout.get_first_line()
792791

@@ -802,6 +801,6 @@ def character_ratio(style, character):
802801

803802
# Zero means some kind of failure, fallback is 0.5.
804803
# We round to try keeping exact values that were altered by Pango.
805-
ratio = round(measure / font_size, 5) or 0.5
804+
ratio = round(measure / style['font_size'], 5) or 0.5
806805
cache[cache_key] = ratio
807806
return ratio

weasyprint/text/fonts.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def font_features(font_kerning='normal', font_variant_ligatures='normal',
330330
return features
331331

332332

333-
def get_font_description(style, font_size=None):
333+
def get_font_description(style):
334334
font_description = ffi.gc(
335335
pango.pango_font_description_new(),
336336
pango.pango_font_description_free)
@@ -342,9 +342,8 @@ def get_font_description(style, font_size=None):
342342
font_description, PANGO_STRETCH[style['font_stretch']])
343343
pango.pango_font_description_set_weight(
344344
font_description, style['font_weight'])
345-
if font_size is not None:
346-
pango.pango_font_description_set_absolute_size(
347-
font_description, units_from_double(font_size))
345+
pango.pango_font_description_set_absolute_size(
346+
font_description, units_from_double(style['font_size']))
348347
if style['font_variation_settings'] != 'normal':
349348
string = ','.join(
350349
f'{key}={value}' for key, value in

weasyprint/text/line_break.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ def first_line_metrics(first_line, text, layout, resume_at, space_collapse,
5858

5959
class Layout:
6060
"""Object holding PangoLayout-related cdata pointers."""
61-
def __init__(self, context, font_size, style, justification_spacing=0,
61+
def __init__(self, context, style, justification_spacing=0,
6262
max_width=None):
6363
self.justification_spacing = justification_spacing
64-
self.setup(context, font_size, style)
64+
self.setup(context, style)
6565
self.max_width = max_width
6666

67-
def setup(self, context, font_size, style):
67+
def setup(self, context, style):
6868
self.context = context
6969
self.style = style
7070
self.first_line_direction = 0
@@ -94,7 +94,7 @@ def setup(self, context, font_size, style):
9494

9595
assert not isinstance(style['font_family'], str), (
9696
'font_family should be a list')
97-
font_description = get_font_description(style, font_size)
97+
font_description = get_font_description(style)
9898
self.layout = ffi.gc(
9999
pango.pango_layout_new(pango_context),
100100
gobject.g_object_unref)
@@ -203,8 +203,7 @@ def add_attr(start, end, spacing):
203203
def set_tabs(self):
204204
if isinstance(self.style['tab_size'], int):
205205
layout = Layout(
206-
self.context, self.style['font_size'], self.style,
207-
self.justification_spacing)
206+
self.context, self.style, self.justification_spacing)
208207
layout.set_text(' ' * self.style['tab_size'])
209208
line, _ = layout.get_first_line()
210209
width, _ = line_size(line, self.style)
@@ -222,7 +221,7 @@ def deactivate(self):
222221
del self.layout, self.language, self.style
223222

224223
def reactivate(self, style):
225-
self.setup(self.context, style['font_size'], style)
224+
self.setup(self.context, style)
226225
self.set_text(self.text, justify=True)
227226

228227

@@ -236,8 +235,7 @@ def create_layout(text, style, context, max_width, justification_spacing):
236235
or ``None`` for unlimited width.
237236
238237
"""
239-
layout = Layout(
240-
context, style['font_size'], style, justification_spacing, max_width)
238+
layout = Layout(context, style, justification_spacing, max_width)
241239

242240
# Make sure that max_width * Pango.SCALE == max_width * 1024 fits in a
243241
# signed integer. Treat bigger values same as None: unconstrained width.

0 commit comments

Comments
 (0)