Skip to content

Commit

Permalink
Always set tabulation width
Browse files Browse the repository at this point in the history
Not setting it makes Pango use a slightly different value of tabulation width,
breaking a test.
  • Loading branch information
liZe committed Sep 5, 2019
1 parent 29fcb45 commit b06a3a9
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions weasyprint/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,10 +728,6 @@ def setup(self, context, font_size, style):
pango.pango_attr_list_insert(attr_list, attr)
pango.pango_layout_set_attributes(self.layout, attr_list)

# Tabs width
if style['tab_size'] != 8: # Default Pango value is 8
self.set_tabs()

def get_first_line(self):
layout_iter = ffi.gc(
pango.pango_layout_get_iter(self.layout),
Expand Down Expand Up @@ -783,6 +779,10 @@ def add_attr(start, end, spacing):
pango.pango_layout_set_attributes(self.layout, attr_list)
pango.pango_attr_list_unref(attr_list)

# Tabs width
if b'\t' in bytestring:
self.set_tabs()

def get_font_metrics(self):
context = pango.pango_layout_get_context(self.layout)
return FontMetrics(context, self.font, self.language)
Expand All @@ -792,14 +792,12 @@ def set_wrap(self, wrap_mode):

def set_tabs(self):
if isinstance(self.style['tab_size'], int):
style = self.style.copy()
style['tab_size'] = 8
layout = Layout(
self.context, style['font_size'], style,
self.context, self.style['font_size'], self.style,
self.justification_spacing)
layout.set_text(' ' * self.style['tab_size'])
line, _ = layout.get_first_line()
width, _ = get_size(line, style)
width, _ = get_size(line, self.style)
width = int(round(width))
else:
width = int(self.style['tab_size'].value)
Expand Down

0 comments on commit b06a3a9

Please sign in to comment.