Skip to content

Commit

Permalink
Workaround for Chrome printing problem
Browse files Browse the repository at this point in the history
  • Loading branch information
kwkbtr committed Nov 7, 2017
1 parent 6ab135c commit dae1ad1
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions resources/vivliostyle-viewport.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
overflow: hidden;
max-width: 100%;
max-height: 100%;
box-sizing: border-box;
}

@media print {
Expand Down
2 changes: 2 additions & 0 deletions src/adapt/ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,8 @@ adapt.ops.StyleInstance.prototype.setPageSizeAndBleed = function(evaluatedPageSi
page.bleedBox.style.top = evaluatedPageSizeAndBleed.bleedOffset + "px";
page.bleedBox.style.bottom = evaluatedPageSizeAndBleed.bleedOffset + "px";
page.bleedBox.style.padding = evaluatedPageSizeAndBleed.bleed + "px";
// Shift 1px to workaround Chrome printing bug
page.bleedBox.style.paddingTop = (evaluatedPageSizeAndBleed.bleed+1) + "px";
};

/**
Expand Down
2 changes: 2 additions & 0 deletions src/adapt/pm.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ adapt.pm.PageMaster = function(scope, name, pseudoName, classes, parent, conditi
this.specified["wrap-flow"] = new adapt.csscasc.CascadeValue(adapt.css.ident.auto, 0);
this.specified["position"] = new adapt.csscasc.CascadeValue(adapt.css.ident.relative, 0);
this.specified["overflow"] = new adapt.csscasc.CascadeValue(adapt.css.ident.visible, 0);
// Shift 1px to workaround Chrome printing bug
this.specified["top"] = new adapt.csscasc.CascadeValue(new adapt.css.Numeric(-1, "px"), 0);
/** @type {Object.<string,string>} */ this.keyMap = {};
};
goog.inherits(adapt.pm.PageMaster, adapt.pm.PageBox);
Expand Down
3 changes: 2 additions & 1 deletion src/vivliostyle/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,8 @@ vivliostyle.page.PageRuleMasterInstance.prototype.initHorizontal = function() {
*/
vivliostyle.page.PageRuleMasterInstance.prototype.initVertical = function() {
var style = this.style;
style["top"] = adapt.css.numericZero;
// Shift 1px to workaround Chrome printing bug
style["top"] = new adapt.css.Numeric(-1, "px");
style["margin-top"] = adapt.css.numericZero;
style["border-top-width"] = adapt.css.numericZero;
style["padding-top"] = adapt.css.numericZero;
Expand Down
6 changes: 6 additions & 0 deletions test/files/file-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ module.exports = [
{file: "page_breaks/class_C_break_point.html", title: "Class C break point"}
]
},
{
category: "Print",
files: [
{file: "print/chrome_page_top_margin_bug.html", title: "Chrome page top margin bug"}
]
},
{
category: "Column",
files: [
Expand Down
30 changes: 30 additions & 0 deletions test/files/print/chrome_page_top_margin_bug.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Chrome page top margin bug</title>
<style>
@page {
size: 400px 200px;
margin: 0;
}

body {
margin: 0;
}

section {
margin-top: 20px;
page-break-after: always;
}
</style>
</head>
<body>
<section>
(1st page) Print this on Chrome and check layout
</section>
<section>
(2nd page) There should be 20px top margin above this text
</section>
</body>
</html>

0 comments on commit dae1ad1

Please sign in to comment.