Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add text-align-last #1389

Merged
merged 1 commit into from Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions weasyprint/css/properties.py
Expand Up @@ -148,6 +148,7 @@
'letter_spacing': 'normal',
'tab_size': 8,
'text_align': 'start',
'text_align_last': 'auto',
'text_indent': Dimension(0, 'px'),
'text_transform': 'none',
'white_space': 'normal',
Expand Down Expand Up @@ -258,6 +259,7 @@
'quotes',
'tab_size',
'text_align',
'text_align_last',
'text_decoration_line',
'text_decoration_color',
'text_decoration_style',
Expand Down
7 changes: 7 additions & 0 deletions weasyprint/css/validation/properties.py
Expand Up @@ -1067,6 +1067,13 @@ def text_align(keyword):
return keyword in ('left', 'right', 'center', 'justify', 'start', 'end')


@property()
@single_keyword
def text_align_last(keyword):
"""``text-align-last`` property validation."""
return keyword in ('auto', 'left', 'right', 'center', 'justify', 'start', 'end')


@property()
def text_decoration_line(tokens):
"""``text-decoration-line`` property validation."""
Expand Down
8 changes: 6 additions & 2 deletions weasyprint/layout/inlines.py
Expand Up @@ -1313,15 +1313,19 @@ def text_align(context, line, available_width, last):
return 0

align = line.style['text_align']
align_last = line.style['text_align_last']
if last:
if align_last != 'auto':
align = align_last
elif align == 'justify':
align = 'start'
space_collapse = line.style['white_space'] in (
'normal', 'nowrap', 'pre-line')
if align in ('left', 'right'):
if (align == 'left') ^ (line.style['direction'] == 'rtl'):
align = 'start'
else:
align = 'end'
if align == 'justify' and last:
align = 'start'
if align == 'start':
return 0
offset = available_width - line.width
Expand Down