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 support for border-image-source and border-image-slice. #2125

Merged
merged 31 commits into from
Apr 26, 2024
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
69e9c55
Add basic support for border-image-source and border-image-slice with…
xavidotron Apr 10, 2024
136ab09
Handle borders of uneven width with border images.
xavidotron Apr 10, 2024
c1966b6
Support non-percent-based coordinates in border-image-slice.
xavidotron Apr 11, 2024
9be367d
Fix silly mistake with fill in border-image-slice.
xavidotron Apr 11, 2024
f6a30fc
Avoid mutating the image-slice
xavidotron Apr 20, 2024
3060263
Rename tests and remove extra comments
liZe Apr 24, 2024
aea95e0
Simplify SVG file
liZe Apr 24, 2024
9e042c2
Correctly split specified and computed values
liZe Apr 24, 2024
6f9550b
Clean border image drawing code
liZe Apr 24, 2024
0bb0f5d
Add validation tests
liZe Apr 25, 2024
e87fc5c
Merge branch 'Kozea:main' into main
xavidotron Apr 25, 2024
d7bd828
Add support for the border-image-repeat CSS property.
xavidotron Apr 26, 2024
e9ac268
Remove unnecessary check for length of border-image-repeat, that's ha…
xavidotron Apr 26, 2024
bd51459
Move border-image-repeat logic to not be in the middle of the slice c…
xavidotron Apr 26, 2024
2fe3364
Add support for border-image-outset.
xavidotron Apr 26, 2024
b3efa78
Support border-image-width.
xavidotron Apr 26, 2024
eae6ebc
Clean coding style
liZe Apr 26, 2024
8005207
Handle gradients for border images
liZe Apr 26, 2024
1f702be
Correctly handle border image slices larger than the image
liZe Apr 26, 2024
703cd03
Don’t swap border image repeat values
liZe Apr 26, 2024
dbcd901
Avoid divisions by 0 when drawing border images
liZe Apr 26, 2024
9c098d6
Use consistent variable name
liZe Apr 26, 2024
acd91eb
Calculate scale and repeat outside the drawing stack
liZe Apr 26, 2024
76197f5
Avoid nested stacks for border images
liZe Apr 26, 2024
d5275f3
Fix corner cases for border images
liZe Apr 26, 2024
48a30e8
Avoid more divisions by 0
liZe Apr 26, 2024
1e20535
Display border images even when there’s no border
liZe Apr 26, 2024
aa79825
Fix extra space value
liZe Apr 26, 2024
65bcfbb
Test border-image shorthand
liZe Apr 26, 2024
886cefe
Put border image drawing in a specific function
liZe Apr 26, 2024
c863373
Update documentation about border images
liZe Apr 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Calculate scale and repeat outside the drawing stack
  • Loading branch information
liZe committed Apr 26, 2024
commit acd91ebb7706820db3da61b3b5ee7c90f86b9874
76 changes: 37 additions & 39 deletions weasyprint/draw.py
Original file line number Diff line number Diff line change
@@ -539,49 +539,47 @@ def draw_border_image(x, y, width, height, slice_x, slice_y,
width, height, slice_width, slice_height)):
return

extra_dx = 0
scale_x = 1
if repeat_x == 'repeat':
n_repeats_x = ceil(width / slice_width)
elif repeat_x == 'space':
n_repeats_x = floor(width / slice_width)
# Space is before the first repeat and after the last,
# so there's one more space than repeat.
extra_dx = (width - n_repeats_x * slice_width) / (n_repeats_x + 1)
elif repeat_x == 'round':
n_repeats_x = max(1, round(width / slice_width))
scale_x = width / (n_repeats_x * slice_width)
else:
n_repeats_x = 1
scale_x = width / slice_width

extra_dy = 0
scale_y = 1
if repeat_y == 'repeat':
n_repeats_y = ceil(height / slice_height)
elif repeat_y == 'space':
n_repeats_y = floor(height / slice_height)
# Space is before the first repeat and after the last,
# so there's one more space than repeat.
extra_dy = (height - n_repeats_y * slice_height) / (n_repeats_y + 1)
elif repeat_y == 'round':
n_repeats_y = max(1, round(height / slice_height))
scale_y = height / (n_repeats_y * slice_height)
else:
n_repeats_y = 1
scale_y = height / slice_height

rendered_width = intrinsic_width * scale_x
rendered_height = intrinsic_height * scale_y
offset_x = rendered_width * slice_x / intrinsic_width
offset_y = rendered_height * slice_y / intrinsic_height

with stacked(stream):
stream.rectangle(x, y, width, height)
stream.clip()
stream.end()
extra_dx = 0
extra_dy = 0

if repeat_x == 'repeat':
n_repeats_x = ceil(width / slice_width)
scale_x = 1
elif repeat_x == 'space':
n_repeats_x = floor(width / slice_width)
scale_x = 1
# Space is before the first repeat and after the last,
# so there's one more space than repeat.
extra_dx = (width - n_repeats_x * slice_width) / (n_repeats_x + 1)
elif repeat_x == 'round':
n_repeats_x = max(1, round(width / slice_width))
scale_x = width / (n_repeats_x * slice_width)
else:
n_repeats_x = 1
scale_x = width / slice_width

if repeat_y == 'repeat':
n_repeats_y = ceil(height / slice_height)
scale_y = 1
elif repeat_y == 'space':
n_repeats_y = floor(height / slice_height)
scale_y = 1
# Space is before the first repeat and after the last,
# so there's one more space than repeat.
extra_dy = (height - n_repeats_y * slice_height) / (n_repeats_y + 1)
elif repeat_y == 'round':
n_repeats_y = max(1, round(height / slice_height))
scale_y = height / (n_repeats_y * slice_height)
else:
n_repeats_y = 1
scale_y = height / slice_height

rendered_width = intrinsic_width * scale_x
rendered_height = intrinsic_height * scale_y
offset_x = rendered_width * slice_x / intrinsic_width
offset_y = rendered_height * slice_y / intrinsic_height
stream.transform(e=x - offset_x + extra_dx, f=y - offset_y + extra_dy)
stream.transform(a=scale_x, d=scale_y)
for xcnt in range(n_repeats_x):