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

fix: page dpi #2771

Merged
merged 2 commits into from
Jun 24, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/pretty-jars-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@react-pdf/layout': minor
'@react-pdf/pdfkit': minor
'@react-pdf/render': minor
'@react-pdf/stylesheet': minor
'@react-pdf/types': minor
---

fix: fix dpi
9 changes: 5 additions & 4 deletions packages/layout/src/page/getSize.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ const flipSizeObject = (v) => ({ width: v.height, height: v.width });
* @returns {{ width: number, height: number }} adjusted size object
*/
const adjustDpi = (v, dpi) => ({
width: v.width ? v.width * dpi : v.width,
height: v.height ? v.height * dpi : v.height,
width: v.width ? v.width * (72 / dpi) : v.width,
height: v.height ? v.height * (72 / dpi) : v.height,
});

/**
Expand Down Expand Up @@ -121,14 +121,15 @@ const getSize = (page) => {
size = getStringSize(value);
} else if (Array.isArray(value)) {
size = toSizeObject(value);
size = adjustDpi(size, dpi);
} else if (type === 'number') {
size = getNumberSize(value);
size = adjustDpi(size, dpi);
} else {
size = value;
size = adjustDpi(size, dpi);
}

size = adjustDpi(size, dpi / 72);

return isLandscape(page) ? flipSizeObject(size) : size;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/layout/src/steps/resolveStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const resolveNodeStyles = (container) => (node) => {
* @returns {Object} document page with resolved styles
*/
export const resolvePageStyles = (page) => {
const dpi = page.props?.dpi || 72;
const dpi = 72; // Removed: page.props?.dpi || 72;
const width = page.box?.width || page.style.width;
const height = page.box?.height || page.style.height;
const orientation = page.props?.orientation || 'portrait';
Expand Down
2 changes: 1 addition & 1 deletion packages/stylesheet/src/transform/units.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const parseValue = (value) => {
const transformUnit = (container, value) => {
const scalar = parseValue(value);

const dpi = container.dpi || 72;
const dpi = 72; // Removed: container.dpi || 72
const mmFactor = (1 / 25.4) * dpi;
const cmFactor = (1 / 2.54) * dpi;

Expand Down