fix: correctly calculate the background repeat path

This commit is contained in:
chaijianxiang 2022-03-30 21:33:37 +08:00
parent 6020386bbe
commit 09b6f0f82f
2 changed files with 67 additions and 8 deletions

View File

@ -226,34 +226,34 @@ export const calculateBackgroundRepeatPath = (
switch (repeat) { switch (repeat) {
case BACKGROUND_REPEAT.REPEAT_X: case BACKGROUND_REPEAT.REPEAT_X:
return [ return [
new Vector(Math.round(backgroundPositioningArea.left), Math.round(backgroundPositioningArea.top + y)), new Vector(Math.round(backgroundPaintingArea.left), Math.round(backgroundPositioningArea.top + y)),
new Vector( new Vector(
Math.round(backgroundPositioningArea.left + backgroundPositioningArea.width), Math.round(backgroundPaintingArea.left + backgroundPaintingArea.width),
Math.round(backgroundPositioningArea.top + y) Math.round(backgroundPositioningArea.top + y)
), ),
new Vector( new Vector(
Math.round(backgroundPositioningArea.left + backgroundPositioningArea.width), Math.round(backgroundPaintingArea.left + backgroundPaintingArea.width),
Math.round(height + backgroundPositioningArea.top + y) Math.round(height + backgroundPositioningArea.top + y)
), ),
new Vector( new Vector(
Math.round(backgroundPositioningArea.left), Math.round(backgroundPaintingArea.left),
Math.round(height + backgroundPositioningArea.top + y) Math.round(height + backgroundPositioningArea.top + y)
) )
]; ];
case BACKGROUND_REPEAT.REPEAT_Y: case BACKGROUND_REPEAT.REPEAT_Y:
return [ return [
new Vector(Math.round(backgroundPositioningArea.left + x), Math.round(backgroundPositioningArea.top)), new Vector(Math.round(backgroundPositioningArea.left + x), Math.round(backgroundPaintingArea.top)),
new Vector( new Vector(
Math.round(backgroundPositioningArea.left + x + width), Math.round(backgroundPositioningArea.left + x + width),
Math.round(backgroundPositioningArea.top) Math.round(backgroundPaintingArea.top)
), ),
new Vector( new Vector(
Math.round(backgroundPositioningArea.left + x + width), Math.round(backgroundPositioningArea.left + x + width),
Math.round(backgroundPositioningArea.height + backgroundPositioningArea.top) Math.round(backgroundPaintingArea.height + backgroundPaintingArea.top)
), ),
new Vector( new Vector(
Math.round(backgroundPositioningArea.left + x), Math.round(backgroundPositioningArea.left + x),
Math.round(backgroundPositioningArea.height + backgroundPositioningArea.top) Math.round(backgroundPaintingArea.height + backgroundPaintingArea.top)
) )
]; ];
case BACKGROUND_REPEAT.NO_REPEAT: case BACKGROUND_REPEAT.NO_REPEAT:

View File

@ -0,0 +1,59 @@
<!DOCTYPE html>
<html>
<head>
<title>Background attribute tests</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="../../test.js"></script>
<style>
html {
background-color: red;
}
body {
background-color: lime;
}
.medium div{
width:100px;
height:100px;
float:left;
margin:10px;
border:20px solid transparent;
border-width: 10px 20px 30px 40px;
background: green;
padding: 25px 15px;
}
.medium{
clear:both;
}
div{
display:block;
}
</style>
</head>
<body>
<div class="medium">
<div style="background:url(../../assets/image.jpg);background-clip: border-box; background-origin: padding-box; background-repeat: repeat-x;"></div>
<div style="background:url(../../assets/image.jpg);background-clip: padding-box; background-origin: padding-box; background-repeat: repeat-x;"></div>
<div style="background:url(../../assets/image.jpg);background-clip: content-box; background-origin: padding-box; background-repeat: repeat-x;"></div>
<div style="background:url(../../assets/image.jpg);background-clip: border-box; background-origin: padding-box; background-repeat: repeat;"></div>
</div>
<div class="medium">
<div style="background:url(../../assets/image.jpg);background-clip: border-box; background-origin: padding-box; background-repeat: repeat-y;"></div>
<div style="background:url(../../assets/image.jpg);background-clip: padding-box; background-origin: padding-box; background-repeat: repeat-y;"></div>
<div style="background:url(../../assets/image.jpg);background-clip: content-box; background-origin: padding-box; background-repeat: repeat-y;"></div>
</div>
<div class="medium">
<div style="background-clip: border-box;"></div>
<div style="background-clip: padding-box;"></div>
<div style="background-clip: content-box;"></div>
<div style=""></div>
</div>
</body>
</html>