Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 6 additions & 2 deletions src/render/canvas/canvas-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ export class CanvasRenderer extends Renderer {

async renderBackgroundImage(container: ElementContainer): Promise<void> {
let index = container.styles.backgroundImage.length - 1;
const repeatTypes = ['repeat', 'no-repeat', 'repeat-x', 'repeat-y'];
for (const backgroundImage of container.styles.backgroundImage.slice(0).reverse()) {
if (backgroundImage.type === CSSImageType.URL) {
let image;
Expand All @@ -602,7 +603,7 @@ export class CanvasRenderer extends Renderer {
]);
const pattern = this.ctx.createPattern(
this.resizeImage(image, width, height),
'repeat'
repeatTypes[+container.styles.backgroundRepeat || 0]
) as CanvasPattern;
this.renderRepeat(path, pattern, x, y);
}
Expand All @@ -623,7 +624,10 @@ export class CanvasRenderer extends Renderer {
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, width, height);
if (width > 0 && height > 0) {
const pattern = this.ctx.createPattern(canvas, 'repeat') as CanvasPattern;
const pattern = this.ctx.createPattern(
canvas,
repeatTypes[+container.styles.backgroundRepeat || 0]
) as CanvasPattern;
this.renderRepeat(path, pattern, x, y);
}
} else if (isRadialGradient(backgroundImage)) {
Expand Down
Binary file added tests/assets/edges.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions tests/reftests/background/repeat.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@
display:block;
}

.shared-area {
text-align: center;
border: solid .5em #0d47a1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
background-color: white;
}

.edges {
width: 80%;
height: 50%;
background-size: contain;
background-position: center center;
background-image: url('../../assets/edges.png');
background-color: white;
background-repeat: no-repeat;
}

</style>

</head>
Expand All @@ -45,12 +65,20 @@
<div style="background:url(../../assets/image.jpg) repeat-x;"></div>
<div style="background:url(../../assets/image.jpg) repeat-y;"></div>
<div style="background:url(../../assets/image.jpg) no-repeat;"></div>
<div class="shared-area">
<p class="edges"></p>
<p class="caption">Edges</p>
</div>
</div>
<div class="small">
<div style="background:url(../../assets/image.jpg);"></div>
<div style="background:url(../../assets/image.jpg) repeat-x;"></div>
<div style="background:url(../../assets/image.jpg) repeat-y;"></div>
<div style="background:url(../../assets/image.jpg) no-repeat;"></div>
<div class="shared-area">
<p class="edges"></p>
<p class="caption">Edges</p>
</div>
</div>

</body>
Expand Down